Skip to content

Commit e7ac599

Browse files
authored
Merge pull request #88 from sebi06/remove_napari_tools
- remove napari-tools - output 6d xarray
2 parents 7ba1e0e + aa689dc commit e7ac599

38 files changed

+19344
-752
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,5 @@ data/nuc_small.czi
183183
data/Tumor_HE_Orig_small_disp.czi
184184
data/Tumor_HE_RGB_disp.czi
185185
.pylintrc
186+
/old
187+
/demo/notebooks/__marimo__

README.md

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
[![Python Version](https://img.shields.io/pypi/pyversions/czitools.svg?color=green)](https://python.org)
88
[![Development Status](https://img.shields.io/pypi/status/czitools.svg)](https://en.wikipedia.org/wiki/Software_release_life_cycle#Alpha)
99

10-
This repository provides a collection of tools to simplify reading CZI (Carl Zeiss Image) pixel and metadata in Python. In addition, it also contains other useful utilities to visualize CZI images inside Napari (needs to be installed). It is also available as a [Python Package on PyPi](https://pypi.org/project/czitools/)
10+
This repository provides a collection of tools to simplify reading CZI (Carl Zeiss Image) pixel and metadata in Python. It is available as a [Python Package on PyPi](https://pypi.org/project/czitools/)
1111

1212
## Installation
1313

14-
To install the basic functionality (will not install Napari und plotting functionality) use:
14+
To install czitools use (will not install Napari or plotting functionality):
1515

1616
```text
1717
pip install czitools
1818
```
1919

20-
To install the package with all optional dependencies use:
20+
To install the package with all optional dependencies use (will not install Napari):
2121

2222
```text
2323
pip install czitools[all]
@@ -39,8 +39,15 @@ from czitools.metadata_tools.microscope import CziMicroscope
3939
from czitools.metadata_tools.add_metadata import CziAddMetaData
4040
from czitools.metadata_tools.detector import CziDetector
4141
from czitools.read_tools import read_tools
42-
from czitools.napari_tools import napari_tools
43-
import napari
42+
43+
try:
44+
import napari
45+
from napari.utils.colormaps import Colormap
46+
47+
show_napari = True
48+
except ImportError:
49+
print("Napari not installed, skipping napari import")
50+
show_napari = False
4451

4552
# get the metadata_tools at once as one big class
4653
mdata = CziMetadata(filepath)
@@ -90,29 +97,50 @@ While the [pylibCZIrw](https://pypi.org/project/pylibCZIrw/) is focussing on rea
9097

9198
```python
9299
# return a dask or numpy array with dimension order STCZYX(A)
93-
array6d, mdata = read_tools.read_6darray(filepath,
94-
use_dask=True,
95-
chunk_zyx=False,
96-
# T=0,
97-
# Z=0
98-
# S=0
99-
# C=0
100-
)
101-
102-
if array6d is None:
103-
print("Empty array6d. Nothing to display in Napari")
104-
else:
105-
106-
# show array inside napari viewer
100+
array6d, mdata = read_tools.read_6darray(filepath, use_xarray=True)
101+
102+
if show_napari:
103+
104+
# show in napari (requires napari to be installed!)
107105
viewer = napari.Viewer()
108-
layers = napari_tools.show(viewer, array6d, mdata,
109-
blending="additive",
110-
contrast='from_czi',
111-
gamma=0.85,
112-
show_metadata="tree",
113-
name_sliders=True)
106+
107+
# loop over all channels
108+
for ch in range(0, array6d.sizes["C"]):
109+
110+
# extract channel subarray
111+
sub_array = array6d.sel(C=ch)
112+
113+
# get the scaling factors for that channel and adapt Z-axis scaling
114+
scalefactors = [1.0] * len(sub_array.shape)
115+
scalefactors[sub_array.get_axis_num("Z")] = mdata.scale.ratio["zx_sf"]
116+
117+
# remove the last scaling factor in case of an RGB image
118+
if "A" in sub_array.dims:
119+
# remove the A axis from the scaling factors
120+
scalefactors.pop(sub_array.get_axis_num("A"))
121+
122+
# get colors and channel name
123+
chname = mdata.channelinfo.names[ch]
124+
125+
# inside the CZI metadata_tools colors are defined as ARGB hexstring
126+
rgb = "#" + mdata.channelinfo.colors[ch][3:]
127+
ncmap = Colormap(["#000000", rgb], name="cm_" + chname)
128+
129+
# add the channel to the viewer
130+
viewer.add_image(
131+
sub_array,
132+
name=chname,
133+
colormap=ncmap,
134+
blending="additive",
135+
scale=scalefactors,
136+
gamma=0.85,
137+
)
138+
139+
# set the axis labels based on the dimensions
140+
viewer.dims.axis_labels = sub_array.dims
114141

115142
napari.run()
143+
116144
```
117145

118146
![5D CZI inside Napari](https://github.com/sebi06/czitools/raw/main/images/czi_napari1.png)
@@ -134,7 +162,6 @@ The basic usage can be inferred from this sample notebook: 
134162
The basic usage can be inferred from this sample notebook: 
135163
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/sebi06/czitools/blob/main/demo/notebooks/omezarr_from_czi_5d.ipynb)
136164

137-
138165
### Write CZI using ZSTD compression
139166

140167
The basic usage can be inferred from this sample notebook: 
@@ -154,14 +181,14 @@ The basic usage can be inferred from this sample notebook: 
154181

155182
The code to read multi-dimensional with delayed reading using Dask array was heavily inspired by input from: [Pradeep Rajasekhar](https://github.com/pr4deepr).
156183

157-
Local installation (base functionality only):
184+
### Local Installation
185+
186+
Local installation:
158187

159188
```text
160189
pip install -e .
161190
```
162191

163-
### Local Installation
164-
165192
Local installation (full functionality):
166193

167194
```text

0 commit comments

Comments
 (0)