harpy.qc.image_histogram#
- harpy.qc.image_histogram(sdata, image_name, channel, bins, scale=None, range=None, ax=None, output=None, fig_kwargs=mappingproxy({}), bar_kwargs=mappingproxy({}), density=False, log_y=False, percentile_lines=None, kind='hist', exclude_zeros=True, exclude_nan=True, title=None, ncols=3, subplot_width=4, subplot_height=3.5, sharex=False, sharey=False, **kwargs)#
Generate and visualize a histogram for a specified image channel within an image of a
SpatialDataobject.- Parameters:
sdata (
SpatialData) – The inputSpatialDataobject containing the image data.image_name (
str) – The name of the image element withinsdatato analyze.channel (
str|int|Sequence[str|int]) – The specific channel of the image data to use for the histogram. Can be a single channel name or index, or a sequence of channel names and/or indices.bins (
int) – The number of bins for the histogram.scale (
str|None(default:None)) – Pyramid level to use whenimage_nameis multiscale. IfNone, the histogram is computed from"scale0". Using a lower-resolution scale provides a faster but approximate histogram.range (
tuple[float,float] |None(default:None)) – The range of values for the histogram as(min, max). If not provided, range is simply(dask.array.nanmin(...), dask.array.nanmax(...)), thus excluding NaN. Forkind="hist", values outside the range are ignored. Forkind="ecdf", the range is used to set the x-axis limits only.fig_kwargs (
dict[str,Any] (default:mappingproxy({}))) – Additional keyword arguments passed toplt.subplots, such asdpiorfigsize, whenax=None(and this function therefore creates the subplot(s)). Ignored ifaxis provided.bar_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Additional keyword arguments passed toax.bar, such ascolororalpha.ax (
Axes|ndarray|None(default:None)) – An existing axes object to plot the histogram. IfNone, a new figure and axes will be created.output (
str|Path(default:None)) – The path to save the generated plot. IfNone, the plot will not be saved.density (
bool(default:False)) – IfTrue, normalize the histogram to a density instead of plotting raw counts.log_y (
bool(default:False)) – IfTrue, use a logarithmic scale for the y-axis.percentile_lines (
Sequence[float] |None(default:None)) – Percentile values in the interval[0, 100]to visualize as vertical guide lines.kind (
str(default:'hist')) – Plot kind. Choose between"hist"for a histogram and"ecdf"for an empirical cumulative distribution plot.exclude_zeros (
bool(default:True)) – IfTrue, exclude zero-valued pixels before plotting and before computing percentile guide lines.exclude_nan (
bool(default:True)) – IfTrue, exclude NaN values before plotting and before computing percentile guide lines.title (
str|None(default:None)) – Custom plot title. Defaults to the channel name. Only applied directly in the single-channel case.ncols (
int(default:3)) – Number of subplot columns to use when plotting multiple channels.subplot_width (
float(default:4)) – Width of each subplot column when plotting multiple channels and no explicitfigsizeis provided infig_kwargs. Ignored whenfig_kwargscontainsfigsize.subplot_height (
float(default:3.5)) – Height of each subplot row when plotting multiple channels and no explicitfigsizeis provided infig_kwargs. Ignored whenfig_kwargscontainsfigsize.sharex (
bool(default:False)) – Whether to share the x-axis across subplots when plotting multiple channels.sharey (
bool(default:False)) – Whether to share the y-axis across subplots when plotting multiple channels.**kwargs – Additional keyword arguments passed to
dask.array.histogram()whenkind="hist".
- Raises:
AssertionError – If
image_nameis not found insdata.images.- Return type:
Examples
import harpy as hp sdata = hp.datasets.pixie_example() ax = hp.qc.image_histogram( sdata, image_name="raw_image_fov0", channel=hp.im.get_dataarray(sdata, element_name="raw_image_fov0").c.data, percentile_lines=[0.1, 99.9], kind="hist", ncols=5, subplot_height=3, subplot_width=3, log_y=False, exclude_nan=True, exclude_zeros=True, density=False, bins=100, )