The data IO module

Utilities related to data reading, writing, fetching, and generation.

vispy.io.imread(filename, format=None)

Read image data from disk

Requires imageio or PIL.

Parameters:

filename : str

Filename to read.

format : str | None

Format of the file. If None, it will be inferred from the filename.

Returns:

data : array

Image data.

vispy.io.imsave(filename, im, format=None)

Save image data to disk

Requires imageio or PIL.

Parameters:

filename : str

Filename to write.

im : array

Image data.

format : str | None

Format of the file. If None, it will be inferred from the filename.

vispy.io.load_iris()

Load the iris dataset

Returns:

iris : NpzFile

data['data'] : a (150, 4) NumPy array with the iris' features data['group'] : a (150,) NumPy array with the iris' group

vispy.io.load_crate()

Load an image of a crate

Returns:

crate : array

256x256x3 crate image.

vispy.io.load_data_file(fname, directory=None, force_download=False)

Get a standard vispy demo data file

Parameters:

fname : str

The filename on the remote demo-data repository to download, e.g. 'molecular_viewer/micelle.npy'. These correspond to paths on https://github.com/vispy/demo-data/.

directory : str | None

Directory to use to save the file. By default, the vispy configuration directory is used.

force_download : bool | str

If True, the file will be downloaded even if a local copy exists (and this copy will be overwritten). Can also be a YYYY-MM-DD date to ensure a file is up-to-date (modified date of a file on disk, if present, is checked).

Returns:

fname : str

The path to the file on the local system.

vispy.io.read_mesh(fname)

Read mesh data from file.

Parameters:

fname : str

File name to read. Format will be inferred from the filename. Currently only '.obj' and '.obj.gz' are supported.

Returns:

vertices : array

Vertices.

faces : array | None

Triangle face definitions.

normals : array

Normals for the mesh.

texcoords : array | None

Texture coordinates.

vispy.io.read_png(filename)

Read a PNG file to RGB8 or RGBA8

Unlike imread, this requires no external dependencies.

Parameters:

filename : str

File to read.

Returns:

data : array

Image data.

See also

write_png, imread, imsave

vispy.io.write_mesh(fname, vertices, faces, normals, texcoords, name='', format='obj', overwrite=False)

Write mesh data to file.

Parameters:

fname : str

Filename to write. Must end with ".obj" or ".gz".

vertices : array

Vertices.

faces : array | None

Triangle face definitions.

normals : array

Normals for the mesh.

texcoords : array | None

Texture coordinates.

name : str

Name of the object.

format : str

Currently only "obj" is supported.

overwrite : bool

If the file exists, overwrite it.

vispy.io.write_png(filename, data)

Write a PNG file

Unlike imsave, this requires no external dependencies.

Parameters:

filename : str

File to save to.

data : array

Image data.

See also

read_png, imread, imsave