Exemple #1
0
 def _get_open_data_params_schema(
         dsd: DatasetDescriptor = None) -> JsonObjectSchema:
     min_date = dsd.time_range[0] if dsd and dsd.time_range else None
     max_date = dsd.time_range[1] if dsd and dsd.time_range else None
     # noinspection PyUnresolvedReferences
     cube_params = dict(
         variable_names=JsonArraySchema(items=JsonStringSchema(
             enum=dsd.data_vars.keys() if dsd and dsd.data_vars else None)),
         time_range=JsonDateSchema.new_range(min_date, max_date))
     if dsd and (('lat' in dsd.dims and 'lon' in dsd.dims) or
                 ('latitude' in dsd.dims and 'longitude' in dsd.dims)):
         min_lon = dsd.bbox[0] if dsd and dsd.bbox else -180
         min_lat = dsd.bbox[1] if dsd and dsd.bbox else -90
         max_lon = dsd.bbox[2] if dsd and dsd.bbox else 180
         max_lat = dsd.bbox[3] if dsd and dsd.bbox else 90
         bbox = JsonArraySchema(
             items=(JsonNumberSchema(minimum=min_lon, maximum=max_lon),
                    JsonNumberSchema(minimum=min_lat, maximum=max_lat),
                    JsonNumberSchema(minimum=min_lon, maximum=max_lon),
                    JsonNumberSchema(minimum=min_lat, maximum=max_lat)))
         cube_params['bbox'] = bbox
     cci_schema = JsonObjectSchema(properties=dict(**cube_params),
                                   required=[],
                                   additional_properties=False)
     return cci_schema
Exemple #2
0
 def test_to_dict(self):
     self.assertEqual({'type': 'number'}, JsonNumberSchema().to_dict())
     self.assertEqual({'type': 'number'},
                      JsonNumberSchema(nullable=False).to_dict())
     self.assertEqual({'type': ['number', 'null']},
                      JsonNumberSchema(nullable=True).to_dict())
     self.assertEqual(
         {
             'type': 'number',
             'exclusiveMinimum': 0,
             'maximum': 100,
             'multipleOf': 10
         },
         JsonNumberSchema(exclusive_minimum=0, maximum=100,
                          multiple_of=10).to_dict())
     self.assertEqual(
         {
             'type': 'integer',
             'minimum': 100,
             'exclusiveMaximum': 200,
             'multipleOf': 20
         },
         JsonIntegerSchema(minimum=100,
                           exclusive_maximum=200,
                           multiple_of=20).to_dict())
Exemple #3
0
 def _get_default_open_params_schema(self) -> JsonObjectSchema:
     params = dict(
         dataset_name=JsonStringSchema(min_length=1,
                                       enum=list(
                                           self._handler_registry.keys())),
         variable_names=JsonArraySchema(
             items=(JsonStringSchema(min_length=0)), unique_items=True),
         crs=JsonStringSchema(),
         # W, S, E, N
         bbox=JsonArraySchema(
             items=(JsonNumberSchema(minimum=-180, maximum=180),
                    JsonNumberSchema(minimum=-90, maximum=90),
                    JsonNumberSchema(minimum=-180, maximum=180),
                    JsonNumberSchema(minimum=-90, maximum=90))),
         spatial_res=JsonNumberSchema(),
         time_range=JsonDateSchema.new_range(),
         time_period=JsonStringSchema(),
     )
     required = [
         'variable_names',
         'bbox',
         'spatial_res',
         'time_range',
     ]
     return JsonObjectSchema(properties=params, required=required)
