Module containing the DataFrame class.

DataFrame#

class ansys.dpf.post.dataframe.DataFrame(data: FieldsContainer | _MockPropertyFieldsContainer, index: MultiIndex | Index | List[int], columns: MultiIndex | Index | List[str] | None = None)#

A DataFrame style API to manipulate DPF data.

property display_max_columns: int#

Returns the current maximum number of columns to display for this Dataframe.

property display_max_rows: int#

Returns the current maximum number of rows to display for this Dataframe.

property columns: MultiIndex#

Returns the MultiIndex for the columns of the DataFrame.

property index: MultiIndex#

Returns the MultiIndex for the rows of the DataFrame.

property axes: List[MultiIndex]#

Returns a list with the row MultiIndex first and the columns MultiIndex second.

property results_index: ResultsIndex | None#

Returns the available ResultsIndex is present.

property mesh_index: MeshIndex | None#

Returns the available MeshIndex is present.

property labels: List[str]#

Returns a list of the names of available LabelIndex indexes.

property array: ndarray#

Returns the data as a np.ndarray for a single combination of column label values.

select(**kwargs)#

Returns a new DataFrame based on selection criteria (value-based).

Parameters:

**kwargs

This function accepts as argument any of the Index names available associated with a value or a list of values. For example, if ‘time’ is an available class:Index <ansys.dpf.post.index.Index> of the class:DataFrame <ansys.dpf.post.DataFrame> df, then you can select the time 1

by using df.select(time=1).

One can get the list of available axes using DataFrame.axes.

Return type:

DataFrame

Returns:

A DataFrame of the selected values.

iselect(**kwargs)#

Returns a new DataFrame based on selection criteria (index-based).

Parameters:

**kwargs – This function accepts as argument any of the Index names available associated with a value or a list of values. For example, if ‘time’ is an available class:Index <ansys.dpf.post.index.Index> of the class:DataFrame <ansys.dpf.post.DataFrame> df, then you can select the first time value by using df.select(set_id=0). One can get the list of available axes using DataFrame.axes.

Return type:

DataFrame

Returns:

A DataFrame of the selected values.

plot(shell_layer=shell_layers.top, **kwargs)#

Plot the result.

Parameters:
  • shell_layer (default: <shell_layers.top: 0>) – Shell layer to show if multi-layered shell data is present. Defaults to top.

  • **kwargs – This function accepts as argument any of the Index names available associated with a single value. For example, if ‘set_ids’ is an available class:Index <ansys.dpf.post.index.Index> of the class:DataFrame <ansys.dpf.post.DataFrame> df, then you can plot the data at set_id 1 by using df.plot(set_ids=1). One can get the list of available axes using DataFrame.axes. If the combination of arguments on axes does not return data, this returns None. Also supports additional keyword arguments for the plotter. For additional keyword arguments, see help(pyvista.plot).

Return type:

Optional[DpfPlotter]

Returns:

The interactive plotter object used for plotting.

animate(save_as: PathLike | str | None = None, deform: bool = False, scale_factor: List[float] | float = 1.0, shell_layer: shell_layers = shell_layers.top, **kwargs)#

Animate the DataFrame along its ‘set’ axis.

Note

At the moment only useful to produce a temporal animation. Each frame will correspond to data for a value of the SetIndex in the columns MultiIndex.

Parameters:
  • save_as (Path of file to save the animation to. Defaults to None. Can be of any format) – supported by pyvista.Plotter.write_frame (.gif, .mp4, …).

  • deform (bool, default: False) – Whether to plot the deformed mesh.

  • scale_factor (float, list, optional) – Scale factor to apply when warping the mesh. Defaults to 1.0. Can be a list to make scaling frequency-dependent.

  • shell_layer (shell_layers, default: <shell_layers.top: 0>) – Shell layer to show if multi-layered shell data is present. Defaults to top.

Returns:

The interactive plotter object used for animation.

