converting op2_results to data frames

23 views
Skip to first unread message

James Cook

unread,
Oct 15, 2024, 3:06:19 PM10/15/24
to pyNastran Discuss
Hi all,

I tried searching and did not see anyone else have this issue yet. When running: isat.get_op2_stats(short=True) as done from the example found here:  https://github.com/SteveDoyle2/pyNastran/blob/main/docs/quick_start/demo/op2_pandas_DataFrames.ipynb.


I noticed my output is this: Results.jpg

Well when trying to convert the results that prelude with "op2_results", nothing is found. How do I find these results so i can convert them all to a dataframe? Thank you. Let me know if I need to clarify anything or include my code.

Steven Doyle

unread,
Oct 15, 2024, 7:06:46 PM10/15/24
to pynastra...@googlegroups.com
Can you include your code?

--
You received this message because you are subscribed to the Google Groups "pyNastran Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pynastran-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pynastran-discuss/643dee8a-9ff1-4424-88df-d717b71e3df7n%40googlegroups.com.

James Cook

unread,
Oct 15, 2024, 9:07:53 PM10/15/24
to pyNastran Discuss
Of course.

import os
import pandas as pd

import pyNastran
pkg_path = pyNastran.__path__[0]
from pyNastran.op2.op2 import read_op2
from pyNastran.utils.nastran_utils import run_nastran

# Initialize the OP2 object
op2_filename=('sp_bar_area_export_20240516_narrowed_down_fem1_sim1-acceleration_static_cases_run01.op2')

isat = read_op2(op2_filename, build_dataframe=True, debug=False, skip_undefined_matrices=True,exclude_results='*strain_energy')

# Get OP2 stats
stats = isat.get_op2_stats(short=True)
print(stats)

When "stats" prints out it shows this:

params:
  K6ROT = 100.0
  OIBULK = 'YES'
  OMACHPR = 'YES'
  POST = -2
  POSTEXT = 'YES'
  UNITSYS = 'MN-MM'
op2_results.eqexin: EQEXIN(nid, ndof, doftype); nnodes=4091
op2_results.gpdt: GPDT(nid_cp_cd_ps, xyz); nnodes=4091
op2_results.bgpdt: BGPDT(cd, xyz); nnodes=4091
op2_results.stress.cbeam_stress[1]
op2_results.stress.cbeam_stress[2]
op2_results.stress.cbeam_stress[3]
op2_results.stress.cbeam_stress[4]
op2_results.stress.cbeam_stress[5]
op2_results.stress.cquad4_composite_stress[1]
op2_results.stress.cquad4_composite_stress[2]
op2_results.stress.cquad4_composite_stress[3]
op2_results.stress.cquad4_composite_stress[4]
op2_results.stress.cquad4_composite_stress[5]
op2_results.stress.ctria3_composite_stress[1]
op2_results.stress.ctria3_composite_stress[2]
op2_results.stress.ctria3_composite_stress[3]
op2_results.stress.ctria3_composite_stress[4]
op2_results.stress.ctria3_composite_stress[5]
op2_results.failure_indices.cquad4_composite_force[1]
op2_results.failure_indices.cquad4_composite_force[2]
op2_results.failure_indices.cquad4_composite_force[3]
op2_results.failure_indices.cquad4_composite_force[4]
op2_results.failure_indices.cquad4_composite_force[5]
displacements[1]
displacements[2]
displacements[3]
displacements[4]
displacements[5]
spc_forces[1]
spc_forces[2]
spc_forces[3]
spc_forces[4]
spc_forces[5]


I then want to see the data frames of each of them, but the only data frames that woll work are highlighted in yellow above. The code I use in the console to look at a dataframe is this: 

op2_results.stress.ctria3_composite_stress = isat.op2_results.stress.ctria3_composite_stress[5]  .data_frame

The error simply says: *** NameError: name 'op2_results' is not defined. So this is mny confusion how come there are several lines above that have "op2_results" that prelude them, but when converting them to a data frame it does not recognize them? I know my op2 file has all those results, but I can't extract them via this method. Thanks for the help.


Upon typing I solved it!!!!!!!

Here is what needs to happen. With any line that contains 'op2_results', like  op2_results.stress.ctria3_composite_stress[5] above, simply parse out everything before the element type. 

ex:  op2_results.stress.ctria3_composite_stress[5] -> ctria3_composite_stress[5], you can then convert to data frame by ctria3_composite_stress=isat.ctria3_composite_stress[5].data_frame

Thanks!

Steven Doyle

unread,
Oct 16, 2024, 12:51:09 AM10/16/24
to pynastra...@googlegroups.com
> op2_results.stress.ctria3_composite_stress[5] -> ctria3_composite_stress[5], you can then convert to data frame by ctria3_composite_stress=isat.ctria3_composite_stress[5].data_frame

 That'll be gone in 1.5. The op2 class is hard to find things, so rather than deleting out functions, it was easier to move the results.

model = read_op2(op2_filename)
model.displacements[1].data_frame
model.op2_results.stress.ctria3_composite_stress[1].data_frame

I tried to be similar to the other form.

Reply all
Reply to author
Forward
0 new messages