Ausnahme gefangen: SSL certificate problem: certificate is not yet valid 📌 PLAXIS Output Visualisation Using Python

🏠 Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeiträge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden Überblick über die wichtigsten Aspekte der IT-Sicherheit in einer sich ständig verändernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch übersetzen, erst Englisch auswählen dann wieder Deutsch!

Google Android Playstore Download Button für Team IT Security



📚 PLAXIS Output Visualisation Using Python


💡 Newskategorie: AI Nachrichten
🔗 Quelle: towardsdatascience.com

PLAXIS AUTOMATION SERIES

Step-by-step guide toward automation

Photo by Luke Chesser on Unsplash

The PLAXIS Output app offers the possibility of using the built-in plotting tool to compare outputs at different phases. Although it provides some basic plot functions which allow users to visualise results, people often go with Excel as it allows flexibility in plot formatting, data manipulation and results sharing.

With no doubt, Excel is a powerful and well-known software for data visualisation. Though, PLAXIS does not provide full integration with Excel, making the extraction and visualisation process time-consuming. There are three possible areas of improvement in terms of data visualisation:

  1. Combine all data into one worksheet for plotting
  2. Automate the process of selecting data series in Excel when creating plots
  3. Create plots with customised series names and axis titles

This tutorial aims to extend the lesson learnt from the 2nd tutorial. We will extract output from multiple phases and use plots to compare the results. This can be done with the following three steps:

  1. Install external module to PLAXIS environment
  2. Extract results for multiple phases
  3. Compare results at different phases using plots in Excel
  4. Formatting with Openpyxl

As before, this tutorial requires the readers have VS Code and PLAXIS environment installed. Follow the instructions from the article below if you’re new to this page. Let’s get started!

Start Using Python to Automate PLAXIS

PLAXIS Example Model

We will use the same PLAXIS 2D model from 2nd tutorial. Follow the instructions below to set up and calculate the model if you haven’t done so.

Goodbye Boring PLAXIS Output with Python

Similar to the last tutorial, we will open the PLAXIS file using “open_output.py” such that the API server can be enabled.

As a recap, we use the following code to open the file:

Screenshot from VS Code by the author

After running the code above, both PLAXIS 2D input and output apps should be opened automatically. From the output app, you should see “SERVER ACTIVE on port 10001”.

Screenshot from PLAXIS by the author

Step 1: Install External Module to PLAXIS Environment

Our goal is to extract results from PLAXIS and create comparison plots in excel. In order to do so, we need three external modules:

  • Pandas
  • Xlsxwriter
  • Openpyxl

The process of installing external modules through PLAXIS command prompt has been described in detail in the 2nd tutorial. Make sure you have gone through the process before proceeding with the following steps.

From the last tutorial, both pandas and xlsxwriter should be installed. Note that Python modules are version sensitive, this is because some modules have connections to other modules and hence version updates may cause malfunctions. This is essential to have consistent module dependencies in the PLAXIS environment.

The versions of modules I have used in this tutorial are as follows:

pandas == 1.5.2
xlsxwriter == 3.0.3
openpyxl == 3.0.9
defusedxml == 0.7.1

To check the current version of module, we can use the following command in the PLAXIS command prompt:

python -m pip show pandas
Screenshot from PLAXIS by the author

If the versions are not consistent, we can use the following command to upgrade/downgrade the version:

python -m pip install --upgrade pandas==1.5.2

Install the rest of the modules:

python -m pip install xlsxwriter==3.0.3
python -m pip install openpyxl==3.0.9
python -m pip install defusedxml==0.7.1

In some situations, you may encounter an error when installing defusedxml

ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied

If that’s your case, try the following code:

python -m pip install --upgrade defusedxml==0.7.1 --user

Now that we have installed all the required modules. We can now ready to extract results from different phases in PLAXIS using Python script.

Step 2: Extract Results for Multiple Phases

The main goal of Step 2 is to extract results (Bending moment) from three phases in the ‘Excavation’ model. We will then export the results to Excel in a worksheet called ‘combined_Plate_1’ with the columns shown below:

Screenshot from excel by the author

First, we create an empty python file and call it “plot_plate_combine.py”.

Import Modules and Start Server

from plxscripting.easy import *
import math
import pandas as pd
from openpyxl import load_workbook
from openpyxl.chart import (
ScatterChart,
Reference,
Series,
)
###############################################
PORT_i = 10000 # Define a port number.
PORT_o = 10001
PASSWORD = 'SxDBR<TYKRAX834~' # Define a password.



# Start the scripting server.
s_i, g_i = new_server('localhost', PORT_i, password=PASSWORD)
s_o, g_o = new_server('localhost', PORT_o, password=PASSWORD)

Define File Name