Exemple #4
0
 def get_search_params_schema(cls,
                              type_specifier: str = None
                              ) -> JsonObjectSchema:
     cls._assert_valid_type_specifier(type_specifier)
     data_ids = CciOdp().dataset_names
     ecvs = set([data_id.split('.')[1] for data_id in data_ids])
     frequencies = set([
         data_id.split('.')[2].replace('-days', ' days').replace(
             'mon', 'month').replace('-yrs',
                                     ' years').replace('yr', 'year')
         for data_id in data_ids
     ])
     processing_levels = set(
         [data_id.split('.')[3] for data_id in data_ids])
     data_types = set([data_id.split('.')[4] for data_id in data_ids])
     sensors = set([data_id.split('.')[5] for data_id in data_ids])
     platforms = set([data_id.split('.')[6] for data_id in data_ids])
     product_strings = set([data_id.split('.')[7] for data_id in data_ids])
     product_versions = set([data_id.split('.')[8] for data_id in data_ids])
     search_params = dict(
         start_date=JsonStringSchema(format='date-time'),
         end_date=JsonStringSchema(format='date-time'),
         bbox=JsonArraySchema(items=(JsonNumberSchema(), JsonNumberSchema(),
                                     JsonNumberSchema(),
                                     JsonNumberSchema())),
         ecv=JsonStringSchema(enum=ecvs),
         frequency=JsonStringSchema(enum=frequencies),
         institute=JsonStringSchema(enum=[
             'Plymouth Marine Laboratory',
             'Alfred-Wegener-Institut Helmholtz-Zentrum für Polar- und Meeresforschung',
             'ENVironmental Earth Observation IT GmbH', 'multi-institution',
             'DTU Space', 'Vienna University of Technology',
             'Deutscher Wetterdienst',
             'Netherlands Institute for Space Research',
             'Technische Universität Dresden',
             'Institute of Environmental Physics',
             'Rutherford Appleton Laboratory',
             'Universite Catholique de Louvain', 'University of Alcala',
             'University of Leicester',
             'Norwegian Meteorological Institute', 'University of Bremen',
             'Belgian Institute for Space Aeronomy',
             'Deutsches Zentrum fuer Luft- und Raumfahrt',
             'Freie Universitaet Berlin',
             'Royal Netherlands Meteorological Institute',
             'The Geological Survey of Denmark and Greenland'
         ]),
         processing_level=JsonStringSchema(enum=processing_levels),
         product_string=JsonStringSchema(enum=product_strings),
         product_version=JsonStringSchema(enum=product_versions),
         data_type=JsonStringSchema(enum=data_types),
         sensor=JsonStringSchema(enum=sensors),
         platform=JsonStringSchema(enum=platforms))
     search_schema = JsonObjectSchema(properties=dict(**search_params),
                                      additional_properties=False)
     return search_schema
Exemple #5
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         required=[
             'ColorBar',
             'ValueRange',
         ],
         properties=dict(ColorBar=JsonStringSchema(min_length=1),
                         ValueRange=JsonArraySchema(
                             items=[JsonNumberSchema(),
                                    JsonNumberSchema()])),
         additional_properties=False,
     )
Exemple #6
0
    def get_open_data_params_schema(self, data_id: Optional[str] = None) -> \
            JsonObjectSchema:
        # If the data_id has a product type suffix, remove it.
        dataset_id = data_id.split(':')[0] if ':' in data_id else data_id

        ds_info = self._dataset_dicts[dataset_id]
        variable_info_table = ds_info['variables']
        bbox = ds_info['bbox']

        params = dict(
            variable_names=JsonArraySchema(
                items=(JsonStringSchema(
                    min_length=0,
                    enum=[
                        cds_api_name
                        for cds_api_name, _, _, _ in variable_info_table
                    ])),
                unique_items=True,
                nullable=True,
                description='identifiers of the requested variables'),
            # crs omitted, since it's constant.
            # W, S, E, N (will be converted to N, W, S, E)
            bbox=JsonArraySchema(
                items=(JsonNumberSchema(minimum=bbox[0], maximum=bbox[2]),
                       JsonNumberSchema(minimum=bbox[1],
                                        maximum=bbox[3]),
                       JsonNumberSchema(minimum=bbox[0],
                                        maximum=bbox[2]),
                       JsonNumberSchema(minimum=bbox[1],
                                        maximum=bbox[3])),
                description='bounding box (min_x, min_y, max_x, max_y)'),
            # spatial_res in the ds_info dictionary gives the minimum
            # resolution, but the ERA5 backend can resample, so we
            # also set a maximum. The choice of 10° as maximum is fairly
            # arbitrary but seems reasonable.
            spatial_res=JsonNumberSchema(minimum=ds_info['spatial_res'],
                                         maximum=10,
                                         default=ds_info['spatial_res'],
                                         description='spatial resolution'),
            time_range=JsonDateSchema.new_range(),
            # time_period (time aggregation period) omitted, since it is
            # constant.
        )
        required = [
            'variable_names',
            'bbox',
            'spatial_res',
            'time_range',
        ]
        return JsonObjectSchema(properties=params,
                                required=required,
                                additional_properties=False)
