Skip to content

Commit 7d8aef1

Browse files
updates following PR reviews
1 parent a27442c commit 7d8aef1

File tree

6 files changed

+61
-80
lines changed

6 files changed

+61
-80
lines changed

CMEW/app/configure_standardise/bin/configure_standardise.sh

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,15 @@
33
# The LICENSE.md file contains full licensing details.
44
# Send the output from 'set -x' to 'stdout' rather than 'stderr'.
55
BASH_XTRACEFD=1
6-
set -xeuo pipefail
7-
8-
# ---------------------------------------------------------------------------
9-
# 0. Defensive programming (multi-run)
10-
# ---------------------------------------------------------------------------
11-
: "${RUN_LABEL:?RUN_LABEL must be set (suite_id e.g. u-bv526)}"
12-
: "${REQUEST_PATH:?REQUEST_PATH must be set}"
13-
: "${VARIABLES_PATH:?VARIABLES_PATH must be set}"
14-
15-
: "${START_YEAR:?START_YEAR must be set}"
16-
: "${NUMBER_OF_YEARS:?NUMBER_OF_YEARS must be set}"
17-
: "${INSTITUTION_ID:?INSTITUTION_ID must be set}"
18-
: "${ROOT_PROC_DIR:?ROOT_PROC_DIR must be set}"
19-
: "${ROOT_DATA_DIR:?ROOT_DATA_DIR must be set}"
6+
set -xeu
207

218
# We support two-model metadata via REF_* + non-REF vars.
229
# Decide which set must be present based on RUN_LABEL.
2310
REF_SUITE_ID="${REF_SUITE_ID:-}"
2411
SUITE_ID="${SUITE_ID:-}"
2512

26-
echo "[INFO] RUN_LABEL=${RUN_LABEL}"
27-
echo "[INFO] REQUEST_PATH=${REQUEST_PATH}"
28-
echo "[INFO] VARIABLES_PATH=${VARIABLES_PATH}"
29-
echo "[INFO] START_YEAR=${START_YEAR}"
30-
echo "[INFO] NUMBER_OF_YEARS=${NUMBER_OF_YEARS}"
31-
echo "[INFO] INSTITUTION_ID=${INSTITUTION_ID}"
32-
echo "[INFO] ROOT_PROC_DIR=${ROOT_PROC_DIR}"
33-
echo "[INFO] ROOT_DATA_DIR=${ROOT_DATA_DIR}"
34-
35-
if [[ -n "${REF_SUITE_ID}" && "${RUN_LABEL}" == "${REF_SUITE_ID}" ]]; then
36-
: "${REF_MODEL_ID:?REF_MODEL_ID must be set (because RUN_LABEL == REF_SUITE_ID)}"
37-
: "${REF_SUITE_ID:?REF_SUITE_ID must be set (because RUN_LABEL == REF_SUITE_ID)}"
38-
: "${REF_CALENDAR:?REF_CALENDAR must be set (because RUN_LABEL == REF_SUITE_ID)}"
39-
: "${REF_VARIANT_LABEL:?REF_VARIANT_LABEL must be set (because RUN_LABEL == REF_SUITE_ID)}"
40-
41-
echo "[INFO] Mode: REF (matched RUN_LABEL==REF_SUITE_ID)"
42-
echo "[INFO] REF_MODEL_ID=${REF_MODEL_ID}"
43-
echo "[INFO] REF_SUITE_ID=${REF_SUITE_ID}"
44-
echo "[INFO] REF_CALENDAR=${REF_CALENDAR}"
45-
echo "[INFO] REF_VARIANT_LABEL=${REF_VARIANT_LABEL}"
46-
else
47-
# evaluation / default path
48-
: "${MODEL_ID:?MODEL_ID must be set}"
49-
: "${SUITE_ID:?SUITE_ID must be set}"
50-
: "${CALENDAR:?CALENDAR must be set}"
51-
: "${VARIANT_LABEL:?VARIANT_LABEL must be set}"
52-
53-
echo "[INFO] Mode: non-REF (legacy/eval/default)"
54-
echo "[INFO] MODEL_ID=${MODEL_ID}"
55-
echo "[INFO] SUITE_ID=${SUITE_ID}"
56-
echo "[INFO] CALENDAR=${CALENDAR}"
57-
echo "[INFO] VARIANT_LABEL=${VARIANT_LABEL}"
58-
fi
59-
6013
# ---------------------------------------------------------------------------
61-
# 1. Create variables.txt once (shared by both runs)
14+
# 1. Create variables.txt
6215
# ---------------------------------------------------------------------------
6316
echo "[INFO] Creating variables file from ESMValTool recipe"
6417
cmew-esmvaltool-env create_variables_file.py