File location: C:\Users\phtsang\Desktop\PLAXIS_V22\Script

File name: can be any name you want

EXCEL_PATH=r'C:\Users\phtsang\Desktop\PLAXIS_V22\Script\\'
EXCEL_NAME='Plate_y.xlsx'


FILENAME=EXCEL_PATH+EXCEL_NAME

Input Definition

In this case, we will extract the bending moment for ‘Plate_1’ from the phases below:

  • ‘Installation of strut [Phase_3]’
  • ‘Second (submerged) excavation stage [Phase_4]’
  • ‘Third excavation stage [Phase_5]’
###############################################
#Inputs:
plate_input=['Plate_1']
phase_input=['Installation of strut [Phase_3]','Second (submerged) excavation stage [Phase_4]','Third excavation stage [Phase_5]']

Your script should look like:

Screenshot from VS Code by the author

Result Extraction

After pre-processing, we will define a function to extract bending moment (a simplified version from last tutorial) and call it “get_plate()”.

def get_plate(plate_o,phase_o):


plateY=g_o.getresults(plate_o,phase_o,g_o.ResultTypes.Plate.Y, "node")
plateM=g_o.getresults(plate_o,phase_o,g_o.ResultTypes.Plate.M2D, "node")


phasename=str(phase_o.Identification).split('[')[0]
col1='Bending Moment [kNm/m]'+'_'+phasename


results = {'Y': plateY,col1: plateM}


plateresults=pd.DataFrame(results)
plateresults = plateresults.sort_values(by=['Y'],ascending=False)


return plateresults
Screenshot from VS Code by the author

Export to Excel

Unlike last tutorial, we want to extract results from multiple phases instead of a single phase. Hence, the “export_excel()” function needs to be modified. Three actions are involved:

  1. Loop through the name of the existing phase from the current model
  2. Cross-check with the input of the phase by the user (i.e. Phase 3, 4 and 5).
  3. Extract results if they match and export to individual worksheet (e.g. Plate_1_Phase_3)
  4. Combine the results into a new Dataframe and export to a worksheet (‘combined_Plate_1’)

These actions can be done with the following code. Let’s break it down!

def export_excel(plate_input,phase_input,filename):
writer = pd.ExcelWriter(filename, engine='xlsxwriter')
combined=[]
for i in range(len(phase)):
for j in range(len(phase_input)):
if phase[i].Identification == phase_input[j]:
name=str(phase[i].Identification).split(' [')[1]
name=name.split(']')[0]
sheet_name = "%s_%s" % (plate[0].Name, name)
results = get_plate(plate[0], phase[i])
combined.append(results)
results.to_excel(writer,sheet_name=sheet_name,index=False)


combinedsheet='combined'+'_'+str(plate[0].Name)
combined=pd.concat(combined, axis=1)
combined.to_excel(writer,sheet_name=combinedsheet,index=False)
writer.save()



export_excel(plate_input,phase_input,FILENAME)
  • We need to first define an empty list ‘combined=[ ]’. This allows us to append the extracted results at each phase into a single list such that we can concatenate them in the last step.
  • Next step is to loop through the existing phases of the model and see which one matches our input. This is done using PLAXIS command ‘phase[i].Identification’ which gives the full name of each phase.
for i in range(len(phase)):
for j in range(len(phase_input)):
if phase[i].Identification == phase_input[j]:
  • The following code is for naming purpose. For example, ‘phase[0].Identification’ will give ‘Installation of strut [Phase_3]’. I want to get ‘Phase_3’ which is sitting between the squared bracket [ ]. Then, I combine ‘Plate_1’ and ‘Phase_3’ to form the worksheet name.
name=str(phase[i].Identification).split(' [')[1]
name=name.split(']')[0]
sheet_name = "%s_%s" % (plate[0].Name, name)
  • The bending moment of PLate_1 at each phase is extracted using ‘get_plate()’ function and stored as results. The results are then appended to the ‘combined’ list through the method ‘combined.append(results)’. Finally, use ‘results.to_excel(writer,sheet_name=sheet_name,index=False)’ to export results at each phase to individual worksheet.
results = get_plate(plate[0], phase[i])
combined.append(results)
results.to_excel(writer,sheet_name=sheet_name,index=False)
  • Last four lines aim to combine the results in ‘combined’ list and export to’combined_Plate_1' worksheet. This is done by pandas’s method ‘concat()’. It is important to input ‘axis=1’ as an argument as it tells pandas to combine the results horizontally (by rows). By default, ‘axis=0’ combines the results vertically (by columns).
combinedsheet='combined'+'_'+str(plate[0].Name
combined=pd.concat(combined, axis=1)
combined.to_excel(writer,sheet_name=combinedsheet,index=False)
writer.save())

