Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBT-719: Frequency to count for time period averages #2006

Merged
merged 7 commits into from
Jun 25, 2024

Conversation

bayliffe
Copy link
Contributor

This change adds a function and CLI to multiply average rates / frequencies within periods by the length of the period over which they are defined to yield an accumulation / count over the same period. This is to be used in the first instance for converting lightning flash frequencies into counts.

Acceptance test data: metoppv/improver_test_data#49

Testing:

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

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.43%. Comparing base (84a8944) to head (30da6f9).
Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2006      +/-   ##
==========================================
+ Coverage   98.39%   98.43%   +0.03%     
==========================================
  Files         124      128       +4     
  Lines       12212    12489     +277     
==========================================
+ Hits        12016    12293     +277     
  Misses        196      196              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
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 @bayliffe 👍

I've added a few minor comments.

improver/utilities/temporal.py Outdated Show resolved Hide resolved
improver/utilities/temporal.py Outdated Show resolved Hide resolved
improver/utilities/temporal.py Show resolved Hide resolved
improver/utilities/temporal.py Show resolved Hide resolved
improver/utilities/temporal.py Show resolved Hide resolved
Copy link
Contributor

@brhooper brhooper 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've added a few minor comments.

time bounds over which it is defined to return a count or accumulation.
The frequency or rate must be defined with time bounds, e.g. an average
frequency across the period. This function will handle a cube with a
non-scalar time coordinate, multiplying each time in the coordiante by the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
non-scalar time coordinate, multiplying each time in the coordiante by the
non-scalar time coordinate, multiplying each time in the coordinate by the

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When will you get onboard with my respelling of coordianté? Note the accent in this version which I think gives it a lovely sound. But fine...

time bounds over which it is defined to return a count or accumulation.
The frequency or rate must be defined with time bounds, e.g. an average
frequency across the period. This function will handle a cube with a
non-scalar time coordinate, multiplying each time in the coordiante by the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
non-scalar time coordinate, multiplying each time in the coordiante by the
non-scalar time coordinate, multiplying each time in the coordinate by the

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet apparently.

raise ValueError(
"time coordinate must have bounds to apply this time-bounds integration"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment, I don't think anything is stopping users from providing a rate/frequency which is (for example) 'per hour', which would lead to unexpected results.

Could an additional check be added along the lines of:

Suggested change
if str(cube.units).find('s-') == -1:
raise ValueError('message')

A corresponding unit test would also be required to demonstrate this functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code will modify the units of the returned cube to ensure that any input unit can be handled. The data will be integrated in seconds, but the unit will include a factor that accounts for the different input units, that why the unit is modified using the * Unit("s") approach. I had failed to demonstrate this in the units tests, so I've added a relevant test.

Copy link
Contributor

@brhooper brhooper 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, this looks good to me.

@gavinevans gavinevans merged commit 57621e5 into metoppv:master Jun 25, 2024
10 checks passed
MoseleyS pushed a commit to MoseleyS/improver that referenced this pull request Aug 22, 2024
* Adds a small utility for rate to accumulation or frequency to count conversion using time bound information. Adds a CLI and unit tests.

* Add style fixes. Add a unit test for the exception.

* Add acceptance tests and fixup the CLI.

* Update checksums, style fix.

* Reorder test statement.

* Added unit test coverage of preservation and removal of cell methods for the integrate time bounds function.

* Add a test to demonstrate how irregular input units are handled. Correct doc-string typos.
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