Skip to content

Commit dd0efea

Browse files
committed
small changes
1 parent c0ea755 commit dd0efea

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,12 @@ def test_resolution_meters_to_degrees(self):
370370
self.assertAlmostEqual(1.0, lon_deg, places=6)
371371

372372
# 222640 m ≈ 2 degrees latitude
373-
lat_deg, lon_deg = resolution_meters_to_degrees((222640, 111320), 0)
373+
(lon_deg, lat_deg) = resolution_meters_to_degrees((111320, 222640), 0)
374374
self.assertAlmostEqual(2.0, lat_deg, places=6)
375375
self.assertAlmostEqual(1.0, lon_deg, places=6)
376376

377377
# At 60 degrees latitude, longitude degrees shrink by cos(60°) = 0.5
378-
lat_deg, lon_deg = resolution_meters_to_degrees(111320, 60)
378+
(lon_deg, lat_deg) = resolution_meters_to_degrees(111320, 60)
379379
self.assertAlmostEqual(1.0, lat_deg, places=6)
380380
self.assertAlmostEqual(1.0 / 0.5, lon_deg, places=6) # 2 degrees
381381

xcube_resampling/gridmapping/coords.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,12 @@ def new_grid_mapping_from_coords(
296296
x_res, y_res = _to_int_or_float(x_res), _to_int_or_float(y_res)
297297
if xy_bbox is None:
298298
x_res_05, y_res_05 = x_res / 2, y_res / 2
299-
x_min = _to_int_or_float(x_coords[..., 0].min() - x_res_05)
300-
x_max = _to_int_or_float(x_coords[..., -1].max() + x_res_05)
301-
if x_max < x_min:
302-
x_min, x_max = x_max, x_min
299+
if np.any(x_coords[..., 0] > x_coords[..., -1]):
300+
x_min = _to_int_or_float(x_coords[..., -1].min() + x_res_05)
301+
x_max = _to_int_or_float(x_coords[..., 0].max() - x_res_05)
302+
else:
303+
x_min = _to_int_or_float(x_coords[..., 0].min() - x_res_05)
304+
x_max = _to_int_or_float(x_coords[..., -1].max() + x_res_05)
303305
if is_j_axis_up:
304306
y_min = _to_int_or_float(float(y_coords[0, ...].min()) - y_res_05)
305307
y_max = _to_int_or_float(float(y_coords[-1, ...].max()) + y_res_05)

xcube_resampling/gridmapping/regular.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ def new_regular_grid_mapping_from_bbox(
193193
"""
194194
if not isinstance(xy_res, tuple):
195195
xy_res = (xy_res, xy_res)
196-
x_size = int(np.ceil((bbox[2] - bbox[0]) / xy_res[1]))
197-
y_size = int(np.ceil(abs(bbox[3] - bbox[1]) / xy_res[0]))
196+
x_size = int(np.ceil((bbox[2] - bbox[0]) / xy_res[0]))
197+
y_size = int(np.ceil(abs(bbox[3] - bbox[1]) / xy_res[1]))
198198
return new_regular_grid_mapping(
199199
size=(x_size, y_size),
200200
xy_min=(bbox[0], bbox[1]),

xcube_resampling/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ def resolution_meters_to_degrees(
299299
if not isinstance(resolution, tuple):
300300
resolution = (resolution, resolution)
301301
return (
302-
resolution[0] / 111320,
303-
resolution[1] / (111320 * np.cos(np.deg2rad(latitude))),
302+
resolution[0] / (111320 * np.cos(np.deg2rad(latitude))),
303+
resolution[1] / 111320,
304304
)
305305

306306

0 commit comments

Comments
 (0)