Skip to content

Use arctan2 for calculating pert_motion_field as opposed to arctan#2

Open
KristianHMoller wants to merge 2 commits into
EnergyWeatherAI:mainfrom
KristianHMoller:bugfix/arctan
Open

Use arctan2 for calculating pert_motion_field as opposed to arctan#2
KristianHMoller wants to merge 2 commits into
EnergyWeatherAI:mainfrom
KristianHMoller:bugfix/arctan

Conversation

@KristianHMoller

Copy link
Copy Markdown

We noted, that even with the alpha and beta noise parameters both set to zero, running probabilistic_advection in ensemble mode yielded results different from those obtained in deterministic mode. The difference was not constant and for some weather scenarios, almost no difference was observed, while for others the difference was large. Specifically, in ensemble mode, "artifacts" would appear in the nowcast.

The source of the discrepancy was tracked to the calculation of pert_motion_field in the script Models/ProbabilisticAdvection.py. The original code:

        pert_motion_field[0, :, :] = pert_abs * np.cos(np.arctan(y / x) + beta_noise)
        pert_motion_field[1, :, :] = pert_abs * np.sin(np.arctan(y / x) + beta_noise)

np.arctan does not consider the signs of the input values and additionally, for x=0 this will yield issues with division by zero. https://numpy.org/doc/stable/reference/generated/numpy.arctan.html

By replacing np.arctan with np.arctan2, these issues seem to be solved. https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html

@KristianHMoller

KristianHMoller commented Jun 29, 2026

Copy link
Copy Markdown
Author

Nowcast based on data MSG-CPP data for May 20, 2025 12.00 UTC. The update to using np.arctan2 as opposed to np.arctan leads to agreement between deterministic and ensemble mode when specifying the noise (alpha and beta) to be zero:
nowcast_3x2_h5

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.

1 participant