f4enix.output.plotter.MeshPlotter#
- class f4enix.output.plotter.MeshPlotter(mesh: PolyData, stl: PolyData | None = None)#
Bases:
objectObject responsible for the plotting of meshes.
Allows slicing in different orientation and plotting of slices.
- Parameters:
mesh (pv.PolyData) – mesh to be sliced
stl (pv.PolyData, optional) – stl to be superimposed in the slices, by default None
- Variables:
mesh (pv.PolyData) – mesh to be sliced
stl (pv.PolyData, optional) – stl to be superimposed in the slices
legend_args (dict) – contains the default parameters for the plot of the scalar bars. use print(self.legend_args) to check the default values. The entire list of parameters that can be used can be found in the pv.Plotter.add_scalar_bar() method
Examples
Load a mesh and stl file and slice them in different way
>>> from f4enix.output.plotter import MeshPlotter ... # Initialize the plotter with the mesh and stl ... # scaling the mesh and stl accordingly to be in the same units ... plotter = MeshPlotter(global_mesh.scale(0.01, inplace=False), ... stl=stl.scale(0.001, inplace=False)) ... # There are many default settings that can be modified ... plotter.legend_args['vertical'] = False ... # -- Different slicing methods can be used: -- ... # toroidal slicing ... toroidal_slices = plotter.slice_toroidal(30) # 30 deg. increment ... # vertical slicing on an axis and defininig number of divisions ... horizontal_slices = plotter.slice_on_axis('z', 3) ... # General slicing using origin and normals for each slice ... slice_params = [ ['slice 1', 0, 0, -11.500, 0, 0, 1], ['slice 2', 9, 0, -8.425, 0.25, 0, 0.9]] ... general_slices = plotter.slice(slice_params)
and then plot the meshes
>>> # Plot the slices ... array_name = 'scalar1' # name of the scalar to be plot from the mesh ... images = plotter.plot_slices(horizontal_slices, array_name, ... n_colors=7, # colors of the legend ... min_max=(1e6, 1e12), # limits ... scale_title='Gy/h') # legend title
Methods
__init__(mesh[, stl])Object responsible for the plotting of meshes.
plot_slices(slices, array_name[, outpath, ...])Plot a series of slices to an outpath folder.
slice(slice_param)Perform arbitrary general slicing providing origin and normal vectors.
slice_on_axis(axis, n)Creates a series of slice of the mesh distributed equally along the specified axis.
slice_toroidal(theta_increment[, center, ...])Create a series of slices of the mesh distributed toroidally equally around the vertical axis (z).
- plot_slices(slices: list[tuple[str, PolyData, PolyData | None]], array_name: str, outpath: PathLike | None = None, min_max: tuple[float] | None = None, log_scale: bool = True, stl_color: str = 'white', n_colors: int = 256, scale_quality: float = 3, scale_title: str | None = None, custom_categories: str | None = None) list[tuple[str, Image]]#
Plot a series of slices to an outpath folder. The slices names are used as file names.
- Parameters:
slices (list[tuple[str, pv.PolyData, Union[pv.PolyData, None]]]) – list of slices to be plotted. Usually produced with MeshPlotter methods.
array_name (str) – name of the scalar array to be plotted
outpath (os.PathLike, optional) – path to the directory that will contain all the plots. This folder must be already created. Files with the same name will be overridden. default is None, meaning that images will not be saved
min_max (tuple[float], optional) – min and max values to be set for the scalars in all plots
log_scale (bool, optional) – if true, activate logarithmic scale, by default True
stl_color (str, optional) – color for the stl, by default ‘white’
n_colors (int, optional) – number of discrete colors to be used in the legend, by default 256
scale_quality (float, optional) – increase the resolution of the picture by a factor, by default 2
scale_title (str, optional) – ovverride the title of the scalar legend. The defualt is None, meaning that the array name will be used.
custom_categorical (str) – plot special categorical plots. Admitted categories are TID, TNF and SDDR.
- Returns:
list of images of the slices
- Return type:
list[tuple[str, Image.Image]]
- Raises:
ValueError – if the path do not exists
- slice(slice_param: list[list]) list[tuple[str, PolyData, PolyData | None]]#
Perform arbitrary general slicing providing origin and normal vectors.
- Parameters:
slice_param (list[list]) –
- matrix of parameters to be provided, one row for each slice.
[[name, x, y, z, normx, normy, normz], …]
- Returns:
contains a list of (slice name, mesh slice, stl slice). the names are assigned according to slicing logic. In case of no stl assigned to the plotter, the stl slice will be equal to None.
- Return type:
list[tuple[str, pv.PolyData, Union[pv.PolyData, None]]]
- slice_on_axis(axis: str, n: int) list[tuple[str, PolyData, PolyData | None]]#
Creates a series of slice of the mesh distributed equally along the specified axis. Stl file will be sliced accordingly if present
- Parameters:
axis (str) – either ‘x’, ‘y’ or ‘z’
n (int) – number of divisions
- Returns:
contains a list of (slice name, mesh slice, stl slice). the names are assigned according to slicing logic. In case of no stl assigned to the plotter, the stl slice will be equal to None.
- Return type:
list[tuple[str, pv.PolyData, Union[pv.PolyData, None]]]
- slice_toroidal(theta_increment: float, center: list = [0, 0, 0], min_max_theta: tuple[float, float] | None = None) list[tuple[str, PolyData, PolyData | None]]#
Create a series of slices of the mesh distributed toroidally equally around the vertical axis (z). Stl file will be sliced accordingly if present
- Parameters:
theta_increment (float) – theta increments to be performed for each slide
center (list, optional) – x, y, z point to be used as center for the slicing, by default [0, 0, 0].
min_max_theta (tuple(float, float), optional) – specify a minimum and max theta for the plots (degrees). This may help avoiding slices in empty regions in partial models if the mesh is not properly rotated. By default is None, meaning that the slicing will start at theta = 0 and finish at theta = pi.
- Returns:
contains a list of (slice name, mesh slice, stl slice). the names are assigned according to slicing logic. In case of no stl assigned to the plotter, the stl slice will be equal to None.
- Return type:
list[tuple[str, pv.PolyData, Union[pv.PolyData, None]]]