1616_XGCM_AXES = Mapping [_XGCM_AXIS_DIRECTION , xgcm .Axis ]
1717
1818
19- def get_n_cell_edges_along_dim (axis : xgcm .Axis | None ) -> int :
19+ def get_cell_edge_count_along_dim (axis : xgcm .Axis | None ) -> int :
2020 if axis is None :
2121 return 1
2222 first_coord = list (axis .coords .items ())[0 ]
@@ -36,7 +36,7 @@ class XGrid(BaseGrid):
3636 This class provides methods and properties required for indexing and interpolating on the grid.
3737
3838 Assumptions:
39- - If using Parcels in the context of a periodic simulation, the provided grid already has a halo
39+ - If using Parcels in the context of a spatially periodic simulation, the provided grid already has a halo
4040
4141 """
4242
@@ -112,19 +112,19 @@ def time(self):
112112
113113 @property
114114 def xdim (self ):
115- return get_n_cell_edges_along_dim (self .xgcm_grid .axes .get ("X" ))
115+ return get_cell_edge_count_along_dim (self .xgcm_grid .axes .get ("X" ))
116116
117117 @property
118118 def ydim (self ):
119- return get_n_cell_edges_along_dim (self .xgcm_grid .axes .get ("Y" ))
119+ return get_cell_edge_count_along_dim (self .xgcm_grid .axes .get ("Y" ))
120120
121121 @property
122122 def zdim (self ):
123- return get_n_cell_edges_along_dim (self .xgcm_grid .axes .get ("Z" ))
123+ return get_cell_edge_count_along_dim (self .xgcm_grid .axes .get ("Z" ))
124124
125125 @property
126126 def tdim (self ):
127- return get_n_cell_edges_along_dim (self .xgcm_grid .axes .get ("T" ))
127+ return get_cell_edge_count_along_dim (self .xgcm_grid .axes .get ("T" ))
128128
129129 @property
130130 def time_origin (self ):
@@ -177,7 +177,7 @@ def search(self, z, y, x, ei=None):
177177 if ds .lon .ndim == 1 :
178178 yi , eta = _search_1d_array (ds .lat .values , y )
179179 xi , xsi = _search_1d_array (ds .lon .values , x )
180- return {"X " : (xi , xsi ), "Y" : (yi , eta ), "Z " : (zi , zeta )}
180+ return {"Z " : (zi , zeta ), "Y" : (yi , eta ), "X " : (xi , xsi )}
181181
182182 yi , xi = None , None
183183 if ei is not None :
@@ -186,9 +186,9 @@ def search(self, z, y, x, ei=None):
186186 yi = axis_indices .get ("Y" )
187187
188188 if ds .lon .ndim == 2 :
189- eta , xsi , yi , xi = _search_indices_curvilinear_2d (self , y , x , yi , xi )
189+ yi , eta , xi , xsi = _search_indices_curvilinear_2d (self , y , x , yi , xi )
190190
191- return {"X " : (xi , xsi ), "Y" : (yi , eta ), "Z " : (zi , zeta )}
191+ return {"Z " : (zi , zeta ), "Y" : (yi , eta ), "X " : (xi , xsi )}
192192
193193 raise NotImplementedError ("Searching in >2D lon/lat arrays is not implemented yet." )
194194
@@ -204,11 +204,7 @@ def unravel_index(self, ei) -> dict[_AXIS_DIRECTION, int]:
204204
205205 yi = ei // self .xdim
206206 xi = ei % self .xdim
207- return {
208- "X" : xi ,
209- "Y" : yi ,
210- "Z" : zi ,
211- }
207+ return {"Z" : zi , "Y" : yi , "X" : xi }
212208
213209
214210def get_axis_from_dim_name (axes : _XGCM_AXES , dim : str ) -> _XGCM_AXIS_DIRECTION | None :
@@ -219,7 +215,7 @@ def get_axis_from_dim_name(axes: _XGCM_AXES, dim: str) -> _XGCM_AXIS_DIRECTION |
219215 return None
220216
221217
222- def get_position_from_dim_name (axes : _XGCM_AXES , dim : str ) -> _XGCM_AXIS_POSITION | None :
218+ def get_xgcm_position_from_dim_name (axes : _XGCM_AXES , dim : str ) -> _XGCM_AXIS_POSITION | None :
223219 """For a given dimension, returns the position of the variable in the grid."""
224220 for axis in axes .values ():
225221 var_to_position = {var : position for position , var in axis .coords .items ()}
@@ -281,16 +277,16 @@ def assert_valid_lat_lon(da_lat, da_lon, axes: _XGCM_AXES):
281277 assert_all_dimensions_correspond_with_axis (da_lon , axes )
282278 assert_all_dimensions_correspond_with_axis (da_lat , axes )
283279
284- dim_to_position = {dim : get_position_from_dim_name (axes , dim ) for dim in da_lon .dims }
285- dim_to_position .update ({dim : get_position_from_dim_name (axes , dim ) for dim in da_lat .dims })
280+ dim_to_position = {dim : get_xgcm_position_from_dim_name (axes , dim ) for dim in da_lon .dims }
281+ dim_to_position .update ({dim : get_xgcm_position_from_dim_name (axes , dim ) for dim in da_lat .dims })
286282
287283 for dim in da_lon .dims :
288- if get_position_from_dim_name (axes , dim ) == "center" :
284+ if get_xgcm_position_from_dim_name (axes , dim ) == "center" :
289285 raise ValueError (
290286 f"Longitude DataArray { da_lon .name !r} with dims { da_lon .dims } is defined on the center of the grid, but must be defined on the F points."
291287 )
292288 for dim in da_lat .dims :
293- if get_position_from_dim_name (axes , dim ) == "center" :
289+ if get_xgcm_position_from_dim_name (axes , dim ) == "center" :
294290 raise ValueError (
295291 f"Latitude DataArray { da_lat .name !r} with dims { da_lat .dims } is defined on the center of the grid, but must be defined on the F points."
296292 )
0 commit comments