Beispiel #1
0
    def test_globe(self):
        # Ensure the globe affects output.
        rugby_globe = ccrs.Globe(semimajor_axis=9000000,
                                 semiminor_axis=9000000,
                                 ellipse=None)
        footy_globe = ccrs.Globe(semimajor_axis=1000000,
                                 semiminor_axis=1000000,
                                 ellipse=None)

        rugby_moll = ccrs.Mollweide(globe=rugby_globe)
        footy_moll = ccrs.Mollweide(globe=footy_globe)

        rugby_pt = rugby_moll.transform_point(
            10,
            10,
            rugby_moll.as_geodetic(),
        )
        footy_pt = footy_moll.transform_point(
            10,
            10,
            footy_moll.as_geodetic(),
        )

        assert_arr_almost_eq(rugby_pt, (1400915, 1741319), decimal=0)
        assert_arr_almost_eq(footy_pt, (155657, 193479), decimal=0)
Beispiel #2
0
def test_transform_points():
    # these always worked
    result = _CRS_ROB.transform_points(_CRS_PC, np.array([35.0]),
                                       np.array([70.0]))
    assert_arr_almost_eq(result, [[2376187.159105642, 7275318.947140937, 0]])

    result = _CRS_ROB.transform_points(_CRS_PC, np.array([35.0]),
                                       np.array([70.0]), np.array([0.0]))
    assert_arr_almost_eq(result, [[2376187.159105642, 7275318.947140937, 0]])

    # this always did something, but result has altered
    result = _CRS_ROB.transform_points(_CRS_PC, np.array([_NAN]),
                                       np.array([70.0]))
    assert_true(np.all(np.isnan(result)))

    # this used to crash + is now fixed
    result = _CRS_ROB.transform_points(_CRS_PC, np.array([35.0]),
                                       np.array([_NAN]))
    assert_true(np.all(np.isnan(result)))

    # multipoint case
    x = np.array([10.0, 21.0, 0.0, 77.7, _NAN, 0.0])
    y = np.array([10.0, _NAN, 10.0, 77.7, 55.5, 0.0])
    z = np.array([10.0, 0.0, 0.0, _NAN, 55.5, 0.0])
    expect_result = np.array([[9.40422591e+05, 1.06952091e+06, 1.00000000e+01],
                              [11.1, 11.2, 11.3], [0.0, 1069520.91213902, 0.0],
                              [22.1, 22.2, 22.3], [33.1, 33.2, 33.3],
                              [0.0, 0.0, 0.0]])
    result = _CRS_ROB.transform_points(_CRS_PC, x, y, z)
    assert_equal(result.shape, (6, 3))
    assert_true(np.all(np.isnan(result[[1, 3, 4], :])))
    result[[1, 3, 4], :] = expect_result[[1, 3, 4], :]
    assert_false(np.any(np.isnan(result)))
    assert_true(np.allclose(result, expect_result))
Beispiel #3
0
    def _check_osgb(self, osgb):
        precision = 1

        if os.environ.get('PROJ_NETWORK') != 'ON':
            grid_name = 'uk_os_OSTN15_NTv2_OSGBtoETRS.tif'
            available = (Path(
                pyproj.datadir.get_data_dir(), grid_name).exists() or Path(
                    pyproj.datadir.get_user_data_dir(), grid_name).exists())
            if not available:
                import warnings
                warnings.warn(f'{grid_name} is unavailable; '
                              'testing OSGB at reduced precision')
                precision = -1

        ll = ccrs.Geodetic()

        # results obtained by streetmap.co.uk.
        lat, lon = np.array([50.462023, -3.478831], dtype=np.double)
        east, north = np.array([295132.1, 63512.6], dtype=np.double)

        # note the handling of precision here...
        assert_almost_equal(osgb.transform_point(lon, lat, ll), [east, north],
                            decimal=precision)
        assert_almost_equal(ll.transform_point(east, north, osgb), [lon, lat],
                            decimal=2)

        r_lon, r_lat = ll.transform_point(east, north, osgb)
        r_inverted = np.array(osgb.transform_point(r_lon, r_lat, ll))
        assert_arr_almost_eq(r_inverted, [east, north], 3)

        r_east, r_north = osgb.transform_point(lon, lat, ll)
        r_inverted = np.array(ll.transform_point(r_east, r_north, osgb))
        assert_arr_almost_eq(r_inverted, [lon, lat])
