rigoudyg / climaf

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

explore('resolve') and alias on variables issue #125

Closed jservonnat closed 5 years ago

jservonnat commented 5 years ago

I've encountered an issue when using .explore('resolve') (that I'm currently trying to use systematically in the C-ESM-EP) on an aliased variable.

For example with tauu aliased to taux, when I want to get a tauu dataset and use explore('resolve') to complete the wildcards:

ds('IGCM_OUT%CM6015S-pd-03%tauu%2500-2509%[-5, 5, 120, 290]%/ccc/store/cont003/thredds%lurtont%IPSLCM6%DEVT%pdControl%ATM%Analyse%TS_MO%monthly%2500_2509%*').explore('resolve').kvp

I got:

{'DIR': 'ATM',
 'OUT': 'Analyse',
 'ave_length': 'TS_MO',
 'clim_period': '2500_2509',
 'clim_period_length': '*',
 'domain': '[-5, 5, 120, 290]',
 'experiment': 'pdControl',
 'frequency': 'monthly',
 'login': 'lurtont',
 'model': 'IPSLCM6',
 'period': 2500-2509,
 'project': 'IGCM_OUT',
 'root': '/ccc/store/cont003/thredds',
 'simulation': 'CM6015S-pd-03',
 'status': 'DEVT',
 'variable': 'taux'}

The attribute variable is updated with the aliased variable name (the one that is actually in the file). The problem appears downstream, when for instance I want to make ensemble statistics: the file contains the variable taux, and not tauu.

I would recommend to not update the attribute variable (as for frequency, that is not updated) with the method explore('resolve').

What do you think?

senesis commented 5 years ago

The issue is slightly more complex : explore('resolve') must consider all aliases for the dataset's project, for translating each variable name found in filenames to the canonical variable name. This is what I try in attached changed code. Could you test it on your case ? classes.py

jservonnat commented 5 years ago

The test didn't fit my needs. I've made a fix in classes.py that works, let me know what you think about it: First, just after self.kvp.copy(), I save the requested variable (req_var):

        dic=self.kvp.copy()
        req_var = dic["variable"]

And use it just before the call to ds() to update the dictionnary:

            # -- Use the requested variable instead of the aliased
            if self.alias :
               dic["variable"]=req_var
            #
            return ds(**dic)
senesis commented 5 years ago

OK. Coded for next release (1.2.11)

senesis commented 5 years ago

Done