Index: trunk/SDToolBox/extract_data.py =================================================================== diff -u -r112 -r116 --- trunk/SDToolBox/extract_data.py (.../extract_data.py) (revision 112) +++ trunk/SDToolBox/extract_data.py (.../extract_data.py) (revision 116) @@ -109,6 +109,11 @@ __file_iterator: list = [] + def __init__(self): + super().__init__() + # Force cleaning up iterator to avoid cached issues. + self.__file_iterator = [] + # Region Abstract methods / properties. @property @abstractmethod @@ -277,7 +282,7 @@ [nn_idx[1][i] for i in unique_idx] return new_nn_idx, \ [unique_nn.tolist().index(nn.tolist()) - for nn in combined_array] + for nn in combined_array] def __get_time_ref_group(self) -> List[str]: return [ Index: trunk/tests/test_extract_data.py =================================================================== diff -u -r112 -r116 --- trunk/tests/test_extract_data.py (.../test_extract_data.py) (revision 112) +++ trunk/tests/test_extract_data.py (.../test_extract_data.py) (revision 116) @@ -10,11 +10,79 @@ from SDToolBox.input_data import InputData from SDToolBox.extract_data import ExtractData import SDToolBox.output_messages as om +import numpy as np class Test_get_era5: @pytest.mark.systemtest + def test_extract_non_gridded_then_gridded(self): + self.test_extract_nongridded_data() + self.test_extract_gridded_data() + + @pytest.mark.systemtest + def test_extract_nongridded_data(self): + acceptance_folder = TestUtils.get_local_test_data_dir('acceptance_tests\\data') + DS = Dataset(os.path.join(acceptance_folder, 'NS_WAM_ERA5.nc')) + assert DS + lonWAM = DS.variables['lon'][:] + latWAM = DS.variables['lat'][:] + + coordsWAM = {'LON': [], 'LAT': []} + for i, j in zip(lonWAM, latWAM): + coordsWAM['LON'].append(i) + coordsWAM['LAT'].append(j) + + # set other data variables + variables = [] # saved names of the entries + for i in DS.variables: + print(i, DS.variables[i].shape) + variables.append(i) + varWAM = [v.lower() for v in variables[5:]] + timeWAMy = [1981] # 1987 to 2018 + + # use the SDToolBox function to create input data + Input_DataWAM = InputData( + input_coordinates=coordsWAM, + input_variables=varWAM, + input_scenarios=['era5'], + input_years=timeWAMy) # default is_gridded is false, referring to points + + # use the SDToolBox function to extract data + # dir_test_data = 'P:\\metocean-data\\open\\ERA5\\data\\Global' + dir_test_data = TestUtils.get_local_test_data_dir('era5_test_data') + extracted_data = ExtractData.get_era_5(dir_test_data, Input_DataWAM) + assert extracted_data is not None + + + @pytest.mark.systemtest + def test_extract_gridded_data(self): + steplon = 0.5 # degrees + lonl = -5 # left lon value + lonr = 11 # right lon value + steplat = 0.5 + latl = 50 # lower lat value + latu = 62 # upper lat value + xrang = np.arange(lonl, lonr+steplon, steplon).tolist() + yrang = np.arange(latl, latu+steplat, steplat).tolist() + + coordsBOX = {'LON': xrang, 'LAT': yrang} + timeWAMy = [1981] # 1987 to 2018 + # use the SDToolBox function to create input data + Input_DataBOX = InputData( + input_coordinates=coordsBOX, + input_variables=['msl'], + input_scenarios=['era5'], + input_years=timeWAMy, + is_gridded = True) + # dir_test_data = 'P:\\metocean-data\\open\\ERA5\\data\\Global' + dir_test_data = TestUtils.get_local_test_data_dir('era5_test_data') + extracted_data = ExtractData.get_era_5(dir_test_data, Input_DataBOX) + + assert extracted_data is not None + + + @pytest.mark.systemtest def test_given_list_of_coordinates_then_subset_is_extracted(self): # 1. Given # When using local data you can just replace the comment in these lines