Skip to content

Commit

Permalink
Merge pull request #757 from QuLogic/proj4-warnings
Browse files Browse the repository at this point in the history
Update Proj4 warnings
  • Loading branch information
pelson committed Apr 20, 2016
2 parents d3df291 + e77cead commit d1e1a69
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
6 changes: 6 additions & 0 deletions lib/cartopy/_crs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The CRS class is the base-class for all projections defined in :mod:`cartopy.crs
"""

from collections import OrderedDict
import re
import warnings

import numpy as np
Expand Down Expand Up @@ -51,6 +52,11 @@ cdef double NAN = float('nan')
PROJ4_RELEASE = pj_get_release()
if six.PY3:
PROJ4_RELEASE = PROJ4_RELEASE.decode()
_match = re.search(r"\d+\.\d+.\d+", PROJ4_RELEASE)
if _match is not None:
PROJ4_VERSION = tuple(int(v) for v in _match.group().split('.'))
else:
PROJ4_VERSION = ()


class Proj4Error(Exception):
Expand Down
22 changes: 17 additions & 5 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from shapely.prepared import prep
import six

from cartopy._crs import CRS, Geocentric, Geodetic, Globe, PROJ4_RELEASE
from cartopy._crs import CRS, Geocentric, Geodetic, Globe, PROJ4_VERSION
import cartopy.trace


Expand Down Expand Up @@ -1454,10 +1454,8 @@ def __init__(self, central_longitude=0, globe=None):
# 40 deg N introduced by incomplete fix to issue #113 (see
# https://trac.osgeo.org/proj/ticket/113).
import re
match = re.search(r"\d\.\d", PROJ4_RELEASE)
if match is not None:
proj4_version = float(match.group())
if 4.8 <= proj4_version < 4.9:
if PROJ4_VERSION != ():
if (4, 8) <= PROJ4_VERSION < (4, 9):
warnings.warn('The Robinson projection in the v4.8.x series '
'of Proj.4 contains a discontinuity at '
'40 deg latitude. Use this projection with '
Expand Down Expand Up @@ -1748,6 +1746,20 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
default globe is created.
"""
# Warn when using Azimuthal Equidistant with proj4 < 4.9.2 due to
# incorrect transformation past 90 deg distance (see
# https://github.com/OSGeo/proj.4/issues/246).
if PROJ4_VERSION != ():
if PROJ4_VERSION < (4, 9, 2):
warnings.warn('The Azimuthal Equidistant projection in Proj.4 '
'older than 4.9.2 incorrectly transforms points '
'farther than 90 deg from the origin. Use this '
'projection with caution.')
else:
warnings.warn('Cannot determine Proj.4 version. The Azimuthal '
'Equidistant projection may be unreliable and '
'should be used with caution.')

proj4_params = [('proj', 'aeqd'), ('lon_0', central_longitude),
('lat_0', central_latitude),
('x_0', false_easting), ('y_0', false_northing)]
Expand Down
9 changes: 0 additions & 9 deletions lib/cartopy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@
import shutil
import types

from cartopy._crs import PROJ4_RELEASE as _PROJ4_RELEASE


_match = re.search(r"\d\.\d", _PROJ4_RELEASE)
if _match is not None:
_proj4_version = float(_match.group())
else:
_proj4_version = 0.0


@contextlib.contextmanager
def temp_dir(suffix=None):
Expand Down
3 changes: 1 addition & 2 deletions lib/cartopy/tests/crs/test_robinson.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
from numpy.testing import assert_array_almost_equal as assert_arr_almost_eq

import cartopy.crs as ccrs
from cartopy.tests import _proj4_version


_NAN = float('nan')
_CRS_PC = ccrs.PlateCarree()
_CRS_ROB = ccrs.Robinson()

# Increase tolerance if using older proj.4 releases
_TOL = -1 if _proj4_version < 4.9 else 7
_TOL = -1 if ccrs.PROJ4_VERSION < (4, 9) else 7


def test_transform_point():
Expand Down
1 change: 0 additions & 1 deletion lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from cartopy.mpl.geoaxes import GeoAxes
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER

from cartopy.tests import _proj4_version
from cartopy.tests.mpl import ImageTesting


Expand Down
6 changes: 3 additions & 3 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@

import cartopy.crs as ccrs

from cartopy.tests import _proj4_version
from cartopy.tests.mpl import ImageTesting


_ROB_TOL = 0.5 if _proj4_version < 4.9 else 0.1
_ROB_TOL = 0.5 if ccrs.PROJ4_VERSION < (4, 9) else 0.1


@ImageTesting(['global_contour_wrap'])
Expand Down Expand Up @@ -119,7 +118,8 @@ def test_global_scatter_wrap_no_transform():
plt.scatter(x, y, c=data)


@ImageTesting(['global_map'], tolerance=16 if _proj4_version < 4.9 else 0.1)
@ImageTesting(['global_map'],
tolerance=16 if ccrs.PROJ4_VERSION < (4, 9) else 0.1)
def test_global_map():
ax = plt.axes(projection=ccrs.Robinson())
# ax.coastlines()
Expand Down
1 change: 0 additions & 1 deletion lib/cartopy/tests/mpl/test_shapely_to_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import cartopy.crs as ccrs
import cartopy.mpl.patch as cpatch

from cartopy.tests import _proj4_version
from cartopy.tests.mpl import ImageTesting


Expand Down

0 comments on commit d1e1a69

Please sign in to comment.