Skip to content

Commit

Permalink
Merge pull request #58 from sebi06/work_in_progress
Browse files Browse the repository at this point in the history
Work in progress
  • Loading branch information
sebi06 authored May 17, 2024
2 parents 3d0731f + 3de7851 commit b763daf
Show file tree
Hide file tree
Showing 64 changed files with 2,850 additions and 2,424 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,5 @@ data/CellDivision_T=10_Z=15_CH=2_DCV_small.czi
/data/Tumor_HE_Orig_small_Label.czi
/data/Tumor_HE_Orig_small_SlidePreview.czi
/data/est_ngff_plate.zarr
/data/est_ngff_plate.zarr
/data/est_ngff_plate.zarr
**/czitools/*.old
78 changes: 60 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,44 @@

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/)

## Installation

To install the basic functionality (will not install Napari und plotting functionality) use:

```text
pip install czitools"
```

To install the package with all optional dependencies use:

```text
pip install czitools[all]
```

## Reading the metadata

Please check [use_metadata_tools.py](https://github.com/sebi06/czitools/blob/main/demo/scripts/use_metadata_tools.py) for some examples.

```python
# get the metadata at once as one big class
mdata = czimd.CziMetadata(filepath)

# get only specific metadata
czi_dimensions = czimd.CziDimensions(filepath)
from czitools.metadata_tools.czi_metadata import CziMetadata, writexml
from czitools.metadata_tools.dimension import CziDimensions
from czitools.metadata_tools.boundingbox import CziBoundingBox
from czitools.metadata_tools.channel import CziChannelInfo
from czitools.metadata_tools.scaling import CziScaling
from czitools.metadata_tools.sample import CziSampleInfo
from czitools.metadata_tools.objective import CziObjectives
from czitools.metadata_tools.microscope import CziMicroscope
from czitools.metadata_tools.add_metadata import CziAddMetaData
from czitools.metadata_tools.detector import CziDetector
from czitools.read_tools import read_tools
from czitools.napari_tools import napari_tools
import napari

# get the metadata_tools at once as one big class
mdata = CziMetadata(filepath)

# get only specific metadata_tools
czi_dimensions = CziDimensions(filepath)
print("SizeS: ", czi_dimensions.SizeS)
print("SizeT: ", czi_dimensions.SizeT)
print("SizeZ: ", czi_dimensions.SizeZ)
Expand All @@ -26,36 +54,36 @@ print("SizeY: ", czi_dimensions.SizeY)
print("SizeX: ", czi_dimensions.SizeX)

# try to write XML to file
xmlfile = czimd.writexml(filepath)
xmlfile = writexml(filepath)

# get info about the channels
czi_channels = czimd.CziChannelInfo(filepath)
czi_channels = CziChannelInfo(filepath)

# get the complete metadata from the CZI as one big object
czimd_complete = czimd.get_metadata_as_object(filepath)
# get the complete metadata_tools from the CZI as one big object
czimd_complete = get_metadata_as_object(filepath)

# get an object containing only the dimension information
czi_dimensions = czimd.CziDimensions(filepath)
czi_dimensions = CziDimensions(filepath)

# get an object containing only the dimension information
czi_scale = czimd.CziScaling(filepath)
czi_scale = CziScaling(filepath)

# get an object containing information about the sample
czi_sample = czimd.CziSampleInfo(filepath)
czi_sample = CziSampleInfo(filepath)

# get info about the objective, the microscope and the detectors
czi_objectives = czimd.CziObjectives(filepath)
czi_detectors = czimd.CziDetector(filepath)
czi_microscope = czimd.CziMicroscope(filepath)
czi_objectives = CziObjectives(filepath)
czi_detectors = CziDetector(filepath)
czi_microscope = CziMicroscope(filepath)

# get info about the sample carrier
czi_sample = czimd.CziSampleInfo(filepath)
czi_sample = CziSampleInfo(filepath)

# get additional metainformation
czi_addmd = czimd.CziAddMetaData(filepath)
czi_addmd = CziAddMetaData(filepath)

# get the complete data about the bounding boxes
czi_bbox = czimd.CziBoundingBox(filepath)
czi_bbox = CziBoundingBox(filepath)
```

## Reading CZI pixel data
Expand Down Expand Up @@ -127,3 +155,17 @@ The basic usage can be inferred from this sample notebook: 
## Remarks

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

Local installation (base functionality only):

```text
pip install -e .
```

### Local Installation

Local installation (full functionality):

```text
pip install -e ".[all]"
```
Binary file modified data/CellDivision_T3_Z5_CH2_X240_Y170_comp1.czi
Binary file not shown.
Binary file modified data/CellDivision_T3_Z5_CH2_X240_Y170_comp2.czi
Binary file not shown.
120 changes: 80 additions & 40 deletions demo/notebooks/omezarr_from_czi_5d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "9873c5dc",
"metadata": {
"editable": true,
Expand All @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "67c73f91",
"metadata": {
"editable": true,
Expand All @@ -62,7 +62,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 11,
"id": "b236d2d9",
"metadata": {},
"outputs": [
Expand All @@ -72,19 +72,21 @@
"'2.15.0'"
]
},
"execution_count": 4,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from czitools import metadata_tools as czimd\n",
"from czitools import read_tools, write_tools\n",
"from czitools.read_tools import read_tools\n",
"from czitools.write_tools import write_tools\n",
"from czitools.metadata_tools import czi_metadata as czimd\n",
"import napari\n",
"from pathlib import Path\n",
"import ome_zarr.reader\n",
"import ome_zarr.scale\n",
"import ome_zarr.writer\n",
"import ome_zarr.format\n",
"from ome_zarr.io import parse_url\n",
"import shutil\n",
"import zarr\n",
Expand All @@ -99,7 +101,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "5b96a0fa",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -130,7 +132,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "2ab02d0c",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -162,28 +164,47 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "68d184ed",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-02-11 14:19:52,010 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-02-11 14:19:52,020 - \u001b[0;30;42mINFO\u001b[0m - Reading BoundingBoxes from CZI image data.\n",
"2024-02-11 14:19:52,021 - \u001b[0;30;42mINFO\u001b[0m - Reading Channel Information from CZI image data.\n",
"2024-02-11 14:19:52,022 - \u001b[0;30;42mINFO\u001b[0m - Reading Scaling from CZI image data.\n",
"2024-02-11 14:19:52,023 - \u001b[0;30;42mINFO\u001b[0m - Reading Objective Information from CZI image data.\n",
"2024-02-11 14:19:52,023 - \u001b[0;30;42mINFO\u001b[0m - Reading Detector Information from CZI image data.\n",
"2024-02-11 14:19:52,024 - \u001b[0;30;42mINFO\u001b[0m - Reading Microscope Information from CZI image data.\n",
"2024-02-11 14:19:52,025 - \u001b[0;30;42mINFO\u001b[0m - Reading SampleCarrier Information from CZI image data.\n",
"2024-02-11 14:19:52,026 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-02-11 14:19:52,028 - \u001b[0;30;42mINFO\u001b[0m - No Scene or Well information found. Try to read XY Stage Coordinates from subblocks.\n",
"2024-02-11 14:19:52,281 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-02-11 14:19:52,291 - \u001b[0;30;42mINFO\u001b[0m - Reading additional Metedata from CZI image data.\n",
"2024-02-11 14:19:52,291 - \u001b[0;30;42mINFO\u001b[0m - No Layers information found.\n",
"2024-02-11 14:19:52,292 - \u001b[0;30;42mINFO\u001b[0m - Reading AttachmentImages from CZI image data.\n"
"2024-05-10 21:28:00,682 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-05-10 21:28:00,687 - \u001b[0;30;42mINFO\u001b[0m - Reading BoundingBoxes from CZI image data.\n",
"2024-05-10 21:28:00,688 - \u001b[0;30;42mINFO\u001b[0m - Reading Channel Information from CZI image data.\n",
"2024-05-10 21:28:00,689 - \u001b[0;30;42mINFO\u001b[0m - Reading Scaling from CZI image data.\n",
"2024-05-10 21:28:00,690 - \u001b[0;30;42mINFO\u001b[0m - Reading Objective Information from CZI image data.\n",
"2024-05-10 21:28:00,691 - \u001b[0;30;42mINFO\u001b[0m - Reading Detector Information from CZI image data.\n",
"2024-05-10 21:28:00,692 - \u001b[0;30;42mINFO\u001b[0m - Reading Microscope Information from CZI image data.\n",
"2024-05-10 21:28:00,692 - \u001b[0;30;42mINFO\u001b[0m - Reading SampleCarrier Information from CZI image data.\n",
"2024-05-10 21:28:00,693 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-05-10 21:28:00,694 - \u001b[0;30;42mINFO\u001b[0m - No Scene or Well information found. Try to read XY Stage Coordinates from subblocks.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "af4099e11f0549379c8fafba72149229",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Reading sublocks planes: 0 2Dplanes [00:00, ? 2Dplanes/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-05-10 21:28:00,721 - \u001b[0;30;42mINFO\u001b[0m - Reading additional Metedata from CZI image data.\n",
"2024-05-10 21:28:00,722 - \u001b[0;30;42mINFO\u001b[0m - No Layers information found.\n",
"2024-05-10 21:28:00,724 - \u001b[0;30;42mINFO\u001b[0m - Reading AttachmentImages from CZI image data.\n"
]
},
{
Expand All @@ -203,34 +224,53 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "1e32b670",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-02-11 14:19:55,788 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-02-11 14:19:55,790 - \u001b[0;30;42mINFO\u001b[0m - Reading BoundingBoxes from CZI image data.\n",
"2024-02-11 14:19:55,792 - \u001b[0;30;42mINFO\u001b[0m - Reading Channel Information from CZI image data.\n",
"2024-02-11 14:19:55,792 - \u001b[0;30;42mINFO\u001b[0m - Reading Scaling from CZI image data.\n",
"2024-02-11 14:19:55,793 - \u001b[0;30;42mINFO\u001b[0m - Reading Objective Information from CZI image data.\n",
"2024-02-11 14:19:55,794 - \u001b[0;30;42mINFO\u001b[0m - Reading Detector Information from CZI image data.\n",
"2024-02-11 14:19:55,795 - \u001b[0;30;42mINFO\u001b[0m - Reading Microscope Information from CZI image data.\n",
"2024-02-11 14:19:55,796 - \u001b[0;30;42mINFO\u001b[0m - Reading SampleCarrier Information from CZI image data.\n",
"2024-02-11 14:19:55,797 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-02-11 14:19:55,798 - \u001b[0;30;42mINFO\u001b[0m - No Scene or Well information found. Try to read XY Stage Coordinates from subblocks.\n",
"2024-02-11 14:19:56,014 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-02-11 14:19:56,021 - \u001b[0;30;42mINFO\u001b[0m - Reading additional Metedata from CZI image data.\n",
"2024-02-11 14:19:56,022 - \u001b[0;30;42mINFO\u001b[0m - No Layers information found.\n",
"2024-02-11 14:19:56,023 - \u001b[0;30;42mINFO\u001b[0m - Reading AttachmentImages from CZI image data.\n"
"2024-05-10 21:28:05,818 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-05-10 21:28:05,820 - \u001b[0;30;42mINFO\u001b[0m - Reading BoundingBoxes from CZI image data.\n",
"2024-05-10 21:28:05,822 - \u001b[0;30;42mINFO\u001b[0m - Reading Channel Information from CZI image data.\n",
"2024-05-10 21:28:05,823 - \u001b[0;30;42mINFO\u001b[0m - Reading Scaling from CZI image data.\n",
"2024-05-10 21:28:05,824 - \u001b[0;30;42mINFO\u001b[0m - Reading Objective Information from CZI image data.\n",
"2024-05-10 21:28:05,825 - \u001b[0;30;42mINFO\u001b[0m - Reading Detector Information from CZI image data.\n",
"2024-05-10 21:28:05,827 - \u001b[0;30;42mINFO\u001b[0m - Reading Microscope Information from CZI image data.\n",
"2024-05-10 21:28:05,828 - \u001b[0;30;42mINFO\u001b[0m - Reading SampleCarrier Information from CZI image data.\n",
"2024-05-10 21:28:05,828 - \u001b[0;30;42mINFO\u001b[0m - Reading Dimensions from CZI image data.\n",
"2024-05-10 21:28:05,830 - \u001b[0;30;42mINFO\u001b[0m - No Scene or Well information found. Try to read XY Stage Coordinates from subblocks.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a5ad1763a40b41cdb280c7ac8a233fc7",
"model_id": "c33ef83c98ff4acbbb09d0c46f11fc74",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Reading sublocks planes: 0 2Dplanes [00:00, ? 2Dplanes/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-05-10 21:28:05,852 - \u001b[0;30;42mINFO\u001b[0m - Reading additional Metedata from CZI image data.\n",
"2024-05-10 21:28:05,853 - \u001b[0;30;42mINFO\u001b[0m - No Layers information found.\n",
"2024-05-10 21:28:05,853 - \u001b[0;30;42mINFO\u001b[0m - Reading AttachmentImages from CZI image data.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3bd107cbfc7d46d79459e7c2d376ee51",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -258,7 +298,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"id": "c670b17c",
"metadata": {},
"outputs": [
Expand Down
Loading

0 comments on commit b763daf

Please sign in to comment.