Tiled

Image tiling module

class PixelValueModel(*, values: list[float | None])[source]

Bases: BaseModel

Pydantic model class for VisiOmatic pixel values.

Parameters:

values (list[float | None]) -- Pixel values.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class PixelModel(*, x: int, y: int, values: list[float | None])[source]

Bases: BaseModel

Pydantic model class for pixels.

Parameters:
  • x (int) -- x coordinate of the pixel.

  • y (int) -- y coordinate of the pixel.

  • values (list[float, None]) -- Pixel values.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class ProfileModel(*, profile: list[PixelModel])[source]

Bases: BaseModel

Pydantic model class for VisiOmatic profiles.

Parameters:

profile (list[PixelModel]) -- List of pixel models.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class TiledModel(*, type: str, version: str, image_name: str, object_name: str, full_size: Tuple[int, ...], tile_size: Tuple[int, ...], tile_levels: int, channels: int, bits_per_channel: int, brightness: float, contrast: float, color_saturation: float, gamma: float, quality: int, header: dict, images: List[ImageModel])[source]

Bases: BaseModel

Pydantic tiled model class.

Parameters:
  • type (str) -- Name of the web service.

  • version (str) -- Version of the web service.

  • full_size (List[int]) -- Full raster size, FITS style (x comes first).

  • tile_size (List[int]) -- Tile size, FITS style.

  • tile_levels (int) -- Number of levels in the image pyramid.

  • channels (int) -- Number of channels.

  • bits_per_channel (int) -- Number of bits per pixel.

  • brightness (float) -- Relative tile brightness (black level).

  • contrast (float) -- Relative tile contrast.

  • color_saturation (float) -- Tile color saturation.

  • gamma (float) -- Tile display gamma.

  • quality (int) -- JPEG quality (0-100).

  • header (dict) -- Image header keyword/value pairs.

  • images (List[ImageModel]) -- List of image model objects.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class Tiled(filename: str, extnum: int | None = None, tilesize: Tuple[int, int] = (256, 256), minmax: Tuple[int, int] | None = None, brightness: float | None = None, contrast: float | None = None, color_saturation: float | None = None, gamma: float | None = None, quality: int | None = None, max_region_tile_count: int | None = None, nthreads: int | None = None)[source]

Bases: object

Class for the tiled image pyramid to be visualized.

Parameters:
  • filename (str | Path,) -- Path to the image.

  • extnum (int, optional) -- Extension number (for Multi-Extension FITS files).

  • tilesize (tuple[int, int], optional) -- shape of the served tiles.

  • minmax (tuple[float, float], optional) -- Intensity cuts of the served tiles.

  • brightness (float, optional) -- Relative tile black level of the served tiles.

  • contrast (float, optional) -- Relative tile contrast of the served tiles.

  • color_saturation (float, optional) -- Default color saturation of the served tiles.

  • gamma (float, optional) -- Display gamma of the served tiles.

  • nthreads (int, optional) -- Number of compute threads for parallelized operations.

compute_nlevels() int[source]

Return the number of image resolution levels.

Returns:

nlevels (int) -- Number of image resolution levels in the pyramid.

compute_grid_shape(level: int = 0) Tuple[int, int, int][source]

Return the number of tiles per axis at a given image resolution level.

Returns:

shape (tuple[int, int, int]) -- Number of tiles.

compute_tile_bordershape(level=0) Tuple[int, int, int][source]

Return the border shape of tiles at a given image resolution level.

Returns:

shape (tuple[int, int, int]) -- Border shape.

get_model() TiledModel[source]

Return a Pydantic model of the tiled object.

Returns:

model (TiledModel) -- Pydantic model instance of the tiled object

make_mosaic(images: List[Image]) None[source]

Stitch together several images to make a mosaic

Parameters:

images (list[Image]) -- list of input images.

make_header() <module 'astropy.io.fits.header' from '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/astropy/io/fits/header.py'>[source]

Generate a FITS header with a global WCS for the mosaic.

Returns:

header (~astropy.io.fits.Header) -- FITS header for the mosaic.

get_iipheaderstr() str[source]

Generate an IIP image header.

Returns:

header (str) -- IIP image header.

convert_tile(tile: ndarray, channel: int | None = None, minmax: Tuple[Tuple[int, float, float], ...] | None = None, mix: Tuple[Tuple[int, float, float, float], ...] | None = None, brightness: float | None = None, contrast: float | None = None, gamma: float | None = None, colormap: str = 'grey', invert: bool = False) ndarray[source]

Process the dynamic range of a tile.

Parameters:
  • tile (ndarray) -- Input tile.

  • channel (int, optional) -- Image channel

  • minmax (list[float, float], optional) -- Tile intensity cuts.

  • mix (list[int, float, float, float], optional) -- Tile slice RGB colors.

  • brightness (float, optional) -- Relative tile brightness (black level).

  • contrast (float, optional) -- Relative tile contrast.

  • gamma (float, optional) -- Inverse tile display gamma.

  • colormap (str, optional) -- Colormap: 'grey' (default), 'jet', 'cold', or 'hot'.

  • invert (bool, optional) -- Invert the colormap.

Returns:

raster (~numpy.ndarray) -- Processed tile image raster.

make_tiles() None[source]

