nearest_gridpoint_info
- nearest_gridpoint_info(fs, lat, lon[, mode])
- nearest_gridpoint_info(fs, location[, mode])
Returns the value and location of the nearest grid point to a given location in each field in
fs
.- Parameters
fs (
Fieldset
) – input fieldsetlat (number) – target latitude
lon (number) – target longitude
location (list) – single target location defined as a list of [lat, lon]
mode (str) – specifies the way missing values are handled. The only allowed value is “valid”.
- Return type
list of dict
The return value is a list containing the following values for each field:
If the nearest gridpoint value is non missing a dictionary is returned with these members:
latitude: latitude of the nearest gridpoint
longitude: longitude of the nearest gridpoint
index: index of nearest gridpoint within the field
distance: distance between the nearest gridpoint and the specified location in km
value: value at the nearest gridpoint
If the nearest gridpoint has missing value the return value depends on
mode
:if
mode
is not specified None is returnedif
mode
is “valid” the dictionary for the nearest valid point from the surrounding gridpoints is returned. If all the surrounding points are missing None is returned
This example:
import metview as mv # read grib with 2 fields on a 1.5x1.5 degree grid f = mv.read("my_data.grib") # get nearest gridpoint info info = mv.nearest_gridpoint_info(f, 47, 19) print(info)
generates the following output:
[{'latitude': 46.5, 'longitude': 19.5, 'index': 6973.0, 'distance': 67.3506, 'value': 291.144}, {'latitude': 46.5, 'longitude': 19.5, 'index': 6973.0, 'distance': 67.3506, 'value': 294.011'}]
Note
See also
nearest_gridpoint()
,surrounding_points_indexes()
andinterpolate()
.