# spatial-image
[![Test](https://github.com/spatial-image/spatial-image/actions/workflows/test.yml/badge.svg)](https://github.com/spatial-image/spatial-image/actions/workflows/test.yml)
[![DOI](https://zenodo.org/badge/234798632.svg)](https://zenodo.org/badge/latestdoi/234798632)
A multi-dimensional spatial image data structure for scientific Python.
To facilitate:
- Multi-scale processing and analysis
- Registration
- Resampling
- Subregion parallel processing
- Coupling with meshes, point sets, and annotations
with scientific images, which are typically multi-dimensional with anisotropic
sampling, this package provides a spatial-image data structure. In addition to
an N-dimensional array of pixel values, spatial metadata defines the location
of the pixel sampling grid in space time. We also label the array dimensions.
This metadata is easily utilized and elegantly carried through image
processing pipelines.
This package defines spatial image metadata, provides a function,
`is_spatial_image`, to verify the expected behavior of a spatial image
instance, and provides a reference function, `to_spatial_image` to convert an
array-like, e.g. a [NumPy
ndarray](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html)
or a [Dask array](https://docs.dask.org/en/latest/array.html), to a spatial
image.
The spatial-image data structure is implemented with [Xarray], a library for
N-D labeled arrays and datasets in Python. The Xarray library is well-tested,
relatively mature, and integrates well with scientific Python ecosystem
tooling. The Xarray library leverages [NumPy](https://numpy.org/) and
[pandas](https://pandas.pydata.org/) for labeled array indexing, integrates
well with machine-learning libraries utilizing the
[scikit-learn](https://scikit-learn.org/) interface, integrates with
[Dask](https://dask.org) for distributed computing, and
[zarr](https://zarr.readthedocs.io/) for serialization.
In essence, a spatial image is an
[`xarray.DataArray`](https://xarray.pydata.org/en/stable/data-structures.html#dataarray)
with a defined set of [`dims`] labels, `{'c', 'x', 'y', 'z', 't'}`,
constraints on the [`coords`], to enforce uniform spacing in a given
direction, and defined set of additional metadata [`attrs`].
## Installation
```
pip install spatial-image
```
## Definitions
### Data Dimensions
A spatial image's xarray [`dims`] belong to the set: `{'c', 'x', 'y', 'z', 't'}`. These dimensions are:
<dl>
<dt>c</dt>
<dd>Component / channel dimension.</dd>
<dt>x</dt>
<dd>First spatial dimension.</dd>
<dt>y</dt>
<dd>Second spatial dimension.</dd>
<dt>z</dt>
<dd>Third spatial dimension.</dd>
<dt>t</dt>
<dd>Time dimension.</dd>
</dl>
### Axis attributes
Each `dim` has an axis with additional attributes to describe the dimension.
<dl>
<dt>long_name</dt>
<dd>A descriptive name for the axis, e.g. <i>anterior-posterior</i> or <i>x-axis</i>. Defaults to the dim name.</dd>
<dt>units</dt>
<dd>Units for the axis, e.g. <i>millimeters</i>. Defaults to the empty string.</dd>
</dl>
### Coordinates
A spatial image's Xarray [`coords`] specify the spatial location of pixels in
the image for the `'x'`, `'y'`, and `'z'` data dimensions. For the `'c'` and
`'t'` data dimensions, component identities and timestamps can optionally
be provided.
Spatial coordinates define the position *in the coordinate reference frame of
the image*. In general, the image's coordinate reference frame may be
different from the world coordinate reference frame.
Pixels are sampled on a uniform, possibly anisotropic, spatial grid. Spatial
coordinates have a 64-bit float type. The difference between adjacent
coordinates, i.e. the pixel *spacing*, for a dimension must be uniform. The
first coordinate value defines the *origin* or *offset* of an image.
The component or channel dimension coordinates defaults to a sequence of
integer identifiers but can be strings describing the channels, e.g. ['r',
'g', 'b'].
The time coordinates can have integer, float, or [`datetime64`] type.
### Motivational Notes
* Image-axis-aligned Cartesian coordinate reference frames enable Pythonic subscripting in processing pipelines on `xarray.DataArray`'s. When indexing with slices, the same slices are applied to the multi-dimensional pixel array as the 1-D coordinate arrays, and the result is valid.
* Regular coordinate spacing enables processing optimizations, both algorithmically and computationally.
## Development
Contributions are welcome and appreciated.
To run the test suite:
```
git clone https://github.com/spatial-image/spatial-image
cd spatial-image
pip install -e ".[test]"
pytest
```
[Xarray]: https://xarray.pydata.org/en/stable/
[`dims`]: https://xarray.pydata.org/en/stable/terminology.html
[`coords`]: https://xarray.pydata.org/en/stable/terminology.html
[`attrs`]: https://xarray.pydata.org/en/stable/data-structures.html
[`datetime64`]: https://docs.scipy.org/doc/numpy/reference/arrays.datetime.html
Raw data
{
"_id": null,
"home_page": "https://github.com/spatial-image/spatial-image",
"name": "spatial-image",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Matt McCormick",
"author_email": "matt.mccormick@kitware.com",
"download_url": "https://files.pythonhosted.org/packages/61/68/7a5b2711c84d4ce5a129555c41a43f05d275ec68aed883ca9633b25f6dfb/spatial_image-1.1.0.tar.gz",
"platform": null,
"description": "# spatial-image\n\n[![Test](https://github.com/spatial-image/spatial-image/actions/workflows/test.yml/badge.svg)](https://github.com/spatial-image/spatial-image/actions/workflows/test.yml)\n[![DOI](https://zenodo.org/badge/234798632.svg)](https://zenodo.org/badge/latestdoi/234798632)\n\nA multi-dimensional spatial image data structure for scientific Python.\n\nTo facilitate:\n\n- Multi-scale processing and analysis\n- Registration\n- Resampling\n- Subregion parallel processing\n- Coupling with meshes, point sets, and annotations\n\nwith scientific images, which are typically multi-dimensional with anisotropic\nsampling, this package provides a spatial-image data structure. In addition to\nan N-dimensional array of pixel values, spatial metadata defines the location\nof the pixel sampling grid in space time. We also label the array dimensions.\nThis metadata is easily utilized and elegantly carried through image\nprocessing pipelines.\n\nThis package defines spatial image metadata, provides a function,\n`is_spatial_image`, to verify the expected behavior of a spatial image\ninstance, and provides a reference function, `to_spatial_image` to convert an\narray-like, e.g. a [NumPy\nndarray](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html)\nor a [Dask array](https://docs.dask.org/en/latest/array.html), to a spatial\nimage.\n\nThe spatial-image data structure is implemented with [Xarray], a library for\nN-D labeled arrays and datasets in Python. The Xarray library is well-tested,\nrelatively mature, and integrates well with scientific Python ecosystem\ntooling. The Xarray library leverages [NumPy](https://numpy.org/) and\n[pandas](https://pandas.pydata.org/) for labeled array indexing, integrates\nwell with machine-learning libraries utilizing the\n[scikit-learn](https://scikit-learn.org/) interface, integrates with\n[Dask](https://dask.org) for distributed computing, and\n[zarr](https://zarr.readthedocs.io/) for serialization.\n\nIn essence, a spatial image is an\n[`xarray.DataArray`](https://xarray.pydata.org/en/stable/data-structures.html#dataarray)\nwith a defined set of [`dims`] labels, `{'c', 'x', 'y', 'z', 't'}`,\nconstraints on the [`coords`], to enforce uniform spacing in a given\ndirection, and defined set of additional metadata [`attrs`].\n\n## Installation\n\n```\npip install spatial-image\n```\n\n## Definitions\n\n### Data Dimensions\n\nA spatial image's xarray [`dims`] belong to the set: `{'c', 'x', 'y', 'z', 't'}`. These dimensions are:\n\n<dl>\n <dt>c</dt>\n <dd>Component / channel dimension.</dd>\n <dt>x</dt>\n <dd>First spatial dimension.</dd>\n <dt>y</dt>\n <dd>Second spatial dimension.</dd>\n <dt>z</dt>\n <dd>Third spatial dimension.</dd>\n <dt>t</dt>\n <dd>Time dimension.</dd>\n</dl>\n\n### Axis attributes\n\nEach `dim` has an axis with additional attributes to describe the dimension.\n\n<dl>\n <dt>long_name</dt>\n <dd>A descriptive name for the axis, e.g. <i>anterior-posterior</i> or <i>x-axis</i>. Defaults to the dim name.</dd>\n <dt>units</dt>\n <dd>Units for the axis, e.g. <i>millimeters</i>. Defaults to the empty string.</dd>\n</dl>\n\n### Coordinates\n\nA spatial image's Xarray [`coords`] specify the spatial location of pixels in\nthe image for the `'x'`, `'y'`, and `'z'` data dimensions. For the `'c'` and\n`'t'` data dimensions, component identities and timestamps can optionally\nbe provided.\n\nSpatial coordinates define the position *in the coordinate reference frame of\nthe image*. In general, the image's coordinate reference frame may be\ndifferent from the world coordinate reference frame.\n\nPixels are sampled on a uniform, possibly anisotropic, spatial grid. Spatial\ncoordinates have a 64-bit float type. The difference between adjacent\ncoordinates, i.e. the pixel *spacing*, for a dimension must be uniform. The\nfirst coordinate value defines the *origin* or *offset* of an image.\n\nThe component or channel dimension coordinates defaults to a sequence of\ninteger identifiers but can be strings describing the channels, e.g. ['r',\n'g', 'b'].\n\nThe time coordinates can have integer, float, or [`datetime64`] type.\n\n### Motivational Notes\n\n* Image-axis-aligned Cartesian coordinate reference frames enable Pythonic subscripting in processing pipelines on `xarray.DataArray`'s. When indexing with slices, the same slices are applied to the multi-dimensional pixel array as the 1-D coordinate arrays, and the result is valid.\n\n* Regular coordinate spacing enables processing optimizations, both algorithmically and computationally.\n\n\n## Development\n\nContributions are welcome and appreciated.\n\nTo run the test suite:\n\n```\ngit clone https://github.com/spatial-image/spatial-image\ncd spatial-image\npip install -e \".[test]\"\npytest\n```\n\n[Xarray]: https://xarray.pydata.org/en/stable/\n[`dims`]: https://xarray.pydata.org/en/stable/terminology.html\n[`coords`]: https://xarray.pydata.org/en/stable/terminology.html\n[`attrs`]: https://xarray.pydata.org/en/stable/data-structures.html\n[`datetime64`]: https://docs.scipy.org/doc/numpy/reference/arrays.datetime.html\n\n",
"bugtrack_url": null,
"license": null,
"summary": "spatial-image",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/spatial-image/spatial-image"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10e5134cfa437c0d87ce33b28b593a9990ceb4dd425e104c8da3efc299dccc55",
"md5": "dbf2a90e00224c258b85f2e06adac4d1",
"sha256": "f7f9b89e20ced35ee50efb588399d384d44c8242bee686a2e8add2fc9ab3ef56"
},
"downloads": -1,
"filename": "spatial_image-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dbf2a90e00224c258b85f2e06adac4d1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8004,
"upload_time": "2024-06-13T19:54:57",
"upload_time_iso_8601": "2024-06-13T19:54:57.757176Z",
"url": "https://files.pythonhosted.org/packages/10/e5/134cfa437c0d87ce33b28b593a9990ceb4dd425e104c8da3efc299dccc55/spatial_image-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "61687a5b2711c84d4ce5a129555c41a43f05d275ec68aed883ca9633b25f6dfb",
"md5": "e2e79a89fdc7c6b319f721c0c09a54ac",
"sha256": "e7fb185644093e96cac510c4184f2777b965b5a7ca25688f379e9acb48e3e07d"
},
"downloads": -1,
"filename": "spatial_image-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "e2e79a89fdc7c6b319f721c0c09a54ac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 12253,
"upload_time": "2024-06-13T19:54:58",
"upload_time_iso_8601": "2024-06-13T19:54:58.738204Z",
"url": "https://files.pythonhosted.org/packages/61/68/7a5b2711c84d4ce5a129555c41a43f05d275ec68aed883ca9633b25f6dfb/spatial_image-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-13 19:54:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "spatial-image",
"github_project": "spatial-image",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "spatial-image"
}