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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
"""PyVista package for 3D plotting and mesh analysis."""
from __future__ import annotations
import os
import sys
from typing import TYPE_CHECKING
from typing import Literal
import warnings
from pyvista._plot import plot as plot
from pyvista._version import __version__ as __version__
from pyvista._version import version_info as version_info
from pyvista.core import *
from pyvista.core import _validation as _validation
from pyvista.core._typing_core._dataset_types import _DataObjectType as _DataObjectType
from pyvista.core._typing_core._dataset_types import (
_DataSetOrMultiBlockType as _DataSetOrMultiBlockType,
)
from pyvista.core._typing_core._dataset_types import _DataSetType as _DataSetType
from pyvista.core._typing_core._dataset_types import _GridType as _GridType
from pyvista.core._typing_core._dataset_types import _PointGridType as _PointGridType
from pyvista.core._typing_core._dataset_types import _PointSetType as _PointSetType
from pyvista.core._vtk_core import vtk_version_info as vtk_version_info
from pyvista.core.cell import _get_vtk_id_type
from pyvista.core.utilities.observers import send_errors_to_logging
from pyvista.core.wrappers import _wrappers as _wrappers
from pyvista.jupyter import set_jupyter_backend as set_jupyter_backend
from pyvista.report import GPUInfo as GPUInfo
from pyvista.report import Report as Report
from pyvista.report import get_gpu_info as get_gpu_info
if TYPE_CHECKING:
import numpy as np
# get the int type from vtk
ID_TYPE: type[np.int32 | np.int64] = _get_vtk_id_type()
# determine if using at least vtk 9.0.0
if vtk_version_info.major < 9: # pragma: no cover
from pyvista.core.errors import VTKVersionError
msg = 'VTK version must be 9.0.0 or greater.'
raise VTKVersionError(msg)
# catch annoying numpy/vtk future warning:
warnings.simplefilter(action='ignore', category=FutureWarning)
# A simple flag to set when generating the documentation
OFF_SCREEN = os.environ.get('PYVISTA_OFF_SCREEN', 'false').lower() == 'true'
# flag for when building the sphinx_gallery
BUILDING_GALLERY = os.environ.get('PYVISTA_BUILDING_GALLERY', 'false').lower() == 'true'
# A threshold for the max cells to compute a volume for when repr-ing
REPR_VOLUME_MAX_CELLS = 1e6
# Set where figures are saved
FIGURE_PATH = os.environ.get('PYVISTA_FIGURE_PATH', None)
ON_SCREENSHOT = os.environ.get('PYVISTA_ON_SCREENSHOT', 'false').lower() == 'true'
# Send VTK messages to the logging module:
send_errors_to_logging()
# theme to use by default for the plot directive
PLOT_DIRECTIVE_THEME = None
# Set a parameter to control default print format for floats outside
# of the plotter
FLOAT_FORMAT = '{:.3e}'
# Serialization format to be used when pickling `DataObject`
PICKLE_FORMAT: Literal['vtk', 'xml', 'legacy'] = 'vtk' if vtk_version_info >= (9, 3) else 'xml'
# Name used for unnamed scalars
DEFAULT_SCALARS_NAME = 'Data'
MAX_N_COLOR_BARS = 10
_VTK_SNAKE_CASE_STATE: Literal['allow', 'warning', 'error'] = 'error'
# Import all modules for type checkers and linters
if TYPE_CHECKING:
from pyvista import demos as demos
from pyvista import examples as examples
from pyvista import ext as ext
from pyvista import trame as trame
from pyvista import utilities as utilities
from pyvista.plotting import *
# Lazily import/access the plotting module
def __getattr__(name):
"""Fetch an attribute ``name`` from ``globals()`` or the ``pyvista.plotting`` module.
This override is implemented to prevent importing all of the plotting module
and GL-dependent VTK modules when importing PyVista.
Raises
------
AttributeError
If the attribute is not found.
"""
import importlib # noqa: PLC0415
import inspect # noqa: PLC0415
allow = {
'demos',
'examples',
'ext',
'trame',
'utilities',
}
if name in allow:
return importlib.import_module(f'pyvista.{name}')
# avoid recursive import
if 'pyvista.plotting' not in sys.modules:
import pyvista.plotting # noqa: F401, PLC0415
try:
feature = inspect.getattr_static(sys.modules['pyvista.plotting'], name)
except AttributeError:
msg = f"module 'pyvista' has no attribute '{name}'"
raise AttributeError(msg) from None
return feature
|