Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f306f2b
initial commit for write selected channels during inference
sbAsma Mar 27, 2026
8f953a3
added config to control filtering of channels in output
sbAsma Mar 27, 2026
2e41993
renamed variable that filters channels
sbAsma Mar 27, 2026
28b3612
defer val_target_channels lookup when filter_output_channels is set
sbAsma Mar 27, 2026
8d773af
add output_channels metadata and default_config based output filtering
sbAsma Mar 28, 2026
967fdbd
applied ruff requested fixes
sbAsma Mar 28, 2026
fe4ea85
fixed backward compatibility for filtering of channels in output
sbAsma Mar 29, 2026
22a3f50
restore default config to default status
sbAsma Mar 29, 2026
55cf5b2
removed unecessary introduced code
sbAsma Mar 29, 2026
6c8bcfb
resolved merge conflict
sbAsma Apr 21, 2026
5c3ac42
Merge branch 'develop' into sbAsma/dev/1705-write-selected-channels
SavvasMel Apr 29, 2026
b4e91e1
merged develop and resolved conflict
sbAsma Jun 10, 2026
f7866ec
Merge branch 'sbAsma/dev/1705-write-selected-channels' of https://git…
sbAsma Jun 10, 2026
59dd297
fixed variable declaration bug
sbAsma Jun 10, 2026
9abaa85
Merge branch 'develop' into sbAsma/dev/1705-write-selected-channels
SavvasMel Jun 12, 2026
55edbae
change ERA5 file
sbAsma Jun 18, 2026
6cd1832
put filtering of channels in function and changed config
sbAsma Jun 22, 2026
f572bd9
Merge branch 'develop' of https://github.com/ecmwf/WeatherGenerator i…
sbAsma Jun 22, 2026
2692418
Merge branch 'develop' into sbAsma/dev/1705-write-selected-channels
sbAsma Jun 22, 2026
7124676
restored ERA5 file
sbAsma Jun 22, 2026
0fcb2f9
Merge branch 'develop' into sbAsma/dev/1705-write-selected-channels
clessig Jun 29, 2026
6f3e8f4
reverted ERA5 config
sbAsma Jul 8, 2026
14109e9
modified field for filtering channels
sbAsma Jul 8, 2026
31c2c5e
Improve channel filter logging and rename config key to output.channels
sbAsma Jul 8, 2026
b49e49a
simplified variables selection
sbAsma Jul 10, 2026
e2b96ab
changed default writing channels to all
sbAsma Jul 14, 2026
c61abab
changed output channel filter to handle None, all, and single-string …
sbAsma Jul 14, 2026
558b7a4
added a more compact code writing
sbAsma Aug 4, 2026
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
4 changes: 4 additions & 0 deletions config/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ validation_config:
normalized_samples: False,
# output streams to write; default all
streams: null,
# channels that will be written; default all
channels: {
"ERA5": "all"
}
}

# run validation before training starts (mainly for model development)
Expand Down
69 changes: 66 additions & 3 deletions src/weathergen/utils/validation_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,68 @@
_logger = logging.getLogger(__name__)


def _filter_output_channels(
filter_cfg,
stream_names: list[str],
target_channels: list[list[str]],
targets_all: list,
preds_all: list,
) -> None:
"""Apply per-stream channel filtering in-place.

Args:
filter_cfg: The ``filter_output_channels`` config mapping
``{STREAM_NAME: [channels]}``. An empty list or ``None`` for a
stream means no filtering for that stream.
stream_names: Ordered list of stream names.
target_channels: Per-stream list of channel names (mutated in-place).
targets_all: Nested list ``[t_idx][stream_idx]`` of target arrays
(mutated in-place).
preds_all: Nested list ``[t_idx][stream_idx]`` of prediction arrays
(mutated in-place).
"""
if not filter_cfg:
return

for stream_idx, stream_name in enumerate(stream_names):
write_vars = filter_cfg.get(stream_name)
if write_vars is None or (isinstance(write_vars, str) and write_vars.lower() == "all"):
continue
write_vars = [write_vars] if isinstance(write_vars, str) else list(write_vars)
if len(write_vars) == 0:
continue

all_channels = target_channels[stream_idx]
write_vars_set = set(write_vars)
keep_idxs = [i for i, ch in enumerate(all_channels) if ch in write_vars_set]

missing = write_vars_set - set(all_channels)
if missing:
_logger.warning(
f"filter_output_channels for stream {stream_name} "
f"contains unknown channels, which will be skipped: {missing}"
)
if not keep_idxs:
_logger.warning(
f"filter_output_channels for stream {stream_name} matched no channels; "
f"skipping filter."
)
continue
if len(keep_idxs) == len(all_channels):
continue
keep_names = [all_channels[i] for i in keep_idxs]
removed_names = [ch for ch in all_channels if ch not in keep_names]
_logger.debug(
f"Filtering output channels for stream {stream_name}: "
f"{len(all_channels)} -> {len(keep_idxs)} channels; "
f"kept: {keep_names}; removed: {removed_names}"
)
target_channels[stream_idx] = [all_channels[i] for i in keep_idxs]
for t_idx in range(len(targets_all)):
targets_all[t_idx][stream_idx] = targets_all[t_idx][stream_idx][:, keep_idxs]
preds_all[t_idx][stream_idx] = preds_all[t_idx][stream_idx][:, :, keep_idxs]


def write_output(
cf, val_cfg, batch_size, mini_epoch, batch_idx, dn_data, batch, model_output, target_aux_out
):
Expand Down Expand Up @@ -119,8 +181,6 @@ def write_output(
for sample in batch.get_source_samples().get_samples()
]

# more prep work

# output stream names to be written, use specified ones or all if nothing specified
stream_names = list(cf.streams.keys())
stream_infos = list(cf.streams.values())
Expand All @@ -135,7 +195,10 @@ def write_output(
target_channels: list[list[str]] = [list(stream.val_target_channels) for stream in stream_infos]
source_channels: list[list[str]] = [list(stream.val_source_channels) for stream in stream_infos]

geoinfo_channels = [[] for _ in stream_infos] # TODO obtain channels
filter_cfg = val_cfg.get("output", {}).get("channels", None)
_filter_output_channels(filter_cfg, stream_names, target_channels, targets_all, preds_all)

geoinfo_channels = [[] for _ in stream_names] # TODO obtain channels

# calculate global sample indices for this batch by offsetting by sample_start
sample_start = batch_idx * batch_size
Expand Down