Exemple #7
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(
             progress=JsonNumberSchema(minimum=0.0),
             # worked=JsonNumberSchema(minimum=0),
             total_work=JsonNumberSchema(exclusive_minimum=0)),
         required=[
             'progress',
             # 'worked',
             'total_work',
         ],
         additional_properties=True,
         factory=cls)
    def get_open_data_params_schema(self, data_id: Optional[str] = None) -> \
            JsonObjectSchema:
        # If the data_id has a product type suffix, remove it.
        dataset_id = data_id.split(':')[0] if ':' in data_id else data_id

        ds_info = self._dataset_dicts[dataset_id]
        variable_info_table = ds_info['variables']
        bbox = ds_info['bbox']

        params = dict(
            dataset_name=JsonStringSchema(
                min_length=1,
                enum=list(self._valid_data_ids),
                description='identifier of the requested dataset'),
            variable_names=JsonArraySchema(
                items=(JsonStringSchema(
                    min_length=0,
                    enum=[
                        cds_api_name
                        for cds_api_name, _, _, _ in variable_info_table
                    ])),
                unique_items=True,
                nullable=True,
                description='identifiers of the requested variables'),
            crs=JsonStringSchema(nullable=True,
                                 default=ds_info['crs'],
                                 enum=[None, ds_info['crs']],
                                 description='co-ordinate reference system'),
            # W, S, E, N (will be converted to N, W, S, E)
            bbox=JsonArraySchema(
                items=(JsonNumberSchema(minimum=bbox[0], maximum=bbox[2]),
                       JsonNumberSchema(minimum=bbox[1], maximum=bbox[3]),
                       JsonNumberSchema(minimum=bbox[0], maximum=bbox[2]),
                       JsonNumberSchema(minimum=bbox[1], maximum=bbox[3])),
                description='bounding box (min_x, min_y, max_x, max_y)'),
            spatial_res=JsonNumberSchema(minimum=ds_info['spatial_res'],
                                         maximum=10,
                                         default=ds_info['spatial_res'],
                                         description='spatial resolution'),
            time_range=JsonDateSchema.new_range(),
            time_period=JsonStringSchema(
                const=ds_info['time_period'],
                description='time aggregation period'),
        )
        required = [
            'variable_names',
            'bbox',
            'spatial_res',
            'time_range',
        ]
        return JsonObjectSchema(properties=params, required=required)
Exemple #9
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         data_id=JsonStringSchema(min_length=1),
         data_type=DataType.get_schema(),
         crs=JsonStringSchema(min_length=1),
         bbox=JsonArraySchema(items=[
             JsonNumberSchema(),
             JsonNumberSchema(),
             JsonNumberSchema(),
             JsonNumberSchema()
         ]),
         time_range=JsonDateSchema.new_range(nullable=True),
         time_period=JsonStringSchema(min_length=1),
         open_params_schema=JsonObjectSchema(additional_properties=True),
     ),
                             required=['data_id', 'data_type'],
                             additional_properties=True,
                             factory=cls)
Exemple #10
0
 def get_schema(cls):
     return JsonObjectSchema(properties=dict(
         variable_names=JsonArraySchema(
             items=JsonStringSchema(min_length=1), min_items=0),
         crs=JsonStringSchema(nullable=True, min_length=1),
         bbox=JsonArraySchema(nullable=True,
                              items=[
                                  JsonNumberSchema(),
                                  JsonNumberSchema(),
                                  JsonNumberSchema(),
                                  JsonNumberSchema()
                              ]),
         spatial_res=JsonNumberSchema(nullable=True, exclusive_minimum=0.0),
         time_range=JsonDateSchema.new_range(nullable=True),
         time_period=JsonStringSchema(nullable=True,
                                      pattern=r'^([1-9][0-9]*)?[DWMY]$'),
     ),
                             required=['variable_names'],
                             additional_properties=False,
                             factory=cls)