min(axis: int | str | None = 0)#

Return the minimum value over the requested axis.

Parameters:

axis (Optional[Union`[:py:class:`int, str]], default: 0) – Axis to perform minimum across. Defaults to the MeshIndex (0), the row index containing mesh entity IDs. This computes the minimum across the mesh for each set. Can also be the SetIndex (1), the column index containing set (time/frequency) IDs. This computes the minimum across sets (time/frequency) for each mesh entity.

Return type:

Union[DataFrame, float]

Returns:

A scalar if the result of the query is a single number, or a DataFrame if several numbers along one or several axes.

Examples

>>> from ansys.dpf import post
>>> from ansys.dpf.post import examples
>>> simulation = post.StaticMechanicalSimulation(examples.download_crankshaft())
>>> displacement = simulation.displacement(all_sets=True)
>>> # Compute the maximum displacement value for each component at each time-step
>>> minimum_over_mesh = displacement.min(axis="node_ids")
>>> print(minimum_over_mesh)  
   results       U (m)
   set_ids           1           2           3
components
         X -7.4732e-04 -1.5081e-03 -2.2755e-03
         Y -4.0138e-04 -8.0316e-04 -1.2014e-03
         Z -2.1555e-04 -4.3299e-04 -6.5101e-04
>>> # Compute the maximum displacement for each node and component across time
>>> minimum_over_time = displacement.min(axis="set_ids")
>>> print(minimum_over_time)  
            results       U (m)
 node_ids components
     4872          X -3.4137e-05
                   Y  5.1667e-04
                   Z -4.1346e-06
     9005          X -5.5625e-05
                   Y  4.8445e-04
                   Z -4.9795e-07
      ...        ...         ...
>>> # Compute the maximum displacement overall
>>> minimum_overall = minimum_over_time.min()
>>> print(minimum_overall)  
   results       U (m)
components
         X -2.2755e-03
         Y -1.2014e-03
         Z -6.5101e-04
max(axis: int | str | None = 0)#

Return the maximum value over the requested axis.

Parameters:

axis (Optional[Union`[:py:class:`int, str]], default: 0) – Axis to perform maximum across. Defaults to the MeshIndex (0), the row index containing mesh entity IDs. This computes the maximum across the mesh for each set. Can also be the SetIndex (1), the column index containing set (time/frequency) IDs. This computes the maximum across sets (time/frequency) for each mesh entity.

Return type:

Union[DataFrame, float]

Returns:

A scalar if the result of the query is a single number, or a DataFrame if several numbers along one or several axes.

Examples

>>> from ansys.dpf import post
>>> from ansys.dpf.post import examples
>>> simulation = post.StaticMechanicalSimulation(examples.download_crankshaft())
>>> displacement = simulation.displacement(all_sets=True)
>>> # Compute the maximum displacement value for each component at each time-step
>>> maximum_over_mesh = displacement.max(axis="node_ids")
>>> print(maximum_over_mesh)  
   results       U (m)
   set_ids           1           2           3
components
         X  7.3303e-04  1.4495e-03  2.1441e-03
         Y  1.3962e-03  2.7884e-03  4.1656e-03
         Z  2.1567e-04  4.3321e-04  6.5135e-04
>>> # Compute the maximum displacement for each node and component across time
>>> maximum_over_time = displacement.max(axis="set_ids")
>>> print(maximum_over_time)  
             results       U (m)
 node_ids components
     4872          X  5.6781e-06
                   Y  1.5417e-03
                   Z -2.6398e-06
     9005          X -2.6323e-06
                   Y  1.4448e-03
                   Z  5.3134e-06
      ...        ...         ...
>>> # Compute the maximum displacement overall
>>> maximum_overall = maximum_over_time.max()
>>> print(maximum_overall)  
   results       U (m)
components
         X  2.1441e-03
         Y  4.1656e-03
         Z  6.5135e-04