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

Support CMIP3 #269

Merged
merged 42 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ecc7111
Add CMIP3 table and data convention
Sep 23, 2019
6f6b51b
Support conventions with no year on filename
Sep 23, 2019
3daa7d9
Support alyas for monthly in checks
Sep 23, 2019
65446dd
Fix tests
Sep 23, 2019
ff874cf
add CMIP3 file structure for DKRZ
LisaBock Sep 24, 2019
675c761
Fix time coord read
Sep 25, 2019
0683e72
Add CMIP3 institutes
Sep 25, 2019
b24388b
Fix typo
Sep 25, 2019
a9c2fb8
Add institute to output file
Sep 25, 2019
80b08ae
Remove duplicated
Sep 25, 2019
9536c1a
Do not override specified keys
Sep 25, 2019
65e279e
Support requested defined accros multiple lines
Sep 25, 2019
440278c
Fix config dev
Sep 25, 2019
57bffbe
small fix in CMIP3 table
LisaBock Oct 11, 2019
372f690
Add CMIP3 table and data convention
Sep 23, 2019
ba6e2a3
Support conventions with no year on filename
Sep 23, 2019
c2fc71c
Support alyas for monthly in checks
Sep 23, 2019
de5b9ae
Fix tests
Sep 23, 2019
0e51471
add CMIP3 file structure for DKRZ
LisaBock Sep 24, 2019
c8c60c4
Fix time coord read
Sep 25, 2019
71bbbeb
Add CMIP3 institutes
Sep 25, 2019
464ec76
Fix typo
Sep 25, 2019
b0a9f55
Add institute to output file
Sep 25, 2019
349bd72
Remove duplicated
Sep 25, 2019
8a1110e
Do not override specified keys
Sep 25, 2019
895c4be
Support requested defined accros multiple lines
Sep 25, 2019
1caf020
Fix config dev
Sep 25, 2019
e3c5439
small fix in CMIP3 table
LisaBock Oct 11, 2019
fbfb87b
Merge branch 'support_cmip3' of https://github.com/ESMValGroup/ESMVal…
Oct 14, 2019
60f8bc7
Changed bracket type for CMIP3 directory sructure
bettina-gier Oct 15, 2019
7f57cd8
Merge branch 'development' into support_cmip3
bouweandela Oct 15, 2019
6ff4674
Pass CMIP3 modeling_realm, freq to vars for derive
bettina-gier Oct 15, 2019
760919e
Merge branch 'support_cmip3' of github.com:ESMValGroup/ESMValCore int…
bettina-gier Oct 15, 2019
5ef0086
add institutes for CMIP3 models (ESGF names)
LisaBock Oct 17, 2019
3361e96
Merge branch 'development' into support_cmip3
LisaBock Nov 19, 2019
6fe99dd
fix CMIP3 table
LisaBock Nov 26, 2019
852f55b
Remove autogenerated file and add it to gitignore
Dec 20, 2019
b9917dd
Added autocomplete test
Dec 20, 2019
e83acd8
Apply suggestions from code review
Jan 9, 2020
007fcf9
Fix miroc plev fix
Jan 9, 2020
02149cc
Merge branch 'master' into support_cmip3
mattiarighi Jan 9, 2020
e88933c
Merge branch 'master' into support_cmip3
mattiarighi Jan 13, 2020
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Autogenerated files
_sidebar.rst.inc

# Distribution / packaging
.Python
build/
Expand Down
33 changes: 27 additions & 6 deletions esmvalcore/_data_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import re
import glob

import iris

