I would like to find the indices of the lon / lat coordinate of the closest location for the lon / lat tuple. It is already available in the Java API as GridCoordSystem.findXYindexFromLatLon (), but I did not find anything comparable in the Python API. What I hope to find in the API, or write myself and contribute to the API (if useful), looks something like this:
def get_indices(netcdf_dataset, lon_value, lat_value):
'''
:param netcdf_dataset an open NetCDF data set object
:param lon_value a longitude value, in degrees (-180...180)
:param lat_value a latitude value, in degrees (-90...90)
:return indices into the lon and lat coordinate variables corresponding to the closest point to the lon/lat value arguments
'''
# some (trigonometry?) code here...
return lon_index, lat_index
Maybe it's not as difficult as I suppose, and I can leave just by using the closest neighbor?
Thanks in advance for any comments or suggestions.
source
share