Exemple #11
0
    def _get_open_data_params_schema(self,
                                     dsd: DatasetDescriptor = None
                                     ) -> JsonObjectSchema:
        min_date, max_date = dsd.time_range if dsd.time_range is not None else (
            None, None)

        cube_params = dict(
            dataset_name=JsonStringSchema(min_length=1),
            variable_names=JsonArraySchema(items=JsonStringSchema(
                enum=[v.name for v in dsd.
                      data_vars] if dsd and dsd.data_vars else None)),
            variable_units=JsonArraySchema(),
            variable_sample_types=JsonArraySchema(),
            tile_size=JsonArraySchema(
                items=(JsonNumberSchema(minimum=1,
                                        maximum=2500,
                                        default=DEFAULT_TILE_SIZE),
                       JsonNumberSchema(minimum=1,
                                        maximum=2500,
                                        default=DEFAULT_TILE_SIZE)),
                default=(DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE)),
            crs=JsonStringSchema(default=DEFAULT_CRS, enum=AVAILABLE_CRS_IDS),
            bbox=JsonArraySchema(items=(JsonNumberSchema(), JsonNumberSchema(),
                                        JsonNumberSchema(),
                                        JsonNumberSchema())),
            spatial_res=JsonNumberSchema(exclusive_minimum=0.0),
            time_range=JsonDateSchema.new_range(min_date=min_date,
                                                max_date=max_date),
            # TODO: add pattern
            time_period=JsonStringSchema(
                default='1D',
                nullable=True,
                enum=[None, *map(lambda n: f'{n}D', range(1, 14)), '1W',
                      '2W']),
            time_tolerance=JsonStringSchema(default=DEFAULT_TIME_TOLERANCE,
                                            format='^([1-9]*[0-9]*)[NULSTH]$'),
            collection_id=JsonStringSchema(),
            four_d=JsonBooleanSchema(default=False),
        )
        cache_params = dict(max_cache_size=JsonIntegerSchema(minimum=0), )
        # required cube_params
        required = [
            'bbox',
            'spatial_res',
            'time_range',
        ]
        sh_params = {}
        if self._sentinel_hub is None:
            # If we are NOT connected to the API (yet), we also include store parameters
            sh_schema = SentinelHubDataStore.get_data_store_params_schema()
            sh_params = sh_schema.properties
            required.extend(sh_schema.required or [])
        return JsonObjectSchema(properties=dict(**sh_params, **cube_params,
                                                **cache_params),
                                required=required)
Exemple #12
0
 def get_schema(cls):
     return JsonObjectSchema(properties=dict(
         variable_names=JsonArraySchema(
             nullable=True,
             items=JsonStringSchema(min_length=1),
             min_items=0),
         crs=JsonStringSchema(nullable=True, min_length=1),
         bbox=JsonArraySchema(nullable=True,
                              items=[
                                  JsonNumberSchema(),
                                  JsonNumberSchema(),
                                  JsonNumberSchema(),
                                  JsonNumberSchema()
                              ]),
         spatial_res=JsonNumberSchema(nullable=True, exclusive_minimum=0.0),
         tile_size=JsonArraySchema(nullable=True,
                                   items=[
                                       JsonIntegerSchema(minimum=1,
                                                         maximum=2500),
                                       JsonIntegerSchema(minimum=1,
                                                         maximum=2500),
                                   ]),
         time_range=JsonDateSchema.new_range(nullable=True),
         time_period=JsonStringSchema(nullable=True,
                                      pattern=r'^([1-9][0-9]*)?[DWMY]$'),
         chunks=JsonObjectSchema(nullable=True,
                                 additional_properties=JsonIntegerSchema(
                                     nullable=True, minimum=1)),
         metadata=JsonObjectSchema(nullable=True,
                                   additional_properties=True),
         variable_metadata=JsonObjectSchema(
             nullable=True,
             additional_properties=JsonObjectSchema(
                 additional_properties=True)),
     ),
                             additional_properties=False,
                             factory=cls)
Exemple #13
0
 def get_schema(cls) -> JsonObjectSchema:
     schema = super().get_schema()
     schema.properties.update(
         dims=JsonObjectSchema(additional_properties=JsonIntegerSchema(
             minimum=0)),
         spatial_res=JsonNumberSchema(exclusive_minimum=0.0),
         coords=JsonObjectSchema(
             additional_properties=VariableDescriptor.get_schema()),
         data_vars=JsonObjectSchema(
             additional_properties=VariableDescriptor.get_schema()),
         attrs=JsonObjectSchema(additional_properties=True),
     )
     schema.required = ['data_id', 'data_type']
     schema.additional_properties = False
     schema.factory = cls
     return schema
