def validate_parameters(parameters, task_id=None): """Validate parameters generated by the parameter parsing task All validation should be done here - are there data restrictions? Combinations that aren't allowed? etc. Returns: parameter dict with all keyword args required to load data. -or- updates the task with ERROR and a message, returning None """ task = CloudCoverageTask.objects.get(pk=task_id) dc = DataAccessApi(config=task.config_path) #validate for any number of criteria here - num acquisitions, etc. acquisitions = dc.list_acquisition_dates(**parameters) if len(acquisitions) < 1: task.complete = True task.update_status("ERROR", "There are no acquistions for this parameter set.") return None task.update_status("WAIT", "Validated parameters.") if not dc.validate_measurements(parameters['product'], parameters['measurements']): parameters['measurements'] = ['blue', 'green', 'red', 'pixel_qa'] dc.close() return parameters
def validate_parameters(parameters, task_id=None): """Validate parameters generated by the parameter parsing task All validation should be done here - are there data restrictions? Combinations that aren't allowed? etc. Returns: parameter dict with all keyword args required to load data. -or- updates the task with ERROR and a message, returning None """ task = FractionalCoverTask.objects.get(pk=task_id) dc = DataAccessApi(config=task.config_path) #validate for any number of criteria here - num acquisitions, etc. acquisitions = dc.list_combined_acquisition_dates(**parameters) if len(acquisitions) < 1: task.complete = True task.update_status("ERROR", "There are no acquistions for this parameter set.") return None if task.compositor.id == "median_pixel" and (task.time_end - task.time_start).days > 367: task.complete = True task.update_status("ERROR", "Median pixel operations are only supported for single year time periods.") return None task.update_status("WAIT", "Validated parameters.") if not dc.validate_measurements(parameters['products'][0], parameters['measurements']): parameters['measurements'] = ['blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'pixel_qa'] dc.close() return parameters
def validate_parameters(parameters, task_id=None): """Validate parameters generated by the parameter parsing task All validation should be done here - are there data restrictions? Combinations that aren't allowed? etc. Returns: parameter dict with all keyword args required to load data. -or- updates the task with ERROR and a message, returning None """ task = NdviAnomalyTask.objects.get(pk=task_id) dc = DataAccessApi(config=task.config_path) acquisitions = dc.list_acquisition_dates(**parameters) if len(acquisitions) < 1: task.complete = True task.update_status("ERROR", "There are no acquistions for this parameter set.") return None # the actual acquisitino exists, lets try the baseline: validation_params = {**parameters} # there were no acquisitions in the year 1000, hopefully validation_params.update({ 'time': (task.time_start.replace(year=task.time_start.year - 5), task.time_start - timedelta(microseconds=1)) }) acquisitions = dc.list_acquisition_dates(**validation_params) # list/map/int chain required to cast int to each baseline month, it won't work if they're strings. grouped_dates = group_datetimes_by_month( acquisitions, months=list(map(int, task.baseline_selection.split(",")))) if not grouped_dates: task.complete = True task.update_status("ERROR", "There are no acquistions for this parameter set.") return None task.update_status("WAIT", "Validated parameters.") if not dc.validate_measurements(parameters['product'], parameters['measurements']): parameters['measurements'] = [ 'blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'pixel_qa' ] dc.close() return parameters
def validate_parameters(parameters, task_id=None): """Validate parameters generated by the parameter parsing task All validation should be done here - are there data restrictions? Combinations that aren't allowed? etc. Returns: parameter dict with all keyword args required to load data. -or- updates the task with ERROR and a message, returning None """ task = AppNameTask.objects.get(pk=task_id) dc = DataAccessApi(config=task.config_path) #validate for any number of criteria here - num acquisitions, etc. # TODO: if this is not a multisensory app, replace list_combined_acquisition_dates with list_acquisition_dates acquisitions = dc.list_combined_acquisition_dates(**parameters) # TODO: are there any additional validations that need to be done here? if len(acquisitions) < 1: task.complete = True task.update_status("ERROR", "There are no acquistions for this parameter set.") return None if task.animated_product.animation_id != "none" and task.compositor.id == "median_pixel": task.complete = True task.update_status( "ERROR", "Animations cannot be generated for median pixel operations.") return None task.update_status("WAIT", "Validated parameters.") # TODO: Check that the measurements exist - for Landsat, we're making sure that cf_mask/pixel_qa are interchangable. # replace ['products'][0] with ['products'] if this is not a multisensory app. if not dc.validate_measurements(parameters['products'][0], parameters['measurements']): parameters['measurements'] = [ 'blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'pixel_qa' ] dc.close() return parameters
def validate_parameters(parameters, task_id=None): """Validate parameters generated by the parameter parsing task All validation should be done here - are there data restrictions? Combinations that aren't allowed? etc. Returns: parameter dict with all keyword args required to load data. -or- updates the task with ERROR and a message, returning None """ task = SlipTask.objects.get(pk=task_id) dc = DataAccessApi(config=task.config_path) acquisitions = dc.list_acquisition_dates(**parameters) if len(acquisitions) < 1: task.complete = True task.update_status("ERROR", "There are no acquistions for this parameter set.") return None if len(acquisitions) < task.baseline_length + 1: task.complete = True task.update_status("ERROR", "There are an insufficient number of acquisitions for your baseline length.") return None validation_parameters = {**parameters} validation_parameters.pop('time') validation_parameters.pop('measurements') validation_parameters.update({'product': 'terra_aster_gdm_' + task.area_id, 'platform': 'TERRA'}) if len(dc.list_acquisition_dates(**validation_parameters)) < 1: task.complete = True task.update_status("ERROR", "There is no elevation data for this parameter set.") return None task.update_status("WAIT", "Validated parameters.") if not dc.validate_measurements(parameters['product'], parameters['measurements']): parameters['measurements'] = ['blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'pixel_qa'] dc.close() return parameters
def validate_parameters(parameters, task_id=None): """Validate parameters generated by the parameter parsing task All validation should be done here - are there data restrictions? Combinations that aren't allowed? etc. Returns: parameter dict with all keyword args required to load data. -or- updates the task with ERROR and a message, returning None """ task = CoastalChangeTask.objects.get(pk=task_id) dc = DataAccessApi(config=task.config_path) validation_params = dict(parameters) # verify that both the start and end year have acquisitions for year in parameters['time']: validation_params.update( {'time': (year, year.replace(year=year.year + 1))}) acquisitions = dc.list_acquisition_dates(**validation_params) if len(acquisitions) < 1: task.complete = True task.update_status( "ERROR", "There must be at least one acquisition in both the start and ending year." ) return None task.update_status("WAIT", "Validated parameters.") if not dc.validate_measurements(parameters['product'], parameters['measurements']): parameters['measurements'] = [ 'blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'pixel_qa' ] dc.close() return parameters