Index: trunk/SDToolBox/data_acquisition.py =================================================================== diff -u -r32 -r34 --- trunk/SDToolBox/data_acquisition.py (.../data_acquisition.py) (revision 32) +++ trunk/SDToolBox/data_acquisition.py (.../data_acquisition.py) (revision 34) @@ -185,6 +185,11 @@ def get_output_netcdf(self): return self.__output_netcdf + def generate_xarray_from_data_dict(self): + xr_data_array = xr.Dataset.from_dict(self.__data_dict) + self.__output_xarray = xr_data_array + return self.__output_xarray + def generate_xarray_from_netcdf(self, netcdf: Dataset): """Generates an xarray and sets a new dataset @@ -325,12 +330,6 @@ Arguments: netcdf {Dataset} -- Extracted dataset. """ - netcdf.createDimension( - self.dim_station_key, - self.__get_station_number()) - netcdf.createDimension( - self.dim_time_key, - self.__get_time_samples()) self.__set_time_and_stations(netcdf) self.__set_geo_data(netcdf) @@ -344,13 +343,22 @@ Returns: netCDF4.Dataset -- Output netCDF4 dataset. """ + # Create dimensions + netcdf.createDimension( + self.dim_station_key, + self.__get_station_number()) + netcdf.createDimension( + self.dim_time_key, + self.__get_time_samples()) + # Stations and Time station_variable = netcdf.createVariable( self.var_station_key, 'u2', (self.dim_station_key,), zlib=True, complevel=5, shuffle=True) station_variable.long_name = 'station name' station_variable.cf_role = 'timeseries_id' + # TODO: not able to set correctly the dimensions. # station_variable[:] = df.columns.levels[1].values + 1 time_variable = netcdf.createVariable( @@ -379,9 +387,9 @@ # there are more than 65536 hours of data, # so it should still be stored as an u4 # resolution of one second - netcdf.variables[self.var_time_key].scale_factor = 1 + time_variable.scale_factor = 1 # NO scaling when scale_factor is already applied - netcdf.variables[self.var_time_key][:] = [ + time_variable[:] = [ time.total_seconds() for time in time_delta_from_origin] Index: trunk/SDToolBox/extract_waves.py =================================================================== diff -u -r31 -r34 --- trunk/SDToolBox/extract_waves.py (.../extract_waves.py) (revision 31) +++ trunk/SDToolBox/extract_waves.py (.../extract_waves.py) (revision 34) @@ -85,7 +85,6 @@ for n_variable, variable_name in enumerate(variable_dict): case_name_value = variable_dict[variable_name] - cases_dict[self.__out_val_key][variable_name] for year in years: print(year, '-', variable_name) base_file_name = 'era5_Global_' + \ Index: trunk/tests/test_output_data.py =================================================================== diff -u -r32 -r34 --- trunk/tests/test_output_data.py (.../test_output_data.py) (revision 32) +++ trunk/tests/test_output_data.py (.../test_output_data.py) (revision 34) @@ -89,7 +89,7 @@ class Test_get_output_xarray: @pytest.mark.systemtest - def test_when_get_xarray_from_netcdf_does_not_raise(self): + def test_when_get_xarray_from_data_dict_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('netCDF_Waves_data') @@ -104,23 +104,16 @@ output_data = extract_wave.subset_era_5(dir_test_data, 1981, 1982) try: - netcdf = output_data.generate_wave_netcdf( - dir_path=output_test_data, - base_name='test_wave', - dataset_code=None, - file_format='CF' - ) - xarray = output_data.generate_xarray_from_netcdf(None) + xarray = output_data.generate_xarray_from_data_dict() except Exception as e_info: pytest.fail( 'Exception thrown but not expected. {}'.format(str(e_info))) # 3. Then - assert netcdf is not None assert xarray is not None @pytest.mark.systemtest - def test_when_get_output_xarray_generates_netcdf_and_xarray(self): + def test_when_get_xarray_from_netcdf_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('netCDF_Waves_data') @@ -135,16 +128,21 @@ output_data = extract_wave.subset_era_5(dir_test_data, 1981, 1982) try: - xarray = xr.Dataset(output_data.get_data_dict()) netcdf = output_data.generate_wave_netcdf( dir_path=output_test_data, base_name='test_wave', dataset_code=None, file_format='CF' ) + xarray = output_data.generate_xarray_from_netcdf(None) except Exception as e_info: pytest.fail( 'Exception thrown but not expected. {}'.format(str(e_info))) # 3. Then - assert netcdf is not None \ No newline at end of file + assert netcdf is not None + assert xarray is not None + + @pytest.mark.systemtest + def test_when_get_output_xarray_generates_netcdf_and_xarray(self): + pass \ No newline at end of file