Skip to content

Commit

Permalink
Merge pull request #30 from sebi06/work_in_progress
Browse files Browse the repository at this point in the history
Work in progress
  • Loading branch information
sebi06 authored Mar 31, 2023
2 parents cea6bdf + 8cc70cd commit 1ccb110
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 128 deletions.
Binary file added data/LLS7_small.czi
Binary file not shown.
30 changes: 6 additions & 24 deletions demo/notebooks/omezarr_from_czi_5d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
"import ome_zarr.writer\n",
"from ome_zarr.io import parse_url\n",
"import shutil\n",
"\n",
"# additional imports\n",
"import zarr\n",
"zarr.__version__\n",
"#from ipytree import Tree, Node"
"zarr.__version__"
]
},
{
Expand All @@ -43,7 +40,7 @@
"outputs": [],
"source": [
"defaultdir = Path.cwd().resolve().parents[1] / \"data\"\n",
"filepath = defaultdir / \"w96_A1+A2.czi\"\n",
"filepath = defaultdir / \"CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi\"\n",
"zarr_path = defaultdir / Path(filepath.name[:-4] + \".ome.zarr\")\n",
"\n",
"print(zarr_path)\n",
Expand Down Expand Up @@ -97,16 +94,7 @@
"# write the image data\n",
"store = parse_url(zarr_path, mode=\"w\").store\n",
"root = zarr.group(store=store)\n",
"root.info"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ba030e3-2e11-4210-a136-5334e713530d",
"metadata": {},
"outputs": [],
"source": [
"root.info\n",
"print(root.tree())"
]
},
Expand Down Expand Up @@ -194,7 +182,6 @@
"outputs": [],
"source": [
"# this is how we can open the file we just wrote in napari\n",
"import napari\n",
"viewer = napari.Viewer()\n",
"viewer.open(zarr_path)"
]
Expand All @@ -210,9 +197,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:ia39] *",
"display_name": "cziread39",
"language": "python",
"name": "conda-env-ia39-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -224,12 +211,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "860439aa1091ca9628697fade70363ec3e96a6399b1dfa15ee9e896d1606a397"
}
"version": "3.9.15"
}
},
"nbformat": 4,
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 @@ -9,7 +9,7 @@
#
#################################################################

from pylibCZIrw import czi as pyczi
# from pylibCZIrw import czi as pyczi
from czitools import pylibczirw_metadata as czimd
from czitools import misc
from pathlib import Path
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = czitools
version = 0.2.2
version = 0.3.0
author = Sebastian Rhode
author_email = sebrhode@gmail.com
url = https://github.com/sebi06/czitools
Expand Down Expand Up @@ -38,7 +38,6 @@ install_requires =
aicspylibczi
tqdm
pylibCZIrw
cztile
numpy
pandas
seaborn
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.2"
__version__ = "0.3.0"
105 changes: 73 additions & 32 deletions src/czitools/_tests/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def test_instrument(czifile: str, result_mic: Dict, result_det: Dict) -> None:
det = czimd.CziDetector(filepath)

# check the microscope data
assert (mic.ID == result_mic[0])
assert (mic.Id == result_mic[0])
assert (mic.Name == result_mic[1])

# check the detector(s) data
assert (det.ID == result_det[0])
assert (det.Id == result_det[0])
assert (det.model == result_det[1])
assert (det.modeltype == result_det[2])
assert (det.name == result_det[3])
Expand All @@ -44,36 +44,77 @@ def test_instrument(czifile: str, result_mic: Dict, result_det: Dict) -> None:
@pytest.mark.parametrize(
"czifile, result",
[
("CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi", {'name': 'Plan-Apochromat 50x/1.2',
'immersion': 'Water',
'NA': 1.2,
'ID': 'Objective:1',
'objmag': 50.0,
'tubelensmag': 1.0,
'totalmag': 50.0}),
("Al2O3_SE_020_sp.czi", {}),
("w96_A1+A2.czi", {'name': 'Plan-Apochromat 20x/0.95',
'immersion': 'Air',
'NA': 0.95,
'ID': 'Objective:1',
'objmag': 20.0,
'tubelensmag': 0.5,
'totalmag': 10.0}),
("Airyscan.czi", {'name': 'Plan-Apochromat 63x/1.4 Oil DIC M27',
'immersion': 'Oil',
'NA': 1.4000000000000001,
'ID': 'Objective:0',
'objmag': 63.0,
'totalmag': 63.0}),
("newCZI_zloc.czi", {}),
("FOV7_HV110_P0500510000.czi", {}),
("Tumor_HE_RGB.czi", {})
("LLS7_small.czi", {'name': ['Objective Reflected Light', 'Objective Observation'],
'model': [],
'immersion': ['Water', 'Water', None],
'NA': [0.44, 1.0],
'Id': ['Objective:1', 'Objective:0', 'Objective:2'],
'objmag': [13.3, 44.83],
'tubelensmag': [],
'totalmag': [13.3, 44.83]}),
("CellDivision_T=3_Z=5_CH=2_X=240_Y=170.czi", {'name': ['Plan-Apochromat 50x/1.2'],
'model': [],
'immersion': ['Water'],
'NA': [1.2],
'Id': ['Objective:1'],
'objmag': [50.0],
'tubelensmag': [1.0],
'totalmag': [50.0]}),
("Al2O3_SE_020_sp.czi", {'name': [],
'model': [],
'immersion': [],
'NA': [],
'Id': [],
'objmag': [],
'tubelensmag': [],
'totalmag': []}),
("w96_A1+A2.czi", {'name': ['Plan-Apochromat 20x/0.95'],
'model': [],
'immersion': ['Air'],
'NA': [0.95],
'Id': ['Objective:1'],
'objmag': [20.0],
'tubelensmag': [0.5],
'totalmag': [10.0]}),
("Airyscan.czi", {'name': ['Plan-Apochromat 63x/1.4 Oil DIC M27'],
'model': [],
'immersion': ['Oil'],
'NA': [1.4000000000000001],
'Id': ['Objective:0'],
'objmag': [63.0],
'tubelensmag': [],
'totalmag': [63.0]}),
("newCZI_zloc.czi", {'name': [],
'model': [],
'immersion': [],
'NA': [],
'Id': [],
'objmag': [],
'tubelensmag': [],
'totalmag': []}),
("FOV7_HV110_P0500510000.czi", {'name': [],
'model': [],
'immersion': [],
'NA': [],
'Id': [],
'objmag': [],
'tubelensmag': [],
'totalmag': []}),
("Tumor_HE_RGB.czi", {'name': [],
'model': [],
'immersion': [],
'NA': [],
'Id': [],
'objmag': [],
'tubelensmag': [],
'totalmag': []})
]
)
Expand Down
15 changes: 15 additions & 0 deletions src/czitools/_tests/test_md_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@
import numpy as np
import pytest
from typing import List, Dict, Tuple, Optional, Type, Any, Union, Mapping
from box import Box, BoxList


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


