climate-service-center / index_calculator

Calculate climate indicators based on xclim
https://index-calculator.readthedocs.io
MIT License
6 stars 5 forks source link

EOBS: r95p und rr95p #47

Open KatharinaBuelow opened 8 months ago

KatharinaBuelow commented 8 months ago

I calculated all precipitation indices using '-search_query variable_id:rr ' and also R95p for eobs and all went fine, but I can not calculate RR95p. I used index_calculation -p EOBS create_scripts -idx RR95p -intake /work/ch0636/eddy/pool/intake-esm_catalogues/EOBS.json -scrpt_dir /scratch/g/g300047/index_calculation -out_dir /work/ch0636/g300047/index_calculation -ofreq sem -submit

and also

index_calculation -p EOBS create_scripts -idx RR95p -intake /work/ch0636/eddy/pool/intake-esm_catalogues/EOBS.json -scrpt_dir /scratch/g/g300047/index_calculation -out_dir /work/ch0636/g300047/index_calculation -ofreq sem -search_query variable_id:rr -submit

Do you have an idea where to look for the mistake? The log file sends me to xarray ? ... .... python3.10/site-packages/xarray/core/dataset.py", line 214, in _get_virtual_variable raise KeyError(key) KeyError: 'rr'

But it worked for everything else very well ?

ludwiglierhammer commented 8 months ago

Hi @KatharinaBuelow, the only information I get from this error message is that the variable rr, wherever, does not occur. As far as I could read in the code, you need to to set a xclim function that calculates RRYYp. You can define this function in the __init__ function of this class. See here.

You can find a list of available xclim functions in the documentation

Hopfully this solves your problem. If not, you can send me the entire error message for a more detailed analysis.

Please submit a new PR if you want to make changes to the code.

KatharinaBuelow commented 8 months ago

Hi @ludwiglierhammer I could in most cases calculate RR95p for euro-cordex using xcalc-0-11-0, but the results do not look good. (You used: x_calc_0.6.1, where the results look good), it is just a problem that starts with new version xcalc_0.7.1 and higher. I use xcalc_0-11-0, which produces wrong files for euro cordex : only 1971-2000 in one file and the timesteps do not have a date

There is no xclim funktion which calculates the percentile value, as far as could see.

You wrote this funktion: https://github.com/climate-service-center/index_calculator/blob/6adf2b4c6e5824822a63a3bfdf0c9077de5690dd/index_calculator/_indices.py#L943 It is not new.

Perhaps I should try eobs later again. Perhaps you could have a look, or if you see better then me and see a xclim funktion for the percentile, let me know I could try to add that as a new index.

ludwiglierhammer commented 8 months ago

I think you should ask the xclim guys about this version issue. I have no knowledge in this percentage area.

Could you send me the entire log file? I may have a look at it.

KatharinaBuelow commented 8 months ago

@ludwiglierhammer ich glaube es hat keine priorität, da wir glaube ich RR95p nicht verwenden, aber es fällt einem ja immer wieder auf die Füße, wenn man etwas nicht löst. Unbenanntes Dokument.pdf Den orginal log file konnte ich hier nicht anhängen

ludwiglierhammer commented 8 months ago

@KatharinaBuelow: Versuch einmal diese Funktion anzupassen:

def _rename_variable_names(self, ds):
    if self.project not in cfjson.keys():
        return ds
    var_names = cfjson[self.project]["variables"]
    units = cfjson[self.project]["units"]
    for dvar in ds.data_vars:
        if dvar in var_names.keys():
            ds = ds.rename({dvar: var_names[dvar]})
            idx = self.var_name.index(dvar)  # new line
            dvar = var_names[dvar]
            self.var_name[idx] = dvar  # new line
        if dvar in units.keys():
            ds[dvar].attrs["units"] = units[dvar]
    return ds

und diesen Codeabschnitt:

self.unlimited_dims = None  # new line
for dim in idx_ds[self.CIname].dims:
    if self.unlimited_dims:  # new ine
        break  # new line    
    for var_name in self.var_name:
        if dim not in self.preproc[var_name].dims:
            self.unlimited_dims = dim
            break

Alles weitere gern in einem neuen PR.