Skip to content

Commit

Permalink
Add unit tests for arcade collection output tasks (#79)
Browse files Browse the repository at this point in the history
* Add docstrings and unit tests for convert model units task

* Add docstrings and unit tests for extract tick json task

* Add docstrings and unit tests for get location voxels task

* Move contours task to convert submodule

* Remove merge parsed results task

* Add ruff linter

* Fix linting issues in input module

* Update docstrings and unit tests for parse growth file task

* Add docstrings and unit tests for parse locations file task

* Add docstrings and unit tests for parse cells file task

* Apply ruff linting

* Apply more ruff linting
  • Loading branch information
jessicasyu authored Sep 4, 2024
1 parent 479bccc commit 1f1edad
Show file tree
Hide file tree
Showing 25 changed files with 1,520 additions and 220 deletions.
101 changes: 59 additions & 42 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 42 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ matplotlib = "^3.7.2"
[tool.poetry.group.dev.dependencies]
black = "^24.3.0"
isort = "^5.12.0"
mypy = "^1.3.0"
mypy = "^1.10.0"
pylint = "^2.16.2"
pytest = "^7.3.0"
pytest-cov = "^4.0.0"
Expand All @@ -30,6 +30,7 @@ furo = "^2023.5.20"
myst-parser = "^2.0.0"
sphinx-copybutton = "^0.5.2"
tox = "^4.5.1"
ruff = "^0.6.3"

[tool.isort]
profile = "black"
Expand All @@ -42,7 +43,7 @@ build-backend = "poetry.core.masonry.api"
disable = [
"missing-module-docstring",
]
good-names = ["i", "j", "k", "x", "y", "z", "ds", "dt", "ax"]
good-names = ["i", "j", "k", "x", "y", "z", "u", "v", "w", "ds", "dt", "ax"]

[tool.pylint.design]
max-args = 10 # maximum number of arguments for function / method
Expand All @@ -59,11 +60,49 @@ namespace_packages = true
module = [
"matplotlib.*",
"pandas.*",
"ruamel.*",
"simulariumio.*",
"skimage.*",
]
ignore_missing_imports = true

[tool.ruff]
line-length = 100
target-version = "py39"

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"COM812", # missing-trailing-comma
"D100", # undocumented-public-module
"D105", # undocumented-magic-method
"D107", # undocumented-public-init
"D202", # no-blank-line-after-function
"D203", # one-blank-line-before-class
"D212", # multi-line-summary-first-line
"D413", # blank-line-after-last-section
"D416", # section-name-ends-in-colon
]

[tool.ruff.lint.pylint]
max-args = 10

[tool.ruff.lint.per-file-ignores]
"tests/*.py" = [
"D", # pydocstyle
"PT009", # pytest-unittest-assertion
"PT027", # pytest-unittest-raises-assertion
"INP001", # implicit-namespace-package
"ANN201", # missing-return-type-undocumented-public-function
"S311", # suspicious-non-cryptographic-random-usage
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
]

