@@ -102,6 +102,13 @@ def curvilinear_point_in_cell(grid, y: np.ndarray, x: np.ndarray, yi: np.ndarray
102102 )
103103
104104 px = np .array ([grid .lon [yi , xi ], grid .lon [yi , xi + 1 ], grid .lon [yi + 1 , xi + 1 ], grid .lon [yi + 1 , xi ]])
105+ lon_span = px .max (axis = 0 ) - px .min (axis = 0 )
106+ antimeridian_cell = lon_span > 180.0
107+ # For any antimeridian cell, bump the positive longitudes by 360 degrees
108+ # This only works if particle longitudes are always gauranteed to be less than 180 degreeds
109+ mask = (px > 0.0 ) & antimeridian_cell [np .newaxis , :]
110+ px [mask ] -= 360.0
111+
105112 py = np .array ([grid .lat [yi , xi ], grid .lat [yi , xi + 1 ], grid .lat [yi + 1 , xi + 1 ], grid .lat [yi + 1 , xi ]])
106113
107114 a , b = np .dot (invA , px ), np .dot (invA , py )
@@ -119,7 +126,6 @@ def curvilinear_point_in_cell(grid, y: np.ndarray, x: np.ndarray, yi: np.ndarray
119126 ((y - py [0 ]) / (py [1 ] - py [0 ]) + (y - py [3 ]) / (py [2 ] - py [3 ])) * 0.5 ,
120127 (x - a [0 ] - a [2 ] * eta ) / (a [1 ] + a [3 ] * eta ),
121128 )
122-
123129 is_in_cell = np .where ((xsi >= 0 ) & (xsi <= 1 ) & (eta >= 0 ) & (eta <= 1 ), 1 , 0 )
124130
125131 return is_in_cell , np .column_stack ((xsi , eta ))
0 commit comments