xarray-ome-ngff


Namexarray-ome-ngff JSON
Version 2.2.0 PyPI version JSON
download
home_pageNone
Summaryxarray and ome-ngff
upload_time2024-05-09 20:45:51
maintainerNone
docs_urlNone
authorDavis Vann Bennett
requires_python<4.0,>=3.9
licenseNone
keywords
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": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Davis Vann Bennett",
    "author_email": "davis.v.bennett@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/45/42/1829e0a0dc916efd44ad1b7731052aaa069c226b2e26a6fca960eb0673b2/xarray_ome_ngff-2.2.0.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": "2.2.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2eb288d68b6c56e07550f26be4f48490a9d08f09ccd2daea9a1fafd5492da6bf",
                "md5": "587b2e0e1704ee959d49a96e2cebd4dd",
                "sha256": "8c8b56e57a95d7dd0aef5e9ee2ca5775c692828edb6769267a8b1056bbaf47e7"
            },
            "downloads": -1,
            "filename": "xarray_ome_ngff-2.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "587b2e0e1704ee959d49a96e2cebd4dd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 13294,
            "upload_time": "2024-05-09T20:45:49",
            "upload_time_iso_8601": "2024-05-09T20:45:49.650115Z",
            "url": "https://files.pythonhosted.org/packages/2e/b2/88d68b6c56e07550f26be4f48490a9d08f09ccd2daea9a1fafd5492da6bf/xarray_ome_ngff-2.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45421829e0a0dc916efd44ad1b7731052aaa069c226b2e26a6fca960eb0673b2",
                "md5": "7c8698711bf6ae2b210c8fa370c1d969",
                "sha256": "4fac0d74402051a7cfe5fe123889c9569a7df03bc6ecc8dac34770c8793d1ec2"
            },
            "downloads": -1,
            "filename": "xarray_ome_ngff-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7c8698711bf6ae2b210c8fa370c1d969",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 12611,
            "upload_time": "2024-05-09T20:45:51",
            "upload_time_iso_8601": "2024-05-09T20:45:51.556823Z",
            "url": "https://files.pythonhosted.org/packages/45/42/1829e0a0dc916efd44ad1b7731052aaa069c226b2e26a6fca960eb0673b2/xarray_ome_ngff-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-09 20:45:51",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "xarray-ome-ngff"
}
        
Elapsed time: 0.31651s