Skip to content

Commit

Permalink
Merge pull request #2957 from pieleric/fix-sparc-alignment-of-tunnel-…
Browse files Browse the repository at this point in the history
…lens-did-not-save-the-aligned-position

[TRCL-517] [fix] SPARC alignment of tunnel lens did not save the aligned position
  • Loading branch information
pieleric authored Dec 6, 2024
2 parents c7e46aa + 4ec7c89 commit e980588
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/odemis/acq/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@
'spec-focus-ext': ("sp-ccd",
{'chamber-light': {'power': 'off'},
# 'spec-selector' will depend on the affects
# for the spec-ded aligner only z axis positions are stored, currently for one WL
'spec-ded-aligner': {'z': "MD:" + model.MD_FAV_POS_ACTIVE},
# slit to the minimum, wavelength to the zeroth order
'spectrograph-dedicated': {'slit-in': 10e-6, 'wavelength': 0},
Expand Down Expand Up @@ -308,7 +307,13 @@
'tunnel-lens-align': ("sp-ccd",
{'chamber-light': {'power': 'off'},
# 'spec-selector' will depend on the affects
# for the spec-ded aligner only z axis positions are stored, currently for one WL
# Note that the spec-ded aligner Z best pos depends on the wavelength being observed,
# but for now, we rely on the user to adjust it. For now, the X & Y positions are
# only manually moved.
# Also, the spectral and temporal-spectrum mode are affected by this position, but
# for now, they don't explicitly move this component, so the GUI alignment tab ensures
# that it's already at the correct position at start-up, and there is no reason it
# moves, unless the user adjusts the alignment.
'spec-ded-aligner': {'z': "MD:" + model.MD_FAV_POS_ACTIVE},
# for the spectrograph dedicated slit fully open and filter always on pass-through
'spectrograph-dedicated': {'grating': 'mirror',
Expand Down
39 changes: 39 additions & 0 deletions src/odemis/gui/cont/tabs/sparc2_align_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,9 @@ def _onAlignMode(self, mode):
main.spec_switch.position.unsubscribe(self._onSpecSwitchPos)
if main.light_aligner:
main.light_aligner.position.unsubscribe(self._onLightAlignPos)
if mode != "tunnel-lens-align":
if main.spec_ded_aligner:
main.spec_ded_aligner.position.unsubscribe(self._on_spec_ded_aligner_pos)

# This is running in a separate thread (future). In most cases, no need to wait.
op_mode = self._mode_to_opm[mode]
Expand Down Expand Up @@ -1154,6 +1157,7 @@ def _onAlignMode(self, mode):
self.panel.cmb_focus_detectors_ext.SetSelection(0)

self.panel.pnl_moi_settings.Show(False)
f.add_done_callback(self._on_tunnel_lens_align_done)
else:
raise ValueError("Unknown alignment mode %s!" % mode)

Expand Down Expand Up @@ -1309,6 +1313,19 @@ def _on_fibalign_done(self, f):
self.panel.btn_m_fibaligner_y.Enable(True)
self.panel.btn_p_fibaligner_y.Enable(True)

def _on_tunnel_lens_align_done(self, f):
"""
Called when the optical path move of tunnel lens align is finished
"""
# Has no effect now, as OPM future are not cancellable (but it makes the
# code more future-proof)
if f.cancelled():
return
logging.debug("Tunnel lens alignment mode ready")

if self.tab_data_model.main.spec_ded_aligner:
self.tab_data_model.main.spec_ded_aligner.position.subscribe(self._on_spec_ded_aligner_pos)

def _on_ccd_stream_play(self, _):
"""
Called when the ccd_stream.should_update or speccnt_stream.should_update VA changes.
Expand Down Expand Up @@ -2037,6 +2054,26 @@ def _on_spec_ded_aligner_init_move(self, f: Future) -> None:
except Exception as ex:
logging.error("spec-ded-aligner initialisation move failed: %s", ex)

def _on_spec_ded_aligner_pos(self, pos):
"""
Called when the spec-ded-aligner is moved (and the tunnel align mode is active),
for updating the MD_FAV_POS_ACTIVE
"""
if self.tab_data_model.main.tab.value != self:
# Should never happen, but for safety, we double check
logging.warning("Received active spec-ded-aligner position while outside of alignment tab")
return

# Update the axis which are supposed to be recorded: the ones already in MD_FAV_POS_ACTIVE
aligner = self.tab_data_model.main.spec_ded_aligner
fib_fav_pos = aligner.getMetadata().get(model.MD_FAV_POS_ACTIVE, {})
for axis, p in pos.items():
if axis in fib_fav_pos:
fib_fav_pos[axis] = p

logging.debug("Updating the active spec-ded-aligner position to %s", fib_fav_pos)
aligner.updateMetadata({model.MD_FAV_POS_ACTIVE: fib_fav_pos})

@call_in_wx_main
def _on_ebeam_blanker(self, blanked: bool) -> None:
"""
Expand Down Expand Up @@ -2130,6 +2167,8 @@ def Show(self, show=True):
main.fibaligner.position.unsubscribe(self._onFiberPos)
if main.light_aligner:
main.light_aligner.position.unsubscribe(self._onLightAlignPos)
if main.spec_ded_aligner:
main.spec_ded_aligner.position.unsubscribe(self._on_spec_ded_aligner_pos)
# Also fit to content now, so that next time the tab is displayed, it's ready
self.panel.vp_align_lens.canvas.fit_view_to_content()

Expand Down

0 comments on commit e980588

Please sign in to comment.