@@ -145,3 +145,57 @@ def test_search_1d_array(array, x, expected_xi, expected_xsi):
145145 xi , xsi = _search_1d_array (array , x )
146146 assert xi == expected_xi
147147 assert np .isclose (xsi , expected_xsi )
148+
149+
150+ @pytest .mark .parametrize (
151+ "grid, da_name, expected" ,
152+ [
153+ pytest .param (
154+ XGrid (xgcm .Grid (datasets ["ds_2d_left" ], periodic = False )),
155+ "U (C grid)" ,
156+ {
157+ "XG" : (np .int64 (0 ), np .float64 (0.0 )),
158+ "YC" : (np .int64 (- 1 ), np .float64 (0.5 )),
159+ "ZG" : (np .int64 (0 ), np .float64 (0.0 )),
160+ },
161+ id = "MITgcm indexing style U (C grid)" ,
162+ ),
163+ pytest .param (
164+ XGrid (xgcm .Grid (datasets ["ds_2d_left" ], periodic = False )),
165+ "V (C grid)" ,
166+ {
167+ "XC" : (np .int64 (- 1 ), np .float64 (0.5 )),
168+ "YG" : (np .int64 (0 ), np .float64 (0.0 )),
169+ "ZG" : (np .int64 (0 ), np .float64 (0.0 )),
170+ },
171+ id = "MITgcm indexing style V (C grid)" ,
172+ ),
173+ pytest .param (
174+ XGrid (xgcm .Grid (datasets ["ds_2d_right" ], periodic = False )),
175+ "U (C grid)" ,
176+ {
177+ "XG" : (np .int64 (0 ), np .float64 (0.0 )),
178+ "YC" : (np .int64 (0 ), np .float64 (0.5 )),
179+ "ZG" : (np .int64 (0 ), np .float64 (0.0 )),
180+ },
181+ id = "NEMO indexing style U (C grid)" ,
182+ ),
183+ pytest .param (
184+ XGrid (xgcm .Grid (datasets ["ds_2d_right" ], periodic = False )),
185+ "V (C grid)" ,
186+ {
187+ "XC" : (np .int64 (0 ), np .float64 (0.5 )),
188+ "YG" : (np .int64 (0 ), np .float64 (0.0 )),
189+ "ZG" : (np .int64 (0 ), np .float64 (0.0 )),
190+ },
191+ id = "NEMO indexing style V (C grid)" ,
192+ ),
193+ ],
194+ )
195+ def test_xgrid_localize_zero_position (grid , da_name , expected ):
196+ """Test localize function using left and right datasets."""
197+ position = grid .search (0 , 0 , 0 )
198+ da = grid .xgcm_grid ._ds [da_name ]
199+
200+ local_position = grid .localize (position , da .dims )
201+ assert local_position == expected , f"Expected { expected } , got { local_position } "
0 commit comments