playnano.io.render_utils module¶
Frame rendering shared by the GIF, video and image sequence exports.
render_frame() scales, colours, resizes and annotates one frame, so all
three exports look the same. Module constants control the appearance:
MIN_FRAME_HEIGHT(512): shorter frames are enlarged to this height; taller frames are not resized.REFERENCE_HEIGHT(512): the frame height at whichfont_scaleis used as given; annotation size scales with the rendered frame height.ANNOTATION_COLOR((255, 255, 255)): RGB colour of the annotations.DEFAULT_FONT_SCALE(2.0): defaultfont_scaleof the exports.
- playnano.io.render_utils.render_frame(frame: ndarray, cmap, timestamp: float, pixel_size_nm: float, scale_bar_length_nm: int, font_scale: float, draw_ts: bool, draw_scale: bool, zmin_val: float | None = None, zmax_val: float | None = None) ndarray[source]¶
Scale, colour, resize and annotate one frame for an animated export.
- Parameters:
frame (numpy.ndarray) – 2D image.
cmap (matplotlib.colors.Colormap) – Colormap to apply.
timestamp (float) – Time to draw, in seconds.
pixel_size_nm (float) – Pixel size of the frame, in nm, used for the scale bar.
scale_bar_length_nm (int) – Length of the scale bar, in nm; 0 hides it.
font_scale (float) – Size of the annotation text for a frame
REFERENCE_HEIGHTpixels high; scaled with the rendered frame height.draw_ts (bool) – Draw the timestamp.
draw_scale (bool) – Draw the scale bar.
zmin_val (float or None, optional) – Heights mapped to the bottom and top of the colormap; values outside are clipped and NaN is drawn in the bottom colour. If they are equal, the whole frame is drawn in the bottom colour. If either is None, the frame is scaled from its own minimum to its maximum, with NaN counted as 0. Default is None.
zmax_val (float or None, optional) – Heights mapped to the bottom and top of the colormap; values outside are clipped and NaN is drawn in the bottom colour. If they are equal, the whole frame is drawn in the bottom colour. If either is None, the frame is scaled from its own minimum to its maximum, with NaN counted as 0. Default is None.
- Returns:
RGB image, uint8, of shape (height, width, 3). Frames shorter than
MIN_FRAME_HEIGHTare enlarged to that height (keeping the aspect ratio) with cubic interpolation.- Return type:
- playnano.io.render_utils.resolve_stack_data(afm_stack, raw: bool) tuple[source]¶
Choose the data and frame metadata for an animated export.
- Parameters:
afm_stack (AFMImageStack) – The stack to export.
raw (bool) – If True and the stack has a
"raw"snapshot, use it, with the frame metadata from before any frames were removed.
- Returns:
stack_data (numpy.ndarray) – The frames to render: the raw snapshot, or
afm_stack.data.meta_src (list of dict) – The matching per-frame metadata.
is_filtered (bool) – True if processed data was chosen, so
_filteredshould be added to the output name.