Index: trunk/SDToolBox/input_data.py =================================================================== diff -u -r69 -r70 --- trunk/SDToolBox/input_data.py (.../input_data.py) (revision 69) +++ trunk/SDToolBox/input_data.py (.../input_data.py) (revision 70) @@ -42,7 +42,8 @@ self, input_coordinates: List[Tuple[float, float]] = [], input_variables: List[str] = [], - input_years: List[int] = []): + input_years: List[int] = [], + is_gridded: bool = False): """Constructor of InputData data structure that can be used by the extract subset methods. @@ -53,10 +54,13 @@ -- List of variables to extract. (default: {[]}) input_years {List[int]} -- List of years as integers. (default: {[]}) + is_gridded {bool} + -- Coordinates represent a grid. (default: {False}) """ self.input_coordinates = input_coordinates self.input_variables = input_variables self.input_years = input_years + self.is_gridded = is_gridded def validate(self): """Validates the data structure based on the given input Index: trunk/tests/test_data_processing.py =================================================================== diff -u -r67 -r70 --- trunk/tests/test_data_processing.py (.../test_data_processing.py) (revision 67) +++ trunk/tests/test_data_processing.py (.../test_data_processing.py) (revision 70) @@ -33,7 +33,7 @@ dims='time') -class Test_FeatureResampling: +class Test_TimeResampling: @pytest.mark.unittest @pytest.mark.parametrize( @@ -57,7 +57,7 @@ frequency_string = None if set_dataset: - dataset = self.get_default_xarray_dataset() + dataset = get_default_xarray_dataset() if set_scale: scale = 2 if set_freq_str: @@ -68,7 +68,7 @@ # 2. When with pytest.raises(Exception) as e_info: - resampled_data = DataProcessing.feature_resampling( + resampled_data = DataProcessing.time_resampling( dataset=dataset, scale=scale, frequency_string=frequency_string @@ -80,14 +80,14 @@ @pytest.mark.unittest def test_when_arguments_given_then_no_exception_risen(self): - dataset = self.get_default_xarray_dataset() + dataset = get_default_xarray_dataset() scale = 1 frequency_string = 'D' resampled_dataset = None # 2. When try: - resampled_data = DataProcessing.feature_resampling( + resampled_data = DataProcessing.time_resampling( dataset=dataset, scale=scale, frequency_string=frequency_string @@ -152,42 +152,34 @@ assert len(resampled_data['time'][:]) > len(resampled_data['time'][:]) -class Test_OutputFeatureResampling: +class Test_SpatialResampling: @pytest.mark.unittest - def test_when_no_output_data_then_exception_risen(self): + def test_when_arguments_given_mean_resample_done(self): # 1. Given - output_data = None - expected_message = om.error_no_dataset_in_output_data - + dir_test_data = TestUtils.get_local_test_data_dir('system_tests_nc') + test_nc_file = os.path.join(dir_test_data, 'dummy_wave_multiple_file.nc') + assert os.path.exists(test_nc_file), '' + \ + 'Test file not found at {}'.format(test_nc_file) + dataset = xr.open_dataset(test_nc_file) + resampled_data = None # 2. When - with pytest.raises(Exception) as e_info: - DataProcessing.output_feature_resampling( - output_data=output_data, - scale=None, - frequency_string=None) + try: + resampled_data = DataProcessing.spatial_resampling( + dataset=dataset, + resolution=2 + ) + except Exception as e_info: + pytest.fail( + 'Exception thrown but not expected:' + + '{}'.format(str(e_info)) + ) # 3. Then - assert str(e_info.value) == expected_message + assert resampled_data is not None + assert len(resampled_data['time'][:]) > len(resampled_data['time'][:]) - @pytest.mark.unittest - def test_when_no_output_xarray_then_exception_risen(self): - # 1. Given - output_data = OutputData(None) - expected_message = om.error_no_dataset_in_output_data - assert output_data.get_xarray() is None - # 2. When - with pytest.raises(Exception) as e_info: - DataProcessing.output_feature_resampling( - output_data=output_data, - scale=None, - frequency_string=None) - - # 3. Then - assert str(e_info.value) == expected_message - - class TestSpatialGradientsCalculation: @pytest.mark.unittest Index: trunk/tests/test_output_data.py =================================================================== diff -u -r59 -r70 --- trunk/tests/test_output_data.py (.../test_output_data.py) (revision 59) +++ trunk/tests/test_output_data.py (.../test_output_data.py) (revision 70) @@ -155,19 +155,32 @@ os.remove(output_netcdf_filepath) + @pytest.mark.unittest + def test_dummy(self): + x = [4.2, 42, 42, 4.2] + y = [2.4, 2.4, 24, 24] + res = np.meshgrid(x, y, sparse=False, indexing='xy') + assert res is not None + @pytest.mark.systemtest def test_when_given_all_arguments_does_not_raise(self): # 1. Given # When using local data you can just replace the comment in these lines - # dir_test_data = \ - # TestUtils.get_local_test_data_dir('era5_test_data') - dir_test_data = 'P:\\metocean-data\\open\\ERA5\\data\\Global' + dir_test_data = \ + TestUtils.get_local_test_data_dir('era5_test_data') + # dir_test_data = 'P:\\metocean-data\\open\\ERA5\\data\\Global' output_test_data = TestUtils.get_local_test_data_dir('output_data') input_data = InputData() input_data.input_variables = ['swh'] - input_data.input_coordinates = [(4.2, 2.4), ] input_data.input_years = [1981, 1982] + input_data.input_coordinates = [ + (4.2, 2.6), + # (2.4, 2.4), + # (42, 24), + # (4.2, 2.4) + ] + input_data.is_gridded = False # 2. When try: Index: trunk/tests/test_data/system_tests_nc/dummy_wave_multiple_file.nc =================================================================== diff -u Binary files differ