Skip to content

Angular correlation code adde to extra.utils - #485

Open
TimBerberich wants to merge 2 commits into
masterfrom
angular_correlation
Open

Angular correlation code adde to extra.utils#485
TimBerberich wants to merge 2 commits into
masterfrom
angular_correlation

Conversation

@TimBerberich

@TimBerberich TimBerberich commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

This adds extra.utils.xcca which contains routines to compute cross-correlations of polar data with and without detector mask.
It also contains routines to compute cumulative/(iterative) averages and variances which are useful if you want compute the average ccf by splitting your entire dataset in parts and then merging computed partial results.

Example:

from extra.utils.xcca import AngularCorrelator, AveragedAngularCorrelationMasked
import numpy as np

data = np.random.rand(100,32,64)
mask = np.random.rand(100,32,64)>0.7

ac = AngularCorrelator(*data.shape[1:])

#compute cross-correlation
ccf  = ac.ccf(data[0],mask=mask[0])
#compute harmonic coefficients of cross-correlation
ccn  = ac.ccn(data[0],mask=mask[0])

# compute average correlation of data parts 1 and 2
accn1 = AveragedAngularCorrelationMasked.from_dataset(data[:50],mask[:50])
accn2 = AveragedAngularCorrelationMasked.from_dataset(data[50:],mask[50:])

# combine partial results
accn1.merge(accn2)

# accessing mean and variance
accn1.mean
accn1.variance

@JamesWrigley JamesWrigley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Broadly looks fine, not that I'm an expert with XCCA 😛 Some thoughts:

  • I would suggest putting AngularCorrelator and friends under applications, it feels too specific a thing to go in utils.
  • The tests should pass.
  • This should have a changelog entry.

Comment thread src/extra/utils/xcca.py
Comment thread src/extra/utils/xcca.py
Comment on lines +239 to +256
r"""Compute the mask corrected cross-correlation function.

Parameters
----------
data : NDArray[np.float64]
Image data on uniform polar grid.
mask : NDArray[np.bool]
(n_1,n_phi): Image mask on uniform polar grid.
max_order : int|None
Maximum considered Fourier series order.

Returns
-------
tuple(NDArray[np.float64],NDArray[np.bool])
((n_q,n_q,2*max_order), (n_q,n_q,2*max_order)): (Cross-correlation function $C(q_1,q_2,\phi)$, Mask of cross-correlation function.)
If max_order == None the last dimension has size n_phi.

"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Old docstring?

Comment thread src/extra/utils/xcca.py
@JamesWrigley

Copy link
Copy Markdown
Member

(also, please either rebase or do a squash merge 🙈 )

@TimBerberich
TimBerberich force-pushed the angular_correlation branch 2 times, most recently from 18746b2 to bcf0b7b Compare June 1, 2026 13:36
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.69103% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.82%. Comparing base (d94a426) to head (d3195ef).

Files with missing lines Patch % Lines
src/extra/applications/xcca.py 92.69% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #485      +/-   ##
==========================================
+ Coverage   72.97%   73.82%   +0.85%     
==========================================
  Files          35       36       +1     
  Lines        6642     6943     +301     
==========================================
+ Hits         4847     5126     +279     
- Misses       1795     1817      +22     

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

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

@TimBerberich
TimBerberich force-pushed the angular_correlation branch from 5c13c2b to 1c8735c Compare June 1, 2026 16:04
@TimBerberich
TimBerberich force-pushed the angular_correlation branch from 006b2d4 to d3195ef Compare June 1, 2026 16:52
@TimBerberich

Copy link
Copy Markdown
Contributor Author

So, everything should be ready to merge now.

@JamesWrigley JamesWrigley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs a rebase to fix the changelog merge conflict, but otherwise LGTM!

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.

2 participants