Generate all tiles from the image.

get_tile_raster(tilelevel: int, tileindex: int, channel: int | None = None, minmax: Tuple[Tuple[int, float, float], ...] | None = None, mix: Tuple[Tuple[int, float, float, float], ...] | None = None, brightness: float | None = None, contrast: float | None = None, gamma: float | None = None, colormap: str = 'grey', invert: bool = False, **_: Any) ndarray[source]

Compute a gray-level or color image raster from a tile.

Parameters:
  • tilelevel (int) -- Tile resolution level.

  • tileindex (int) -- Tile index.

  • channel (int) -- Data channel (first channel is 1)

  • minmax (list[float, float], optional) -- Tile intensity cuts.

  • brightness (float, optional) -- Relative tile brightness.

  • contrast (float, optional) -- Relative tile contrast.

  • gamma (float, optional) -- Inverse tile display gamma.

  • colormap (str, optional) -- Colormap: 'grey' (default), 'jet', 'cold', or 'hot'.

  • invert (bool, optional) -- Invert the colormap.

Returns:

raster (~numpy.ndarray) -- The computed tile image raster.

encode(raster: ndarray, channel: int | None = None, colormap: str = 'grey', quality: int | None = None, **_: Any) bytes[source]

Generate a JPEG bytestream from an image raster (e.g., a tile).

Parameters:
  • raster (ndarray) -- Input tile.

  • channel (int, optional) -- Data channel (first channel is 1)

  • colormap (str, optional) -- Colormap: 'grey' (default), 'jet', 'cold', or 'hot'.

  • quality (int, optional) -- JPEG quality (0-100)

Returns:

tile (bytes) -- JPEG bytestream of the tile.

get_encoded_tile = <methodtools._LruCacheWire object>[source]
get_encoded_region(bounds: Tuple[Tuple[int, int], Tuple[int, int]], binning: int = 1, channel: int | None = None, colormap: str = 'grey', **kwargs: Any) bytes[source]

Return a JPEG bytestream of a specific image region by stitching tiles that fall in that region.

Parameters:
  • bounds (tuple[tuple[int, int], tuple[int, int]]) -- Image boundaries in pixels.

  • binning (int, optional) -- Binning factor per axis, in pixels.

  • channel (int, optional) -- Data channel (first channel is 1)

  • colormap (str, optional) -- Colormap: 'grey' (default), 'jet', 'cold', or 'hot'.

  • **kwargs -- Additional get_tile_raster() and encode() keyword arguments.

Returns:

tile (bytes) -- JPEG bytestream of the tile.

Raises:

IndexError -- exception: An error occurred because of unexpected bounding box coordinates. It is raised if any of the following occur: - The number of requested region tiles exceeds max_region_tile_count. - Bounding box coordinates are inconsistent.

get_pixel_values(channels: Tuple[int], pos: Tuple[int, int]) PixelValueModel[source]

Get pixel values at the given pixel coordinates in merged frame.

Parameters:
  • channels (tuple[int]) -- Tuple of data channels (first channel is 1).

  • pos (tuple[int, int]) -- Pixel coordinates.

Returns:

value (~numpy.ndarray) -- Pixel value at the given position, or NaN outside of the frame boundaries.

get_profiles(channels: Tuple[int, ...] | None, pos1: Tuple[int, int], pos2: Tuple[int, int]) ProfileModel[source]

Get image profile(s) between the given pixel coordinates in the merged frame.

Parameters:
  • channels (tuple[int, ...] or None) -- Tuple of data channels (first channel is 1) or None for all channels.

  • pos1 (tuple[int, int]) -- Start pixel coordinates.

  • pos2 (tuple[int, int]) -- End pixel coordinates.

Returns:

profile (ProfileModel) -- Profile pydantic model of pixel value(s) along the line.

get_data()[source]

Get current memory-mapped image data.

Returns:

data (numpy.ndarray) -- Image data.

get_tiles()[source]

Get current memory-mapped tile data.

Returns:

data (numpy.ndarray) -- Tile data.

pickledTiled(filename: str, **kwargs) Tiled[source]

Return pickled Tiled object if available, or initialized otherwise.

Parameters:
  • filename (str | Path) -- Path to the image.

  • **kwargs (dict) -- Additional keyword arguments.

Returns:

tiled (object) -- Tiled object pickled from file if available, or initialized otherwise.

get_object_filename(image_filename: str) str[source]

Return the name of the file containing the pickled Tiled object.

Parameters:

filename (Image) -- Full image filename.

Returns:

filename (str) -- Pickled object filename.

get_data_filename(image_filename: str) str[source]

Return the name of the file containing the memory-mapped image data.

Parameters:

filename (Image) -- Full image filename.

Returns:

filename (str) -- Filename of the memory-mapped image data.

get_tiles_filename(image_filename: str) str[source]

Return the name of the file containing the memory-mapped tile datacube.

Parameters:

filename (Image) -- Full image filename.

Returns:

filename (str) -- Filename of the memory mapped tile datacube.

get_image_filename(prefix: str) str[source]

Return the name of the file containing the memory-mapped image datacube.

Parameters:

prefix (str) -- Image name prefix.

Returns:

filename (str) -- Filename of the memory mapped tile datacube.