Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic DataFrame print #418

Merged
merged 35 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7f7e051
Add per-Index data format
PProfizi Jun 7, 2023
053a7b4
Add per-Index data format
PProfizi Jun 7, 2023
c7ae453
Add DataFrame._format_cells()
PProfizi Jun 7, 2023
9954267
Fix index format label_default_format
PProfizi Jun 7, 2023
71c4f1f
Revert "Fix index format label_default_format"
PProfizi Jun 7, 2023
45558e7
Revert "Add per-Index data format"
PProfizi Jun 7, 2023
72f35b0
Revert "Add per-Index data format"
PProfizi Jun 7, 2023
e8e484f
Refactor DataFrame._update_str() ti use adaptive sizing with DataFram…
PProfizi Jun 7, 2023
6784e90
WIP: ElementalNodal not functional!
PProfizi Jun 12, 2023
98fb13a
Working for ElementalNodal, updated tests
PProfizi Jun 12, 2023
d580d66
WIP
PProfizi Jun 13, 2023
b03bcc8
Element nodes are shown as zero-based
PProfizi Jun 13, 2023
f8ecd3b
Element nodes are shown as zero-based
PProfizi Jun 13, 2023
514a471
Works for multi-steps with elementalnodal
PProfizi Jun 13, 2023
c3360d9
WIP
PProfizi Jun 26, 2023
97e4027
Working version
PProfizi Jun 27, 2023
25c9a64
Add setters and getters for display
PProfizi Jun 27, 2023
01de409
Update test_dataframe_str() accordingly
PProfizi Jun 27, 2023
1872c8a
Fox case where no mesh_index (entity_ids=[1])
PProfizi Jun 27, 2023
16fb4c0
Fix Dataframe._update_str
PProfizi Jun 27, 2023
2e1083f
Merge branch 'master' into feat/dataframe_view
PProfizi Jun 27, 2023
126e4cd
Improve section on load_simulation at beginning of most examples
PProfizi Jun 27, 2023
45c419f
Set dtype of MeshIndex as int
PProfizi Jun 28, 2023
af80226
Improve repr of Index by using actual class name
PProfizi Jun 28, 2023
6fc8e2b
Add a first version of an example on Dataframe manipulation
PProfizi Jun 28, 2023
0be6906
Merge remote-tracking branch 'origin/feat/dataframe_view' into feat/d…
PProfizi Jun 28, 2023
1595285
Update test_dataframe_repr
PProfizi Jun 28, 2023
d9fe7b2
Update 00-dataframe-manipulation.py
PProfizi Jun 28, 2023
8c6eb1b
Update 00-dataframe-manipulation.py
PProfizi Jun 28, 2023
454afd1
Fix Codacy errors
PProfizi Jun 28, 2023
c32e038
Improve example layout
PProfizi Jun 28, 2023
105cd9e
Fix Codacy issue
PProfizi Jun 28, 2023
864223a
Remove rogue prints from test_dataframe.py
PProfizi Jun 29, 2023
c0eb1f1
Remove rogue prints from test_simulation.py
PProfizi Jun 29, 2023
c0121c6
Remove rogue prints from legacy tests
PProfizi Jun 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/00-Different-analysis-types/01-static-simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# on Linux.

example_path = examples.find_static_rst()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
3 changes: 2 additions & 1 deletion examples/00-Different-analysis-types/02-modal-simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# on Linux.

example_path = examples.download_modal_frame()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.ModalMechanicalSimulation(example_path)

###############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
# on Linux.

example_path = examples.find_msup_transient()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.TransientMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
# on Linux.

example_path = examples.download_harmonic_clamped_pipe()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.HarmonicMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
152 changes: 152 additions & 0 deletions examples/01-Detailed-Examples/00-dataframe-manipulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
"""
.. _ref_dataframe_example:

Create and manipulate a DPF Dataframe
=====================================
In this script a Dataframe is generated by extracting a result from a static simulation.
It then showcases different Dataframe viewing and manipulation possibilities.
"""

###############################################################################
# Perform required imports
# ------------------------
# Perform required imports. # This example uses a supplied file that you can
# get by importing the DPF ``examples`` package.

from ansys.dpf import post
from ansys.dpf.post import examples

###############################################################################
# Get the ``Simulation`` object
# -----------------------------
# Get the ``Simulation`` object that allows access to the result. The ``Simulation``
# object must be instantiated with the path for the result file. For example,
# ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"``
# on Linux.

example_path = examples.download_crankshaft()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
print(simulation)

###############################################################################
# Get a ``Dataframe`` object
# --------------------------
# Extract a result as a Dataframe
displacement_dataframe = simulation.displacement(all_sets=True)

# The Dataframe is displayed as a table, with row and column labels to identify the data.
print(displacement_dataframe)

###############################################################################
# Explore ``Index`` objects
# -------------------------
# The data labels are each defined by an Index object or one of its specialized subtypes.

# The Dataframe's column labels are defined in Dataframe.columns.
print(displacement_dataframe.columns)

###############################################################################
# A ``ResultIndex`` index defines the result stored in the Dataframe.
print(displacement_dataframe.columns[0])
# print(displacement_dataframe.columns.results_index) # equivalent
###############################################################################
# You can check values available for an Index
print(displacement_dataframe.columns[0].values)

