yt.data_objects.image_array.ImageArray.write_png

ImageArray.write_png(filename, clip_ratio=None, background='black', rescale=True)[source]

Writes ImageArray to png file.

Parameters:

filename: string :

Note filename not be modified.

clip_ratio: float, optional :

Image will be clipped before saving to the standard deviation of the image multiplied by this value. Useful for enhancing images. Default: None

background: :

This can be used to set a background color for the image, and can take several types of values:

  • white: white background, opaque
  • black: black background, opaque
  • None: transparent background
  • 4-element array [r,g,b,a]: arbitrary rgba setting.

Default: ‘black’

rescale: boolean, optional :

If True, will write out a rescaled image (without modifying the original image). Default: True

Examples

>>> im = np.zeros([64,128,4])
>>> for i in range(im.shape[0]):
...     for k in range(im.shape[2]):
...         im[i,:,k] = np.linspace(0.,10.*k, im.shape[1])
>>> im_arr = ImageArray(im)
>>> im_arr.write_png('standard.png')
>>> im_arr.write_png('non-scaled.png', rescale=False)
>>> im_arr.write_png('black_bg.png', background='black')
>>> im_arr.write_png('white_bg.png', background='white')
>>> im_arr.write_png('green_bg.png', background=[0,1,0,1])
>>> im_arr.write_png('transparent_bg.png', background=None)