Skip to content

Commit

Permalink
Add unit tests for arcade collection convert tasks (#80)
Browse files Browse the repository at this point in the history
* Bump scikit-image (0.19.3 -> 0.24.0)

* Add Python 3.11 to workflows

* Add Python 3.11 to tox

* Start adding unit tests and documentation for convert to simularium task

* Finish adding unit tests and docstrings for convert to simularium tasks

* Fix linting issues

* Move build tar instance to test utilities module

* Add docstrings and unit tests for convert to contours task

* Add docstrings and unit tests for convert to images task

* Remove test return values

* Add docstrings and unit tests for convert to meshes task

* Rename to locations tar for clarity

* Add ignore to pyproject

* Apply linting suggestions for convert to meshes task

* Update convert to images task to support TFE format

* Add docstrings and unit tests for convert to colorizer task

* Rename colorizer to TFE

* Add docstrings to convert to projection task
  • Loading branch information
jessicasyu authored Sep 18, 2024
1 parent 1f1edad commit 186b2d5
Show file tree
Hide file tree
Showing 24 changed files with 4,422 additions and 368 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ jobs:

strategy:
matrix:
python-version: ["3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11"]

steps:

- name: Checkout the repo
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -31,7 +32,7 @@ jobs:
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-dependencies.outputs.cache-hit != 'true'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python 3.9
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.9
Expand All @@ -30,7 +31,7 @@ jobs:
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-dependencies.outputs.cache-hit != 'true'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python 3.9
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.9
Expand All @@ -27,7 +28,7 @@ jobs:
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-dependencies.outputs.cache-hit != 'true'
Expand Down
154 changes: 67 additions & 87 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python = "^3.9"
prefect = "^2.14.3"
numpy = "^1.24.2"
pandas = "^1.5.3"
scikit-image = "^0.19.3"
scikit-image = "^0.24.0"
simulariumio = "^1.7.0"
matplotlib = "^3.7.2"

Expand Down Expand Up @@ -43,7 +43,7 @@ build-backend = "poetry.core.masonry.api"
disable = [
"missing-module-docstring",
]
good-names = ["i", "j", "k", "x", "y", "z", "u", "v", "w", "ds", "dt", "ax"]
good-names = ["i", "j", "k", "x", "y", "z", "u", "v", "w", "ds", "dt", "dx", "dy", "dz", "ax"]

[tool.pylint.design]
max-args = 10 # maximum number of arguments for function / method
Expand Down Expand Up @@ -95,6 +95,9 @@ max-args = 10
"INP001", # implicit-namespace-package
"ANN201", # missing-return-type-undocumented-public-function
"S311", # suspicious-non-cryptographic-random-usage
"ANN001", # missing-type-function-argument
"ANN003", # missing-type-kwargs
"ANN202", # missing-type-args
]

[tool.coverage.report]
Expand All @@ -107,7 +110,7 @@ exclude_lines = [
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = py{39,310}, format, lint, typecheck
envlist = py{39,310,311}, format, lint, typecheck
skipsdist=True
[testenv]
Expand Down
4 changes: 2 additions & 2 deletions src/arcade_collection/convert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

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
from .convert_to_simularium import convert_to_simularium
from .convert_to_simularium_objects import convert_to_simularium_objects
from .convert_to_simularium_shapes import convert_to_simularium_shapes
from .convert_to_tfe import convert_to_tfe

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)
convert_to_simularium = task(convert_to_simularium)
convert_to_simularium_objects = task(convert_to_simularium_objects)
convert_to_simularium_shapes = task(convert_to_simularium_shapes)
convert_to_tfe = task(convert_to_tfe)
77 changes: 0 additions & 77 deletions src/arcade_collection/convert/convert_to_colorizer.py

This file was deleted.

46 changes: 40 additions & 6 deletions src/arcade_collection/convert/convert_to_contours.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,64 @@
"side1": (0, 2, 1),
"side2": (2, 1, 0),
}
"""Axis rotations for different contour views."""


def convert_to_contours(
series_key: str,
data_tar: tarfile.TarFile,
locations_tar: tarfile.TarFile,
frame: int,
regions: list[str],
box: tuple[int, int, int],
indices: dict[str, list[int]],
) -> dict[str, dict[str, dict[int, list]]]:
locations = extract_tick_json(data_tar, series_key, frame, "LOCATIONS")
"""
Convert data to iso-valued contours.
Contours are calculated using "marching squares" method. Note that these
contours follow the iso-values, which means that a single "square" voxel
will produce a diamond-shaped contour. For the exact outline of a set of
voxels, consider using ``extract_voxel_contours`` from the
``abm_shape_collection`` package.
Parameters
----------
series_key
Simulation series key.
locations_tar
Archive of location data.
frame
Frame number.
regions
List of regions.
box
Size of bounding box.
indices
Map of view to slice indices.
Returns
-------
:
Map of region, view, and index to contours.
"""

locations = extract_tick_json(locations_tar, series_key, frame, "LOCATIONS")

contours: dict[str, dict[str, dict[int, list]]] = {
region: {view: {} for view in indices.keys()} for region in regions
region: {view: {} for view in indices} for region in regions
}

for location in locations:
for region in regions:
array = np.zeros(box)
voxels = get_location_voxels(location, region)
voxels = get_location_voxels(location, region if region != "DEFAULT" else None)

if len(voxels) == 0:
continue

array[tuple(np.transpose(voxels))] = 1

for view in indices.keys():
for view in indices:
array_rotated = np.moveaxis(array, [0, 1, 2], ROTATIONS[view])

for index in indices[view]:
Expand All @@ -49,6 +80,9 @@ def convert_to_contours(
if index not in contours[region][view]:
contours[region][view][index] = []

contours[region][view][index].extend(measure.find_contours(array_slice))
array_contours = [
contour.tolist() for contour in measure.find_contours(array_slice)
]
contours[region][view][index].extend(array_contours)

return contours
Loading

0 comments on commit 186b2d5

Please sign in to comment.