tiffslide_xarray


Nametiffslide_xarray JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/swamidasslab/tiffslide-xarray
SummaryXarray extension that uses xarray to lazy read 2D Tiff files.
upload_time2023-11-13 15:35:36
maintainer
docs_urlNone
authorS. Joshua Swamidass
requires_python>=3.9,<4.0
license
keywords tiffslide xarray
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TiffSlide-Xarray


A simple integration library between tiffslide and xarray.

## Installation

Install from pypi:

```
pip install tiffslide-xarray
```

## Usage

This library hooks into xarray's extension system as a backend engine. So
it can be used even without importing.

```python
from xarray import open_dataset

slide_level0 = open_dataset("input.svs")
```

The library automatically recoginizes "tiff" and "svs" files. If required,
the "engine" keyword can force usage:

```python
slide_level0 = open_dataset("input.another_extension", engine="tiffslide")
```


Tifflside uses the fsspec and tifffiles packages to open files. Options to these
libraries can be passed using the "storage_options" and "tifffile_options" keyword
arguments.

```python
slide_level0 = open_dataset("s3://input.svs", storage_options={"s3": ... })
```

By default, the level 0 of the the file is read. Other levels can be read by using
the "level" keyword.

```python
slide_level1 = open_dataset("input.svs", level=1)
```

Negative levels are allowed to allow indexing from end of the level array.
```python
slide_level_last = open_dataset("input.svs", level=-1)
```

Opening All Levels
==================

To open all the levels in the slide, use the "open_all" to return a datatree of the 
slide.

```python
from tiffslide_xarray import open_all_levels

slide = open_all_levels(input.svs)
```

The returned datatree places level0 at the root group, and places subsequent
levels at the f"level{n}" group. 


Data and MetaData Model
=======================

The data for each slide is accessible at "image,"

```python
slide_level0.image
slide_level0["image]
```

Coordinates for the x, y and c dimensions are added, in units of "pixels" in the level 0
slide. This makes the cordinates between different levels directly compariable. The library
assumes there are three channels, in the order of (r, g, b). 

```python
>>> slide_level0.x
[0, 1, 2...]
>>> slide_level0.y
[0, 1, 2...]
>>> slide_level0.c
['r', 'g', 'b']
```

All the metadata from the slide is stored in the dataset attributes. The source file name is
added to the metadata of both the 'image' array and the dataset. If found in the metadata, the microns 
per pixel (mpp) is stored in the attributes of the 'x' and 'y' coordinates.

Lazy Loading
============

Slides are lazy loaded which makes the initial open very quick, and
loading of small regions is quick (but not cached). Loading of large regions can be slow. 
To manage this, be sure to call "load" on datasets to bring them into memory
if they will be accessed multiple times.

For example, this code will execute two costly reads:

```python
roi = slide_level1.sel(x=slice(10000, 40000), x=slice(5000, 20000))  # select a large ROI

roi2 = 2.0 * roi   # first read
roi2 = 3.0 * roi   # second read
```

Calling "load" on "roi" or "slide_level1" solves this problem.

```python
roi = slide_level1.sel(x=slice(10000, 40000), x=slice(5000, 20000))  # select a large ROI

roi = roi.load() # load the ROI into memory for subsequent processing.
roi2 = 2.0 * roi   # no read
roi2 = 3.0 * roi   # no read
```

Requesting Feedback
===================

