environmentaltools.common.find_indexes

environmentaltools.common.find_indexes(latvar, lonvar, lat0, lon0)[source]

Find array indices of coordinates nearest to target location.

Uses great circle distance (tunnel through Earth) as the distance metric for finding the closest grid point.

Parameters:
  • latvar (np.ndarray) – Array of latitude values (degrees).

  • lonvar (np.ndarray) – Array of longitude values (degrees).

  • lat0 (float) – Target latitude (degrees).

  • lon0 (float) – Target longitude (degrees).

Returns:

(lat_index, lon_index) - Array indices of nearest point, or (None, None)

if arrays are empty.

Return type:

tuple

References

https://www.unidata.ucar.edu/blogs/developer/en/entry/accessing_netcdf_data_by_coordinates