Skip to content

Conversation

@d-chambers
Copy link
Contributor

Description

This PR does 3 sorta related things:

  1. Adds a dim_reduce keyword to Patch.aggregate and friends (eg mean, min, max) which controls what happens to the aggregated dimension. Options now are to apply another numpy-like reducer, squeeze out the dimension, or empty it. The default behavior is unchanged, but the additional options are useful when calculating stats over patches in a spool.

  2. Unified getting dimension name, axis, and values from args and kwargs into one new function dascore.utils.patch.get_dim_axis_value and replaced usages of two overlapping functions that did this before.

  3. Added a validate_call option to patch_function which uses pydantic's validate_call decorator to do type checking on patch functions when enabled. This makes it much easier to enforce certain types and ranges on patch function parameters.

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes.
  • documented the new feature with docstrings or appropriate doc page.
  • included a test. See testing guidelines.
  • your name has been added to the contributors page (docs/contributors.md).
  • added the "ready_for_review" tag once the PR is ready to be reviewed.

@codecov
Copy link

codecov bot commented Nov 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.85%. Comparing base (c045e6e) to head (70ac5b0).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master     #456    +/-   ##
========================================
  Coverage   99.84%   99.85%            
========================================
  Files         114      115     +1     
  Lines        9258     9372   +114     
========================================
+ Hits         9244     9358   +114     
  Misses         14       14            
Flag Coverage Δ
unittests 99.85% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@d-chambers d-chambers added the ready_for_review PR is ready for review label Nov 4, 2024
dim_reduce
How to reduce the dimensional coordinate associated with the
aggregated axis. Can be the name of any valid aggregator, a callable,
"empty" - which returns and empty coord, or "squeeze" which drops
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be helpful to note that "empty" is the default behavior.

dim_reduce: str | Callable = "empty",
) -> PatchType:
"""
Aggregate values along a specified dimension.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The notes section in the docs should be revised based on the new dim_reduce argument.

is found in args, its corresponding values is `None`.
Return the name of the dimension, its axis position, and its value.
Examples
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for including these examples in the docs. Super helpful as this function is being used in a lot of other functions.

Copy link
Collaborator

@ahmadtourei ahmadtourei left a comment

Choose a reason for hiding this comment

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

Looks great! Please see my comments on a couple of suggestions.

@d-chambers d-chambers merged commit dc1d36f into master Nov 8, 2024
@d-chambers d-chambers deleted the dim_reduce branch November 8, 2024 04:09
This was referenced Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready_for_review PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants