Skip to content
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

Loosen OSGB tests if grids are unavailable #1884

Merged
merged 1 commit into from
Sep 22, 2021
Merged
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
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