10000 Bump minimum Proj to 8.0.0 by QuLogic · Pull Request #1854 · SciTools/cartopy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Bump minimum Proj to 8.0.0 #1854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Circle CI configuration file
# https://circleci.com/docs/

---
version: 2.1


###########################################
# Define some common steps as YAML anchors.
#

apt-run: &apt-install
apt-run: &apt-install
name: Install apt packages
command: |
apt-get -qq update
Expand All @@ -17,15 +18,18 @@ apt-run: &apt-install
g++ \
make

env-run: &env-setup
env-run: &env-setup
# Create the basic testing environment
# Mixing conda-forge and defaults in root is a recipe for trouble, so create
# a separate environment.
name: Setup conda environment
command: |
conda config --set always_yes yes --set changeps1 no --set show_channel_urls yes
conda create -n test-environment python=$PYTHON_VERSION
conda config \
--set always_yes yes \
--set changeps1 no \
--set show_channel_urls yes
conda config --add channels conda-forge
conda create -n test-environment python=$PYTHON_VERSION

deps-run: &deps-install
name: Install Python dependencies
Expand Down
125 changes: 3 additions & 122 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,7 @@
WGS84_SEMIMINOR_AXIS = 6356752.3142


def _safe_pj_transform_611(src_crs, tgt_crs, x, y, z=None, trap=True):
"""
Workaround bug in Proj 6.1.1+ with +to_meter on +proj=ob_tran.

See https://github.com/OSGeo/proj#1782.
"""
lonlat = ('latlon', 'latlong', 'lonlat', 'longlat')

if (
src_crs.proj4_params.get('proj', '') == 'ob_tran' and
src_crs.proj4_params.get('o_proj', '') in lonlat and
'to_meter' in src_crs.proj4_params
):
x *= src_crs.proj4_params['to_meter']
y *= src_crs.proj4_params['to_meter']

transformer = Transformer.from_crs(src_crs, tgt_crs, always_xy=True)
transformed_coords = transformer.transform(x, y, z, errcheck=trap)
if z is None:
xx, yy = transformed_coords
zz = 0
else:
xx, yy, zz = transformed_coords

if (
tgt_crs.proj4_params.get('proj', '') == 'ob_tran' and
tgt_crs.proj4_params.get('o_proj', '') in lonlat and
'to_meter' in tgt_crs.proj4_params
):
xx /= tgt_crs.proj4_params['to_meter']
yy /= tgt_crs.proj4_params['to_meter']

return xx, yy, zz


def _safe_pj_transform_pre_611(src_crs, tgt_crs, x, y, z=None, trap=True):
def _safe_pj_transform(src_crs, tgt_crs, x, y, z=None, trap=True):
transformer = Transformer.from_crs(src_crs, tgt_crs, always_xy=True)
transformed_coords = transformer.transform(x, y, z, errcheck=trap)
if z is None:
Expand All @@ -85,12 +50,6 @@ def _safe_pj_transform_pre_611(src_crs, tgt_crs, x, y, z=None, trap=True):
return xx, yy, zz


if (6, 1, 1) <= PROJ_VERSION < (6, 3, 0):
_safe_pj_transform = _safe_pj_transform_611
else:
_safe_pj_transform = _safe_pj_transform_pre_611


