Skip to content

Commit

Permalink
fix: Fix ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeschamps committed Dec 17, 2024
1 parent 1034707 commit 57be075
Show file tree
Hide file tree
Showing 42 changed files with 229 additions and 226 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ checks = [
"GL02", # Closing quotes should be placed in the line after the last text
# in the docstring
"GL03", # Double line break found
"RT04", # Return value description should start with a capital letter
]
exclude = [ # don't report on objects that match any of these regex
"test_*",
Expand Down
3 changes: 1 addition & 2 deletions src/careamics/cli/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import Optional
from typing import Annotated, Optional

import click
import typer
import yaml
from typing_extensions import Annotated

from ..config import (
Configuration,
Expand Down
3 changes: 1 addition & 2 deletions src/careamics/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
"""

from pathlib import Path
from typing import Optional
from typing import Annotated, Optional

import click
import typer
from typing_extensions import Annotated

from ..careamist import CAREamist
from . import conf
Expand Down
6 changes: 3 additions & 3 deletions src/careamics/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Utility functions for the CAREamics CLI."""

from typing import Optional, Tuple
from typing import Optional


def handle_2D_3D_callback(
value: Optional[Tuple[int, int, int]]
) -> Optional[Tuple[int, ...]]:
value: Optional[tuple[int, int, int]]
) -> Optional[tuple[int, ...]]:
"""
Callback for options that require 2D or 3D inputs.
Expand Down
6 changes: 3 additions & 3 deletions src/careamics/config/architectures/architecture_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Base model for the various CAREamics architectures."""

from typing import Any, Dict
from typing import Any

from pydantic import BaseModel

Expand All @@ -15,7 +15,7 @@ class ArchitectureModel(BaseModel):
architecture: str
"""Name of the architecture."""

def model_dump(self, **kwargs: Any) -> Dict[str, Any]:
def model_dump(self, **kwargs: Any) -> dict[str, Any]:
"""
Dump the model as a dictionary, ignoring the architecture keyword.
Expand All @@ -26,7 +26,7 @@ def model_dump(self, **kwargs: Any) -> Dict[str, Any]:
Returns
-------
dict[str, Any]
{str: Any}
Model as a dictionary.
"""
model_dict = super().model_dump(**kwargs)
Expand Down
4 changes: 2 additions & 2 deletions src/careamics/config/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from pprint import pformat
from typing import Any, Literal, Optional, Union
from typing import Annotated, Any, Literal, Optional, Union

import numpy as np
from numpy.typing import NDArray
Expand All @@ -15,7 +15,7 @@
field_validator,
model_validator,
)
from typing_extensions import Annotated, Self
from typing_extensions import Self

from .support import SupportedTransform
from .transformations import TRANSFORMS_UNION, N2VManipulateModel
Expand Down
3 changes: 1 addition & 2 deletions src/careamics/config/likelihood_model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Likelihood model."""

from typing import Literal, Optional, Union
from typing import Annotated, Literal, Optional, Union

import numpy as np
import torch
from pydantic import BaseModel, ConfigDict, PlainSerializer, PlainValidator
from typing_extensions import Annotated

from careamics.models.lvae.noise_models import (
GaussianMixtureNoiseModel,
Expand Down
3 changes: 1 addition & 2 deletions src/careamics/config/nm_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Noise models config."""

from pathlib import Path
from typing import Literal, Optional, Union
from typing import Annotated, Literal, Optional, Union

import numpy as np
import torch
Expand All @@ -12,7 +12,6 @@
PlainSerializer,
PlainValidator,
)
from typing_extensions import Annotated

from careamics.utils.serializers import _array_to_json, _to_numpy

Expand Down
6 changes: 3 additions & 3 deletions src/careamics/config/transformations/transform_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Parent model for the transforms."""

from typing import Any, Dict
from typing import Any

from pydantic import BaseModel, ConfigDict

Expand All @@ -23,7 +23,7 @@ class TransformModel(BaseModel):

name: str

def model_dump(self, **kwargs) -> Dict[str, Any]:
def model_dump(self, **kwargs) -> dict[str, Any]:
"""
Return the model as a dictionary.
Expand All @@ -34,7 +34,7 @@ def model_dump(self, **kwargs) -> Dict[str, Any]:
Returns
-------
Dict[str, Any]
{str: Any}
Dictionary representation of the model.
"""
model_dict = super().model_dump(**kwargs)
Expand Down
3 changes: 1 addition & 2 deletions src/careamics/config/transformations/transform_union.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Type used to represent all transformations users can create."""

from typing import Union
from typing import Annotated, Union

from pydantic import Discriminator
from typing_extensions import Annotated

