Ejemplo n.º 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
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         name=JsonStringSchema(min_length=1),
         dtype=JsonStringSchema(min_length=1),
         dims=JsonArraySchema(items=JsonStringSchema(min_length=1)),
         chunks=JsonArraySchema(items=JsonIntegerSchema(minimum=0)),
         attrs=JsonObjectSchema(additional_properties=True),
     ),
                             required=['name', 'dtype', 'dims'],
                             additional_properties=False,
                             factory=cls)
Ejemplo n.º 5
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         job_id=JsonStringSchema(min_length=1),
         job_status=CubeGeneratorJobStatus.get_schema(),
         job_result=CubeGeneratorResult.get_schema(),
         output=JsonArraySchema(items=JsonStringSchema(), nullable=True),
         progress=JsonArraySchema(items=CubeGeneratorProgress.get_schema(),
                                  nullable=True)),
                             required=['job_id', 'job_status'],
                             additional_properties=True,
                             factory=cls)
Ejemplo n.º 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)
Ejemplo n.º 7
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(
            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)
Ejemplo n.º 8
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(
             status=JsonStringSchema(enum=STATUS_IDS),
             status_code=JsonIntegerSchema(),
             result=cls.get_result_schema(),
             message=JsonStringSchema(),
             output=JsonArraySchema(items=JsonStringSchema()),
             traceback=JsonArraySchema(items=JsonStringSchema()),
             versions=JsonObjectSchema(additional_properties=True)),
         required=['status'],
         additional_properties=True,
         factory=cls,
     )
Ejemplo n.º 9
0
 def get_schema(cls) -> JsonObjectSchema:
     """Get the JSON-schema for FileSet objects."""
     return JsonObjectSchema(
         properties=dict(
             path=JsonStringSchema(min_length=1),
             sub_path=JsonStringSchema(min_length=1),
             storage_params=JsonObjectSchema(additional_properties=True),
             includes=JsonArraySchema(items=JsonStringSchema(min_length=1)),
             excludes=JsonArraySchema(items=JsonStringSchema(min_length=1)),
         ),
         additional_properties=False,
         required=['path'],
         factory=cls,
     )
Ejemplo n.º 10
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(
             IsSubstitute=JsonBooleanSchema(),
             RequiredScopes=JsonArraySchema(items=IdentifierSchema)),
         additional_properties=False,
     )
Ejemplo n.º 11
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=ServiceConfig,
         properties=dict(
             Authentication=Authentication.get_schema(),
             DatasetAttribution=JsonArraySchema(items=StringSchema),
             DatasetChunkCacheSize=ChunkSizeSchema,
             Datasets=JsonArraySchema(items=DatasetConfig.get_schema()),
             DataStores=JsonArraySchema(items=DataStoreConfig.get_schema()),
             PlaceGroups=JsonArraySchema(
                 items=PlaceGroupConfig.get_schema()),
             Styles=JsonArraySchema(items=StyleConfig.get_schema()),
             ServiceProvider=ServiceProvider.get_schema(),
         ),
         additional_properties=False,
     )
Ejemplo n.º 12
0
 def test_from_instance_tuple(self):
     self.assertEqual([False, 2, 'U'],
                      JsonArraySchema(items=[
                          JsonBooleanSchema(),
                          JsonIntegerSchema(),
                          JsonStringSchema()
                      ]).from_instance([False, 2, 'U']))
