@@ -79,31 +79,31 @@ def _hash_cell_size(self):
7979 """Computes the size of the hash cells from the source grid.
8080 The hash cell size is set to 1/2 of the square root of the curvilinear cell area
8181 """
82- return np .sqrt (np .median (planar_quad_area (self ._source_grid .lon , self ._source_grid .lat ))) * 0.5
82+ return np .sqrt (np .median (planar_quad_area (self ._source_grid .lat , self ._source_grid .lon ))) * 0.5
8383
8484 def _hash_index2d (self , coords ):
8585 """Computes the 2-d hash index (i,j) for the location (x,y), where x and y are given in spherical
8686 coordinates (in degrees)
8787 """
8888 # Wrap longitude to [-180, 180]
89- lon = ( coords [:, 0 ] + 180.0 ) % ( 360.0 ) - 180.0
89+ lon = coords [:, 1 ]
9090 i = ((lon - self ._xmin ) / self ._dh ).astype (np .int32 )
91- j = ((coords [:, 1 ] - self ._ymin ) / self ._dh ).astype (np .int32 )
92- return i , j
91+ j = ((coords [:, 0 ] - self ._ymin ) / self ._dh ).astype (np .int32 )
92+ return j , i
9393
9494 def _hash_index (self , coords ):
9595 """Computes the flattened hash index for the location (x,y), where x and y are given in spherical
9696 coordinates (in degrees). The single dimensioned hash index orders the flat index with all of the
9797 i-points first and then all the j-points.
9898 """
99- i , j = self ._hash_index2d (coords )
99+ j , i = self ._hash_index2d (coords )
100100 return i + self ._nx * j
101101
102102 def _grid_ij_for_eid (self , eid ):
103103 """Returns the (i,j) grid coordinates for the given element id (eid)"""
104104 j = eid // (self ._source_grid .xdim )
105105 i = eid - j * (self ._source_grid .xdim )
106- return i , j
106+ return j , i
107107
108108 def _initialize_face_hash_table (self ):
109109 """Create a mapping that relates unstructured grid faces to hash indices by determining
@@ -112,26 +112,26 @@ def _initialize_face_hash_table(self):
112112 if self ._face_hash_table is None or self .reconstruct :
113113 index_to_face = [[] for i in range (self ._nx * self ._ny )]
114114 # Get the bounds of each curvilinear faces
115- lon_bounds , lat_bounds = curvilinear_grid_facebounds (
116- self ._source_grid .lon ,
115+ lat_bounds , lon_bounds = curvilinear_grid_facebounds (
117116 self ._source_grid .lat ,
117+ self ._source_grid .lon ,
118118 )
119119 coords = np .stack (
120120 (
121- lon_bounds [:, :, 0 ].flatten (),
122121 lat_bounds [:, :, 0 ].flatten (),
122+ lon_bounds [:, :, 0 ].flatten (),
123123 ),
124124 axis = - 1 ,
125125 )
126- xi1 , yi1 = self ._hash_index2d (coords )
126+ yi1 , xi1 = self ._hash_index2d (coords )
127127 coords = np .stack (
128128 (
129- lon_bounds [:, :, 1 ].flatten (),
130129 lat_bounds [:, :, 1 ].flatten (),
130+ lon_bounds [:, :, 1 ].flatten (),
131131 ),
132132 axis = - 1 ,
133133 )
134- xi2 , yi2 = self ._hash_index2d (coords )
134+ yi2 , xi2 = self ._hash_index2d (coords )
135135 nface = (self ._source_grid .xdim ) * (self ._source_grid .ydim )
136136 for eid in range (nface ):
137137 for j in range (yi1 [eid ], yi2 [eid ] + 1 ):
@@ -157,7 +157,7 @@ def query(
157157 Parameters
158158 ----------
159159 coords : array_like
160- coordinate pairs in degrees (lon, lat ) to query.
160+ coordinate pairs in degrees (lat, lon ) to query.
161161
162162
163163 Returns
@@ -176,11 +176,11 @@ def query(
176176
177177 for i , (coord , candidates ) in enumerate (zip (coords , candidate_faces , strict = False )):
178178 for face_id in candidates :
179- xi , yi = self ._grid_ij_for_eid (face_id )
179+ yi , xi = self ._grid_ij_for_eid (face_id )
180180 nodes = np .stack (
181181 (
182- self ._xbound [yi , xi , :],
183182 self ._ybound [yi , xi , :],
183+ self ._xbound [yi , xi , :],
184184 ),
185185 axis = - 1 ,
186186 )
@@ -211,9 +211,9 @@ def _barycentric_coordinates(nodes, point, min_area=1e-8):
211211 Parameters
212212 ----------
213213 nodes : numpy.ndarray
214- Spherical coordinates (lon, lat) of each corner node of a face
214+ Spherical coordinates (lat,lon ) of each corner node of a face
215215 point : numpy.ndarray
216- Spherical coordinates (lon, lat) of the point
216+ Spherical coordinates (lat,lon ) of the point
217217
218218 Returns
219219 -------
@@ -239,7 +239,7 @@ def _barycentric_coordinates(nodes, point, min_area=1e-8):
239239 return barycentric_coords
240240
241241
242- def planar_quad_area (lon , lat ):
242+ def planar_quad_area (lat , lon ):
243243 """Computes the area of each quadrilateral face in a curvilinear grid.
244244 The lon and lat arrays are assumed to be 2D arrays of points with dimensions (n_y, n_x).
245245 The area is computed using the Shoelace formula.
@@ -272,10 +272,10 @@ def planar_quad_area(lon, lat):
272272 return area
273273
274274
275- def curvilinear_grid_facebounds (lon , lat ):
275+ def curvilinear_grid_facebounds (lat , lon ):
276276 """Computes the bounds of each curvilinear face in the grid.
277277 The lon and lat arrays are assumed to be 2D arrays of points with dimensions (n_y, n_x).
278- The bounds are for faces whose corner node vertices are defined by lon, lat.
278+ The bounds are for faces whose corner node vertices are defined by lat,lon .
279279 Face(yi,xi) is surrounding by points (yi,xi), (yi,xi+1), (yi+1,xi+1), (yi+1,xi).
280280 This method is only used during hashgrid construction to determine which curvilinear
281281 faces overlap with which hash cells.
@@ -304,4 +304,4 @@ def curvilinear_grid_facebounds(lon, lat):
304304 yf_high = yf .max (axis = - 1 )
305305 ybounds = np .stack ([yf_low , yf_high ], axis = - 1 )
306306
307- return xbounds , ybounds
307+ return ybounds , xbounds
0 commit comments