diff --git a/geodepy/tests/test_ntv2_transform.py b/geodepy/tests/test_ntv2_transform.py new file mode 100644 index 0000000..2baa96d --- /dev/null +++ b/geodepy/tests/test_ntv2_transform.py @@ -0,0 +1,136 @@ +import struct +import tempfile +import unittest +from pathlib import Path + +from geodepy.ntv2reader import read_ntv2_file +from geodepy.transform import ntv2_2d + +# NTv2 longitudes are positive west and grid coordinates are in arcseconds. +SOUTH = -32.0 * 3600 +EAST = -142.0 * 3600 +INTERVAL = 360.0 +SIZE = 7 +METHODS = ("bilinear", "bicubic") +# Interpolated shifts are rounded to six decimal places in arcseconds. +TOLERANCE = 1e-6 / 3600 + 1e-13 + + +def shifts_at(y, x, sign=1): + """Affine fields with exactly representable float32 values at grid nodes.""" + return sign * (0.5 + y / 16 + x / 32), sign * (-0.25 + y / 64 - x / 32) + + +def coordinate_at(y, x): + return (SOUTH + y * INTERVAL) / 3600, -(EAST + x * INTERVAL) / 3600 + + +def write_grid(path, sign=1): + """Write a small NTv2 file so tests exercise the actual interpolators.""" + + def record(name, value): + if isinstance(value, str): + data = value.encode("ascii").ljust(8) + elif isinstance(value, int): + data = struct.pack("