Skip to content

Commit

Permalink
Split into smaller subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
sebi06 committed May 10, 2024
1 parent 7922a41 commit b5db6e8
Show file tree
Hide file tree
Showing 51 changed files with 162 additions and 177 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
*.old
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pip install czitools[all]
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
# get the metadata_tools at once as one big class
mdata = czimd.CziMetadata(filepath)

# get only specific metadata
# get only specific metadata_tools
czi_dimensions = czimd.CziDimensions(filepath)
print("SizeS: ", czi_dimensions.SizeS)
print("SizeT: ", czi_dimensions.SizeT)
Expand All @@ -45,7 +45,7 @@ xmlfile = czimd.writexml(filepath)
# get info about the channels
czi_channels = czimd.CziChannelInfo(filepath)

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

# get an object containing only the dimension information
Expand Down
6 changes: 3 additions & 3 deletions demo/scripts/read_attachment_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from czitools.read_tools import AttachmentType
from pathlib import Path
import os
from czitools.czi_metadata import CziMetadata
from czitools.metadata.attachment import CziAttachments
from czitools.metadata_tools.czi_metadata import CziMetadata
from czitools.metadata_tools.attachment import CziAttachments

# adapt to your needs
defaultdir = Path(Path(__file__).resolve().parents[2]) / "data"
Expand All @@ -14,7 +14,7 @@
# filepath = r"Tumor_HE_Orig_small.czi"
# filepath = r"CellDivision_T=10_Z=15_CH=2_DCV_small.czi"

# read all metadata and check for the attachment images
# read all metadata_tools and check for the attachment images
md = CziMetadata(filepath)
print(f"CZI Image has Label {md.attachments.has_label}")
print(f"CZI Image has SlidePreview {md.attachments.has_preview}")
Expand Down
7 changes: 4 additions & 3 deletions demo/scripts/read_czi_aicsimageio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import napari
from aicsimageio import AICSImage
from czitools import napari_tools, czi_metadata as czimd
from czitools.tools import misc
from czitools import napari_tools
from czitools.metadata_tools import czi_metadata as czimd
from czitools.utils import misc
import os
from pathlib import Path

Expand All @@ -28,7 +29,7 @@
)
print(filepath)

# get the complete metadata using czitools
# get the complete metadata_tools using czitools
mdata = czimd.CziMetadata(filepath)

# test using AICSImageIO (needs to be installed)
Expand Down
36 changes: 18 additions & 18 deletions demo/scripts/use_metadata_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@
#
#################################################################

from czitools.czi_metadata import CziMetadata, writexml, get_metadata_as_object, obj2dict
from czitools.metadata.dimension import CziDimensions
from czitools.metadata.boundingbox import CziBoundingBox
from czitools.metadata.channel import CziChannelInfo
from czitools.metadata.scaling import CziScaling
from czitools.metadata.sample import CziSampleInfo
from czitools.metadata.objective import CziObjectives
from czitools.metadata.microscope import CziMicroscope
from czitools.metadata.add_metadata import CziAddMetaData
from czitools.metadata.detector import CziDetector
from czitools.tools import misc
from czitools.metadata_tools.czi_metadata import CziMetadata, writexml, get_metadata_as_object, obj2dict
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.utils import misc
from pathlib import Path

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

# open s simple dialog to select a CZI file
filepath = misc.openfile(directory=str(defaultdir),
title="Open CZI Image File",
ftypename="CZI Files",
extension="*.czi")
title="Open CZI Image File",
ftypename="CZI Files",
extension="*.czi")
print(filepath)

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

# get only specific metadata
# get only specific metadata_tools
czi_dimensions = CziDimensions(filepath)
print("SizeS: ", czi_dimensions.SizeS)
print("SizeT: ", czi_dimensions.SizeT)
Expand All @@ -50,7 +50,7 @@
# get info about the channels
czi_channels = CziChannelInfo(filepath)

