def clean(self, value):
if not isinstance(value, six.string_types):<EOL><INDENT>raise ParameterNotValidError<EOL><DEDENT>try:<EOL><INDENT>source, value = value.split('<STR_LIT>', <NUM_LIT:1>)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ParameterNotValidError<EOL><DEDENT>if source == '<STR_LIT>':<EOL><INDENT>if '<STR_LIT:@>' in value:<EOL><INDENT>value, timestamp = value.split('<STR_LIT:@>', <NUM_LIT:1>)<EOL>try:<EOL><INDENT>service_time = timestamp_to_date(int(timestamp))<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ParameterNotValidError<EOL><DEDENT><DEDENT>else:<EOL><INDENT>service_time = None<EOL><DEDENT>if '<STR_LIT::>' in value:<EOL><INDENT>service_name, variable_name = value.split('<STR_LIT::>', <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>service_name = value<EOL>variable_name = None<EOL><DEDENT>try:<EOL><INDENT>self.service = Service.objects.get(name=service_name)<EOL><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>raise ParameterNotValidError("<STR_LIT>".format(service_name))<EOL><DEDENT>if variable_name:<EOL><INDENT>try:<EOL><INDENT>variable = self.service.variable_set.all().get(variable=variable_name)<EOL><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>raise ParameterNotValidError("<STR_LIT>".format(variable_name))<EOL><DEDENT>if service_time is not None:<EOL><INDENT>time_index = best_fit(variable.time_stops, service_time)<EOL><DEDENT>else:<EOL><INDENT>time_index = None<EOL><DEDENT>data = self.get_grid_for_variable(variable, time_index=time_index)<EOL>return Raster(data, variable.full_extent, <NUM_LIT:1>, <NUM_LIT:0>, self.is_y_increasing(variable))<EOL><DEDENT>else:<EOL><INDENT>return self.dataset<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ParameterNotValidError('<STR_LIT>'.format(source))<EOL><DEDENT>
Cleans and returns the given value, or raises a ParameterNotValidError exception