| 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 |
|
| 8 |
from geotiepoints.simple_modis_interpolator import modis_1km_to_250m, modis_1km_to_500m |
| 9 |
from .test_modisinterpolator import ( |
| 10 |
assert_geodetic_distance, |
| 11 |
load_1km_lonlat_as_xarray_dask, |
| 12 |
load_1km_lonlat_as_dask, |
| 13 |
load_1km_lonlat_as_numpy, |
| 14 |
load_500m_lonlat_expected_as_xarray_dask, |
| 15 |
load_250m_lonlat_expected_as_xarray_dask, |
| 16 |
) |
| 17 |
|
| 18 |
from .utils import CustomScheduler |
| 19 |
|
| 20 |
|
| 21 |
@pytest.mark.parametrize( |
| 22 |
("input_func", "exp_func", "interp_func", "dist_max"), |
| 23 |
[ |
| 24 |
(load_1km_lonlat_as_xarray_dask, load_500m_lonlat_expected_as_xarray_dask, modis_1km_to_500m, 16), |
| 25 |
(load_1km_lonlat_as_xarray_dask, load_250m_lonlat_expected_as_xarray_dask, modis_1km_to_250m, 27.35), |
| 26 |
(load_1km_lonlat_as_dask, load_500m_lonlat_expected_as_xarray_dask, modis_1km_to_500m, 16), |
| 27 |
(load_1km_lonlat_as_dask, load_250m_lonlat_expected_as_xarray_dask, modis_1km_to_250m, 27.35), |
| 28 |
(load_1km_lonlat_as_numpy, load_500m_lonlat_expected_as_xarray_dask, modis_1km_to_500m, 16), |
| 29 |
(load_1km_lonlat_as_numpy, load_250m_lonlat_expected_as_xarray_dask, modis_1km_to_250m, 27.35), |
| 30 |
] |
| 31 |
) |
| 32 |
def test_basic_interp(input_func, exp_func, interp_func, dist_max): |
| 33 |
lon1, lat1 = input_func() |
| 34 |
lons_exp, lats_exp = exp_func() |
| 35 |
|
| 36 |
# when working with dask arrays, we shouldn't compute anything |
| 37 |
with dask.config.set(scheduler=CustomScheduler(0)): |
| 38 |
lons, lats = interp_func(lon1, lat1) |
| 39 |
|
| 40 |
if hasattr(lons, "compute"): |
| 41 |
lons, lats = da.compute(lons, lats) |
| 42 |
assert_geodetic_distance(lons, lats, lons_exp, lats_exp, dist_max) |
| 43 |
assert not np.any(np.isnan(lons)) |
| 44 |
assert not np.any(np.isnan(lats)) |
| 45 |
|
| 46 |
|
| 47 |
def test_nonstandard_scan_size(): |
| 48 |
lon1, lat1 = load_1km_lonlat_as_xarray_dask() |
| 49 |
# remove 1 row from the end |
| 50 |
lon1 = lon1[:-1] |
| 51 |
lat1 = lat1[:-1] |
| 52 |
|
| 53 |
pytest.raises(ValueError, modis_1km_to_250m, lon1, lat1) |