Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development cmip6fx conventions with cmor fixes to fx vars #22

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d320745
added fx path and file templates for fx vars for CMIP6
valeriupredoi Apr 29, 2019
6810170
replaced dodgy fxdir with actual mip
valeriupredoi Apr 29, 2019
07adaca
replaced fxvar to short_name
valeriupredoi Apr 29, 2019
09e3a12
implemented changes for fx files support for CMIP6 and actual treatme…
valeriupredoi May 1, 2019
5747d44
added a dedicated function for fx files dicovery and added profile wi…
valeriupredoi May 1, 2019
53a7f41
added conditional on fx frequency to disable time axis checks
valeriupredoi May 1, 2019
70da3c7
reassigning the output of the fxvar var as input for fx_file for the …
valeriupredoi May 1, 2019
d9565ba
generalize fx variable handling for CMIP5 as well
valeriupredoi May 2, 2019
d8f7ae8
correct implementation of fx files handling for both cmip5 and cmip6 …
valeriupredoi May 2, 2019
266fcee
implemented automation if fx vars are present in variable but are not…
valeriupredoi May 3, 2019
fa456d7
rewritten the fx var setup and made it more robust
valeriupredoi May 6, 2019
37f58a3
cleaned up and modularized
valeriupredoi May 7, 2019
bc83b80
added mapper for cmip6 fx mips - this needs more variables to be added
valeriupredoi May 7, 2019
f575d44
added function mapper for cmip6 fx variables
valeriupredoi May 7, 2019
eb6fdcd
added mapping for cmip6 fx variable mip
valeriupredoi May 7, 2019
eafcecd
fixed a snag that will assign fx file vars to fx file vars bleh
valeriupredoi May 7, 2019
633c48f
cleaned up and restructured a bit; also added check on tasks remove d…
valeriupredoi May 8, 2019
5084ef2
found and fixed bug in variable derivation tasking
valeriupredoi May 8, 2019
d83efe4
fixed another derive related bug
valeriupredoi May 8, 2019
6bf63b4
reverting task to original since implementation with ancestors is in
valeriupredoi May 8, 2019
89ded15
added use of ancestors rather than assigning task priorities in task.py
valeriupredoi May 8, 2019
eebf2f2
Merge branch 'version2_development' into version2_development_cmip6fx…
valeriupredoi May 8, 2019
8937743
fixed problem with overwriting ancestor files
valeriupredoi May 8, 2019
79896c3
allow for a different outfile path if we have a parent variable
valeriupredoi May 8, 2019
e4fe5c1
generalized for inclusion of fx variables as regular variables in recipe
valeriupredoi May 9, 2019
adb2551
fixed data finder test
valeriupredoi May 9, 2019
438bc04
removed all references to fx files and dirs
valeriupredoi May 10, 2019
5a5d617
removed fx related functions
valeriupredoi May 10, 2019
8db5f55
time chacks to be done only if the variable is not fx
valeriupredoi May 10, 2019
e16afb5
inline changes for removal of fx files finding and a bit of cleanup
valeriupredoi May 10, 2019
67aab02
removed data finder test for fx files
valeriupredoi May 10, 2019
7f08001
removed fx files functionalities
valeriupredoi May 10, 2019
10723da
more cleanup and migration of fx specific funcs to new module
valeriupredoi May 10, 2019
d025c0a
created WIP fx stuff module
valeriupredoi May 10, 2019
2ca8e08
removed all references to fx structure
valeriupredoi May 10, 2019
5068594
removed all traces of specific fx file retrieval
valeriupredoi May 12, 2019
909e34f
do time checks only if not fx variable
valeriupredoi May 12, 2019
1bbf364
removed references to fx files and dirs
valeriupredoi May 12, 2019
3e63424
removed fx files function
valeriupredoi May 12, 2019
33b9066
restructuring to allow for fx vars treated like any other var
valeriupredoi May 12, 2019
5614f7c
cleaning up
valeriupredoi May 13, 2019
475cd8f
cleaning up
valeriupredoi May 13, 2019
0ee4a72
fixed test for new fx file retrieval
valeriupredoi May 13, 2019
6989951
added checks for no time gating
valeriupredoi May 13, 2019
988d09c
fixed the test to reflect the new standards
valeriupredoi May 13, 2019
775715c
fixed the test to reflect the new standards
valeriupredoi May 13, 2019
32b6376
fixed the data structure standard to reflect new standards
valeriupredoi May 13, 2019
d50465c
Merge branch 'version2_development' into version2_development_fx_REST…
valeriupredoi May 13, 2019
f290436
Merge branch 'version2_development_fx_RESTRUCTURED' into version2_dev…
valeriupredoi May 13, 2019
26cf5ba
cleaning up again
valeriupredoi May 13, 2019
b0025fd
removed unused module
valeriupredoi May 13, 2019
87c5494
fixed almost all tests, bar a derive one that I need to look into mor…
valeriupredoi May 13, 2019
7325751
fixed test properly to account for full functionality of fx ancestry …
valeriupredoi May 15, 2019
7cc6c09
final bug fixes and error raising
valeriupredoi May 15, 2019
07fa270
Merge branch 'version2_development' into version2_development_cmip6fx…
valeriupredoi Jun 10, 2019
2166810
Merge branch 'development' into development_cmip6fxConventions
valeriupredoi Jun 10, 2019
d4ad12f
removed stray import introduced by merge
valeriupredoi Jun 10, 2019
ef631a9
removed unused import
valeriupredoi Jun 10, 2019
c127f45
Merge branch 'development' into development_cmip6fxConventions
valeriupredoi Jun 14, 2019
fefc715
removed unused import
valeriupredoi Jun 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions esmvalcore/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,6 @@ def get_institutes(variable):
return CFG.get(project, {}).get('institutes', {}).get(dataset, [])