from .n2v_manipulate_model import N2VManipulateModel
from .xy_flip_model import XYFlipModel
Expand Down
6 changes: 3 additions & 3 deletions src/careamics/config/validators/validator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
These functions are used to validate dimensions and axes of inputs.
"""

from typing import List, Optional, Tuple, Union
from typing import Optional, Union

_AXES = "STCZYX"

Expand Down Expand Up @@ -79,14 +79,14 @@ def value_ge_than_8_power_of_2(


def patch_size_ge_than_8_power_of_2(
patch_list: Optional[Union[List[int], Union[Tuple[int, ...]]]],
patch_list: Optional[Union[list[int], Union[tuple[int, ...]]]],
) -> None:
"""
Validate that each entry is greater or equal than 8 and a power of 2.
Parameters
----------
patch_list : Optional[Union[List[int]]]
patch_list : list or typle of int, or None
Patch size.
Raises
Expand Down
10 changes: 4 additions & 6 deletions src/careamics/dataset/dataset_utils/dataset_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Dataset utilities."""

from typing import List, Tuple

import numpy as np

from careamics.utils.logging import get_logger
Expand All @@ -10,14 +8,14 @@


def _get_shape_order(
shape_in: Tuple[int, ...], axes_in: str, ref_axes: str = "STCZYX"
) -> Tuple[Tuple[int, ...], str, List[int]]:
shape_in: tuple[int, ...], axes_in: str, ref_axes: str = "STCZYX"
) -> tuple[tuple[int, ...], str, list[int]]:
"""
Compute a new shape for the array based on the reference axes.
Parameters
----------
shape_in : Tuple[int, ...]
shape_in : tuple[int, ...]
Input shape.
axes_in : str
Input axes.
Expand All @@ -26,7 +24,7 @@ def _get_shape_order(
Returns
-------
Tuple[Tuple[int, ...], str, List[int]]
tuple[tuple[int, ...], str, list[int]]
New shape, new axes, indices of axes in the new axes order.
"""
indices = [axes_in.find(k) for k in ref_axes]
Expand Down
18 changes: 9 additions & 9 deletions src/careamics/dataset/dataset_utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fnmatch import fnmatch
from pathlib import Path
from typing import List, Union
from typing import Union

import numpy as np

Expand All @@ -12,12 +12,12 @@
logger = get_logger(__name__)


def get_files_size(files: List[Path]) -> float:
def get_files_size(files: list[Path]) -> float:
"""Get files size in MB.
Parameters
----------
files : List[Path]
files : list of pathlib.Path
List of files.
Returns
Expand All @@ -32,7 +32,7 @@ def list_files(
data_path: Union[str, Path],
data_type: Union[str, SupportedData],
extension_filter: str = "",
) -> List[Path]:
) -> list[Path]:
"""List recursively files in `data_path` and return a sorted list.
If `data_path` is a file, its name is validated against the `data_type` using
Expand All @@ -55,8 +55,8 @@ def list_files(
Returns
-------
List[Path]
List of pathlib.Path objects.
list[Path]
list of pathlib.Path objects.
Raises
------
Expand Down Expand Up @@ -105,17 +105,17 @@ def list_files(
return files


def validate_source_target_files(src_files: List[Path], tar_files: List[Path]) -> None:
def validate_source_target_files(src_files: list[Path], tar_files: list[Path]) -> None:
"""
Validate source and target path lists.
The two lists should have the same number of files, and the filenames should match.
Parameters
----------
src_files : List[Path]
src_files : list of pathlib.Path
List of source files.
tar_files : List[Path]
tar_files : list of pathlib.Path
List of target files.
Raises
Expand Down
3 changes: 2 additions & 1 deletion src/careamics/dataset/dataset_utils/iterate_over_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Generator
from pathlib import Path
from typing import Callable, Generator, Optional, Union
from typing import Callable, Optional, Union

from numpy.typing import NDArray
from torch.utils.data import get_worker_info
Expand Down
3 changes: 2 additions & 1 deletion src/careamics/dataset/iterable_pred_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Generator
from pathlib import Path
from typing import Any, Callable, Generator
from typing import Any, Callable

from numpy.typing import NDArray
from torch.utils.data import IterableDataset
Expand Down
3 changes: 2 additions & 1 deletion src/careamics/dataset/iterable_tiled_pred_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Generator
from pathlib import Path
from typing import Any, Callable, Generator
from typing import Any, Callable

from numpy.typing import NDArray
from torch.utils.data import IterableDataset
Expand Down
21 changes: 11 additions & 10 deletions src/careamics/dataset/patching/random_patching.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Random patching utilities."""

from typing import Generator, List, Optional, Tuple, Union
from collections.abc import Generator
from typing import Optional, Union

import numpy as np
import zarr
Expand All @@ -11,10 +12,10 @@
# TOOD split in testable functions
def extract_patches_random(
arr: np.ndarray,
patch_size: Union[List[int], Tuple[int, ...]],
patch_size: Union[list[int], tuple[int, ...]],
target: Optional[np.ndarray] = None,
seed: Optional[int] = None,
) -> Generator[Tuple[np.ndarray, Optional[np.ndarray]], None, None]:
) -> Generator[tuple[np.ndarray, Optional[np.ndarray]], None, None]:
"""
Generate patches from an array in a random manner.
Expand All @@ -31,12 +32,12 @@ def extract_patches_random(
----------
arr : np.ndarray
Input image array.
patch_size : Tuple[int]
patch_size : tuple of int
Patch sizes in each dimension.
target : Optional[np.ndarray], optional
Target array, by default None.
seed : Optional[int], optional
Random seed, by default None.
seed : int or None, default=None
Random seed.
Yields
------
Expand Down Expand Up @@ -112,8 +113,8 @@ def extract_patches_random(

def extract_patches_random_from_chunks(
arr: zarr.Array,
patch_size: Union[List[int], Tuple[int, ...]],
chunk_size: Union[List[int], Tuple[int, ...]],
patch_size: Union[list[int], tuple[int, ...]],
chunk_size: Union[list[int], tuple[int, ...]],
chunk_limit: Optional[int] = None,
seed: Optional[int] = None,
) -> Generator[np.ndarray, None, None]:
Expand All @@ -127,9 +128,9 @@ def extract_patches_random_from_chunks(
----------
arr : np.ndarray
Input image array.
patch_size : Union[List[int], Tuple[int, ...]]
patch_size : Union[list[int], tuple[int, ...]]
Patch sizes in each dimension.
chunk_size : Union[List[int], Tuple[int, ...]]
chunk_size : Union[list[int], tuple[int, ...]]
Chunk sizes to load from the.
chunk_limit : Optional[int], optional
Number of chunks to load, by default None.
Expand Down
Loading

0 comments on commit 57be075

Please sign in to comment.