def test_transform_point():
    # this way has always worked
    result = _CRS_ROB.transform_point(35.0, 70.0, _CRS_PC)
    assert_arr_almost_eq(result, (2376187.27182751, 7275317.81573085), _TOL)

    # this always did something, but result has altered
    result = _CRS_ROB.transform_point(_NAN, 70.0, _CRS_PC)
    assert_true(np.all(np.isnan(result)))

    # this used to crash + is now fixed
    result = _CRS_ROB.transform_point(35.0, _NAN, _CRS_PC)
    assert_true(np.all(np.isnan(result)))
Beispiel #5
0
def test_transform_point():
    # this way has always worked
    result = _CRS_ROB.transform_point(35.0, 70.0, _CRS_PC)
    assert_arr_almost_eq(result, (2376187.159105642, 7275318.947140937))

    # this always did something, but result has altered
    result = _CRS_ROB.transform_point(_NAN, 70.0, _CRS_PC)
    assert_true(np.all(np.isnan(result)))

    # this used to crash + is now fixed
    result = _CRS_ROB.transform_point(35.0, _NAN, _CRS_PC)
    assert_true(np.all(np.isnan(result)))
Beispiel #6
0
def test_transform_point():
    # this way has always worked
    result = _CRS_ROB.transform_point(35.0, 70.0, _CRS_PC)
    assert_arr_almost_eq(result, (2376187.27182751, 7275317.81573085), _TOL)

    # this always did something, but result has altered
    result = _CRS_ROB.transform_point(_NAN, 70.0, _CRS_PC)
    assert_true(np.all(np.isnan(result)))

    # this used to crash + is now fixed
    result = _CRS_ROB.transform_point(35.0, _NAN, _CRS_PC)
    assert_true(np.all(np.isnan(result)))
Beispiel #7
0
def test_transform_point():
    # this way has always worked
    result = _CRS_ROB.transform_point(35.0, 70.0, _CRS_PC)
    assert_arr_almost_eq(result, (2376187.159105642, 7275318.947140937))

    # this always did something, but result has altered
    result = _CRS_ROB.transform_point(_NAN, 70.0, _CRS_PC)
    assert_true(np.all(np.isnan(result)))

    # this used to crash + is now fixed
    result = _CRS_ROB.transform_point(35.0, _NAN, _CRS_PC)
    assert_true(np.all(np.isnan(result)))
Beispiel #8
0
    def test_osni(self):
        osni = ccrs.OSNI()
        ll = ccrs.Geodetic()

        # results obtained by nearby.org.uk.
        lat, lon = np.array([54.5622169298669, -5.54159863617957],
                            dtype=np.double)
        east, north = np.array([359000, 371000], dtype=np.double)

        assert_arr_almost_eq(osni.transform_point(lon, lat, ll),
                             np.array([east, north]), -1)
        assert_arr_almost_eq(ll.transform_point(east, north, osni),
                             np.array([lon, lat]), 3)
Beispiel #9
0
    def test_globe(self):
        # Ensure the globe affects output.
        rugby_globe = ccrs.Globe(semimajor_axis=9000000,
                                 semiminor_axis=1000000)
        footy_globe = ccrs.Globe(semimajor_axis=1000000,
                                 semiminor_axis=1000000)

        rugby_moll = ccrs.Mollweide(globe=rugby_globe)
        footy_moll = ccrs.Mollweide(globe=footy_globe)

        rugby_pt = rugby_moll.transform_point(10, 10, ccrs.Geodetic())
        footy_pt = footy_moll.transform_point(10, 10, ccrs.Geodetic())

        assert_arr_almost_eq(rugby_pt, (1400915, 1741319), decimal=0)
        assert_arr_almost_eq(footy_pt, (155657, 193479), decimal=0)
Beispiel #10
0
    def test_osni(self):
        osni = ccrs.OSNI()
        ll = ccrs.Geodetic()

        # results obtained by nearby.org.uk.
        lat, lon = np.array([54.5622169298669, -5.54159863617957],
                            dtype=np.double)
        east, north = np.array([359000, 371000], dtype=np.double)

        assert_arr_almost_eq(osni.transform_point(lon, lat, ll),
                             np.array([east, north]),
                             -1)
        assert_arr_almost_eq(ll.transform_point(east, north, osni),
                             np.array([lon, lat]),
                             3)
