| 1 |
"""Tests for simple MODIS interpolators.""" |
| 2 |
|
| 3 |
import numpy as np |
| 4 |
import pytest |
| 5 |
import dask |
| 6 |
import dask.array as da |
| •7 |
import os |
| 8 |
|
| 9 |
FILENAME_DATA = os.path.join( |
| 10 |
os.path.dirname(__file__), '../../testdata/modis_test_data.h5') |
| 11 |
|
| 12 |
|
| 13 |
from geotiepoints.simple_modis_interpolator import modis_1km_to_250m, modis_1km_to_500m |
| 14 |
from .test_modisinterpolator import ( |
| 15 |
assert_geodetic_distance, |
| 16 |
load_1km_lonlat_as_xarray_dask, |
| 17 |
load_1km_lonlat_as_dask, |
| 18 |
load_1km_lonlat_as_numpy, |
| 19 |
load_500m_lonlat_expected_as_xarray_dask, |
| 20 |
load_250m_lonlat_expected_as_xarray_dask, |
| 21 |
) |
| 22 |
|
| 23 |
from .utils import CustomScheduler |
| 24 |
|
| 25 |
|
| •26 |
@pytest.mark.skipif(not os.path.exists(FILENAME_DATA), reason="data file not available") |
| 27 |
@pytest.mark.parametrize( |
| 28 |
("input_func", "exp_func", "interp_func", "dist_max"), |
| 29 |
[ |
| 30 |
(load_1km_lonlat_as_xarray_dask, load_500m_lonlat_expected_as_xarray_dask, modis_1km_to_500m, 16), |
| 31 |
(load_1km_lonlat_as_xarray_dask, load_250m_lonlat_expected_as_xarray_dask, modis_1km_to_250m, 27.35), |
| 32 |
(load_1km_lonlat_as_dask, load_500m_lonlat_expected_as_xarray_dask, modis_1km_to_500m, 16), |
| 33 |
(load_1km_lonlat_as_dask, load_250m_lonlat_expected_as_xarray_dask, modis_1km_to_250m, 27.35), |
| 34 |
(load_1km_lonlat_as_numpy, load_500m_lonlat_expected_as_xarray_dask, modis_1km_to_500m, 16), |
| 35 |
(load_1km_lonlat_as_numpy, load_250m_lonlat_expected_as_xarray_dask, modis_1km_to_250m, 27.35), |
| 36 |
] |
| 37 |
) |
| 38 |
def test_basic_interp(input_func, exp_func, interp_func, dist_max): |
| 39 |
lon1, lat1 = input_func() |
| 40 |
lons_exp, lats_exp = exp_func() |
| 41 |
|
| 42 |
# when working with dask arrays, we shouldn't compute anything |
| 43 |
with dask.config.set(scheduler=CustomScheduler(0)): |
| 44 |
lons, lats = interp_func(lon1, lat1) |
| 45 |
|
| 46 |
if hasattr(lons, "compute"): |
| 47 |
lons, lats = da.compute(lons, lats) |
| 48 |
assert_geodetic_distance(lons, lats, lons_exp, lats_exp, dist_max) |
| 49 |
assert not np.any(np.isnan(lons)) |
| 50 |
assert not np.any(np.isnan(lats)) |
| 51 |
|
| 52 |
|
| •53 |
@pytest.mark.skipif(not os.path.exists(FILENAME_DATA), reason="data file not available") |
| 54 |
def test_nonstandard_scan_size(): |
| 55 |
lon1, lat1 = load_1km_lonlat_as_xarray_dask() |
| 56 |
# remove 1 row from the end |
| 57 |
lon1 = lon1[:-1] |
| 58 |
lat1 = lat1[:-1] |
| 59 |
|
| 60 |
pytest.raises(ValueError, modis_1km_to_250m, lon1, lat1) |