Ejemplo n.º 13
0
 def get_open_data_params_schema(self,
                                 data_id: str = None) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         group=JsonStringSchema(
             description='Group path. (a.k.a. path in zarr terminology.).',
             min_length=1,
         ),
         chunks=JsonObjectSchema(
             description=
             'Optional chunk sizes along each dimension. Chunk size values may '
             'be None, "auto" or an integer value.',
             examples=[{
                 'time': None,
                 'lat': 'auto',
                 'lon': 90
             }, {
                 'time': 1,
                 'y': 512,
                 'x': 512
             }],
             additional_properties=True,
         ),
         decode_cf=JsonBooleanSchema(
             description=
             'Whether to decode these variables, assuming they were saved '
             'according to CF conventions.',
             default=True,
         ),
         mask_and_scale=JsonBooleanSchema(
             description=
             'If True, replace array values equal to attribute "_FillValue" with NaN. '
             'Use "scaling_factor" and "add_offset" attributes to compute actual values.',
             default=True,
         ),
         decode_times=JsonBooleanSchema(
             description=
             'If True, decode times encoded in the standard NetCDF datetime format '
             'into datetime objects. Otherwise, leave them encoded as numbers.',
             default=True,
         ),
         decode_coords=JsonBooleanSchema(
             description=
             'If True, decode the \"coordinates\" attribute to identify coordinates in '
             'the resulting dataset.',
             default=True,
         ),
         drop_variables=JsonArraySchema(
             items=JsonStringSchema(min_length=1), ),
         consolidated=JsonBooleanSchema(
             description=
             'Whether to open the store using zarr\'s consolidated metadata '
             'capability. Only works for stores that have already been consolidated.',
             default=False,
         ),
     ),
                             required=[],
                             additional_properties=False)
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def get_schema(cls):
     return JsonObjectSchema(
         properties=dict(input_config=InputConfig.get_schema(),
                         input_configs=JsonArraySchema(
                             items=InputConfig.get_schema(), min_items=1),
                         cube_config=CubeConfig.get_schema(),
                         output_config=OutputConfig.get_schema(),
                         callback_config=CallbackConfig.get_schema()),
         required=['cube_config', 'output_config'],
         factory=cls,
     )
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         succeeded=JsonIntegerSchema(nullable=True),
         failed=JsonIntegerSchema(nullable=True),
         active=JsonIntegerSchema(nullable=True),
         start_time=JsonStringSchema(nullable=True),
         completion_time=JsonStringSchema(nullable=True),
         conditions=JsonArraySchema(
             items=JsonObjectSchema(additional_properties=True),
             nullable=True)),
                             additional_properties=True,
                             factory=cls)
Ejemplo n.º 18
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,
     )
Ejemplo n.º 19
0
    def test_from_json_object_array_object(self):
        person_schema = JsonObjectSchema(
            properties=dict(name=JsonStringSchema(),
                            age=JsonIntegerSchema(),
                            deleted=JsonBooleanSchema(default=False)))

        schema = JsonObjectSchema(properties=dict(persons=JsonArraySchema(
            items=person_schema)))

        value = {
            'persons': [{
                'name': 'Bibo',
                'age': 15
            }, {
                'name': 'Ernie',
                'age': 12
            }]
        }

        self.assertEqual(
            {
                'persons': [{
                    'name': 'Bibo',
                    'age': 15,
                    'deleted': False
                }, {
                    'name': 'Ernie',
                    'age': 12,
                    'deleted': False
                }]
            }, schema.from_instance(value))

        Assignment = namedtuple('Assignment', ['persons'])
        schema.factory = Assignment
        self.assertEqual(
            Assignment(persons=[{
                'name': 'Bibo',
                'age': 15,
                'deleted': False
            }, {
                'name': 'Ernie',
                'age': 12,
                'deleted': False
            }]), schema.from_instance(value))

        Person = namedtuple('Person', ['name', 'age', 'deleted'])
        person_schema.factory = Person
        self.assertEqual(
            Assignment(persons=[
                Person(name='Bibo', age=15, deleted=False),
                Person(name='Ernie', age=12, deleted=False)
            ]), schema.from_instance(value))
Ejemplo n.º 20
0
def _get_common_dataset_properties():
    return dict(
        Title=StringSchema,
        TimeSeriesDataset=IdentifierSchema,
        BoundingBox=BoundingBoxSchema,
        ChunkCacheSize=ChunkSizeSchema,
        Augmentation=Augmentation.get_schema(),
        Style=IdentifierSchema,
        Hidden=BooleanSchema,
        AccessControl=AccessControl.get_schema(),
        PlaceGroups=JsonArraySchema(items=JsonObjectSchema(properties=dict(
            PlaceGroupRef=IdentifierSchema, ), )),
    )
