From 6d69358dbbdfd72c578ad8673d565300e38f9fda Mon Sep 17 00:00:00 2001 From: s214735 <s214735@dtu.dk> Date: Mon, 30 Dec 2024 10:09:51 +0100 Subject: [PATCH] griffe warning fixes --- qim3d/features/_common_features_methods.py | 18 +++--- qim3d/filters/_common_filter_methods.py | 55 +++++++++---------- qim3d/io/_loading.py | 6 +- qim3d/io/_ome_zarr.py | 5 +- qim3d/io/_saving.py | 14 ++--- qim3d/mesh/_common_mesh_methods.py | 3 +- .../operations/_common_operations_methods.py | 4 +- qim3d/processing/_layers.py | 2 +- qim3d/processing/_local_thickness.py | 2 +- qim3d/processing/_structure_tensor.py | 2 +- qim3d/viz/_cc.py | 2 +- qim3d/viz/_data_exploration.py | 12 ++-- qim3d/viz/_detection.py | 2 +- qim3d/viz/_k3d.py | 4 +- 14 files changed, 64 insertions(+), 67 deletions(-) diff --git a/qim3d/features/_common_features_methods.py b/qim3d/features/_common_features_methods.py index afac05f2..cceb3b3d 100644 --- a/qim3d/features/_common_features_methods.py +++ b/qim3d/features/_common_features_methods.py @@ -10,11 +10,11 @@ def volume(obj, **mesh_kwargs) -> float: Compute the volume of a 3D volume or mesh. Args: - obj: Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. - **mesh_kwargs: Additional arguments for mesh creation if the input is a volume. + obj (np.ndarray or trimesh.Trimesh): Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. + **mesh_kwargs (Any): Additional arguments for mesh creation if the input is a volume. Returns: - volume: The volume of the object. + volume (float): The volume of the object. Example: Compute volume from a mesh: @@ -54,11 +54,11 @@ def area(obj, **mesh_kwargs) -> float: Compute the surface area of a 3D volume or mesh. Args: - obj: Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. - **mesh_kwargs: Additional arguments for mesh creation if the input is a volume. + obj (np.ndarray or trimesh.Trimesh): Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. + **mesh_kwargs (Any): Additional arguments for mesh creation if the input is a volume. Returns: - area: The surface area of the object. + area (float): The surface area of the object. Example: Compute area from a mesh: @@ -101,11 +101,11 @@ def sphericity(obj, **mesh_kwargs) -> float: actual surface area. Args: - obj: Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. - **mesh_kwargs: Additional arguments for mesh creation if the input is a volume. + obj (np.ndarray or trimesh.Trimesh): Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. + **mesh_kwargs (Any): Additional arguments for mesh creation if the input is a volume. Returns: - sphericity: A float value representing the sphericity of the object. + sphericity (float): A float value representing the sphericity of the object. Example: Compute sphericity from a mesh: diff --git a/qim3d/filters/_common_filter_methods.py b/qim3d/filters/_common_filter_methods.py index 002b0d1b..cbd97ce4 100644 --- a/qim3d/filters/_common_filter_methods.py +++ b/qim3d/filters/_common_filter_methods.py @@ -215,14 +215,14 @@ def gaussian(vol, dask=False, chunks='auto', *args, **kwargs): Applies a Gaussian filter to the input volume using scipy.ndimage.gaussian_filter or dask_image.ndfilters.gaussian_filter. Args: - vol: The input image or volume. - dask: Whether to use Dask for the Gaussian filter. - chunks: Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. - *args: Additional positional arguments for the Gaussian filter. - **kwargs: Additional keyword arguments for the Gaussian filter. + vol (np.ndarray): The input image or volume. + dask (bool, optional): Whether to use Dask for the Gaussian filter. + chunks (int or tuple or "'auto'", optional): Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. + *args (Any): Additional positional arguments for the Gaussian filter. + **kwargs (Any): Additional keyword arguments for the Gaussian filter. Returns: - The filtered image or volume. + filtered_vol (np.ndarray): The filtered image or volume. """ if dask: @@ -241,13 +241,13 @@ def median(vol, dask=False, chunks='auto', **kwargs): Applies a median filter to the input volume using scipy.ndimage.median_filter or dask_image.ndfilters.median_filter. Args: - vol: The input image or volume. - dask: Whether to use Dask for the median filter. - chunks: Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. - **kwargs: Additional keyword arguments for the median filter. + vol (np.ndarray): The input image or volume. + dask (bool, optional): Whether to use Dask for the median filter. + chunks (int or tuple or "'auto'", optional): Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. + **kwargs (Any): Additional keyword arguments for the median filter. Returns: - The filtered image or volume. + filtered_vol (np.ndarray): The filtered image or volume. """ if dask: if not isinstance(vol, da.Array): @@ -265,13 +265,13 @@ def maximum(vol, dask=False, chunks='auto', **kwargs): Applies a maximum filter to the input volume using scipy.ndimage.maximum_filter or dask_image.ndfilters.maximum_filter. Args: - vol: The input image or volume. - dask: Whether to use Dask for the maximum filter. - chunks: Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. - **kwargs: Additional keyword arguments for the maximum filter. + vol (np.ndarray): The input image or volume. + dask (bool, optional): Whether to use Dask for the maximum filter. + chunks (int or tuple or "'auto'", optional): Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. + **kwargs (Any): Additional keyword arguments for the maximum filter. Returns: - The filtered image or volume. + filtered_vol (np.ndarray): The filtered image or volume. """ if dask: if not isinstance(vol, da.Array): @@ -289,13 +289,13 @@ def minimum(vol, dask=False, chunks='auto', **kwargs): Applies a minimum filter to the input volume using scipy.ndimage.minimum_filter or dask_image.ndfilters.minimum_filter. Args: - vol: The input image or volume. - dask: Whether to use Dask for the minimum filter. - chunks: Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. - **kwargs: Additional keyword arguments for the minimum filter. + vol (np.ndarray): The input image or volume. + dask (bool, optional): Whether to use Dask for the minimum filter. + chunks (int or tuple or "'auto'", optional): Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. + **kwargs (Any): Additional keyword arguments for the minimum filter. Returns: - The filtered image or volume. + filtered_vol (np.ndarray): The filtered image or volume. """ if dask: if not isinstance(vol, da.Array): @@ -312,15 +312,14 @@ def tophat(vol, dask=False, chunks='auto', **kwargs): Remove background from the volume. Args: - vol: The volume to remove background from. - radius: The radius of the structuring element (default: 3). - background: Color of the background, 'dark' or 'bright' (default: 'dark'). If 'bright', volume will be inverted. - dask: Whether to use Dask for the tophat filter (not supported, will default to SciPy). - chunks: Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. - **kwargs: Additional keyword arguments. + vol (np.ndarray): The volume to remove background from. + dask (bool, optional): Whether to use Dask for the tophat filter (not supported, will default to SciPy). + **kwargs (Any): Additional keyword arguments. + `radius` (float): The radius of the structuring element (default: 3). + `background` (str): Color of the background, 'dark' or 'bright' (default: 'dark'). If 'bright', volume will be inverted. Returns: - vol: The volume with background removed. + filtered_vol (np.ndarray): The volume with background removed. """ radius = kwargs["radius"] if "radius" in kwargs else 3 diff --git a/qim3d/io/_loading.py b/qim3d/io/_loading.py index 19641df3..3f32876d 100644 --- a/qim3d/io/_loading.py +++ b/qim3d/io/_loading.py @@ -797,7 +797,7 @@ def load( force_load (bool, optional): If the file size exceeds available memory, a MemoryError is raised. If force_load is True, the error is changed to warning and the loader tries to load it anyway. Default is False. dim_order (tuple, optional): The order of the dimensions in the volume for .vol files. Default is (2,1,0) which corresponds to (z,y,x) - **kwargs: Additional keyword arguments supported by `DataLoader`: + **kwargs (Any): Additional keyword arguments supported by `DataLoader`: - `virtual_stack` (bool) - `dataset_name` (str) - `return_metadata` (bool) @@ -868,10 +868,10 @@ def load_mesh(filename): Load a mesh from an .obj file using trimesh. Args: - filename: The path to the .obj file. + filename (str or os.PathLike): The path to the .obj file. Returns: - mesh: A trimesh object containing the mesh data (vertices and faces). + mesh (trimesh.Trimesh): A trimesh object containing the mesh data (vertices and faces). Example: ```python diff --git a/qim3d/io/_ome_zarr.py b/qim3d/io/_ome_zarr.py index ae517315..2a1174a0 100644 --- a/qim3d/io/_ome_zarr.py +++ b/qim3d/io/_ome_zarr.py @@ -222,7 +222,7 @@ def export_ome_zarr( ``` Returns: - None: This function writes the OME-Zarr data to the specified directory and does not return any value. + None (None): This function writes the OME-Zarr data to the specified directory and does not return any value. """ # Check if directory exists @@ -315,8 +315,7 @@ def import_ome_zarr(path, scale=0, load=True): If False, returns a lazy Dask array. Defaults to True. Returns: - np.ndarray or dask.array.Array: The requested image data, either as a NumPy array if `load=True`, - or a Dask array if `load=False`. + vol (np.ndarray or dask.array.Array): The requested image data, either as a NumPy array if `load=True`, or a Dask array if `load=False`. Raises: ValueError: If the requested `scale` does not exist in the data. diff --git a/qim3d/io/_saving.py b/qim3d/io/_saving.py index dc163572..ce21aa8a 100644 --- a/qim3d/io/_saving.py +++ b/qim3d/io/_saving.py @@ -424,14 +424,14 @@ def save( (only relevant for TIFF stacks). Default is None sliced_dim (int, optional): Specifies the dimension that is sliced in case a TIFF stack is saved as several files (only relevant for TIFF stacks). Default is 0, i.e., the first dimension. - **kwargs: Additional keyword arguments to be passed to the DataSaver constructor + **kwargs (Any): Additional keyword arguments to be passed to the DataSaver constructor Raises: ValueError: If the provided path is an existing directory and self.basename is not provided <strong>OR</strong> - If the file format is not supported <strong>OR</strong> - If the provided path does not exist and self.basename is not provided <strong>OR</strong> - If a file extension is not provided <strong>OR</strong> - if a file with the specified path already exists and replace=False. + If the file format is not supported <strong>OR</strong> + If the provided path does not exist and self.basename is not provided <strong>OR</strong> + If a file extension is not provided <strong>OR</strong> + if a file with the specified path already exists and replace=False. Example: ```python @@ -469,8 +469,8 @@ def save_mesh(filename, mesh): Save a trimesh object to an .obj file. Args: - filename: The name of the file to save the mesh. - mesh: A trimesh.Trimesh object representing the mesh. + filename (str): The name of the file to save the mesh. + mesh (trimesh.Trimesh): A trimesh.Trimesh object representing the mesh. Example: ```python diff --git a/qim3d/mesh/_common_mesh_methods.py b/qim3d/mesh/_common_mesh_methods.py index ce837ff2..d8cc0789 100644 --- a/qim3d/mesh/_common_mesh_methods.py +++ b/qim3d/mesh/_common_mesh_methods.py @@ -20,8 +20,7 @@ def from_volume( volume (np.ndarray): The 3D numpy array representing the volume. level (float, optional): The threshold value for Marching Cubes. If None, Otsu's method is used. step_size (int, optional): The step size for the Marching Cubes algorithm. - allow_degenerate (bool, optional): Whether to allow degenerate (i.e. zero-area) triangles in the end-result. - If False, degenerate triangles are removed, at the cost of making the algorithm slower. Default False. + allow_degenerate (bool, optional): Whether to allow degenerate (i.e. zero-area) triangles in the end-result. If False, degenerate triangles are removed, at the cost of making the algorithm slower. Default False. padding (tuple of int, optional): Padding to add around the volume. **kwargs: Additional keyword arguments to pass to `skimage.measure.marching_cubes`. diff --git a/qim3d/operations/_common_operations_methods.py b/qim3d/operations/_common_operations_methods.py index f266173e..449b2d53 100644 --- a/qim3d/operations/_common_operations_methods.py +++ b/qim3d/operations/_common_operations_methods.py @@ -19,7 +19,7 @@ def remove_background( median_filter_size (int, optional): The size of the median filter. Defaults to 2. min_object_radius (int, optional): The radius of the structuring element for the tophat filter. Defaults to 3. background (str, optional): The background type. Can be 'dark' or 'bright'. Defaults to 'dark'. - **median_kwargs: Additional keyword arguments for the Median filter. + **median_kwargs (Any): Additional keyword arguments for the Median filter. Returns: np.ndarray: The volume with background removed. @@ -73,7 +73,7 @@ def fade_mask( geometry (str, optional): The geometric shape of the fading. Can be 'spherical' or 'cylindrical'. Defaults to 'spherical'. invert (bool, optional): Flag for inverting the fading. Defaults to False. axis (int, optional): The axis along which to apply the fading. Defaults to 0. - **kwargs: Additional keyword arguments for the edge fading. + **kwargs (Any): Additional keyword arguments for the edge fading. Returns: vol_faded (np.ndarray): The volume with edge fading applied. diff --git a/qim3d/processing/_layers.py b/qim3d/processing/_layers.py index b62a6c46..5650ef18 100644 --- a/qim3d/processing/_layers.py +++ b/qim3d/processing/_layers.py @@ -18,7 +18,7 @@ def segment_layers(data:np.ndarray, inverted:bool = False, n_layers:int = 1, del wrap: If True, starting and ending point of the border between layers are at the same level Returns: - segmentations: list of numpy arrays, even if n_layers == 1, each array is only 0s and 1s, 1s segmenting this specific layer + segmentations (list[np.ndarray]): list of numpy arrays, even if n_layers == 1, each array is only 0s and 1s, 1s segmenting this specific layer Raises: TypeError: If Data is not np.array, if n_layers is not integer. diff --git a/qim3d/processing/_local_thickness.py b/qim3d/processing/_local_thickness.py index c4920dbf..9e1811aa 100644 --- a/qim3d/processing/_local_thickness.py +++ b/qim3d/processing/_local_thickness.py @@ -31,7 +31,7 @@ def local_thickness( mask (np.ndarray, optional): binary mask of the same size of the image defining parts of the image to be included in the computation of the local thickness. Default is None. visualize (bool, optional): Whether to visualize the local thickness. Default is False. - **viz_kwargs: Additional keyword arguments passed to `qim3d.viz.local_thickness`. Only used if `visualize=True`. + **viz_kwargs (Any): Additional keyword arguments passed to `qim3d.viz.local_thickness`. Only used if `visualize=True`. Returns: local_thickness (np.ndarray): 2D or 3D NumPy array representing the local thickness of the input image/volume. diff --git a/qim3d/processing/_structure_tensor.py b/qim3d/processing/_structure_tensor.py index 10eba890..1af53a8e 100644 --- a/qim3d/processing/_structure_tensor.py +++ b/qim3d/processing/_structure_tensor.py @@ -31,7 +31,7 @@ def structure_tensor( base_noise (bool, optional): A flag indicating whether to add a small noise to the volume. Default is True. full (bool, optional): A flag indicating that all three eigenvalues should be returned. Default is False. visualize (bool, optional): Whether to visualize the structure tensor. Default is False. - **viz_kwargs: Additional keyword arguments for passed to `qim3d.viz.vectors`. Only used if `visualize=True`. + **viz_kwargs (Any): Additional keyword arguments for passed to `qim3d.viz.vectors`. Only used if `visualize=True`. Raises: ValueError: If the input volume is not 3D. diff --git a/qim3d/viz/_cc.py b/qim3d/viz/_cc.py index 21a7e8b5..0bd03466 100644 --- a/qim3d/viz/_cc.py +++ b/qim3d/viz/_cc.py @@ -29,7 +29,7 @@ def plot_cc( color_map (str, optional): Specifies the color map for the image. Defaults to "viridis". value_min (float, optional): Together with vmax define the data range the colormap covers. By default colormap covers the full range. Defaults to None. value_max (float, optional): Together with vmin define the data range the colormap covers. By default colormap covers the full range. Defaults to None - **kwargs: Additional keyword arguments to pass to `qim3d.viz.slices_grid`. + **kwargs (Any): Additional keyword arguments to pass to `qim3d.viz.slices_grid`. Returns: figs (list[plt.Figure]): List of figures, if `display_figure=False`. diff --git a/qim3d/viz/_data_exploration.py b/qim3d/viz/_data_exploration.py index 3611c9a1..8a16b194 100644 --- a/qim3d/viz/_data_exploration.py +++ b/qim3d/viz/_data_exploration.py @@ -46,7 +46,7 @@ def slices_grid( If `slice_positions` is given as a list, `num_slices` will be ignored and the slices from `slice_positions` will be plotted. Args: - vol np.ndarray: The 3D volume to be sliced. + volume (np.ndarray): The 3D volume to be sliced. slice_axis (int, optional): Specifies the axis, or dimension, along which to slice. Defaults to 0. slice_positions (str, int, list, optional): One or several slicing levels. If None, linearly spaced slices will be displayed. Defaults to None. num_slices (int, optional): Defines how many slices the user wants to be displayed. Defaults to 15. @@ -605,7 +605,7 @@ def chunks(zarr_path: str, **kwargs): Args: zarr_path (str): Path to the Zarr dataset. - **kwargs: Additional keyword arguments to pass to the visualization method. + **kwargs (Any): Additional keyword arguments to pass to the visualization method. Example: ```python @@ -872,9 +872,9 @@ def histogram( Args: volume (np.ndarray): A 3D NumPy array representing the volume to be visualized. - bins (Union[int, str], optional): Number of histogram bins or a binning strategy (e.g., "auto"). Default is "auto". + bins (int or str, optional): Number of histogram bins or a binning strategy (e.g., "auto"). Default is "auto". axis (int, optional): Axis along which to take a slice. Default is 0. - slice_idx (Union[int, str], optional): Specifies the slice to visualize. If an integer, it represents the slice index along the selected axis. + slice_idx (int or str, optional): Specifies the slice to visualize. If an integer, it represents the slice index along the selected axis. If "middle", the function uses the middle slice. If None, the entire volume is visualized. Default is None. kde (bool, optional): Whether to overlay a kernel density estimate. Default is True. log_scale (bool, optional): Whether to use a logarithmic scale on the y-axis. Default is False. @@ -886,10 +886,10 @@ def histogram( element (str, optional): Type of histogram to draw ('bars', 'step', or 'poly'). Default is "step". return_fig (bool, optional): If True, returns the figure object instead of showing it directly. Default is False. show (bool, optional): If True, displays the plot. If False, suppresses display. Default is True. - **sns_kwargs: Additional keyword arguments for `seaborn.histplot`. + **sns_kwargs (Any): Additional keyword arguments for `seaborn.histplot`. Returns: - Optional[matplotlib.figure.Figure]: If `return_fig` is True, returns the generated figure object. Otherwise, returns None. + fig (Optional[matplotlib.figure.Figure]): If `return_fig` is True, returns the generated figure object. Otherwise, returns None. Raises: ValueError: If `axis` is not a valid axis index (0, 1, or 2). diff --git a/qim3d/viz/_detection.py b/qim3d/viz/_detection.py index 43843fb5..fa34eef1 100644 --- a/qim3d/viz/_detection.py +++ b/qim3d/viz/_detection.py @@ -20,7 +20,7 @@ def circles(blobs, vol, alpha=0.5, color="#ff9900", **kwargs): vol (array-like): The 3D volume on which to plot the blobs. alpha (float, optional): The transparency of the blobs. Defaults to 0.5. color (str, optional): The color of the blobs. Defaults to "#ff9900". - **kwargs: Arbitrary keyword arguments for the `slices` function. + **kwargs (Any): Arbitrary keyword arguments for the `slices` function. Returns: slicer_obj (ipywidgets.interactive): An interactive widget for visualizing the blobs. diff --git a/qim3d/viz/_k3d.py b/qim3d/viz/_k3d.py index d2945b2f..382c220e 100644 --- a/qim3d/viz/_k3d.py +++ b/qim3d/viz/_k3d.py @@ -50,7 +50,7 @@ def volumetric( Lower values will render faster but with lower quality. max_voxels (int, optional): Defaults to 512^3. data_type (str, optional): Default to 'scaled_float16'. - **kwargs: Additional keyword arguments to be passed to the `k3d.plot` function. + **kwargs (Any): Additional keyword arguments to be passed to the `k3d.plot` function. Returns: plot (k3d.plot): If `show=False`, returns the K3D plot object. @@ -196,7 +196,7 @@ def mesh( save (bool or str, optional): If True, saves the visualization as an HTML file. If a string is provided, it's interpreted as the file path where the HTML file will be saved. Defaults to False. - **kwargs: Additional keyword arguments to be passed to the `k3d.plot` function. + **kwargs (Any): Additional keyword arguments to be passed to the `k3d.plot` function. Returns: plot (k3d.plot): If `show=False`, returns the K3D plot object. -- GitLab