Skip to content

Commit

Permalink
Show files of supplementary variables explicitly in log (#2303)
Browse files Browse the repository at this point in the history
Co-authored-by: Bouwe Andela <[email protected]>
  • Loading branch information
schlunma and bouweandela authored Jan 17, 2024
1 parent 009a985 commit a9e2f51
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions esmvalcore/_recipe/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,42 @@ def _add_to_download_list(dataset):


def _schedule_for_download(datasets):
"""Schedule files for download and show the list of files in the log."""
"""Schedule files for download."""
for dataset in datasets:
_add_to_download_list(dataset)
for supplementary_ds in dataset.supplementaries:
_add_to_download_list(supplementary_ds)

files = list(dataset.files)
for supplementary_ds in dataset.supplementaries:
files.extend(supplementary_ds.files)

def _log_input_files(datasets: Iterable[Dataset]) -> None:
"""Show list of files in log (including supplementaries)."""
for dataset in datasets:
# Only log supplementary variables if present
supplementary_files_str = ""
if dataset.supplementaries:
for sup_ds in dataset.supplementaries:
supplementary_files_str += (
f"\nwith files for supplementary variable "
f"{sup_ds['short_name']}:\n{_get_files_str(sup_ds)}"
)

logger.debug(
"Using input files for variable %s of dataset %s:\n%s",
"Using input files for variable %s of dataset %s:\n%s%s",
dataset.facets['short_name'],
dataset.facets['alias'].replace('_', ' '),
'\n'.join(f'{f} (will be downloaded)' if not f.exists() else str(f)
for f in files),
dataset.facets['alias'].replace('_', ' '), # type: ignore
_get_files_str(dataset),
supplementary_files_str
)


def _get_files_str(dataset: Dataset) -> str:
"""Get nice string representation of all files of a dataset."""
return '\n'.join(
f' {f}' if f.exists() # type: ignore
else f' {f} (will be downloaded)' for f in dataset.files
)


def _check_input_files(input_datasets: Iterable[Dataset]) -> set[str]:
"""Check that the required input files are available."""
missing = set()
Expand Down Expand Up @@ -517,6 +534,7 @@ def _get_preprocessor_products(
_set_version(dataset, input_datasets)
USED_DATASETS.append(dataset)
_schedule_for_download(input_datasets)
_log_input_files(input_datasets)
logger.info("Found input files for %s", dataset.summary(shorten=True))

filename = _get_output_file(
Expand Down

0 comments on commit a9e2f51

Please sign in to comment.