CMEW/app/configure_standardise/bin/create_request_file.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,32 @@
2929
Environment variables are accessed directly via os.environ[...].
3030
"""
3131

32-
from __future__ import annotations
33-
3432
import configparser
3533
import os
3634
from pathlib import Path
3735

3836

39-
def create_request() -> configparser.ConfigParser:
37+
def create_request():
38+
"""
39+
Build a CDDS request configuration for the run identified by RUN_LABEL.
40+
41+
The function expects a two-run CMEW configuration to be present in the
42+
environment: one reference run (REF_*) and
43+
one evaluation run (MODEL_ID/SUITE_ID/...).
44+
45+
Behaviour:
46+
- Reads all required metadata directly from environment variables.
47+
- Selects the reference or evaluation metadata according to RUN_LABEL.
48+
- Raises KeyError if a required environment variable is missing.
49+
- Raises KeyError if RUN_LABEL matches neither REF_SUITE_ID nor SUITE_ID.
50+
51+
Returns
52+
-------
53+
configparser.ConfigParser
54+
A populated CDDS request configuration with sections:
55+
metadata, common, data, misc, and conversion.
56+
"""
57+
4058
# Required time window
4159
start_year = int(os.environ["START_YEAR"])
4260
number_of_years = int(os.environ["NUMBER_OF_YEARS"])
@@ -62,7 +80,6 @@ def create_request() -> configparser.ConfigParser:
6280
# Must be set in two-run mode
6381
run_label = os.environ["RUN_LABEL"].strip()
6482

65-
# Optional experiment IDs (default to "amip" if not provided)
6683
ref_experiment_id = (
6784
os.environ.get("REF_EXPERIMENT_ID", "amip").strip() or "amip"
6885
)
@@ -143,15 +160,35 @@ def create_request() -> configparser.ConfigParser:
143160
return request
144161

145162

146-
def write_request(
147-
request: configparser.ConfigParser, target_path: Path
148-
) -> None:
163+
def write_request(request, target_path):
164+
"""
165+
Write a CDDS request configuration to disk.
166+
167+
The parent directory of ``target_path`` is created if it does
168+
not already exist.
169+
170+
Parameters
171+
----------
172+
request : configparser.ConfigParser
173+
The populated request configuration to write.
174+
target_path : pathlib.Path
175+
Destination file path for the generated request configuration.
176+
"""
177+
149178
target_path.parent.mkdir(parents=True, exist_ok=True)
150179
with open(target_path, mode="w", encoding="utf-8") as fh:
151180
request.write(fh)
152181

153182

154-
def main() -> None:
183+
def main():
184+
"""
185+
Generate and write the request file for the current task environment.
186+
187+
The output file location is taken from the REQUEST_PATH environment
188+
variable. All other required inputs are read from the environment
189+
by ``create_request()``.
190+
"""
191+
155192
target_path = Path(os.environ["REQUEST_PATH"])
156193
request = create_request()
157194
write_request(request, target_path)
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
#!/bin/bash
2-
# (C) Crown Copyright 2024-2026, Met Office.
2+
# (C) Crown Copyright 2024-2025, Met Office.
33
# The LICENSE.md file contains full licensing details.
4-
54
# Send the output from 'set -x' to 'stdout' rather than 'stderr'.
65
BASH_XTRACEFD=1
7-
set -xeuo pipefail
8-
9-
: "${ROOT_DATA_DIR:?ROOT_DATA_DIR must be set}"
10-
: "${CYLC_WORKFLOW_SHARE_DIR:?CYLC_WORKFLOW_SHARE_DIR must be set}"
11-
: "${CDDS_SOFTWARE_DIR:?CDDS_SOFTWARE_DIR must be set}"
6+
set -xeu
127

138
RESTRUCTURE_COMMAND="${CDDS_SOFTWARE_DIR}/ceda-mip-tools/bin/restructure_for_cmip6"
149
ROOT_RESTRUCTURED_DIR="${CYLC_WORKFLOW_SHARE_DIR}/work/"
1510

16-
# This ensures restructuring occurs once after both conversions complete.
17-
echo "[INFO] Restructuring ${ROOT_DATA_DIR} -> ${ROOT_RESTRUCTURED_DIR}"
1811
"${RESTRUCTURE_COMMAND}" -d "${ROOT_RESTRUCTURED_DIR}" "${ROOT_DATA_DIR}"

CMEW/app/standardise_model_data/bin/standardise_model_data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Standardise data for both REF and EVAL runs via CDDS.
55

66
BASH_XTRACEFD=1
7-
set -xeuo pipefail
7+
set -xeu
88

99
: "${RUN_LABEL:?RUN_LABEL must be set (ref/eval)}"
1010
: "${REQUEST_PATH:?REQUEST_PATH must be set}"

CMEW/app/standardise_model_data/rose-app.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Crown Copyright 2024-2026, Met Office.
1+
# (C) Crown Copyright 2024-2025, Met Office.
22
# The LICENSE.md file contains full licensing details.
33

44
[command]

CMEW/flow.cylc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@
2424
{%- if not UNITTEST %}
2525
install_env_file => configure_recipe & add_datasets
2626
add_datasets => configure_for<recipe>
27-
2827
configure_for<recipe> => configure_standardise<recipe,dataset>
28+
=> standardise_model_data<dataset> => restructure_dirs
29+
configure_recipe & restructure_dirs
30+
=> run_recipe<recipe> & housekeeping
2931

30-
configure_standardise<recipe,dataset> => standardise_model_data<dataset>
31-
standardise_model_data<dataset> => restructure_dirs
32-
33-
configure_recipe & restructure_dirs => run_recipe<recipe>
34-
run_recipe<recipe> => housekeeping
3532
{%- if TEST %}
3633
run_recipe<recipe> => compare<recipe>
3734
{%- endif %}
@@ -66,6 +63,11 @@
6663
ROOT_SOFTWARE_DIR = ${CDDS_SOFTWARE_DIR}
6764
CDDS_VERSION = {{ CDDS_VERSION }}
6865

66+
[[PER_DATASET]]
67+
[[[environment]]]
68+
RUN_LABEL = ${CYLC_TASK_PARAM_dataset}
69+
REQUEST_PATH = ${CYLC_WORKFLOW_SHARE_DIR}/etc/request_${CYLC_TASK_PARAM_dataset}.cfg
70+
6971
# Multi-run metadata family: reference and evaluation runs
7072
[[MODEL_RUNS]]
7173
[[[environment]]]
@@ -123,21 +125,17 @@
123125
REF_SUITE_ID = {{ REF_SUITE_ID }}
124126

125127
[[configure_standardise<recipe,dataset>]]
126-
inherit = STANDARDISE, RECIPE, MODEL_RUNS
128+
inherit = STANDARDISE, RECIPE, MODEL_RUNS, PER_DATASET
127129
[[[environment]]]
128130
ROSE_TASK_APP = configure_standardise
129-
RUN_LABEL = %(dataset)s
130-
REQUEST_PATH = ${CYLC_WORKFLOW_SHARE_DIR}/etc/request_%(dataset)s.cfg
131131
START_YEAR = {{ START_YEAR }}
132132
NUMBER_OF_YEARS = {{ NUMBER_OF_YEARS }}
133133

134134
[[standardise_model_data<dataset>]]
135-
inherit = STANDARDISE
135+
inherit = STANDARDISE, PER_DATASET
136136
[[[environment]]]
137137
ROSE_TASK_APP = standardise_model_data
138138
SITE = {{ SITE }}
139-
RUN_LABEL = %(dataset)s
140-
REQUEST_PATH = ${CYLC_WORKFLOW_SHARE_DIR}/etc/request_%(dataset)s.cfg
141139

142140
[[restructure_dirs]]
143141
inherit = STANDARDISE

0 commit comments

Comments
 (0)