Skip to content

953 stochastic noise#2275

Merged
maxwhitemet merged 21 commits intometoppv:masterfrom
maxwhitemet:953_stochastic_noise
Mar 19, 2026
Merged

953 stochastic noise#2275
maxwhitemet merged 21 commits intometoppv:masterfrom
maxwhitemet:953_stochastic_noise

Conversation

@maxwhitemet
Copy link
Copy Markdown
Contributor

@maxwhitemet maxwhitemet commented Jan 8, 2026

Addresses #953.

This PR adds the plugin, CLI, and tests for stochastic noise generation.

The acceptance tests show the impact, with data available here.
image

Testing:

  • Ran tests and they passed OK
  • Added new tests for the new feature(s)

@cpelley
Copy link
Copy Markdown
Contributor

cpelley commented Jan 12, 2026

@maxwhitemet, could you merge/rebase master into your branch. The failing "CI Tests / Test-Coverage (pull_request)" should hopefully be addressed by the now merged #2273

image

There does appear to be a new issue potentially with the improver documentation building now though... (different issue)

@cpelley
Copy link
Copy Markdown
Contributor

cpelley commented Jan 13, 2026

Ignore the test coverage failure. Fixed in #2282

Copy link
Copy Markdown
Contributor

@gavinevans gavinevans left a comment

Choose a reason for hiding this comment

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

Thanks @maxwhitemet 👍

I've added some comments below.

Comment thread envs/environment_b.yml Outdated
Comment thread envs/environment_b.yml Outdated
Comment thread improver/cli/stochastic_noise.py Outdated
Comment thread improver/cli/stochastic_noise.py Outdated
Comment thread envs/conda-forge.yml Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver_tests/precipitation/stochastic_noise/test_StochasticNoise.py Outdated
Comment thread improver_tests/precipitation/stochastic_noise/test_StochasticNoise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Copy link
Copy Markdown
Contributor Author

@maxwhitemet maxwhitemet left a comment

Choose a reason for hiding this comment

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

Thank you for the review @gavinevans. I have now made the requested changes.

Comment thread envs/conda-forge.yml Outdated
Comment thread envs/environment_b.yml Outdated
Comment thread envs/environment_b.yml Outdated
Comment thread improver/cli/stochastic_noise.py Outdated
Comment thread improver/cli/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver_tests/precipitation/stochastic_noise/test_StochasticNoise.py Outdated
Comment thread improver_tests/precipitation/stochastic_noise/test_StochasticNoise.py Outdated
Copy link
Copy Markdown
Contributor

@gavinevans gavinevans left a comment

Choose a reason for hiding this comment

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

I've added some minor comments.

Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/calibration/stochastic_noise.py
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver_tests/calibration/stochastic_noise/test_StochasticNoise.py
Copy link
Copy Markdown
Contributor Author

@maxwhitemet maxwhitemet left a comment

Choose a reason for hiding this comment

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

Thanks @gavinevans. I have implemented your feedback

Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/calibration/stochastic_noise.py
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver_tests/calibration/stochastic_noise/test_StochasticNoise.py
gavinevans
gavinevans previously approved these changes Jan 28, 2026
Copy link
Copy Markdown
Contributor

@bayliffe bayliffe left a comment

Choose a reason for hiding this comment

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

Thanks Max, a few comments. The thrust of some of my comments it to make this less precipitation specific, but I've not highlighted everywhere this needs to happen, so think about variable names (e.g. dry_mask) and comments to make it less precip specific, using precip as an example if that's instructive.

I'm also interested in you making changes to better handle the expected shape of cubes and the coordinate order, rather than assuming realization is first and simply indexing it with that assumption.

Comment thread improver/cli/stochastic_noise.py
Comment thread improver/cli/stochastic_noise.py Outdated
Comment thread improver/cli/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
n_realiz = template.coord("realization").points.size
tasks = []
for k in range(n_realiz):
realiz_data = template_dB.data[k].astype(np.float32)
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.

There is an implicit assumption that the first index of the cube here corresponds to realization but I don't think that's been written anywhere, checked, or enforeced.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have now changed the looping to use the iris slices_over method with the realization dimension.

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.

One more question on this. Does the slice passed to do_fft need to be 2-dimensional? Would a time, realization, y, x cube work with this code?

If it does need to be 2D then you could either set a limitation in the code that raises an error if there are more than realization, y, x coordinates, or you could create y, x slices requiring that realization be one of the remaining dimensions, and reconstruct a cube back to the original shape at the end. We do this in a few places and Gavin could give you a steer as to whether this will ever be needed or just to go for the exception (again, assuming it has to be a 2D slice passed in here).

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.

