예제 #1
0
 def test_invalid_data_id(self):
     store = CDSDataStore(cds_api_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     with self.assertRaises(ValueError):
         store.open_data('this-data-id-does-not-exist',
                         variable_names=['2m_temperature'],
                         hours=[0],
                         months=[1],
                         years=[2019])
예제 #2
0
 def test_request_parameter_out_of_range(self):
     store = CDSDataStore(cds_api_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     with self.assertRaises(ValidationError):
         store.open_data('reanalysis-era5-single-levels:ensemble_mean',
                         variable_names=['2m_temperature'],
                         bbox=[-1, -1, 181, 1],
                         spatial_res=0.25,
                         time_period='1M',
                         time_range=['2019-01-01', '2020-12-31'])
예제 #3
0
 def test_soil_moisture_empty_variables_list(self):
     store = CDSDataStore(endpoint_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     dataset = store.open_data('satellite-soil-moisture:volumetric:10-day',
                               variable_names=[],
                               time_range=['1981-06-14', '1982-02-13'])
     self.assertEqual(len(dataset.data_vars), 0)
     self.assertEqual(26, len(dataset.variables['time']))
     self.assertEqual(1441, len(dataset.variables['lon']))
예제 #4
0
 def test_copy_on_open(self):
     store = CDSDataStore(client_class=CDSClientMock,
                          endpoint_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     data_id = 'satellite-soil-moisture:volumetric:monthly'
     with tempfile.TemporaryDirectory() as temp_dir:
         request_path = os.path.join(temp_dir, 'request.json')
         result_path = os.path.join(temp_dir, 'result')
         zarr_path = os.path.join(temp_dir, 'result.zarr')
         store.open_data(
             data_id,
             _save_request_to=request_path,
             _save_file_to=result_path,
             _save_zarr_to=zarr_path,
             variable_names=['volumetric_surface_soil_moisture'],
             time_range=['2015-01-01', '2015-02-28'],
         )
         self.assertTrue(os.path.isfile(request_path))
         self.assertTrue(os.path.isfile(result_path))
         self.assertTrue(os.path.isdir(zarr_path))
예제 #5
0
 def test_open_data_empty_variables_list_2(self):
     store = CDSDataStore(cds_api_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     dataset = store.open_data('satellite-soil-moisture:volumetric:10-day',
                               variable_names=[],
                               bbox=[-180, -90, 180, 90],
                               spatial_res=0.25,
                               time_period='10D',
                               time_range=['1981-06-14', '1982-02-13'])
     self.assertEqual(len(dataset.data_vars), 0)
     self.assertEqual(26, len(dataset.variables['time']))
     self.assertEqual(1441, len(dataset.variables['lon']))
예제 #6
0
 def test_open_data_empty_variables_list_1(self):
     store = CDSDataStore(cds_api_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     dataset = store.open_data(
         'reanalysis-era5-land-monthly-means:monthly_averaged_reanalysis',
         variable_names=[],
         bbox=[-45, 0, 45, 60],
         spatial_res=0.25,
         time_period='1M',
         time_range=['2015-01-01', '2016-12-31'])
     self.assertEqual(len(dataset.data_vars), 0)
     self.assertEqual(24, len(dataset.variables['time']))
     self.assertEqual(361, len(dataset.variables['lon']))
예제 #7
0
 def test_open_data_null_variables_list(self):
     store = CDSDataStore(client_class=CDSClientMock,
                          cds_api_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     data_id = 'reanalysis-era5-single-levels-monthly-means:'\
         'monthly_averaged_reanalysis'
     schema = store.get_open_data_params_schema(data_id)
     n_vars = len(schema.properties['variable_names'].items.enum)
     dataset = store.open_data(data_id,
                               variable_names=None,
                               bbox=[-1, -1, 1, 1],
                               spatial_res=0.25,
                               time_period='1M',
                               time_range=['2015-10-15', '2015-10-15'])
     self.assertEqual(n_vars, len(dataset.data_vars))
예제 #8
0
 def test_era5_land_hourly(self):
     store = CDSDataStore(client_class=CDSClientMock,
                          cds_api_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     dataset = store.open_data(
         'reanalysis-era5-land',
         variable_names=['2m_temperature'],
         bbox=[9.5, 49.5, 10.5, 50.5],
         spatial_res=0.1,
         time_period='1H',
         time_range=['2015-01-01', '2015-01-02'],
     )
     self.assertIsNotNone(dataset)
     self.assertTrue('t2m' in dataset.variables)
     self.assertEqual(48, len(dataset.variables['time']))
예제 #9
0
 def test_era5_land_monthly(self):
     store = CDSDataStore(client_class=CDSClientMock,
                          endpoint_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     dataset = store.open_data(
         'reanalysis-era5-land-monthly-means:'
         'monthly_averaged_reanalysis',
         variable_names=['2m_temperature', '10m_u_component_of_wind'],
         bbox=[9.5, 49.5, 10.5, 50.5],
         spatial_res=0.1,
         time_range=['2015-01-01', '2016-12-31'],
     )
     self.assertIsNotNone(dataset)
     self.assertTrue('t2m' in dataset.variables)
     self.assertTrue('u10' in dataset.variables)
예제 #10
0
 def test_normalize_variable_names(self):
     store = CDSDataStore(client_class=CDSClientMock, normalize_names=True,
                          endpoint_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     dataset = store.open_data(
         'reanalysis-era5-single-levels-monthly-means:'
         'monthly_averaged_reanalysis',
         # Should be returned as p54.162, and normalized to p54_162.
         variable_names=['vertical_integral_of_temperature'],
         bbox=[-2, -2, 2, 2],
         spatial_res=1.0,
         time_range=['2019-01-01', '2020-12-31'],
     )
     self.assertIsNotNone(dataset)
     self.assertTrue('p54_162' in dataset.variables)
예제 #11
0
 def test_era5_single_levels_hourly(self):
     store = CDSDataStore(client_class=CDSClientMock,
                          endpoint_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     dataset = store.open_data(
         'reanalysis-era5-single-levels:'
         'reanalysis',
         variable_names=['2m_temperature'],
         bbox=[9, 49, 11, 51],
         spatial_res=0.25,
         time_range=['2015-01-01',
                     '2015-01-02'],
     )
     self.assertIsNotNone(dataset)
     self.assertTrue('t2m' in dataset.variables)
     self.assertEqual(48, len(dataset.variables['time']))
예제 #12
0
 def test_soil_moisture_volumetric_minimal_params(self):
     store = CDSDataStore(client_class=CDSClientMock,
                          endpoint_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     data_id = 'satellite-soil-moisture:volumetric:monthly'
     dataset = store.open_data(
         data_id,
         time_range=['2015-01-01', '2015-02-28'],
     )
     self.assertTrue('sm' in dataset.variables)
     self.assertEqual(2, len(dataset.variables['time']))
     self.assertEqual('2014-12-31T12:00:00Z',
                      dataset.attrs['time_coverage_start'])
     self.assertEqual('2015-02-28T12:00:00Z',
                      dataset.attrs['time_coverage_end'])
     description = store.describe_data(data_id)
     self.assertCountEqual(description.data_vars.keys(),
                           map(str, dataset.data_vars))
예제 #13
0
 def test_soil_moisture_without_optional_parameters(self):
     store = CDSDataStore(client_class=CDSClientMock,
                          cds_api_url=_CDS_API_URL,
                          cds_api_key=_CDS_API_KEY)
     data_id = 'satellite-soil-moisture:volumetric:monthly'
     dataset = store.open_data(
         data_id,
         variable_names=['volumetric_surface_soil_moisture'],
         time_range=['2015-01-01', '2015-02-28'],
     )
     self.assertTrue('sm' in dataset.variables)
     self.assertEqual(2, len(dataset.variables['time']))
     self.assertEqual('2014-12-31T12:00:00Z',
                      dataset.attrs['time_coverage_start'])
     self.assertEqual('2015-02-28T12:00:00Z',
                      dataset.attrs['time_coverage_end'])
     description = store.describe_data(data_id)
     self.assertEqual(sorted([dv.name for dv in description.data_vars]),
                      sorted(map(str, dataset.data_vars)))
예제 #14
0
    def test_soil_moisture_saturation_10_day(self):
        store = CDSDataStore(client_class=CDSClientMock,
                             endpoint_url=_CDS_API_URL,
                             cds_api_key=_CDS_API_KEY)

        data_id = 'satellite-soil-moisture:saturation:10-day'
        dataset = store.open_data(
            data_id,
            time_range=['2015-04-01', '2015-04-11'],
        )
        self.assertTrue('sm' in dataset.variables)
        self.assertEqual(2, len(dataset.variables['time']))
        self.assertEqual('2015-03-31T12:00:00Z',
                         dataset.attrs['time_coverage_start'])
        self.assertEqual('2015-04-20T12:00:00Z',
                         dataset.attrs['time_coverage_end'])
        description = store.describe_data(data_id)
        self.assertCountEqual(description.data_vars.keys(),
                              map(str, dataset.data_vars))