@pytest.mark.parametrize(
"czifile",
[
"LLS7_small.czi"
]
)
def test_read_metadata(czifile: str) -> None:

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

assert (isinstance(md, czimd.CziMetadata) is True)


def test_pixeltypes_1() -> None:

# get the CZI filepath
Expand Down
46 changes: 39 additions & 7 deletions src/czitools/_tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from czitools import pylibczirw_tools, misc
from pathlib import Path
import dask.array as da
import zarr
import pandas as pd
import pytest
import numpy as np
from typing import List, Dict, Tuple, Optional, Type, Any, Union, Mapping

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


@pytest.mark.parametrize(
"czifile, dimindex, posdim, shape",
[
Expand All @@ -31,7 +34,7 @@ def test_slicedim(czifile: str, dimindex: int, posdim: int, shape: Tuple[int]) -
remove_adim=True)

dim_array = misc.slicedim(mdarray, dimindex, posdim)
assert(dim_array.shape == shape)
assert (dim_array.shape == shape)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -68,17 +71,17 @@ def test_get_planetable(czifile: str, csvfile: str, xstart: List[int], ystart: L
separator=",",
index=True)

assert(csvfile == (basedir / "data" / csvfile).as_posix())
assert (csvfile == (basedir / "data" / csvfile).as_posix())

# remove the file
Path.unlink(Path(csvfile))

planetable_filtered = misc.filter_planetable(planetable, s=0, t=0, z=0, c=0)

assert(planetable_filtered["xstart"][0] == xstart[0])
assert(planetable_filtered["xstart"][1] == xstart[1])
assert(planetable_filtered["ystart"][0] == ystart[0])
assert(planetable_filtered["ystart"][1] == ystart[1])
assert (planetable_filtered["xstart"][0] == xstart[0])
assert (planetable_filtered["xstart"][1] == xstart[1])
assert (planetable_filtered["ystart"][0] == ystart[0])
assert (planetable_filtered["ystart"][1] == ystart[1])


@pytest.mark.parametrize(
Expand All @@ -91,8 +94,37 @@ def test_get_planetable(czifile: str, csvfile: str, xstart: List[int], ystart: L
]
)
def test_check_dimsize(entry: Optional[int], set2value: int, result: int) -> None:
"""
This function checks the dimension size of an entry against a set value
and compares it to a result.
assert (misc.check_dimsize(entry, set2value=set2value) == result)
Parameters:
entry (Optional[int]): The entry to be checked.
set2value (int): The set value to compare the entry against.
result (int): The expected result of the comparison.
Returns: None.
"""

assert (misc.check_dimsize(entry, set2value=set2value) == result)


@pytest.mark.parametrize(
"array, min_value, max_value, corr_min, corr_max",
[
(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], np.int16), 1, 9, 1.0, 1.0),
(zarr.array(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], np.int16)), 1, 9, 1.0, 1.0),
(da.from_array(np.array([[1, 2, 0], [4, -5, 6], [7, 8, 9]], np.int16)), -5, 9, 1.0, 1.0)
]
)
def test_calc_scaling(array: Union[np.ndarray, da.Array, zarr.Array],
min_value: int,
max_value: int,
corr_min: float,
corr_max: float) -> None:

minv, maxv = misc.calc_scaling(array,
corr_min=corr_min,
corr_max=corr_max)

assert (min_value == minv)
assert (max_value == maxv)
Loading

0 comments on commit 1ccb110

Please sign in to comment.