from ._config import get_project_config

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,8 +48,8 @@ def get_start_end_year(filename):
"""
name = os.path.splitext(filename)[0]

filename = name.split(os.sep)[-1]
filename_list = [elem.split('-') for elem in filename.split('_')]
name = name.split(os.sep)[-1]
filename_list = [elem.split('-') for elem in name.split('_')]
filename_list = [elem for sublist in filename_list for elem in sublist]

pos_ydates = [elem.isdigit() and len(elem) >= 4 for elem in filename_list]
Expand All @@ -67,16 +69,35 @@ def get_start_end_year(filename):
filename_list[ind] for ind, _ in enumerate(pos_ydates)
if pos_ydates_r[ind] or pos_ydates_l[ind]
]

start_year = None
end_year = None
if len(dates) == 1:
start_year = int(dates[0][:4])
end_year = start_year
elif len(dates) == 2:
start_year, end_year = int(dates[0][:4]), int(dates[1][:4])
else:
raise ValueError('Name {0} dates do not match a recognized '
'pattern'.format(name))

# Slower than just parsing the name
bouweandela marked this conversation as resolved.
Show resolved Hide resolved
try:
cubes = iris.load(filename)
except OSError:
raise ValueError('File {0} can not be read'.format(filename))

for cube in cubes:
logger.debug(cube)
try:
time = cube.coord('time')
except iris.exceptions.CoordinateNotFoundError:
continue
start_year = time.cell(0).point.year
end_year = time.cell(-1).point.year
break

if not start_year or not end_year:
jvegreg marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(
'File {0} dates do not match a recognized pattern and time can '
'not be readed from the file'.format(filename)
jvegreg marked this conversation as resolved.
Show resolved Hide resolved
)
return start_year, end_year


Expand Down
14 changes: 8 additions & 6 deletions esmvalcore/_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,12 +1002,14 @@ def _initialize_variables(self, raw_variable, raw_datasets):
required_keys.update({'start_year', 'end_year'})
for variable in variables:
_update_from_others(variable, ['cmor_table', 'mip'], datasets)
institute = get_institutes(variable)
if institute:
variable['institute'] = institute
activity = get_activity(variable)
if activity:
variable['activity'] = activity
if 'institute' not in variable:
institute = get_institutes(variable)
if institute:
variable['institute'] = institute
if 'activity' not in variable:
activity = get_activity(variable)
if activity:
variable['activity'] = activity
check.variable(variable, required_keys)
variables = self._expand_ensemble(variables)
return variables
Expand Down
3 changes: 1 addition & 2 deletions esmvalcore/cmor/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def _check_dim_names(self):
coord.var_name = coordinate.out_name
else:
self.report_error(
'Coordinate {0} has var name {1}'
'Coordinate {0} has var name {1} '
'instead of {2}',
coordinate.name,
Expand Down Expand Up @@ -509,7 +508,7 @@ def _check_time_coord(self):
freq = self.frequency
if freq.lower().endswith('pt'):
freq = freq[:-2]
if freq == 'mon':
if freq in ['mon', 'mo']:
for i in range(len(coord.points) - 1):
first = coord.cell(i).point
second = coord.cell(i + 1).point
Expand Down
50 changes: 48 additions & 2 deletions esmvalcore/cmor/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def read_cmor_tables(cfg_developer):
cmor_strict = project.get('cmor_strict', True)
default_table_prefix = project.get('cmor_default_table_prefix', '')

if cmor_type == 'CMIP5':
if cmor_type == 'CMIP3':
CMOR_TABLES[table] = CMIP3Info(
table_path, default=custom, strict=cmor_strict,
)
elif cmor_type == 'CMIP5':
CMOR_TABLES[table] = CMIP5Info(
table_path, default=custom, strict=cmor_strict,
)
Expand Down Expand Up @@ -629,7 +633,9 @@ def _read_coordinate(self, value):
if key in ('variable_entry', 'axis_entry'):
return coord
if key == 'requested':
coord.requested = value.split(' ')
coord.requested.extend(
(val for val in value.split(' ') if val)
)
continue
if hasattr(coord, key):
setattr(coord, key, value)
Expand Down Expand Up @@ -707,6 +713,46 @@ def get_variable(self, table, short_name, derived=False):
return var_info


class CMIP3Info(CMIP5Info):
"""
Class to read CMIP3-like data request.

Parameters
----------
cmor_tables_path: basestring
Path to the folder containing the Tables folder with the json files

default: object
Default table to look variables on if not found

strict: bool
If False, will look for a variable in other tables if it can not be
found in the requested one

"""

def _read_table_file(self, table_file, table=None):
for dim in ('zlevel',):
coord = CoordinateInfo(dim)
coord.generic_level = True
coord.axis = 'Z'
self.coords[dim] = coord
super()._read_table_file(table_file, table)

def _read_coordinate(self, value):
coord = super()._read_coordinate(value)
if not coord.out_name:
coord.out_name = coord.name
coord.var_name = coord.name
return coord

def _read_variable(self, short_name, frequency):
var = super()._read_variable(short_name, frequency)
var.modeling_realm = None
var.frequency = None
return var


class CustomInfo(CMIP5Info):
"""
Class to read custom var info for ESMVal.
Expand Down
104 changes: 104 additions & 0 deletions esmvalcore/cmor/tables/cmip3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
2 changes: 2 additions & 0 deletions esmvalcore/cmor/tables/cmip3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cmip3-cmor-tables
Text Tables for CMOR1 to create a CMIP3 dataset
Loading