class Globe(object):
"""
Define an ellipsoid and, optionally, how to relate it to the real world.
Expand Down Expand Up @@ -1465,12 +1424,8 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
('lat_0', central_latitude), ('k', scale_factor),
('x_0', false_easting), ('y_0', false_northing),
('units', 'm')]
if PROJ_VERSION < (6, 0, 0):
if not approx:
proj4_params[0] = ('proj', 'etmerc')
else:
if approx:
proj4_params += [('approx', None)]
if approx:
proj4_params += [('approx', None)]
super().__init__(proj4_params, globe=globe)

self.threshold = 1e4
Expand Down Expand Up @@ -2018,25 +1973,6 @@ def __init__(self, central_latitude=0.0, central_longitude=0.0,
false_easting=0.0, false_northing=0.0,
true_scale_latitude=None,
scale_factor=None, globe=None):
# Warn when using Stereographic with proj < 5.0.0 due to
# incorrect transformation with lon_0=0 (see
# https://github.com/OSGeo/proj.4/issues/194).
if central_latitude == 0:
if PROJ_VERSION != ():
if PROJ_VERSION < (5, 0, 0):
warnings.warn(
'The Stereographic projection in Proj older than '
'5.0.0 incorrectly transforms points when '
'central_latitude=0. Use this projection with '
'caution.',
stacklevel=2)
else:
warnings.warn(
'Cannot determine Proj version. The Stereographic '
'projection may be unreliable and should be used with '
'caution.',
stacklevel=2)

proj4_params = [('proj', 'stere'), ('lat_0', central_latitude),
('lon_0', central_longitude),
('x_0', false_easting), ('y_0', false_northing)]
Expand Down Expand Up @@ -2115,19 +2051,6 @@ class Orthographic(Projection):

def __init__(self, central_longitude=0.0, central_latitude=0.0,
globe=None):
if PROJ_VERSION != ():
if (5, 0, 0) <= PROJ_VERSION < (5, 1, 0):
warnings.warn(
'The Orthographic projection in the v5.0.x series of Proj '
'incorrectly transforms points. Use this projection with '
'caution.',
stacklevel=2)
else:
warnings.warn(
'Cannot determine Proj version. The Orthographic projection '
'may be unreliable and should be used with caution.',
stacklevel=2)

proj4_params = [('proj', 'ortho'), ('lon_0', central_longitude),
('lat_0', central_latitude)]
super().__init__(proj4_params, globe=globe)
Expand Down Expand Up @@ -2350,11 +2273,6 @@ def __init__(self, central_longitude=0, false_easting=None,
If omitted, a default globe is created.

"""
if PROJ_VERSION < (5, 2, 0):
_proj_ver = '.'.join(str(v) for v in PROJ_VERSION)
raise ValueError('The EqualEarth projection requires Proj version '
f'5.2.0, but you are using {_proj_ver}.')

