Skip to content

Commit

Permalink
Merge pull request #90 from thewtex/pre-commit
Browse files Browse the repository at this point in the history
pre commit
  • Loading branch information
thewtex committed Jul 22, 2024
2 parents aef9c3c + ef65ae8 commit 18213a0
Show file tree
Hide file tree
Showing 22 changed files with 953 additions and 331 deletions.
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 <info@numfocus.org>
#
# 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

0 comments on commit 18213a0

Please sign in to comment.