aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/tests/test_viewer_fixtures.py
blob: 5c0b88b8a8e5f54419cc3d44cf6e982b1579f9f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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))