Example #1
0
    def test_load_regridder(self, tmp_path):

        test_dataset, _, _ = _make_dataset(size=(10, 10))
        test_dataset.to_netcdf(tmp_path / 'regridder.nc')

        output = BasePreProcessor.load_reference_grid(tmp_path /
                                                      'regridder.nc')

        assert set(output.variables) == {
            'lat', 'lon'
        }, f'Got extra variables: {output.variables}'
Example #2
0
    def test_load_regridder(self, tmp_path):

        test_dataset, _, _ = _make_dataset(size=(10, 10))
        test_dataset.to_netcdf(tmp_path / "regridder.nc")

        output = BasePreProcessor.load_reference_grid(tmp_path /
                                                      "regridder.nc")

        assert set(output.variables) == {
            "lat",
            "lon",
        }, f"Got extra variables: {output.variables}"
Example #3
0
# ------------------------------------------------------------------------------
# Test PREPROCESSING
# ------------------------------------------------------------------------------
from src.preprocess.base import BasePreProcessor

b = BasePreProcessor()
ds1_kenya = b.chop_roi(ds1, inverse_lat=True)
ds2_kenya = b.chop_roi(ds2, inverse_lat=True)

# concat across initialisation dates
ds_kenya = xr.concat([ds1_kenya, ds2_kenya], dim="initialisation_date")
stacked = ds_kenya.stack(time=("initialisation_date", "forecast_horizon"))

# stack each individually
k1 = ds1_kenya.stack(time=("initialisation_date", "forecast_horizon"))
k2 = ds2_kenya.stack(time=("initialisation_date", "forecast_horizon"))

# test selectors
stacked.sel(forecast_horizon=np.timedelta64(28, "D"))
stacked.sel(initialisation_date="1997-01-01")
stacked.swap_dims({"time": "valid_time"}).sel(valid_time="1997-04")

# test regridding
ref_ds = b.load_reference_grid(path_to_grid=Path("data/interim/chirps_preprocessed.nc"))
ds1_kenya_regrid = b.regrid(
    ds1_kenya.rename({"latitude": "lat", "longitude": "lon"}), ref_ds
)

# test resampling time
b.resample_time()