rigoudyg / climaf

CliMAF - a Climate Model Analysis Framework - doc at : http://climaf.readthedocs.org/
Other
16 stars 7 forks source link

Is there a way to print a (more) detailed CRS? #220

Closed jypeter closed 2 years ago

jypeter commented 2 years ago

This is loosely linked to #197

I'm experimenting with applying operations to ensembles, and checking the incrementally longer crs I get after chaining several operations. Unfortunately, I'm only getting the detailed parameters for llbox. I don't know if this is because llbox is the first operator I use, or because the other operators are not set up to print their parameters

Maybe I should use my_ds.buildcrs(crsrewrite=some_hopefully_existing_function) instead of my_ds.crs?

I understand of course the interest of usually keeping the crs not too long so that it remains readable. I'm just wondering if there is an existing way of getting a detailed crs when you are debugging. Maybe there is a way to get this by playing with the logging parameters, but I'm more looking for a way to get the information in the code, from a dataset object

As an example, here is a part of my code:

        working_ens = all_ens_dic[period_ens_key]

        # Extract a specific region (REGION selection)
        tmp_reg_ens = llbox(working_ens, **current_region)

        # Compute the annual mean (TEMPORAL mean)
        tmp_reg_time_ens = clim_average(tmp_reg_ens, 'annual')

        # Compute the global mean (SPATIAL mean)
        tmp_reg_time_space_ens = space_average(tmp_reg_time_ens)

And I get the following crs results for one of the members (with only the detailed parameters of llbox)

>>> working_ens['AWI-ESM-1-1-LR_AWI'].crs
"ds('CMIP6%%pr%1855-1954%global%/bdd%AWI-ESM-1-1-LR%AWI%CMIP%Amon%piControl%r1i1p1f1%gn%latest')"

>>> tmp_reg_ens['AWI-ESM-1-1-LR_AWI'].crs
"llbox(ds('CMIP6%%pr%1855-1954%global%/bdd%AWI-ESM-1-1-LR%AWI%CMIP%Amon%piControl%r1i1p1f1%gn%latest'),latmax=60,latmin=30,lonmax=150,lonmin=40)"

>>> tmp_reg_time_ens['AWI-ESM-1-1-LR_AWI'].crs
"time_average(llbox(ds('CMIP6%%pr%1855-1954%global%/bdd%AWI-ESM-1-1-LR%AWI%CMIP%Amon%piControl%r1i1p1f1%gn%latest'),latmax=60,latmin=30,lonmax=150,lonmin=40))"

>>> tmp_reg_time_space_ens['AWI-ESM-1-1-LR_AWI'].crs
"space_average(time_average(llbox(ds('CMIP6%%pr%1855-1954%global%/bdd%AWI-ESM-1-1-LR%AWI%CMIP%Amon%piControl%r1i1p1f1%gn%latest'),latmax=60,latmin=30,lonmax=150,lonmin=40)))"
senesis commented 2 years ago

Your example only shows that operation clim_average(...,'annual') translates in CRS as time_average(...) without any parameter. This is the correct, complete translation, as shown by the code, and this is enough to recompute the value if needed.

It can be considered as unfortunate that calling function clim_average translates in time_average in CRS, but this is the price to pay if one wants to provide a versatile climaf function that embeds climaf operators.

You may also have discovered here that a call to clim_average(...,'annual') may lead to incorrect results if argument dataset does not cover full years.

jypeter commented 2 years ago

My mistake for not noticing that we had clim_average and time_average! :-(

I actually wanted to perform an average on all time steps, for each member of an ensemble, but I thought that time_average could not be applied to an ensemble (as described in #223) and decided to use clim_average(...,'annual')