Skip to content

Commit 70f477c

Browse files
committed
Revert EWA-related changes
Revert "Fix pyproj Transform usage in ll2cr" This reverts commit 45408da. Revert "Remove unused CRS import in ll2cr cython" This reverts commit b23d662.
1 parent 22dd2e6 commit 70f477c

File tree

3 files changed

+27
-40
lines changed

3 files changed

+27
-40
lines changed

pyresample/ewa/_ll2cr.pyx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
__docformat__ = "restructuredtext en"
2424

2525
import numpy
26-
from pyproj import Transformer
27-
from pyproj.enums import TransformDirection
26+
from pyproj import Proj
2827

2928
cimport cython
3029
cimport numpy
3130

32-
from pyresample.utils.proj4 import get_geodetic_crs_with_no_datum_shift
33-
3431
numpy.import_array()
3532

3633
# column and rows can only be doubles for now until the PROJ.4 is linked directly so float->double casting can be done
@@ -43,18 +40,18 @@ cdef extern from "numpy/npy_math.h":
4340
bint npy_isnan(double x)
4441

4542

46-
def projection_circumference(t):
43+
def projection_circumference(p):
4744
"""Return the projection circumference if the projection is cylindrical, None otherwise.
4845
4946
Projections that are not cylindrical and centered on the globes axis
5047
can not easily have data cross the antimeridian of the projection.
5148
"""
52-
lon0, lat0 = t.transform(0, 0, direction=TransformDirection.INVERSE)
49+
lon0, lat0 = p(0, 0, inverse=True)
5350
lon1 = lon0 + 180.0
5451
lat1 = lat0 + 5.0
55-
x0, y0 = t.transform(lon0, lat0) # should result in zero or near zero
56-
x1, y1 = t.transform(lon1, lat0)
57-
x2, y2 = t.transform(lon1, lat1)
52+
x0, y0 = p(lon0, lat0) # should result in zero or near zero
53+
x1, y1 = p(lon1, lat0)
54+
x2, y2 = p(lon1, lat1)
5855
if y0 != y1 or x1 != x2:
5956
return 0.0
6057
return abs(x1 - x0) * 2
@@ -64,7 +61,7 @@ def projection_circumference(t):
6461
@cython.wraparound(False)
6562
@cython.cdivision(True)
6663
def ll2cr_dynamic(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtype, ndim=2] lat_arr,
67-
cr_dtype fill_in, object src_crs, object dst_crs,
64+
cr_dtype fill_in, str proj4_definition,
6865
double cell_width, double cell_height,
6966
width=None, height=None,
7067
origin_x=None, origin_y=None):
@@ -101,13 +98,13 @@ def ll2cr_dynamic(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtyp
10198
of limitations in pyproj.
10299
"""
103100
# pure python stuff for now
104-
t = Transformer.from_crs(src_crs, dst_crs, always_xy=True)
101+
p = Proj(proj4_definition)
105102

106103
# Pyproj currently makes a copy so we don't have to do anything special here
107-
cdef tuple projected_tuple = t.transform(lon_arr, lat_arr)
104+
cdef tuple projected_tuple = p(lon_arr, lat_arr)
108105
cdef cr_dtype[:, ::1] rows_out = projected_tuple[1]
109106
cdef cr_dtype[:, ::1] cols_out = projected_tuple[0]
110-
cdef double proj_circum = projection_circumference(t)
107+
cdef double proj_circum = projection_circumference(p)
111108
cdef unsigned int w
112109
cdef unsigned int h
113110
cdef double ox
@@ -206,7 +203,7 @@ def ll2cr_dynamic(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtyp
206203
@cython.wraparound(False)
207204
@cython.cdivision(True)
208205
def ll2cr_static(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtype, ndim=2] lat_arr,
209-
cr_dtype fill_in, object src_crs, object dst_crs,
206+
cr_dtype fill_in, str proj4_definition,
210207
double cell_width, double cell_height,
211208
unsigned int width, unsigned int height,
212209
double origin_x, double origin_y):
@@ -232,11 +229,11 @@ def ll2cr_static(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtype
232229
of limitations in pyproj.
233230
"""
234231
# TODO: Rewrite so it is no GIL
235-
# pure python stuff for now
236-
t = Transformer.from_crs(src_crs, dst_crs, always_xy=True)
232+
# pure python stuff for now
233+
p = Proj(proj4_definition)
237234

238235
# Pyproj currently makes a copy so we don't have to do anything special here
239-
cdef tuple projected_tuple = t.transform(lon_arr, lat_arr)
236+
cdef tuple projected_tuple = p(lon_arr, lat_arr)
240237
cdef cr_dtype[:, ::1] rows_out = projected_tuple[1]
241238
cdef cr_dtype[:, ::1] cols_out = projected_tuple[0]
242239
cdef cr_dtype[:, ::1] lons_view = lon_arr

pyresample/ewa/ewa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def ll2cr(swath_def, area_def, fill=np.nan, copy=True):
7676
ox = area_def.area_extent[0] + cw / 2.
7777
oy = area_def.area_extent[3] + ch / 2.
7878
swath_points_in_grid = _ll2cr.ll2cr_static(lons, lats, fill,
79-
swath_def.crs, area_def.crs, cw, ch, w, h, ox, oy)
79+
p, cw, ch, w, h, ox, oy)
8080
return swath_points_in_grid, lons, lats
8181

8282

pyresample/test/test_ewa_ll2cr.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import unittest
2222

2323
import numpy as np
24-
from pyproj import CRS
2524

2625
from pyresample.test.utils import create_test_latitude, create_test_longitude
2726

