Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] container-level validation, add docs #19

Merged
merged 70 commits into from
Mar 27, 2024
Merged
Changes from 42 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
90507a9
feat: use pydantic-zarr for representing multiscale groups
d-v-b Jun 6, 2023
7295c26
chore: update type signature of version in latest multiscale, althoug…
d-v-b Jun 6, 2023
20c4a8c
feat: update to pydantic 2 / pydantic-zarr 0.5.2
d-v-b Nov 8, 2023
9c72f28
feat: pointless renaming
d-v-b Nov 8, 2023
00ee033
feat: big refactor: split validators into separate functions, rename …
d-v-b Dec 20, 2023
dd469b6
feat: use python 3.10 as baseline, refactor the test suite a bit, use…
d-v-b Jan 1, 2024
87dad87
lint
d-v-b Jan 1, 2024
ec6649f
feat: use a tighter module-local name convention for specialized Grou…
d-v-b Jan 9, 2024
4044348
begin adding docs and convenience function for multiscale creation
d-v-b Feb 4, 2024
845bf4e
docs: add mkdocs.yml
d-v-b Feb 12, 2024
62ab448
merge branch "use_pydantic_zarr" from origin
d-v-b Feb 15, 2024
192d6e0
tighten some names and type annotations
d-v-b Feb 15, 2024
7d28336
start handling deeper arrays
d-v-b Feb 15, 2024
601972b
flattening and unflattening routines for GroupSpec
d-v-b Feb 20, 2024
ba81fa0
fix: use tuple instead of list for transforms; defer to pydantic-zarr…
d-v-b Mar 3, 2024
f50108b
chore: add gha
d-v-b Mar 3, 2024
ae5fb4a
feat: use pydantic-zarr for representing multiscale groups
d-v-b Jun 6, 2023
64fbfa8
chore: update type signature of version in latest multiscale, althoug…
d-v-b Jun 6, 2023
45ce1c4
feat: update to pydantic 2 / pydantic-zarr 0.5.2
d-v-b Nov 8, 2023
41bdf3f
feat: pointless renaming
d-v-b Nov 8, 2023
6dab0a8
feat: big refactor: split validators into separate functions, rename …
d-v-b Dec 20, 2023
fb777cb
feat: use python 3.10 as baseline, refactor the test suite a bit, use…
d-v-b Jan 1, 2024
02e09ee
lint
d-v-b Jan 1, 2024
675992f
feat: use a tighter module-local name convention for specialized Grou…
d-v-b Jan 9, 2024
2825b07
begin adding docs and convenience function for multiscale creation
d-v-b Feb 4, 2024
c502b36
docs: add mkdocs.yml
d-v-b Feb 12, 2024
94e08dd
merge branch "use_pydantic_zarr" from origin
d-v-b Feb 15, 2024
5f7b90d
tighten some names and type annotations
d-v-b Feb 15, 2024
5e2cbbe
start handling deeper arrays
d-v-b Feb 15, 2024
5296cce
flattening and unflattening routines for GroupSpec
d-v-b Feb 20, 2024
9a226ab
fix: use tuple instead of list for transforms; defer to pydantic-zarr…
d-v-b Mar 3, 2024
0887e4a
chore: add gha
d-v-b Mar 3, 2024
81afac6
chore: fix broken tests
d-v-b Mar 3, 2024
07b2e1e
Merge branch 'use_pydantic_zarr' of https://github.com/JaneliaSciComp…
d-v-b Mar 3, 2024
a365bfa
remove redundant ci
d-v-b Mar 3, 2024
0087042
lint
d-v-b Mar 4, 2024
007438b
ci: increment the python version used for linting
d-v-b Mar 4, 2024
8b871f7
chore: use typing_extensions for self import
d-v-b Mar 4, 2024
475ecca
remove extra script
d-v-b Mar 4, 2024
bb349cc
fix: remove support for group_scale and group_translation in Group.fr…
d-v-b Mar 4, 2024
c2a6831
Update pyproject.toml
d-v-b Mar 6, 2024
474e541
Update poetry.lock
d-v-b Mar 6, 2024
ce03791
add doctests, set minimum python version to 3.9
d-v-b Mar 11, 2024
c7d0f3a
handle numpy arrays as arguments to and transforms
d-v-b Mar 11, 2024
2af58d7
dont cast to list
d-v-b Mar 11, 2024
516d35d
add multiscale creation example
d-v-b Mar 11, 2024
c4c1cd7
add chunking to group creation example
d-v-b Mar 11, 2024
a63fef5
simplify array creation in example, and remove incorrect translation
d-v-b Mar 11, 2024
a40f2bc
chore: depluralize module names
d-v-b Mar 12, 2024
7a28df7
docs: update docs
d-v-b Mar 12, 2024
0214f65
docs: more docs
d-v-b Mar 12, 2024
8d0e640
test: remove unnecessary transform validation logic
d-v-b Mar 12, 2024
cb86c5d
docs: add links, remove unused var from examples
d-v-b Mar 20, 2024
a3e4b4f
bump deps, using latest version of pydantic-zarr
d-v-b Mar 20, 2024
2923fdd
add chunks keyword argument to from_arrays, and corresponding normali…
d-v-b Mar 20, 2024
f5156b8
add from __future__ imports, and use Union instead of |
d-v-b Mar 20, 2024
b8e55ab
add chunks to from_array tests
d-v-b Mar 20, 2024
e6407f7
chore: update lockfile
d-v-b Mar 20, 2024
d80a120
chore: add python 3.9 to ci
d-v-b Mar 20, 2024
26f1fe8
docs: fix example
d-v-b Mar 20, 2024
d1808e2
feat: expand function signature of from_arrays to include compressor,…
d-v-b Mar 20, 2024
fd0c19a
feat: use tuples instead of lists
d-v-b Mar 20, 2024
b5e6ba9
update tests for tuples
d-v-b Mar 20, 2024
88290a4
add validation example
d-v-b Mar 20, 2024
472d75e
docs
d-v-b Mar 20, 2024
297338d
docstring
d-v-b Mar 20, 2024
e7228f7
more text about
d-v-b Mar 21, 2024
53fcc82
chore: bump deps
d-v-b Mar 27, 2024
fa3f922
test: parametrize test_coordinate_transforms_invalid_ndims
d-v-b Mar 27, 2024
9e915f7
test: shorten the names of some test functions
d-v-b Mar 27, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.10"
- uses: abatilo/actions-poetry@v2
- run: poetry install
- run: poetry run pre-commit run --all-files
@@ -20,9 +20,9 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.10"
- "3.12"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python 3.8 and 3.9 are still not eol. I know about some of the niceties that newer versions add, but for adoption of this package it might be a tad restrictive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good point -- I was going by the numpy schedule here, according to which python 3.9 will not be supported after april

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try testing on 3.8 and 3.9 and see what breaks

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I always forget about the numpy schedule... Honestly, out of practicality and the intended user-base (bio-image community, at least that's what I think) for me it's more important what conda-forge currently supports. But I would be the first to admit that I'm biased there.

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
14 changes: 6 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -5,18 +5,16 @@ default_stages: [commit, push]
default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- repo: https://github.com/charliermarsh/ruff-pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.245'
rev: v0.1.8
hooks:
# Run the linter.
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [ --fix ]
# Run the formatter.
- id: ruff-format
1 change: 1 addition & 0 deletions docs/api/v04/axis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pydantic_ome_ngff.v04.axis
1 change: 1 addition & 0 deletions docs/api/v04/label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pydantic_ome_ngff.v04.label
1 change: 1 addition & 0 deletions docs/api/v04/multiscales.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pydantic_ome_ngff.v04.multiscales
1 change: 1 addition & 0 deletions docs/api/v04/plate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pydantic_ome_ngff.v04.plate
1 change: 1 addition & 0 deletions docs/api/v04/transforms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pydantic_ome_ngff.v04.transforms
19 changes: 19 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# pydantic-ome-ngff

[Pydantic](https://docs.pydantic.dev/latest/) models for [OME-NGFF](https://ngff.openmicroscopy.org/)

# About

This library aims to provide models for the the metadata objects and Zarr hierarchies described in the [OME-NGFF](https://ngff.openmicroscopy.org/) specifications.

# Reading Multiscale metadata

```python
# example data on S3-compatible cloud storage
from pydantic_ome_ngff.v04.multiscales import Group
import zarr
url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr"
zgroup = zarr.open(url)
group = Group.from_zarr(zgroup)

```
63 changes: 63 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
site_name: pydantic-ome-ngff
site_url: https://janeliascicomp.github.io/pydantic-ome-ngff/
site_author: Davis Bennett
site_description: >-
Pydantic models for the OME-NGFF file format.

# Repository
repo_name: janeliascicomp/pydantic-ome-ngff
repo_url: https://github.com/janeliascicomp/pydantic-zarr

# Copyright
copyright: Copyright © 2016 - 2023 HHMI / Janelia

theme:
features:
- navigation.expand
name: material
palette:
# Palette toggle for light mode
- scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode

# Palette toggle for dark mode
- scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode

nav:
- About: index.md
- API:
- v04:
- api/v04/multiscales.md
- api/v04/axis.md
- api/v04/transforms.md

plugins:
- mkdocstrings:
handlers:
python:
options:
docstring_style: numpy
members_order: source
separate_signature: true
filters: ["!^_"]
docstring_options:
ignore_init_summary: true
merge_init_into_class: true

markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- toc:
baselevel: 2
toc_depth: 4
permalink: "#"
1,747 changes: 1,310 additions & 437 deletions poetry.lock

Large diffs are not rendered by default.

42 changes: 38 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@ readme = "README.md"
packages = [{include = "pydantic_ome_ngff", from="src"}]

[tool.poetry.dependencies]
python = "^3.9"
pydantic = "^1.10.4"

python = "^3.10"
pydantic-zarr = "0.6.1"
rich = "^13.6.0"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.0.4"
@@ -21,6 +21,12 @@ mypy = "^1.0.1"
requests = "^2.28.2"
pytest-cov = "^4.0.0"


[tool.poetry.group.docs.dependencies]
mkdocs-material = "^9.5.5"
mkdocstrings = {extras = ["python"], version = "^0.24.0"}
pytest-examples = "^0.0.9"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
@@ -44,4 +50,32 @@ disallow_untyped_defs = true
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = 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"
4 changes: 4 additions & 0 deletions src/pydantic_ome_ngff/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2023-present Davis Vann Bennett <davis.v.bennett@gmail.com>
#
# SPDX-License-Identifier: MIT
__version__ = "0.3.0"
9 changes: 2 additions & 7 deletions src/pydantic_ome_ngff/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from pydantic import BaseModel, Extra
from pydantic import BaseModel


class StrictBase(BaseModel):
class StrictBase(BaseModel, extra="forbid"):
"""
A pydantic basemodel that refuses extra fields.
"""

class Config:
extra = Extra.forbid


class VersionedBase(BaseModel):
"""
@@ -22,5 +19,3 @@ class StrictVersionedBase(VersionedBase, StrictBase):
"""
An internally versioned pydantic basemodel that refuses extra fields.
"""

...
10 changes: 5 additions & 5 deletions src/pydantic_ome_ngff/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic_ome_ngff.latest.axes import Axis # noqa
from pydantic_ome_ngff.latest.multiscales import Multiscale # noqa
from pydantic_ome_ngff.latest.imageLabel import ImageLabel # noqa
from pydantic_ome_ngff.latest.well import Well # noqa
from pydantic_ome_ngff.latest.plate import Plate # noqa
from pydantic_ome_ngff.latest.axis import Axis # noqa
from pydantic_ome_ngff.latest.multiscales import MultiscaleMetadata # noqa
from pydantic_ome_ngff.latest.label import ImageLabel # noqa
from pydantic_ome_ngff.latest.well import WellMeta # noqa
from pydantic_ome_ngff.latest.plate import PlateMeta # noqa
from pydantic_ome_ngff.latest.base import version # noqa
12 changes: 0 additions & 12 deletions src/pydantic_ome_ngff/latest/axes.py

This file was deleted.

12 changes: 12 additions & 0 deletions src/pydantic_ome_ngff/latest/axis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pydantic_ome_ngff.v04.axis as axisV04

AxisType = axisV04.AxisType


class Axis(axisV04.Axis):
"""
Axis metadata.
See https://ngff.openmicroscopy.org/latest/#axes-md

Note: this metadata is unchanged from version 0.4 of the spec.
"""
8 changes: 7 additions & 1 deletion src/pydantic_ome_ngff/latest/base.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
version = "0.5-dev"
from __future__ import annotations
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Literal

version: Literal["0.5-dev"] = "0.5-dev"
56 changes: 0 additions & 56 deletions src/pydantic_ome_ngff/latest/coordinateTransformations.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
from typing import Optional
from pydantic_ome_ngff.v04.imageLabel import ImageLabel as ImageLabelV04

from pydantic_ome_ngff.latest.base import version
from pydantic_ome_ngff.v04.label import ImageLabel as ImageLabelV04


class ImageLabel(ImageLabelV04):
@@ -13,4 +13,4 @@ class ImageLabel(ImageLabelV04):
# we need to put the version here as a private class attribute because the version
# is not required by the spec...
_version = version
version: Optional[str] = version
version: str | None = version
Loading