Beispiel #11
0
    def test_transform_points_nD(self):
        rlons = np.array([[350., 352., 354.], [350., 352., 354.]])
        rlats = np.array([[-5., -0., 1.], [-4., -1., 0.]])

        src_proj = ccrs.RotatedGeodetic(pole_longitude=178.0,
                                        pole_latitude=38.0)
        target_proj = ccrs.Geodetic()
        res = target_proj.transform_points(x=rlons, y=rlats, src_crs=src_proj)
        unrotated_lon = res[..., 0]
        unrotated_lat = res[..., 1]

        # Solutions derived by proj4 direct.
        solx = np.array([[-16.42176094, -14.85892262, -11.90627520],
                         [-16.71055023, -14.58434624, -11.68799988]])
        soly = np.array([[46.00724251, 51.29188893, 52.59101488],
                         [46.98728486, 50.30706042, 51.60004528]])
        assert_arr_almost_eq(unrotated_lon, solx)
        assert_arr_almost_eq(unrotated_lat, soly)
Beispiel #12
0
    def test_transform_points_1D(self):
        rlons = np.array([350., 352., 354., 356.])
        rlats = np.array([-5., -0., 5., 10.])

        src_proj = ccrs.RotatedGeodetic(pole_longitude=178.0,
                                        pole_latitude=38.0)
        target_proj = ccrs.Geodetic()
        res = target_proj.transform_points(x=rlons, y=rlats, src_crs=src_proj)
        unrotated_lon = res[..., 0]
        unrotated_lat = res[..., 1]

        # Solutions derived by proj4 direct.
        solx = np.array(
            [-16.42176094, -14.85892262, -12.88946157, -10.35078336])
        soly = np.array([46.00724251, 51.29188893, 56.55031485, 61.77015703])

        assert_arr_almost_eq(unrotated_lon, solx)
        assert_arr_almost_eq(unrotated_lat, soly)
Beispiel #13
0
def test_transform_points():
    # these always worked
    result = _CRS_ROB.transform_points(_CRS_PC,
                                       np.array([35.0]),
                                       np.array([70.0]))
    assert_arr_almost_eq(result,
                         [[2376187.159105642, 7275318.947140937, 0]])

    result = _CRS_ROB.transform_points(_CRS_PC,
                                       np.array([35.0]),
                                       np.array([70.0]),
                                       np.array([0.0]))
    assert_arr_almost_eq(result,
                         [[2376187.159105642, 7275318.947140937, 0]])

    # this always did something, but result has altered
    result = _CRS_ROB.transform_points(_CRS_PC,
                                       np.array([_NAN]),
                                       np.array([70.0]))
    assert_true(np.all(np.isnan(result)))

    # this used to crash + is now fixed
    result = _CRS_ROB.transform_points(_CRS_PC,
                                       np.array([35.0]),
                                       np.array([_NAN]))
    assert_true(np.all(np.isnan(result)))

    # multipoint case
    x = np.array([10.0, 21.0, 0.0, 77.7, _NAN, 0.0])
    y = np.array([10.0, _NAN, 10.0, 77.7, 55.5, 0.0])
    z = np.array([10.0, 0.0, 0.0, _NAN, 55.5, 0.0])
    expect_result = np.array(
        [[9.40422591e+05, 1.06952091e+06, 1.00000000e+01],
         [11.1, 11.2, 11.3],
         [0.0, 1069520.91213902, 0.0],
         [22.1, 22.2, 22.3],
         [33.1, 33.2, 33.3],
         [0.0, 0.0, 0.0]])
    result = _CRS_ROB.transform_points(_CRS_PC, x, y, z)
    assert_equal(result.shape, (6, 3))
    assert_true(np.all(np.isnan(result[[1, 3, 4], :])))
    result[[1, 3, 4], :] = expect_result[[1, 3, 4], :]
    assert_false(np.any(np.isnan(result)))
    assert_true(np.allclose(result, expect_result))
Beispiel #14
0
    def test_transform_points_nD(self):
        rlons = np.array([[350., 352., 354.], [350., 352., 354.]])
        rlats = np.array([[-5., -0., 1.], [-4., -1., 0.]])

        src_proj = ccrs.RotatedGeodetic(pole_longitude=178.0,
                                        pole_latitude=38.0)
        target_proj = ccrs.Geodetic()
        res = target_proj.transform_points(x=rlons, y=rlats,
                                           src_crs=src_proj)
        unrotated_lon = res[..., 0]
        unrotated_lat = res[..., 1]

        # Solutions derived by proj direct.
        solx = np.array([[-16.42176094, -14.85892262, -11.90627520],
                         [-16.71055023, -14.58434624, -11.68799988]])
        soly = np.array([[46.00724251, 51.29188893, 52.59101488],
                         [46.98728486, 50.30706042, 51.60004528]])
        assert_arr_almost_eq(unrotated_lon, solx)
        assert_arr_almost_eq(unrotated_lat, soly)