proj_params = [('proj', 'eqearth'), ('lon_0', central_longitude)]
super().__init__(proj_params, central_longitude,
false_easting=false_easting,
Expand Down Expand Up @@ -2436,22 +2354,6 @@ def __init__(self, central_longitude=0, globe=None,
This projection does not handle elliptical globes.

"""
# Warn when using Robinson with proj 4.8 due to discontinuity at
# 40 deg N introduced by incomplete fix to issue #113 (see
# https://github.com/OSGeo/proj.4/issues/113).
if PROJ_VERSION != ():
if (4, 8) <= PROJ_VERSION < (4, 9):
warnings.warn('The Robinson projection in the v4.8.x series '
'of Proj contains a discontinuity at '
'40 deg latitude. Use this projection with '
'caution.',
stacklevel=2)
else:
warnings.warn('Cannot determine Proj version. The Robinson '
'projection may be unreliable and should be used '
'with caution.',
stacklevel=2)

proj4_params = [('proj', 'robin'), ('lon_0', central_longitude)]
super().__init__(proj4_params, central_longitude,
false_easting=false_easting,
Expand Down Expand Up @@ -2543,11 +2445,6 @@ def __init__(self, central_longitude=0, globe=None, emphasis='land'):
super().__init__(proj4_params, globe=globe)

elif emphasis == 'ocean':
if PROJ_VERSION < (7, 1, 0):
_proj_ver = '.'.join(str(v) for v in PROJ_VERSION)
raise ValueError('The Interrupted Goode Homolosine ocean '
'projection requires Proj version 7.1.0, '
f'but you are using {_proj_ver}')
proj4_params = [('proj', 'igh_o'), ('lon_0', central_longitude)]
super().__init__(proj4_params, globe=globe)

Expand Down Expand Up @@ -2929,22 +2826,6 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
globe is created.

"""
# Warn when using Azimuthal Equidistant with proj < 4.9.2 due to
# incorrect transformation past 90 deg distance (see
# https://github.com/OSGeo/proj.4/issues/246).
if PROJ_VERSION != ():
if PROJ_VERSION < (4, 9, 2):
warnings.warn('The Azimuthal Equi AE88 distant projection in Proj '
'older than 4.9.2 incorrectly transforms points '
'farther than 90 deg from the origin. Use this '
'projection with caution.',
stacklevel=2)
else:
warnings.warn('Cannot determine Proj version. The Azimuthal '
'Equidistant projection may be unreliable and '
'should be used with caution.',
stacklevel=2)

proj4_params = [('proj', 'aeqd'), ('lon_0', central_longitude),
('lat_0', central_latitude),
('x_0', false_easting), ('y_0', false_northing)]
Expand Down
4 changes: 0 additions & 4 deletions lib/cartopy/tests/crs/test_equal_earth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
from .helpers import check_proj_params


pytestmark = pytest.mark.skipif(ccrs.PROJ_VERSION < (5, 2, 0),
reason='Proj is too old.')


def test_default():
eqearth = ccrs.EqualEarth()
other_args = {'ellps=WGS84', 'lon_0=0'}
Expand Down
6 changes: 0 additions & 6 deletions lib/cartopy/tests/crs/test_interrupted_goode_homolosine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

@pytest.mark.parametrize("emphasis", ["land", "ocean"])
def test_default(emphasis):
if emphasis == "ocean" and ccrs.PROJ_VERSION < (7, 1, 0):
pytest.skip()
igh = ccrs.InterruptedGoodeHomolosine(emphasis=emphasis)
other_args = {"ellps=WGS84", "lon_0=0"}
if emphasis == "land":
Expand All @@ -36,8 +34,6 @@ def test_default(emphasis):

@pytest.mark.parametrize("emphasis", ["land", "ocean"])
def test_eccentric_globe(emphasis):
if emphasis == "ocean" and ccrs.PROJ_VERSION < (7, 1, 0):
pytest.skip()
globe = ccrs.Globe(semimajor_axis=1000, semiminor_axis=500, ellipse=None)
igh = ccrs.InterruptedGoodeHomolosine(globe=globe, emphasis=emphasis)
other_args = {"a=1000", "b=500", "lon_0=0"}
Expand All @@ -55,8 +51,6 @@ def test_eccentric_globe(emphasis):
[("land", -10.0), ("land", 10.0), ("ocean", -10.0), ("ocean", 10.0)],
)
def test_central_longitude(emphasis, lon):
if emphasis == "ocean" and ccrs.PROJ_VERSION < (7, 1, 0):
pytest.skip()
igh = ccrs.InterruptedGoodeHomolosine(
central_longitude=lon, emphasis=emphasis
)
Expand Down
8 changes: 2 additions & 6 deletions lib/cartopy/tests/crs/test_orthographic.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def test_ellipse_globe():
with pytest.warns(UserWarning,
match='does not handle elliptical globes.') as w:
ortho = ccrs.Orthographic(globe=globe)
assert len(w) == (2
if (5, 0, 0) <= ccrs.PROJ_VERSION < (5, 1, 0)
else 1)
assert len(w) == 1

other_args = {'ellps=WGS84', 'lon_0=0.0', 'lat_0=0.0'}
check_proj_params('ortho', ortho, other_args)
Expand All @@ -61,9 +59,7 @@ def test_eccentric_globe():
with pytest.warns(UserWarning,
match='does not handle elliptical globes.') as w:
ortho = ccrs.Orthographic(globe=globe)
assert len(w) == (2
if (5, 0, 0) <= ccrs.PROJ_VERSION < (5, 1, 0)
else 1)
assert len(w) == 1

other_args = {'a=1000', 'b=500', 'lon_0=0.0', 'lat_0=0.0'}
check_proj_params('ortho', ortho, other_args)
Expand Down
39 changes: 10 additions & 29 deletions lib/cartopy/tests/crs/test_robinson.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,14 @@
_CRS_PC = ccrs.PlateCarree()
_CRS_ROB = ccrs.Robinson()

# Increase tolerance if using older proj releases
if ccrs.PROJ_VERSION >= (6, 3, 1):
_TRANSFORM_TOL = 7
elif ccrs.PROJ_VERSION >= (4, 9):
_TRANSFORM_TOL = 0
else:
_TRANSFORM_TOL = -1
_LIMIT_TOL = -1 # if ccrs.PROJ_VERSION < (5, 2, 0) else 7


def test_default():
robin = ccrs.Robinson()
other_args = {'a=6378137.0', 'lon_0=0'}
check_proj_params('robin', robin, other_args)

assert_almost_equal(robin.x_limits,
[-17005833.3305252, 17005833.3305252])
assert_almost_equal(robin.y_limits,
[-8625154.6651000, 8625154.6651000], _LIMIT_TOL)
assert_almost_equal(robin.x_limits, [-17005833.3305252, 17005833.3305252])
assert_almost_equal(robin.y_limits, [-8625154.6651000, 8625154.6651000])


def test_sphere_globe():
Expand All @@ -47,8 +36,7 @@ def test_sphere_globe():
check_proj_params('robin', robin, other_args)

assert_almost_equal(robin.x_limits, [-2666.2696851, 2666.2696851])
assert_almost_equal(robin.y_limits, [-1352.3000000, 1352.3000000],
_LIMIT_TOL)
assert_almost_equal(robin.y_limits, [-1352.3000000, 1352.3000000])


def test_ellipse_globe():
Expand All @@ -63,8 +51,7 @@ def test_ellipse_globe():

# Limits are the same as default since ellipses are not supported.
assert_almost_equal(robin.x_limits, [-17005833.3305252, 17005833.3305252])
assert_almost_equal(robin.y_limits, [-8625154.6651000, 8625154.6651000],
_LIMIT_TOL)
assert_almost_equal(robin.y_limits, [-8625154.6651000, 8625154.6651000])


def test_eccentric_globe():
Expand All @@ -80,8 +67,7 @@ def test_eccentric_globe():

# Limits are the same as spheres since ellipses are not supported.
assert_almost_equal(robin.x_limits, [-2666.2696851, 2666.2696851])
assert_almost_equal(robin.y_limits, [-1352.3000000, 1352.3000000],
_LIMIT_TOL)
assert_almost_equal(robin.y_limits, [-1352.3000000, 1352.3000000])


def test_offset():
Expand All @@ -99,11 +85,9 @@ def test_central_longitude(lon):
other_args = {'a=6378137.0', f'lon_0={lon}'}
check_proj_params('robin', robin, other_args)

assert_almost_equal(robin.x_limits,
[-17005833.3305252, 17005833.3305252],
assert_almost_equal(robin.x_limits, [-17005833.3305252, 17005833.3305252],
decimal=5)
assert_almost_equal(robin.y_limits,
[-8625154.6651000, 8625154.6651000], _LIMIT_TOL)
assert_almost_equal(robin.y_limits, [-8625154.6651000, 8625154.6651000])


def test_transform_point():
Expand All @@ -115,8 +99,7 @@ def test_transform_point():

# this way has always worked
result = _CRS_ROB.transform_point(35.0, 70.0, _CRS_PC)
assert_array_almost_equal(result, (2376187.2182271, 7275318.1162980),
_TRANSFORM_TOL)
assert_array_almost_equal(result, (2376187.2182271, 7275318.1162980))

# this always did something, but result has altered
result = _CRS_ROB.transform_point(np.nan, 70.0, _CRS_PC)
Expand All @@ -139,16 +122,14 @@ def test_transform_points():
np.array([35.0]),
np.array([70.0]))
assert_array_almost_equal(result,
[[2376187.2182271, 7275318.1162980, 0]],
_TRANSFORM_TOL)
[[2376187.2182271, 7275318.1162980, 0]])

result = _CRS_ROB.transform_points(_CRS_PC,
np.array([35.0]),
np.array([70.0]),
np.array([0.0]))
assert_array_almost_equal(result,
[[2376187.2182271, 7275318.1162980, 0]],
_TRANSFORM_TOL)
[[2376187.2182271, 7275318.1162980, 0]])

# this always did something, but result has altered
result = _CRS_ROB.transform_points(_CRS_PC,
Expand Down
5 changes: 2 additions & 3 deletions lib/cartopy/tests/crs/test_transverse_mercator.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ def setup_class(self):
def test_default(self, approx):
proj = ccrs.OSNI(approx=approx)
res = proj.transform_point(*self.point_a, src_crs=self.src_crs)
np.testing.assert_array_almost_equal(
res, (275614.26762651594, 386984.206429612),
decimal=0 if ccrs.PROJ_VERSION < (5, 0, 0) else 6)
np.testing.assert_array_almost_equal(res,
(275614.267627, 386984.206430))

def test_nan(self):
proj = ccrs.OSNI(approx=True)
Expand Down
Loading
0