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

Faster time coordinate categorization #5999

Merged
merged 13 commits into from
Aug 30, 2024

Conversation

bouweandela
Copy link
Member

@bouweandela bouweandela commented Jun 11, 2024

🚀 Pull Request

Description

Make time coordinate categorization faster by converting the time points to datetimes in a single call.

Example script:

In [1]: import numpy as np

In [2]: import cf_units

In [3]: from iris.cube import Cube

In [4]: from iris.coords import DimCoord

In [5]: from iris.coord_categorisation import add_year

In [6]: coord = DimCoord(np.arange(10000), standard_name='time', units=cf_units.Unit("days since epoch", "standard"))

In [7]: cube = Cube(np.empty(10000), dim_coords_and_dims=[(coord, 0)])

In [8]: %timeit add_year(cube.copy(), 'time')
9.99 ms ± 24.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

while with the current main branch, the timing result is

345 ms ± 2.07 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Consult Iris pull request check list


Add any of the below labels to trigger actions on this PR:

  • benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.78%. Comparing base (9a23aa0) to head (16b20b3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5999   +/-   ##
=======================================
  Coverage   89.77%   89.78%           
=======================================
  Files          88       88           
  Lines       23037    23056   +19     
  Branches     5038     5027   -11     
=======================================
+ Hits        20681    20700   +19     
  Misses       1624     1624           
  Partials      732      732           

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

@bouweandela bouweandela marked this pull request as ready for review June 11, 2024 08:18
@bouweandela
Copy link
Member Author

Would it make sense to add the example code above as a benchmark?

Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

Excellent idea @bouweandela, we just need to come to an agreement on how best to identify the cases where we're dealing with dates.

lib/iris/coord_categorisation.py Outdated Show resolved Hide resolved
lib/iris/coord_categorisation.py Show resolved Hide resolved
Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

OK, final couple of comments and I think we're ready to go 🚀

lib/iris/coord_categorisation.py Outdated Show resolved Hide resolved
docs/src/whatsnew/latest.rst Outdated Show resolved Hide resolved
@trexfeathers trexfeathers merged commit 1bfe311 into SciTools:main Aug 30, 2024
21 checks passed
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