Skip to content
Snippets Groups Projects
Commit 950b2052 authored by s214735's avatar s214735
Browse files

more

parent 427ecd0b
No related branches found
No related tags found
1 merge request!143Type hints
......@@ -21,7 +21,7 @@ class Convert:
"""
self.chunk_shape = kwargs.get("chunk_shape", (64, 64, 64))
def convert(self, input_path, output_path):
def convert(self, input_path: str, output_path: str):
def get_file_extension(file_path):
root, ext = os.path.splitext(file_path)
if ext in ['.gz', '.bz2', '.xz']: # handle common compressed extensions
......@@ -67,7 +67,7 @@ class Convert:
else:
raise ValueError("Invalid path")
def convert_tif_to_zarr(self, tif_path, zarr_path):
def convert_tif_to_zarr(self, tif_path: str, zarr_path: str):
"""Convert a tiff file to a zarr file
Args:
......@@ -97,7 +97,7 @@ class Convert:
return z
def convert_zarr_to_tif(self, zarr_path, tif_path):
def convert_zarr_to_tif(self, zarr_path: str, tif_path: str):
"""Convert a zarr file to a tiff file
Args:
......@@ -110,7 +110,7 @@ class Convert:
z = zarr.open(zarr_path)
save(tif_path, z)
def convert_nifti_to_zarr(self, nifti_path, zarr_path):
def convert_nifti_to_zarr(self, nifti_path: str, zarr_path: str):
"""Convert a nifti file to a zarr file
Args:
......@@ -139,7 +139,7 @@ class Convert:
return z
def convert_zarr_to_nifti(self, zarr_path, nifti_path, compression=False):
def convert_zarr_to_nifti(self, zarr_path: str, nifti_path: str, compression: bool = False):
"""Convert a zarr file to a nifti file
Args:
......
......@@ -76,7 +76,7 @@ class Downloader:
[file_name_n](load_file,optional): Function to download file number n in the given folder.
"""
def __init__(self, folder):
def __init__(self, folder: str):
files = _extract_names(folder)
for idx, file in enumerate(files):
......@@ -88,7 +88,7 @@ class Downloader:
setattr(self, f'{file_name.split(".")[0]}', self._make_fn(folder, file))
def _make_fn(self, folder, file):
def _make_fn(self, folder: str, file: str):
"""Private method that returns a function. The function downloads the chosen file from the folder.
Args:
......@@ -101,7 +101,7 @@ class Downloader:
url_dl = "https://archive.compute.dtu.dk/download/public/projects/viscomp_data_repository"
def _download(load_file=False, virtual_stack=True):
def _download(load_file: bool = False, virtual_stack: bool = True):
"""Downloads the file and optionally also loads it.
Args:
......@@ -121,7 +121,7 @@ class Downloader:
return _download
def _update_progress(pbar, blocknum, bs):
def _update_progress(pbar: tqdm, blocknum: int, bs: int):
"""
Helper function for the ´download_file()´ function. Updates the progress bar.
"""
......@@ -129,7 +129,7 @@ def _update_progress(pbar, blocknum, bs):
pbar.update(blocknum * bs - pbar.n)
def _get_file_size(url):
def _get_file_size(url: str):
"""
Helper function for the ´download_file()´ function. Finds the size of the file.
"""
......@@ -137,7 +137,7 @@ def _get_file_size(url):
return int(urllib.request.urlopen(url).info().get("Content-Length", -1))
def download_file(path, name, file):
def download_file(path: str, name: str, file: str):
"""Downloads the file from path / name / file.
Args:
......@@ -177,7 +177,7 @@ def download_file(path, name, file):
)
def _extract_html(url):
def _extract_html(url: str):
"""Extracts the html content of a webpage in "utf-8"
Args:
......@@ -198,7 +198,7 @@ def _extract_html(url):
return html_content
def _extract_names(name=None):
def _extract_names(name: str = None):
"""Extracts the names of the folders and files.
Finds the names of either the folders if no name is given,
......
......@@ -76,7 +76,7 @@ class DataLoader:
self.dim_order = kwargs.get("dim_order", (2, 1, 0))
self.PIL_extensions = (".jp2", ".jpg", "jpeg", ".png", "gif", ".bmp", ".webp")
def load_tiff(self, path):
def load_tiff(self, path: str):
"""Load a TIFF file from the specified path.
Args:
......@@ -100,7 +100,7 @@ class DataLoader:
return vol
def load_h5(self, path):
def load_h5(self, path: str):
"""Load an HDF5 file from the specified path.
Args:
......@@ -183,7 +183,7 @@ class DataLoader:
else:
return vol
def load_tiff_stack(self, path):
def load_tiff_stack(self, path: str):
"""Load a stack of TIFF files from the specified path.
Args:
......@@ -237,7 +237,7 @@ class DataLoader:
return vol
def load_txrm(self, path):
def load_txrm(self, path: str):
"""Load a TXRM/XRM/TXM file from the specified path.
Args:
......@@ -308,7 +308,7 @@ class DataLoader:
else:
return vol
def load_nifti(self, path):
def load_nifti(self, path: str):
"""Load a NIfTI file from the specified path.
Args:
......@@ -338,7 +338,7 @@ class DataLoader:
else:
return vol
def load_pil(self, path):
def load_pil(self, path: str):
"""Load a PIL image from the specified path
Args:
......@@ -349,7 +349,7 @@ class DataLoader:
"""
return np.array(Image.open(path))
def load_PIL_stack(self, path):
def load_PIL_stack(self, path: str):
"""Load a stack of PIL files from the specified path.
Args:
......@@ -433,7 +433,7 @@ class DataLoader:
def _load_vgi_metadata(self, path):
def _load_vgi_metadata(self, path: str):
"""Helper functions that loads metadata from a VGI file
Args:
......@@ -482,7 +482,7 @@ class DataLoader:
return meta_data
def load_vol(self, path):
def load_vol(self, path: str):
"""Load a VOL filed based on the VGI metadata file
Args:
......@@ -548,7 +548,7 @@ class DataLoader:
else:
return vol
def load_dicom(self, path):
def load_dicom(self, path: str):
"""Load a DICOM file
Args:
......@@ -563,7 +563,7 @@ class DataLoader:
else:
return dcm_data.pixel_array
def load_dicom_dir(self, path):
def load_dicom_dir(self, path: str):
"""Load a directory of DICOM files into a numpy 3d array
Args:
......@@ -654,7 +654,7 @@ class DataLoader:
message + " Set 'force_load=True' to ignore this error."
)
def load(self, path):
def load(self, path: str):
"""
Load a file or directory based on the given path.
......@@ -757,14 +757,14 @@ def _get_ole_offsets(ole):
def load(
path,
virtual_stack=False,
dataset_name=None,
return_metadata=False,
contains=None,
path: str,
virtual_stack: bool = False,
dataset_name: bool = None,
return_metadata: bool = False,
contains: bool = None,
progress_bar: bool = True,
force_load: bool = False,
dim_order=(2, 1, 0),
dim_order: tuple = (2, 1, 0),
**kwargs,
):
"""
......@@ -854,7 +854,7 @@ def load(
return data
def load_mesh(filename):
def load_mesh(filename: str):
"""
Load a mesh from an .obj file using trimesh.
......
......@@ -46,13 +46,13 @@ class OMEScaler(
"""Scaler in the style of OME-Zarr.
This is needed because their current zoom implementation is broken."""
def __init__(self, order=0, downscale=2, max_layer=5, method="scaleZYXdask"):
def __init__(self, order: int = 0, downscale: float = 2, max_layer: int = 5, method: str = "scaleZYXdask"):
self.order = order
self.downscale = downscale
self.max_layer = max_layer
self.method = method
def scaleZYX(self, base):
def scaleZYX(self, base: dask.array):
"""Downsample using :func:`scipy.ndimage.zoom`."""
rv = [base]
log.info(f"- Scale 0: {rv[-1].shape}")
......@@ -63,7 +63,7 @@ class OMEScaler(
return list(rv)
def scaleZYXdask(self, base):
def scaleZYXdask(self, base: dask.array):
"""
Downsample a 3D volume using Dask and scipy.ndimage.zoom.
......
......@@ -76,7 +76,7 @@ class DataSaver:
self.sliced_dim = kwargs.get("sliced_dim", 0)
self.chunk_shape = kwargs.get("chunk_shape", "auto")
def save_tiff(self, path, data):
def save_tiff(self, path: str, data: np.ndarray):
"""Save data to a TIFF file to the given path.
Args:
......@@ -85,7 +85,7 @@ class DataSaver:
"""
tifffile.imwrite(path, data, compression=self.compression)
def save_tiff_stack(self, path, data):
def save_tiff_stack(self, path: str, data: np.ndarray):
"""Save data as a TIFF stack containing slices in separate files to the given path.
The slices will be named according to the basename plus a suffix with a zero-filled
value corresponding to the slice number
......@@ -124,7 +124,7 @@ class DataSaver:
f"Total of {no_slices} files saved following the pattern '{pattern_string}'"
)
def save_nifti(self, path, data):
def save_nifti(self, path: str, data: np.ndarray):
"""Save data to a NIfTI file to the given path.
Args:
......@@ -154,7 +154,7 @@ class DataSaver:
# Save image
nib.save(img, path)
def save_vol(self, path, data):
def save_vol(self, path: str, data: np.ndarray):
"""Save data to a VOL file to the given path.
Args:
......@@ -200,7 +200,7 @@ class DataSaver:
"dataset", data=data, compression="gzip" if self.compression else None
)
def save_dicom(self, path, data):
def save_dicom(self, path: str, data: np.ndarray):
"""Save data to a DICOM file to the given path.
Args:
......@@ -255,7 +255,7 @@ class DataSaver:
ds.save_as(path)
def save_to_zarr(self, path, data):
def save_to_zarr(self, path: str, data: np.ndarray):
"""Saves a Dask array to a Zarr array on disk.
Args:
......@@ -284,7 +284,7 @@ class DataSaver:
)
zarr_array[:] = data
def save_PIL(self, path, data):
def save_PIL(self, path: str, data: np.ndarray):
"""Save data to a PIL file to the given path.
Args:
......@@ -303,7 +303,7 @@ class DataSaver:
# Save image
img.save(path)
def save(self, path, data):
def save(self, path: str, data: np.ndarray):
"""Save data to the given path.
Args:
......
......@@ -28,7 +28,7 @@ class Sync:
return False
def check_destination(self, source, destination, checksum=False, verbose=True):
def check_destination(self, source: str, destination: str, checksum: bool = False, verbose: bool = True):
"""Check if all files from 'source' are in 'destination'
This function compares the files in the 'source' directory to those in
......@@ -80,7 +80,7 @@ class Sync:
return diff_files
def compare_dirs(self, source, destination, checksum=False, verbose=True):
def compare_dirs(self, source: str, destination: str, checksum: bool = False, verbose: bool = True):
"""Checks whether 'source' and 'destination' directories are synchronized.
This function compares the contents of two directories
......@@ -168,7 +168,7 @@ class Sync:
)
return
def count_files_and_dirs(self, path, verbose=True):
def count_files_and_dirs(self, path: str, verbose: bool = True):
"""Count the number of files and directories in the given path.
This function recursively counts the number of files and
......
......@@ -8,8 +8,8 @@ from qim3d.utils._logger import log
def from_volume(
volume: np.ndarray,
level: float = None,
step_size=1,
allow_degenerate=False,
step_size: int = 1,
allow_degenerate: bool = False,
padding: Tuple[int, int, int] = (2, 2, 2),
**kwargs: Any,
) -> trimesh.Trimesh:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment