Running postprocessing on multiple results

Post Reply
raffaele.derisi
Posts: 7
Joined: Sun May 09, 2021 7:51 pm

Running postprocessing on multiple results

Post by raffaele.derisi » Sun May 16, 2021 7:49 pm

Dear STKO Team,

I am currently running the same postprocessing script on multiple output databases generated by STKO for different accelerograms.

The general form of the instructions is:
1. OpneDatabase --> App.runCommand("OpenDatabase", "RECORDERS.mpco")
2. Instructions --> runpy.run_path(path_name='POST_PROCESSING_FILE.py')
3. CloseDatabase -->doc.removeDatabase(db)


I can successfully open the database, run the instructions and close the database once.
However, I am unable to repeat this sequence of instructions more than once. In fact, after the first time, the software crashes. I think this is due to the import of modules multiple times?

Can you please help me with this issue?

Thank you in advance for your help.

Best wishes,

Raffaele

STRUCTURE OF THE CODE: - The Green Line is the line that does not work.

from PyMpc import *
from os import chdir
import runpy
App.clearTerminal()

chdir('ACC_1')
App.runCommand("OpenDatabase", "RECORDERS_PART_1.mpco")
doc = App.postDocument()
doc.clearPlotGroups()
doc.clearCharts()
doc.clearChartData()
doc.commitChanges()
doc.dirty = True
doc.select(None)
runpy.run_path(path_name='POST_PROCESSING_FINAL_PART_1.py')
db = doc.getDatabase(1)
doc.removeDatabase(db)
App.setBusy(False)

App.clearTerminal()
App.runCommand("OpenDatabase", "RECORDERS_PART_2.mpco")
doc = App.postDocument()
doc.clearPlotGroups()
doc.clearCharts()
doc.clearChartData()
doc.commitChanges()
doc.dirty = True
doc.select(None)
runpy.run_path(path_name='POST_PROCESSING_FINAL_PART_2.py')
db = doc.getDatabase(1)
doc.removeDatabase(db)
App.setBusy(False)

chdir("..")

STKO Team
Posts: 3066
Joined: Tue Oct 29, 2019 8:45 am

Re: Running postprocessing on multiple results

Post by STKO Team » Tue May 18, 2021 10:30 am

Hi Raffaele,
I've never used runpy, but I've seen that there could be many side effects.
Are you really sure you need it?
Probably you can just import the module and use functions there...

For example, if "POST_PROCESSING_FINAL_PART_1.py" contains functions that take the document or the databse as argument and work with it, you can simply put that script into one of the folder you loaded into your ScriptExplored,
and import your module with

import POST_PROCESSING_FINAL_PART_1 as instructions

then you can replace your green line with something else
#runpy.run_path(path_name='POST_PROCESSING_FINAL_PART_2.py')
instruction.compute(doc)

BuuNguyen
Posts: 134
Joined: Fri Oct 29, 2021 3:28 am
Location: Paraguay
Contact:

Re: Running postprocessing on multiple results

Post by BuuNguyen » Thu Jan 06, 2022 10:13 am

Hello,

Where can I find the syntax list of this code?
For example, for numpy, mathplotlib libraries in Python, there are some website to explain the syntaxes.

Thank you,
Buu

STKO Team
Posts: 3066
Joined: Tue Oct 29, 2019 8:45 am

Re: Running postprocessing on multiple results

Post by STKO Team » Thu Jan 13, 2022 6:32 pm

each of them has it's own documentation, just google it...

Post Reply