Exemple #14
0
 def get_data_store_params_schema(cls) -> JsonObjectSchema:
     cciodp_params = dict(
         endpoint_url=JsonStringSchema(default=OPENSEARCH_CEDA_URL),
         endpoint_description_url=JsonStringSchema(default=CCI_ODD_URL),
         enable_warnings=JsonBooleanSchema(
             default=False, title='Whether to output warnings'),
         num_retries=JsonIntegerSchema(
             default=DEFAULT_NUM_RETRIES,
             minimum=0,
             title='Number of retries when requesting data fails'),
         retry_backoff_max=JsonIntegerSchema(
             default=DEFAULT_RETRY_BACKOFF_MAX, minimum=0),
         retry_backoff_base=JsonNumberSchema(
             default=DEFAULT_RETRY_BACKOFF_BASE, exclusive_minimum=1.0),
         user_agent=JsonStringSchema(default=None))
     return JsonObjectSchema(properties=dict(**cciodp_params),
                             required=None,
                             additional_properties=False)
Exemple #15
0
    def test_process_kwargs_subset(self):
        schema = JsonObjectSchema(
            properties=dict(
                client_id=JsonStringSchema(default='bibo'),
                client_secret=JsonStringSchema(default='2w908435t'),
                geom=JsonStringSchema(),
                crs=JsonStringSchema(const='WGS84'),
                spatial_res=JsonNumberSchema(),
                time_range=JsonStringSchema(),
                time_period=JsonStringSchema(default='8D'),
                max_cache_size=JsonIntegerSchema(),
            ),
            required=[
                'client_id', 'client_secret', 'geom', 'crs', 'spatial_res',
                'time_range'
            ],
        )

        kwargs = dict(client_secret='094529g',
                      geom='POINT (12.2, 53.9)',
                      spatial_res=0.5,
                      time_range='2010,2014',
                      max_cache_size=2**32)

        cred_kwargs, kwargs = schema.process_kwargs_subset(
            kwargs, ['client_id', 'client_secret'])
        self.assertEqual(dict(client_id='bibo', client_secret='094529g'),
                         cred_kwargs)
        self.assertEqual(
            dict(geom='POINT (12.2, 53.9)',
                 spatial_res=0.5,
                 time_range='2010,2014',
                 max_cache_size=2**32), kwargs)

        ds_kwargs, kwargs = schema.process_kwargs_subset(
            kwargs,
            ['geom', 'crs', 'spatial_res', 'time_range', 'time_period'])
        self.assertEqual(
            dict(crs='WGS84',
                 geom='POINT (12.2, 53.9)',
                 spatial_res=0.5,
                 time_range='2010,2014'), ds_kwargs)
        self.assertEqual(dict(max_cache_size=2**32), kwargs)
Exemple #16
0
 def get_data_store_params_schema(cls) -> JsonObjectSchema:
     sh_params = dict(
         client_id=JsonStringSchema(
             title='SENTINEL Hub API client identifier',
             description=
             'Preferably set by environment variable SH_CLIENT_ID'),
         client_secret=JsonStringSchema(
             title='SENTINEL Hub API client secret',
             description=
             'Preferably set by environment variable SH_CLIENT_SECRET'),
         api_url=JsonStringSchema(default=DEFAULT_SH_API_URL,
                                  title='SENTINEL Hub API URL'),
         oauth2_url=JsonStringSchema(
             default=DEFAULT_SH_OAUTH2_URL,
             title='SENTINEL Hub API authorisation URL'),
         enable_warnings=JsonBooleanSchema(
             default=False, title='Whether to output warnings'),
         error_policy=JsonStringSchema(
             default='fail',
             enum=['fail', 'warn', 'ignore'],
             title='Policy for errors while requesting data'),
         num_retries=JsonIntegerSchema(
             default=DEFAULT_NUM_RETRIES,
             minimum=0,
             title='Number of retries when requesting data fails'),
         retry_backoff_max=JsonIntegerSchema(
             default=DEFAULT_RETRY_BACKOFF_MAX, minimum=0),
         retry_backoff_base=JsonNumberSchema(
             default=DEFAULT_RETRY_BACKOFF_BASE, exclusive_minimum=1.0),
     )
     required = None
     if not DEFAULT_CLIENT_ID or not DEFAULT_CLIENT_SECRET:
         required = []
         if DEFAULT_CLIENT_ID is None:
             required.append('client_id')
         if DEFAULT_CLIENT_SECRET is None:
             required.append('client_secret')
     return JsonObjectSchema(properties=sh_params,
                             required=required,
                             additional_properties=False)