def replace_mip_fx(fx_file):
"""Replace MIP so to retrieve correct fx files."""
default_mip = 'Amon'
if fx_file not in CFG['CMIP5']['fx_mip_change']:
logger.warning(
'mip for fx variable %s is not specified in '
'config_developer.yml, using default (%s)', fx_file, default_mip)
new_mip = CFG['CMIP5']['fx_mip_change'].get(fx_file, default_mip)
logger.debug("Switching mip for fx file finding to %s", new_mip)
return new_mip


TAGS_CONFIG_FILE = os.path.join(
DIAGNOSTICS_PATH, 'config-references.yml')

Expand Down
80 changes: 35 additions & 45 deletions esmvalcore/_data_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import os
import re

from ._config import get_project_config, replace_mip_fx
from .cmor.table import CMOR_TABLES
from ._config import get_project_config

logger = logging.getLogger(__name__)


def find_files(dirnames, filenames):
"""Find files matching filenames in dirnames."""
logger.debug("Looking for files matching %s in %s", filenames, dirnames)
logger.info("Looking for files matching %s in %s", filenames, dirnames)

result = []
for dirname in dirnames:
Expand Down Expand Up @@ -93,7 +92,7 @@ def select_files(filenames, start_year, end_year):
return selection


def _replace_tags(path, variable, fx_var=None):
def _replace_tags(path, variable):
"""Replace tags in the config-developer's file with actual values."""
path = path.strip('/')

Expand All @@ -104,9 +103,7 @@ def _replace_tags(path, variable, fx_var=None):
original_tag = tag
tag, _, _ = _get_caps_options(tag)

if tag == 'fx_var':
replacewith = fx_var
elif tag == 'latestversion': # handled separately later
if tag == 'latestversion': # handled separately later
continue
elif tag in variable:
replacewith = variable[tag]
Expand Down Expand Up @@ -196,16 +193,16 @@ def get_rootpath(rootpath, project):
raise KeyError('default rootpath must be specified in config-user file')


