Skip to content

Commit

Permalink
Merge branch 'main' into fix_patching
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeschamps authored May 6, 2024
2 parents 8da04db + 105a45c commit 9d25c23
Show file tree
Hide file tree
Showing 46 changed files with 82 additions and 50 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ ci:

repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.14
rev: v0.16
hooks:
- id: validate-pyproject

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.4.3
hooks:
- id: ruff
args: [--fix, --target-version, py38]

- repo: https://github.com/psf/black
rev: 23.9.1
rev: 24.4.2
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.10.0
hooks:
- id: mypy
files: "^src/"
Expand All @@ -36,13 +36,13 @@ repos:

# check docstrings
- repo: https://github.com/numpy/numpydoc
rev: v1.6.0
rev: v1.7.0
hooks:
- id: numpydoc-validation

# jupyter linting and formatting
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
rev: 1.8.5
hooks:
- id: nbqa-ruff
args: [--fix]
Expand All @@ -51,6 +51,6 @@ repos:

# strip out jupyter notebooks
- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
rev: 0.7.1
hooks:
- id: nbstripout
15 changes: 5 additions & 10 deletions src/careamics/careamist.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ def __init__( # numpydoc ignore=GL08
source: Union[Path, str],
work_dir: Optional[str] = None,
experiment_name: str = "CAREamics",
) -> None:
...
) -> None: ...

@overload
def __init__( # numpydoc ignore=GL08
self,
source: Configuration,
work_dir: Optional[str] = None,
experiment_name: str = "CAREamics",
) -> None:
...
) -> None: ...

def __init__(
self,
Expand Down Expand Up @@ -478,8 +476,7 @@ def predict( # numpydoc ignore=GL08
source: CAREamicsPredictData,
*,
checkpoint: Optional[Literal["best", "last"]] = None,
) -> Union[list, np.ndarray]:
...
) -> Union[list, np.ndarray]: ...

@overload
def predict( # numpydoc ignore=GL08
Expand All @@ -497,8 +494,7 @@ def predict( # numpydoc ignore=GL08
read_source_func: Optional[Callable] = None,
extension_filter: str = "",
checkpoint: Optional[Literal["best", "last"]] = None,
) -> Union[list, np.ndarray]:
...
) -> Union[list, np.ndarray]: ...

@overload
def predict( # numpydoc ignore=GL08
Expand All @@ -514,8 +510,7 @@ def predict( # numpydoc ignore=GL08
tta_transforms: bool = True,
dataloader_params: Optional[Dict] = None,
checkpoint: Optional[Literal["best", "last"]] = None,
) -> Union[list, np.ndarray]:
...
) -> Union[list, np.ndarray]: ...

