Skip to content

Commit

Permalink
remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
njwilson23 committed Apr 23, 2017
1 parent 95bd455 commit 65daeb1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 60 deletions.
25 changes: 3 additions & 22 deletions karta/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,6 @@
"WGS84": (6378137.0, None, 298.257223563, "WGS 84"),
"sphere": (6370997.0, 6370997.0, None, "Normal Sphere (r=6370997)")}

def ellipsoid_major_axis(name):
a, _, _ = ELLIPSOID_DATA[name]
return a

def ellipsoid_minor_axis(name):
a, b, rf = ELLIPSOID_DATA[name]
if b is None:
b = a-a/rf
return b

def ellipsoid_flattening(name):
a, b, rf = ELLIPSOID_DATA[name]
if rf is None:
rf = a/(a-b)
return 1.0/rf

class Ellipsoid(object):
def __init__(self, name, a=None, b=None, f=None, rf=None):
if a is None:
Expand Down Expand Up @@ -285,14 +269,11 @@ def __init__(self, proj, name=None):
return

def __eq__(self, other):
if (not hasattr(other, "_proj")) or (not hasattr(other, "_geod")):
return False

if (getattr(self._proj, "srs", 0) == getattr(other._proj, "srs", 1) and
if (hasattr(other, "_proj") and hasattr(other, "_geod") and
getattr(self._proj, "srs", 0) == getattr(other._proj, "srs", 1) and
getattr(self._geod, "initstring", 0) == getattr(other._geod, "initstring", 1)):
return True
else:
return False
return False

def __ne__(self, other):
return not self.__eq__(other)
Expand Down
40 changes: 2 additions & 38 deletions tests/crs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ def assertTuplesAlmostEqual(self, a, b, tol=1e-8):
for _a, _b in zip(a, b):
if abs(_a-_b) > tol:
unittest.fail()
return

def test_get_proj4(self):
c0 = crs.SphericalEarth
self.assertEqual(c0.get_proj4(), "+proj=lonlat +ellps=sphere +datum=WGS84")

c1 = crs.LonLatWGS84
proj4 = c1.get_proj4()
proj4 = c1.proj4
self.assertTrue("+proj=lonlat" in proj4)
self.assertTrue("+ellps=WGS84" in proj4)

c2 = crs.NSIDCNorth
proj4 = c2.get_proj4()
proj4 = c2.proj4
self.assertTrue("+proj=stere" in proj4)
self.assertTrue("+lat_0=90" in proj4)
self.assertTrue("+lat_ts=70" in proj4)
Expand All @@ -36,7 +35,6 @@ def test_get_proj4(self):
self.assertTrue("+y_0=0" in proj4)
self.assertTrue("+units=m" in proj4)
self.assertTrue("+datum=WGS84" in proj4)
return

def test_get_wkt(self):
c0 = crs.SphericalEarth
Expand All @@ -48,22 +46,17 @@ def test_get_wkt(self):

c2 = crs.NSIDCNorth
self.assertTrue('PROJCS["unnamed",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.25722' in c2.wkt)
#self.assertTrue('AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329' in c2.wkt)
#self.assertTrue('AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]],PROJECTION["Polar_Stereographic"],PARAMETER["latitude_of_origin",70],PARAMETER["central_meridian",-45],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1]]' in c2.wkt)
return

def test_CartesianProj(self):
xp, yp = crs.Cartesian.project(3.0, 4.0)
self.assertEqual((xp, yp), (3.0, 4.0))
return

def test_CartesianForward(self):
az = math.atan(0.75) * 180.0 / math.pi
lons, lats, backaz = crs.Cartesian.forward(0.0, 0.0, az, 5)
self.assertAlmostEqual(lons, 3.0, places=12)
self.assertAlmostEqual(lats, 4.0, places=12)
self.assertAlmostEqual(backaz, az+180.0, places=12)
return

def test_CartesianInverse(self):
lon0 = 367.0
Expand All @@ -79,7 +72,6 @@ def test_CartesianInverse(self):
self.assertAlmostEqual(d_ans, d, places=12)
self.assertAlmostEqual(az_ans, az, places=12)
self.assertAlmostEqual(baz_ans, baz, places=12)
return

def test_CartesianInverse2(self):
lon0 = 367.0
Expand All @@ -95,7 +87,6 @@ def test_CartesianInverse2(self):
self.assertAlmostEqual(d_, d, places=12)
self.assertAlmostEqual(az_, az, places=12)
self.assertAlmostEqual(baz_, baz, places=12)
return

def test_SphericalForward1(self):
lon1 = 0.0
Expand All @@ -105,7 +96,6 @@ def test_SphericalForward1(self):
self.assertAlmostEqual(lon2, 45.000084759104425, places=8)
self.assertAlmostEqual(lat2, 0.0, places=8)
self.assertAlmostEqual(baz, -90.0, places=8)
return

def test_SphericalForward2(self):
lon1 = 30.0
Expand All @@ -115,7 +105,6 @@ def test_SphericalForward2(self):
self.assertAlmostEqual(lon2, 75.00008475910442, places=8)
self.assertAlmostEqual(lat2, 0.0, places=8)
self.assertAlmostEqual(baz, -90.0, places=8)
return

def test_SphericalForward3(self):
lon1 = -120.0
Expand All @@ -125,7 +114,6 @@ def test_SphericalForward3(self):
self.assertAlmostEqual(lon2, -146.51186194714958, places=6)
self.assertAlmostEqual(lat2, 57.99979808258465, places=6)
self.assertAlmostEqual(baz, 108.48890006687964, places=6)
return

def test_SphericalInverse1(self):
lon1 = 0.0
Expand All @@ -136,7 +124,6 @@ def test_SphericalInverse1(self):
self.assertEqual(az, -90.0)
self.assertEqual(baz, 90.0)
self.assertAlmostEqual(dist, 5003769.342810653, places=6)
return

def test_SphericalInverse2(self):
lon1 = 32.0
Expand All @@ -147,7 +134,6 @@ def test_SphericalInverse2(self):
self.assertAlmostEqual(az, 15.597740818516172, places=6)
self.assertAlmostEqual(baz, -165.04174639642943, places=6)
self.assertAlmostEqual(dist, 2533567.302751705, places=6)
return

def test_SphericalInverse3(self):
lon1 = 32.0
Expand All @@ -158,7 +144,6 @@ def test_SphericalInverse3(self):
self.assertAlmostEqual(az, 165.0417463964294, places=6)
self.assertAlmostEqual(baz, -15.597740818516172, places=6)
self.assertAlmostEqual(dist, 2533567.302751705, places=6)
return

def test_SphericalArea(self):
r = 6378137.0
Expand All @@ -168,7 +153,6 @@ def test_SphericalArea(self):
y2 = 41.79331020506
S12 = karta.geodesy.spherical_area(r, x1, y1, x2, y2)
self.assertAlmostEqual(abs(S12)/1e6, 84516702.1955, places=4)
return

def test_SphericalArea_dateline(self):
r = 6378137.0
Expand All @@ -178,7 +162,6 @@ def test_SphericalArea_dateline(self):
y2 = 41.79331020506
S12 = karta.geodesy.spherical_area(r, x1, y1, x2, y2)
self.assertAlmostEqual(abs(S12)/1e6, 84516702.1955, places=4)
return


def test_SphericalIntersection(self):
Expand All @@ -193,7 +176,6 @@ def test_SphericalIntersection(self):
self.assertRaises(karta.errors.NoIntersection,
lambda: geodesy.intersection_spherical([(45, 0), (230, 0)],
[(50, -10), (50, 10)]))
return


def test_EllipsoidalEquatorialAzimuth(self):
Expand All @@ -204,7 +186,6 @@ def test_EllipsoidalEquatorialAzimuth(self):
az2, baz2, _ = crs.LonLatWGS84.inverse(180.0, 0.0, 5, 0.0)
self.assertEqual(az2, -90)
self.assertEqual(baz2, 90)
return

def test_EllipsoidalArea(self):
a = 6378137.0
Expand All @@ -215,7 +196,6 @@ def test_EllipsoidalArea(self):
y2 = 41.79331020506
S12 = karta.geodesy.ellipsoidal_area(a, b, x1, y1, x2, y2)
self.assertAlmostEqual(abs(S12)/1e6, 84275623.42235, places=4)
return

def test_EllipsoidalArea_dateline(self):
a = 6378137.0
Expand All @@ -226,7 +206,6 @@ def test_EllipsoidalArea_dateline(self):
y2 = 41.79331020506
S12 = karta.geodesy.ellipsoidal_area(a, b, x1, y1, x2, y2)
self.assertAlmostEqual(abs(S12)/1e6, 84275623.42235, places=4)
return

def test_ConstructProj4(self):
# Canonical constructor
Expand All @@ -238,31 +217,27 @@ def test_ConstructProj4(self):
# Fail if no geodetic information given
self.assertRaises(karta.errors.CRSError,
lambda: crs.ProjectedCRS("+proj=longlat +no_defs"))
return

def test_equal1(self):
WGS84 = crs.ProjectedCRS("+proj=longlat +datum=WGS84 +no_defs",
name="WGS84 (Geographical)")
WGS84_ = crs.ProjectedCRS("+proj=longlat +datum=WGS84 +no_defs",
name="WGS84 (Geographical)")
self.assertTrue(WGS84 == WGS84_)
return

def test_equal2(self):
WGS84 = crs.ProjectedCRS("+proj=longlat +datum=WGS84 +no_defs",
name="WGS84 (Geographical)")
NAD83 = crs.ProjectedCRS("+proj=longlat +datum=NAD83 +no_defs",
name="NAD83 (Geographical)")
self.assertTrue(not WGS84 == NAD83)
return

def test_not_equal1(self):
WGS84 = crs.ProjectedCRS("+proj=longlat +datum=WGS84 +no_defs",
name="WGS84 (Geographical)")
NAD83 = crs.ProjectedCRS("+proj=longlat +datum=NAD83 +no_defs",
name="NAD83 (Geographical)")
self.assertTrue(WGS84 != NAD83)
return

def test_not_equal2(self):
WGS84 = crs.ProjectedCRS("+proj=longlat +datum=WGS84 +no_defs",
Expand All @@ -271,7 +246,6 @@ def test_not_equal2(self):
WGS84_ = crs.ProjectedCRS("+proj=longlat +datum=WGS84 +no_defs",
name="WGS84 (Geographical)")
self.assertTrue(not WGS84 != WGS84_)
return

def test_export_wkt_same_as_parent(self):
# Checks for bug that occured where shapefiles saved with NSIDCNorth
Expand Down Expand Up @@ -304,7 +278,6 @@ def assertTuplesAlmostEqual(self, a, b, tol=1e-8):
for _a, _b in zip(a, b):
if abs(_a-_b) > tol:
self.fail()
return

def test_isbetween_circular(self):
self.assertTrue(geodesy.isbetween_circular(90, 80, 100))
Expand All @@ -314,20 +287,17 @@ def test_isbetween_circular(self):
self.assertFalse(geodesy.isbetween_circular(60, 90, -110))
self.assertFalse(geodesy.isbetween_circular(50, 45, 226))
self.assertFalse(geodesy.isbetween_circular(50, 45, 225))
return

def test_cross_3d(self):
self.assertEqual(geodesy.cross((0, 0, 1), (0, 0, 1)), (0, 0, 0))
self.assertEqual(geodesy.cross((0, 0, 1), (1, 0, 0)), (0, 1, 0))
self.assertEqual(geodesy.cross((1, 0, 0), (0, 0, 1)), (0, -1, 0))
return

def test_cart2sph(self):
self.assertTuplesAlmostEqual(geodesy.cart2sph(1, 1, 1),
(45.0, 35.2643896827))
self.assertTuplesAlmostEqual(geodesy.cart2sph(1, 0, 1), (0.0, 45.0))
self.assertTuplesAlmostEqual(geodesy.cart2sph(-1, 1, 0), (135.0, 0.0))
return

def test_EllipsoidalForward(self):
np.random.seed(43)
Expand Down Expand Up @@ -366,34 +336,28 @@ def test_EllipsoidalNearAntipodalInverse(self):
self.assertAlmostEqual(az, az_, places=4)
self.assertAlmostEqual(baz, baz_, places=4)
self.assertAlmostEqual(d, d_, places=4)
return

def test_brent1(self):
def forsythe(x):
return x**3 - 2*x - 5
self.assertAlmostEqual(2.094551482,
geodesy.fzero_brent(2, 3, forsythe, 1e-12))
return

def test_brent2(self):
self.assertAlmostEqual(0.7390851332,
geodesy.fzero_brent(0, 1, lambda x: math.cos(x)-x, 1e-12))
return

def test_brent3(self):
self.assertAlmostEqual(0.0,
geodesy.fzero_brent(-1, 1, lambda x: math.sin(x)-x, 1e-12))
return

def test_brent4(self):
self.assertAlmostEqual(0.0,
geodesy.fzero_brent(0, 1, lambda x: math.sin(x)-x, 1e-12))
return

def test_brent_bracket_error(self):
self.assertRaises(ValueError,
geodesy.fzero_brent, 0.2, 2, lambda x: math.sin(x)-x, 1e-12)
return

if __name__ == "__main__":
unittest.main()
Expand Down

0 comments on commit 65daeb1

Please sign in to comment.