Yes, for our usage, the input to do_fft needs to be 2-dimensional. I don't think we have to support the presence of a time coordinate, so perhaps just checking that the input cube has the expected dimension coordinates, and if not raising an exception, would be fine.

Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver_tests/precipitation/stochastic_noise/test_StochasticNoise.py Outdated
@bayliffe
Copy link
Copy Markdown
Contributor

I forgot to say that this code is currently within the precipitation directory. If you do make it less precip-specific then it should probably move.

Copy link
Copy Markdown
Contributor Author

@maxwhitemet maxwhitemet left a comment

Choose a reason for hiding this comment

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

Thank you for the review @bayliffe. I believe I have addressed all requested changes.

Regarding your comment on where the plugin sits: stochastic_noise and its associated tests now sit under the calibration directory.

Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/cli/stochastic_noise.py
Comment thread improver_tests/precipitation/stochastic_noise/test_StochasticNoise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
Comment thread improver/precipitation/stochastic_noise.py Outdated
n_realiz = template.coord("realization").points.size
tasks = []
for k in range(n_realiz):
realiz_data = template_dB.data[k].astype(np.float32)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have now changed the looping to use the iris slices_over method with the realization dimension.

Copy link
Copy Markdown
Contributor

@bayliffe bayliffe left a comment

Choose a reason for hiding this comment

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

One more question, but this looks good. Thanks for all the changes.

@maxwhitemet maxwhitemet force-pushed the 953_stochastic_noise branch from e911f7c to 2549cef Compare March 10, 2026 17:43
@maxwhitemet
Copy link
Copy Markdown
Contributor Author

One more question, but this looks good. Thanks for all the changes.

Thank you for your review @bayliffe. I have added a broad utility to handle the dimensionality concern here: #2327. As this has created a merge dependency, I have set the ticket as blocked for now.

Copy link
Copy Markdown
Contributor

@cpelley cpelley left a comment

Choose a reason for hiding this comment

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

Please remember to expose the plugin via improver/api/init.py

@maxwhitemet maxwhitemet force-pushed the 953_stochastic_noise branch from 24cf6c2 to 3d041d1 Compare March 12, 2026 16:16
Copy link
Copy Markdown
Contributor

@bayliffe bayliffe left a comment

Choose a reason for hiding this comment

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

Stuff to fix, but basically there.

Comment thread envs/conda-forge.yml Outdated
- pysteps
>>>>>>> 897e0cb9 (Add pytest to environments)
=======
>>>>>>> 08001d9b (Undo environemnt changes)
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.

You've left unresolved conflicts from merging in these files which is causing the tests to fail.

Comment thread envs/environment_b.yml Outdated
# estimate-emos-coefficients, nowcast-accumulate, nowcast-extrapolate,
# nowcast-optical-flow-from-winds, and stochastic-noise.
# See doc/source/Dependencies.rst for more information.
>>>>>>> 08001d9b (Undo environemnt changes)
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.

Further unresolved merging issues.

Comment thread improver/calibration/stochastic_noise.py Outdated
@maxwhitemet maxwhitemet force-pushed the 953_stochastic_noise branch from bd73a41 to 0f9b432 Compare March 19, 2026 12:09
Comment thread envs/environment_b.yml
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have pulled in the latest changes from upstream here. I am however not sure if this looks correct

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.

Nope. You can look at the current upstream master to see what's there:

https://github.com/metoppv/improver/blob/master/envs/environment_b.yml

Unless you intended to delete the temporal-interpolate and forecast-trajectory-gap-filler entries then this is incorrect.

Copy link
Copy Markdown
Contributor Author

@maxwhitemet maxwhitemet left a comment

Choose a reason for hiding this comment

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

Thanks @bayliffe. I fixed the problems highlighted.

Comment thread improver/calibration/stochastic_noise.py Outdated
@bayliffe bayliffe dismissed cpelley’s stale review March 19, 2026 15:45

Requested change made.

@maxwhitemet maxwhitemet merged commit 195d349 into metoppv:master Mar 19, 2026
7 checks passed
MoseleyS added a commit that referenced this pull request Mar 24, 2026
* master:
  Add attribute to record secondary forecast sources when clustering realizations (#2332)
  953 stochastic noise (#2275)
  Add configurable grid spacing relative tolerance (#2308)
gavinevans added a commit to gavinevans/improver that referenced this pull request Mar 24, 2026
…lustering

* upstream/master:
  Add attribute to record secondary forecast sources when clustering realizations (metoppv#2332)
  953 stochastic noise (metoppv#2275)
  Add configurable grid spacing relative tolerance (metoppv#2308)
  Cube dim validation utility (metoppv#2327)
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.

4 participants