Skip to content

Commit

Permalink
data.plt.spatial_scatter can support showing base image.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanliwei-coder committed Nov 6, 2024
1 parent 6a4df89 commit 06e7425
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions stereo/plots/plot_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ def spatial_scatter(
title: Optional[str] = None,
vmin: float = None,
vmax: float = None,
base_image: Optional[str] = None,
base_im_cmap: Optional[str] = 'Greys',
base_im_to_gray : bool = False,
**kwargs
):
"""
Expand All @@ -357,6 +360,11 @@ def spatial_scatter(
:param x_label: list of x label.
:param y_label: list of y label.
:param title: the title label.
:param vmin: The value representing the lower limit of the color scale. Values smaller than vmin are plotted with the same color as vmin.
:param vmax: The value representing the higher limit of the color scale. Values greater than vmax are plotted with the same color as vmax.
:param base_image: the path of mask image to be displayed as background, it must already be registered to the same coordinate system as the data.
:param base_im_cmap: the color map of the base image, only availabel when base image is gray scale image.
:param base_im_to_gray: whether to convert the base image to gray scale if base image is RGB/RGBA image.
:param show_plotting_scale: wheter to display the plotting scale.
:param out_path: the path to save the figure.
:param out_dpi: the dpi when the figure is saved.
Expand All @@ -371,10 +379,39 @@ def spatial_scatter(
if set it to `False`, the coordinates will not be changed.
:param horizontal_offset_additional: the additional offset between each slice on horizontal direction while reorganizing coordinates.
:param vertical_offset_additional: the additional offset between each slice on vertical direction while reorganizing coordinates.
:param vmin: The value representing the lower limit of the color scale. Values smaller than vmin are plotted with the same color as vmin.
:param vmax: The value representing the higher limit of the color scale. Values greater than vmax are plotted with the same color as vmax.
""" # noqa
from .scatter import multi_scatter
x = self.data.position[:, 0]
y = self.data.position[:, 1]
x_min, x_max = int(x.min()), int(x.max())
y_min, y_max = int(y.min()), int(y.max())
boundary = [x_min, x_max, y_min, y_max]
marker = 's'

base_im_boundary = None
base_image_data = None
base_im_value_range = None
if base_image is not None:
# base_image_data = tiff.imread(base_image)
with tiff.TiffFile(base_image) as tif:
base_image_data = tif.asarray()
if x_min > 0 or y_min > 0:
x_min = max(0, x_min - PLOT_BASE_IMAGE_EXPANSION)
y_min = max(0, y_min - PLOT_BASE_IMAGE_EXPANSION)
x_max += PLOT_BASE_IMAGE_EXPANSION
y_max += PLOT_BASE_IMAGE_EXPANSION
base_image_data = base_image_data[y_min:(y_max + 1), x_min:(x_max + 1)]
base_im_boundary = [x_min, x_max, y_max, y_min]
shaped_metadata = tif.shaped_metadata
if shaped_metadata is not None:
metadata = shaped_metadata[0]
if 'value_range' in metadata:
base_im_value_range = metadata['value_range']
marker = 'o'

if 'marker' not in kwargs:
kwargs['marker'] = marker

if isinstance(cells_key, str):
cells_key = [cells_key]
if title is None:
Expand All @@ -398,6 +435,12 @@ def spatial_scatter(
height=height,
vmin=vmin,
vmax=vmax,
boundary=boundary,
base_image=base_image_data,
base_im_cmap=base_im_cmap,
base_im_boundary=base_im_boundary,
base_im_value_range=base_im_value_range,
base_im_to_gray=base_im_to_gray,
**kwargs
)
return fig
Expand Down

0 comments on commit 06e7425

Please sign in to comment.