Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,34 @@ packages = ["viscy"]
write_to = "viscy/_version.py"

[tool.ruff]
src = ["viscy", "tests"]
line-length = 88
lint.extend-select = ["I001"]
lint.isort.known-first-party = ["viscy"]
src = ["viscy", "tests"]
extend-include = ["*.ipynb"]
target-version = "py311"
# Exclude the following for now. Later on we should check every Python file.
extend-exclude = ["viscy/scripts/*", "applications/*", "examples/*"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
docstring-code-format = true
docstring-code-line-length = "dynamic"

[tool.ruff.lint]
select = [
"D", # pydocstyle
"I", # isort
]
ignore = [
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"D105", # __magic__ methods are often self-explanatory, allow missing docstrings
"D107", # Missing docstring in __init__
# Disable one in each pair of mutually incompatible rules
"D203", # We don’t want a blank line before a class docstring
"D213", # <> We want docstrings to start immediately after the opening triple quote
"D400", # first line should end with a period [Bug: doesn’t work with single-line docstrings]
"D401", # First line should be in imperative mood; try rephrasing
]
per-file-ignores."tests/*" = ["D"]
pydocstyle.convention = "numpy"
1 change: 0 additions & 1 deletion tests/data/test_hcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from iohub import open_ome_zarr
from monai.transforms import RandSpatialCropSamplesd
from pytest import mark

from viscy.data.hcs import HCSDataModule
from viscy.trainer import VisCyTrainer

Expand Down
1 change: 0 additions & 1 deletion tests/data/test_select.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from iohub.ngff import open_ome_zarr

from viscy.data.select import SelectWell


Expand Down
1 change: 0 additions & 1 deletion tests/data/test_triplet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pandas as pd
from iohub import open_ome_zarr
from pytest import mark

from viscy.data.triplet import TripletDataModule


Expand Down
1 change: 0 additions & 1 deletion tests/evaluation/test_cell_feature_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pandas as pd
import pytest
from skimage import measure

from viscy.representation.evaluation.feature import CellFeatures, DynamicFeatures


Expand Down
1 change: 0 additions & 1 deletion tests/evaluation/test_evaluation_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import torch
from skimage import data, measure
from skimage.util import img_as_float

from viscy.translation.evaluation_metrics import (
POD_metric,
VOI_metric,
Expand Down
3 changes: 1 addition & 2 deletions tests/preprocessing/generate_masks_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pandas as pd
import skimage.io as sk_im_io
from testfixtures import TempDirectory

from viscy.preprocessing.generate_masks import MaskProcessor
from viscy.utils import aux_utils as aux_utils

Expand Down Expand Up @@ -129,7 +128,7 @@ def test_generate_masks_uni(self):
nose.tools.assert_equal(len(frames_meta), exp_len)
for idx in range(exp_len):
nose.tools.assert_equal(
"im_c003_z00{}_t000_p001.npy".format(idx),
f"im_c003_z00{idx}_t000_p001.npy",
frames_meta.iloc[idx]["file_name"],
)

Expand Down
7 changes: 3 additions & 4 deletions tests/preprocessing/resize_images_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import cv2
import numpy as np
import pandas as pd
from testfixtures import TempDirectory

import viscy.preprocessing.resize_images as resize_images
import viscy.utils.aux_utils as aux_utils
from testfixtures import TempDirectory


class TestResizeImages(unittest.TestCase):
Expand Down Expand Up @@ -133,7 +132,7 @@ def test_resize_volumes(self):
),
ignore_index=True,
)
op_fname = "im_c00{}_z000_t005_p007_3.3-0.8-1.0.npy".format(c)
op_fname = "im_c00{c}_z000_t005_p007_3.3-0.8-1.0.npy".format(c)
exp_meta_dict.append(
{
"time_idx": self.time_idx,
Expand Down Expand Up @@ -169,7 +168,7 @@ def test_resize_volumes(self):
exp_meta_dict = []
for c in channel_ids:
for s in [0, 2]:
op_fname = "im_c00{}_z00{}_t005_p007_3.3-0.8-1.0.npy".format(c, s)
op_fname = "im_c00{c}_z00{s}_t005_p007_3.3-0.8-1.0.npy".format(c, s)
exp_meta_dict.append(
{
"time_idx": self.time_idx,
Expand Down
1 change: 0 additions & 1 deletion tests/preprocessing/test_pixel_ratio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from numpy.testing import assert_allclose

from viscy.preprocessing.pixel_ratio import sematic_class_weights


Expand Down
1 change: 0 additions & 1 deletion tests/representation/test_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pandas as pd
import pytest
from iohub import open_ome_zarr

from viscy.representation.evaluation.feature import (
CellFeatures,
DynamicFeatures,
Expand Down
1 change: 0 additions & 1 deletion tests/representation/test_lca.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import torch
from sklearn.linear_model import LogisticRegression

from viscy.representation.evaluation.lca import linear_from_binary_logistic_regression


Expand Down
1 change: 0 additions & 1 deletion tests/transforms/test_adjust_contrast.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import torch
from monai.transforms import AdjustContrast, Compose

from viscy.transforms import BatchedRandAdjustContrast, BatchedRandAdjustContrastd


Expand Down
1 change: 0 additions & 1 deletion tests/transforms/test_crop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import torch
from monai.transforms import Compose

from viscy.transforms._crop import (
BatchedCenterSpatialCrop,
BatchedCenterSpatialCropd,
Expand Down
1 change: 0 additions & 1 deletion tests/transforms/test_flip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import torch

from viscy.transforms import BatchedRandFlip, BatchedRandFlipd


Expand Down
1 change: 0 additions & 1 deletion tests/transforms/test_gaussian_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
get_gaussian_kernel3d,
)
from monai.transforms.intensity.array import GaussianSmooth

from viscy.transforms import BatchedRandGaussianSmooth, BatchedRandGaussianSmoothd
from viscy.transforms._gaussian_smooth import filter3d_separable

Expand Down
1 change: 0 additions & 1 deletion tests/transforms/test_noise.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import torch
from monai.transforms import Compose

from viscy.transforms import BatchedRandGaussianNoise, BatchedRandGaussianNoised


Expand Down
1 change: 0 additions & 1 deletion tests/transforms/test_scale_intensity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import torch
from monai.transforms import RandScaleIntensity

from viscy.transforms import BatchedRandScaleIntensity, BatchedRandScaleIntensityd


Expand Down
1 change: 0 additions & 1 deletion tests/transforms/test_transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import torch

from viscy.transforms._decollate import Decollate
from viscy.transforms._transforms import (
BatchedScaleIntensityRangePercentiles,
Expand Down
1 change: 0 additions & 1 deletion tests/translation/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest
from lightning.pytorch.loggers import CSVLogger
from numpy.testing import assert_array_equal

from viscy.data.segmentation import SegmentationDataModule
from viscy.trainer import Trainer
from viscy.translation.evaluation import SegmentationMetrics2D
Expand Down
1 change: 0 additions & 1 deletion tests/unet/networks/Unet25D_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import torch

import viscy.utils.cli_utils as io_utils
from viscy.unet.networks.Unet25D import Unet25d

Expand Down
1 change: 0 additions & 1 deletion tests/unet/networks/Unet2D_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import torch

import viscy.utils.cli_utils as io_utils
from viscy.unet.networks.Unet2D import Unet2d

Expand Down
1 change: 0 additions & 1 deletion tests/unet/networks/layers/ConvBlock2D_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import torch

import viscy.utils.cli_utils as io_utils
from viscy.unet.networks.layers.ConvBlock2D import ConvBlock2D

Expand Down
1 change: 0 additions & 1 deletion tests/unet/networks/layers/ConvBlock3D_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import torch

import viscy.utils.cli_utils as io_utils
from viscy.unet.networks.layers.ConvBlock3D import ConvBlock3D

Expand Down
1 change: 0 additions & 1 deletion tests/unet/test_fcmae.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import torch

from viscy.unet.networks.fcmae import (
FullyConvolutionalMAE,
MaskedAdaptiveProjection,
Expand Down
1 change: 0 additions & 1 deletion tests/utils/image_utils_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np

from viscy.utils.image_utils import grid_sample_pixel_values, preprocess_image


Expand Down
1 change: 0 additions & 1 deletion tests/utils/masks_utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
from skimage import draw
from skimage.filters import gaussian

from viscy.utils.masks import (
create_unimodal_mask,
get_unet_border_weight_map,
Expand Down
3 changes: 1 addition & 2 deletions tests/utils/mp_utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import numpy as np
import numpy.testing
import skimage.io as sk_im_io
from testfixtures import TempDirectory

import viscy.utils.aux_utils as aux_utils
import viscy.utils.image_utils as image_utils
import viscy.utils.mp_utils as mp_utils
from testfixtures import TempDirectory
from viscy.utils.masks import create_otsu_mask


Expand Down
1 change: 0 additions & 1 deletion viscy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
"""Learning vision for cells"""
24 changes: 19 additions & 5 deletions viscy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,39 @@
import torch
from jsonargparse import lazy_instance
from lightning.pytorch import LightningDataModule, LightningModule
from lightning.pytorch.cli import LightningCLI
from lightning.pytorch.cli import LightningArgumentParser, LightningCLI
from lightning.pytorch.loggers import TensorBoardLogger

from viscy.trainer import VisCyTrainer


class VisCyCLI(LightningCLI):
"""Extending lightning CLI arguments and defualts."""
"""Extending Lightning CLI arguments and defaults for VisCy."""

@staticmethod
def subcommands() -> dict[str, set[str]]:
"""Define subcommands and their required arguments.

Returns
-------
dict[str, set[str]]
Dictionary mapping subcommand names to sets of required argument names.
"""
subcommands = LightningCLI.subcommands()
subcommand_base_args = {"model"}
subcommands["preprocess"] = subcommand_base_args
subcommands["export"] = subcommand_base_args
subcommands["precompute"] = subcommand_base_args
return subcommands

def add_arguments_to_parser(self, parser) -> None:
def add_arguments_to_parser(self, parser: LightningArgumentParser) -> None:
"""Add default arguments to the Lightning CLI parser.

Parameters
----------
parser : LightningArgumentParser
Lightning CLI parser instance to configure.
"""
parser.set_defaults(
{
"trainer.logger": lazy_instance(
Expand All @@ -45,8 +59,8 @@ def _setup_environment() -> None:


def main() -> None:
"""
Main Lightning CLI entry point.
"""Run the Lightning CLI entry point.

Parse log level and set TF32 precision.
Set default random seed to 42.
"""
Expand Down
Loading