This project currently in alpha to obtain feedback on the API. Please
submit issues or API feature/modification requests to: https://github.com/swamidasslab/tiffslide-xarray.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/swamidasslab/tiffslide-xarray",
    "name": "tiffslide_xarray",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "tiffslide,xarray",
    "author": "S. Joshua Swamidass",
    "author_email": "swamidass@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8f/4c/11cdb968664a2c0caf86b4673f8b5372d9f5434516d0e38b8079deb3c85d/tiffslide_xarray-0.1.tar.gz",
    "platform": null,
    "description": "# TiffSlide-Xarray\n\n\nA simple integration library between tiffslide and xarray.\n\n## Installation\n\nInstall from pypi:\n\n```\npip install tiffslide-xarray\n```\n\n## Usage\n\nThis library hooks into xarray's extension system as a backend engine. So\nit can be used even without importing.\n\n```python\nfrom xarray import open_dataset\n\nslide_level0 = open_dataset(\"input.svs\")\n```\n\nThe library automatically recoginizes \"tiff\" and \"svs\" files. If required,\nthe \"engine\" keyword can force usage:\n\n```python\nslide_level0 = open_dataset(\"input.another_extension\", engine=\"tiffslide\")\n```\n\n\nTifflside uses the fsspec and tifffiles packages to open files. Options to these\nlibraries can be passed using the \"storage_options\" and \"tifffile_options\" keyword\narguments.\n\n```python\nslide_level0 = open_dataset(\"s3://input.svs\", storage_options={\"s3\": ... })\n```\n\nBy default, the level 0 of the the file is read. Other levels can be read by using\nthe \"level\" keyword.\n\n```python\nslide_level1 = open_dataset(\"input.svs\", level=1)\n```\n\nNegative levels are allowed to allow indexing from end of the level array.\n```python\nslide_level_last = open_dataset(\"input.svs\", level=-1)\n```\n\nOpening All Levels\n==================\n\nTo open all the levels in the slide, use the \"open_all\" to return a datatree of the \nslide.\n\n```python\nfrom tiffslide_xarray import open_all_levels\n\nslide = open_all_levels(input.svs)\n```\n\nThe returned datatree places level0 at the root group, and places subsequent\nlevels at the f\"level{n}\" group. \n\n\nData and MetaData Model\n=======================\n\nThe data for each slide is accessible at \"image,\"\n\n```python\nslide_level0.image\nslide_level0[\"image]\n```\n\nCoordinates for the x, y and c dimensions are added, in units of \"pixels\" in the level 0\nslide. This makes the cordinates between different levels directly compariable. The library\nassumes there are three channels, in the order of (r, g, b). \n\n```python\n>>> slide_level0.x\n[0, 1, 2...]\n>>> slide_level0.y\n[0, 1, 2...]\n>>> slide_level0.c\n['r', 'g', 'b']\n```\n\nAll the metadata from the slide is stored in the dataset attributes. The source file name is\nadded to the metadata of both the 'image' array and the dataset. If found in the metadata, the microns \nper pixel (mpp) is stored in the attributes of the 'x' and 'y' coordinates.\n\nLazy Loading\n============\n\nSlides are lazy loaded which makes the initial open very quick, and\nloading of small regions is quick (but not cached). Loading of large regions can be slow. \nTo manage this, be sure to call \"load\" on datasets to bring them into memory\nif they will be accessed multiple times.\n\nFor example, this code will execute two costly reads:\n\n```python\nroi = slide_level1.sel(x=slice(10000, 40000), x=slice(5000, 20000))  # select a large ROI\n\nroi2 = 2.0 * roi   # first read\nroi2 = 3.0 * roi   # second read\n```\n\nCalling \"load\" on \"roi\" or \"slide_level1\" solves this problem.\n\n```python\nroi = slide_level1.sel(x=slice(10000, 40000), x=slice(5000, 20000))  # select a large ROI\n\nroi = roi.load() # load the ROI into memory for subsequent processing.\nroi2 = 2.0 * roi   # no read\nroi2 = 3.0 * roi   # no read\n```\n\nRequesting Feedback\n===================\n\nThis project currently in alpha to obtain feedback on the API. Please\nsubmit issues or API feature/modification requests to: https://github.com/swamidasslab/tiffslide-xarray.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Xarray extension that uses xarray to lazy read 2D Tiff files.",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/swamidasslab/tiffslide-xarray",
        "Repository": "https://github.com/swamidasslab/tiffslide-xarray"
    },
    "split_keywords": [
        "tiffslide",
        "xarray"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cd880f0e43c12f1946bb703edf6999daefca8fbf3acd2aaad185fae6cd7ba32",
                "md5": "8f69dbc4af0f9ae5be92e77903fecf09",
                "sha256": "b2cfee7ffe5bb37fa3ecb24217d70b29788f215553af1c13b28446b89ee288cb"
            },
            "downloads": -1,
            "filename": "tiffslide_xarray-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8f69dbc4af0f9ae5be92e77903fecf09",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 14955,
            "upload_time": "2023-11-13T15:35:34",
            "upload_time_iso_8601": "2023-11-13T15:35:34.753606Z",
            "url": "https://files.pythonhosted.org/packages/6c/d8/80f0e43c12f1946bb703edf6999daefca8fbf3acd2aaad185fae6cd7ba32/tiffslide_xarray-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f4c11cdb968664a2c0caf86b4673f8b5372d9f5434516d0e38b8079deb3c85d",
                "md5": "a2cf34c9486f8d7db91e824ebc3c7f81",
                "sha256": "acc48e9e56926b7792c7d839133b7feec08a4a309e80184e1f0fe643f0393d06"
            },
            "downloads": -1,
            "filename": "tiffslide_xarray-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a2cf34c9486f8d7db91e824ebc3c7f81",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 14243,
            "upload_time": "2023-11-13T15:35:36",
            "upload_time_iso_8601": "2023-11-13T15:35:36.527629Z",
            "url": "https://files.pythonhosted.org/packages/8f/4c/11cdb968664a2c0caf86b4673f8b5372d9f5434516d0e38b8079deb3c85d/tiffslide_xarray-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-13 15:35:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "swamidasslab",
    "github_project": "tiffslide-xarray",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "tiffslide_xarray"
}
        
Elapsed time: 0.16051s