Exemple #17
0
                             f' referring to a configured store')
        return store_pool.get_store_instance(store_instance_id)
    return DataStoreInstance(DataStoreConfig(store_id, store_params))


DATA_STORE_CONFIG_SCHEMA = JsonObjectSchema(
    properties=dict(
        store_id=JsonStringSchema(min_length=1),
        store_params=JsonObjectSchema(additional_properties=True),
        title=JsonStringSchema(min_length=1),
        description=JsonStringSchema(min_length=1),
        cost_params=JsonObjectSchema(
            properties=dict(
                input_pixels_per_punit=JsonIntegerSchema(minimum=1),
                output_pixels_per_punit=JsonIntegerSchema(minimum=1),
                input_punits_weight=JsonNumberSchema(exclusive_minimum=0.0,
                                                     default=1.0),
                output_punits_weight=JsonNumberSchema(exclusive_minimum=0.0,
                                                      default=1.0),
            ),
            additional_properties=False,
            required=['input_pixels_per_punit', 'output_pixels_per_punit'],
        )),
    required=['store_id'],
)

DATA_STORE_POOL_SCHEMA = JsonObjectSchema(
    additional_properties=DATA_STORE_CONFIG_SCHEMA, )


class DataStoreConfig:
    """
Exemple #18
0
from xcube.util.assertions import assert_instance
from xcube.util.jsonschema import JsonBooleanSchema
from xcube.util.jsonschema import JsonIntegerSchema
from xcube.util.jsonschema import JsonNumberSchema
from xcube.util.jsonschema import JsonObjectSchema
from ..accessor import DataOpener
from ..accessor import DataWriter
from ..datatype import DataType
from ..error import DataStoreError

COMMON_STORAGE_OPTIONS_SCHEMA_PROPERTIES = dict(
    # passed to ``DirCache``, if the implementation supports
    # directory listing caching. Pass use_listings_cache=False
    # to disable such caching.
    use_listings_cache=JsonBooleanSchema(),
    listings_expiry_time=JsonNumberSchema(),
    max_paths=JsonIntegerSchema(),
    # If this is a cachable implementation, pass True here to force
    # creating a new instance even if a matching instance exists, and prevent
    # storing this instance.
    skip_instance_cache=JsonBooleanSchema(),
    asynchronous=JsonBooleanSchema(),
)

PROTOCOL_PARAM_NAME = 'protocol'
STORAGE_OPTIONS_PARAM_NAME = 'storage_options'
FS_PARAM_NAME = 'fs'
ROOT_PARAM_NAME = 'root'


class FsAccessor:
Exemple #19
0
 def test_to_instance(self):
     self.assertEqual(
         0.6,
         JsonNumberSchema(exclusive_minimum=0,
                          exclusive_maximum=1).to_instance(0.6))
Exemple #20
0
from abc import ABC

from xcube.util.jsonschema import JsonArraySchema
from xcube.util.jsonschema import JsonBooleanSchema
from xcube.util.jsonschema import JsonNumberSchema
from xcube.util.jsonschema import JsonObject
from xcube.util.jsonschema import JsonObjectSchema
from xcube.util.jsonschema import JsonStringSchema

BooleanSchema = JsonBooleanSchema()
NumberSchema = JsonNumberSchema()
UrlSchema = JsonStringSchema(format='uri')
IdentifierSchema = JsonStringSchema(min_length=1)
ChunkSizeSchema = JsonStringSchema(min_length=2)  # TODO: use pattern
StringSchema = JsonStringSchema()
PathSchema = JsonStringSchema(min_length=1)
BoundingBoxSchema = JsonArraySchema(
    items=[NumberSchema, NumberSchema, NumberSchema, NumberSchema])
FileSystemSchema = JsonStringSchema(
    enum=['memory', 'obs', 'local', 's3', 'file'])


class _ConfigObject(JsonObject, ABC):
    def __init__(self, **kwargs):
        self._inject_attrs(kwargs)


class ServiceConfig(_ConfigObject):
    @classmethod
    def get_schema(cls) -> JsonObjectSchema:
        return JsonObjectSchema(
Exemple #21
0
 def test_from_instance(self):
     self.assertEqual(
         6,
         JsonNumberSchema(minimum=0, maximum=10,
                          multiple_of=2).from_instance(6))
Exemple #22
0
 def test_check_type(self):
     with self.assertRaises(ValueError) as cm:
         JsonNumberSchema(type='float')
     self.assertEqual('Type must be one of "integer", "number"',
                      f'{cm.exception}')
Exemple #23
0
 def get_open_data_params_schema(self, data_id: str) -> JsonObjectSchema:
     _, variable_spec, aggregation = data_id.split(':')
     variables = self._var_map[variable_spec][0]
     sensors = self._var_map[variable_spec][1]
     params = dict(
         dataset_name=JsonStringSchema(min_length=1,
                                       enum=self.get_supported_data_ids()),
         # The only allowed variable is already determined by the
         # data_id, so this schema forces an array containing only that
         # variable.
         variable_names=JsonArraySchema(items=(JsonStringSchema(
             min_length=0, enum=variables, default=variables[0])),
                                        unique_items=True),
         # Source for CRS information: §6.5 of
         # https://www.esa-soilmoisture-cci.org/sites/default/files/documents/CCI2_Soil_Moisture_D3.3.1_Product_Users_Guide%201.2.pdf
         crs=JsonStringSchema(nullable=True,
                              default='WGS84',
                              enum=[None, 'WGS84']),
         # W, S, E, N (will be converted to N, W, S, E).
         # For the soil moisture dataset, all data is global and no
         # geographic subsetting is possible, so the values are fixed
         # (i.e. minimum == maximum for every limit).
         bbox=JsonArraySchema(
             items=(JsonNumberSchema(minimum=-180, maximum=-180),
                    JsonNumberSchema(minimum=-90, maximum=-90),
                    JsonNumberSchema(minimum=180, maximum=180),
                    JsonNumberSchema(minimum=90, maximum=90))),
         # Like the bounding box, the spatial resolution is fixed.
         spatial_res=JsonNumberSchema(minimum=0.25,
                                      maximum=0.25,
                                      default=0.25),
         time_range=JsonDateSchema.new_range(),
         time_period=JsonStringSchema(
             enum=[self._aggregation_map[aggregation]]),
         # Non-standard parameters start here. There are complex
         # interdependencies between allowed values for these and for
         # the date specifiers, which can't be represented in JSON Schema.
         # The best we can do is to make them all available, set sensible
         # defaults, and trust that the user knows what they're requesting.
         type_of_sensor=JsonStringSchema(
             enum=sensors,
             default=sensors[0],
             title='Type of sensor',
             description=(
                 'Passive sensors measure reflected sunlight. '
                 'Active sensors have their own source of illumination.')),
         type_of_record=JsonStringSchema(
             enum=['cdr', 'icdr'],
             title='Type of record',
             description=(
                 'When dealing with satellite data it is common to '
                 'encounter references to Climate Data Records (CDR) and '
                 'interim-CDR (ICDR). For this dataset, both the ICDR and '
                 'CDR parts of each product were generated using the same '
                 'software and algorithms. The CDR is intended to have '
                 'sufficient length, consistency, and continuity to detect '
                 'climate variability and change. The ICDR provides a '
                 'short-delay access to current data where consistency with '
                 'the CDR baseline is expected but was not extensively '
                 'checked.'),
             default='cdr'),
         version=JsonStringSchema(
             enum=[
                 'v201706.0.0', 'v201812.0.0', 'v201812.0.1', 'v201912.0.0'
             ],
             title='Data version',
             description=(
                 'Format: vMajor.Minor.Run, e.g. "v201706.0.0". The Major '
                 'number usually represents the year (YYYY) and month (MM) '
                 'of date. The initial value for Minor is zero, and will '
                 'increment when updating the file. If there is a need – '
                 'e.g. because of technical issues – to replace a file '
                 'which has already been made public, the Run number of '
                 'the replacement file shifts to the next increment. The '
                 'initial Run number is zero.'),
             default='v201912.0.0'))
     required = [
         'variable_names',
         'time_range',
     ]
     return JsonObjectSchema(properties=dict(**params, ), required=required)