Ouranosinc / xscen

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

create_ensemble_on with calendar noleap #303

Open juliettelavoie opened 9 months ago

juliettelavoie commented 9 months ago

Setup Information

Description

I am trying to use create_ensemble_on in to_dataset. I want to convert calendars to noleap. I get an error to use cftime, but that arg is not available through to_dataset. It is fixed to calendar == "default". Why is cftime only acceptable with default ? Is there a problem with adding a use_cftime_for_calendar arg to to_dataset ?

https://github.com/Ouranosinc/xscen/blob/db7c976c4557c154a815cc2eae7f7d48490f6e3c/xscen/catalog.py#L493

Steps To Reproduce

cat = xs.ProjectCatalog('simulation.json')
cat.search(**dict(
        variable='tasmax', 
        source=['MIROC6', 'CanESM5'],
        processing_level='biasadjusted',
        bias_adjust_project=['ESPO-G6-R2'],
        experiment=['ssp245'],
        member='r1i1p1f1')).to_dataset(create_ensemble_on=["institution", "source"], calendar='noleap')

gives:

ValueError: Calendar 'noleap' is only valid with cftime. Try using `use_cftime=True`.

Additional context

Note that technically these two sources are already noleap in cftime. When I use to_dataset without converting to a calendar, the time axis becomes a numpy datetime (but february 29th are still missing.) This seems like a weird behavior to me. It leads to issue, because xr.infer_freqdoesn't work anymore (outputs None). This means that default xclim checks on indicators fail.

Contribution

aulemahal commented 9 months ago

Hum. haha what was I thinking ? Maybe its a typo and I actually meant calendar != 'default' ?

Because "default" is the name xclim (and only xclim) gives to the numpy datetime calendar.

On the other hand, if all datasets are using noleap and you are not getting a noleap calendar output, than that's an issue of catalog.to_dask think. Strange!

juliettelavoie commented 9 months ago

calendar != 'default' fixes my problem, I'll make the change in my partition PR.