Esempio n. 1
0
 def test_default(self):
     geos = ccrs.RotatedGeodetic(30, 15, 27)
     expected = [
         '+datum=WGS84', 'ellps=WGS84', 'lon_0=210', 'no_defs',
         'o_lat_p=15', 'o_lon_p=27', 'o_proj=latlon', 'proj=ob_tran',
         'to_meter=0.0174532925199433'
     ]
     self.check_proj4_params(geos, expected)
Esempio n. 2
0
 def test_as_cartopy_crs(self):
     if cartopy.__version__ < '0.12':
         with mock.patch('warnings.warn') as warn:
             accrs = self.rp_crs.as_cartopy_crs()
             self.assertEqual(warn.call_count, 1)
     else:
         accrs = self.rp_crs.as_cartopy_crs()
         expected = ccrs.RotatedGeodetic(self.pole_lon, self.pole_lat,
                                         self.rotation_about_new_pole)
         self.assertEqual(sorted(accrs.proj4_init.split(' +')),
                          sorted(expected.proj4_init.split(' +')))
Esempio n. 3
0
def rotate_pole(lons, lats, pole_lon, pole_lat):
    """
    Convert arrays of lons and lats to ones on a rotated pole.

        grid_lons, grid_lats = rotate_pole(lons, lats, pole_lon, pole_lat)

    .. note:: Uses proj.4 to perform the conversion.

    """
    src_proj = ccrs.Geodetic()
    target_proj = ccrs.RotatedGeodetic(pole_longitude=pole_lon,
                                       pole_latitude=pole_lat)
    res = target_proj.transform_points(x=lons, y=lats, src_crs=src_proj)
    rotated_lon = res[..., 0]
    rotated_lat = res[..., 1]

    return rotated_lon, rotated_lat
Esempio n. 4
0
def unrotate_pole(rotated_lons, rotated_lats, pole_lon, pole_lat):
    """
    Convert arrays of rotated-pole longitudes and latitudes to unrotated
    arrays of longitudes and latitudes. The values of ``pole_lon`` and
    ``pole_lat`` should describe the location of the rotated pole that
    describes the arrays of rotated-pole longitudes and latitudes.

    As the arrays of rotated-pole longitudes and latitudes must describe a
    rectilinear grid, the arrays of rotated-pole longitudes and latitudes must
    be of the same shape as each other.

    Example::

        lons, lats = unrotate_pole(rotated_lons, rotated_lats, \
          pole_lon, pole_lat)

    .. note:: Uses proj.4 to perform the conversion.

    Args:

        * rotated_lons:
            An array of rotated-pole longitude values.
        * rotated_lats:
            An array of rotated-pole latitude values.
        * pole_lon:
            The longitude of the rotated pole that describes the arrays of
            rotated-pole longitudes and latitudes.
        * pole_lat:
            The latitude of the rotated pole that describes the arrays of
            rotated-pole longitudes and latitudes.

    Returns:
        An array of unrotated longitudes and an array of unrotated latitudes.

    """
    src_proj = ccrs.RotatedGeodetic(
        pole_longitude=pole_lon, pole_latitude=pole_lat
    )
    target_proj = ccrs.Geodetic()
    res = target_proj.transform_points(
        x=rotated_lons, y=rotated_lats, src_crs=src_proj
    )
    unrotated_lon = res[..., 0]
    unrotated_lat = res[..., 1]

    return unrotated_lon, unrotated_lat
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
def unrotate_pole(rotated_lons, rotated_lats, pole_lon, pole_lat):
    """
    Convert rotated-pole lons and lats to unrotated ones.

        lons, lats = unrotate_pole(grid_lons, grid_lats, pole_lon, pole_lat)

    .. note:: Uses proj.4 to perform the conversion.

    """
    src_proj = ccrs.RotatedGeodetic(pole_longitude=pole_lon,
                                    pole_latitude=pole_lat)
    target_proj = ccrs.Geodetic()
    res = target_proj.transform_points(x=rotated_lons,
                                       y=rotated_lats,
                                       src_crs=src_proj)
    unrotated_lon = res[..., 0]
    unrotated_lat = res[..., 1]

    return unrotated_lon, unrotated_lat
Esempio n. 8
0
 def as_cartopy_crs(self):
     return ccrs.RotatedGeodetic(**self._ccrs_kwargs())
Esempio n. 9
0
def test_default():
    geos = ccrs.RotatedGeodetic(30, 15, 27)
    other_args = {'datum=WGS84', 'ellps=WGS84', 'lon_0=210', 'o_lat_p=15',
                  'o_lon_p=27'} | common_other_args
    check_proj_params('ob_tran', geos, other_args)
         false_northing=500_000,
         standard_parallels=(64.25, 65.75),
         globe=ccrs.Globe(ellipse="GRS80"),
     )),
    (
        # Not sure how else to define this case other than copying what
        # our cartopy -> pyproj converter does...
        pyproj.CRS.from_epsg("""
            +ellps=WGS84 +a=6371229 +b=6371229
            +proj=ob_tran +o_proj=latlon +o_lon_p=0.0 +o_lat_p=177.5
            +lon_0=217.5
            +to_meter=0.0174532925199433 +no_defs
            """),
        ccrs.RotatedGeodetic(
            37.5,
            177.5,
            globe=ccrs.Globe(semimajor_axis=6371229, semiminor_axis=6371229),
        )),
]


@pytest.mark.parametrize("source, target", cases)
def test_as_cartopy(source, target):
    converted = util.crs.as_cartopy_crs(source)
    # Cartopy implements equality by comparing proj4 strings, which may
    # fail due to differences such as the order of parameters, or whether a
    # number ends with ".0" or not.  Instead, compare the underlying dicts.
    assert converted.proj4_params == target.proj4_params


# Note that we can reuse the same cases, but labeled the other way round