def _find_input_dirs(variable, rootpath, drs, fx_var=None):
def _find_input_dirs(variable, rootpath, drs):
"""Return a the full paths to input directories."""
project = variable['project']

root = get_rootpath(rootpath, project)
input_type = 'input_{}dir'.format('fx_' if fx_var else '')
input_type = 'input_dir'
path_template = _select_drs(input_type, drs, project)

dirnames = []
for dirname_template in _replace_tags(path_template, variable, fx_var):
for dirname_template in _replace_tags(path_template, variable):
for base_path in root:
dirname = os.path.join(base_path, dirname_template)
dirname = _resolve_latestversion(dirname)
Expand All @@ -218,51 +215,36 @@ def _find_input_dirs(variable, rootpath, drs, fx_var=None):
return dirnames


def _get_filenames_glob(variable, drs, fx_var=None):
def _get_filenames_glob(variable, drs):
"""Return patterns that can be used to look for input files."""
input_type = 'input_{}file'.format('fx_' if fx_var else '')
input_type = 'input_file'
path_template = _select_drs(input_type, drs, variable['project'])
filenames_glob = _replace_tags(path_template, variable, fx_var)
filenames_glob = _replace_tags(path_template, variable)
return filenames_glob


def _find_input_files(variable, rootpath, drs, fx_var=None):
logger.debug("Looking for input %sfiles for variable %s of dataset %s",
fx_var + ' fx ' if fx_var else '', variable['short_name'],
variable['dataset'])

input_dirs = _find_input_dirs(variable, rootpath, drs, fx_var)
filenames_glob = _get_filenames_glob(variable, drs, fx_var)
def _find_input_files(variable, rootpath, drs):
input_dirs = _find_input_dirs(variable, rootpath, drs)
filenames_glob = _get_filenames_glob(variable, drs)
files = find_files(input_dirs, filenames_glob)

return files


def get_input_filelist(variable, rootpath, drs):
"""Return the full path to input files."""
# change ensemble to fixed r0i0p0 for fx variables
if variable['project'] == 'CMIP5'and variable['frequency'] == 'fx':
variable['ensemble'] = 'r0i0p0'
files = _find_input_files(variable, rootpath, drs)
files = select_files(files, variable['start_year'], variable['end_year'])
# do time gating only for non-fx variables
if variable['frequency'] != 'fx':
files = select_files(files, variable['start_year'],
variable['end_year'])
return files


def get_input_fx_filelist(variable, rootpath, drs):
"""Return a dict with the full path to fx input files."""
fx_files = {}
for fx_var in variable['fx_files']:
var = dict(variable)
var['mip'] = replace_mip_fx(fx_var)
table = CMOR_TABLES[var['cmor_table']].get_table(var['mip'])
var['frequency'] = table.frequency
realm = getattr(table.get(var['short_name']), 'modeling_realm', None)
var['modeling_realm'] = realm if realm else table.realm

files = _find_input_files(var, rootpath, drs, fx_var)
fx_files[fx_var] = files[0] if files else None

return fx_files


def get_output_file(variable, preproc_dir):
def get_output_file(variable, preproc_dir, parent_var=None):
"""Return the full path to the output (preprocessed) file."""
cfg = get_project_config(variable['project'])

Expand All @@ -271,12 +253,20 @@ def get_output_file(variable, preproc_dir):
variable = dict(variable)
variable['exp'] = '-'.join(variable['exp'])

outfile = os.path.join(
preproc_dir,
variable['diagnostic'],
variable['variable_group'],
_replace_tags(cfg['output_file'], variable)[0] + '.nc',
)
if not parent_var:
outfile = os.path.join(
preproc_dir,
variable['diagnostic'],
variable['variable_group'],
_replace_tags(cfg['output_file'], variable)[0] + '.nc',
)
else:
outfile = os.path.join(
preproc_dir,
variable['diagnostic'],
parent_var['variable_group'],
_replace_tags(cfg['output_file'], variable)[0] + '.nc',
)

return outfile

Expand Down
Loading