Ouranosinc / xscen

A climate change scenario-building analysis framework.
https://xscen.readthedocs.io/
Apache License 2.0
15 stars 2 forks source link

`subset_warming_levels` does not verify that the full timeseries exists #360

Closed RondeauG closed 7 months ago

RondeauG commented 7 months ago

Setup Information

Description

As long as start_yr is within ds, subset_warming_level will return something. https://github.com/Ouranosinc/xscen/blob/8bb4c0a6342fc845d9462eed808ece75caa9cb98/xscen/extract.py#L1267

We should also check for end_yr.

Steps To Reproduce

Let's say that I have a dataset from 1965-2017 with CMIP6_CanESM5_ssp585_r1i1p1.

subset_warming_level(ds, wl=0.5, window=20)

<xarray.Dataset> Size: 393kB
Dimensions:       (warminglevel: 1, time: 240, station_id: 393)
Coordinates:
  * warminglevel  (warminglevel) object 8B '+0.5Cvs1850-1900'
  * time          (time) datetime64[ns] 2kB 1971-01-01 1971-02-01 ... 1990-12-01

subset_warming_level(ds, wl=2.0, window=20) Only 3 years in the dataset!

<xarray.Dataset> Size: 90kB
Dimensions:       (warminglevel: 1, time: 48, station_id: 393)
Coordinates:
  * warminglevel  (warminglevel) object 8B '+2Cvs1850-1900'
  * time          (time) datetime64[ns] 384B 2014-01-01 ... 2017-12-01

subset_warming_level(ds, wl=3.0, window=20)

None

Additional context

I'm sure that we tested that at some point...

Contribution

juliettelavoie commented 7 months ago

This is making me think that this might be a problem everywhere we cut a period. It never fails or warn. For example, in train we ask for a period, but it will be invisible in the output if the full period was not actually there...

At least in climatological_op, we have min_periods that checks. Maybe this is what you remember testing ?

RondeauG commented 7 months ago

This is making me think that this might be a problem everywhere we cut a period. It never fails or warn.

Yeah, we should indeed open an issue for that. I confirm that everywhere that we simply use a .sel, there is a possibility that only part of the period is covered.