[tool.tox]
legacy_tox_ini = """
[tox]
Expand All @@ -84,6 +123,7 @@ commands =
[testenv:lint]
commands =
poetry run pylint --ignore-patterns=test.*?py src/ tests/ --fail-under=9.0
poetry run ruff check src/ tests/
[testenv:typecheck]
commands =
Expand Down
2 changes: 2 additions & 0 deletions src/arcade_collection/convert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from prefect import task

from .convert_to_colorizer import convert_to_colorizer
from .convert_to_contours import convert_to_contours
from .convert_to_images import convert_to_images
from .convert_to_meshes import convert_to_meshes
from .convert_to_projection import convert_to_projection
Expand All @@ -11,6 +12,7 @@
from .convert_to_simularium_shapes import convert_to_simularium_shapes

convert_to_colorizer = task(convert_to_colorizer)
convert_to_contours = task(convert_to_contours)
convert_to_images = task(convert_to_images)
convert_to_meshes = task(convert_to_meshes)
convert_to_projection = task(convert_to_projection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}


def get_voxel_contours(
def convert_to_contours(
series_key: str,
data_tar: tarfile.TarFile,
frame: int,
Expand Down
4 changes: 2 additions & 2 deletions src/arcade_collection/convert/convert_to_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

from arcade_collection.output.get_voxel_contours import get_voxel_contours
from arcade_collection.convert.convert_to_contours import convert_to_contours


def convert_to_projection(
Expand Down Expand Up @@ -47,7 +47,7 @@ def convert_to_projection(
"side1": list(range(1, width)),
"side2": list(range(1, length)),
}
contours = get_voxel_contours(series_key, data_tar, frame, regions, box, indices)
contours = convert_to_contours(series_key, data_tar, frame, regions, box, indices)

for region in regions:
color = colors[region]
Expand Down
22 changes: 10 additions & 12 deletions src/arcade_collection/input/convert_to_cells_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ def convert_to_cell(
height = samples.z.max() - samples.z.min()

critical_volume = convert_value_distribution(
(reference["volume"] if "volume" in reference else volume),
reference.get("volume", volume),
volume_distributions["DEFAULT"],
critical_volume_distributions["DEFAULT"],
)

critical_height = convert_value_distribution(
(reference["height"] if "height" in reference else height),
reference.get("height", height),
height_distributions["DEFAULT"],
critical_height_distributions["DEFAULT"],
)
Expand All @@ -146,7 +146,7 @@ def convert_to_cell(
"criticals": [critical_volume, critical_height],
}

if "region" in samples.columns and not samples["region"].isnull().all():
if "region" in samples.columns and not samples["region"].isna().all():
regions = [
convert_to_cell_region(
region,
Expand Down Expand Up @@ -210,13 +210,13 @@ def convert_to_cell_region(
region_height = region_samples.z.max() - region_samples.z.min()

region_critical_volume = convert_value_distribution(
(reference[f"volume.{region}"] if f"volume.{region}" in reference else region_volume),
reference.get(f"volume.{region}", region_volume),
volume_distributions[region],
critical_volume_distributions[region],
)

region_critical_height = convert_value_distribution(
(reference[f"height.{region}"] if f"height.{region}" in reference else region_height),
reference.get(f"height.{region}", region_height),
height_distributions[region],
critical_height_distributions[region],
)
Expand All @@ -234,7 +234,7 @@ def get_cell_state(
threshold_fractions: dict[str, float],
) -> str:
"""
Estimates cell state based on cell volume.
Estimate cell state based on cell volume.
The threshold fractions dictionary defines the monotonic thresholds between
different cell states. For a given volume v, critical volume V, and states
Expand Down Expand Up @@ -274,7 +274,7 @@ def convert_value_distribution(
target_distribution: tuple[float, float],
) -> float:
"""
Estimates target value based on source value and source and target distributions.
Estimate target value based on source value and source and target distributions.
Parameters
----------
Expand All @@ -294,13 +294,12 @@ def convert_value_distribution(
source_avg, source_std = source_distribution
target_avg, target_std = target_distribution
z_scored_value = (value - source_avg) / source_std
converted_value = z_scored_value * target_std + target_avg
return converted_value
return z_scored_value * target_std + target_avg


def filter_cell_reference(cell_id: int, reference: pd.DataFrame) -> dict:
"""
Filters reference data for given cell id.
Filter reference data for given cell id.
Parameters
----------
Expand All @@ -316,5 +315,4 @@ def filter_cell_reference(cell_id: int, reference: pd.DataFrame) -> dict:
"""

cell_reference = reference[reference["ID"] == cell_id].squeeze()
cell_reference = cell_reference.to_dict() if not cell_reference.empty else {}
return cell_reference
return cell_reference.to_dict() if not cell_reference.empty else {}
Loading

0 comments on commit 1f1edad

Please sign in to comment.