def validate_restricted(self, x, fieldname, schema, path, restricted): """Validate that the requested products are available by date or role""" if not restricted: return # Like extents, we need to do some initial validation of the input up front, # and let those individual validators output the errors if 'inputs' not in x: return if not self.validate_type_array(x['inputs']): return req_prods = x.get(fieldname) if not req_prods: return avail_prods = (ordering.OrderingProvider() .available_products(x['inputs'], self.username)) not_implemented = avail_prods.pop('not_implemented', None) date_restricted = avail_prods.pop('date_restricted', None) # Check for to make sure there is only one sensor type in there if len(avail_prods) > 1: return if date_restricted: restr_prods = date_restricted.keys() for key in restr_prods: if key not in req_prods: date_restricted.pop(key, None) if date_restricted: self._error('Requested products are restricted by date', date_restricted, fieldname, path=path) prods = [] for key in avail_prods: prods = [_ for _ in avail_prods[key]['products']] if not prods: return dif = list(set(req_prods) - set(prods)) if date_restricted: for d in dif: if d in date_restricted: dif.remove(d) if dif: self._error('Requested products are not available', dif, fieldname, path=path)
def validate_restricted(self, x, fieldname, schema, path, restricted): """Validate that the requested products are available by date or role""" if not restricted: return # Like extents, we need to do some initial validation of the input up front, # and let those individual validators output the errors if 'inputs' not in x: return if not self.validate_type_array(x['inputs']): return req_prods = x.get(fieldname) if not req_prods: return avail_prods = (ordering.OrderingProvider() .available_products(x['inputs'], self.username)) not_implemented = avail_prods.pop('not_implemented', None) date_restricted = avail_prods.pop('date_restricted', None) ordering_restricted = avail_prods.pop('ordering_restricted', None) # Check for to make sure there is only one sensor type in there if len(avail_prods) > 1: return if not_implemented: self._errors.append("Requested IDs are not recognized. Remove: {}" .format(not_implemented)) if date_restricted: restr_prods = date_restricted.keys() for key in restr_prods: if key not in req_prods: date_restricted.pop(key, None) if date_restricted: for product_type in date_restricted: msg = ("Requested {} products are restricted by date. " "Remove {} scenes: {}" .format(product_type, path.split('.products')[0], [x.upper() for x in date_restricted[product_type]])) self._errors.append(msg) if ordering_restricted: restr_sensors = ordering_restricted.keys() for sensor in restr_sensors: msg = ("Requested sensor is restricted from ordering. " "Remove: {}".format(sensor)) self._errors.append(msg) prods = [] for key in avail_prods: prods = [_ for _ in avail_prods[key]['products']] if not prods: return dif = list(set(req_prods) - set(prods)) if date_restricted: for d in dif: if d in date_restricted: dif.remove(d) if dif: for d in dif: if type(x) == dict: scene_ids = [s.upper() for s in x['inputs']] msg = ("Requested {} products are not available. " "Remove {} scenes: {}" .format(d, path.split('.products')[0], scene_ids)) self._errors.append(msg) restr_source = self.restricted['source'] sensors = [s for s in self.data_source.keys() if s in sn.SensorCONST.instances.keys()] other_sensors = set(sensors) - set(restr_source['sensors']) parse_customize = lambda c: ((c in self.data_source) and (self.data_source.get(c) != restr_source.get(c))) if not other_sensors: if not set(req_prods) - set(restr_source['products']): if not any(map(parse_customize, restr_source['custom'])): msg = restr_source['message'].strip() if msg not in self._errors: self._errors.append(msg)
def validate_restricted(self, x, fieldname, schema, path, restricted): """Validate that the requested products are available by date or role""" if not restricted: return # Like extents, we need to do some initial validation of the input up front, # and let those individual validators output the errors if 'inputs' not in x: return if not self.validate_type_array(x['inputs']): return req_prods = x.get(fieldname) if not req_prods: return try: req_scene = x.get('inputs')[0] except IndexError: return inst = sn.instance(req_scene) avail_prods = (ordering.OrderingProvider().available_products( x['inputs'], self.username)) not_implemented = avail_prods.pop('not_implemented', None) date_restricted = avail_prods.pop('date_restricted', None) ordering_restricted = avail_prods.pop('ordering_restricted', None) # Check for to make sure there is only one sensor type in there if len(avail_prods) > 1: return if not_implemented: self._errors.append( "Requested IDs are not recognized. Remove: {}".format( not_implemented)) if date_restricted: restr_prods = date_restricted.keys() for key in restr_prods: if key not in req_prods: date_restricted.pop(key, None) if date_restricted: for product_type in date_restricted: msg = ("Requested {} products are restricted by date. " "Remove {} scenes: {}".format( product_type, path.split('.products')[0], [ x.upper() for x in date_restricted[product_type] ])) self._errors.append(msg) if ordering_restricted: restr_sensors = ordering_restricted.keys() for sensor in restr_sensors: msg = ("Requested sensor is restricted from ordering. " "Remove: {}".format(sensor)) self._errors.append(msg) prods = [] for key in avail_prods: prods = [_ for _ in avail_prods[key]['products']] if not prods: return dif = list(set(req_prods) - set(prods)) if date_restricted: for d in dif: if d in date_restricted: dif.remove(d) if dif: for d in dif: if type(x) == dict: scene_ids = [s.upper() for s in x['inputs']] msg = ("Requested {} products are not available. " "Remove {} scenes: {}".format( d, path.split('.products')[0], scene_ids)) self._errors.append(msg) # Enforce non-customized l1 ordering restriction for Landsat restr_source = self.restricted['source'] landsat_sensors = restr_source['sensors'] sensors = [ s for s in self.data_source.keys() if s in sn.SensorCONST.instances.keys() and s in landsat_sensors ] parse_customize = lambda c: ( (c in self.data_source) and (self.data_source.get(c) != restr_source.get(c))) if sensors and 'LANDSAT' in inst.lta_json_name: if not set(req_prods) - set(restr_source['products']): if not any(map(parse_customize, restr_source['custom'])): msg = restr_source['message'].strip() if msg not in self._errors: self._errors.append(msg) # Enforce non-customized l1 ordering restriction for MODIS and VIIRS restr_modis_viirs = self.restricted['source_daac'] modis_viirs_sensors = restr_modis_viirs['sensors'] sensors_mv = [ s for s in self.data_source.keys() if s in sn.SensorCONST.instances.keys() and s in modis_viirs_sensors ] parse_modis_customize = lambda c: ( (c in self.data_source) and (self.data_source.get(c) != restr_modis_viirs.get(c))) if sensors_mv and ('MODIS' in inst.lta_json_name or 'VIIRS' in inst.lta_json_name): if not set(req_prods) - set(restr_modis_viirs['products']): if not any( map(parse_modis_customize, restr_modis_viirs['custom'])): msg = restr_modis_viirs['message'].strip() if msg not in self._errors: self._errors.append(msg) # Enforce restricted product ordering for MODIS NDVI if 'MODIS' in inst.lta_json_name: restr_modis_ndvi = self.restricted['source_modis_ndvi'] modis_sensors = restr_modis_ndvi['modis_sensors'] req_ndvi_sensors = [ s for s in self.data_source.keys() if s in sn.SensorCONST.instances.keys() and s in modis_sensors ] invalid_req = set(req_ndvi_sensors) - set( restr_modis_ndvi['ndvi_sensors']) if invalid_req: if 'modis_ndvi' in req_prods: msg = restr_modis_ndvi['message'].strip() if msg not in self._errors: self._errors.append(msg) # Enforce sensor-restricted product ordering for LaORCA if 'orca' in req_prods: restr_orca_info = self.restricted['source_orca_sensors'] orca_sensors = restr_orca_info['sensors'] req_orca_sensors = [ s for s in self.data_source.keys() if s in sn.SensorCONST.instances.keys() and s in orca_sensors ] invalid_orca_req = set(req_orca_sensors) - set( restr_orca_info['orca_sensors']) if invalid_orca_req: msg = restr_orca_info['message'].strip() if msg not in self._errors: self._errors.append(msg) # Make sure that all required st options are included st = 'st' stalg_single_channel = 'stalg_single_channel' stalg_split_window = 'stalg_split_window' reanalysis_data = [ 'reanalsrc_narr', 'reanalsrc_merra2', 'reanalsrc_fp', 'reanalsrc_fpit' ] if st in req_prods: if stalg_single_channel not in req_prods and stalg_split_window not in req_prods: msg = "Missing surface temperature algorithm - " \ "please choose from ['{0}' (olitirs only), '{1}']".format(stalg_split_window, stalg_single_channel) if msg not in self._errors: self._errors.append(msg) if stalg_single_channel in req_prods and not any( [r for r in reanalysis_data if r in req_prods]): msg = "Missing reanalysis data source for single channel algorithm - " \ "please choose from {}".format(reanalysis_data) if msg not in self._errors: self._errors.append(msg) all_st_options = list() all_st_options.append(stalg_split_window) all_st_options.append(stalg_single_channel) all_st_options.extend(reanalysis_data) if any([x for x in all_st_options if x in req_prods ]) and st not in req_prods: msg = "Must include 'st' in products if specifying surface temperature options" if msg not in self._errors: self._errors.append(msg)