Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyzubov committed Oct 25, 2024
1 parent b2b0fb9 commit 5fe4953
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 39 deletions.
24 changes: 12 additions & 12 deletions tif_to_zarr/conversion_lib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the Conversion class used to convert tiff file to OME-NGFF Zarr (contains chunked array)."""

import dask.array as da
import numpy as np
from tifffile import imwrite, TiffFile
Expand All @@ -11,15 +12,15 @@

class Conversion:
"""A class used to convert tiff file to zarr array with properly formatted OME-NGFF metadata."""

def __init__(
self,
input_filepath : str,
output_filepath : str,
axes : List[str],
translation : List[float],
scale : List[float],
units : List[str]
input_filepath: str,
output_filepath: str,
axes: List[str],
translation: List[float],
scale: List[float],
units: List[str],
):
"""Construct all the necessary attributes for the proper conversion of tiff to OME-NGFF Zarr.
Expand All @@ -40,12 +41,11 @@ def __init__(
"units": units,
}


def read_tiff(self):
"""Read tiff file and store array, axes and metadata in a dictionary.
Returns:
[numpy.array, [str], dict]: returns tiff image as numpy array object, axis naming and order, and imagej style metadata.
[numpy.array, [str], dict]: returns tiff image as numpy array object, axis naming and order, and imagej style metadata.
"""
try:
with TiffFile(self.input_filepath) as tiff:
Expand All @@ -60,11 +60,11 @@ def read_tiff(self):
sys.exit(1)
return [volume_numpy, axes, imagej_metadata]

def dask_to_zarray(self, tiff_data : List, chunks : List):
def dask_to_zarray(self, tiff_data: List, chunks: List):
"""Store dask array in a zarr file.
Args:
tiff_data (List): a list containing tiff image as numpy array object, axis naming and order, and imagej style metadata.
tiff_data (List): a list containing tiff image as numpy array object, axis naming and order, and imagej style metadata.
chunks (List): what chunk size to use for output zarr array
"""
# create root group
Expand Down Expand Up @@ -95,7 +95,7 @@ def numpy_to_zarray(self, tiff_data, chunks):
"""Store numpy array in a zarr file.
Args:
tiff_data (List): a list containing tiff image as numpy array object, axis naming and order, and imagej style metadata.
tiff_data (List): a list containing tiff image as numpy array object, axis naming and order, and imagej style metadata.
chunks (List): what chunk size to use for output zarr array
"""
# create root group
Expand Down
26 changes: 7 additions & 19 deletions tif_to_zarr/n5_attrs_template.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
{
"axes": [
"x",
"y",
"z"
],
"multiscales": [
{
"datasets": [

],
"name": "em/fibsem-uint8"
}
],

"pixelResolution":{"dimensions":[0.0,0.0,0.0],"unit":"nm"},
"ordering":"C",
"scales":[],
"units":["nm","nm","nm"],
"translate":[0,0,0]
"axes": ["x", "y", "z"],
"multiscales": [{"datasets": [], "name": "em/fibsem-uint8"}],
"pixelResolution": {"dimensions": [0.0, 0.0, 0.0], "unit": "nm"},
"ordering": "C",
"scales": [],
"units": ["nm", "nm", "nm"],
"translate": [0, 0, 0]
}
11 changes: 3 additions & 8 deletions tif_to_zarr/zarr_attrs_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
"version": "",
"name": "",
"axes": [],
"datasets": [

],
"coordinateTransformations": [

]

"datasets": [],
"coordinateTransformations": []
}
]
}
}

0 comments on commit 5fe4953

Please sign in to comment.