@@ -71,15 +70,14 @@ def test_lcc_basic1(self):
7170
lat_arr = create_test_latitude(18.0, 40.0, (50, 100), dtype=np.float64)
7271
grid_info = static_lcc.copy()
7372
fill_in = np.nan
74-
src_crs = CRS.from_epsg(4326)
75-
dst_crs = CRS.from_proj4(grid_info["proj4_definition"])
73+
proj_str = grid_info["proj4_definition"]
7674
cw = grid_info["cell_width"]
7775
ch = grid_info["cell_height"]
7876
ox = grid_info["origin_x"]
7977
oy = grid_info["origin_y"]
8078
w = grid_info["width"]
8179
h = grid_info["height"]
82-
points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, src_crs, dst_crs,
80+
points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str,
8381
cw, ch, w, h, ox, oy)
8482
self.assertEqual(points_in_grid, lon_arr.size, "all these test points should fall in this grid")
8583

@@ -94,15 +92,14 @@ def test_geo_antimeridian(self):
9492

9593
grid_info = static_geo_whole_earth.copy()
9694
fill_in = np.nan
97-
src_crs = CRS.from_epsg(4326)
98-
dst_crs = CRS.from_proj4(grid_info["proj4_definition"])
95+
proj_str = grid_info['proj4_definition']
9996
cw = grid_info['cell_width']
10097
ch = grid_info['cell_height']
10198
ox = grid_info['origin_x']
10299
oy = grid_info['origin_y']
103100
w = grid_info['width']
104101
h = grid_info['height']
105-
points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, src_crs, dst_crs,
102+
points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str,
106103
cw, ch, w, h, ox, oy)
107104
self.assertEqual(points_in_grid, lon_arr.size,
108105
'all these test points should fall in this grid')
@@ -113,15 +110,14 @@ def test_lcc_fail1(self):
113110
lat_arr = create_test_latitude(18.0, 40.0, (50, 100), dtype=np.float64)
114111
grid_info = static_lcc.copy()
115112
fill_in = np.nan
116-
src_crs = CRS.from_epsg(4326)
117-
dst_crs = CRS.from_proj4(grid_info["proj4_definition"])
113+
proj_str = grid_info["proj4_definition"]
118114
cw = grid_info["cell_width"]
119115
ch = grid_info["cell_height"]
120116
ox = grid_info["origin_x"]
121117
oy = grid_info["origin_y"]
122118
w = grid_info["width"]
123119
h = grid_info["height"]
124-
points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, src_crs, dst_crs,
120+
points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str,
125121
cw, ch, w, h, ox, oy)
126122
self.assertEqual(points_in_grid, 0, "none of these test points should fall in this grid")
127123

@@ -135,16 +131,14 @@ def test_latlong_basic1(self):
135131
lat_arr = create_test_latitude(15.0, 30.0, (50, 100), dtype=np.float64)
136132
grid_info = dynamic_wgs84.copy()
137133
fill_in = np.nan
138-
src_crs = CRS.from_epsg(4326)
139-
dst_crs = CRS.from_proj4(grid_info["proj4_definition"])
134+
proj_str = grid_info["proj4_definition"]
140135
cw = grid_info["cell_width"]
141136
ch = grid_info["cell_height"]
142137
ox = grid_info["origin_x"]
143138
oy = grid_info["origin_y"]
144139
w = grid_info["width"]
145140
h = grid_info["height"]
146-
points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in,
147-
src_crs, dst_crs,
141+
points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in, proj_str,
148142
cw, ch, w, h, ox, oy)
149143
self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid")
150144
self.assertIs(lon_arr, lon_res)
@@ -158,16 +152,14 @@ def test_latlong_basic2(self):
158152
lat_arr = create_test_latitude(15.0, 30.0, (50, 100), twist_factor=-0.1, dtype=np.float64)
159153
grid_info = dynamic_wgs84.copy()
160154
fill_in = np.nan
161-
src_crs = CRS.from_epsg(4326)
162-
dst_crs = CRS.from_proj4(grid_info["proj4_definition"])
155+
proj_str = grid_info["proj4_definition"]
163156
cw = grid_info["cell_width"]
164157
ch = grid_info["cell_height"]
165158
ox = grid_info["origin_x"]
166159
oy = grid_info["origin_y"]
167160
w = grid_info["width"]
168161
h = grid_info["height"]
169-
points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in,
170-
src_crs, dst_crs,
162+
points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in, proj_str,
171163
cw, ch, w, h, ox, oy)
172164
self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid")
173165
self.assertIs(lon_arr, lon_res)
@@ -181,16 +173,14 @@ def test_latlong_dateline1(self):
181173
lat_arr = create_test_latitude(15.0, 30.0, (50, 100), twist_factor=-0.1, dtype=np.float64)
182174
grid_info = dynamic_wgs84.copy()
183175
fill_in = np.nan
184-
src_crs = CRS.from_epsg(4326)
185-
dst_crs = CRS.from_proj4(grid_info["proj4_definition"])
176+
proj_str = grid_info["proj4_definition"]
186177
cw = grid_info["cell_width"]
187178
ch = grid_info["cell_height"]
188179
ox = grid_info["origin_x"]
189180
oy = grid_info["origin_y"]
190181
w = grid_info["width"]
191182
h = grid_info["height"]
192-
points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in,
193-
src_crs, dst_crs,
183+
points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in, proj_str,
194184
cw, ch, w, h, ox, oy)
195185
self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid")
196186
self.assertIs(lon_arr, lon_res)

0 commit comments

Comments
 (0)