Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Avoid resampling for SPI indices #276

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion icclim/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from xarray.core.dataset import Dataset

from icclim.ecad.ecad_indices import EcadIndexRegistry
from icclim.ecad.xclim_binding import XCLIM_BINDING
from icclim.generic_indices.generic_indicators import (
GenericIndicator,
GenericIndicatorRegistry,
Expand Down Expand Up @@ -569,7 +570,17 @@ def _compute_climate_index(
else:
result_da = result_da.rename(climate_index.name)
result_da.attrs[UNITS_KEY] = _get_unit(config.out_unit, result_da)
if config.frequency.post_processing is not None and "time" in result_da.dims:
if (
config.frequency.post_processing is not None
and "time" in result_da.dims
and not isinstance(
climate_index,
(
XCLIM_BINDING.StandardizedPrecipitationIndex6,
XCLIM_BINDING.StandardizedPrecipitationIndex3,
),
)
):
resampled_da, time_bounds = config.frequency.post_processing(result_da)
result_ds = resampled_da.to_dataset()
if time_bounds is not None:
Expand Down
8 changes: 4 additions & 4 deletions icclim/tests/test_input_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_read_dataset_xr_ds__simple(self):
# THEN
xr.testing.assert_equal(ds_res.pouet, ds.pouet)

def test_read_dataset_netcdf_success(self):
def test_read_dataset__netcdf_success(self):
# GIVEN
ds = xr.Dataset({"pouet": self.pr_da})
ds.to_netcdf(self.OUTPUT_NC_FILE)
Expand All @@ -117,7 +117,7 @@ def test_read_dataset_netcdf_success(self):
# THEN
xr.testing.assert_equal(ds_res.pouet, ds.pouet)

def test_read_dataset_multi_netcdf_success(self):
def test_read_dataset__multi_netcdf_success(self):
# GIVEN
ds = xr.Dataset({"pouet": self.pr_da})
ds.to_netcdf(self.OUTPUT_NC_FILE)
Expand All @@ -128,7 +128,7 @@ def test_read_dataset_multi_netcdf_success(self):
xr.testing.assert_equal(ds_res.pouet, ds.pouet)
xr.testing.assert_equal(ds_res.patapouet, ds.pouet)

def test_read_dataset_zarr_store_success(self):
def test_read_dataset__zarr_store_success(self):
# GIVEN
ds = xr.Dataset({"pouet": self.pr_da})
ds.to_zarr(self.OUTPUT_ZARR_STORE)
Expand All @@ -137,7 +137,7 @@ def test_read_dataset_zarr_store_success(self):
# THEN
xr.testing.assert_equal(ds_res.pouet, ds.pouet)

def test_read_dataset_not_implemented_error(self):
def test_read_dataset__not_implemented_error(self):
# THEN
with pytest.raises(NotImplementedError):
# WHEN
Expand Down
9 changes: 9 additions & 0 deletions icclim/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ def test_indices_all_from_Dataset__seasonal_SPI_error(self):
base_period_time_range=("2042-01-01", "2042-12-31"),
)

def test_spi6__no_time_bounds(self):
dataset = icclim.index(
index_name="spi6",
in_files=self.full_data,
var_name="pr",
base_period_time_range=["2042-01-01", "2042-06-01"],
).load()
assert "time_bounds" not in dataset.coords

def test_indices_all_from_Dataset__seasonal(self):
res = icclim.indices(
index_group="all",
Expand Down
Loading