Exemple #1
0
def parse_gridded_request(request):
    """
    Parses a request for a gridded forecast.
    """
    # takes the first 4 '|' separated fields, if fewer than
    # k exist the missing fields are replaced with None
    model_domain, grid_str, hours_str, variables = split_fields(request, 4)
    model, domain_str = model_domain.split(':')
    # parse the domain and make sure its ok
    domain = utils.parse_domain(domain_str)
    # parse the grid_string
    resol = utils.parse_resolution(grid_str)
    # parse the hours string
    hours = utils.parse_hours(hours_str)
    # check the variables
    if variables is None:
        variables = []
    else:
        variables = variables.split(',')
    variables = utils.validate_variables(variables)
    return {'type': 'gridded',
            'model': model.lower().strip(),
            'domain': domain,
            'resolution': resol,
            'hours': hours,
            'variables': variables}
Exemple #2
0
def normalize(zygrib_query):
    # turn days/hours into hours
    hour_resolution = zygrib_query.pop('hours')
    days = zygrib_query.pop('days')
    hours = np.arange(0., days * 24. + hour_resolution, hour_resolution)
    zygrib_query['hours'] = hours
    zygrib_query['type'] = 'gridded'
    model = zygrib_query.get('model', None)
    zygrib_query['model'] = utils.validate_model(model)
    variables = utils.validate_variables(zygrib_query.get('variables', []))
    zygrib_query['variables'] = variables
    return zygrib_query
Exemple #3
0
        model = 'gefs'
    location = utils.parse_location(location_str)
    # default to 4 days every three hours
    time_str = time_str or '5,6'
    # First try parsing the format `days,period`
    try:
      hours = utils.parse_times(time_str)
    except ValueError, e:
      # if that fails try the gridded format `hour0,hour1,...,hourn`
      hours = utils.parse_hours(time_str)

    if variables is None:
        variables = []
    else:
        variables = variables.split(',')
    variables = utils.validate_variables(variables)

    send_image = image is not None

    return {'type': 'spot',
            'model': model,
            'location': location,
            'hours': hours,
            'variables': variables,
            'send-image': send_image}


def parse_send_request(body):
    """
    Parses the a saildoc-like send request and returns
    a dictionary of attributes from the query.