Skip to content

Commit 559bd7c

Browse files
committed
Initial antimeridian handling refactoring
1 parent 1f974b5 commit 559bd7c

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

pyresample/geometry.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,19 +1242,13 @@ def freeze(self, lonslats=None, resolution=None, shape=None, proj_info=None,
12421242
projections and data cases not covering the north or south pole.
12431243
The possible options are:
12441244
1245-
* "modify_extents": Set the X bounds to the edges of the data, but
1246-
add 360 to the right-most bound. This has the effect of making
1247-
the area coordinates continuous from the left side to the
1248-
right side. However, this means that some coordinates will be
1249-
outside the coordinate space of the projection. Although most
1250-
PROJ and pyresample functionality can handle this there may be
1251-
some edge cases.
1252-
* "modify_crs": Change the prime meridian of the projection
1253-
from 0 degrees longitude to 180 degrees longitude. This has
1254-
the effect of putting the data on a continuous coordinate
1245+
* "modify_extents": Deprecated. Use "modify_crs".
1246+
* "modify_crs": Modify the projection definition to wrap longitude
1247+
values so they are between 0 and 360 degrees (PROJ ``lon_wrap=180``).
1248+
This has the effect of putting the data on a continuous coordinate
12551249
system. However, this means that comparing data resampled to
1256-
this resulting area and an area not over the anti-meridian
1257-
would be more difficult.
1250+
this resulting area and an area not using this longitude
1251+
wrapping may require extra care.
12581252
* "global_extents": Ignore the bounds of the data and use -180/180
12591253
degrees as the west and east bounds of the data. This will
12601254
generate a large output area, but with the benefit of keeping
@@ -1265,6 +1259,10 @@ def freeze(self, lonslats=None, resolution=None, shape=None, proj_info=None,
12651259
Shape parameters are ignored if the instance is created
12661260
with the `optimize_projection` flag set to True.
12671261
"""
1262+
if antimeridian_mode == "modify_extents":
1263+
warnings.warn("Antimeridian mode 'modify_extents' is deprecated. Use 'modify_crs' instead.", stacklevel=2)
1264+
antimeridian_mode = "modify_crs"
1265+
12681266
with ignore_pyproj_proj_warnings():
12691267
proj_dict = self._get_proj_dict()
12701268
projection = self._projection
@@ -1311,7 +1309,7 @@ def _compute_bound_centers(self, proj_dict, lonslats, antimeridian_mode):
13111309
# cross anti-meridian of projection
13121310
xmin, xmax = self._compute_new_x_corners_for_antimeridian(xarr, antimeridian_mode)
13131311
if antimeridian_mode == "modify_crs":
1314-
proj_dict.update({"pm": 180.0})
1312+
proj_dict.update({"lon_wrap": 180})
13151313
return proj_dict, (xmin, ymin, xmax, ymax)
13161314

13171315
@staticmethod
@@ -1334,9 +1332,6 @@ def _compute_new_x_corners_for_antimeridian(self, xarr, antimeridian_mode):
13341332
xmax = np.nanmax(wrapped_array)
13351333
if hasattr(wrapped_array, "compute"):
13361334
xmin, xmax = da.compute(xmin, xmax)
1337-
if antimeridian_mode == "modify_crs":
1338-
xmin -= 180
1339-
xmax -= 180
13401335
return xmin, xmax
13411336

13421337

pyresample/kd_tree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ def _create_resample_kdtree(self, chunks=CHUNK_SIZE):
973973
chunks=chunks)
974974
valid_input_idx = ((source_lons >= -180) & (source_lons <= 180) & (source_lats <= 90) & (source_lats >= -90))
975975
input_coords = lonlat2xyz(source_lons, source_lats)
976+
976977
input_coords = input_coords[valid_input_idx.ravel(), :]
977978

978979
# Build kd-tree on input

pyresample/utils/proj4.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ def ignore_pyproj_proj_warnings():
180180
def get_geodetic_crs_with_no_datum_shift(crs: CRS) -> CRS:
181181
"""Get the geodetic CRS for the provided CRS but with no prime meridian shift."""
182182
gcrs = crs.geodetic_crs
183-
if gcrs.prime_meridian.longitude == 0:
184-
return gcrs
183+
# if gcrs.prime_meridian.longitude == 0 and gcrs.lon:
184+
# return gcrs
185185
with ignore_pyproj_proj_warnings():
186186
gcrs_dict = gcrs.to_dict()
187187
gcrs_dict.pop("pm", None)
188+
# gcrs_dict.pop("lon_wrap", None)
188189
gcrs_pm0 = CRS.from_dict(gcrs_dict)
189190
return gcrs_pm0

0 commit comments

Comments
 (0)