SampleBaseImage#

class astropathdb.db_io._sample_utils.SampleBaseImage(astrodb, sampleid)#

Helper class for the lazy image loading.

Functionality is driven through build_multiscale_datatree_image() which returns a multiscale datatree image that can be directly added to a SpatialData object.

Parameters:
  • sampleid (str) – A sampleid for the image.

  • astrodb (AstroDB) – The AstroDB to use as the query engine.

SampleBaseImage Attributes#

SampleBaseImage Methods#

build_multiscale_datatree_image([tile_dims])

Build a multiscale dask datatree image for a sample's image pyramid.

SampleBaseImage References#

Attribute Reference#

attribute DB_LEVELS: ClassVar[int] = 9#

Method Reference#

method build_multiscale_datatree_image(tile_dims=None)#

Build a multiscale dask datatree image for a sample’s image pyramid.

The scales are from 0 (highest resolution) to 9 (lowest resolution) and named ‘scaleX’, with X indicating the resolution (ex. scale0).

Note

The scale is reversed from what is in the database where the scales are 9 to 0 (highest to lowest resolution).

Parameters:

tile_dims (tuple[DataArray, DataArray] | None) – A list of two dataframes specifying the image dimensions for the sample. The dataframe should have columns x,y,level for distinct combinations. The second should have a single column ztype for the distinct image z layers, in any order (Defaults to None and will be automatically grabbed from the database).

Returns:

A multiscale image in DataTree format where the image itself is a Dask object which queries the regions when requested. Its channels are the ztype layers in ascending order.

Return type:

DataTree

Private Attribute Reference#

attribute __astrodb#
attribute __sampleid#

Private Method Reference#

static __hex_to_image(x, image_dtype=np.int8)#

Convert image hex string to an image.

Parameters:
  • x (str) – The hex string to convert to an image.

  • image_dtype (dtype) – The data type of the input image (Defaults to int8).

Return type:

ndarray

method __organize_chunk(img_dict, start_positions, chunk_size, num_tiles, z_range)#

Organize the image chunk from the query into a usable (z,y,x) image.

Parameters:
  • img_dict (dict) – A dictionary mapping of the query with keys (x,y,z) and values holding the image query results

  • start_positions (tuple) – Starting tile positions for the mapping.

  • chunk_size (tuple) – The actual chunk sizes in y and x directions

  • num_tiles (tuple) – The number of tiles in the query, used to get edges

  • z_range (list) – The z range of the tiles

Returns:

A numpy array the size of the input chunk

Return type:

ndarray

static __preprocess_img_result(q_result)#

Pre-process the query result into a dictionary for faster access.

Create a dictionary to store (x, y, z) -> img for fast access

Parameters:

q_result (DataFrame)

Return type:

dict[tuple[int, int, int], str]

method __query_img(start_positions, end_positions, level)#
Parameters:
Return type:

dict[tuple[int, int, int], str]

method __retrieve_chunk(level, start_positions, chunk_size, z_range)#
Parameters:
Return type:

ndarray

static __find_chunk_size(idx, max_shape)#
Parameters:
Return type:

int

method _create_dask_img(image_tiles, level, z_range, image_edge)#
Parameters:
Return type:

Array

method _add_scale(shape, level, z_range)#
Parameters:
Return type:

Dataset

method _get_sample_img_dims()#
Return type:

tuple[DataArray, DataArray]