Skip to content

Commit 9edbb32

Browse files
committed
resolve pyproj deprecation
1 parent f154a72 commit 9edbb32

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

pyxlma/coords.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CoordinateSystem(object):
2727
transformations to/from an ECEF cartesian system, e.g.
2828
>>> self.ERSxyz = proj4.Proj(proj='geocent', ellps='WGS84', datum='WGS84')
2929
>>> self.ERSlla = proj4.Proj(proj='latlong', ellps='WGS84', datum='WGS84')
30-
>>> projectedData = proj4.transform(self.ERSlla, self.ERSxyz, lat, lon, alt )
30+
>>> projectedData = proj4.Transformer.from_crs(self.ERSlla.crs, self.ERSxyz.crs).transform(lon, lat, alt)
3131
The ECEF system has its origin at the center of the earth, with the +Z toward the north pole,
3232
+X toward (lat=0, lon=0), and +Y right-handed orthogonal to +X, +Z
3333
@@ -80,7 +80,7 @@ def toECEF(self, lon, lat, alt):
8080
lon = atleast_1d(lon)
8181
alt = atleast_1d(alt)
8282
if (lat.shape[0] == 0): return lon, lat, alt # proj doesn't like empties
83-
projectedData = array(proj4.transform(self.ERSlla, self.ERSxyz, lon, lat, alt ))
83+
projectedData = array(proj4.Transformer.from_crs(self.ERSlla.crs, self.ERSxyz.crs).transform(lon, lat, alt))
8484
if len(projectedData.shape) == 1:
8585
return projectedData[0], projectedData[1], projectedData[2]
8686
else:
@@ -91,7 +91,7 @@ def fromECEF(self, x, y, z):
9191
y = atleast_1d(y)
9292
z = atleast_1d(z)
9393
if (x.shape[0] == 0): return x, y, z # proj doesn't like empties
94-
projectedData = array(proj4.transform(self.ERSxyz, self.ERSlla, x, y, z ))
94+
projectedData = array(proj4.Transformer.from_crs(self.ERSxyz.crs, self.ERSlla.crs).transform(x, y, z))
9595
if len(projectedData.shape) == 1:
9696
return projectedData[0], projectedData[1], projectedData[2]
9797
else:
@@ -125,15 +125,15 @@ def toECEF(self, x, y, z):
125125
x += self.cx
126126
y += self.cy
127127
z += self.cz
128-
projectedData = array(proj4.transform(self.projection, self.ERSxyz, x, y, z ))
128+
projectedData = array(proj4.Transformer.from_crs(self.projection.crs, self.ERSxyz.crs).transform(x, y, z))
129129
if len(projectedData.shape) == 1:
130130
px, py, pz = projectedData[0], projectedData[1], projectedData[2]
131131
else:
132132
px, py, pz = projectedData[0,:], projectedData[1,:], projectedData[2,:]
133133
return px, py, pz
134134