Ejemplo n.º 21
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=Authentication,
         required=[
             'Domain',
             'Audience',
         ],
         properties=dict(
             Domain=JsonStringSchema(),
             Audience=UrlSchema,
             Algorithms=JsonArraySchema(items=IdentifierSchema),
         ),
         additional_properties=False,
     )
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=DataStoreConfig,
         required=[
             'Identifier',
             'StoreId',
         ],
         properties=dict(
             Identifier=IdentifierSchema,
             StoreId=IdentifierSchema,
             StoreParams=JsonObjectSchema(additional_properties=True, ),
             Datasets=JsonArraySchema(
                 items=DataStoreDatasetConfig.get_schema(), ),
         ),
         additional_properties=False,
     )
Ejemplo n.º 24
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=DatasetConfig,
         required=['Identifier', 'Path'],
         properties=dict(
             Identifier=IdentifierSchema,
             Path=PathSchema,
             FileSystem=FileSystemSchema,
             Anonymous=BooleanSchema,
             Endpoint=UrlSchema,
             Region=IdentifierSchema,
             Function=IdentifierSchema,
             InputDatasets=JsonArraySchema(items=IdentifierSchema),
             InputParameters=JsonObjectSchema(additional_properties=True, ),
             **_get_common_dataset_properties(),
         ),
         additional_properties=False,
     )
Ejemplo n.º 25
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)
Ejemplo n.º 26
0
 def test_tuple_validates_as_array(self):
     self.assertTupleEqual((1, 2, 3),
                           JsonArraySchema().to_instance((1, 2, 3)))
Ejemplo n.º 27
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)
Ejemplo n.º 28
0
    def get_open_data_params_schema(self, data_id: str) -> JsonObjectSchema:
        _, variable_spec, _ = data_id.split(':')
        variable_properties = self._var_map[variable_spec]

        params = dict(
            time_range=JsonDateSchema.new_range(),
            # crs, bbox, and spatial_res omitted, since they're constant.
            # time_period omitted, since (although the store as a whole offers
            # three aggregation periods) it's constant for a given data-id.

            # There are complex interdependencies between allowed values for
            # these parameters 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 will be added below *only* if >1 type available.

            # There's only one variable available per data ID, but we can't
            # omit variable_names, because we need to support the
            # variable_names=[] case (to produce an empty cube).
            variable_names=JsonArraySchema(
                items=(JsonStringSchema(
                    min_length=0,
                    enum=variable_properties.variables,
                    default=variable_properties.variables[0])),
                unique_items=True,
                default=[variable_properties.variables[0]]),
            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'))

        if len(variable_properties.sensor_types) > 1:
            params['type_of_sensor'] = JsonStringSchema(
                enum=variable_properties.sensor_types,
                default=variable_properties.sensor_types[0],
                title='Type of sensor',
                description=(
                    'Passive sensors measure reflected sunlight. '
                    'Active sensors have their own source of illumination.'))

        return JsonObjectSchema(properties=params,
                                required=['time_range'],
                                additional_properties=False)
Ejemplo n.º 29
0
        default=True,
    ),
    decode_times=JsonBooleanSchema(
        description='If True, decode times encoded in the'
        ' standard NetCDF datetime format '
        'into datetime objects. Otherwise,'
        ' leave them encoded as numbers.',
        default=True,
    ),
    decode_coords=JsonBooleanSchema(
        description='If True, decode the \"coordinates\"'
        ' attribute to identify coordinates in '
        'the resulting dataset.',
        default=True,
    ),
    drop_variables=JsonArraySchema(items=JsonStringSchema(min_length=1), ),
    consolidated=JsonBooleanSchema(
        description='Whether to open the store using'
        ' Zarr\'s consolidated metadata '
        'capability. Only works for stores that'
        ' have already been consolidated.',
        default=False,
    ),
),
                                                required=[],
                                                additional_properties=False)

ZARR_WRITE_DATA_PARAMS_SCHEMA = JsonObjectSchema(properties=dict(
    group=JsonStringSchema(
        description='Group path.'
        ' (a.k.a. path in zarr terminology.).',
Ejemplo n.º 30
0
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(
            factory=ServiceConfig,
            properties=dict(