Debian Codegraph @

geotiepoints/tests/test_modis.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 """Unit tests for python-geotiepoints: MODIS examples."""
2
3 import numpy as np
4 import h5py
5 import os
6
7 import pytest
8
9 FILENAME_250M_RESULT = os.path.join(
10 os.path.dirname(__file__), '../../testdata/250m_lonlat_section_result.h5')
11 FILENAME_250M_INPUT = os.path.join(
12 os.path.dirname(__file__), '../../testdata/250m_lonlat_section_input.h5')
13
14 FILENAME_FULL = os.path.join(
15 os.path.dirname(__file__), '../../testdata/test_5_to_1_geoloc_full.h5')
16 FILENAME_5KM = os.path.join(
17 os.path.dirname(__file__), '../../testdata/test_5_to_1_geoloc_5km.h5')
18
19 from geotiepoints import (modis5kmto1km, modis1kmto250m)
20
21 from geotiepoints import get_scene_splits
22
23
24 class TestUtils:
25 """Class for unit testing the ancillary interpolation functions."""
26
27 def test_get_numof_subscene_lines(self):
28 """Test getting the number of sub-scene lines.
29
30 Function is dependent on the number of CPUs and for various number of
31 lines in a scan.
32 """
33 ncpus = 3
34 scene_splits = get_scene_splits(1060, 10, ncpus)
35 assert list(scene_splits) == [350, 700, 1050]
36
37
38 class TestMODIS:
39 """Class for system testing the MODIS interpolation."""
40
41 def test_5_to_1(self):
42 """Test the 5km to 1km interpolation facility."""
43
44 with h5py.File(FILENAME_FULL) as h5f:
45 glons = h5f['longitude'][:] / 1000.
46 glats = h5f['latitude'][:] / 1000.
47
48 with h5py.File(FILENAME_5KM) as h5f:
49 lons = h5f['longitude'][:] / 1000.
50 lats = h5f['latitude'][:] / 1000.
51
52 tlons, tlats = modis5kmto1km(lons, lats)
53
54 np.testing.assert_allclose(tlons, glons, atol=0.05)
55 np.testing.assert_allclose(tlats, glats, atol=0.05)
56
57 @pytest.mark.parametrize("ncores", [None, 4])
58 def test_1000m_to_250m(self, ncores):
59 """Test the 1 km to 250 meter interpolation facility."""
60 if ncores:
61 import multiprocessing as mp
62 mp.set_start_method("spawn", force=True)
63
64 with h5py.File(FILENAME_250M_RESULT) as h5f:
65 glons = h5f['longitude'][:] / 1000.
66 glats = h5f['latitude'][:] / 1000.
67
68 with h5py.File(FILENAME_250M_INPUT) as h5f:
69 lons = h5f['longitude'][:] / 1000.
70 lats = h5f['latitude'][:] / 1000.
71
72 kwargs = {"cores": ncores} if ncores is not None else {}
73 tlons, tlats = modis1kmto250m(lons, lats, **kwargs)
74 np.testing.assert_allclose(tlons, glons, atol=0.05)
75 np.testing.assert_allclose(tlats, glats, atol=0.05)