import json import unittest from pathlib import Path import numpy as np from mapgen import projections as PJ FIX = Path(__file__).resolve().parents[1] / "viewer" / "tests" / "fixtures" / "projections.json" POINTS = [(0.0, 0.0), (30.0, 120.0), (-60.0, -170.0), (89.0, 45.0), (10.0, -179.0), (-45.5, 33.3)] class ViewerFixtureTest(unittest.TestCase): def test_write_projection_fixture(self): lat = np.array([p[0] for p in POINTS]) lon = np.array([p[1] for p in POINTS]) x, y = PJ.equal_earth_forward(lat, lon) data = {"ee_xmax": float(PJ.EE_XMAX), "ee_ymax": float(PJ.EE_YMAX), "equal_earth": [{"lat": float(a), "lon": float(b), "x": float(c), "y": float(d)} for a, b, c, d in zip(lat, lon, x, y)]} FIX.parent.mkdir(parents=True, exist_ok=True) FIX.write_text(json.dumps(data, indent=1)) self.assertEqual(len(json.loads(FIX.read_text())["equal_earth"]), len(POINTS))