Skip to content

Commit

Permalink
Add esmvalcore.dataset module (#1877)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com>
  • Loading branch information
bouweandela and schlunma authored Jan 13, 2023
1 parent 80dc689 commit de1a27d
Show file tree
Hide file tree
Showing 40 changed files with 4,171 additions and 108 deletions.
5 changes: 5 additions & 0 deletions doc/api/esmvalcore.dataset.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dataset
=======

.. automodule:: esmvalcore.dataset
:no-show-inheritance:
1 change: 1 addition & 0 deletions doc/api/esmvalcore.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ library. This section documents the public API of ESMValCore.

esmvalcore.cmor
esmvalcore.config
esmvalcore.dataset
esmvalcore.esgf
esmvalcore.exceptions
esmvalcore.iris_helpers
Expand Down
3 changes: 2 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'autodocsumm',
'nbsphinx',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
Expand All @@ -54,7 +56,6 @@
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'autodocsumm',
]

autodoc_default_options = {
Expand Down
13 changes: 13 additions & 0 deletions doc/example-notebooks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Example notebooks
*****************

Example notebooks are available in the
`notebooks <https://github.com/ESMValGroup/ESMValCore/tree/main/notebooks>`__
folder and can also be viewed here.
These notebooks demonstrate the use of the :ref:`Python API <api>`.

.. toctree::
:maxdepth: 1
:glob:

notebooks/*
1 change: 1 addition & 0 deletions doc/gensidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def _header(project, text):

_header("esmvalcore", "ESMValCore")
_write("esmvalcore", "Getting started", "quickstart/index")
_write("esmvalcore", "Example notebooks", "example-notebooks")
_write("esmvalcore", "The recipe format", "recipe/index")
_write("esmvalcore", "Diagnostic script interfaces", "interfaces")
_write("esmvalcore", "Development", "develop/index")
Expand Down
1 change: 1 addition & 0 deletions doc/notebooks
5 changes: 5 additions & 0 deletions doc/quickstart/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ omitted in the file.
# on a computer without an internet connection.
offline: true
# Search ESGF for files even when files are available locally --- true/[false]
# This option is useful to make sure you have the latest version of all files.
# Remember to set ``offline: false`` if this option is set to ``true``.
always_search_esgf: false
# Auxiliary data directory
# Used by some recipes to look for additional datasets.
auxiliary_data_dir: ~/auxiliary_data
Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ dependencies:
- yamale
# Python packages needed for building docs
- autodocsumm>=0.2.2
- ipython
- nbsphinx
- sphinx>=5
- sphinx_rtd_theme
# Python packages needed for testing
Expand Down
2 changes: 1 addition & 1 deletion esmvalcore/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def process_recipe(recipe_file: Path, session):
import shutil
import warnings

from ._recipe import read_recipe_file
from esmvalcore._recipe.recipe import read_recipe_file
if not recipe_file.is_file():
import errno
raise OSError(errno.ENOENT, "Specified recipe file does not exist",
Expand Down
1 change: 1 addition & 0 deletions esmvalcore/_recipe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Load and run recipes."""
27 changes: 14 additions & 13 deletions esmvalcore/_recipe_checks.py → esmvalcore/_recipe/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import isodate
import yamale

from .exceptions import InputFilesNotFound, RecipeError
from .local import _get_start_end_year
from .preprocessor import TIME_PREPROCESSORS, PreprocessingTask
from .preprocessor._multimodel import STATISTIC_MAPPING
from esmvalcore.exceptions import InputFilesNotFound, RecipeError
from esmvalcore.local import _get_start_end_year, _parse_period
from esmvalcore.preprocessor import TIME_PREPROCESSORS, PreprocessingTask
from esmvalcore.preprocessor._multimodel import STATISTIC_MAPPING

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -141,18 +141,20 @@ def data_availability(input_files, var, patterns, log=True):

if not input_files:
raise InputFilesNotFound(
f"Missing data for {var['alias']}: {var['short_name']}")
f"Missing data for {var.get('alias', 'dataset')}: "
f"{var['short_name']}")

if var['frequency'] == 'fx':
# check time availability only for non-fx variables
if 'timerange' not in var:
return
start_year = var['start_year']
end_year = var['end_year']

start_date, end_date = _parse_period(var['timerange'])
start_year = int(start_date[0:4])
end_year = int(end_date[0:4])
required_years = set(range(start_year, end_year + 1, 1))
available_years = set()

for filename in input_files:
start, end = _get_start_end_year(filename)
for file in input_files:
start, end = _get_start_end_year(file.name)
available_years.update(range(start, end + 1))

missing_years = required_years - available_years
Expand Down Expand Up @@ -246,8 +248,7 @@ def _verify_keep_input_datasets(keep_input_datasets):
if not isinstance(keep_input_datasets, bool):
raise RecipeError(
"Invalid value encountered for `keep_input_datasets`."
f"Must be defined as a boolean. Got {keep_input_datasets}."
)
f"Must be defined as a boolean. Got {keep_input_datasets}.")


def _verify_arguments(given, expected):
Expand Down
Loading

0 comments on commit de1a27d

Please sign in to comment.