Note
Go to the end to download the full example code.
Viewing Clear Control#
Example of opening a Clear Control dataset and viewing with napari.
Usage:
$ python view_clearcontrol_dataset.py <OPTIONAL Clear Control dataset>
If the dataset path is not provided, it creates a mock dataset of random integers.
Setup
import sys
import tempfile
import time
from iohub.clearcontrol import (
ClearControlFOV,
create_mock_clear_control_dataset,
)
Parse optional Clear Control dataset path. Mock dataset is created if dataset path is not provided.
if len(sys.argv) < 2:
print("Loading mock random noise dataset ...")
path = f"{tempfile.gettempdir()}/dataset.cc"
create_mock_clear_control_dataset(path)
else:
path = sys.argv[1]
Loading mock random noise dataset ...
Open Clear Control dataset.
s = time.time()
cc = ClearControlFOV(path, cache=True)
print("init time (secs)", time.time() - s)
init time (secs) 0.0001285076141357422
Time load time of a single volume.
s = time.time()
cc[0, 0]
print("single volume load time (secs)", time.time() - s)
Traceback (most recent call last):
File "/tmp/tmp6ck5egm1/docs/examples/run_view_clearcontrol_dataset.py", line 49, in <module>
cc[0, 0]
~~^^^^^^
File "/tmp/tmp6ck5egm1/iohub/clearcontrol.py", line 325, in __getitem__
return self._load_array(key)
^^^^^^^^^^^^^^^^^^^^^
File "/tmp/tmp6ck5egm1/iohub/clearcontrol.py", line 125, in _key_cache_wrapper
self._cache_array = f(self, key)
^^^^^^^^^^^^
File "/tmp/tmp6ck5egm1/iohub/clearcontrol.py", line 335, in _load_array
shape = self.shape
^^^^^^^^^^
File "/tmp/tmp6ck5egm1/iohub/clearcontrol.py", line 192, in shape
last_line = f.readlines()[-1].decode("utf-8")
~~~~~~~~~~~~~^^^^
IndexError: list index out of range
Load dataset using napari
if __name__ == "__main__":
try:
import napari
s = time.time()
napari.view_image(cc)
print("napari load time (secs)", time.time() - s)
napari.run()
except ModuleNotFoundError:
pass