Skip to content

Refactor channels config - #451

Merged
dfulu merged 5 commits into
dev_feb2026_speedupsfrom
part_23
Oct 21, 2026
Merged

dfulu merged 5 commits into
dev_feb2026_speedupsfrom
part_23

Conversation

@dfulu

@dfulu dfulu commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Pull Request

Description

This PR refactors the channels part of the config. Previously we had multiple entries in the config to specify the selection and processing of the channels. We had separate entries to define the list of channels used, their normalisation constants, and which of them should be diffed.

This PR wraps those together so the channels are configured in one entry. This removes some of the validation we need, and removes the users requirement to duplicate the list of channels between channels selected, channels diffed, and the channel normalisation stats.

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

return self

@model_validator(mode="after")
def check_all_channels_have_normalisation_constants(self) -> "Satellite":

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get this for free now with the new config format

return _validate_grid_resolution_minutes(resolution)

@model_validator(mode="after")
def validate_accum_channels_subset(self) -> "NWP":

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get this for free now with the new config format

return provider

@model_validator(mode="after")
def check_all_channels_have_normalisation_constants(self) -> "NWP":

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get this for free now with the new config format

@field_validator("channels")
def validate_channel_names(cls, channels: list[Channel]) -> list[Channel]:
"""Reject duplicate source channel names."""
_validate_unique_channel_names(channels)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add extra validation that all the channel names are unique

if config.satellite is not None:
sat_config = config.satellite
normalisation_arrays["sat"] = _build_source_normalisation_arrays(
[sat_config.normalisation_constants[channel] for channel in sat_config.channels]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cleaner now since the normalisation constants are attached to the channels themselves


class NormalisationConstantsMixin(Base):
"""Normalisation constants for multiple channels."""
class NWPChannel(Channel):

@dfulu dfulu Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These get their own class since we support optionally differencing NWP channels but not satellite channels

_validate_configuration(config)


def test_accum_channels_validation(config_filename):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its now impossible to misconfigure the accumulated channels in the way this test covered

Comment thread tests/config/test_save.py
def test_save_load_yaml_configuration(tmp_path, config_filename):
"""Make sure a saved configuration is the same after loading"""

# Start with this config

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stripped out these unnecessary seeming comments


def test_normalise_channels(config_filename):
config = load_yaml_configuration(config_filename)
config.satellite.channels = ["b", "a"]

@dfulu dfulu Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes just directly maps these settings to the new config schema

@felix-e-h-p
felix-e-h-p self-requested a review October 20, 2026 13:59

@felix-e-h-p felix-e-h-p left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small one. Could we mention in the mean/std field descriptions (not just the NWPChannel docstring) that for accumulated: true these apply to the differenced values? Otherwise looks great, nice one!

@dfulu

dfulu commented Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

Small one. Could we mention in the mean/std field descriptions (not just the NWPChannel docstring) that for accumulated: true these apply to the differenced values? Otherwise looks great, nice one!

I don't think we should do it on Channel since it won't make sense in the context of satellite data which we do not support differencing for. I can add it to the description of accumulated parameter though?

EDIT: I've added to the description of accumulated to make it more explicit that the normalisation values apply to the differenced values

@dfulu
dfulu requested a review from felix-e-h-p October 21, 2026 14:10
@felix-e-h-p

Copy link
Copy Markdown
Contributor

Good to go, just the conflicts - thanks!

@dfulu

dfulu commented Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

Good to go, just the conflicts - thanks!

I'm waiting on part_22 to be approved and merged, then I'll squash it onto dev and I'll rebase and squash this and all the others onto dev

Base automatically changed from part_22 to dev_feb2026_speedups October 21, 2026 16:58
@dfulu
dfulu merged commit 9523691 into dev_feb2026_speedups Oct 21, 2026
4 checks passed
@dfulu
dfulu deleted the part_23 branch October 21, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants