Skip to content

Commit

Permalink
Factor out duplicate parsing of proj.4 version.
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Apr 11, 2016
1 parent e565c8a commit e77cead
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 26 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
15 changes: 5 additions & 10 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 = tuple(int(v) for v in match.group().split('.'))
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 @@ -1751,11 +1749,8 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
# 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).
import re
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('.'))
if proj4_version < (4, 9, 2):
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 '
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 e77cead

Please sign in to comment.