Beispiel #15
0
    def test_transform_points_nD(self):
        rlons = numpy.array([[350., 352.], [350., 352.]])
        rlats = numpy.array([[-5., -0.], [-4., -1.]])

        src_proj = ccrs.RotatedGeodetic(pole_longitude=178.0,
                                        pole_latitude=38.0)
        target_proj = ccrs.Geodetic()
        res = target_proj.transform_points(x=rlons, y=rlats,
                                           src_crs=src_proj)

        unrotated_lon, unrotated_lat, _ = res.transpose()

        # Solutions derived by proj4 direct.
        solx = numpy.array([[-16.42176094, -14.85892262],
                            [-16.71055023, -14.58434624]])
        soly = numpy.array([[46.00724251, 51.29188893],
                            [46.98728486, 50.30706042]])

        assert_arr_almost_eq(unrotated_lon, solx)
        assert_arr_almost_eq(unrotated_lat, soly)
Beispiel #16
0
    def test_transform_points_1D(self):
        rlons = np.array([350., 352., 354., 356.])
        rlats = np.array([-5., -0., 5., 10.])

        src_proj = ccrs.RotatedGeodetic(pole_longitude=178.0,
                                        pole_latitude=38.0)
        target_proj = ccrs.Geodetic()
        res = target_proj.transform_points(x=rlons, y=rlats,
                                           src_crs=src_proj)
        unrotated_lon = res[..., 0]
        unrotated_lat = res[..., 1]

        # Solutions derived by proj direct.
        solx = np.array([-16.42176094, -14.85892262,
                         -12.88946157, -10.35078336])
        soly = np.array([46.00724251, 51.29188893,
                         56.55031485, 61.77015703])

        assert_arr_almost_eq(unrotated_lon, solx)
        assert_arr_almost_eq(unrotated_lat, soly)
Beispiel #17
0
 def test_utm(self):
     utm30n = ccrs.UTM(30)
     ll = ccrs.Geodetic()
     lat, lon = np.array([51.5, -3.0], dtype=np.double)
     east, north = np.array([500000, 5705429.2], dtype=np.double)
     assert_arr_almost_eq(utm30n.transform_point(lon, lat, ll),
                          [east, north],
                          decimal=1)
     assert_arr_almost_eq(ll.transform_point(east, north, utm30n),
                          [lon, lat],
                          decimal=1)
     utm38s = ccrs.UTM(38, southern_hemisphere=True)
     lat, lon = np.array([-18.92, 47.5], dtype=np.double)
     east, north = np.array([763316.7, 7906160.8], dtype=np.double)
     assert_arr_almost_eq(utm38s.transform_point(lon, lat, ll),
                          [east, north],
                          decimal=1)
     assert_arr_almost_eq(ll.transform_point(east, north, utm38s),
                          [lon, lat],
                          decimal=1)
Beispiel #18
0
    def _check_osgb(self, osgb):
        ll = ccrs.Geodetic()

        # results obtained by streetmap.co.uk.
        lat, lon = np.array([50.462023, -3.478831], dtype=np.double)
        east, north = np.array([295131, 63511], dtype=np.double)

        # note the handling of precision here...
        assert_arr_almost_eq(np.array(osgb.transform_point(lon, lat, ll)),
                             np.array([east, north]), 1)
        assert_arr_almost_eq(ll.transform_point(east, north, osgb), [lon, lat],
                             2)

        r_lon, r_lat = ll.transform_point(east, north, osgb)
        r_inverted = np.array(osgb.transform_point(r_lon, r_lat, ll))
        assert_arr_almost_eq(r_inverted, [east, north], 3)

        r_east, r_north = osgb.transform_point(lon, lat, ll)
        r_inverted = np.array(ll.transform_point(r_east, r_north, osgb))
        assert_arr_almost_eq(r_inverted, [lon, lat])
Beispiel #19
0
 def test_utm(self):
     utm30n = ccrs.UTM(30)
     ll = ccrs.Geodetic()
     lat, lon = np.array([51.5, -3.0], dtype=np.double)
     east, north = np.array([500000, 5705429.2], dtype=np.double)
     assert_arr_almost_eq(utm30n.transform_point(lon, lat, ll),
                          [east, north],
                          decimal=1)
     assert_arr_almost_eq(ll.transform_point(east, north, utm30n),
                          [lon, lat],
                          decimal=1)
     utm38s = ccrs.UTM(38, southern_hemisphere=True)
     lat, lon = np.array([-18.92, 47.5], dtype=np.double)
     east, north = np.array([763316.7, 7906160.8], dtype=np.double)
     assert_arr_almost_eq(utm38s.transform_point(lon, lat, ll),
                          [east, north],
                          decimal=1)
     assert_arr_almost_eq(ll.transform_point(east, north, utm38s),
                          [lon, lat],
                          decimal=1)