# get the complete metadata from the CZI as one big object
# 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
Expand Down Expand Up @@ -83,7 +83,7 @@
print(czi_bbox.total_rect)
print(czi_bbox.total_bounding_box["C"])

# get selected metadata as a dictionary
# get selected metadata_tools as a dictionary
mdata_dict = obj2dict(mdata)

# and convert to pd.DataFrame
Expand Down
2 changes: 1 addition & 1 deletion demo/scripts/use_read_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from czitools import read_tools
from czitools import napari_tools
from czitools.tools import misc
from czitools.utils import misc
import napari
from pathlib import Path

Expand Down
5 changes: 3 additions & 2 deletions demo/scripts/use_write_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#
#################################################################

from czitools import read_tools, write_tools, czi_metadata as czimd
from czitools import read_tools, write_tools
from czitools.metadata_tools import czi_metadata as czimd
import napari
from pathlib import Path

Expand All @@ -18,7 +19,7 @@
filepath = defaultdir / "CellDivision_T3_Z5_CH2_X240_Y170.czi"
zarr_path = Path(str(filepath)[:-4] + ".ome.zarr")

# get the metadata at once as one big class
# get the metadata_tools at once as one big class
mdata = czimd.CziMetadata(filepath)
print("Number of Scenes: ", mdata.image.SizeS)
scene_id = 0
Expand Down
22 changes: 0 additions & 22 deletions src/czitools/_tests/conftest.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/czitools/_tests/test_bounding_box.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
from pylibCZIrw import czi
import pytest
Expand Down
2 changes: 1 addition & 1 deletion src/czitools/_tests/test_channelinfo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
import pytest
from typing import List

Expand Down
2 changes: 1 addition & 1 deletion src/czitools/_tests/test_czimd_box.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
import pytest
from typing import List
Expand Down
2 changes: 1 addition & 1 deletion src/czitools/_tests/test_dimensions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
import pytest
from typing import List, Any
Expand Down
2 changes: 1 addition & 1 deletion src/czitools/_tests/test_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
import pytest
from typing import List
Expand Down
6 changes: 3 additions & 3 deletions src/czitools/_tests/test_instrument.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
import pytest
from typing import Dict
Expand All @@ -25,7 +25,7 @@
)
def test_instrument(czifile: str, result_mic: Dict, result_det: Dict) -> None:

# get the filepath and the metadata
# get the filepath and the metadata_tools
filepath = basedir / "data" / czifile
mic = czimd.CziMicroscope(filepath)
det = czimd.CziDetector(filepath)
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_instrument(czifile: str, result_mic: Dict, result_det: Dict) -> None:
)
def test_objectives(czifile: str, result: Dict) -> None:

# get the filepath and the metadata
# get the filepath and the metadata_tools
filepath = basedir / "data" / czifile
obj = czimd.CziObjectives(filepath)

Expand Down
6 changes: 3 additions & 3 deletions src/czitools/_tests/test_md_general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
import numpy as np
import pytest
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_scene_shape(czifile: str, shape: bool) -> None:

assert (Path.exists(filepath) is True)

# get the complete metadata at once as one big class
# get the complete metadata_tools at once as one big class
md = czimd.CziMetadata(filepath)

assert (md.scene_shape_is_consistent == shape)
Expand All @@ -123,7 +123,7 @@ def test_reading_czi_fresh():

filepath = basedir / r"data/A01_segSD.czi"

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

assert (mdata.sample.well_array_names == [])
Expand Down
4 changes: 2 additions & 2 deletions src/czitools/_tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from czitools import read_tools
from czitools.tools import misc
from czitools.read_tools import read_tools
from czitools.utils import misc
from pathlib import Path
import dask.array as da
import zarr
Expand Down
7 changes: 4 additions & 3 deletions src/czitools/_tests/test_napari_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

try:
import napari
from czitools import napari_tools, czi_metadata
from czitools.napari_tools import napari_tools
from czitools.metadata_tools import czi_metadata

NAPARI_INSTALLED = True
except (ImportError, ModuleNotFoundError) as error:
NAPARI_INSTALLED = False


