Ouranosinc / xclim

Library of derived climate variables, ie climate indicators, based on xarray.
https://xclim.readthedocs.io/en/stable/
Apache License 2.0
328 stars 58 forks source link

Use precomputed quantiles in the train step of the quantile mapping routines #1222

Closed folmerkrikken closed 9 months ago

folmerkrikken commented 1 year ago

Addressing a Problem?

Hi, First of all thanks for providing such a nice package! It is hugely helpful in many of my project.

I've been using the quantile mapping routines a lot and was wondering if it is also possible to use pre-computed quantiles to the training step of the quantile mapping routines. As far as I can see from the documentation it requires to use datasets with a time dimension.

This option would help to optimize performance because the quantiles of the observational product do not need to be recomputed every time the training step is performed for different models but the same observational product. Secondly, I would like to test the option to regrid the quantiles of e.g. a climate model to the observational dataset i.s.o. the raw climate model data. Especially with large datasets this could reduce the computational resources quite a lot.

Potential Solution

A solution would be to add the possibility in the train step of the xclim.sdba.adjustment methods to add precomputed quantiles, both for the simulation and the reference data.

Thanks in advance,

Folmer Krikken

Code of Conduct

aulemahal commented 1 year ago

Hi @folmerkrikken!

use pre-computed quantiles to the training step of the quantile mapping routines.

This is not exactly possible currently. What the train-adjust method allows is to skip the training step when we already have done it. This is documented here : https://xclim.readthedocs.io/en/stable/notebooks/sdba-advanced.html#Initializing-an-Adjustment-object-from-a-training-dataset

But here, I think you only want the reference to be pre-computed, not the whole training data. This is not currently possible, but the implementation for quantile mapping methods shouldn't be too hard. We're open to pull requests ;)!

I believe the sdba._adjustment.eqm_train function could be modified to detect if ref has a "time" or a "quantile" dimension, and thus not repeat the quantile computation. And similarly for hist, why not!

This is currently not a priority on our side, so we won't have time to implement it soon. But if you submit a PR, we'll be there to help you!