def predict(
self,
Expand Down
1 change: 0 additions & 1 deletion src/careamics/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Configuration module."""


__all__ = [
"AlgorithmConfig",
"DataConfig",
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/callback_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Checkpoint saving configuration."""

from __future__ import annotations

from datetime import timedelta
Expand Down
8 changes: 5 additions & 3 deletions src/careamics/config/configuration_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,11 @@ def create_n2v_configuration(
# n2v2 and structn2v
nv2_transform = {
"name": SupportedTransform.N2V_MANIPULATE.value,
"strategy": SupportedPixelManipulation.MEDIAN.value
if use_n2v2
else SupportedPixelManipulation.UNIFORM.value,
"strategy": (
SupportedPixelManipulation.MEDIAN.value
if use_n2v2
else SupportedPixelManipulation.UNIFORM.value
),
"roi_size": roi_size,
"masked_pixel_percentage": masked_pixel_percentage,
"struct_mask_axis": struct_n2v_axis,
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/configuration_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pydantic CAREamics configuration."""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/data_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data configuration."""

from __future__ import annotations

from pprint import pformat
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/inference_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pydantic model representing CAREamics prediction configuration."""

from __future__ import annotations

from typing import Any, List, Literal, Optional, Union
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/references/algorithm_descriptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Descriptions of the algorithms used in CAREmics."""

from pydantic import BaseModel

CUSTOM = "Custom"
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/references/references.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""References for the CAREamics algorithms."""

from bioimageio.spec.generic.v0_3 import CiteEntry

N2VRef = CiteEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module defines the various extraction strategies available in CAREamics.
"""

from careamics.utils import BaseEnum


Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/training_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Training configuration."""

from __future__ import annotations

from pprint import pformat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pydantic model for the N2VManipulate transform."""

from typing import Literal

from pydantic import ConfigDict, Field, field_validator
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/transformations/nd_flip_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pydantic model for the NDFlip transform."""

from typing import Literal

from pydantic import ConfigDict, Field
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/transformations/normalize_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pydantic model for the Normalize transform."""

from typing import Literal

from pydantic import ConfigDict, Field
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/transformations/transform_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Parent model for the transforms."""

from typing import Any, Dict

from pydantic import BaseModel, ConfigDict
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pydantic model for the XYRandomRotate90 transform."""

from typing import Literal

from pydantic import ConfigDict, Field
Expand Down
1 change: 1 addition & 0 deletions src/careamics/config/validators/validator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
These functions are used to validate dimensions and axes of inputs.
"""

from typing import List, Optional, Tuple, Union

_AXES = "STCZYX"
Expand Down
1 change: 1 addition & 0 deletions src/careamics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
See https://sybil.readthedocs.io/en/latest/use.html#pytest
"""

from pathlib import Path

import pytest
Expand Down
1 change: 0 additions & 1 deletion src/careamics/dataset/dataset_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Files and arrays utils used in the datasets."""


__all__ = [
"reshape_array",
"get_files_size",
Expand Down
1 change: 1 addition & 0 deletions src/careamics/dataset/dataset_utils/dataset_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Convenience methods for datasets."""

from typing import List, Tuple

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions src/careamics/dataset/in_memory_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""In-memory dataset module."""

from __future__ import annotations

import copy
Expand Down
1 change: 0 additions & 1 deletion src/careamics/dataset/patching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Patching and tiling functions."""


__all__ = [
"get_patch_transform",
]
Expand Down
8 changes: 5 additions & 3 deletions src/careamics/dataset/patching/patch_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def get_patch_transform(
return Aug.Compose(
transforms,
# apply image aug to "target"
additional_targets={"target": "image"}
if (with_target and normalize_mask) # TODO check this
else {},
additional_targets=(
{"target": "image"}
if (with_target and normalize_mask) # TODO check this
else {}
),
)
1 change: 1 addition & 0 deletions src/careamics/dataset/patching/patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
These functions are used to tile images into patches or tiles.
"""

from pathlib import Path
from typing import Callable, List, Tuple, Union

Expand Down
16 changes: 10 additions & 6 deletions src/careamics/dataset/patching/tiled_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@ def _compute_crop_and_stitch_coords_1d(
stitch_coords.append(
(
i + overlap // 2 if i > 0 else 0,
i + tile_size - overlap // 2
if crop_coords[-1][1] < axis_size
else axis_size,
(
i + tile_size - overlap // 2
if crop_coords[-1][1] < axis_size
else axis_size
),
)
)

# Add the coordinates to crop the overlap from the prediction.
overlap_crop_coords.append(
(
overlap // 2 if i > 0 else 0,
tile_size - overlap // 2
if crop_coords[-1][1] < axis_size
else tile_size,
(
tile_size - overlap // 2
if crop_coords[-1][1] < axis_size
else tile_size
),
)
)

Expand Down
25 changes: 13 additions & 12 deletions src/careamics/lightning_datamodule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Training and validation Lightning data modules."""

from pathlib import Path
from typing import Any, Callable, Dict, List, Literal, Optional, Union

Expand Down Expand Up @@ -341,9 +342,9 @@ def setup(self, *args: Any, **kwargs: Any) -> None:
self.train_dataset = InMemoryDataset(
data_config=self.data_config,
inputs=self.train_files,
data_target=self.train_target_files
if self.train_data_target
else None,
data_target=(
self.train_target_files if self.train_data_target else None
),
read_source_func=self.read_source_func,
)

Expand All @@ -352,9 +353,9 @@ def setup(self, *args: Any, **kwargs: Any) -> None:
self.val_dataset = InMemoryDataset(
data_config=self.data_config,
inputs=self.val_files,
data_target=self.val_target_files
if self.val_data_target
else None,
data_target=(
self.val_target_files if self.val_data_target else None
),
read_source_func=self.read_source_func,
)
else:
Expand All @@ -370,9 +371,9 @@ def setup(self, *args: Any, **kwargs: Any) -> None:
self.train_dataset = PathIterableDataset(
data_config=self.data_config,
src_files=self.train_files,
target_files=self.train_target_files
if self.train_data_target
else None,
target_files=(
self.train_target_files if self.train_data_target else None
),
read_source_func=self.read_source_func,
)

Expand All @@ -382,9 +383,9 @@ def setup(self, *args: Any, **kwargs: Any) -> None:
self.val_dataset = PathIterableDataset(
data_config=self.data_config,
src_files=self.val_files,
target_files=self.val_target_files
if self.val_data_target
else None,
target_files=(
self.val_target_files if self.val_data_target else None
),
read_source_func=self.read_source_func,
)
elif len(self.train_files) <= self.val_minimum_split:
Expand Down
1 change: 1 addition & 0 deletions src/careamics/lightning_prediction_datamodule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Prediction Lightning data modules."""

from pathlib import Path
from typing import Any, Callable, List, Literal, Optional, Tuple, Union

Expand Down
1 change: 0 additions & 1 deletion src/careamics/losses/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Losses module."""


from .loss_factory import loss_factory

# from .noise_model_factory import noise_model_factory as noise_model_factory
Expand Down
1 change: 1 addition & 0 deletions src/careamics/losses/loss_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module contains a factory function for creating loss functions.
"""

from typing import Callable, Union

from ..config.support import SupportedLoss
Expand Down
1 change: 0 additions & 1 deletion src/careamics/model_io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Model I/O utilities."""


__all__ = ["load_pretrained", "export_to_bmz"]


Expand Down
1 change: 1 addition & 0 deletions src/careamics/model_io/bioimage/_readme_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions used to create a README.md file for BMZ export."""

from pathlib import Path
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions src/careamics/model_io/bioimage/bioimage_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bioimage.io utils."""

from pathlib import Path
from typing import Union

Expand Down
Loading

0 comments on commit 9d25c23

Please sign in to comment.