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 fieldsetlats (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 geopointsmode (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 whenfs
only contains one field, and list otherwise.lats
andlons
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 forlocation
. For multiple locations an ndarray is returned.when
gpt
is specified only the first field offs
is used. The result is aGeopoints
containing the the nearest gridpoint values for all the locations ingpt
. Where it is not possible to generate a sensible value due to lack of valid data infs
, 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 functionremove_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.
Note
See also interpolate()
, nearest_gridpoint_info()
and surrounding_points_indexes()
.