-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MVP of napari viewer #30
Open
ieivanov
wants to merge
4
commits into
main
Choose a base branch
from
viewer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from pycromanager import Dataset | ||
import numpy as np | ||
import napari | ||
import time | ||
from napari.qt import thread_worker | ||
|
||
LF_LAYER_NAME = 'label-free data' | ||
LS_LAYER_NAME = 'light-sheet data' | ||
|
||
lf_dataset_path = r'Z:\rawdata\mantis\2023_04_20 HEK RAC1 PCNA\1timepoint_test_1\1timepoint_test_labelfree_1' | ||
ls_dataset_path = r'Z:\rawdata\mantis\2023_04_20 HEK RAC1 PCNA\1timepoint_test_1\1timepoint_test_lightsheet_1' | ||
|
||
viewer = napari.Viewer() | ||
lf_dataset = Dataset(lf_dataset_path) | ||
ls_dataset = Dataset(ls_dataset_path) | ||
|
||
t_start = time.time() | ||
|
||
def update_layers(data): | ||
""" | ||
update the napari layer with the new image | ||
""" | ||
lf_data = data[0] | ||
ls_data = data[1] | ||
|
||
if lf_data is not None and ls_data is not None: | ||
# update data | ||
try: | ||
viewer.layers[LF_LAYER_NAME].data = lf_data | ||
viewer.layers[LS_LAYER_NAME].data = ls_data | ||
# layers do not exist, create display | ||
except KeyError: | ||
viewer.add_image(lf_data, name=LF_LAYER_NAME) | ||
viewer.add_image(ls_data, name=LS_LAYER_NAME) | ||
|
||
@thread_worker(connect={'yielded': update_layers}) | ||
def napari_signaller(lf_dataset, ls_dataset): | ||
""" | ||
Monitor for signals that Acqusition has a new image ready, and when that happens | ||
update napari appropriately | ||
""" | ||
while True: | ||
if time.time() - t_start < 60: | ||
print('waiting 1 sec') | ||
time.sleep(1) | ||
elif time.time() - t_start < 5 * 60: | ||
print('waiting 15 sec') | ||
time.sleep(15) | ||
elif time.time() - t_start < 60 * 60: | ||
print('waiting 2 min') | ||
time.sleep(2 * 60) | ||
else: | ||
print('waiting 10 min') | ||
time.sleep(10 * 60) | ||
|
||
lf_data, ls_data = None, None | ||
if lf_dataset is not None and ls_dataset is not None: | ||
lf_data = lf_dataset.as_array() | ||
ls_data = ls_dataset.as_array() | ||
|
||
yield (lf_data, ls_data) | ||
|
||
napari_signaller(lf_dataset, ls_dataset) | ||
napari.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
import time | ||
|
||
import click | ||
import napari | ||
|
||
from napari.qt import thread_worker | ||
from pycromanager import Dataset | ||
|
||
_verbose = False | ||
LF_LAYER_NAME = 'label-free data' | ||
LS_LAYER_NAME = 'light-sheet data' | ||
|
||
viewer = napari.Viewer() | ||
t_start = time.time() | ||
|
||
|
||
def update_layers(data): | ||
""" | ||
update the napari layer with the new image | ||
""" | ||
lf_data = data[0] | ||
ls_data = data[1] | ||
|
||
if lf_data is not None and ls_data is not None: | ||
# update data | ||
try: | ||
viewer.layers[LF_LAYER_NAME].data = lf_data | ||
viewer.layers[LS_LAYER_NAME].data = ls_data | ||
# layers do not exist, create display | ||
except KeyError: | ||
viewer.add_image(lf_data, name=LF_LAYER_NAME) | ||
viewer.add_image(ls_data, name=LS_LAYER_NAME) | ||
|
||
|
||
@thread_worker(connect={'yielded': update_layers}) | ||
def napari_signaller(lf_dataset_path, ls_dataset_path): | ||
""" | ||
Monitor for signals that Acquisition has a new image ready, and when that happens | ||
update napari appropriately | ||
""" | ||
while True: | ||
lf_dataset = Dataset(lf_dataset_path) | ||
ls_dataset = Dataset(ls_dataset_path) | ||
|
||
lf_data = lf_dataset.as_array() | ||
ls_data = ls_dataset.as_array() | ||
if _verbose: | ||
print(f'LF data shape: {lf_data.shape}, LF data shape: {ls_data.shape}') | ||
|
||
yield (lf_data, ls_data) | ||
|
||
if time.time() - t_start < 60: | ||
if _verbose: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these be |
||
print('waiting 1 sec') | ||
time.sleep(5) | ||
elif time.time() - t_start < 5 * 60: | ||
if _verbose: | ||
print('waiting 15 sec') | ||
time.sleep(15) | ||
elif time.time() - t_start < 60 * 60: | ||
if _verbose: | ||
print('waiting 2 min') | ||
time.sleep(2 * 60) | ||
else: | ||
if _verbose: | ||
print('waiting 10 min') | ||
time.sleep(10 * 60) | ||
|
||
if _verbose: | ||
print('Closing datasets') | ||
lf_dataset.close() | ||
ls_dataset.close() | ||
|
||
|
||
@click.command() | ||
@click.argument( | ||
"dataset_path", | ||
type=click.Path(exists=True, file_okay=False), | ||
) | ||
def run_viewer(dataset_path): | ||
dirname, basename = os.path.split(dataset_path) | ||
|
||
lf_dataset_name = '_'.join(basename.split('_')[:-1]) + '_labelfree_1' | ||
lf_dataset_path = os.path.join(dirname, basename, lf_dataset_name) | ||
|
||
ls_dataset_name = '_'.join(basename.split('_')[:-1]) + '_lightsheet_1' | ||
ls_dataset_path = os.path.join(dirname, basename, ls_dataset_name) | ||
|
||
napari_signaller(lf_dataset_path, ls_dataset_path) | ||
napari.run() | ||
|
||
|
||
if __name__ == '__main__': | ||
run_viewer() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be slightly faster to check the key with something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same function from recOrder:
https://github.com/mehta-lab/recOrder/blob/802cc62cac537749ab5dce5535d7c0a18137f819/recOrder/plugin/main_widget.py#L1106-L1136