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

Define table specifications #582

Merged
merged 35 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0402afc
Always add `fractal_roi_table_version` to table zarr attributes (ref …
tcompa Oct 19, 2023
cc4119e
Add roi-table doc page placeholder
tcompa Oct 19, 2023
76370c2
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Oct 20, 2023
be7d4ae
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Oct 20, 2023
e8db002
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Oct 20, 2023
0c7a9e4
First draft of ROI docs
tcompa Oct 23, 2023
6587653
Add mathjax support in documentation (close #588)
tcompa Oct 23, 2023
fbaf56e
Cross-reference to docs of other projects (close #587)
tcompa Oct 23, 2023
f5969e7
Use `zarr.hierarchy.Group` for type hints (ref #587)
tcompa Oct 23, 2023
08d7e8b
Second draft of ROI-table documentation
tcompa Oct 23, 2023
7097e86
Update CHANGELOG [skip ci]
tcompa Oct 23, 2023
318e9cf
Minor fixes to ROI-tables docs
tcompa Oct 23, 2023
8194716
Fix broken link
tcompa Oct 23, 2023
a592935
Add example of `write_table` [skip ci]
tcompa Oct 23, 2023
93f1044
Add info on table columns [skip ci]
tcompa Oct 23, 2023
ba4e35a
Add notes about Z arbitrary units [skip ci]
tcompa Oct 23, 2023
379637a
Clean up ROI-table future-perspectives section [skip ci]
tcompa Oct 23, 2023
f046e91
Add default-tables docs section [skip ci]
tcompa Oct 23, 2023
aed64cb
Minor fixes to ROI-tables docs [skip ci]
tcompa Oct 23, 2023
d9bf08b
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Oct 26, 2023
b416c9d
Rename table doc page
tcompa Oct 26, 2023
edac9b8
First review of table docs
tcompa Oct 26, 2023
c43a08f
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Oct 26, 2023
a902dc4
BROKEN Stash of current changes
tcompa Oct 27, 2023
be2c725
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Oct 30, 2023
c2d9d52
Update docstring of `convert_ROIs_from_3D_to_2D`
tcompa Oct 30, 2023
49a9b65
Update tables docs
tcompa Oct 30, 2023
1ecc130
Rename `__ROI_TABLE_VERSION__` into `__FRACTAL_TABLE_VERSION__`
tcompa Oct 30, 2023
b8ba5e7
Update CHANGELOG
tcompa Oct 30, 2023
26435d6
Fix feature-table description in specs
tcompa Oct 30, 2023
0def945
Minor updates to table specs [skip ci]
tcompa Oct 30, 2023
e1e44ab
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Oct 30, 2023
d72adb8
Merge branch 'main' into 529-write-docs-page-for-fractal-tasks-core-r…
tcompa Nov 2, 2023
43a622e
Improve tables docs page
tcompa Nov 2, 2023
98514aa
Rephrase sentence about Z size of FOV/well ROIs
tcompa Nov 2, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* Remove assumptions on ROI-table columns from `get_ROI_table_with_translation` helper function of `calculate_registration_image_based` task (\#591).
* Testing:
* Cache Zenodo data, within GitHub actions (\#585).
* Documentation:
* Define V1 of table specs (\#582).
* Add mathjax support (\#582).
* Add cross-reference inventories to external APIs (\#582).

# 0.13.0

Expand Down
16 changes: 16 additions & 0 deletions docs/javascripts/mathjax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};

document$.subscribe(() => {
MathJax.typesetPromise()
})
475 changes: 475 additions & 0 deletions docs/tables.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions fractal_tasks_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

__VERSION__ = "0.13.1"
__OME_NGFF_VERSION__ = "0.4"
__FRACTAL_TABLE_VERSION__ = "1"
4 changes: 2 additions & 2 deletions fractal_tasks_core/lib_ngff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional
from typing import Union

import zarr
import zarr.hierarchy
from pydantic import BaseModel
from pydantic import Field
from pydantic import validator
Expand Down Expand Up @@ -422,7 +422,7 @@ def load_NgffWellMeta(zarr_path: str) -> NgffWellMeta:
raise e


def detect_ome_ngff_type(group: zarr.Group) -> str:
def detect_ome_ngff_type(group: zarr.hierarchy.Group) -> str:
"""
Given a Zarr group, find whether it is an OME-NGFF plate, well or image.

Expand Down
4 changes: 4 additions & 0 deletions fractal_tasks_core/lib_regions_of_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def convert_ROIs_from_3D_to_2D(
"""
TBD

Note that this function is only relevant when the ROIs in adata span the
whole extent of the Z axis.
TODO: check this explicitly.

Args:
adata: TBD
pixel_size_z: TBD
Expand Down
15 changes: 10 additions & 5 deletions fractal_tasks_core/lib_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
from typing import Union

import anndata as ad
import zarr
import zarr.hierarchy
from anndata.experimental import write_elem
from zarr.errors import ContainsGroupError
from zarr.errors import GroupNotFoundError

from fractal_tasks_core import __FRACTAL_TABLE_VERSION__


class OverwriteNotAllowedError(RuntimeError):
pass
Expand All @@ -34,7 +36,7 @@ def open_zarr_group_with_overwrite(
overwrite: bool,
logger: Optional[logging.Logger] = None,
**open_group_kwargs: Any,
) -> zarr.Group:
) -> zarr.hierarchy.Group:
"""
Wrap `zarr.open_group` and add `overwrite` argument.

Expand Down Expand Up @@ -122,7 +124,7 @@ def open_zarr_group_with_overwrite(


def _write_elem_with_overwrite(
group: zarr.Group,
group: zarr.hierarchy.Group,
key: str,
elem: Any,
*,
Expand Down Expand Up @@ -184,7 +186,7 @@ def _write_elem_with_overwrite(


def write_table(
image_group: zarr.Group,
image_group: zarr.hierarchy.Group,
table_name: str,
table: ad.AnnData,
overwrite: bool = False,
Expand Down Expand Up @@ -291,11 +293,14 @@ def write_table(
# Update table_group attributes with table_attrs key/value pairs
table_group.attrs.update(**table_attrs)

# Always add information about the fractal-roi-table version
table_group.attrs.update(fractal_table_version=__FRACTAL_TABLE_VERSION__)

return table_group


def prepare_label_group(
image_group: zarr.Group,
image_group: zarr.hierarchy.Group,
label_name: str,
overwrite: bool = False,
label_attrs: Optional[dict[str, Any]] = None,
Expand Down
44 changes: 30 additions & 14 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ repo_url: https://github.com/fractal-analytics-platform/fractal-tasks-core
repo_name: fractal-tasks-core

markdown_extensions:
- admonition
- pymdownx.details
- pymdownx.emoji
- pymdownx.magiclink
- pymdownx.snippets:
check_paths: true
base_path:
- fractal_tasks_core/__FRACTAL_MANIFEST__.json
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.tasklist
- toc:
permalink: true
- admonition
- pymdownx.details
- pymdownx.emoji
- pymdownx.magiclink
- pymdownx.snippets:
check_paths: true
base_path:
- fractal_tasks_core/__FRACTAL_MANIFEST__.json
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.tasklist
- toc:
permalink: true
- pymdownx.arithmatex:
generic: true
- footnotes

extra_javascript:
- javascripts/mathjax.js
- https://polyfill.io/v3/polyfill.min.js?features=es6
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js

theme:
name: "material"
Expand Down Expand Up @@ -51,6 +59,7 @@ nav:
- Run tasks in Python scripts: tasks_in_scripts.md
- Write a custom task: custom_task.md
- Task manifest: manifest.md
- Tables: tables.md
- Code reference: reference/fractal_tasks_core/
- Development: development.md
- Changelog: changelog.md
Expand All @@ -71,6 +80,13 @@ plugins:
default_handler: python
handlers:
python:
import:
- url: https://docs.python.org/objects.inv
- url: https://numpy.org/doc/stable/objects.inv
- url: https://zarr.readthedocs.io/en/stable/objects.inv
- url: https://anndata.readthedocs.io/en/latest/objects.inv
- url: https://docs.dask.org/en/stable/objects.inv
# - url: https://docs.pydantic.dev/latest/objects.inv # This points to V2
options:
show_signature_annotations: false
docstring_section_style: "spacy"
Expand Down
5 changes: 5 additions & 0 deletions tests/test_unit_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import zarr
from devtools import debug

from fractal_tasks_core import __FRACTAL_TABLE_VERSION__
from fractal_tasks_core.lib_write import _write_elem_with_overwrite
from fractal_tasks_core.lib_write import open_zarr_group_with_overwrite
from fractal_tasks_core.lib_write import OverwriteNotAllowedError
Expand Down Expand Up @@ -127,6 +128,10 @@ def test_write_table(tmp_path):
assert image_group["tables"].attrs.asdict() == dict(tables=["table_a"])
for key in ["region", "instance_key", "type"]:
assert key not in table_a_group.attrs.keys()
assert (
table_a_group.attrs["fractal_table_version"]
== __FRACTAL_TABLE_VERSION__
)

# Run write_table again, with overwrite=True
table_a_group = write_table(
Expand Down
Loading