-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from sebi06/work_in_progress
Work in progress
- Loading branch information
Showing
17 changed files
with
581 additions
and
162 deletions.
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
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,19 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from pylibCZIrw import czi as pyczi | ||
|
||
filepath = r"F:\Testdata_Zeiss\CZI_Testfiles\DAPI_GFP.czi" | ||
|
||
|
||
class ZenReader: | ||
|
||
def __init__(self, filepath): | ||
self.filepath = filepath | ||
self._czidoc = pyczi.CziReader(self.filepath) | ||
|
||
def read_czi(self): | ||
total_bounding_box = self._czidoc.total_bounding_box | ||
print(total_bounding_box) | ||
|
||
def __del__(self): | ||
self._czidoc.close() |
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,85 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
################################################################# | ||
# File : read_write_czi.py | ||
# Author : sebi06 | ||
# | ||
# Disclaimer: This code is purely experimental. Feel free to | ||
# use it at your own risk. | ||
# | ||
################################################################# | ||
|
||
from pylibCZIrw import czi as pyczi | ||
from czitools.metadata_tools.czi_metadata import CziChannelInfo | ||
import numpy as np | ||
|
||
|
||
# def hex_to_rgb(hex_string: str) -> tuple[int, int, int]: | ||
# """ | ||
# Convert a hexadecimal color string to an RGB tuple. | ||
# Args: | ||
# hex_string (str): A string representing a color in hexadecimal format (e.g., '#RRGGBB'). | ||
# Returns: | ||
# tuple: A tuple containing the RGB values (r, g, b) as integers. | ||
# """ | ||
# # Remove the '#' character | ||
# hex_string = hex_string.lstrip("#") | ||
|
||
# # Convert hex string to integer values | ||
# r = int(hex_string[0:2], 16) | ||
# g = int(hex_string[2:4], 16) | ||
# b = int(hex_string[4:6], 16) | ||
|
||
# return r, g, b | ||
|
||
# filepath = r"F:\Github\czitools\data\Tumor_HE_Orig_small.czi" | ||
# filepath = r"F:\Github\czitools\data\CellDivision_T3_Z5_CH2_X240_Y170.czi" | ||
filepath = r"F:\Github\czitools\data\Al2O3_SE_020_sp.czi" | ||
# filepath = r"F:\Github\czitools\data\w96_A1+A2.czi" | ||
filepath_new = filepath[:-4] + "_disp.czi" | ||
|
||
write_new = False | ||
|
||
ch_info = CziChannelInfo(filepath, verbose=True) | ||
|
||
channel_names_dict = {index: value for index, value in enumerate(ch_info.names)} | ||
|
||
display_settings_dict = ch_info.czi_disp_settings | ||
|
||
# display_settings_dict = {} | ||
|
||
# for channel_index in range(len(ch_info.names)): | ||
|
||
# # inside the CZI metadata_tools colors are defined as ARGB hexstring | ||
# r, g, b = hex_to_rgb(ch_info.colors[channel_index][3:]) | ||
|
||
# display_settings_dict[channel_index] = pyczi.ChannelDisplaySettingsDataClass( | ||
# True, | ||
# pyczi.TintingMode.Color, | ||
# pyczi.Rgb8Color(np.uint8(r), np.uint8(g), np.uint8(b)), | ||
# ch_info.clims[channel_index][0], | ||
# ch_info.clims[channel_index][1], | ||
# ) | ||
|
||
|
||
with pyczi.open_czi(filepath) as czidoc: | ||
|
||
ch0 = czidoc.read(plane={"T": 0, "Z": 0, "C": 0}) | ||
# ch1 = czidoc.read(plane={"T": 0, "Z": 0, "C": 1}) | ||
|
||
print(f"ch_info: {ch_info}") | ||
|
||
if write_new: | ||
|
||
with pyczi.create_czi(filepath_new, exist_ok=True) as czidoc: | ||
|
||
# write the 2D plane to the new CZI file | ||
czidoc.write(data=ch0, plane={"T": 0, "Z": 0, "C": 0}) | ||
# czidoc.write(data=ch1, plane={"T": 0, "Z": 0, "C": 1}) | ||
|
||
# write the document title, channel names and dispaly settings | ||
czidoc.write_metadata( | ||
document_name="test", | ||
channel_names=channel_names_dict, | ||
display_settings=display_settings_dict, | ||
) |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[metadata] | ||
name = czitools | ||
version = 0.7.3 | ||
version = 0.7.4 | ||
author = Sebastian Rhode | ||
author_email = [email protected] | ||
url = https://github.com/sebi06/czitools | ||
|
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# __init__.py | ||
# version of the czitools package | ||
__version__ = "0.7.3" | ||
__version__ = "0.7.4" |
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 |
---|---|---|
@@ -1,43 +1,137 @@ | ||
from pathlib import Path | ||
from czitools.metadata_tools import czi_metadata as czimd | ||
import pytest | ||
from typing import List | ||
from typing import List, Dict | ||
from pylibCZIrw import czi as pyczi | ||
|
||
|
||
basedir = Path(__file__).resolve().parents[3] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"czifile, clims, colors, gamma, names, dyes", | ||
"czifile, clims, colors, gamma, names, dyes, ch_disp, is_rgb, is_consistent, pxtypes", | ||
[ | ||
("CellDivision_T3_Z5_CH2_X240_Y170.czi", | ||
[[0.0, 0.05983062485694667], [0.0, 0.24975967040512703]], | ||
["#FFFF7E00", "#FF00FF33"], | ||
[0.7999999999999998, 0.7999999999999998], | ||
["LED555", "LED470"], | ||
["AF555", "AF488"]), | ||
("Al2O3_SE_020_sp.czi", | ||
[[0.0, 0.5]], | ||
["#80808000"], | ||
[0.85], | ||
["CH1"], | ||
["Dye-CH1"]), | ||
("w96_A1+A2.czi", | ||
[[0.000871455799315693, 0.044245974575704575], [0.000881881329185286, 0.05011349562051524]], | ||
['#FFFF1800', '#FF00FF33'], | ||
[0.7999999999999998, 0.7999999999999998], | ||
['AF568', 'AF488'], | ||
['AF568', 'AF488']) | ||
] | ||
( | ||
"Tumor_HE_Orig_small.czi", | ||
[[0.0, 0.5]], | ||
["#80808000"], | ||
[0.85], | ||
["CH1"], | ||
["Brigh"], | ||
{ | ||
0: pyczi.ChannelDisplaySettingsDataClass( | ||
True, | ||
pyczi.TintingMode.none, | ||
pyczi.Rgb8Color(r=128, g=128, b=0), | ||
0.0, | ||
1.0, | ||
) | ||
}, | ||
{0: True}, | ||
True, | ||
{0: "Bgr24"}, | ||
), | ||
( | ||
"CellDivision_T3_Z5_CH2_X240_Y170.czi", | ||
[[0.0, 0.05983062485694667], [0.0, 0.24975967040512703]], | ||
["#FFFF7E00", "#FF00FF33"], | ||
[0.7999999999999998, 0.7999999999999998], | ||
["LED555", "LED470"], | ||
["AF555", "AF488"], | ||
{ | ||
0: pyczi.ChannelDisplaySettingsDataClass( | ||
True, | ||
pyczi.TintingMode.Color, | ||
pyczi.Rgb8Color(r=255, g=126, b=0), | ||
0.0, | ||
0.05983062485694667, | ||
), | ||
1: pyczi.ChannelDisplaySettingsDataClass( | ||
True, | ||
pyczi.TintingMode.Color, | ||
pyczi.Rgb8Color(r=0, g=255, b=51), | ||
0.0, | ||
0.24975967040512703, | ||
), | ||
}, | ||
{0: False, 1: False}, | ||
True, | ||
{0: "Gray16", 1: "Gray16"}, | ||
), | ||
( | ||
"Al2O3_SE_020_sp.czi", | ||
[[0.0, 0.5]], | ||
["#80808000"], | ||
[0.85], | ||
["CH1"], | ||
["Dye-CH1"], | ||
{ | ||
0: pyczi.ChannelDisplaySettingsDataClass( | ||
True, | ||
pyczi.TintingMode.Color, | ||
pyczi.Rgb8Color(r=128, g=128, b=0), | ||
0.0, | ||
0.5, | ||
) | ||
}, | ||
{0: False}, | ||
True, | ||
{0: "Gray8"}, | ||
), | ||
( | ||
"w96_A1+A2.czi", | ||
[ | ||
[0.000871455799315693, 0.044245974575704575], | ||
[0.000881881329185286, 0.05011349562051524], | ||
], | ||
["#FFFF1800", "#FF00FF33"], | ||
[0.7999999999999998, 0.7999999999999998], | ||
["AF568", "AF488"], | ||
["AF568", "AF488"], | ||
{ | ||
0: pyczi.ChannelDisplaySettingsDataClass( | ||
True, | ||
pyczi.TintingMode.Color, | ||
pyczi.Rgb8Color(r=255, g=24, b=0), | ||
0.000871455799315693, | ||
0.044245974575704575, | ||
), | ||
1: pyczi.ChannelDisplaySettingsDataClass( | ||
True, | ||
pyczi.TintingMode.Color, | ||
pyczi.Rgb8Color(r=0, g=255, b=51), | ||
0.000881881329185286, | ||
0.05011349562051524, | ||
), | ||
}, | ||
{0: False, 1: False}, | ||
True, | ||
{0: "Gray16", 1: "Gray16"}, | ||
), | ||
], | ||
) | ||
def test_channelinfo(czifile: str, clims: List, colors: List, gamma: List, names: List, dyes: List) -> None: | ||
def test_channelinfo( | ||
czifile: str, | ||
clims: List[List[float]], | ||
colors: List[str], | ||
gamma: List[float], | ||
names: List[str], | ||
dyes: List[str], | ||
ch_disp: Dict[int, pyczi.ChannelDisplaySettingsDataClass], | ||
is_rgb: Dict[int, bool], | ||
is_consistent: bool, | ||
pxtypes: Dict[int, str], | ||
) -> None: | ||
# get the CZI filepath | ||
filepath = basedir / "data" / czifile | ||
czi_channels = czimd.CziChannelInfo(filepath) | ||
czi_channels = czimd.CziChannelInfo(filepath, verbose=False) | ||
|
||
assert (czi_channels.clims == clims) | ||
assert (czi_channels.colors == colors) | ||
assert (czi_channels.gamma == gamma) | ||
assert (czi_channels.names == names) | ||
assert (czi_channels.dyes == dyes) | ||
assert czi_channels.clims == clims | ||
assert czi_channels.colors == colors | ||
assert czi_channels.gamma == gamma | ||
assert czi_channels.names == names | ||
assert czi_channels.dyes == dyes | ||
assert czi_channels.czi_disp_settings == ch_disp | ||
assert czi_channels.isRGB == is_rgb | ||
assert czi_channels.consistent_pixeltypes == is_consistent | ||
assert czi_channels.pixeltypes == pxtypes |
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
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
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
Oops, something went wrong.