from czitools import read_tools
from czitools.read_tools import read_tools
import numpy as np
from czitools.czi_metadata import CziMetadata
from czitools.metadata_tools.czi_metadata import CziMetadata
from pathlib import Path
from typing import Dict, Tuple, Literal
import os
Expand Down
7 changes: 4 additions & 3 deletions src/czitools/_tests/test_read_attachments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from czitools import read_tools, czi_metadata
from czitools.read_tools import AttachmentType
from czitools.read_tools import read_tools
from czitools.metadata_tools import czi_metadata
from czitools.metadata_tools.helper import AttachmentType
from pathlib import Path
import numpy as np
import pytest
Expand Down Expand Up @@ -42,7 +43,7 @@ def test_read_attachments_images(
has_prescan: bool,
array_shape: Tuple[int, int, int],
) -> None:
# get the filepath and the metadata
# get the filepath and the metadata_tools
filepath = basedir / "data" / cziname

# get info about attachments only
Expand Down
2 changes: 1 addition & 1 deletion src/czitools/_tests/test_read_mdarray.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import read_tools
from czitools.read_tools import read_tools
from pathlib import Path
import dask.array as da
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion src/czitools/_tests/test_save_planetable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import unittest
import os
from czitools.tools import misc
from czitools.utils import misc


class TestSavePlanetTable(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions src/czitools/_tests/test_scaling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
from box import BoxList
import pytest
Expand All @@ -21,7 +21,7 @@
)
def test_scaling1(czifile: str, results: Dict) -> None:

# get the filepath and the metadata
# get the filepath and the metadata_tools
filepath = basedir / "data" / czifile
czi_scaling = czimd.CziScaling(filepath)
out = czi_scaling.__dict__
Expand Down
4 changes: 2 additions & 2 deletions src/czitools/_tests/test_stageXY.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from czitools import czi_metadata as czimd
from czitools.metadata_tools import czi_metadata as czimd
from pathlib import Path
import pytest
from typing import Dict
Expand Down Expand Up @@ -28,7 +28,7 @@ def test_stage_xy(czifile: str, results: Dict) -> None:
# get the CZI filepath
filepath = basedir / "data" / czifile

# read the metadata
# read the metadata_tools
md = czimd.CziMetadata(filepath)

if md.image.SizeS is not None:
Expand Down
12 changes: 7 additions & 5 deletions src/czitools/_tests/test_writing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from czitools import read_tools, write_tools, czi_metadata as czimd
from czitools.tools import misc
from czitools.read_tools import read_tools
from czitools.write_tools import write_tools
from czitools.metadata_tools import czi_metadata as czimd
from czitools.utils import misc
from pylibCZIrw import czi as pyczi
import shutil
from pathlib import Path
Expand Down Expand Up @@ -96,7 +98,7 @@ def test_write_2(
# write the plane with shape (Y, X, 1) to the new CZI file
czidoc_w.write(data=mdarray[0, 0, ch, z, ...], plane={"C": ch, "Z": z})

# get the complete metadata at once as one big class
# get the complete metadata_tools at once as one big class
mdata = czimd.CziMetadata(newczi)

assert mdata.pyczi_dims == pyczi_dims
Expand Down Expand Up @@ -152,7 +154,7 @@ def test_write_3(
# change the x-position for the next round to write "side-by-side"
xstart = xstart + 512

# get the complete metadata at once as one big class
# get the complete metadata_tools at once as one big class
mdata = czimd.CziMetadata(newczi_zloc)

assert mdata.pyczi_dims == pyczi_dims
Expand Down Expand Up @@ -224,7 +226,7 @@ def test_write_4(
location=(locx[z], locy[z]),
)

# get the complete metadata at once as one big class
# get the complete metadata_tools at once as one big class
mdata = czimd.CziMetadata(newczi_zscenes)

assert mdata.pyczi_dims == pyczi_dims
Expand Down
File renamed without changes.
Loading

0 comments on commit b5db6e8

Please sign in to comment.