135135
def fromECEF(self, x, y, z):
136-
projectedData = array(proj4.transform(self.ERSxyz, self.projection, x, y, z ))
136+
projectedData = array(proj4.Transformer.from_crs(self.ERSxyz.crs, self.projection.crs).transform(x, y, z))
137137
if len(projectedData.shape) == 1:
138138
px, py, pz = projectedData[0], projectedData[1], projectedData[2]
139139
else:
@@ -221,10 +221,10 @@ def __init__(self, subsat_lon=0.0, subsat_lat=0.0, sweep_axis='y',
221221

222222
def toECEF(self, x, y, z):
223223
X, Y, Z = x*self.h, y*self.h, z*self.h
224-
return proj4.transform(self.fixedgrid, self.ECEFxyz, X, Y, Z)
224+
return proj4.Transformer.from_crs(self.fixedgrid.crs, self.ECEFxyz.crs).transform(X, Y, Z)
225225

226226
def fromECEF(self, x, y, z):
227-
X, Y, Z = proj4.transform(self.ECEFxyz, self.fixedgrid, x, y, z)
227+
X, Y, Z = proj4.Transformer.from_crs(self.ECEFxyz.crs, self.fixedgrid.crs).transform(x, y, z)
228228
return X/self.h, Y/self.h, Z/self.h
229229

230230
# class AltitudePreservingMapProjection(MapProjection):
@@ -253,8 +253,8 @@ def __init__(self, ctrLat, ctrLon, ctrAlt, datum='WGS84', ellps='WGS84', effecti
253253
self.lla = proj4.Proj(proj='latlong', ellps=self.ellps, datum=self.datum)
254254
self.xyz = proj4.Proj(proj='geocent', ellps=self.ellps, datum=self.datum)
255255

256-
self.Requator, foo1, foo2 = proj4.transform(self.lla,self.xyz,0,0,0) # Equatorial radius - WGS-84 value = 6378137.0
257-
foo1, foo2, self.Rpolar = proj4.transform(self.lla,self.xyz,0,90,0) # Polar radius - WGS-84 value = 6356752.314
256+
self.Requator, _, _ = proj4.Transformer.from_crs(self.lla.crs, self.xyz.crs).transform(0,0,0) # Equatorial radius - WGS-84 value = 6378137.0
257+
_, _, self.Rpolar = proj4.Transformer.from_crs(self.lla.crs, self.xyz.crs).transform(0,90,0) # Polar radius - WGS-84 value = 6356752.314
258258
self.flattening = (self.Requator-self.Rpolar)/self.Requator
259259

260260
self.eccen = (2.0-self.flattening)*self.flattening # First eccentricity squared - WGS-84 value = 0.00669437999013
@@ -374,10 +374,10 @@ def __init__(self, ctrLat=0.0, ctrLon=0.0, ctrAlt=0.0):
374374

375375
ERSlla = proj4.Proj(proj='latlong', ellps='WGS84', datum='WGS84')
376376
ERSxyz = proj4.Proj(proj='geocent', ellps='WGS84', datum='WGS84')
377-
self.centerECEF = array(proj4.transform(ERSlla, ERSxyz, ctrLon, ctrLat, ctrAlt))
377+
self.centerECEF = array(proj4.Transformer.from_crs(ERSlla.crs, ERSxyz.crs).transform(ctrLon, ctrLat, ctrAlt))
378378

379379
#location of point directly above local center
380-
aboveCenterECEF = array(proj4.transform(ERSlla, ERSxyz, ctrLon, ctrLat, self.ctrAlt+1e3))
380+
aboveCenterECEF = array(proj4.Transformer.from_crs(ERSlla.crs, ERSxyz.crs).transform(ctrLon, ctrLat, self.ctrAlt+1e3))
381381

382382
#normal vector to earth's surface at the center is the local z direction
383383
n = aboveCenterECEF - self.centerECEF
@@ -396,7 +396,7 @@ def __init__(self, ctrLat=0.0, ctrLon=0.0, ctrAlt=0.0):
396396
# Point just to the north of the center on earth's surface, projected onto the tangent plane
397397
# This calculation seems like it should only be done with latitude/north since the local x
398398
# direction curves away along a non-straight line when projected onto the plane
399-
northCenterECEF = array(proj4.transform(ERSlla, ERSxyz, self.ctrLon, self.ctrLat+1.01, self.ctrAlt))
399+
northCenterECEF = array(proj4.Transformer.from_crs(ERSlla.crs, ERSxyz.crs).transform(self.ctrLon, self.ctrLat+1.01, self.ctrAlt))
400400
localy = dot(P, northCenterECEF[:,None] )
401401
localy = localy / norm(localy)
402402

tests/test_coords.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def test_geographic():
3131
def test_geographic_one_point():
3232
geosys = GeographicSystem()
3333
ecef_coords = geosys.toECEF(np.atleast_1d(test_lons[-1]), np.atleast_1d(test_lats[-1]), np.atleast_1d(test_alts[-1]))
34-
print(len(np.atleast_1d(test_lons[-1]).shape))
3534
lons, lats, alts = geosys.fromECEF(*ecef_coords)
3635

3736
assert np.allclose(ecef_coords[0], test_ecef_X[-1])
@@ -119,7 +118,6 @@ def test_radar_system_height():
119118
def test_radar_system_elevation():
120119
ADRAD_rcs = RadarCoordinateSystem(30.6177, -96.3365, 114)
121120
tornado_slant_range, radar_elevation = ADRAD_rcs.getSlantRangeElevation(17144.013390611748, 550.2784673999995)
122-
print(tornado_slant_range, radar_elevation)
123121
assert np.allclose(tornado_slant_range, 17150)
124122
assert np.allclose(radar_elevation, 1.4)
125123

0 commit comments

Comments
 (0)