Skip to content

Commit

Permalink
Merge pull request #94 from melonora/xarray_datatree
Browse files Browse the repository at this point in the history
adjust to xarray datatree
  • Loading branch information
thewtex authored Nov 5, 2024
2 parents 2eccb02 + d483b0b commit 05c5696
Show file tree
Hide file tree
Showing 10 changed files with 1,788 additions and 1,740 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
max-parallel: 5
matrix:
os: [ubuntu-22.04, windows-2022, macos-12, macos-14]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ examples/sub-I46_ses-SPIM_sample-BrocaAreaS01_stain-GAD67_chunk-00_SPIM*
examples/dask-worker-space/
.pixi/
examples/Cell_Colony.zarr/
.idea/

# Byte-compiled / optimized / DLL files
__pycache__/
16 changes: 10 additions & 6 deletions examples/ConvertTiffFile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "cffe4de0",
"metadata": {},
"outputs": [],
"metadata": {
"jupyter": {
"is_executing": true
}
},
"source": [
"import sys\n",
"!{sys.executable} -m pip install --upgrade multiscale-spatial-image matplotlib tifffile zarr ome-types dask_image 'dask[diagnostics]'"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
Expand All @@ -34,7 +38,7 @@
"import zarr\n",
"import ome_types\n",
"import dask.array as da\n",
"import datatree\n",
"from xarray import open_datatree\n",
"from numcodecs import Blosc"
]
},
Expand Down Expand Up @@ -1296,7 +1300,7 @@
"source": [
"store = zarr.storage.DirectoryStore(f'{image_name}.zarr/0', dimension_separator='/')\n",
"\n",
"new_multiscale = datatree.open_datatree(store, engine='zarr')\n",
"new_multiscale = open_datatree(store, engine='zarr')\n",
"new_multiscale['scale2'].ds[name].isel(x=250).plot.imshow()"
]
}
Expand Down
3 changes: 1 addition & 2 deletions multiscale_spatial_image/multiscale_spatial_image.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Union

from datatree import DataTree
from xarray import DataTree, register_datatree_accessor
import numpy as np
from collections.abc import MutableMapping
from pathlib import Path
from zarr.storage import BaseStore
from datatree import register_datatree_accessor


@register_datatree_accessor("msi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from spatial_image import to_spatial_image

from .to_multiscale import to_multiscale, Methods
from datatree import DataTree
from xarray import DataTree


def itk_image_to_multiscale(
Expand Down
4 changes: 2 additions & 2 deletions multiscale_spatial_image/to_multiscale/to_multiscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from spatial_image import SpatialImage # type: ignore


from datatree import DataTree
from xarray import DataTree

from ._xarray import _downsample_xarray_coarsen
from ._itk import (
Expand Down Expand Up @@ -184,6 +184,6 @@ def to_multiscale(
label="mode",
)

multiscale = DataTree.from_dict(d=data_objects)
multiscale = DataTree.from_dict(data_objects)

return multiscale
3,477 changes: 1,762 additions & 1,715 deletions pixi.lock

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ classifiers = [
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
]
keywords = [
"itk",
Expand All @@ -28,18 +27,17 @@ keywords = [
"zarr",
"dask",
"imaging",
"visualization",
"visualization"
]
dynamic = ["version"]

requires-python = ">=3.8"
requires-python = ">=3.10"
dependencies = [
"numpy",
"dask",
"python-dateutil",
"spatial_image>=0.2.1",
"xarray",
"xarray-datatree>=0.0.5",
"xarray>=2024.10.0",
"zarr",
]

Expand Down Expand Up @@ -71,7 +69,7 @@ dask-image = [
imagej = [
"pyimagej",
]
notebooks = ["matplotlib>=3.9.1,<4", "ome-types>=0.5.1.post1,<0.6", "tqdm>=4.66.4,<5"]
notebooks = ["matplotlib>=3.9.2,<4", "ome-types>=0.5.1.post1,<0.6", "tqdm>=4.66.4,<5"]

[tool.black]
line-length = 88
Expand Down Expand Up @@ -99,21 +97,21 @@ lint = { features = ["lint"], no-default-feature = true, solve-group = "default"
test = { cmd = "pytest", description = "Run the test suite" }

[tool.pixi.feature.test.dependencies]
python = "3.9.*"
python = "3.10.*"

[tool.pixi.feature.notebooks.dependencies]
openjdk = "8.*"
maven = ">=3.9.8,<3.10"
jupyterlab = ">=4.2.4,<4.3"
python = "3.9.*"
python = "3.10.*"

[tool.pixi.feature.notebooks.tasks]
init-imagej = { cmd = "python3 -c \"import imagej; ij = imagej.init('2.15.0'); print(ij.getVersion())\"", description = "Initialize the python imagej installation" }
test-notebooks = { cmd = "pytest --nbmake --nbmake-timeout=3000 examples/ConvertImageioImageResource.ipynb examples/ConvertITKImage.ipynb examples/ConvertPyImageJDataset.ipynb examples/ConvertTiffFile.ipynb examples/HelloMultiscaleSpatialImageWorld.ipynb", depends-on = ["init-imagej"], description = "Test the notebooks" }
dev-notebooks = { cmd = "jupyter lab examples", description = "Start Jupyter Lab" }

[tool.pixi.feature.data.dependencies]
python = ">=3.9.19,<4"
python = ">=3.10.0,<4"
pooch = ">=1.8.2,<2"

[tool.pixi.feature.data.tasks]
Expand Down
3 changes: 1 addition & 2 deletions test/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pooch
from zarr.storage import DirectoryStore
import xarray as xr
from datatree import open_datatree

test_data_ipfs_cid = "bafybeiaskr5fxg6rbcwlxl6ibzqhubdleacenrpbnymc6oblwoi7ceqzta"
test_data_sha256 = "507dd779cba007c46ea68a5fe8865cabd5d8a7e00816470faae9195d1f1c3cd1"
Expand Down Expand Up @@ -58,7 +57,7 @@ def verify_against_baseline(dataset_name, baseline_name, multiscale):
test_data_dir / f"baseline/{dataset_name}/{baseline_name}",
dimension_separator="/",
)
dt = open_datatree(store, engine="zarr", mode="r")
dt = xr.open_datatree(store, engine="zarr", mode="r")
xr.testing.assert_equal(dt.ds, multiscale.ds)
for scale in multiscale.children:
xr.testing.assert_equal(dt[scale].ds, multiscale[scale].ds)
Expand Down
2 changes: 1 addition & 1 deletion test/test_ngff_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from referencing import Registry, Resource
from jsonschema import Draft202012Validator

from datatree import DataTree
from xarray import DataTree

from multiscale_spatial_image import to_multiscale, MultiscaleSpatialImage
from spatial_image import to_spatial_image
Expand Down

0 comments on commit 05c5696

Please sign in to comment.