From 65daeb19315a46c093d571c250325a5c30c7a463 Mon Sep 17 00:00:00 2001 From: Nat Wilson Date: Sun, 23 Apr 2017 11:37:27 -0700 Subject: [PATCH] remove dead code --- karta/crs.py | 25 +++---------------------- tests/crs_tests.py | 40 ++-------------------------------------- 2 files changed, 5 insertions(+), 60 deletions(-) diff --git a/karta/crs.py b/karta/crs.py index cda4c21..6fe55ce 100644 --- a/karta/crs.py +++ b/karta/crs.py @@ -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: @@ -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) diff --git a/tests/crs_tests.py b/tests/crs_tests.py index 8862d17..60cbe32 100644 --- a/tests/crs_tests.py +++ b/tests/crs_tests.py @@ -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) @@ -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 @@ -48,14 +46,10 @@ 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 @@ -63,7 +57,6 @@ def test_CartesianForward(self): 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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): @@ -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): @@ -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 @@ -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 @@ -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 @@ -238,7 +217,6 @@ 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", @@ -246,7 +224,6 @@ def test_equal1(self): 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", @@ -254,7 +231,6 @@ def test_equal2(self): 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", @@ -262,7 +238,6 @@ def test_not_equal1(self): 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", @@ -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 @@ -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)) @@ -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) @@ -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()