Skip to content

Commit

Permalink
Transformations (#30)
Browse files Browse the repository at this point in the history
* start axis transposition

* fix implementation of axis transposition

* fix a few type errors

* use literal set constructor

* use hatch

* version tweaks

* adjust project description

* tweaks to pyproject.toml

* update test workflow to use hatch

* remove linting action

* add pip listing explicitly
  • Loading branch information
d-v-b authored Jun 5, 2024
1 parent dd9e43c commit 1ad54ea
Show file tree
Hide file tree
Showing 23 changed files with 734 additions and 185 deletions.
4 changes: 4 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
48 changes: 22 additions & 26 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,28 @@ on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: abatilo/actions-poetry@v2
- run: poetry install
- run: poetry run pre-commit run --all-files

test:
strategy:
fail-fast: false
matrix:
python-version:
- "3.9"
- "3.10"
- "3.10"
- "3.12"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: py=${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: abatilo/actions-poetry@v2
- run: poetry install
- run: poetry run pytest --verbose --cov src/pydantic_ome_ngff
cache: 'pip'
- name: Install Hatch
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Set Up Hatch Env
run: |
hatch env create test.py${{ matrix.python-version }}
hatch env run -e test.py${{ matrix.python-version }} pip list
- name: Run Tests
run: |
hatch env run --env test.py${{ matrix.python-version }} run
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json
# Pyre type checker
.pyre/
.vscode/settings.json

# version file
src/pydantic_ome_ngff/_version.py
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ except ValidationError as e:
"""
1 validation error for Group
Value error, Dataset s0 was specified in multiscale metadata, but no array with that name was found in the hierarchy. All arrays referenced in multiscale metadata must be contained in the group. [type=value_error, input_value={'zarr_version': 2, 'attr...: 'zstd', 'level': 3}}}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/value_error
For further information visit https://errors.pydantic.dev/2.7/v/value_error
"""

group_model_wrong_array = group_model.model_dump()
Expand All @@ -482,6 +482,6 @@ except ValidationError as e:
"""
1 validation error for Group
Value error, Transform type='scale' scale=(1, 1) has dimensionality 2, which does not match the dimensionality of the array found in this group at s0 (1). Transform dimensionality must match array dimensionality. [type=value_error, input_value={'zarr_version': 2, 'attr...: 'zstd', 'level': 3}}}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/value_error
For further information visit https://errors.pydantic.dev/2.7/v/value_error
"""
```
138 changes: 84 additions & 54 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,93 @@
[tool.poetry]
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "pydantic-ome-ngff"
version = "0.5.0"
description = "Pydantic models for the OME-NGFF"
authors = ["Davis Vann Bennett <[email protected]>"]
license = "MIT"
dynamic = ["version"]
description = "Pydantic models for the OME-NGFF file format."
readme = "README.md"
packages = [{include = "pydantic_ome_ngff", from="src"}]
requires-python = ">=3.9"
license = "MIT"
keywords = ["ngff", "pydantic", "ome-ngff", "zarr"]
authors = [
{ name = "Davis Vann Benntt", email = "[email protected]" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = [
"pydantic-zarr == 0.7.0"
]

[tool.poetry.dependencies]
python = "^3.9"
pydantic-zarr = "0.7.0"
[project.urls]
Documentation = "https://janeliascicomp.github.io/pydantic-ome-ngff"
Issues = "https://github.com/janeliascicomp/pydantic-ome-ngff/issues"
Source = "https://github.com/janeliascicomp/pydantic-ome-ngff"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.0.4"
isort = "^5.12.0"
jsonschema = "^4.17.3"
pytest = "^7.2.1"
mypy = "^1.0.1"
requests = "^2.28.2"
pytest-cov = "^4.0.0"
fsspec = {version = "^2024.2.0", extras=["http"]}
[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/pydantic_ome_ngff/_version.py"

[tool.hatch.envs.test]
dependencies = [
"pytest==8.0.0",
"pytest-examples==0.0.9",
"fsspec[http]==2024.2.0",
"requests==2.32.3",
"pytest-cov==5.0.0",
"jsonschema==4.17.3"
]

[tool.poetry.group.docs.dependencies]
mkdocs-material = "^9.5.5"
mkdocstrings = {extras = ["python"], version = "^0.24.0"}
pytest-examples = "^0.0.9"
[tool.hatch.envs.test.scripts]
run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests"
run = "run-coverage --no-cov"
run-verbose = "run-coverage --verbose"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[[tool.hatch.envs.test.matrix]]
python = ["3.9", "3.10", "3.11"]

[tool.hatch.envs.types]
extra-dependencies = [
"mypy>=1.0.0",
]

[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/pydantic_ome_ngff tests}"

[tool.hatch.env.docs]
dependencies = [
"mkdocs-material==9.5.5",
"mkdocstrings==0.24.0"
]

[tool.hatch.envs.docs.scripts]
serve = "mkdocs serve --watch=src"

[tool.coverage.run]
source_pkgs = ["pydantic_ome_ngff", "tests"]
branch = true
parallel = true
omit = [
"src/pydantic_ome_ngff/__about__.py",
]

[tool.coverage.paths]
pydantic_ome_ngff = ["src/pydantic_ome_ngff", "*/pydantic-ome-ngff/src/pydantic_ome_ngff"]
tests = ["tests", "*/pydantic-ome-ngff/tests"]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.mypy]
plugins = [
Expand All @@ -50,32 +108,4 @@ disallow_untyped_defs = true
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true


[tool.coverage.run]
source = ['src']
branch = true
context = '${CONTEXT}'

[tool.coverage.report]
precision = 2
exclude_lines = [
'pragma: no cover',
'raise NotImplementedError',
'if TYPE_CHECKING:',
'if typing.TYPE_CHECKING:',
'@overload',
'@typing.overload',
'\(Protocol\):$',
'typing.assert_never',
'assert_never',
]

[tool.coverage.paths]
source = [
'src/'
]

[tool.coverage.html]
directory = "htmlcov"
warn_untyped_fields = true
4 changes: 0 additions & 4 deletions src/pydantic_ome_ngff/__about__.py

This file was deleted.

3 changes: 0 additions & 3 deletions src/pydantic_ome_ngff/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from importlib.metadata import version as _version

__version__ = _version(__name__)
1 change: 1 addition & 0 deletions src/pydantic_ome_ngff/latest/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down
6 changes: 3 additions & 3 deletions src/pydantic_ome_ngff/latest/multiscale.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

from typing import Literal
from pydantic_ome_ngff.latest.base import version

import pydantic_ome_ngff.v04.multiscale as msv04
from pydantic_ome_ngff.latest.base import version


class Dataset(msv04.Dataset):
Expand All @@ -20,8 +22,6 @@ class Dataset(msv04.Dataset):
The coordinate transformations for this image.
"""

...


class MultiscaleMetadata(msv04.MultiscaleMetadata):
"""
Expand Down
12 changes: 2 additions & 10 deletions src/pydantic_ome_ngff/latest/transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import Union

import pydantic_ome_ngff.v04.transform as tx


Expand All @@ -9,44 +11,34 @@ class Identity(tx.Identity):
See https://ngff.openmicroscopy.org/latest/#trafo-md
"""

...


class PathScale(tx.PathScale):
""" "
A coordinateTransform with at "path" field.
See https://ngff.openmicroscopy.org/latest/#trafo-md
"""

...


class PathTranslation(tx.PathTranslation):
""" "
A coordinateTransform with at "path" field.
See https://ngff.openmicroscopy.org/latest/#trafo-md
"""

...


class VectorTranslation(tx.VectorTranslation):
"""
A translation transform with a `translate` field that is a vector.
See https://ngff.openmicroscopy.org/latest/#trafo-md
"""

...


class VectorScale(tx.VectorScale):
"""
A scale transform with a `scale` field that is a vector.
See https://ngff.openmicroscopy.org/latest/#trafo-md
"""

...


Scale = Union[VectorScale, PathScale]
Translation = Union[VectorTranslation, PathTranslation]
Expand Down
1 change: 1 addition & 0 deletions src/pydantic_ome_ngff/latest/well.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

from pydantic_ome_ngff.latest.base import version
from pydantic_ome_ngff.v04.well import WellMetadata as WellMetaV04

Expand Down
13 changes: 7 additions & 6 deletions src/pydantic_ome_ngff/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations
from typing import TYPE_CHECKING, runtime_checkable

from collections import Counter
from typing import Protocol
from typing import TYPE_CHECKING, Protocol, runtime_checkable

import numpy as np

if TYPE_CHECKING:
from typing import Dict, Iterable, Hashable, Tuple, Any
from typing import Any, Hashable, Iterable


def duplicates(values: Iterable[Hashable]) -> Dict[Hashable, int]:
def duplicates(values: Iterable[Hashable]) -> dict[Hashable, int]:
"""
Takes a sequence of hashable elements and returns a dict where the keys are the
elements of the input that occurred at least once, and the values are the
Expand All @@ -20,13 +21,13 @@ def duplicates(values: Iterable[Hashable]) -> Dict[Hashable, int]:

@runtime_checkable
class ArrayLike(Protocol):
shape: Tuple[int, ...]
shape: tuple[int, ...]
dtype: np.dtype[Any]


@runtime_checkable
class ChunkedArrayLike(ArrayLike, Protocol):
chunks: Tuple[int, ...]
chunks: tuple[int, ...]


def listify_numpy(data: Any) -> Any:
Expand Down
8 changes: 4 additions & 4 deletions src/pydantic_ome_ngff/v04/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pydantic_ome_ngff.v04.axis import Axis
from pydantic_ome_ngff.v04.transform import Transform
from pydantic_ome_ngff.v04.multiscale import MultiscaleMetadata
from pydantic_ome_ngff.v04.base import version
from pydantic_ome_ngff.v04.label import ImageLabel
from pydantic_ome_ngff.v04.well import WellMetadata
from pydantic_ome_ngff.v04.multiscale import MultiscaleMetadata
from pydantic_ome_ngff.v04.plate import PlateMetadata
from pydantic_ome_ngff.v04.base import version
from pydantic_ome_ngff.v04.transform import Transform
from pydantic_ome_ngff.v04.well import WellMetadata

__all__ = [
"Axis",
Expand Down
Loading

0 comments on commit 1ad54ea

Please sign in to comment.