Name | xarray-ome-ngff JSON |
Version |
3.1.1
JSON |
| download |
home_page | None |
Summary | Xarray and OME-NGFF |
upload_time | 2024-09-10 09:06:59 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
ngff
xarray
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# xarray-ome-ngff
Integrating [Xarray](https://docs.xarray.dev/en/stable/) with [OME-NGFF](https://ngff.openmicroscopy.org/).
## Help
See [documentation](https://janeliascicomp.github.io/xarray-ome-ngff/) for more details
## Usage
### Read OME-NGFF data
```python
import zarr
from xarray_ome_ngff import read_multiscale_group, DaskArrayWrapper
group = zarr.open_group("https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr")
# this ensures that we create a Dask array, which gives us lazy loading
array_wrapper = DaskArrayWrapper(chunks=10)
arrays = read_multiscale_group(group, array_wrapper=array_wrapper)
print(arrays)
"""
{'0': <xarray.DataArray 'array-bb42996937dbff7600e0481e2b1572cc' (c: 2, z: 236,
y: 275, x: 271)>
dask.array<array, shape=(2, 236, 275, 271), dtype=uint16, chunksize=(2, 10, 10, 10), chunktype=numpy.ndarray>
Coordinates:
* c (c) float64 0.0 1.0
* z (z) float64 0.0 0.5002 1.0 1.501 2.001 ... 116.0 116.5 117.0 117.5
* y (y) float64 0.0 0.3604 0.7208 1.081 ... 97.67 98.03 98.39 98.75
* x (x) float64 0.0 0.3604 0.7208 1.081 ... 96.23 96.59 96.95 97.31, '1': <xarray.DataArray 'array-2bfe6d4a6d289444ca93aa84fcb36342' (c: 2, z: 236,
y: 137, x: 135)>
dask.array<array, shape=(2, 236, 137, 135), dtype=uint16, chunksize=(2, 10, 10, 10), chunktype=numpy.ndarray>
Coordinates:
* c (c) float64 0.0 1.0
* z (z) float64 0.0 0.5002 1.0 1.501 2.001 ... 116.0 116.5 117.0 117.5
* y (y) float64 0.0 0.7208 1.442 2.162 ... 95.87 96.59 97.31 98.03
* x (x) float64 0.0 0.7208 1.442 2.162 ... 94.42 95.15 95.87 96.59, '2': <xarray.DataArray 'array-80c5fc67c0c57909c0a050656a5ab630' (c: 2, z: 236,
y: 68, x: 67)>
dask.array<array, shape=(2, 236, 68, 67), dtype=uint16, chunksize=(2, 10, 10, 10), chunktype=numpy.ndarray>
Coordinates:
* c (c) float64 0.0 1.0
* z (z) float64 0.0 0.5002 1.0 1.501 2.001 ... 116.0 116.5 117.0 117.5
* y (y) float64 0.0 1.442 2.883 4.325 5.766 ... 92.26 93.7 95.15 96.59
* x (x) float64 0.0 1.442 2.883 4.325 5.766 ... 90.82 92.26 93.7 95.15}
"""
```
### Create OME-NGFF data
```python
import numpy as np
from xarray import DataArray
from xarray_ome_ngff import create_multiscale_group
from zarr import MemoryStore
base_array = DataArray(
np.zeros((10,10), dtype='uint8'),
coords={
'x': DataArray(np.arange(-5,5) * 3, dims=('x',), attrs={'units': 'meter'}),
'y': DataArray(np.arange(-10, 0) * 3, dims=('y',), attrs={'units': 'meter'})
})
# create a little multiscale pyramid
arrays = {
's0': base_array,
's1': base_array.coarsen({'x': 2, 'y': 2}, boundary='trim').mean().astype(base_array.dtype)
}
# This example uses in-memory storage, but you can use a
# different store class from `zarr`
store = MemoryStore()
group = create_multiscale_group(store=store, path='my_group', arrays=arrays)
print(group.attrs.asdict())
"""
{
'multiscales': (
{
'version': '0.4',
'name': None,
'type': None,
'metadata': None,
'datasets': (
{
'path': 's0',
'coordinateTransformations': (
{'type': 'scale', 'scale': (3.0, 3.0)},
{'type': 'translation', 'translation': (-15.0, -30.0)},
),
},
{
'path': 's1',
'coordinateTransformations': (
{'type': 'scale', 'scale': (6.0, 6.0)},
{'type': 'translation', 'translation': (-13.5, -28.5)},
),
},
),
'axes': (
{'name': 'x', 'type': 'space', 'unit': 'meter'},
{'name': 'y', 'type': 'space', 'unit': 'meter'},
),
'coordinateTransformations': None,
},
)
}
"""
# check that the arrays are there
print(tuple(group.arrays()))
"""
(('s0', <zarr.core.Array '/my_group/s0' (10, 10) uint8>), ('s1', <zarr.core.Array '/my_group/s1' (5, 5) uint8>))
"""
# write data to the arrays
for path, array in arrays.items():
group[path][:] = array.data
```
Raw data
{
"_id": null,
"home_page": null,
"name": "xarray-ome-ngff",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "ngff, xarray",
"author": null,
"author_email": "Davis Vann Bennett <davis.v.bennett@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/db/3e/528a61df20598c31e7ec7e5a98a50fcdd9431475f35e180f74fb1fe510b8/xarray_ome_ngff-3.1.1.tar.gz",
"platform": null,
"description": "# xarray-ome-ngff\n\nIntegrating [Xarray](https://docs.xarray.dev/en/stable/) with [OME-NGFF](https://ngff.openmicroscopy.org/).\n\n## Help\nSee [documentation](https://janeliascicomp.github.io/xarray-ome-ngff/) for more details\n\n## Usage\n\n### Read OME-NGFF data\n\n```python\nimport zarr\nfrom xarray_ome_ngff import read_multiscale_group, DaskArrayWrapper\ngroup = zarr.open_group(\"https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr\")\n\n# this ensures that we create a Dask array, which gives us lazy loading\narray_wrapper = DaskArrayWrapper(chunks=10)\narrays = read_multiscale_group(group, array_wrapper=array_wrapper)\nprint(arrays)\n\"\"\"\n{'0': <xarray.DataArray 'array-bb42996937dbff7600e0481e2b1572cc' (c: 2, z: 236,\n y: 275, x: 271)>\ndask.array<array, shape=(2, 236, 275, 271), dtype=uint16, chunksize=(2, 10, 10, 10), chunktype=numpy.ndarray>\nCoordinates:\n * c (c) float64 0.0 1.0\n * z (z) float64 0.0 0.5002 1.0 1.501 2.001 ... 116.0 116.5 117.0 117.5\n * y (y) float64 0.0 0.3604 0.7208 1.081 ... 97.67 98.03 98.39 98.75\n * x (x) float64 0.0 0.3604 0.7208 1.081 ... 96.23 96.59 96.95 97.31, '1': <xarray.DataArray 'array-2bfe6d4a6d289444ca93aa84fcb36342' (c: 2, z: 236,\n y: 137, x: 135)>\ndask.array<array, shape=(2, 236, 137, 135), dtype=uint16, chunksize=(2, 10, 10, 10), chunktype=numpy.ndarray>\nCoordinates:\n * c (c) float64 0.0 1.0\n * z (z) float64 0.0 0.5002 1.0 1.501 2.001 ... 116.0 116.5 117.0 117.5\n * y (y) float64 0.0 0.7208 1.442 2.162 ... 95.87 96.59 97.31 98.03\n * x (x) float64 0.0 0.7208 1.442 2.162 ... 94.42 95.15 95.87 96.59, '2': <xarray.DataArray 'array-80c5fc67c0c57909c0a050656a5ab630' (c: 2, z: 236,\n y: 68, x: 67)>\ndask.array<array, shape=(2, 236, 68, 67), dtype=uint16, chunksize=(2, 10, 10, 10), chunktype=numpy.ndarray>\nCoordinates:\n * c (c) float64 0.0 1.0\n * z (z) float64 0.0 0.5002 1.0 1.501 2.001 ... 116.0 116.5 117.0 117.5\n * y (y) float64 0.0 1.442 2.883 4.325 5.766 ... 92.26 93.7 95.15 96.59\n * x (x) float64 0.0 1.442 2.883 4.325 5.766 ... 90.82 92.26 93.7 95.15}\n\"\"\"\n```\n\n### Create OME-NGFF data\n\n```python\nimport numpy as np\nfrom xarray import DataArray\nfrom xarray_ome_ngff import create_multiscale_group\nfrom zarr import MemoryStore\n\nbase_array = DataArray(\n np.zeros((10,10), dtype='uint8'),\n coords={\n 'x': DataArray(np.arange(-5,5) * 3, dims=('x',), attrs={'units': 'meter'}),\n 'y': DataArray(np.arange(-10, 0) * 3, dims=('y',), attrs={'units': 'meter'})\n })\n\n# create a little multiscale pyramid\narrays = {\n 's0': base_array,\n 's1': base_array.coarsen({'x': 2, 'y': 2}, boundary='trim').mean().astype(base_array.dtype)\n}\n\n# This example uses in-memory storage, but you can use a \n# different store class from `zarr`\nstore = MemoryStore()\n\ngroup = create_multiscale_group(store=store, path='my_group', arrays=arrays)\nprint(group.attrs.asdict())\n\"\"\"\n{\n 'multiscales': (\n {\n 'version': '0.4',\n 'name': None,\n 'type': None,\n 'metadata': None,\n 'datasets': (\n {\n 'path': 's0',\n 'coordinateTransformations': (\n {'type': 'scale', 'scale': (3.0, 3.0)},\n {'type': 'translation', 'translation': (-15.0, -30.0)},\n ),\n },\n {\n 'path': 's1',\n 'coordinateTransformations': (\n {'type': 'scale', 'scale': (6.0, 6.0)},\n {'type': 'translation', 'translation': (-13.5, -28.5)},\n ),\n },\n ),\n 'axes': (\n {'name': 'x', 'type': 'space', 'unit': 'meter'},\n {'name': 'y', 'type': 'space', 'unit': 'meter'},\n ),\n 'coordinateTransformations': None,\n },\n )\n}\n\"\"\"\n\n# check that the arrays are there\nprint(tuple(group.arrays()))\n\"\"\"\n(('s0', <zarr.core.Array '/my_group/s0' (10, 10) uint8>), ('s1', <zarr.core.Array '/my_group/s1' (5, 5) uint8>))\n\"\"\"\n\n# write data to the arrays\nfor path, array in arrays.items():\n group[path][:] = array.data\n```",
"bugtrack_url": null,
"license": null,
"summary": "Xarray and OME-NGFF",
"version": "3.1.1",
"project_urls": {
"Documentation": "https://janeliascicomp.github.io/xarray-ome-ngff",
"Issues": "https://github.com/janeliascicomp/xarray-ome-ngff/issues",
"Source": "https://github.com/janeliascicomp/xarray-ome-ngff"
},
"split_keywords": [
"ngff",
" xarray"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4565a733c9f1c28cfa50ec566cdb09f5040304db52e121dfd5dd6ed46454c473",
"md5": "40fd96efe38a81d65486f844439bec95",
"sha256": "7b30286c249bbf7ffbb2ab4240ca5af03fd7b27a37ecf9e6220be51d16cc179b"
},
"downloads": -1,
"filename": "xarray_ome_ngff-3.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "40fd96efe38a81d65486f844439bec95",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 15134,
"upload_time": "2024-09-10T09:06:57",
"upload_time_iso_8601": "2024-09-10T09:06:57.892145Z",
"url": "https://files.pythonhosted.org/packages/45/65/a733c9f1c28cfa50ec566cdb09f5040304db52e121dfd5dd6ed46454c473/xarray_ome_ngff-3.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "db3e528a61df20598c31e7ec7e5a98a50fcdd9431475f35e180f74fb1fe510b8",
"md5": "b4bcb881023fb569fbfea25a3ae17ef7",
"sha256": "b0a012f32de7517f96bf7be37a913f1c69beb12b727806ed4f761ab3cdf9a182"
},
"downloads": -1,
"filename": "xarray_ome_ngff-3.1.1.tar.gz",
"has_sig": false,
"md5_digest": "b4bcb881023fb569fbfea25a3ae17ef7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 23403,
"upload_time": "2024-09-10T09:06:59",
"upload_time_iso_8601": "2024-09-10T09:06:59.396996Z",
"url": "https://files.pythonhosted.org/packages/db/3e/528a61df20598c31e7ec7e5a98a50fcdd9431475f35e180f74fb1fe510b8/xarray_ome_ngff-3.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-10 09:06:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "janeliascicomp",
"github_project": "xarray-ome-ngff",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "xarray-ome-ngff"
}