yt.visualization.image_writer.write_image

yt.visualization.image_writer.write_image(image, filename, color_bounds=None, cmap_name='algae', func=<function <lambda>>)[source]

Write out a floating point array directly to a PNG file, scaling it and applying a colormap.

This function will scale an image and directly call libpng to write out a colormapped version of that image. It is designed for rapid-fire saving of image buffers generated using yt.visualization.api.FixedResolutionBuffers and the like.

Parameters:

image : array_like

This is an (unscaled) array of floating point values, shape (N,N,) to save in a PNG file.

filename : string

Filename to save as.

color_bounds : tuple of floats, optional

The min and max to scale between. Outlying values will be clipped.

cmap_name : string, optional

An acceptable colormap. See either yt.visualization.color_maps or http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps .

func : function, optional

A function to transform the buffer before applying a colormap.

Returns:

scaled_image : uint8 image that has been saved

Examples

>>> sl = ds.slice(0, 0.5, "Density")
>>> frb1 = FixedResolutionBuffer(sl, (0.2, 0.3, 0.4, 0.5),
                (1024, 1024))
>>> write_image(frb1["Density"], "saved.png")