diff --git a/qim3d/io/_convert.py b/qim3d/io/_convert.py index 4ab6c0a99e71eff51949309359dd42c1276f96dd..9244ef88e8aa73e19ad98c237d37299e85460b0c 100644 --- a/qim3d/io/_convert.py +++ b/qim3d/io/_convert.py @@ -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: diff --git a/qim3d/io/_downloader.py b/qim3d/io/_downloader.py index fe42e410c120b5ab6efe77037d1071579add55de..18e36ca591ad2bf0859cc2b05f18d0033de3f8ee 100644 --- a/qim3d/io/_downloader.py +++ b/qim3d/io/_downloader.py @@ -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, diff --git a/qim3d/io/_loading.py b/qim3d/io/_loading.py index e5f2191e8f71fd276e9b9460d6dabf4c6e8d4995..b558c3f4eabf7a64f819b26abb9c073eb709cda6 100644 --- a/qim3d/io/_loading.py +++ b/qim3d/io/_loading.py @@ -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, - progress_bar:bool = True, + 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. diff --git a/qim3d/io/_ome_zarr.py b/qim3d/io/_ome_zarr.py index 46b6801c697205bf02846775161fd7e5d9ee1c0e..36ec5b800f5bad7e91dc679cec6a86e97a6456f0 100644 --- a/qim3d/io/_ome_zarr.py +++ b/qim3d/io/_ome_zarr.py @@ -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. diff --git a/qim3d/io/_saving.py b/qim3d/io/_saving.py index efe7f2ced024ac5150f27071ea1be1bdeede0dad..378a8b60afb180f366db1c4a423afebe54a5c661 100644 --- a/qim3d/io/_saving.py +++ b/qim3d/io/_saving.py @@ -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: diff --git a/qim3d/io/_sync.py b/qim3d/io/_sync.py index 9085ae88b3a4e60b6ce2a0744c8983c825b635a3..5cc4b5e566490f3efa586356f7e21d0a1c920c57 100644 --- a/qim3d/io/_sync.py +++ b/qim3d/io/_sync.py @@ -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 diff --git a/qim3d/mesh/_common_mesh_methods.py b/qim3d/mesh/_common_mesh_methods.py index 535fcae886ce081c20c5bb01628341beba5163c3..87cb9d8bfc792ca939d2e0afab00eff4510c2a91 100644 --- a/qim3d/mesh/_common_mesh_methods.py +++ b/qim3d/mesh/_common_mesh_methods.py @@ -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: