Skip to content

Commit

Permalink
Redo overlay2 (#425)
Browse files Browse the repository at this point in the history
* pull out time loops

* save list of tensors in one line with torch.stack

* pass ND, pad to 4D, then save

* fix 2d bug

* factor out recorder-to-waveorder model conversion

* minor niceties

* error never catches

* less verbose

* label (nm) wavelength on gui

* wip birefringence working

* phase and fluorescence added

* fix indentation error

* fixed issue with torch thread global variable causing crashdump

* isort and black

* pass um consistently to config files

* adding tests for cli

* option to have or remove multiprocessing.

* fixing test and removing printf in applyaffine

* iohub upgrade integration

* fix comment

* convert to nm in recorder models

* fix minor phase bug

* bump waveorder dependency

* handle birefringence parameters more clearly

* better docs

* trigger on latest "Orientation*" layer

* walk the layer list backwards

* simplify

* document birefringence overlay behavior

---------

Co-authored-by: Eduardo Hirata-Miyasaki <edhiratam@gmail.com>
  • Loading branch information
talonchandler and edyoshikun authored Aug 23, 2023
1 parent 828f266 commit bbf3502
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions recOrder/plugin/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,31 +1171,41 @@ def handle_bg_bire_image_update(self, value):
)

def handle_layers_updated(self, event: Event):
"""Whenever a layer is inserted or moved, we check if the top layer
starts with 'Orientation*'. If it is, we search for a layer that starts
with 'Retardance*' and has the same suffix as 'Orientation*', then use the
'Orientation*'-'Retardance*' pair to generate a 'BirefringenceOverlay*'
layer.
We also color the 'Orientation*' layer in an HSV colormap.
"""

layers: LayerList = event.source
latest_layer_name = layers[-1].name
channels = ["Retardance", "Orientation"]
for ch in channels:
if latest_layer_name.startswith(ch):
suffix = latest_layer_name.replace(ch, "")
other_name = channels[1 - channels.index(ch)] + suffix
overlay_name = "BirefringenceOverlay" + suffix
if other_name in layers and overlay_name not in layers:
logging.info(
"Detected updated birefringence layers: "
f"'{latest_layer_name}', '{other_name}'"
)
self._draw_bire_overlay(
[ch + suffix, other_name], overlay_name
)
if latest_layer_name.startswith(channels[1]):
# if the first channel starts with "Orientation"
if layers[-1].name.startswith("Orientation"):
orientation_name = layers[-1].name
suffix = orientation_name.replace("Orientation", "")
retardance_name = "Retardance" + suffix
overlay_name = "BirefringenceOverlay" + suffix
# if the matching retardance layer is present, generate an overlay
if retardance_name in layers:
logging.info(
"Detected updated birefringence layers: "
f"'{retardance_name}', '{orientation_name}'"
)
self._draw_bire_overlay(
retardance_name, orientation_name, overlay_name
)

# always display layers that start with "Orientation" in hsv
logging.info(
"Detected orientation layer in updated layer list."
"Setting its colormap to HSV."
)
self.viewer.layers[latest_layer_name].colormap = "hsv"
self.viewer.layers[orientation_name].colormap = "hsv"

def _draw_bire_overlay(
self, source_names: list[str, str], overlay_name: str
self, retardance_name: str, orientation_name: str, overlay_name: str
):
def _layer_data(name: str):
data = self.viewer.layers[name].data
Expand All @@ -1210,7 +1220,6 @@ def _layer_data(name: str):
def _draw(overlay):
self._add_or_update_image_layer(overlay, overlay_name, cmap="rgb")

orientation_name, retardance_name = sorted(source_names)
retardance = _layer_data(retardance_name)
orientation = _layer_data(orientation_name)
worker = create_worker(
Expand Down

0 comments on commit bbf3502

Please sign in to comment.