Skip to content

Commit

Permalink
Merge pull request #28 from sebi06/work_in_progress
Browse files Browse the repository at this point in the history
Work in progress
  • Loading branch information
sebi06 authored Feb 9, 2023
2 parents 3ff0090 + 86b8a48 commit efa9eca
Show file tree
Hide file tree
Showing 20 changed files with 483 additions and 436 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ xmlfile = czimd.writexml(filepath)
czi_channels = czimd.CziChannelInfo(filepath)

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

# get an object containing only the dimension information
czi_dimensions = czimd.CziDimensions(filepath)
Expand Down
Binary file added data/10x10.czi
Binary file not shown.
Binary file added data/nuc_small.czi
Binary file not shown.
6 changes: 3 additions & 3 deletions demo/notebooks/save_with_ZSTD_compression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:ia39]",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "conda-env-ia39-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -158,7 +158,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.10.8"
},
"vscode": {
"interpreter": {
Expand Down
2 changes: 1 addition & 1 deletion demo/scripts/use_pylibczirw_metadata_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
czi_channels = czimd.CziChannelInfo(filepath)

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

# get an object containing only the dimension information
czi_dimensions = czimd.CziDimensions(filepath)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = czitools
version = 0.2.0
version = 0.2.1
author = Sebastian Rhode
author_email = [email protected]
url = https://github.com/sebi06/czitools
Expand Down
2 changes: 1 addition & 1 deletion src/czitools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# __init__.py
# version of the czitools package
__version__ = "0.2.0"
__version__ = "0.2.1"
69 changes: 37 additions & 32 deletions src/czitools/_tests/test_channelinfo.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
from pathlib import Path
from czitools import pylibczirw_metadata as czimd

basedir = Path(__file__).resolve().parents[3]


def test_channelinfo():

# get the CZI filepath
filepath = basedir / r"data/CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi"
czi_channels = czimd.CziChannelInfo(filepath)

assert (czi_channels.clims == [[0.0, 0.05983062485694667], [0.0, 0.24975967040512703]])
assert (czi_channels.colors == ["#FFFF7E00", "#FF00FF33"])
assert (czi_channels.gamma == [0.7999999999999998, 0.7999999999999998])
assert (czi_channels.names == ["LED555", "LED470"])
assert (czi_channels.dyes == ["AF555", "AF488"])

# get the CZI filepath
filepath = basedir / r"data/Al2O3_SE_020_sp.czi"
czi_channels = czimd.CziChannelInfo(filepath)

assert (czi_channels.clims == [[0.0, 0.5]])
assert (czi_channels.colors == ["#80808000"])
assert (czi_channels.gamma == [0.85])
assert (czi_channels.names == ["CH1"])
assert (czi_channels.dyes == ["Dye-CH1"])
import pytest
from typing import List, Dict, Tuple, Optional, Type, Any, Union, Mapping

basedir = Path(__file__).resolve().parents[3] / "data"

@pytest.mark.parametrize(
"czifile, clims, colors, gamma, names, dyes",
[
("CellDivision_T=3_Z=5_CH=2_X=240_Y=170.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'])
]
)
def test_channelinfo(czifile: str, clims: List, colors: List, gamma: List, names: List, dyes: List) -> None:

# get the CZI filepath
filepath = basedir / r"data/w96_A1+A2.czi"
filepath = basedir / czifile
czi_channels = czimd.CziChannelInfo(filepath)

assert (czi_channels.clims == [[0.000871455799315693, 0.044245974575704575], [
0.000881881329185286, 0.05011349562051524]])
assert (czi_channels.colors == ['#FFFF1800', '#FF00FF33'])
assert (czi_channels.gamma == [0.7999999999999998, 0.7999999999999998])
assert (czi_channels.names == ['AF568', 'AF488'])
assert (czi_channels.dyes == ['AF568', 'AF488'])
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)
106 changes: 56 additions & 50 deletions src/czitools/_tests/test_czimd_box.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,68 @@
from czitools import pylibczirw_metadata as czimd
from pathlib import Path, PurePath
import pytest
from typing import List, Dict, Tuple, Optional, Type, Any, Union, Mapping


# adapt to your needs
defaultdir = Path(__file__).resolve().parents[3] / "data"

def test_general_attr():

@pytest.mark.parametrize(
"attribute",
[
"has_customattr",
"has_exp",
"has_disp",
"has_hardware",
"has_scale",
"has_instrument",
"has_microscopes",
"has_detectors",
"has_objectives",
"has_tubelenses",
"has_disp",
"has_channels",
"has_info",
"has_app",
"has_doc",
"has_image",
"has_scenes",
"has_dims"
]
)
def test_general_attr(attribute: str) -> None:

filepath = defaultdir / "CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi"

czibox = czimd.get_czimd_box(filepath)

assert(hasattr(czibox, "has_customattr"))
assert(hasattr(czibox, "has_exp = False"))
assert(hasattr(czibox, "has_disp"))
assert(hasattr(czibox, "has_hardware"))
assert(hasattr(czibox, "has_scale"))
assert(hasattr(czibox, "has_instrument"))
assert(hasattr(czibox, "has_microscopes"))
assert(hasattr(czibox, "has_detectors"))
assert(hasattr(czibox, "has_objectives"))
assert(hasattr(czibox, "has_tubelenses"))
assert(hasattr(czibox, "has_disp"))
assert(hasattr(czibox, "has_channels"))
assert(hasattr(czibox, "has_info"))
assert(hasattr(czibox, "has_app"))
assert(hasattr(czibox, "has_doc"))
assert(hasattr(czibox, "has_image"))
assert(hasattr(czibox, "has_scenes"))
assert(hasattr(czibox, "has_dims"))


def test_box():

czifiles = ["CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi",
"Al2O3_SE_020_sp.czi",
"w96_A1+A2.czi",
"Airyscan.czi",
"newCZI_zloc.czi",
"does_not_exist.czi",
"FOV7_HV110_P0500510000.czi",
"Tumor_HE_RGB.czi",
"WP96_4Pos_B4-10_DAPI.czi",
"S=3_1Pos_2Mosaic_T=2=Z=3_CH=2_sm.czi"
]

results = [True, True, True, True, True, False, True, True, True, True]

for czifile, result in zip(czifiles, results):

filepath = defaultdir / czifile

try:
czibox = czimd.get_czimd_box(filepath)
ok = True
except Exception:
ok = False

assert(ok == result)

test_box()
assert (hasattr(czibox, attribute))


@pytest.mark.parametrize(
"czifile, expected",
[
("CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi", True),
("Al2O3_SE_020_sp.czi", True),
("w96_A1+A2.czi", True),
("Airyscan.czi", True),
("newCZI_zloc.czi", True),
("does_not_exist.czi", False),
("FOV7_HV110_P0500510000.czi", True),
("Tumor_HE_RGB.czi", True),
("WP96_4Pos_B4-10_DAPI.czi", True),
("S=3_1Pos_2Mosaic_T=2=Z=3_CH=2_sm.czi", True)
]
)
def test_box(czifile: List[str], expected: bool) -> None:

filepath = defaultdir / czifile

try:
czibox = czimd.get_czimd_box(filepath)
ok = True
except Exception:
ok = False

assert (ok == expected)
26 changes: 16 additions & 10 deletions src/czitools/_tests/test_dimensions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

from czitools import pylibczirw_metadata as czimd
from pathlib import Path
import pytest
from typing import List, Dict, Tuple, Optional, Type, Any, Union, Mapping

basedir = Path(__file__).resolve().parents[3]

# get the CZI filepath
filepath = basedir / r"data/CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi"
@pytest.mark.parametrize(
"czifile, dimension",
[
("CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi", [None, 3, 5, 2, 170, 240])
]
)
def test_dimensions(czifile: str, dimension: List[Any]) -> None:


def test_dimensions():
filepath = basedir / "data" / czifile

czi_dimensions = czimd.CziDimensions(filepath)
print("SizeS: ", czi_dimensions.SizeS)
Expand All @@ -18,9 +24,9 @@ def test_dimensions():
print("SizeY: ", czi_dimensions.SizeY)
print("SizeX: ", czi_dimensions.SizeX)

assert (czi_dimensions.SizeS is None)
assert (czi_dimensions.SizeT == 3)
assert (czi_dimensions.SizeZ == 5)
assert (czi_dimensions.SizeC == 2)
assert (czi_dimensions.SizeY == 170)
assert (czi_dimensions.SizeX == 240)
assert (czi_dimensions.SizeS == dimension[0])
assert (czi_dimensions.SizeT == dimension[1])
assert (czi_dimensions.SizeZ == dimension[2])
assert (czi_dimensions.SizeC == dimension[3])
assert (czi_dimensions.SizeY == dimension[4])
assert (czi_dimensions.SizeX == dimension[5])
71 changes: 34 additions & 37 deletions src/czitools/_tests/test_info.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
from czitools import pylibczirw_metadata as czimd
from pathlib import Path
import pytest
from typing import List, Dict, Tuple, Optional, Type, Any, Union, Mapping

basedir = Path(__file__).resolve().parents[3]


def test_information():

to_test = {0: r"data/CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi",
1: r"data/Airyscan.czi",
2: r"data/newCZI_zloc.czi"}

results = {0: ['ZEN 3.2 (blue edition)',
'3.2.0.00001',
'2016-02-12T09:41:02.4915604Z',
True,
'CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi'],
1: ['ZEN (blue edition)',
'3.5.093.00000',
None,
True,
'Airyscan.czi'],
2: ['pylibCZIrw',
'3.2.1',
None,
True,
'newCZI_zloc.czi']
}

for t in range(len(to_test)):

# get the filepath
filepath = basedir / to_test[t]
md = czimd.CziMetadata(filepath)

assert (md.software_name == results[t][0])
assert (md.software_version == results[t][1])
assert (md.acquisition_date == results[t][2])
assert (Path.exists(Path(md.dirname)) == results[t][3])
assert (md.filename == results[t][4])


test_information()
@pytest.mark.parametrize(
"czifile, result",
[
("CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi", ['ZEN 3.2 (blue edition)',
'3.2.0.00001',
'2016-02-12T09:41:02.4915604Z',
True,
'CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi']),
("Airyscan.czi", ['ZEN (blue edition)',
'3.5.093.00000',
None,
True,
'Airyscan.czi']),
("newCZI_zloc.czi", ['pylibCZIrw',
'3.2.1',
None,
True,
'newCZI_zloc.czi'])
]
)
def test_information(czifile: str, result: List) -> None:

filepath = basedir / "data" / czifile
md = czimd.CziMetadata(filepath)

assert (md.software_name == result[0])
assert (md.software_version == result[1])
assert (md.acquisition_date == result[2])
assert (Path.exists(Path(md.dirname)) == result[3])
assert (md.filename == result[4])
Loading

0 comments on commit efa9eca

Please sign in to comment.