Skip to content

Add DetectorData API#408

Merged
philsmt merged 4 commits intomasterfrom
feat/detectordata
Apr 9, 2026
Merged

Add DetectorData API#408
philsmt merged 4 commits intomasterfrom
feat/detectordata

Conversation

@philsmt
Copy link
Copy Markdown
Collaborator

@philsmt philsmt commented Oct 27, 2025

As the CAL team has been refactoring the injection code away from the legacy calibrationDBRemote API, we noticed that handling PDU details is somewhat cumbersome and requires replicating non-obvious RESTful requests in many places. As we do not want to add further auxiliary functions to CalCatAPIClient, this PR adds an API accompanying CalibrationData by DetectorData.

@philsmt philsmt requested a review from takluyver October 27, 2025 15:00
@philsmt philsmt added the enhancement New feature or request label Oct 27, 2025
@philsmt philsmt force-pushed the feat/detectordata branch 4 times, most recently from 96dd6af to d260aad Compare October 27, 2025 15:30
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 91.91176% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.14%. Comparing base (1dbf021) to head (8767ba3).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/extra/calibration.py 91.91% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #408      +/-   ##
==========================================
+ Coverage   72.76%   73.14%   +0.37%     
==========================================
  Files          35       35              
  Lines        6136     6248     +112     
==========================================
+ Hits         4465     4570     +105     
- Misses       1671     1678       +7     

☔ 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.

@philsmt philsmt changed the base branch from master to caldata-from-correction October 27, 2025 15:36
@philsmt
Copy link
Copy Markdown
Collaborator Author

philsmt commented Oct 27, 2025

Pointing at caldata-from-corrections until it is merged to fix the CI.

Rebased on top of master given that PR is merged.

Base automatically changed from caldata-from-correction to master October 28, 2025 10:26
Copy link
Copy Markdown
Member

@takluyver takluyver left a comment

Choose a reason for hiding this comment

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

Is the goal to replace CalibrationData.module_details and .detector_name with a DetectorData object? If so, we might need to do something about the .from_correction(..., use_calcat=False) case, where we don't have most of the info this assumes, just the bare minimum of detector name, aggregator names and PDU names.

Comment thread src/extra/calibration.py Outdated
Comment thread src/extra/calibration.py Outdated
Comment thread src/extra/calibration.py Outdated
Comment thread src/extra/calibration.py Outdated
@philsmt
Copy link
Copy Markdown
Collaborator Author

philsmt commented Oct 30, 2025

Is the goal to replace CalibrationData.module_details and .detector_name with a DetectorData object?

I suppose that would be neat, but quite the refactor around CalibrationData. We could also emulate module_details via the DetectorData for compatibility. I might want to start out with a detector property on CalibrationData constructing the object at the (potential) cost of re-querying, or try to construct it with the information present.

@takluyver
Copy link
Copy Markdown
Member

In the context of using DetectorData in CalibrationData, we discussed whether it should be possible to select down modules within DetectorData. I think I'm OK with saying that DetectorData may represent part of a detector. Possibly it could have a detdata.base object pointing to the original object with all modules, like numpy array views. But I'm not sure when we'd use that.

Another option would be to keep DetectorData whole, with all the modules we originally found, and have caldata.selected_modules indicate which modules are in use. 🤷

@philsmt
Copy link
Copy Markdown
Collaborator Author

philsmt commented Nov 12, 2025

Apart from addressing the comments, I tried to base the CalibrationData on top of DetectorData.

I tried to do this in a minimalistic approach by preserving all business logic and only emulating detector_name and module_details underneath. It passes the test suite just fine, what are your thoughts?

Technically there are some differences in obscure fields like detector_type_id and such, but I don't expect this to matter in practice.

Comment thread tests/test_calibration.py Outdated
Comment thread src/extra/calibration.py Outdated
Comment thread src/extra/calibration.py
Comment thread src/extra/calibration.py Outdated
Comment thread src/extra/calibration.py Outdated
Comment thread tests/test_calibration.py
@philsmt philsmt force-pushed the feat/detectordata branch 3 times, most recently from b7cd956 to 427cceb Compare December 23, 2025 11:59
@philsmt
Copy link
Copy Markdown
Collaborator Author

philsmt commented Dec 23, 2025

I cleaned up the history now, could you please have a look at the remaining discussions on whether they're actionable?

Comment thread tests/test_calibration.py Outdated
Comment thread src/extra/calibration.py Outdated
Comment thread src/extra/calibration.py Outdated
Comment on lines +978 to +979
module_number=pdu.module_number,
module_number_at_ccv_begin_at=pdu.module_number,
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.

Let's not guess here. Either we preserve two separate values from what CalCat returns so we can return them separately, or else just return a single module_number field. It just creates confusion otherwise.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oops, this was probably a preliminary measure when trying out the compatibility layer.

Does it ever make sense to look at module numbers different from when the CCV was taken?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As discussed, I removed module_number_at_ccv_begin_at for now.

@philsmt philsmt force-pushed the feat/detectordata branch from 93146aa to caeac0c Compare March 20, 2026 14:22
@takluyver
Copy link
Copy Markdown
Member

The cassette files for the tests seem to have ~doubled in size (or more):

image

I think --record-mode=all maybe adds the new requests to the existing ones? Though I'm a bit confused, because some of the old requests seem to change as well. I think the rewrite record mode will completely replace the previous responses, so the files don't grow. This is what the comment in test_calibration suggests:

# Most of these tests use saved HTTP responses by default (with pytest-recording).
# To ignore these & use exflcalproxy, run pytest with the --disable-recording flag.
# To record responses for a new test making HTTP requests, pass --record-mode=once.
# To update the saved cassettes from exflcalproxy, pass --record-mode=rewrite.

@philsmt philsmt force-pushed the feat/detectordata branch from caeac0c to 7868e3e Compare March 23, 2026 13:36
@philsmt
Copy link
Copy Markdown
Collaborator Author

philsmt commented Mar 23, 2026

Hmm I see, I tried to clean up by deleting and generating them again from scratch. Does this look better?

@takluyver
Copy link
Copy Markdown
Member

Thanks, indeed it now looks like the cassette files stay roughly the same size.

LGTM

@takluyver takluyver force-pushed the feat/detectordata branch from 7868e3e to 830bfc7 Compare April 2, 2026 08:36
@takluyver
Copy link
Copy Markdown
Member

I've rebased onto master to resolve some conflicts. I think this is ready to be merged.

Comment thread src/extra/calibration.py Outdated
Comment on lines +1494 to +1495
def from_id(cls, detector_id, pdu_snapshot_at=None, client=None):
"""Look up a detector and its modules by CalCat numerical ID.
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.

Nitpicking, but having both from_id and from_identifier feels like setting up ongoing low-level confusion, and the one people probably want more often is the longer one.

How about we call this one from_calcat_id()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I can see that confusion.

How about from_numerical_id() as already written in the docstring?

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.

That's OK by me. I think 'numeric' also works if you want to shorten it slightly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. I'll take your earlier LGTM then once the pipeline finishes.

@philsmt philsmt force-pushed the feat/detectordata branch from 830bfc7 to 8767ba3 Compare April 9, 2026 13:49
@philsmt philsmt merged commit 99a48ec into master Apr 9, 2026
10 checks passed
@philsmt philsmt deleted the feat/detectordata branch April 9, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants