librosa icon indicating copy to clipboard operation
librosa copied to clipboard

Add Metrogram Transform

Open danferns opened this issue 3 months ago • 4 comments

Reference Issue

Reference #1909

What does this implement/fix? Explain your changes.

This is currently a draft PR to welcome early feedback.

What's done:

  • [x] implementation of metrogram and interp_broadcast (for computing the DFT/AC product or Fundamental Tempogram)
  • [x] API documentation for the same

What's left:

  • [x] example for metrogram
  • [ ] example for interpolation function
  • [ ] tests for metrogram
  • [ ] tests for interpolation function

metrogram

Takes in a tempogram, an array of factors, and an aggregate function, and returns the metrogram. If the aggregate is set to None, the product before aggregation is returned.

interp_broadcast

Takes in two ndarrays with their differing positioning data along an axis, and a "target" array of positioning data. Both arrays are interpolated at the target points to make them broadcast-compatible.

Then a user supplied broadcast operation (defaults to np.multiply) is performed on them before returning. If the function is set to None, the broadcast-compatible arrays are returned separately.

Any other comments?

Do we want metrogram to optionally directly accept audio as y?

danferns avatar Oct 20 '25 14:10 danferns

Dropping a note to indicate that I see this PR and will get to review it as soon as I have time.

Meanwhile: would it be possible for you to re-target this PR against the 1.0 dev branch? I don't expect there to be much in the way of conflicts here, but the plan right now is to prioritize 1.0 above a point release on 0.11.

bmcfee avatar Oct 27 '25 13:10 bmcfee

Feel free to take your time! :smile:

I've switched the target branch and got no effective merge conflicts.

danferns avatar Oct 28 '25 14:10 danferns

Codecov Report

:x: Patch coverage is 39.47368% with 23 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 98.34%. Comparing base (8b92a65) to head (3de0470).

Files with missing lines Patch % Lines
librosa/util/utils.py 40.74% 16 Missing :warning:
librosa/feature/rhythm.py 36.36% 7 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##           1.0.0dev    #1986      +/-   ##
============================================
- Coverage     98.81%   98.34%   -0.47%     
============================================
  Files            34       34              
  Lines          4801     4837      +36     
============================================
+ Hits           4744     4757      +13     
- Misses           57       80      +23     
Flag Coverage Δ
unittests 98.34% <39.47%> (-0.47%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 31 '25 15:10 codecov[bot]

Thank you for the review! I've addressed most of the minor comments. I'll work on the examples next.

Also, James Cozens (who authored this method) found us working on this PR! He has kindly offered his help if needed and will be sharing a preprint with more details on his implementation.

danferns avatar Dec 03 '25 09:12 danferns