33import numpy as np
44from copy import copy
55from dnora .type_manager .spectral_conventions import SpectralConvention
6+ import os
67
78
89def load_test_spec (shifted = False , math = False ):
@@ -23,10 +24,19 @@ def load_test_spec(shifted=False, math=False):
2324 D = np .linspace (0.0 , 345.0 , 24 ) # np.loadtxt('data/dir.test')
2425
2526 S = np .ones ((2 , 2 , len (f ), len (D )), float )
26- S [0 , 0 , :, :] = np .loadtxt ("data/spec1.test" )
27- S [0 , 1 , :, :] = np .loadtxt ("data/spec2.test" )
28- S [1 , 0 , :, :] = np .loadtxt ("data/spec3.test" )
29- S [1 , 1 , :, :] = np .loadtxt ("data/spec4.test" )
27+
28+ # Get the current file's directory (the test file's directory)
29+ current_dir = os .path .dirname (__file__ )
30+
31+ # Construct the absolute path to the data file
32+ data_file1 = os .path .join (current_dir , "data" , "spec1.test" )
33+ data_file2 = os .path .join (current_dir , "data" , "spec2.test" )
34+ data_file3 = os .path .join (current_dir , "data" , "spec3.test" )
35+ data_file4 = os .path .join (current_dir , "data" , "spec4.test" )
36+ S [0 , 0 , :, :] = np .loadtxt (data_file1 )
37+ S [0 , 1 , :, :] = np .loadtxt (data_file2 )
38+ S [1 , 0 , :, :] = np .loadtxt (data_file3 )
39+ S [1 , 1 , :, :] = np .loadtxt (data_file4 )
3040
3141 return S , D
3242
@@ -35,7 +45,7 @@ def loop_conventions(list_of_conventions, S, D):
3545 Snew = copy (S )
3646 inds = np .array (range (S .shape [0 ]))
3747 Dnew = copy (D )
38- freq = np .linspace (0.0345 , 0.5476 , 30 )
48+ freq = np .linspace (0.0345 , 0.5476 , 30 )
3949 for n in range (len (list_of_conventions ) - 1 ):
4050 cur_c = list_of_conventions [n ]
4151 wan_c = list_of_conventions [n + 1 ]
@@ -44,7 +54,7 @@ def loop_conventions(list_of_conventions, S, D):
4454 )
4555 if not isinstance (bnd_processor , list ):
4656 bnd_processor = [bnd_processor ]
47-
57+
4858 for processor in bnd_processor :
4959 Snew , Dnew , _ , _ , _ = processor (
5060 spec = Snew , dirs = Dnew , freq = freq , inds = inds , times = None
@@ -58,7 +68,7 @@ def test_ocean_to_met(self):
5868 D = np .arange (0 , 360 , dD )
5969 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
6070 freq = np .array ([[0.1 ]])
61- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
71+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
6272 inds = np .array (range (S .shape [0 ]))
6373 bnd_processor = (
6474 dnora .process .spectra .spectral_processor_for_convention_change (
@@ -82,14 +92,14 @@ def test_ocean_to_ww3(self):
8292 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
8393 inds = np .array (range (S .shape [0 ]))
8494 freq = np .array ([[0.1 ]])
85- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
95+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
8696 bnd_processor = (
8797 dnora .process .spectra .spectral_processor_for_convention_change (
8898 current_convention = SpectralConvention .OCEAN ,
8999 wanted_convention = SpectralConvention .WW3 ,
90100 )
91101 )
92-
102+
93103 Snew , Dnew , _ , _ , _ = bnd_processor (
94104 spec = S , dirs = D , freq = freq , inds = inds , times = None
95105 )
@@ -110,7 +120,7 @@ def test_ocean_to_math(self):
110120 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
111121 inds = np .array (range (S .shape [0 ]))
112122 freq = np .array ([[0.1 ]])
113- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
123+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
114124 bnd_processor = (
115125 dnora .process .spectra .spectral_processor_for_convention_change (
116126 current_convention = SpectralConvention .OCEAN ,
@@ -133,7 +143,7 @@ def test_ocean_to_mathvec(self):
133143 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
134144 inds = np .array (range (S .shape [0 ]))
135145 freq = np .array ([[0.1 ]])
136- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
146+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
137147 bnd_processor = (
138148 dnora .process .spectra .spectral_processor_for_convention_change (
139149 current_convention = SpectralConvention .OCEAN ,
@@ -164,7 +174,7 @@ def test_ww3_to_ocean(self):
164174 )
165175 inds = np .array (range (S .shape [0 ]))
166176 freq = np .array ([[0.1 ]])
167- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
177+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
168178 bnd_processor = (
169179 dnora .process .spectra .spectral_processor_for_convention_change (
170180 current_convention = SpectralConvention .WW3 ,
@@ -196,7 +206,7 @@ def test_ww3_to_met(self):
196206 )
197207 inds = np .array (range (S .shape [0 ]))
198208 freq = np .array ([[0.1 ]])
199- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
209+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
200210 bnd_processor = (
201211 dnora .process .spectra .spectral_processor_for_convention_change (
202212 current_convention = SpectralConvention .WW3 ,
@@ -229,7 +239,7 @@ def test_ww3_to_math(self):
229239 )
230240 inds = np .array (range (S .shape [0 ]))
231241 freq = np .array ([[0.1 ]])
232- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
242+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
233243 bnd_processor = (
234244 dnora .process .spectra .spectral_processor_for_convention_change (
235245 current_convention = SpectralConvention .WW3 ,
@@ -265,7 +275,7 @@ def test_ww3_to_mathvec(self):
265275 )
266276 inds = np .array (range (S .shape [0 ]))
267277 freq = np .array ([[0.1 ]])
268- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
278+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
269279 bnd_processor = (
270280 dnora .process .spectra .spectral_processor_for_convention_change (
271281 current_convention = SpectralConvention .WW3 ,
@@ -304,7 +314,7 @@ def test_met_to_ocean(self):
304314 )
305315 inds = np .array (range (S .shape [0 ]))
306316 freq = np .array ([[0.1 ]])
307- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
317+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
308318 bnd_processor = (
309319 dnora .process .spectra .spectral_processor_for_convention_change (
310320 current_convention = SpectralConvention .MET ,
@@ -332,7 +342,7 @@ def test_met_to_ww3(self):
332342 )
333343 inds = np .array (range (S .shape [0 ]))
334344 freq = np .array ([[0.1 ]])
335- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
345+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
336346 bnd_processor = (
337347 dnora .process .spectra .spectral_processor_for_convention_change (
338348 current_convention = SpectralConvention .MET ,
@@ -368,7 +378,7 @@ def test_met_to_math(self):
368378 )
369379 inds = np .array (range (S .shape [0 ]))
370380 freq = np .array ([[0.1 ]])
371- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
381+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
372382 bnd_processor = (
373383 dnora .process .spectra .spectral_processor_for_convention_change (
374384 current_convention = SpectralConvention .MET ,
@@ -400,7 +410,7 @@ def test_met_to_mathvec(self):
400410 )
401411 inds = np .array (range (S .shape [0 ]))
402412 freq = np .array ([[0.1 ]])
403- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
413+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
404414 bnd_processor = (
405415 dnora .process .spectra .spectral_processor_for_convention_change (
406416 current_convention = SpectralConvention .MET ,
@@ -440,7 +450,7 @@ def test_math_to_ocean(self):
440450 )
441451 inds = np .array (range (S .shape [0 ]))
442452 freq = np .array ([[0.1 ]])
443- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
453+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
444454 bnd_processor = (
445455 dnora .process .spectra .spectral_processor_for_convention_change (
446456 current_convention = SpectralConvention .MATH ,
@@ -469,7 +479,7 @@ def test_math_to_ww3(self):
469479 )
470480 inds = np .array (range (S .shape [0 ]))
471481 freq = np .array ([[0.1 ]])
472- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
482+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
473483 bnd_processor = (
474484 dnora .process .spectra .spectral_processor_for_convention_change (
475485 current_convention = SpectralConvention .MATH ,
@@ -501,7 +511,7 @@ def test_math_to_met(self):
501511 )
502512 inds = np .array (range (S .shape [0 ]))
503513 freq = np .array ([[0.1 ]])
504- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
514+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
505515 bnd_processor = (
506516 dnora .process .spectra .spectral_processor_for_convention_change (
507517 current_convention = SpectralConvention .MATH ,
@@ -531,7 +541,7 @@ def test_math_to_mathvec(self):
531541 )
532542 inds = np .array (range (S .shape [0 ]))
533543 freq = np .array ([[0.1 ]])
534- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
544+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
535545 bnd_processor = (
536546 dnora .process .spectra .spectral_processor_for_convention_change (
537547 current_convention = SpectralConvention .MATH ,
@@ -564,7 +574,7 @@ def test_mathvec_to_ocean(self):
564574 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
565575 inds = np .array (range (S .shape [0 ]))
566576 freq = np .array ([[0.1 ]])
567- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
577+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
568578 bnd_processor = (
569579 dnora .process .spectra .spectral_processor_for_convention_change (
570580 current_convention = SpectralConvention .MATHVEC ,
@@ -586,7 +596,7 @@ def test_mathvec_to_met(self):
586596 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
587597 inds = np .array (range (S .shape [0 ]))
588598 freq = np .array ([[0.1 ]])
589- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
599+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
590600 bnd_processor = (
591601 dnora .process .spectra .spectral_processor_for_convention_change (
592602 current_convention = SpectralConvention .MATHVEC ,
@@ -615,7 +625,7 @@ def test_mathvec_to_ww3(self):
615625 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
616626 inds = np .array (range (S .shape [0 ]))
617627 freq = np .array ([[0.1 ]])
618- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
628+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
619629 bnd_processor = (
620630 dnora .process .spectra .spectral_processor_for_convention_change (
621631 current_convention = SpectralConvention .MATHVEC ,
@@ -642,7 +652,7 @@ def test_mathvec_to_math(self):
642652 S = np .array ([np .arange (0 , 36 , dD / 10 ), np .arange (0 , 36 , dD / 10 )])
643653 inds = np .array (range (S .shape [0 ]))
644654 freq = np .array ([[0.1 ]])
645- S = np .reshape (S , (S .shape [0 ],len (freq ),S .shape [- 1 ]))
655+ S = np .reshape (S , (S .shape [0 ], len (freq ), S .shape [- 1 ]))
646656 bnd_processor = (
647657 dnora .process .spectra .spectral_processor_for_convention_change (
648658 current_convention = SpectralConvention .MATHVEC ,
0 commit comments