1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
import numpy as np
import xarray as xr
from tools_test import build_footprint, fake_dataset, fake_ecmwf_0100_1h
from mapraster.main import map_raster
def test_map_raster_no_antimeridian():
dataset = fake_dataset(cross_antimeridian=False)
footprint = build_footprint(dataset)
raster = fake_ecmwf_0100_1h(
to180=True,
with_nan=False,
)
out = map_raster(
raster_ds=raster,
originalDataset=dataset,
footprint=footprint,
cross_antimeridian=False,
)
assert set(out.data_vars) == {"U10", "V10"}
assert out["U10"].shape == dataset["longitude"].shape
assert not np.all(np.isnan(out["U10"].values))
test_map_raster_no_antimeridian()
def test_map_raster_cross_antimeridian():
dataset = fake_dataset(cross_antimeridian=True)
footprint = build_footprint(dataset)
raster = fake_ecmwf_0100_1h(
to180=False,
with_nan=False,
)
out = map_raster(
raster_ds=raster,
originalDataset=dataset,
footprint=footprint,
cross_antimeridian=True,
)
assert set(out.data_vars) == {"U10", "V10"}
assert out["U10"].shape == dataset["longitude"].shape
assert not np.all(np.isnan(out["V10"].values))
test_map_raster_cross_antimeridian()
def test_map_raster_with_nan():
dataset = fake_dataset(cross_antimeridian=True)
footprint = build_footprint(dataset)
raster = fake_ecmwf_0100_1h(
to180=False,
with_nan=True,
)
out = map_raster(
raster_ds=raster,
originalDataset=dataset,
footprint=footprint,
cross_antimeridian=True,
)
# No full NaN since raster is build with partial NaN only
assert not np.all(np.isnan(out["U10"].values))
# check there are NaN in the output
nan_ratio = np.isnan(out["U10"].values).mean()
assert nan_ratio > 0.01
test_map_raster_with_nan()
|