Skip to content

Tomo dark/flat: never link another proposal's dark/flat - #105

Merged
Jakub Wlodek (jwlodek) merged 5 commits into
NSLS2:mainfrom
sligara7:tomo-dark-flat-same-proposal
Oct 23, 2026
Merged

Jakub Wlodek (jwlodek) merged 5 commits into
NSLS2:mainfrom
sligara7:tomo-dark-flat-same-proposal

Conversation

@sligara7

@sligara7 Anthony Sligar (sligara7) commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

A tomo scan in a new proposal was exported with the previous proposal's dark/flat: at HEX, scans 249–256 (pass-312143) all link dark/flat scan 246 (pass-314022). RE.md is shared by the beamline and keeps last_dark_flat_uid across a proposal switch, and the exporter linked it without checking.

  • Exporter: links the start document's dark/flat only if it is from the same proposal and cycle, however the proposal was switched (GUI, CLI sync-experiment, queueserver worker). An explicit dark_flat_id is used as given. An unresolvable dark/flat (implicit or explicit) is skipped with a warning instead of failing the export.
  • Plan stub: clear_last_dark_flat() removes last_dark_flat_uid / last_dark_flat_scan_id from RE.md; reset_scan_id calls it, since resetting the scan ID also retires earlier dark/flats.

Verification: mock/unit tests only. tests/test_dark_flat_proposal.py (9 tests); the new stub and explicit-id tests fail on the previous commit. Full suite: 335 passed (non-GUI), 48 passed (GUI, offscreen). Root cause confirmed from Tiled at HEX (scans 249–256); not yet run on the beamline. Already-exported .nxs files for 249–256 need a re-export after this merges.

RE.md is shared by the beamline and kept last_dark_flat_uid across a proposal switch, so tomo scans in a new proposal were exported with the previous proposal's dark/flat (HEX scans 249-256, pass-312143 -> scan 246, pass-314022).

- switch_proposal removes last_dark_flat_uid/scan_id when moving to a different proposal (the GUI's queueserver path removes them from the worker's RE.md too).
- The exporter links the start document's dark/flat only if it is from the same proposal, and skips an unresolvable uid with a warning instead of failing the export. An explicit dark_flat_id is still used as given.

Assisted-by: copilot:claude-opus-5-5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Failed proposal switches can delete the active proposal’s valid calibration metadata before authentication succeeds.

1 open issue
What changed in this PR

This PR prevents tomography exports from automatically linking another proposal’s dark/flat calibration, addressing stale metadata retained across proposal switches.

Changes:

  • Clears tracked dark/flat metadata when changing proposals, including through the GUI’s QueueServer path.
  • Checks proposal identity before linking automatic calibrations, skips unresolved references, and preserves explicit overrides.
  • Adds seven regression tests covering proposal switching and calibration selection.
File Description
tests/​test_dark_flat_proposal.py Tests metadata cleanup and calibration selection.
src/​hextools/​utils/​__init__.py Defines shared calibration keys and clears them on proposal changes.
src/​hextools/​tomography/​utils.py Uses shared keys when tracking dark/flat runs.
src/​hextools/​gui/​live_re_md_viewer.py Propagates calibration-key removal to the QueueServer worker.
src/​hextools/​exporters/​tomography.py Validates automatically selected calibrations against the scan’s proposal.

Review effort: Balanced

Comment thread src/hextools/utils/__init__.py Outdated

@jwlodek Jakub Wlodek (jwlodek) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few comments

Comment thread src/hextools/exporters/tomography.py Outdated
Comment thread src/hextools/exporters/tomography.py Outdated
Comment thread src/hextools/gui/live_re_md_viewer.py Outdated
…; drop the GUI worker script

Review (jwlodek, Copilot): a same-proposal dark/flat from an earlier cycle is stale; a failed login must keep the current proposal's dark/flat. The exporter check covers every way of switching (GUI, CLI sync-experiment, queueserver worker), so the GUI no longer edits the worker's RE.md.

Assisted-by: copilot:claude-opus-5-5
Copilot AI balanced review requested due to automatic review settings October 23, 2026 16:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Queue Server GUI switches clear only a local snapshot, leaving stale calibration references in the worker’s metadata.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/hextools/utils/__init__.py Outdated
…oposal switch; warn on an unresolvable explicit id

Review (jwlodek): switch_proposal no longer clears RE.md; clear_last_dark_flat() does, and reset_scan_id calls it, so it runs in the RE that owns RE.md (worker or local). The exporter warns and links no dark/flat when an explicit dark_flat_id does not resolve, instead of raising; resolve_dark_flat_run logs the dark/flat it uses.

Assisted-by: copilot:claude-opus-5-5
Copilot AI balanced review requested due to automatic review settings October 23, 2026 16:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused changes and regression coverage address the reported calibration-linking issue with no identified blocking findings.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jwlodek Jakub Wlodek (jwlodek) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One last note

Comment thread src/hextools/exporters/tomography.py Outdated
Co-authored-by: Jakub Wlodek <jwlodek.dev@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 16:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The resolver rejects explicit cross-proposal or cross-cycle overrides instead of preserving the documented override behavior.

1 open issue

Review effort: Balanced

Comment thread src/hextools/exporters/tomography.py Outdated
… too

Follows the accepted suggestion: drop the now always-true guard, update the docstring, and replace the 'explicit id honoured across proposals' test with one that refuses it and one that an explicit id overrides the start document.

Assisted-by: copilot:claude-opus-5-5
Copilot AI balanced review requested due to automatic review settings October 23, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human confirmation is needed because the description and implementation specify different behavior for explicit dark/flat selections.

1 open issue

Review effort: Balanced

@jwlodek
Jakub Wlodek (jwlodek) merged commit ae14996 into NSLS2:main Oct 23, 2026
6 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