nearest_gridpoint

nearest_gridpoint(fs, lats, lons[, mode])
nearest_gridpoint(fs, location[, mode])
nearest_gridpoint(fs, gpt[, mode])

Returns the nearest gridpoint value from fs for a given location (or locations).

Parameters
  • fs (Fieldset) – input fieldset

  • lats (number or ndarray) – target latitude(s)

  • lons (number or ndarray) – target longitudes(s)

  • location (list) – single target location defined as a list of [lat, lon]

  • gpt (Geopoints) – input geopoints

  • mode (str) – specifies the way missing values are handled. The only allowed value is “valid”.

Return type

number or list or ndarray or Geopoints

fs must be a gridded field.

The nearest gridpoint extraction depends on the arguments:

  • location defines a single location. The return value is a number when fs only contains one field, and list otherwise.

  • lats and lons can define either a single location (as number) or multiple locations (as ndarray). If a single location is specified the return value is the same as for location. For multiple locations an ndarray is returned.

  • when gpt is specified only the first field of fs is used. The result is a Geopoints containing the the nearest gridpoint values for all the locations in gpt. Where it is not possible to generate a sensible value due to lack of valid data in fs, the internal geopoints missing value is used (this value can be checked for with the built-in variable geo_missing_value or removed with the function remove_missing_values()).

Parameter mode controls the return value when the nearest gridpoint value is a missing value or the location is out of the grid area:

  • by default, None is returned for a single location and nan for multiple locations.

  • if mode is ‘valid’ then from out of the surrounding gridpoints the nearest valid one is returned; None or nan will still be returned if all the surrounding points are missing.