Your final script should look like:

Screenshot from VS Code by the author

Now that we have extracted results from all phases, we can then proceed with creating plots in Excel using Python.

Step 3: Compare results at different phases using plots in Excel with Openpyxl

Lastly, we will learn about Openpyxl which is a module that allows us to create Excel plot.

We create a function, call it “get_combined_plot()”.

  • df_inter stores the dataframe obtained from the ‘combined_Plate_1’. sheet is where I specify the worksheet ‘combined_Plate_1’ such that I can create plot there.
def get_combined_plot(filename,sheetname):
df_inter = pd.read_excel(filename, sheet_name = sheetname,engine="openpyxl")
wb=load_workbook(filename)
sheet=wb[sheetname]
  • Then, create a chart object called ‘chart1’ which is a scatter chart. After that, we assign axis titles using openpyxl methods (x_axis.title and y_axis.title).
  • yvalue stores the Y coordinates of the results using method ‘Reference()’.
  • position & prow is where I specify the location of the plot.
    chart1=ScatterChart()
chart1.x_axis.title = 'Bending Moment (kNm/m)'
chart1.y_axis.title = 'RL (m)'
chart={'chart1':chart1}
yvalue=Reference(sheet,min_col=1,min_row=2,max_row=len(df_inter)+1)
position='G'
prow=1
  • Then, extract the bending moment values from second column and store them in value.
  • Once we have data for x and y axis, we use ‘Series()’ to create a series and assign it to ‘chart1’ using ‘chart1.series.append(series)’.
    if df_inter.columns.values[1].split(' [')[0] == 'Bending Moment'
value=Reference(sheet,min_col=2,min_row=2,max_row=len(df_inter)+1)
series=Series(yvalue,value,title=list(df_inter.columns.values)[1])

chart1.series.append(series):
  • The code below is mainly for formatting which set plot styles such as height, tick box and legend position etc (like typical excel plot setting). More formatting details are outlined in the official documentation:

Charts - openpyxl 3.0.10 documentation

    charts='chart1'
chart[charts].height=15
chart[charts].y_axis.tickLblPos = 'low'
chart[charts].legend.position = 'b'


if ord(position)<89 and prow<=2:
sheet.add_chart(chart[charts], position+str(1))
position=chr(ord(position)+10)
prow=prow+1
wb.save(filename)
  • The steps above created plot using the first two columns (i.e. ‘Y’ and ‘Bending Moment [kNm/m]_Installation of strut ‘)
  • Final step is to loop through the rest of the columns and add them as two extra series to the existing plot.
  • In order to identify if the columns contain Y coordinate or Bending moment, we need to use if-else statement.
  • If the column title is ‘Y’, it will store the column values to yvalue (i.e. y axis). If the column title contains ‘Bending Moment’, it will store column values to value (i.e. x axis).
    for i in range(3,len(df_inter.columns)+1):
if df_inter.columns.values[i-1].split('.')[0] != 'Y':
if df_inter.columns.values[i-1].split(' [')[0] == 'Bending Moment':
value=Reference(sheet,min_col=i,min_row=2,max_row=len(df_inter)+1)
series=Series(yvalue,value,title=list(df_inter.columns.values)[i-1])
chart1.series.append(series)
elif df_inter.columns.values[i-1].split('.')[0] == 'Y':
yvalue=Reference(sheet,min_col=i,min_row=2,max_row=len(df_inter)+1)
wb.save(filename)

The final script is shown below:

def get_combined_plot(filename,sheetname):
df_inter = pd.read_excel(filename, sheet_name = sheetname,engine="openpyxl")
wb=load_workbook(filename)
sheet=wb[sheetname]


chart1=ScatterChart()
chart1.x_axis.title = 'Bending Moment (kNm/m)'
chart1.y_axis.title = 'RL (m)'
chart={'chart1':chart1}
xvalue=Reference(sheet,min_col=1,min_row=2,max_row=len(df_inter)+1)
position='G'
prow=1


if df_inter.columns.values[1].split(' [')[0] == 'Bending Moment':
value=Reference(sheet,min_col=2,min_row=2,max_row=len(df_inter)+1)
series=Series(xvalue,value,title=list(df_inter.columns.values)[1])


chart1.series.append(series)

charts='chart1'
chart[charts].height=15
chart[charts].y_axis.tickLblPos = 'low'
chart[charts].legend.position = 'b'


if ord(position)<89 and prow<=2:
sheet.add_chart(chart[charts], position+str(1))
position=chr(ord(position)+10)
prow=prow+1
wb.save(filename)


