Example

Example#

class Example(
name: str,
function: Callable[..., _DatasetT_co],
paths: tuple[str, ...],
file_sizes: tuple[int, ...],
source_urls: tuple[str, ...],
)[source]#

A single example dataset: its files, where they come from, and how to read it.

Added in version 0.49.

Call get_example() to get an example; this class is not meant to be constructed directly. Every sequence-valued field is a tuple with one entry per path, in the same order, including for single-file examples. The class is generic over the dataset load() returns and the tuple readers returns, which get_example() resolves statically for every example name.

Examples#

Download Python source code | Download Jupyter notebook

Look up an example. This resolves its files but does not read them.

>>> from pyvista import examples
>>> frog = examples.get_example('frog')
>>> frog.name
'frog'

It is stored as two files, but only one of them is read.

>>> len(frog.paths)
2
>>> len(frog.readers)
1

Sizes are in bytes, one per path, so examples compare directly.

>>> bunny = examples.get_example('bunny')
>>> sum(frog.file_sizes) > sum(bunny.file_sizes)
True

Read the dataset itself.

>>> mesh = frog.load()
>>> mesh.n_cells
31594185

Attributes#

Example.readers

Return a reader for each file which has one.

Example.name

Name of the example, such as 'frog'.

Example.function

Public function which returns this example's dataset, such as examples.download_frog.

Example.paths

Local path of every file or folder belonging to the example, in declaration order.

Example.file_sizes

Size in bytes of each entry in paths, one per path, folders counted in full.

Example.source_urls

URL of each file which is downloaded, empty for an example which ships with PyVista.

Methods#

Example.load()

Read the example and return its dataset.