Skip to content

Commit

Permalink
Merge pull request #1884 from QuLogic/fix-osgb-tests
Browse files Browse the repository at this point in the history
Loosen OSGB tests if grids are unavailable
  • Loading branch information
greglucas authored Sep 22, 2021
2 parents 851199b + 5d999f3 commit 4a16d24
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 4a16d24

Please sign in to comment.