intake_io.util
Module Contents
Functions
|
Get axis order given image, shape or number of dimensions. |
|
|
|
Get pixel spacing of image or specific image axes. |
|
Get pixel spacing unit of image or specific image axes. |
|
Get pixel array of image. |
|
Combine inputs to xarray.DataArray. |
|
Get catalog yml of data sources. |
|
|
|
Utility function to clean YAML representation of intake source. |
- intake_io.util.get_axes(x: Any) str
Get axis order given image, shape or number of dimensions.
Supported axes Name
Dimension
i
image index
t
time
c
channel
z
z
y
y
x
x
Uses metadata where available (xarray data structures), otherwise assumes itczyx-ordering (intake_io default) using the last ndim axes. The only exception are 2D RGB images, which may be cyx or yxc.
- intake_io.util.get_spatial_axes(x: Any)
- intake_io.util.get_spacing(image: Union[xarray.Dataset, xarray.DataArray], axes: Optional[str] = None) Union[Tuple[Optional[float], Ellipsis], Optional[float]]
Get pixel spacing of image or specific image axes.
The return value for an axis without spacing metadata is either None or 1.0, depending on what format the image was loaded from. None is preferred.
- Parameters
image – Image
axes – Specific axes and ordering, or None for all axes in image dim order.
- Returns
Pixel spacing as tuple, or directly if a single axis is requested.
- intake_io.util.get_spacing_units(image: Union[xarray.Dataset, xarray.DataArray], axes: Optional[str] = None) Union[Tuple[Optional[str], Ellipsis], Optional[str]]
Get pixel spacing unit of image or specific image axes.
The return value for an axis without spacing metadata is None.
- Parameters
image – Image
axes – Specific axes and ordering, or None for all axes in image dim order.
- Returns
Pixel spacing units as tuple, or directly if a single axis is requested.
- intake_io.util.to_numpy(image: Union[xarray.Dataset, xarray.DataArray, numpy.ndarray]) numpy.ndarray
Get pixel array of image.
- Parameters
image – Image
- Returns
Array
- intake_io.util.to_xarray(image: Any, spacing: Union[Dict[str, Optional[float]], Tuple[Optional[float], Ellipsis], None] = None, axes: Optional[str] = None, coords: Optional[Dict[str, Any]] = None, spacing_units: Union[Dict[str, Optional[str]], Tuple[Optional[str], Ellipsis], None] = None, name: Optional[str] = None, attrs: Optional[Dict[str, Any]] = None, partition: Optional[Any] = None) xarray.DataArray
Combine inputs to xarray.DataArray.
Preserve metadata where available and possible.
- Parameters
image – The image.
spacing – Time resolution and pixel spacing, as dict (axes are keys) or tuple (in image axes order, ignoring the discontinuous axes “c” and “i”). Axes without pixel spacing metadata can be omitted (dict) or set to None (dict and tuple).
axes – The image axes, e.g. “tyz”.
coords – Axis coordinates for axes not covered by the spacing parameter (e.g. channel names), or to overwrite the spacing parameter with e.g. non-uniform spacing values.
spacing_units – Time resolution and pixel spacing units, as dict (axes are keys) or tuple (in image axes order, ignoring the discontinuous axes “c” and “i”). Axes without pixel spacing metadata can be omitted (dict) or set to None (dict and tuple).
name – Name
attrs – Additional metadata
partition – Partition
- Returns
Image and any metadata
- intake_io.util.get_catalog(sources: Iterable[intake.source.DataSource], filepath: Optional[str] = None) str
Get catalog yml of data sources.
- Parameters
sources – Data sources
filepath – File path to save catalog to, or None if saving the result to file is not intended.
- Returns
The yml text
- intake_io.util.partition_gen(image: Union[xarray.DataArray, xarray.Dataset], inner_axes: str, uri: str, multikey: bool = False, sep_outer: str = '.', sep_inner: str = '_') Generator[Tuple[Union[xarray.DataArray, xarray.Dataset], str], None, None]