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

pre commit #90

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/notebook-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:

- name: Test notebooks
run: |
pixi run test-notebooks
pixi run test-notebooks
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test

on: [push,pull_request]
on: [push, pull_request]

jobs:
test:
Expand All @@ -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.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -30,4 +30,4 @@ jobs:
if: ${{ matrix.os != 'mac-14' && matrix.package == '3.8' }}
uses: mikepenz/action-junit-report@v2
with:
report_paths: 'junit/test-results*.xml'
report_paths: "junit/test-results*.xml"
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
exclude: (^.pixi/|.snap|pixi.lock)

ci:
autoupdate_commit_msg: "ENH: update pre-commit hooks"
autofix_commit_msg: "STYLE: pre-commit fixes"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-symlinks
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.5"
hooks:
- id: codespell
exclude: examples/

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.9.0.5"
hooks:
- id: shellcheck

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: test/conftest.py
- id: ruff-format
75 changes: 55 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![DOI](https://zenodo.org/badge/379678181.svg)](https://zenodo.org/badge/latestdoi/379678181)

Generate a multiscale, chunked, multi-dimensional spatial image data structure that can serialized to [OME-NGFF].

Each scale is a scientific Python [Xarray] [spatial-image] [Dataset], organized into nodes of an Xarray [Datatree].
Generate a multiscale, chunked, multi-dimensional spatial image data structure
that can serialized to [OME-NGFF].

Each scale is a scientific Python [Xarray] [spatial-image] [Dataset], organized
into nodes of an Xarray [Datatree].

## Installation

Expand All @@ -32,8 +33,8 @@ image = to_spatial_image(array)
print(image)
```

An [Xarray] [spatial-image] [DataArray].
Spatial metadata can also be passed during construction.
An [Xarray] [spatial-image] [DataArray]. Spatial metadata can also be passed
during construction.

```
<xarray.SpatialImage 'image' (y: 128, x: 128)>
Expand Down Expand Up @@ -82,9 +83,11 @@ DataTree('multiscales', parent=None)
image (y, x) uint8 dask.array<chunksize=(16, 16), meta=np.ndarray>
```

Store as an Open Microscopy Environment-Next Generation File Format ([OME-NGFF]) / [netCDF] [Zarr] store.
Store as an Open Microscopy Environment-Next Generation File Format ([OME-NGFF])
/ [netCDF] [Zarr] store.

It is highly recommended to use `dimension_separator='/'` in the construction of the Zarr stores.
It is highly recommended to use `dimension_separator='/'` in the construction of
the Zarr stores.

```python
store = zarr.storage.DirectoryStore('multiscale.zarr', dimension_separator='/')
Expand All @@ -96,26 +99,51 @@ released. We mean it :-).

## Examples

- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FHelloMultiscaleSpatialImageWorld.ipynb) [Hello MultiscaleSpatialImage World!](./examples/HelloMultiscaleSpatialImageWorld.ipynb)
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FConvertITKImage.ipynb) [Convert itk.Image](./examples/ConvertITKImage.ipynb)
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FConvertImageioImageResource.ipynb) [Convert imageio ImageResource](./examples/ConvertImageioImageResource.ipynb)
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FConvertPyImageJDataset.ipynb) [Convert pyimagej Dataset](./examples/ConvertPyImageJDataset.ipynb)
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FHelloMultiscaleSpatialImageWorld.ipynb)
[Hello MultiscaleSpatialImage World!](./examples/HelloMultiscaleSpatialImageWorld.ipynb)
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FConvertITKImage.ipynb)
[Convert itk.Image](./examples/ConvertITKImage.ipynb)
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FConvertImageioImageResource.ipynb)
[Convert imageio ImageResource](./examples/ConvertImageioImageResource.ipynb)
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/spatial-image/multiscale-spatial-image/main?urlpath=lab/tree/examples%2FConvertPyImageJDataset.ipynb)
[Convert pyimagej Dataset](./examples/ConvertPyImageJDataset.ipynb)

## Development

Contributions are welcome and appreciated.

To run the test suite:
### Get the source code

```
```shell
git clone https://github.com/spatial-image/multiscale-spatial-image
cd multiscale-spatial-image
pip install -e ".[test]"
pytest
# Notebook tests
pytest --nbmake --nbmake-timeout=3000 examples/*ipynb
```

### Install dependencies

First install [pixi]. Then, install project dependencies:

```shell
pixi install -a
pixi run pre-commit-install
```

### Run the test suite

The unit tests:

```shell
pixi run -e test test
```

The notebooks tests:

```shell
pixi run test-notebooks
```

### Update test data

To add new or update testing data, such as a new baseline for this block:

```py
Expand Down Expand Up @@ -150,10 +178,15 @@ gzip -9 ../data.tar
python3 -c 'import pooch; print(pooch.file_hash("../data.tar.gz"))'
```

Update the `test_data_sha256` variable in the *test/_data.py* file.
Upload the data to [web3.storage](https://web3.storage).
And update the `test_data_ipfs_cid` [Content Identifier (CID)](https://proto.school/anatomy-of-a-cid/01) variable, which is available in the web3.storage web page interface.
Update the `test_data_sha256` variable in the _test/\_data.py_ file. Upload the
data to [web3.storage](https://web3.storage). And update the
`test_data_ipfs_cid`
[Content Identifier (CID)](https://proto.school/anatomy-of-a-cid/01) variable,
which is available in the web3.storage web page interface.

### Submit the patch

We use the standard [GitHub flow].

[spatial-image]: https://github.com/spatial-image/spatial-image
[Xarray]: https://xarray.pydata.org/en/stable/
Expand All @@ -164,3 +197,5 @@ And update the `test_data_ipfs_cid` [Content Identifier (CID)](https://proto.sch
[Zarr]: https://zarr.readthedocs.io/en/stable/
[Dask]: https://docs.dask.org/en/stable/array.html
[netCDF]: https://www.unidata.ucar.edu/software/netcdf/
[pixi]: https://pixi.sh
[GitHub flow]: https://docs.github.com/en/get-started/using-github/github-flow
2 changes: 1 addition & 1 deletion multiscale_spatial_image/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present NumFOCUS <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = '1.0.0'
__version__ = "1.0.0"
13 changes: 6 additions & 7 deletions multiscale_spatial_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

Generate a multiscale spatial image."""


__all__ = [
"MultiscaleSpatialImage",
"Methods",
"to_multiscale",
"itk_image_to_multiscale",
"__version__",
"MultiscaleSpatialImage",
"Methods",
"to_multiscale",
"itk_image_to_multiscale",
"__version__",
]

from .__about__ import __version__
from .multiscale_spatial_image import MultiscaleSpatialImage
from .to_multiscale import Methods, to_multiscale, itk_image_to_multiscale
from .to_multiscale import Methods, to_multiscale, itk_image_to_multiscale
5 changes: 1 addition & 4 deletions multiscale_spatial_image/multiscale_spatial_image.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from typing import Union, List
from typing import Union

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


Expand Down
4 changes: 3 additions & 1 deletion multiscale_spatial_image/to_multiscale/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .to_multiscale import Methods, to_multiscale
from .to_multiscale import Methods, to_multiscale
from .itk_image_to_multiscale import itk_image_to_multiscale

__all__ = ["Methods", "to_multiscale", "itk_image_to_multiscale"]
Loading
Loading