Skip to content

Commit

Permalink
Loosen OSGB tests if grids are unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Oct 7, 2021
1 parent 2f92abd commit 112af97
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/cartopy/tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import copy
from io import BytesIO
import os
from pathlib import Path
import pickle

import numpy as np
Expand Down Expand Up @@ -46,19 +48,31 @@ def test_osni(self, approx):
3)

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_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)
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))
Expand Down

0 comments on commit 112af97

Please sign in to comment.