Tiled

Image tiling module

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

Bases: BaseModel

Pydantic model class for VisiOmatic pixel values.

Parameters:

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

classmethod construct(_fields_set: SetStr | None = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = 'allow' was set since it adds all passed values

copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: DictStrAny | None = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters:
  • include -- fields to include in new model

  • exclude -- fields to exclude from new model, as with values this takes precedence over include

  • update -- values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep -- set to True to make a deep copy of the model

Returns:

new model instance

dict(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

json(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = None, models_as_dict: bool = True, **dumps_kwargs: Any) str

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

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[Union[float, None]]) -- Pixel values.

classmethod construct(_fields_set: SetStr | None = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = 'allow' was set since it adds all passed values

copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: DictStrAny | None = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters:
  • include -- fields to include in new model

  • exclude -- fields to exclude from new model, as with values this takes precedence over include

  • update -- values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep -- set to True to make a deep copy of the model

Returns:

new model instance

dict(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

json(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = None, models_as_dict: bool = True, **dumps_kwargs: Any) str

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

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

Bases: BaseModel

Pydantic model class for VisiOmatic profiles.

Parameters:

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

classmethod construct(_fields_set: SetStr | None = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = 'allow' was set since it adds all passed values

copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: DictStrAny | None = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters:
  • include -- fields to include in new model

  • exclude -- fields to exclude from new model, as with values this takes precedence over include

  • update -- values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep -- set to True to make a deep copy of the model

Returns:

new model instance

dict(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

json(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = None, models_as_dict: bool = True, **dumps_kwargs: Any) str

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

class TiledModel(*, type: str, version: 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.

classmethod construct(_fields_set: SetStr | None = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = 'allow' was set since it adds all passed values

copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: DictStrAny | None = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters:
  • include -- fields to include in new model

  • exclude -- fields to exclude from new model, as with values this takes precedence over include

  • update -- values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep -- set to True to make a deep copy of the model

Returns:

new model instance

dict(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

json(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = None, models_as_dict: bool = True, **dumps_kwargs: Any) str

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

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, 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 '/usr/lib64/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:

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

make_tiles() None[source]

Generate all tiles from the image.

get_tile(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, quality: int | None = None) bytes[source]

Generate a JPEG bytestream 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.

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

Returns:

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

get_tile_cached = <methodtools._LruCacheWire object>[source]
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 tile datacube.

Parameters:

prefix (str) -- Image name prefix.

Returns:

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