###############################################################################
# A ``SetIndex`` index defines the available set IDs available.
# A set ID is a unique identifier associated to each time-step, step and sub-step, or frequency
# available in a simulation.
# As shown next, an Index has a name and a list of values of a given type.
print(displacement_dataframe.columns[1])
print(displacement_dataframe.columns[1].values)

###############################################################################
# The Dataframe's row labels are defined in Dataframe.index.
print(displacement_dataframe.index)

###############################################################################
# A ``MeshIndex`` defines the mesh entities for which data is available.
# It can store node IDs, element IDs, or face IDs.
print(displacement_dataframe.index[0])
# print(displacement_dataframe.index.mesh_index) # equivalent
###############################################################################
# Since the list of possible values can be long and querying it can be costly,
# the list of available values may not be determined unless explicitly asked.
print(displacement_dataframe.index[0].values)
###############################################################################
# The ``MeshIndex`` will then be updated to display the actual number of entities available.
print(displacement_dataframe.index[0])
# IMPORTANT: Note that the mesh entity IDs ordered based on the internal data storage structure,
# they are not by ascending order by default!

###############################################################################
# A ``CompIndex`` defines the result components for which data is available.
print(displacement_dataframe.index[1])
print(displacement_dataframe.index[1].values)

###############################################################################
# Change the Dataframe print
# --------------------------
# Options exist to configure the way a Dataframe is displayed.
# You can change the number of data rows displayed with:
displacement_dataframe.display_max_rows = 9
print(displacement_dataframe)
###############################################################################
# Or the number of data columns displayed with:
displacement_dataframe.display_max_columns = 2
print(displacement_dataframe)
# Notice that the ``...`` symbols specify that the Dataframe is truncated in that direction.

###############################################################################
# The special case of ElementalNodal results
# ------------------------------------------
# When dealing with results located on each node of each element (aka. ElementalNodal),
# an ``ElementNodeIndex`` index is added at creation to specify the node number in the
# element's connectivity.
stress = simulation.stress()
print(stress)
print(stress.columns[2])

###############################################################################
# Data selection
# --------------
# To select specific columns or rows, use the index names as arguments for the ``DataFrame.select``
# method, taking lists of values:
disp_X_1 = displacement_dataframe.select(
set_ids=[1], node_ids=[4872, 9005], components=["X"]
)
print(disp_X_1)

###############################################################################
# You can also select along an index using a zero-based position with ``Dataframe.iselect``:
disp_Y_9005_3 = displacement_dataframe.iselect(
set_ids=[2], node_ids=[1], components=[1]
)
print(disp_Y_9005_3)

###############################################################################
# Extract data
# ------------
# Once the Dataframe contains the specific data you require, extract it as an array with:
print(disp_X_1.array)
# IMPORTANT: Note that for the extraction of the Dataframe's data as an array to make sense,
# you must first filter the columns label values to a unique combination of values.
# The exception is for ElementalNodal data, which is returned as a 2D array.
print(stress.array.shape)

###############################################################################
# Plot a Dataframe
# ------------------
displacement_dataframe.plot()

###############################################################################
# Animate a transient Dataframe
# -----------------------------
displacement_dataframe.animate()
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# on Linux.

example_path = examples.download_modal_frame()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.ModalMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# on Linux.

example_path = examples.download_all_kinds_of_complexity_modal()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.ModalMechanicalSimulation(example_path)
# print the simulation to get an overview of what's available
print(simulation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# on Linux.

example_path = examples.download_harmonic_clamped_pipe()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.HarmonicMechanicalSimulation(example_path)

###############################################################################
Expand Down
3 changes: 2 additions & 1 deletion examples/01-Detailed-Examples/04-invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# on Linux.

example_path = examples.download_crankshaft()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
3 changes: 2 additions & 1 deletion examples/01-Detailed-Examples/05-export_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# on Linux.

example_path = examples.download_crankshaft()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
4 changes: 4 additions & 0 deletions examples/01-Detailed-Examples/06-compute-min-max.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
# on Linux.

example_path = examples.download_crankshaft()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
# on Linux.

example_path = examples.download_crankshaft()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for auto-completion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
3 changes: 2 additions & 1 deletion examples/02-Performance-Improvements/02-mesh-skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
# on Linux.

example_path = examples.download_crankshaft()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
# on Linux.

example_path = examples.download_crankshaft()
# to automatically detect the simulation type, use:
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
3 changes: 0 additions & 3 deletions examples/03-Cyclic-Examples/03-cyclic-mesh-external-layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
# on Linux.

example_path = examples.download_modal_cyclic()
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
simulation = post.ModalMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
3 changes: 0 additions & 3 deletions examples/03-Cyclic-Examples/04-cyclic-mesh-skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
# on Linux.

example_path = examples.download_modal_cyclic()
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
simulation = post.ModalMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
3 changes: 0 additions & 3 deletions examples/03-Cyclic-Examples/05-modal_cyclic_no_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
# on Linux.

example_path = examples.download_modal_cyclic()
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
simulation = post.ModalMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
Expand Down
Loading