rigoudyg / climaf

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

Errors with 'first_XXY' or 'last_XXY' #124

Closed jservonnat closed 5 years ago

jservonnat commented 5 years ago

I've tried to use the value 'first_10Y' or 'last_10Y' for period and it works very well. There is only an issue if ds() doesn't find any file matching the request. It directly returns an error (python error, not CliMAF error) that is not easy to understand for the user:

test = ds(project='CMIP6', variable='tos', table='Amon', model='IPSL-CM6A-LR', experiment='historical',
          period='first_10Y', version='latest')
warning  : no file found for {'domain': 'global', 'experiment': 'historical', 'institute': '*', 'table': 'Amon', 'period': '*', 'simulation': '', 'project': 'CMIP6', 'version': 'latest', 'grid': 'g*', 'realization': 'r1i1p1f*', 'variable': 'tos', 'mip': '*', 'model': 'IPSL-CM6A-LR', 'root': '/bdd'}, at these data locations ['${root}/CMIP6/${mip}/${institute}/${model}/${experiment}/${realization}/${table}/${variable}/${grid}/${version}/${variable}_${table}_${model}_${experiment}_${realization}_${grid}_${PERIOD}.nc', '${root}/CMIP6/${mip}/${institute}/${model}/${experiment}/${realization}/${table}/${variable}/${grid}/${version}/${variable}_${table}_${model}_${experiment}_${realization}_${grid}.nc'] 
warning  : Please check these empty attributes ['simulation']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-33-dced38ba2e95> in <module>()
      1 cdef('version','latest', project='CMIP5')
      2 test = ds(project='CMIP6', variable='tos', table='Amon', model='IPSL-CM6A-LR', experiment='historical',
----> 3           period='first_10Y', version='latest')

/ciclad-home/jservon/Evaluation/CliMAF/climaf_installs/climaf_1.2.10/climaf/classes.pyc in ds(*args, **kwargs)
   1375             if match is not None :
   1376                 return resolve_first_or_last_years(copy.deepcopy(kwargs),match.group('duration'),
-> 1377                                                    option=match.group('option').lower())
   1378         return cdataset(**select_projects(**kwargs))
   1379 

/ciclad-home/jservon/Evaluation/CliMAF/climaf_installs/climaf_1.2.10/climaf/classes.pyc in resolve_first_or_last_years(kwargs, duration, option)
   1973     explorer=ds(**kwargs)
   1974     attributes=explorer.explore(option='choices')
-> 1975     periods=attributes['period']
   1976     period=periods[-1]
   1977     if option=='last'  : kwargs['period']=lastyears(period,int(duration))

KeyError: 'period'

The error is returned directly from the call to ds(). And if we use an explicit period (say, '1980') or '*' instead of 'first_10Y' or 'last_10Y', we don't have the error (which is what we got used to).

That would be great to have the same behavior for the explicit period, '*' or 'last_XXY' and 'first_XXY'. For me the best behavior is to have an error only when checking what ds() found, either with summary or explore.

What do you think?

jservonnat commented 5 years ago

Fixed by @senesis