From bc4227342ec6d46bf0049966659b6f33273674ed Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Wed, 1 Sep 2021 15:51:06 -0500 Subject: [PATCH] snapshot... --- modules/util/lon_lat_grid.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/util/lon_lat_grid.py b/modules/util/lon_lat_grid.py index 66254434..0cf2d2c7 100644 --- a/modules/util/lon_lat_grid.py +++ b/modules/util/lon_lat_grid.py @@ -19,7 +19,7 @@ class MyGenericException(Exception): class LonLatGrid: # grd_lons, grd_lats: the longitude, latitude of each grid point (must be 2D grids), must have same shape # Incoming longitude must be in range: 0 - 360 degrees - # Can have NaN for off Earth grid points. + # Can have NaN for off Earth grid points (these are handled internally). def __init__(self, grd_lons, grd_lats): if grd_lons.shape != grd_lats.shape: raise MyGenericException('incoming lons,lats must have same shape') @@ -50,9 +50,10 @@ class LonLatGrid: # locate nearest neighbor for incoming target in earth coordinates (Should not have NaNs) # lons, lats can be flat or 2D + # closeness_threshold: if < distance of located_point to target, return off grid # incoming longitude must be in range: 0 - 360 degrees # returns NN indexes relative to the grid determined in the ctr. - def value_to_index(self, lons, lats): + def value_to_index(self, lons, lats, closeness_threshold=2000): if lons.shape != lats.shape: raise MyGenericException('incoming lons,lats must have same shape') @@ -65,8 +66,9 @@ class LonLatGrid: xy = np.stack([lons, lats], axis=1) dist, indices = self.kd.query(np.deg2rad(xy)) + dist *= 6370000 # convert unit radius to meters - valid = indices < self.map_indexes.size + valid = (indices < self.map_indexes.size) & (dist < closeness_threshold) indices = indices[valid] return self.map_indexes[indices], indices -- GitLab