Exemplo n.º 1
0
    def test_client_url_and_key_parameters(self):
        """Test passing URL and key parameters to client constructor

        This test verifies that the CDS API URL and key, when specified as
        parameters to CDSDataOpener, are correctly passed to the CDS client,
        overriding any configuration file or environment variable settings.
        """

        self._set_up_api_configuration('wrong URL 1', 'wrong key 1',
                                       'wrong URL 2', 'wrong key 2')
        cds_api_url = 'https://example.com/'
        cds_api_key = 'xyzzy'
        opener = CDSDataOpener(client_class=CDSClientMock,
                               cds_api_url=cds_api_url,
                               cds_api_key=cds_api_key)
        opener.open_data(
            'reanalysis-era5-single-levels-monthly-means:'
            'monthly_averaged_reanalysis',
            variable_names=['2m_temperature'],
            bbox=[-180, -90, 180, 90],
            spatial_res=0.25,
            time_period='1M',
            time_range=['2015-10-15', '2015-10-15'],
        )
        client = opener.last_instantiated_client
        self.assertEqual(cds_api_url, client.url)
        self.assertEqual(cds_api_key, client.key)
Exemplo n.º 2
0
    def test_get_open_params_schema_without_data_id(self):
        opener = CDSDataOpener(cds_api_url=_CDS_API_URL,
                               cds_api_key=_CDS_API_KEY)
        schema = opener.get_open_data_params_schema()

        actual = schema.to_dict()
        self.assertCountEqual(['type', 'properties', 'required'],
                              actual.keys())
        self.assertEqual('object', actual['type'])
        self.assertCountEqual(
            ['bbox', 'spatial_res', 'variable_names', 'time_range'],
            actual['required'])
        self.assertCountEqual([
            'dataset_name', 'variable_names', 'crs', 'bbox', 'spatial_res',
            'time_range', 'time_period'
        ], actual['properties'].keys())
Exemplo n.º 3
0
    def _get_client(**opener_args):
        """Return the client instantiated to open a dataset

        Open a dataset and return the client that was instantiated to execute
        the CDS API query.
        """
        opener = CDSDataOpener(client_class=CDSClientMock, **opener_args)
        opener.open_data(
            'reanalysis-era5-single-levels-monthly-means:'
            'monthly_averaged_reanalysis',
            variable_names=['2m_temperature'],
            bbox=[-180, -90, 180, 90],
            spatial_res=0.25,
            time_period='1M',
            time_range=['2015-10-15', '2015-10-15'],
        )
        return opener.last_instantiated_client
Exemplo n.º 4
0
 def test_open(self):
     opener = CDSDataOpener(client_class=CDSClientMock,
                            endpoint_url=_CDS_API_URL,
                            cds_api_key=_CDS_API_KEY)
     dataset = opener.open_data(
         'reanalysis-era5-single-levels-monthly-means:'
         'monthly_averaged_reanalysis',
         variable_names=['2m_temperature'],
         bbox=[-1, -1, 1, 1],
         spatial_res=0.25,
         time_range=['2015-10-15', '2016-02-02'],
     )
     self.assertIsNotNone(dataset)
     # We expect the closest representable time selection corresponding
     # to the requested range: months 10-12 and 1-2 for years 2015 and 2016,
     # thus (3 + 2) * 2 = 10 time-points in total.
     self.assertEqual(10, len(dataset.variables['time']))
Exemplo n.º 5
0
    def test_era5_bounds(self):
        opener = CDSDataOpener(client_class=CDSClientMock,
                               endpoint_url=_CDS_API_URL,
                               cds_api_key=_CDS_API_KEY)
        dataset = opener.open_data(
            'reanalysis-era5-single-levels-monthly-means:'
            'monthly_averaged_reanalysis',
            variable_names=['2m_temperature'],
            bbox=[-180, -90, 180, 90],
            spatial_res=0.25,
            time_range=['2015-10-15', '2015-10-15'],
        )

        self.assertIsNotNone(dataset)

        west, south, east, north = xcube.core.geom.get_dataset_bounds(dataset)
        self.assertGreaterEqual(west, -180.0)
        self.assertGreaterEqual(south, -90.0)
        self.assertLessEqual(east, 180.0)
        self.assertLessEqual(north, 90.0)
        self.assertNotEqual(west, east)
        self.assertLessEqual(south, north)