for i in range(3,len(df_inter.columns)+1):
if df_inter.columns.values[i-1].split('.')[0] != 'Y':
if df_inter.columns.values[i-1].split(' [')[0] == 'Bending Moment':
value=Reference(sheet,min_col=i,min_row=2,max_row=len(df_inter)+1)
series=Series(xvalue,value,title=list(df_inter.columns.values)[i-1])
chart1.series.append(series)
elif df_inter.columns.values[i-1].split('.')[0] == 'Y':
xvalue=Reference(sheet,min_col=i,min_row=2,max_row=len(df_inter)+1)
wb.save(filename)


combinedsheet='combined_Plate_1'
get_combined_plot(FILENAME,combinedsheet)
Screenshot from VS Code by the author
Screenshot from VS Code by the author

Run the script with the following.

(PLAXIS) C:\Users\phtsang\Desktop\PLAXIS_V22\Script>python plot_plate_combine.py

Now if you open the excel spreadsheet in the location you specified earlier and go to ‘combined_Plate_1’ worksheet. You can see we have extracted the Y coordinate and Bending moment for all three phases. More importantly, we have a plot that contains all results which allow us to compare the bending moment at different phases!

Screenshot from excel by the author

Fantastic! You have successfully extracted results from PLAXIS and used them to create a plot in Excel using Python.

Conclusion

That’s all for the third tutorial on PLAXIS output visualisation using Python. By now, you should be able to extract results at multiple phases and create plots in excel for result comparison. This can be further extended to include multiple structural elements at various stages, which means the whole output extraction process can be automated. I will further talk about this in future tutorials.

If you enjoy reading this type of content, feel free to follow my page. I will keep posting this series of tutorials on automating PLAXIS with Python. Apart from that, I’m also keen to share knowledge on how to use Python to automate workflow in engineering.


PLAXIS Output Visualisation Using Python was originally published in Towards Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.

...



📌 PLAXIS Output Visualisation Using Python


📈 81.86 Punkte

📌 Visualisation 101: Choosing the Best Visualisation Type


📈 51.36 Punkte

📌 Goodbye Boring PLAXIS Output with Python


📈 51.07 Punkte

📌 Start Using Python to Automate PLAXIS


📈 42.36 Punkte

📌 Using Python to Interact With Excel (PLAXIS Input)


📈 42.36 Punkte

📌 Build Soil Profile in PLAXIS Using Python


📈 42.36 Punkte

📌 How to Create Beautiful Waffle Charts for Data Visualisation in Python


📈 32.19 Punkte

📌 Can’t Believe How Easy It Is To Plot Such A Data Visualisation In Python


📈 32.19 Punkte

📌 DEF CON 26 RECON VILLAGE - yamakira - Building Visualisation Platforms for OSINT Data Using OSS


📈 30.79 Punkte

📌 go-ipfs up to 0.7.x Console Output escape output


📈 27.63 Punkte

📌 PHP: The first rule of the output buffering is you do not talk about the output buffering


📈 27.63 Punkte

📌 Krane - Kubernetes RBAC Static Analysis And Visualisation Tool


📈 25.68 Punkte

📌 3D and Motion in Data Visualisation


📈 25.68 Punkte

📌 Svelte & Data Visualisation


📈 25.68 Punkte

📌 From chaos to order: achieving understanding of algorithms through visualisation


📈 25.68 Punkte

📌 8 Tips for Effective Data Visualisation


📈 25.68 Punkte

📌 Constellation - A Graph-Focused Data Visualisation And Interactive Analysis Application


📈 25.68 Punkte

📌 Data Visualisation 101: Playbook for Attention-Grabbing Visuals


📈 25.68 Punkte

📌 PowerBI -Getting started with one of the most powerful Visualisation tool!


📈 25.68 Punkte

📌 An Interactive Visualisation for your Graph Neural Network Explanations


📈 25.68 Punkte

📌 Extracting Ghidra Decompiler Output with Python


📈 20.33 Punkte

📌 ChatGPT AP: Function Calling with Python JSON Output Example


📈 20.33 Punkte

📌 Basic Input/Output in Python


📈 20.33 Punkte

📌 Any books similar to Black Hat Python, or Violent Python that use Python v3?


📈 19.54 Punkte

📌 What Makes Python Python? (aka Everything About Python’s Grammar)


📈 19.54 Punkte

📌 Switching Geany to execute Python files as Python 3, not Python 2


📈 19.54 Punkte

📌 Python for Beginners [1 of 44] Programming with Python | Python for Beginners


📈 19.54 Punkte

📌 Introducing More Python for Beginners | More Python for Beginners [1 of 20] | More Python for Beginners


📈 19.54 Punkte

📌 Pufferüberlauf in python-crcmod, python-cryptography und python-cryptography-vectors (SUSE)


📈 19.54 Punkte











matomo