init
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 452 KiB |
@@ -0,0 +1,11 @@
|
||||
"""Examples module."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import download_3ds as download_3ds
|
||||
from . import gltf as gltf
|
||||
from . import planets as planets
|
||||
from . import vrml as vrml
|
||||
from .cells import plot_cell as plot_cell
|
||||
from .downloads import *
|
||||
from .examples import *
|
||||
@@ -0,0 +1,843 @@
|
||||
"""Abstraction layer for downloading, reading, and loading dataset files.
|
||||
|
||||
The classes and methods in this module define an API for working with either
|
||||
a single file or multiple files which may be downloaded and/or loaded as an
|
||||
example dataset.
|
||||
|
||||
Many datasets have a straightforward input to output mapping:
|
||||
file -> read -> dataset
|
||||
|
||||
However, some file formats require multiple input files for reading (e.g.
|
||||
separate data and header files):
|
||||
(file1, file1) -> read -> dataset
|
||||
|
||||
Or, a dataset may be combination of two separate datasets:
|
||||
file1 -> read -> dataset1 ┬─> combined_dataset
|
||||
file2 -> read -> dataset2 ┘
|
||||
|
||||
In some cases, the input may be a folder instead of a file (e.g. DICOM):
|
||||
folder -> read -> dataset
|
||||
|
||||
In addition, there may be a need to customize the reading function to read
|
||||
files with specific options enabled (e.g. set a time value), or perform
|
||||
post-read processing to modify the dataset (e.g. set active scalars).
|
||||
|
||||
This module aims to serve these use cases and provide a flexible way of
|
||||
downloading, reading, and processing files with a generic mapping:
|
||||
file or files or folder -> fully processed dataset(s) in any form
|
||||
|
||||
"""
|
||||
|
||||
# mypy: disable-error-code="redundant-expr"
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
from collections.abc import Sequence
|
||||
import functools
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Any
|
||||
from typing import Generic
|
||||
from typing import Protocol
|
||||
from typing import TypeVar
|
||||
from typing import Union
|
||||
from typing import cast
|
||||
from typing import final
|
||||
from typing import runtime_checkable
|
||||
|
||||
import pyvista as pv
|
||||
from pyvista.core._typing_core import NumpyArray
|
||||
from pyvista.core.utilities.fileio import get_ext
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
|
||||
# Define TypeVars for two main class definitions used by this module:
|
||||
# 1. classes for single file inputs: T -> T
|
||||
# 2. classes for multi-file inputs: (T, ...) -> (T, ...)
|
||||
# Any properties with these typevars should have a one-to-one mapping for all files
|
||||
_FilePropStrType_co = TypeVar(
|
||||
'_FilePropStrType_co',
|
||||
str,
|
||||
tuple[str, ...],
|
||||
covariant=True,
|
||||
)
|
||||
_FilePropIntType_co = TypeVar(
|
||||
'_FilePropIntType_co',
|
||||
int,
|
||||
tuple[int, ...],
|
||||
covariant=True,
|
||||
)
|
||||
|
||||
DatasetObject = Union[pv.DataSet, pv.Texture, NumpyArray[Any], pv.MultiBlock]
|
||||
DatasetType = Union[
|
||||
type[pv.DataSet],
|
||||
type[pv.Texture],
|
||||
type[NumpyArray[Any]],
|
||||
type[pv.MultiBlock],
|
||||
]
|
||||
|
||||
|
||||
class _BaseFilePropsProtocol(Generic[_FilePropStrType_co, _FilePropIntType_co]):
|
||||
@property
|
||||
@abstractmethod
|
||||
def path(self) -> _FilePropStrType_co:
|
||||
"""Return the path(s) of all files."""
|
||||
|
||||
@property
|
||||
def num_files(self) -> int:
|
||||
"""Return the number of files from path or paths.
|
||||
|
||||
If a path is a folder, the number of files contained in the folder is returned.
|
||||
"""
|
||||
path = self.path
|
||||
paths = [path] if isinstance(path, str) else path
|
||||
return sum(1 if os.path.isfile(p) else len(_get_all_nested_filepaths(p)) for p in paths)
|
||||
|
||||
@property
|
||||
def unique_extension(self) -> str | tuple[str, ...]:
|
||||
"""Return the unique file extension(s) from all files."""
|
||||
return _get_unique_extension(self.path)
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def _filesize_bytes(self) -> _FilePropIntType_co:
|
||||
"""Return the file size(s) of all files in bytes."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def _filesize_format(self) -> _FilePropStrType_co:
|
||||
"""Return the formatted size of all file(s)."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def _total_size_bytes(self) -> int:
|
||||
"""Return the total size of all files in bytes."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def total_size(self) -> str:
|
||||
"""Return the total size of all files formatted as a string."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def _reader(
|
||||
self,
|
||||
) -> pv.BaseReader | tuple[pv.BaseReader | None, ...] | None:
|
||||
"""Return the base file reader(s) used to read the files."""
|
||||
|
||||
@property
|
||||
def unique_reader_type(
|
||||
self,
|
||||
) -> type[pv.BaseReader] | tuple[type[pv.BaseReader], ...] | None:
|
||||
"""Return unique reader type(s) from all file readers."""
|
||||
return _get_unique_reader_type(self._reader)
|
||||
|
||||
|
||||
class _SingleFilePropsProtocol(_BaseFilePropsProtocol[str, int]):
|
||||
"""Define file properties of a single file."""
|
||||
|
||||
|
||||
class _MultiFilePropsProtocol(
|
||||
_BaseFilePropsProtocol[tuple[str, ...], tuple[int, ...]],
|
||||
):
|
||||
"""Define file properties of multiple files."""
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class _Downloadable(Protocol[_FilePropStrType_co]):
|
||||
"""Class which downloads file(s) from a source."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def source_name(self) -> _FilePropStrType_co:
|
||||
"""Return the name of the download relative to the base url."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def base_url(self) -> _FilePropStrType_co:
|
||||
"""Return the base url of the download."""
|
||||
|
||||
@property
|
||||
def source_url_raw(self) -> _FilePropStrType_co:
|
||||
"""Return the raw source of the download.
|
||||
|
||||
This is the full URL used to download the data directly.
|
||||
"""
|
||||
name = self.source_name
|
||||
name_iter = [name] if isinstance(name, str) else name
|
||||
url = self.base_url
|
||||
base_url_iter = [url] if isinstance(url, str) else url
|
||||
url_raw = list(map(os.path.join, base_url_iter, name_iter))
|
||||
return url_raw[0] if isinstance(name, str) else tuple(url_raw)
|
||||
|
||||
@property
|
||||
def source_url_blob(self) -> _FilePropStrType_co:
|
||||
"""Return the blob source of the download.
|
||||
|
||||
This URL is useful for linking to the source webpage for
|
||||
a human to open on a browser.
|
||||
"""
|
||||
# Make single urls iterable and replace 'raw' with 'blob'
|
||||
url_raw = self.source_url_raw
|
||||
url_iter = [url_raw] if isinstance(url_raw, str) else url_raw
|
||||
url_blob = [url.replace('/raw/', '/blob/') for url in url_iter]
|
||||
return url_blob[0] if isinstance(url_raw, str) else tuple(url_blob)
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def path(self) -> _FilePropStrType_co:
|
||||
"""Return the file path of downloaded file."""
|
||||
|
||||
@abstractmethod
|
||||
def download(self) -> _FilePropStrType_co:
|
||||
"""Download and return the file path(s)."""
|
||||
|
||||
|
||||
class _DatasetLoader:
|
||||
"""Load a dataset."""
|
||||
|
||||
def __init__(self, load_func: Callable[..., DatasetObject]):
|
||||
self._load_func = load_func
|
||||
self._dataset: DatasetObject | None = None
|
||||
|
||||
@property
|
||||
@final
|
||||
def dataset(self) -> DatasetObject | None:
|
||||
"""Return the loaded dataset object(s)."""
|
||||
return self._dataset
|
||||
|
||||
def load(self, *args, **kwargs) -> DatasetObject:
|
||||
"""Load and return the dataset."""
|
||||
# Subclasses should override this as needed
|
||||
return self._load_func(*args, **kwargs)
|
||||
|
||||
@final
|
||||
def load_and_store_dataset(self) -> DatasetObject:
|
||||
"""Load the dataset and store it."""
|
||||
dataset = self.load()
|
||||
self._dataset = dataset
|
||||
return dataset
|
||||
|
||||
@final
|
||||
def clear_dataset(self):
|
||||
"""Clear the stored dataset object from memory."""
|
||||
del self._dataset
|
||||
|
||||
@property
|
||||
@final
|
||||
def dataset_iterable(self) -> tuple[DatasetObject, ...]:
|
||||
"""Return a tuple of all dataset object(s), including any nested objects.
|
||||
|
||||
If the dataset is a MultiBlock, the MultiBlock itself is also returned as the first
|
||||
item. Any nested MultiBlocks are not included, only their datasets.
|
||||
|
||||
E.g. for a composite dataset:
|
||||
MultiBlock -> (MultiBlock, Block0, Block1, ...)
|
||||
"""
|
||||
dataset = self.dataset
|
||||
|
||||
def _flat(obj):
|
||||
if isinstance(obj, Sequence):
|
||||
output_list = [] # type: ignore[var-annotated]
|
||||
for item in obj:
|
||||
(
|
||||
output_list.extend(item)
|
||||
if isinstance(item, Sequence)
|
||||
else output_list.append(item)
|
||||
)
|
||||
if any(isinstance(item, Sequence) for item in output_list):
|
||||
return _flat(output_list)
|
||||
return output_list
|
||||
else:
|
||||
return [obj]
|
||||
|
||||
flat = _flat(dataset)
|
||||
if isinstance(dataset, pv.MultiBlock):
|
||||
flat.insert(0, dataset)
|
||||
return tuple(flat)
|
||||
|
||||
@property
|
||||
@final
|
||||
def unique_dataset_type(
|
||||
self,
|
||||
) -> DatasetType | tuple[DatasetType, ...] | None:
|
||||
"""Return unique dataset type(s) from all datasets."""
|
||||
return _get_unique_dataset_type(self.dataset_iterable)
|
||||
|
||||
@property
|
||||
@final
|
||||
def unique_cell_types(
|
||||
self,
|
||||
) -> tuple[pv.CellType, ...]:
|
||||
"""Return unique cell types from all datasets."""
|
||||
cell_types: dict[pv.CellType, None] = {}
|
||||
for data in self.dataset_iterable:
|
||||
# Get the underlying dataset for the texture
|
||||
dataset = (
|
||||
cast('pv.ImageData', pv.wrap(data.GetInput()))
|
||||
if isinstance(data, pv.Texture)
|
||||
else data
|
||||
)
|
||||
try:
|
||||
if isinstance(dataset, pv.ExplicitStructuredGrid):
|
||||
# extract_cells_by_type does not support this datatype
|
||||
# so get cells manually
|
||||
cells = (c.type for c in dataset.cell)
|
||||
[cell_types.update({cell_type: None}) for cell_type in cells]
|
||||
else:
|
||||
for cell_type in pv.CellType:
|
||||
extracted = dataset.extract_cells_by_type(cell_type) # type: ignore[union-attr]
|
||||
if extracted.n_cells > 0:
|
||||
cell_types[cell_type] = None
|
||||
except AttributeError:
|
||||
continue
|
||||
return tuple(sorted(cell_types.keys()))
|
||||
|
||||
|
||||
class _SingleFile(_SingleFilePropsProtocol):
|
||||
"""Wrap a single file."""
|
||||
|
||||
def __init__(self, path):
|
||||
from pyvista.examples.downloads import USER_DATA_PATH # noqa: PLC0415
|
||||
|
||||
self._path = (
|
||||
path if path is None or os.path.isabs(path) else os.path.join(USER_DATA_PATH, path)
|
||||
)
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def _filesize_bytes(self) -> int:
|
||||
return _get_file_or_folder_size(self.path)
|
||||
|
||||
@property
|
||||
def _filesize_format(self) -> str:
|
||||
return _format_file_size(self._filesize_bytes)
|
||||
|
||||
@property
|
||||
def _total_size_bytes(self) -> int:
|
||||
return self._filesize_bytes
|
||||
|
||||
@property
|
||||
def total_size(self) -> str:
|
||||
return self._filesize_format
|
||||
|
||||
@property
|
||||
def _reader(self) -> pv.BaseReader | None:
|
||||
return None
|
||||
|
||||
|
||||
class _SingleFileDatasetLoader(_SingleFile, _DatasetLoader):
|
||||
"""Wrap a single file for loading.
|
||||
|
||||
Specify the read function and/or load functions for reading and processing the
|
||||
dataset. The read function is called on the file path first, then, if a load
|
||||
function is specified, the load function is called on the output from the read
|
||||
function.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
path
|
||||
Path of the file to be loaded.
|
||||
|
||||
read_func
|
||||
Specify the function used to read the file. Defaults to :func:`pyvista.read`.
|
||||
This can be used for customizing the reader's properties, or using another
|
||||
read function (e.g. :func:`pyvista.read_texture` for textures). The function
|
||||
must have the file path as the first argument and should return a dataset.
|
||||
If default arguments are required by your desired read function, consider
|
||||
using :class:`functools.partial` to pre-set the arguments before passing it
|
||||
as an argument to the loader.
|
||||
|
||||
load_func
|
||||
Specify the function used to load the file. Defaults to `None`. This is typically
|
||||
used to specify any processing of the dataset after reading. The load function
|
||||
typically will accept a dataset as an input and return a dataset.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
path: str,
|
||||
read_func: Callable[[str], DatasetType] | None = None,
|
||||
load_func: Callable[[DatasetType], Any] | None = None,
|
||||
):
|
||||
_SingleFile.__init__(self, path)
|
||||
_DatasetLoader.__init__(self, load_func) # type: ignore[arg-type]
|
||||
self._read_func = pv.read if path and read_func is None else read_func
|
||||
|
||||
@property
|
||||
def _reader(self) -> pv.BaseReader | None:
|
||||
# TODO: return the actual reader used, and not just a lookup
|
||||
# (this will require an update to the 'read_func' API)
|
||||
try:
|
||||
return pv.get_reader(self.path)
|
||||
except ValueError:
|
||||
# Cannot be read directly (requires custom reader)
|
||||
return None
|
||||
|
||||
@property
|
||||
def path_loadable(self) -> str:
|
||||
return self.path
|
||||
|
||||
def load(self):
|
||||
path = self.path
|
||||
read_func = self._read_func
|
||||
load_func = self._load_func
|
||||
try:
|
||||
# Read and load normally
|
||||
return read_func(path) if load_func is None else load_func(read_func(path)) # type: ignore[misc]
|
||||
except OSError:
|
||||
# Handle error generated by pv.read if reading a directory
|
||||
if read_func is pv.read and Path(path).is_dir():
|
||||
# Re-define read function to read all files in a directory as a multiblock
|
||||
read_func = lambda path: _load_as_multiblock( # type: ignore[assignment]
|
||||
[
|
||||
_SingleFileDatasetLoader(str(Path(path, fname)))
|
||||
for fname in sorted(os.listdir(path)) # noqa: PTH208
|
||||
],
|
||||
)
|
||||
return read_func(path) if load_func is None else load_func(read_func(path))
|
||||
else:
|
||||
msg = f'Error loading dataset from path:\n\t{self.path}'
|
||||
raise RuntimeError(msg)
|
||||
|
||||
|
||||
class _DownloadableFile(_SingleFile, _Downloadable[str]):
|
||||
"""Wrap a single file which must be downloaded.
|
||||
|
||||
If downloading a file from an archive, set the filepath of the zip as
|
||||
``path`` and set ``target_file`` as the file to extract. If the path is
|
||||
a zip file and no target file is specified, the entire archive is downloaded
|
||||
and extracted and the root directory of the path is returned.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
path: str,
|
||||
target_file: str | None = None,
|
||||
):
|
||||
_SingleFile.__init__(self, path)
|
||||
|
||||
from pyvista.examples.downloads import SOURCE # noqa: PLC0415
|
||||
from pyvista.examples.downloads import USER_DATA_PATH # noqa: PLC0415
|
||||
from pyvista.examples.downloads import _download_archive_file_or_folder # noqa: PLC0415
|
||||
from pyvista.examples.downloads import download_file # noqa: PLC0415
|
||||
from pyvista.examples.downloads import file_from_files # noqa: PLC0415
|
||||
from pyvista.examples.examples import dir_path # noqa: PLC0415
|
||||
|
||||
if Path(path).is_absolute():
|
||||
# Absolute path must point to a built-in dataset
|
||||
assert Path(path).parent == Path(
|
||||
dir_path,
|
||||
), 'Absolute path must point to a built-in dataset.'
|
||||
self._base_url = 'https://github.com/pyvista/pyvista/raw/main/pyvista/examples/'
|
||||
self._source_name = Path(path).name
|
||||
# the dataset is already downloaded (it's built-in)
|
||||
# so make download() simply return the local filepath
|
||||
self._download_func = lambda _: path
|
||||
else:
|
||||
# Relative path, use vars from downloads.py
|
||||
self._base_url = SOURCE
|
||||
self._download_func = download_file
|
||||
self._source_name = Path(path).name if Path(path).is_absolute() else path
|
||||
|
||||
target_file = '' if target_file is None and (get_ext(path) == '.zip') else target_file
|
||||
if target_file is not None:
|
||||
# download from archive
|
||||
self._download_func = functools.partial(
|
||||
_download_archive_file_or_folder,
|
||||
target_file=target_file,
|
||||
)
|
||||
# The file path currently points to the archive, not the target file itself
|
||||
# Try to resolve the full path to the target file (without downloading) if
|
||||
# the archive already exists in the cache
|
||||
fullpath = None
|
||||
if os.path.isfile(self.path):
|
||||
try:
|
||||
# Get file path
|
||||
fullpath = file_from_files(target_file, self.path)
|
||||
except (FileNotFoundError, RuntimeError):
|
||||
# Get folder path
|
||||
fullpath = os.path.join(USER_DATA_PATH, path + '.unzip', target_file)
|
||||
fullpath = fullpath if os.path.isdir(fullpath) else None
|
||||
# set the file path as the relative path of the target file if
|
||||
# the fullpath could not be resolved (i.e. not yet downloaded)
|
||||
self._path = target_file if fullpath is None else fullpath
|
||||
|
||||
@property
|
||||
def source_name(self) -> str:
|
||||
return self._source_name
|
||||
|
||||
@property
|
||||
def base_url(self) -> str:
|
||||
return self._base_url
|
||||
|
||||
def download(self) -> str:
|
||||
path = self._download_func(self._source_name)
|
||||
assert os.path.isfile(path) or os.path.isdir(path)
|
||||
# Reset the path since the full path for archive files
|
||||
# isn't known until after downloading
|
||||
self._path = path
|
||||
return path
|
||||
|
||||
|
||||
class _SingleFileDownloadableDatasetLoader(_SingleFileDatasetLoader, _DownloadableFile):
|
||||
"""Wrap a single file which must first be downloaded and which can also be loaded.
|
||||
|
||||
.. warning::
|
||||
|
||||
``download()`` should be called before accessing other attributes. Otherwise,
|
||||
calling ``load()`` or ``path`` may fail or produce unexpected results.
|
||||
|
||||
"""
|
||||
|
||||
def __init__( # noqa: PLR0917
|
||||
self,
|
||||
path: str,
|
||||
read_func: Callable[[str], DatasetType] | None = None,
|
||||
load_func: Callable[[DatasetType], DatasetType] | None = None,
|
||||
target_file: str | None = None,
|
||||
):
|
||||
_SingleFileDatasetLoader.__init__(self, path, read_func=read_func, load_func=load_func)
|
||||
_DownloadableFile.__init__(self, path, target_file=target_file)
|
||||
|
||||
|
||||
class _MultiFileDatasetLoader(_DatasetLoader, _MultiFilePropsProtocol):
|
||||
"""Wrap multiple files for loading.
|
||||
|
||||
Some use cases for loading multi-file examples include:
|
||||
|
||||
1. Multiple input files, and each file is read/loaded independently
|
||||
E.g.: loading two separate datasets for the example
|
||||
See ``download_bolt_nut`` for a reference implementation.
|
||||
|
||||
2. Multiple input files, but only one is read or loaded directly
|
||||
E.g.: loading a single dataset from a file format where data and metadata are
|
||||
stored in separate files, such as ``.raw`` and ``.mhd``.
|
||||
See ``download_head`` for a reference implementation.
|
||||
|
||||
3. Multiple input files, all of which make up part of the loaded dataset
|
||||
E.g.: loading six separate image files for cubemaps
|
||||
See ``download_sky_box_cube_map`` for a reference implementation.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
files_func
|
||||
Specify the function which will return a sequence of :class:`_SingleFile`
|
||||
objects required for loading the dataset. Alternatively, a directory can be
|
||||
specified, in which case a separate single-file dataset loader is created
|
||||
for each file with a default reader.
|
||||
|
||||
load_func
|
||||
Specify the function used to load the files. By default, :meth:`load()` is called
|
||||
on all the files (if loadable) and a tuple containing the loaded datasets is returned.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
files_func: str | Callable[[], Sequence[_SingleFileDatasetLoader | _DownloadableFile]],
|
||||
load_func: Callable[[Sequence[_SingleFileDatasetLoader]], Any] | None = None,
|
||||
):
|
||||
self._files_func = files_func
|
||||
self._file_loaders_ = None
|
||||
if load_func is None:
|
||||
load_func = _load_as_dataset_or_multiblock
|
||||
|
||||
_DatasetLoader.__init__(self, load_func)
|
||||
|
||||
@property
|
||||
def _file_objects(self):
|
||||
if self._file_loaders_ is None and not isinstance(self._files_func, str):
|
||||
self._file_loaders_ = self._files_func() # type: ignore[assignment]
|
||||
return self._file_loaders_
|
||||
|
||||
@property
|
||||
def path(self) -> tuple[str, ...]:
|
||||
return tuple(_flatten_nested_sequence([file.path for file in self._file_objects]))
|
||||
|
||||
@property
|
||||
def path_loadable(self) -> tuple[str, ...]:
|
||||
return tuple(
|
||||
file.path for file in self._file_objects if isinstance(file, _SingleFileDatasetLoader)
|
||||
)
|
||||
|
||||
@property
|
||||
def _filesize_bytes(self) -> tuple[int, ...]:
|
||||
return tuple(
|
||||
_flatten_nested_sequence([file._filesize_bytes for file in self._file_objects]),
|
||||
)
|
||||
|
||||
@property
|
||||
def _filesize_format(self) -> tuple[str, ...]:
|
||||
return tuple(_format_file_size(size) for size in self._filesize_bytes)
|
||||
|
||||
@property
|
||||
def _total_size_bytes(self) -> int:
|
||||
return sum(file._total_size_bytes for file in self._file_objects)
|
||||
|
||||
@property
|
||||
def total_size(self) -> str:
|
||||
return _format_file_size(self._total_size_bytes)
|
||||
|
||||
@property
|
||||
def _reader(
|
||||
self,
|
||||
) -> pv.BaseReader | tuple[pv.BaseReader | None, ...] | None:
|
||||
# TODO: return the actual reader used, and not just a lookup
|
||||
# (this will require an update to the 'read_func' API)
|
||||
reader = _flatten_nested_sequence([file._reader for file in self._file_objects])
|
||||
# flatten in case any file objects themselves are multifiles
|
||||
reader_out: list[pv.BaseReader] = []
|
||||
for r in reader:
|
||||
reader_out.extend(r) if isinstance(r, Sequence) else reader_out.append(r)
|
||||
return tuple(reader_out)
|
||||
|
||||
def load(self):
|
||||
return self._load_func(self._file_objects)
|
||||
|
||||
|
||||
class _MultiFileDownloadableDatasetLoader(
|
||||
_MultiFileDatasetLoader,
|
||||
_Downloadable[tuple[str, ...]],
|
||||
):
|
||||
"""Wrap multiple files for downloading and loading."""
|
||||
|
||||
@property
|
||||
def source_name(self) -> tuple[str, ...]:
|
||||
name = [file.source_name for file in self._file_objects if isinstance(file, _Downloadable)]
|
||||
return tuple(_flatten_nested_sequence(name))
|
||||
|
||||
@property
|
||||
def base_url(self) -> tuple[str, ...]:
|
||||
url = [file.base_url for file in self._file_objects if isinstance(file, _Downloadable)]
|
||||
return tuple(_flatten_nested_sequence(url))
|
||||
|
||||
def download(self) -> tuple[str, ...]:
|
||||
path = [file.download() for file in self._file_objects if isinstance(file, _Downloadable)]
|
||||
# flatten paths in case any loaders have multiple files
|
||||
path_out = _flatten_nested_sequence(path)
|
||||
assert all(os.path.isfile(p) or os.path.isdir(p) for p in path_out)
|
||||
return tuple(path_out)
|
||||
|
||||
|
||||
_ScalarType = TypeVar('_ScalarType', int, str, pv.BaseReader)
|
||||
|
||||
|
||||
def _flatten_nested_sequence(nested: Sequence[_ScalarType | Sequence[_ScalarType]]):
|
||||
"""Flatten nested sequences of objects."""
|
||||
flat: list[_ScalarType] = []
|
||||
for item in nested:
|
||||
if isinstance(item, Sequence) and not isinstance(item, str):
|
||||
flat.extend(item)
|
||||
else:
|
||||
flat.append(item)
|
||||
return flat
|
||||
|
||||
|
||||
def _download_dataset(
|
||||
dataset_loader: _SingleFileDownloadableDatasetLoader | _MultiFileDownloadableDatasetLoader,
|
||||
*,
|
||||
load: bool = True,
|
||||
metafiles: bool = False,
|
||||
):
|
||||
"""Download and load a dataset file or files.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
dataset_loader
|
||||
SingleFile or MultiFile object(s) of the dataset(s) to download or load.
|
||||
|
||||
load
|
||||
Read and load the file after downloading. When ``False``,
|
||||
return the path or paths to the example's file(s).
|
||||
|
||||
metafiles
|
||||
When ``load`` is ``False``, set this value to ``True`` to
|
||||
return all files required to load the example, including any metafiles.
|
||||
If ``False``, only the paths of files which are explicitly loaded are
|
||||
returned. E.g if a file format uses two files to specify the header info
|
||||
and file data separately, setting ``metafiles=True`` will return a tuple
|
||||
with both file paths, whereas setting ``metafiles=False`` will only return
|
||||
the single path of the header file as a string.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Any
|
||||
Loaded dataset or path(s) to the example's files depending on the ``load``
|
||||
parameter. Dataset may be a texture, mesh, multiblock, array, tuple of meshes,
|
||||
or any other output loaded by the example.
|
||||
|
||||
"""
|
||||
# Download all files for the dataset, include any metafiles
|
||||
path = dataset_loader.download()
|
||||
|
||||
# Exclude non-loadable metafiles from result (if any)
|
||||
if not metafiles and isinstance(dataset_loader, _MultiFileDownloadableDatasetLoader):
|
||||
path = dataset_loader.path_loadable
|
||||
# Return scalar if only one loadable file
|
||||
path = path[0] if len(path) == 1 else path
|
||||
|
||||
return dataset_loader.load() if load else path
|
||||
|
||||
|
||||
def _load_as_multiblock(
|
||||
files: Sequence[_SingleFileDatasetLoader | _MultiFileDatasetLoader],
|
||||
names: Sequence[str] | None = None,
|
||||
) -> pv.MultiBlock:
|
||||
"""Load multiple files as a MultiBlock.
|
||||
|
||||
This function can be used as a loading function for :class:`MultiFileLoadable`
|
||||
If the use of the ``names`` parameter is needed, use :class:`functools.partial`
|
||||
to partially specify the names parameter before passing it as loading function.
|
||||
"""
|
||||
multi = pv.MultiBlock()
|
||||
if names is None:
|
||||
# set names, use filename without ext by default or dirname
|
||||
paths = _flatten_nested_sequence(
|
||||
[file.path_loadable for file in files if isinstance(file, _DatasetLoader)],
|
||||
)
|
||||
paths = [Path(path) for path in paths]
|
||||
names = [
|
||||
path.name[: -len(get_ext(path.name))] if path.is_file() else path.name
|
||||
for path in paths
|
||||
]
|
||||
|
||||
for file, name in zip(files, names):
|
||||
if not isinstance(file, _DatasetLoader):
|
||||
continue # type: ignore[unreachable]
|
||||
loaded = file.load()
|
||||
assert isinstance(
|
||||
loaded,
|
||||
(pv.MultiBlock, pv.DataSet),
|
||||
), (
|
||||
f'Only MultiBlock or DataSet objects can be loaded as a MultiBlock. '
|
||||
f"Got {type(loaded)}.'"
|
||||
)
|
||||
multi.append(loaded, name)
|
||||
return multi
|
||||
|
||||
|
||||
def _load_as_cubemap(files: str | _SingleFile | Sequence[_SingleFile]) -> pv.Texture:
|
||||
"""Load multiple files as a cubemap.
|
||||
|
||||
Input may be a single directory with 6 cubemap files, or a sequence
|
||||
of 6 files
|
||||
"""
|
||||
path = (
|
||||
files
|
||||
if isinstance(files, str)
|
||||
else (files.path if isinstance(files, _SingleFile) else [file.path for file in files])
|
||||
)
|
||||
|
||||
return (
|
||||
pv.cubemap(path)
|
||||
if isinstance(files, str) and os.path.isdir(files)
|
||||
else pv.cubemap_from_filenames(path)
|
||||
)
|
||||
|
||||
|
||||
def _load_as_dataset_or_multiblock(files):
|
||||
multiblock = _load_as_multiblock(files)
|
||||
return multiblock[0] if len(multiblock) == 1 else multiblock
|
||||
|
||||
|
||||
def _load_and_merge(files: Sequence[_SingleFile]):
|
||||
"""Load all loadable files as separate datasets and merge them."""
|
||||
loaded = [file.load() for file in files if isinstance(file, _DatasetLoader)]
|
||||
assert len(loaded) > 0
|
||||
return pv.merge(loaded)
|
||||
|
||||
|
||||
def _get_file_or_folder_size(filepath) -> int:
|
||||
if os.path.isfile(filepath):
|
||||
return os.path.getsize(filepath)
|
||||
assert os.path.isdir(filepath), 'Expected a file or folder path.'
|
||||
all_filepaths = _get_all_nested_filepaths(filepath)
|
||||
return sum(os.path.getsize(file) for file in all_filepaths)
|
||||
|
||||
|
||||
def _format_file_size(size: int) -> str:
|
||||
size_flt = float(size)
|
||||
for unit in ('B', 'KB', 'MB'):
|
||||
if round(size_flt * 10) / 10 < 1000.0:
|
||||
return f'{int(size_flt)} {unit}' if unit == 'B' else f'{size_flt:3.1f} {unit}'
|
||||
size_flt /= 1000.0
|
||||
return f'{size_flt:.1f} GB'
|
||||
|
||||
|
||||
def _get_file_or_folder_ext(path: str):
|
||||
"""Wrap the `get_ext` function to handle special cases for directories."""
|
||||
if os.path.isfile(path):
|
||||
return get_ext(path)
|
||||
assert os.path.isdir(path), 'Expected a file or folder path.'
|
||||
all_paths = _get_all_nested_filepaths(path)
|
||||
ext = [get_ext(file) for file in all_paths]
|
||||
assert len(ext) != 0, f'No files with extensions were found in"\n\t{path}'
|
||||
return ext
|
||||
|
||||
|
||||
def _get_all_nested_filepaths(filepath, *, exclude_readme=True):
|
||||
"""Walk through directory and get all file paths.
|
||||
|
||||
Optionally exclude any readme files (if any).
|
||||
"""
|
||||
assert os.path.isfile(filepath) or os.path.isdir(filepath)
|
||||
condition = lambda name: True if not exclude_readme else not name.lower().startswith('readme')
|
||||
return next(
|
||||
[os.path.join(path, name) for name in files if condition(name)]
|
||||
for path, _, files in os.walk(filepath)
|
||||
)
|
||||
|
||||
|
||||
def _get_unique_extension(path: str | Sequence[str]):
|
||||
"""Return a file extension or unique set of file extensions from a path or paths."""
|
||||
ext_set = set()
|
||||
fname_sequence = [path] if isinstance(path, str) else path
|
||||
|
||||
# Add all file extensions to the set
|
||||
for file in fname_sequence:
|
||||
ext = _get_file_or_folder_ext(file)
|
||||
ext_set.add(ext) if isinstance(ext, str) else ext_set.update(ext)
|
||||
|
||||
# Format output
|
||||
ext_output = tuple(ext_set)
|
||||
return ext_output[0] if len(ext_output) == 1 else tuple(sorted(ext_output))
|
||||
|
||||
|
||||
def _get_unique_reader_type(
|
||||
reader: pv.BaseReader | tuple[pv.BaseReader | None, ...] | None,
|
||||
) -> type[pv.BaseReader] | tuple[type[pv.BaseReader], ...] | None:
|
||||
"""Return a reader type or tuple of unique reader types."""
|
||||
if reader is None or (isinstance(reader, Sequence) and all(r is None for r in reader)):
|
||||
return None
|
||||
reader_set: set[type[pv.BaseReader]] = set()
|
||||
reader_type = (
|
||||
[type(reader)]
|
||||
if not isinstance(reader, Sequence)
|
||||
else [type(r) for r in reader if r is not None]
|
||||
)
|
||||
|
||||
# Add all reader types to the set
|
||||
reader_set.update(reader_type)
|
||||
|
||||
# Format output
|
||||
reader_output = tuple(reader_set)
|
||||
return reader_output[0] if len(reader_output) == 1 else tuple(reader_output)
|
||||
|
||||
|
||||
def _get_unique_dataset_type(
|
||||
dataset_iterable: tuple[DatasetObject, ...],
|
||||
) -> DatasetType | tuple[DatasetType, ...]:
|
||||
"""Return a dataset type or tuple of unique dataset types."""
|
||||
dataset_types: dict[DatasetType, None] = {} # use dict as an ordered set
|
||||
for dataset in dataset_iterable:
|
||||
dataset_types[type(dataset)] = None
|
||||
output = tuple(dataset_types.keys())
|
||||
return output[0] if len(output) == 1 else output
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,28 @@
|
||||
"""Contains 3ds examples."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .downloads import download_file
|
||||
|
||||
|
||||
def download_iflamigm(): # pragma: no cover
|
||||
"""Download a iflamigm image.
|
||||
|
||||
.. versionadded:: 0.44.0
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the 3DS file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> download_3ds_file = examples.download_3ds.download_iflamigm()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_3ds(download_3ds_file)
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return download_file('iflamigm.3ds')
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,798 @@
|
||||
"""Built-in examples that ship with PyVista and do not need to be downloaded.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> mesh = examples.load_ant()
|
||||
>>> mesh.plot()
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
import pyvista
|
||||
from pyvista.examples._dataset_loader import _DatasetLoader
|
||||
from pyvista.examples._dataset_loader import _SingleFileDownloadableDatasetLoader
|
||||
|
||||
# get location of this folder and the example files
|
||||
dir_path = str(Path(os.path.realpath(__file__)).parent)
|
||||
antfile = str(Path(dir_path) / 'ant.ply')
|
||||
planefile = str(Path(dir_path) / 'airplane.ply')
|
||||
hexbeamfile = str(Path(dir_path) / 'hexbeam.vtk')
|
||||
spherefile = str(Path(dir_path) / 'sphere.ply')
|
||||
uniformfile = str(Path(dir_path) / 'uniform.vtk')
|
||||
rectfile = str(Path(dir_path) / 'rectilinear.vtk')
|
||||
globefile = str(Path(dir_path) / 'globe.vtk')
|
||||
mapfile = str(Path(dir_path) / '2k_earth_daymap.jpg')
|
||||
channelsfile = str(Path(dir_path) / 'channels.vti')
|
||||
logofile = str(Path(dir_path) / 'pyvista_logo.png')
|
||||
nutfile = str(Path(dir_path) / 'nut.ply')
|
||||
frogtissuesfile = str(Path(dir_path) / 'frog_tissues.vti')
|
||||
|
||||
|
||||
def load_ant():
|
||||
"""Load ply ant mesh.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_ant()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Ant Dataset <ant_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_ant.load()
|
||||
|
||||
|
||||
_dataset_ant = _SingleFileDownloadableDatasetLoader(antfile, read_func=pyvista.PolyData) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def load_airplane():
|
||||
"""Load ply airplane mesh.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_airplane()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Airplane Dataset <airplane_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_airplane.load()
|
||||
|
||||
|
||||
_dataset_airplane = _SingleFileDownloadableDatasetLoader(planefile, read_func=pyvista.PolyData) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def load_sphere():
|
||||
"""Load sphere ply mesh.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_sphere()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Sphere Dataset <sphere_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_sphere.load()
|
||||
|
||||
|
||||
_dataset_sphere = _SingleFileDownloadableDatasetLoader(spherefile, read_func=pyvista.PolyData) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def load_uniform():
|
||||
"""Load a sample uniform grid.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.ImageData
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_uniform()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Uniform Dataset <uniform_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_uniform.load()
|
||||
|
||||
|
||||
_dataset_uniform = _SingleFileDownloadableDatasetLoader(uniformfile, read_func=pyvista.ImageData) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def load_rectilinear():
|
||||
"""Load a sample uniform grid.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.RectilinearGrid
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_rectilinear()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Rectilinear Dataset <rectilinear_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_rectilinear.load()
|
||||
|
||||
|
||||
_dataset_rectilinear = _SingleFileDownloadableDatasetLoader(
|
||||
rectfile,
|
||||
read_func=pyvista.RectilinearGrid, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
|
||||
def load_hexbeam():
|
||||
"""Load a sample UnstructuredGrid.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.UnstructuredGrid
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_hexbeam()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Hexbeam Dataset <hexbeam_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_hexbeam.load()
|
||||
|
||||
|
||||
_dataset_hexbeam = _SingleFileDownloadableDatasetLoader(
|
||||
hexbeamfile,
|
||||
read_func=pyvista.UnstructuredGrid, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
|
||||
def load_tetbeam():
|
||||
"""Load a sample UnstructuredGrid containing only tetrahedral cells.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.UnstructuredGrid
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_tetbeam()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Tetbeam Dataset <tetbeam_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_tetbeam.load()
|
||||
|
||||
|
||||
def _tetbeam_load_func():
|
||||
# make the geometry identical to the hexbeam
|
||||
xrng = np.linspace(0, 1, 3)
|
||||
yrng = np.linspace(0, 1, 3)
|
||||
zrng = np.linspace(0, 5, 11)
|
||||
grid = pyvista.RectilinearGrid(xrng, yrng, zrng)
|
||||
return grid.to_tetrahedra()
|
||||
|
||||
|
||||
_dataset_tetbeam = _DatasetLoader(_tetbeam_load_func)
|
||||
|
||||
|
||||
def load_structured():
|
||||
"""Load a simple StructuredGrid.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.StructuredGrid
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_structured()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Structured Dataset <structured_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_structured.load()
|
||||
|
||||
|
||||
def _structured_load_func():
|
||||
x = np.arange(-10, 10, 0.25)
|
||||
y = np.arange(-10, 10, 0.25)
|
||||
x, y = np.meshgrid(x, y)
|
||||
r = np.sqrt(x**2 + y**2)
|
||||
z = np.sin(r)
|
||||
return pyvista.StructuredGrid(x, y, z)
|
||||
|
||||
|
||||
_dataset_structured = _DatasetLoader(_structured_load_func)
|
||||
|
||||
|
||||
def load_globe():
|
||||
"""Load a globe source.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
Globe dataset with earth texture.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_globe()
|
||||
>>> texture = examples.load_globe_texture()
|
||||
>>> dataset.plot(texture=texture)
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Globe Dataset <globe_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_globe.load()
|
||||
|
||||
|
||||
_dataset_globe = _SingleFileDownloadableDatasetLoader(globefile, read_func=pyvista.PolyData) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def load_globe_texture():
|
||||
"""Load a pyvista.Texture that can be applied to the globe source.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.Texture
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_globe_texture()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Globe Texture Dataset <globe_texture_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_globe_texture.load()
|
||||
|
||||
|
||||
_dataset_globe_texture = _SingleFileDownloadableDatasetLoader(
|
||||
mapfile,
|
||||
read_func=pyvista.read_texture, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
|
||||
def load_channels():
|
||||
"""Load a uniform grid of fluvial channels in the subsurface.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.ImageData
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> dataset = examples.load_channels()
|
||||
>>> dataset.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Channels Dataset <channels_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_channels.load()
|
||||
|
||||
|
||||
_dataset_channels = _SingleFileDownloadableDatasetLoader(channelsfile)
|
||||
|
||||
|
||||
def load_spline():
|
||||
"""Load an example spline mesh.
|
||||
|
||||
This example data was created with:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> import numpy as np
|
||||
>>> import pyvista as pv
|
||||
>>> theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
|
||||
>>> z = np.linspace(-2, 2, 100)
|
||||
>>> r = z**2 + 1
|
||||
>>> x = r * np.sin(theta)
|
||||
>>> y = r * np.cos(theta)
|
||||
>>> points = np.column_stack((x, y, z))
|
||||
>>> mesh = pv.Spline(points, 1000)
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
Spline mesh.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> spline = examples.load_spline()
|
||||
>>> spline.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Spline Dataset <spline_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_spline.load()
|
||||
|
||||
|
||||
def _spline_load_func():
|
||||
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
|
||||
z = np.linspace(-2, 2, 100)
|
||||
r = z**2 + 1
|
||||
x = r * np.sin(theta)
|
||||
y = r * np.cos(theta)
|
||||
points = np.column_stack((x, y, z))
|
||||
return pyvista.Spline(points, 1000)
|
||||
|
||||
|
||||
_dataset_spline = _DatasetLoader(_spline_load_func)
|
||||
|
||||
|
||||
def load_random_hills():
|
||||
"""Create random hills toy example.
|
||||
|
||||
Uses the parametric random hill function to create hills oriented
|
||||
like topography and adds an elevation array.
|
||||
|
||||
This example dataset was created with:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> mesh = pv.ParametricRandomHills() # doctest:+SKIP
|
||||
>>> mesh = mesh.elevation() # doctest:+SKIP
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
Random hills mesh.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> mesh = examples.load_random_hills()
|
||||
>>> mesh.plot()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Random Hills Dataset <random_hills_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_random_hills.load()
|
||||
|
||||
|
||||
def _random_hills_load_func():
|
||||
mesh = pyvista.ParametricRandomHills()
|
||||
return mesh.elevation()
|
||||
|
||||
|
||||
_dataset_random_hills = _DatasetLoader(_random_hills_load_func)
|
||||
|
||||
|
||||
def load_sphere_vectors():
|
||||
"""Create example sphere with a swirly vector field defined on nodes.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
Mesh containing vectors.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> mesh = examples.load_sphere_vectors()
|
||||
>>> mesh.point_data
|
||||
pyvista DataSetAttributes
|
||||
Association : POINT
|
||||
Active Scalars : vectors
|
||||
Active Vectors : vectors
|
||||
Active Texture : None
|
||||
Active Normals : Normals
|
||||
Contains arrays :
|
||||
Normals float32 (842, 3) NORMALS
|
||||
vectors float32 (842, 3) VECTORS
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Sphere Vectors Dataset <sphere_vectors_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_sphere_vectors.load()
|
||||
|
||||
|
||||
def _sphere_vectors_load_func() -> pyvista.PolyData:
|
||||
sphere = pyvista.Sphere(radius=math.pi)
|
||||
|
||||
# make cool swirly pattern
|
||||
vectors = np.vstack(
|
||||
(
|
||||
np.sin(sphere.points[:, 0]),
|
||||
np.cos(sphere.points[:, 1]),
|
||||
np.cos(sphere.points[:, 2]),
|
||||
),
|
||||
).T
|
||||
|
||||
# add and scale
|
||||
sphere['vectors'] = vectors * 0.3
|
||||
sphere.set_active_vectors('vectors')
|
||||
return sphere
|
||||
|
||||
|
||||
_dataset_sphere_vectors = _DatasetLoader(_sphere_vectors_load_func)
|
||||
|
||||
|
||||
def load_explicit_structured(dimensions=(5, 6, 7), spacing=(20, 10, 1)):
|
||||
"""Load a simple explicit structured grid.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
dimensions : tuple(int), optional
|
||||
Grid dimensions. Default is (5, 6, 7).
|
||||
spacing : tuple(int), optional
|
||||
Grid spacing. Default is (20, 10, 1).
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.ExplicitStructuredGrid
|
||||
An explicit structured grid.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> grid = examples.load_explicit_structured()
|
||||
>>> grid.plot(show_edges=True)
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Explicit Structured Dataset <explicit_structured_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_explicit_structured.load(dimensions=dimensions, spacing=spacing)
|
||||
|
||||
|
||||
def _explicit_structured_load_func(dimensions=(5, 6, 7), spacing=(20, 10, 1)):
|
||||
ni, nj, nk = np.asarray(dimensions) - 1
|
||||
si, sj, sk = spacing
|
||||
xi = np.arange(0.0, (ni + 1) * si, si)
|
||||
yi = np.arange(0.0, (nj + 1) * sj, sj)
|
||||
zi = np.arange(0.0, (nk + 1) * sk, sk)
|
||||
|
||||
return pyvista.StructuredGrid(
|
||||
*np.meshgrid(xi, yi, zi, indexing='ij')
|
||||
).cast_to_explicit_structured_grid()
|
||||
|
||||
|
||||
_dataset_explicit_structured = _DatasetLoader(_explicit_structured_load_func)
|
||||
|
||||
|
||||
def load_nut():
|
||||
"""Load an example nut mesh.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.PolyData
|
||||
A sample nut surface dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
Load an example nut and plot with smooth shading.
|
||||
|
||||
>>> from pyvista import examples
|
||||
>>> mesh = examples.load_nut()
|
||||
>>> mesh.plot(smooth_shading=True, split_sharp_edges=True)
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Nut Dataset <nut_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_nut.load()
|
||||
|
||||
|
||||
_dataset_nut = _SingleFileDownloadableDatasetLoader(nutfile)
|
||||
|
||||
|
||||
def load_hydrogen_orbital(n=1, l=0, m=0, zoom_fac=1.0): # noqa: PLR0917
|
||||
"""Load the hydrogen wave function for a :class:`pyvista.ImageData`.
|
||||
|
||||
This is the solution to the Schrödinger equation for hydrogen
|
||||
evaluated in three-dimensional Cartesian space.
|
||||
|
||||
Inspired by `Hydrogen Wave Function
|
||||
<http://staff.ustc.edu.cn/~zqj/posts/Hydrogen-Wavefunction/>`_.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
n : int, default: 1
|
||||
Principal quantum number. Must be a positive integer. This is often
|
||||
referred to as the "energy level" or "shell".
|
||||
|
||||
l : int, default: 0
|
||||
Azimuthal quantum number. Must be a non-negative integer strictly
|
||||
smaller than ``n``. By convention this value is represented by the
|
||||
letters s, p, d, f, etc.
|
||||
|
||||
m : int, default: 0
|
||||
Magnetic quantum number. Must be an integer ranging from ``-l`` to
|
||||
``l`` (inclusive). This is the orientation of the angular momentum in
|
||||
space.
|
||||
|
||||
zoom_fac : float, default: 1.0
|
||||
Zoom factor for the electron cloud. Increase this value to focus on the
|
||||
center of the electron cloud.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.ImageData
|
||||
ImageData containing two ``point_data`` arrays:
|
||||
|
||||
* ``'real_wf'`` - Real part of the wave function.
|
||||
* ``'wf'`` - Complex wave function.
|
||||
|
||||
Notes
|
||||
-----
|
||||
This example requires `sympy <https://www.sympy.org/>`_.
|
||||
|
||||
Examples
|
||||
--------
|
||||
Plot the 3dxy orbital of a hydrogen atom. This corresponds to the quantum
|
||||
numbers ``n=3``, ``l=2``, and ``m=-2``.
|
||||
|
||||
>>> from pyvista import examples
|
||||
>>> grid = examples.load_hydrogen_orbital(3, 2, -2)
|
||||
>>> grid.plot(volume=True, opacity=[1, 0, 1], cmap='magma')
|
||||
|
||||
See :ref:`atomic_orbitals_example` for additional examples using
|
||||
this function.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Hydrogen Orbital Dataset <hydrogen_orbital_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_hydrogen_orbital.load(n=n, l=l, m=m, zoom_fac=zoom_fac)
|
||||
|
||||
|
||||
def _hydrogen_orbital_load_func(n=1, l=0, m=0, zoom_fac=1.0): # noqa: PLR0917
|
||||
try:
|
||||
from sympy import lambdify
|
||||
from sympy.abc import phi
|
||||
from sympy.abc import r
|
||||
from sympy.abc import theta
|
||||
from sympy.physics.hydrogen import Psi_nlm
|
||||
except ImportError: # pragma: no cover
|
||||
msg = '\n\nInstall sympy to run this example. Run:\n\n pip install sympy\n'
|
||||
raise ImportError(msg) from None
|
||||
|
||||
if n < 1:
|
||||
msg = '`n` must be at least 1'
|
||||
raise ValueError(msg)
|
||||
if l not in range(n):
|
||||
msg = f'`l` must be one of: {list(range(n))}'
|
||||
raise ValueError(msg)
|
||||
if m not in range(-l, l + 1):
|
||||
msg = f'`m` must be one of: {list(range(-l, l + 1))}'
|
||||
raise ValueError(msg)
|
||||
|
||||
psi = lambdify((r, phi, theta), Psi_nlm(n, l, m, r, phi, theta, 1), 'numpy')
|
||||
|
||||
org = 1.5 * n**2 + 1.0 if n == 1 else 1.5 * n**2 + 10.0
|
||||
|
||||
org /= zoom_fac
|
||||
|
||||
dim = 100
|
||||
sp = (org * 2) / (dim - 1)
|
||||
grid = pyvista.ImageData(
|
||||
dimensions=(dim, dim, dim),
|
||||
spacing=(sp, sp, sp),
|
||||
origin=(-org, -org, -org),
|
||||
)
|
||||
|
||||
r, theta, phi = pyvista.cartesian_to_spherical(grid.x, grid.y, grid.z)
|
||||
wfc = psi(r, phi, theta).reshape(grid.dimensions)
|
||||
|
||||
grid['real_wf'] = np.real(wfc.ravel())
|
||||
grid['wf'] = wfc.ravel()
|
||||
return grid
|
||||
|
||||
|
||||
_dataset_hydrogen_orbital = _DatasetLoader(_hydrogen_orbital_load_func)
|
||||
|
||||
|
||||
def load_logo():
|
||||
"""Load the PyVista logo as a :class:`pyvista.ImageData`.
|
||||
|
||||
.. note::
|
||||
|
||||
Alternative versions of the logo file are also available from the ``logo``
|
||||
directory at https://github.com/pyvista/pyvista/. This includes
|
||||
higher-resolution ``.png`` files and a vectorized ``.svg`` version.
|
||||
|
||||
.. versionchanged:: 0.45
|
||||
|
||||
The dimensions of the image is now ``1389 x 592``.
|
||||
Previously, it was ``1920 x 718``.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.ImageData
|
||||
ImageData of the PyVista logo.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from pyvista import examples
|
||||
>>> image = examples.load_logo()
|
||||
>>> image.dimensions
|
||||
(1389, 592, 1)
|
||||
|
||||
>>> image.plot(cpos='xy', zoom='tight', rgb=True, show_axes=False)
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Logo Dataset <logo_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
"""
|
||||
return _dataset_logo.load()
|
||||
|
||||
|
||||
_dataset_logo = _SingleFileDownloadableDatasetLoader(logofile)
|
||||
|
||||
|
||||
def load_frog_tissues():
|
||||
"""Load frog tissues dataset.
|
||||
|
||||
This dataset contains tissue segmentation labels for the frog dataset.
|
||||
|
||||
.. versionadded:: 0.44.0
|
||||
|
||||
Returns
|
||||
-------
|
||||
pyvista.ImageData
|
||||
Dataset.
|
||||
|
||||
Examples
|
||||
--------
|
||||
Load data
|
||||
|
||||
>>> import numpy as np
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> data = examples.load_frog_tissues()
|
||||
|
||||
Plot tissue labels as a volume
|
||||
|
||||
First, define plotting parameters
|
||||
|
||||
>>> # Configure colors / color bar
|
||||
>>> clim = data.get_data_range() # Set color bar limits to match data
|
||||
>>> cmap = 'glasbey' # Use a categorical colormap
|
||||
>>> categories = True # Ensure n_colors matches number of labels
|
||||
>>> opacity = 'foreground' # Make foreground opaque, background transparent
|
||||
>>> opacity_unit_distance = 1
|
||||
|
||||
Set plotting resolution to half the image's spacing
|
||||
|
||||
>>> res = np.array(data.spacing) / 2
|
||||
|
||||
Define rendering parameters
|
||||
|
||||
>>> mapper = 'gpu'
|
||||
>>> shade = True
|
||||
>>> ambient = 0.3
|
||||
>>> diffuse = 0.6
|
||||
>>> specular = 0.5
|
||||
>>> specular_power = 40
|
||||
|
||||
Make and show plot
|
||||
|
||||
>>> p = pv.Plotter()
|
||||
>>> _ = p.add_volume(
|
||||
... data,
|
||||
... clim=clim,
|
||||
... ambient=ambient,
|
||||
... shade=shade,
|
||||
... diffuse=diffuse,
|
||||
... specular=specular,
|
||||
... specular_power=specular_power,
|
||||
... mapper=mapper,
|
||||
... opacity=opacity,
|
||||
... opacity_unit_distance=opacity_unit_distance,
|
||||
... categories=categories,
|
||||
... cmap=cmap,
|
||||
... resolution=res,
|
||||
... )
|
||||
>>> p.camera_position = 'yx' # Set camera to provide a dorsal view
|
||||
>>> p.show()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`Frog Tissues Dataset <frog_tissues_dataset>`
|
||||
See this dataset in the Dataset Gallery for more info.
|
||||
|
||||
:ref:`Frog Dataset <frog_dataset>`
|
||||
|
||||
:ref:`medical_dataset_gallery`
|
||||
Browse other medical datasets.
|
||||
|
||||
"""
|
||||
return _dataset_frog_tissues.load()
|
||||
|
||||
|
||||
_dataset_frog_tissues = _SingleFileDownloadableDatasetLoader(frogtissuesfile)
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -0,0 +1,139 @@
|
||||
"""Contains glTF examples."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pooch
|
||||
|
||||
from .downloads import USER_DATA_PATH
|
||||
|
||||
GLTF_FETCHER = pooch.create(
|
||||
path=USER_DATA_PATH,
|
||||
base_url='https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/',
|
||||
registry={
|
||||
'Avocado/glTF-Binary/Avocado.glb': None,
|
||||
'CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb': None,
|
||||
'DamagedHelmet/glTF-Embedded/DamagedHelmet.gltf': None,
|
||||
'GearboxAssy/glTF-Binary/GearboxAssy.glb': None,
|
||||
'SheenChair/glTF-Binary/SheenChair.glb': None,
|
||||
},
|
||||
retry_if_failed=3,
|
||||
)
|
||||
|
||||
|
||||
def download_damaged_helmet(): # pragma: no cover
|
||||
"""Download the damaged helmet example.
|
||||
|
||||
Files hosted at https://github.com/KhronosGroup/glTF-Sample-Models
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the gltf file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> gltf_file = examples.gltf.download_damaged_helmet()
|
||||
>>> cubemap = examples.download_sky_box_cube_map()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_gltf(gltf_file)
|
||||
>>> pl.set_environment_texture(cubemap)
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return GLTF_FETCHER.fetch('DamagedHelmet/glTF-Embedded/DamagedHelmet.gltf')
|
||||
|
||||
|
||||
def download_sheen_chair(): # pragma: no cover
|
||||
"""Download the sheen chair example.
|
||||
|
||||
Files hosted at https://github.com/KhronosGroup/glTF-Sample-Models
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the gltf file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> gltf_file = examples.gltf.download_sheen_chair()
|
||||
>>> cubemap = examples.download_sky_box_cube_map()
|
||||
>>> pl = pv.Plotter() # doctest:+SKIP
|
||||
>>> pl.import_gltf(gltf_file) # doctest:+SKIP
|
||||
>>> pl.set_environment_texture(cubemap) # doctest:+SKIP
|
||||
>>> pl.show() # doctest:+SKIP
|
||||
|
||||
"""
|
||||
return GLTF_FETCHER.fetch('SheenChair/glTF-Binary/SheenChair.glb')
|
||||
|
||||
|
||||
def download_gearbox(): # pragma: no cover
|
||||
"""Download the gearbox example.
|
||||
|
||||
Files hosted at https://github.com/KhronosGroup/glTF-Sample-Models
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the gltf file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> gltf_file = examples.gltf.download_gearbox()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_gltf(gltf_file)
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return GLTF_FETCHER.fetch('GearboxAssy/glTF-Binary/GearboxAssy.glb')
|
||||
|
||||
|
||||
def download_avocado(): # pragma: no cover
|
||||
"""Download the avocado example.
|
||||
|
||||
Files hosted at https://github.com/KhronosGroup/glTF-Sample-Models
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the gltf file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> gltf_file = examples.gltf.download_avocado()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_gltf(gltf_file)
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return GLTF_FETCHER.fetch('Avocado/glTF-Binary/Avocado.glb')
|
||||
|
||||
|
||||
def download_milk_truck(): # pragma: no cover
|
||||
"""Download the milk truck example.
|
||||
|
||||
Files hosted at https://github.com/KhronosGroup/glTF-Sample-Models
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the gltf file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> gltf_file = examples.gltf.download_milk_truck()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_gltf(gltf_file)
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return GLTF_FETCHER.fetch('CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb')
|
||||
@@ -0,0 +1,159 @@
|
||||
# vtk DataFile Version 4.1
|
||||
vtk output
|
||||
ASCII
|
||||
DATASET UNSTRUCTURED_GRID
|
||||
POINTS 99 double
|
||||
0 0 0 1 0 0 0.5 0 0
|
||||
1 1 0 1 0.5 0 0 1 0
|
||||
0.5 1 0 0 0.5 0 0.5 0.5 0
|
||||
0 0 5 1 0 5 0.5 0 5
|
||||
1 1 5 1 0.5 5 0 1 5
|
||||
0.5 1 5 0 0.5 5 0.5 0.5 5
|
||||
1 0 0.5 1 0 1 1 0 1.5
|
||||
1 0 2 1 0 2.5 1 0 3
|
||||
1 0 3.5 1 0 4 1 0 4.5
|
||||
0 0 0.5 0 0 1 0 0 1.5
|
||||
0 0 2 0 0 2.5 0 0 3
|
||||
0 0 3.5 0 0 4 0 0 4.5
|
||||
0.5 0 0.5 0.5 0 1 0.5 0 1.5
|
||||
0.5 0 2 0.5 0 2.5 0.5 0 3
|
||||
0.5 0 3.5 0.5 0 4 0.5 0 4.5
|
||||
1 1 0.5 1 1 1 1 1 1.5
|
||||
1 1 2 1 1 2.5 1 1 3
|
||||
1 1 3.5 1 1 4 1 1 4.5
|
||||
1 0.5 0.5 1 0.5 1 1 0.5 1.5
|
||||
1 0.5 2 1 0.5 2.5 1 0.5 3
|
||||
1 0.5 3.5 1 0.5 4 1 0.5 4.5
|
||||
0 1 0.5 0 1 1 0 1 1.5
|
||||
0 1 2 0 1 2.5 0 1 3
|
||||
0 1 3.5 0 1 4 0 1 4.5
|
||||
0.5 1 0.5 0.5 1 1 0.5 1 1.5
|
||||
0.5 1 2 0.5 1 2.5 0.5 1 3
|
||||
0.5 1 3.5 0.5 1 4 0.5 1 4.5
|
||||
0 0.5 0.5 0 0.5 1 0 0.5 1.5
|
||||
0 0.5 2 0 0.5 2.5 0 0.5 3
|
||||
0 0.5 3.5 0 0.5 4 0 0.5 4.5
|
||||
0.5 0.5 0.5 0.5 0.5 1 0.5 0.5 1.5
|
||||
0.5 0.5 2 0.5 0.5 2.5 0.5 0.5 3
|
||||
0.5 0.5 3.5 0.5 0.5 4 0.5 0.5 4.5
|
||||
|
||||
CELLS 40 360
|
||||
8 0 2 8 7 27 36 90 81
|
||||
8 2 1 4 8 36 18 54 90
|
||||
8 7 8 6 5 81 90 72 63
|
||||
8 8 4 3 6 90 54 45 72
|
||||
8 27 36 90 81 28 37 91 82
|
||||
8 36 18 54 90 37 19 55 91
|
||||
8 81 90 72 63 82 91 73 64
|
||||
8 90 54 45 72 91 55 46 73
|
||||
8 28 37 91 82 29 38 92 83
|
||||
8 37 19 55 91 38 20 56 92
|
||||
8 82 91 73 64 83 92 74 65
|
||||
8 91 55 46 73 92 56 47 74
|
||||
8 29 38 92 83 30 39 93 84
|
||||
8 38 20 56 92 39 21 57 93
|
||||
8 83 92 74 65 84 93 75 66
|
||||
8 92 56 47 74 93 57 48 75
|
||||
8 30 39 93 84 31 40 94 85
|
||||
8 39 21 57 93 40 22 58 94
|
||||
8 84 93 75 66 85 94 76 67
|
||||
8 93 57 48 75 94 58 49 76
|
||||
8 31 40 94 85 32 41 95 86
|
||||
8 40 22 58 94 41 23 59 95
|
||||
8 85 94 76 67 86 95 77 68
|
||||
8 94 58 49 76 95 59 50 77
|
||||
8 32 41 95 86 33 42 96 87
|
||||
8 41 23 59 95 42 24 60 96
|
||||
8 86 95 77 68 87 96 78 69
|
||||
8 95 59 50 77 96 60 51 78
|
||||
8 33 42 96 87 34 43 97 88
|
||||
8 42 24 60 96 43 25 61 97
|
||||
8 87 96 78 69 88 97 79 70
|
||||
8 96 60 51 78 97 61 52 79
|
||||
8 34 43 97 88 35 44 98 89
|
||||
8 43 25 61 97 44 26 62 98
|
||||
8 88 97 79 70 89 98 80 71
|
||||
8 97 61 52 79 98 62 53 80
|
||||
8 35 44 98 89 9 11 17 16
|
||||
8 44 26 62 98 11 10 13 17
|
||||
8 89 98 80 71 16 17 15 14
|
||||
8 98 62 53 80 17 13 12 15
|
||||
|
||||
CELL_TYPES 40
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
|
||||
CELL_DATA 40
|
||||
SCALARS sample_cell_scalars int
|
||||
LOOKUP_TABLE default
|
||||
1 2 3 4 5 6 7 8 9
|
||||
10 11 12 13 14 15 16 17 18
|
||||
19 20 21 22 23 24 25 26 27
|
||||
28 29 30 31 32 33 34 35 36
|
||||
37 38 39 40
|
||||
POINT_DATA 99
|
||||
FIELD FieldData 2
|
||||
sample_point_scalars 1 99 vtktypeint64
|
||||
1 2 4 6 8 10 12 15 19
|
||||
22 23 25 27 29 31 33 36 40
|
||||
44 46 48 50 52 54 56 58 60
|
||||
63 65 67 69 71 73 75 77 79
|
||||
91 93 95 97 99 101 103 105 107
|
||||
119 121 123 125 127 129 131 133 135
|
||||
147 149 151 153 155 157 159 161 163
|
||||
175 177 179 181 183 185 187 189 191
|
||||
203 205 207 209 211 213 215 217 219
|
||||
240 242 244 246 248 250 252 254 256
|
||||
286 288 290 292 294 296 298 300 302
|
||||
|
||||
VTKorigID 1 99 vtktypeint64
|
||||
0 1 2 3 4 5 6 7 8
|
||||
9 10 11 12 13 14 15 16 17
|
||||
18 19 20 21 22 23 24 25 26
|
||||
27 28 29 30 31 32 33 34 35
|
||||
36 37 38 39 40 41 42 43 44
|
||||
45 46 47 48 49 50 51 52 53
|
||||
54 55 56 57 58 59 60 61 62
|
||||
63 64 65 66 67 68 69 70 71
|
||||
72 73 74 75 76 77 78 79 80
|
||||
81 82 83 84 85 86 87 88 89
|
||||
90 91 92 93 94 95 96 97 98
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 251 KiB |
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,75 @@
|
||||
"""Contains vrml examples."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pyvista.examples.downloads import download_file
|
||||
|
||||
|
||||
def download_teapot(): # pragma: no cover
|
||||
"""Download the a 2-manifold solid version of the famous teapot example.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the VRML file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> vrml_file = examples.vrml.download_teapot()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_vrml(vrml_file)
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return download_file('vrml/teapot.wrl')
|
||||
|
||||
|
||||
def download_sextant(): # pragma: no cover
|
||||
"""Download the sextant example.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the VRML file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> vrml_file = examples.vrml.download_sextant()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_vrml(vrml_file)
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return download_file('vrml/sextant.wrl')
|
||||
|
||||
|
||||
def download_grasshopper(): # pragma: no cover
|
||||
"""Download the grasshoper example.
|
||||
|
||||
.. versionadded:: 0.45
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Filename of the VRML file.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> import pyvista as pv
|
||||
>>> from pyvista import examples
|
||||
>>> vrml_file = examples.vrml.download_grasshopper()
|
||||
>>> pl = pv.Plotter()
|
||||
>>> pl.import_vrml(vrml_file)
|
||||
>>> pl.camera_position = [
|
||||
... (25.0, 32.0, 44.0),
|
||||
... (0.0, 0.931, -6.68),
|
||||
... (-0.20, 0.90, -0.44),
|
||||
... ]
|
||||
>>> pl.show()
|
||||
|
||||
"""
|
||||
return download_file('grasshopper/grasshop.wrl')
|
||||
Reference in New Issue
Block a user