@@ -177,7 +177,7 @@ def cumsum_by_track(field, track):
177
177
178
178
179
179
@njit (cache = True , fastmath = True )
180
- def interp2d_geo (x_g , y_g , z_g , m_g , x , y ):
180
+ def interp2d_geo (x_g , y_g , z_g , m_g , x , y , nearest = False ):
181
181
"""
182
182
For geographic grid, test of cicularity.
183
183
@@ -187,6 +187,7 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
187
187
:param array m_g: Boolean grid, True if value is masked
188
188
:param array x: coordinate where interpolate z
189
189
:param array y: coordinate where interpolate z
190
+ :param bool nearest: if true we will take nearest pixel
190
191
:return: z interpolated
191
192
:rtype: array
192
193
"""
@@ -223,9 +224,21 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
223
224
if m_g [i0 , j0 ] or m_g [i0 , j1 ] or m_g [i1 , j0 ] or m_g [i1 , j1 ]:
224
225
z [i ] = nan
225
226
else :
226
- z [i ] = (z00 * (1 - xd ) + (z10 * xd )) * (1 - yd ) + (
227
- z01 * (1 - xd ) + z11 * xd
228
- ) * yd
227
+ if nearest :
228
+ if xd <= 0.5 :
229
+ if yd <= 0.5 :
230
+ z [i ] = z00
231
+ else :
232
+ z [i ] = z01
233
+ else :
234
+ if yd <= 0.5 :
235
+ z [i ] = z10
236
+ else :
237
+ z [i ] = z11
238
+ else :
239
+ z [i ] = (z00 * (1 - xd ) + (z10 * xd )) * (1 - yd ) + (
240
+ z01 * (1 - xd ) + z11 * xd
241
+ ) * yd
229
242
return z
230
243
231
244
0 commit comments