Skip to content

Correct equality used in ECC transformation approach - #2416

Open
gavinevans wants to merge 4 commits into
metoppv:masterfrom
gavinevans:mobt_783_gamma_equality
Open

Correct equality used in ECC transformation approach#2416
gavinevans wants to merge 4 commits into
metoppv:masterfrom
gavinevans:mobt_783_gamma_equality

Conversation

@gavinevans

@gavinevans gavinevans commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Related issues: #2303

Description
This PR modifies an equality that is used as part of the gamma distribution fitting, which is part of the ECC transformation approach, where a gamma distribution is fitted for each grid point. The issue was that stochastic noise (as a negative value) had been added to the realization forecast prior to this step, however, this negative stochastic noise wasn't intended to affect the gamma distribution fitting, which has only intended for "real" precipitation forecast values. The presence of negative values in the inputs was skewing the mean and standard deviation estimate for the gamma distribution and giving output that didn't look quite as intended i.e. higher precipitation values than expected. To address this the equality used when considering the nan_mask_value argument has been made "<=", so that values equal to and less than this value will be set to NaN for the gamma distribution fitting section.

Testing:

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

…alues using the gamma distribution. Otherwise, negative stochastic noise values are included, which isn't the intention.

@mo-jbeaver mo-jbeaver 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.

All tests passed successfully, just added a few comments to the unit test for clarification.

err_msg="Negative intensity value should map to approximately zero in gamma CDF",
)
# The right column has positive value (2.0) and should map to a percentile
# close to 0.037 for this test setup.

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.

Where has the 0.037 come from?

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've extended this comment, so that it's clearer where the 0.037 has come from.


# The key assertion: negative values in input produce very low percentiles (near 0)
# because gamma CDF on negative values returns 0. This confirms negative values
# are masked in mean/std calculation but still evaluated by gamma CDF.

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.

Should there also be a check for the mean/std calculation?

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 don't think that I need to explicitly calculate the mean and standard deviation in this unit test but I've rewritten this comment to, hopefully, be a bit clearer about how the numbers in the result are calculated.

@mo-jbeaver mo-jbeaver assigned gavinevans and unassigned mo-jbeaver Jul 24, 2026
@gavinevans gavinevans assigned mo-jbeaver and unassigned gavinevans Jul 24, 2026

@brhooper brhooper 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.

Thanks @gavinevans, I've added one minor comment.

result[:, 0],
[0.0, 0.157, 0.843],
atol=1e-3,
err_msg="Negative intensity value should map to zero in gamma CDF",

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.

This error message should be updated to reflect what is being tested.

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've made a minor update to this error message.

mo-jbeaver
mo-jbeaver previously approved these changes Jul 24, 2026

@mo-jbeaver mo-jbeaver 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.

This is a lot easier to follow now, thanks!

@mo-jbeaver mo-jbeaver assigned gavinevans and unassigned mo-jbeaver Jul 24, 2026

@brhooper brhooper 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.

Thanks @gavinevans

One more small comment.

),
)
# Check that all values are finite
assert np.all(np.isfinite(result))

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.

I think we're explicitly checking the value of every point in result now, so can this line be removed?

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've removed this assertion.

@brhooper brhooper assigned gavinevans and unassigned brhooper Jul 27, 2026
@gavinevans gavinevans assigned brhooper and unassigned gavinevans Jul 27, 2026
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.

3 participants