Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 34 additions & 34 deletions src/CSET/cset_workflow/app/fetch_fcst/bin/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _get_needed_environment_variables() -> dict:
def _get_needed_environment_variables_obs() -> dict:
"""Load the needed variables from the environment."""
variables = {
"subtype": os.environ["OBS_SUBTYPE"],
"subtype": ast.literal_eval(os.environ.get("OBS_SUBTYPE")),
"data_time": datetime.fromisoformat(os.environ["CYLC_TASK_CYCLE_POINT"]),
"forecast_length": isodate.parse_duration(os.environ["ANALYSIS_LENGTH"]),
"obs_fields": ast.literal_eval(os.environ["SURFACE_SYNOP_FIELDS"]),
Expand Down Expand Up @@ -331,40 +331,40 @@ def fetch_obs(obs_retriever: FileRetrieverABC):
os.makedirs(cycle_obs_dir, exist_ok=True)
logging.debug("Output directory: %s", cycle_obs_dir)

# We will get just one file for now, but follow the templating
# syntax for the model for consistency.
obs_base_path = (
v["subtype"]
+ "_"
+ "%Y%m%dT%H%MZ_dt_"
+ str(int(v["forecast_length"].total_seconds() // 3600)).zfill(3)
+ ".nc"
)
paths = _template_file_path(
obs_base_path,
"initiation",
v["data_time"],
v["forecast_length"],
timedelta(seconds=0),
v["obs_interval"],
)
logging.info("Retrieving paths:\n%s", "\n".join(paths))

# Use obs retriever to transfer data with multiple threads.
# We shouldn't need to iterate as we do for the forecast data
# because these files will be smaller.
try:
obs_retriever.get_file(
paths[0],
v["subtype"],
v["obs_fields"],
# Loop over requested obs subtypes
for subtype in v["subtype"]:
obs_base_path = (
subtype
+ "_"
+ "%Y%m%dT%H%MZ_dt_"
+ str(int(v["forecast_length"].total_seconds() // 3600)).zfill(3)
+ ".nc"
)
paths = _template_file_path(
obs_base_path,
"initiation",
v["data_time"],
v["obs_offset"],
v["forecast_length"],
timedelta(seconds=0),
v["obs_interval"],
cycle_obs_dir,
wmo_nmbrs=v["wmo_nmbrs"],
subarea_extent=v["subarea_extent"],
)
except Exception as exc:
raise ValueError("No observations available.") from exc
logging.info("Retrieving paths:\n%s", "\n".join(paths))

# Use obs retriever to transfer data with multiple threads.
# We shouldn't need to iterate as we do for the forecast data
# because these files will be smaller.
try:
obs_retriever.get_file(
paths[0],
subtype,
v["obs_fields"],
v["data_time"],
v["obs_offset"],
v["forecast_length"],
v["obs_interval"],
cycle_obs_dir,
wmo_nmbrs=v["wmo_nmbrs"],
subarea_extent=v["subarea_extent"],
)
except Exception as exc:
raise ValueError("No observations available.") from exc
10 changes: 6 additions & 4 deletions src/CSET/loaders/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def load(conf: Config):
recipe="generic_obs_scatterplot.yaml",
variables={
"OBSVARNAME": obs_field,
"PLOTTING_PROJECTION": conf.PLOTTING_PROJECTION
if conf.PLOTTING_PROJECTION
"SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
"SUBAREA_EXTENT": conf.SUBAREA_EXTENT
if conf.SELECT_SUBAREA
else None,
},
model_ids="OBS",
Expand All @@ -56,8 +57,9 @@ def load(conf: Config):
"OBSVARNAME": obs_field,
"VARNAME": model_field,
"MODEL_NAME": model["name"],
"PLOTTING_PROJECTION": conf.PLOTTING_PROJECTION
if conf.PLOTTING_PROJECTION
"SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
"SUBAREA_EXTENT": conf.SUBAREA_EXTENT
if conf.SELECT_SUBAREA
else None,
},
model_ids=[model["id"], "OBS"],
Expand Down
Loading
Loading