Beispiel #20
0
    def _check_osgb(self, osgb):
        ll = ccrs.Geodetic()

        # results obtained by streetmap.co.uk.
        lat, lon = np.array([50.462023, -3.478831], dtype=np.double)
        east, north = np.array([295131, 63511], dtype=np.double)

        # note the handling of precision here...
        assert_arr_almost_eq(np.array(osgb.transform_point(lon, lat, ll)),
                             np.array([east, north]),
                             1)
        assert_arr_almost_eq(ll.transform_point(east, north, osgb),
                             [lon, lat],
                             2)

        r_lon, r_lat = ll.transform_point(east, north, osgb)
        r_inverted = np.array(osgb.transform_point(r_lon, r_lat, ll))
        assert_arr_almost_eq(r_inverted, [east, north], 3)

        r_east, r_north = osgb.transform_point(lon, lat, ll)
        r_inverted = np.array(ll.transform_point(r_east, r_north, osgb))
        assert_arr_almost_eq(r_inverted, [lon, lat])
Beispiel #21
0
    def test_project_point(self):
        point = sgeom.Point([0, 45])
        multi_point = sgeom.MultiPoint([point, sgeom.Point([180, 45])])

        pc = ccrs.PlateCarree()
        pc_rotated = ccrs.PlateCarree(central_longitude=180)

        result = pc_rotated.project_geometry(point, pc)
        assert_arr_almost_eq(result.xy, [[-180.], [45.]])

        result = pc_rotated.project_geometry(multi_point, pc)
        assert isinstance(result, sgeom.MultiPoint)
        assert len(result) == 2
        assert_arr_almost_eq(result[0].xy, [[-180.], [45.]])
        assert_arr_almost_eq(result[1].xy, [[0], [45.]])
Beispiel #22
0
    def test_project_point(self):
        point = sgeom.Point([0, 45])
        multi_point = sgeom.MultiPoint([point, sgeom.Point([180, 45])])

        pc = ccrs.PlateCarree()
        pc_rotated = ccrs.PlateCarree(central_longitude=180)

        result = pc_rotated.project_geometry(point, pc)
        assert_arr_almost_eq(result.xy, [[-180.], [45.]])

        result = pc_rotated.project_geometry(multi_point, pc)
        assert isinstance(result, sgeom.MultiPoint)
        assert len(result) == 2
        assert_arr_almost_eq(result[0].xy, [[-180.], [45.]])
        assert_arr_almost_eq(result[1].xy, [[0], [45.]])
Beispiel #23
0
    def test_transform_points_xyz(self):
        # Test geodetic transforms when using z value
        rx = np.array([2574.32516e3])
        ry = np.array([837.562e3])
        rz = np.array([5761.325e3])

        src_proj = ccrs.Geocentric()
        target_proj = ccrs.Geodetic()

        res = target_proj.transform_points(x=rx, y=ry, z=rz, src_crs=src_proj)

        glat = res[..., 0]
        glon = res[..., 1]
        galt = res[..., 2]

        # Solution generated by pyproj
        solx = np.array([18.0224043189])
        soly = np.array([64.9796515089])
        solz = np.array([5048.03893734])

        assert_arr_almost_eq(glat, solx)
        assert_arr_almost_eq(glon, soly)
        assert_arr_almost_eq(galt, solz)
Beispiel #24
0
    def test_transform_points_xyz(self):
        # Test geodetic transforms when using z value
        rx = np.array([2574.32516e3])
        ry = np.array([837.562e3])
        rz = np.array([5761.325e3])

        src_proj = ccrs.Geocentric()
        target_proj = ccrs.Geodetic()

        res = target_proj.transform_points(x=rx, y=ry, z=rz,
                                           src_crs=src_proj)

        glat = res[..., 0]
        glon = res[..., 1]
        galt = res[..., 2]

        # Solution generated by pyproj
        solx = np.array([18.0224043189])
        soly = np.array([64.9796515089])
        solz = np.array([5048.03893734])

        assert_arr_almost_eq(glat, solx)
        assert_arr_almost_eq(glon, soly)
        assert_arr_almost_eq(galt, solz)