Using openquake as a python library

531 views
Skip to first unread message

Hyeuk Ryu

unread,
Feb 27, 2018, 9:15:06 PM2/27/18
to OpenQuake Users
Hi,

I managed to read an user-defined ground motion field with openquake.commonlib.readinput.get_gmfs, but was not able to figure out how to get an intensity at asset site. Would you be able to provide me any guidance on this? For the reference, I'm currently running v2.5.0.
Thanks.

Regards,

Hyeuk

Michele Simionato

unread,
Feb 27, 2018, 11:26:21 PM2/27/18
to OpenQuake Users


On Wednesday, February 28, 2018 at 3:15:06 AM UTC+1, Hyeuk Ryu wrote:
Hi,

I managed to read an user-defined ground motion field with openquake.commonlib.readinput.get_gmfs, but was not able to figure out how to get an intensity at asset site. Would you be able to provide me any guidance on this? For the reference, I'm currently running v2.5.0.

If you want to use OpenQuake as a library, the first thing to do is to forget about the packages, use master from GitHub and stay updated everyday. For instance
the internal format of the exposure changed even yesterday.
Then you have to invest a significant amount of time studying the code. Fortunately you are only interested in the scenario calculators which are the simplest calculators,
but still they are risk calculators which are substantially more complex than hazard calculators. Also the code changes literally every day. For instance the example
that was valid four months ago https://github.com/gem/oq-engine/pull/3127 is already broken in current master, even if it should still work in engine 2.9.
There are no easy recipes for the moment. Hopefully the code will mature in the future but we are not there yet.

     Michele

Anirudh Rao

unread,
Feb 28, 2018, 1:44:43 AM2/28/18
to openqua...@googlegroups.com
Hi Hyeuk,

If your goal is to be able to estimate both damage and losses for a scenario earthquake in a single calculation, another option could be to simply use the scenario_damage calculator and provide a consequence model (damage-to-loss model) file along with the fragility model file. The outputs will then include both damage and loss estimates for the scenario.

Anirudh



Best regards,
ANIRUDH RAO    seismic risk engineer    LinkedIn: Anirudh Rao    +39-0382-5169-936
GLOBAL EARTHQUAKE MODEL    working together to assess risk
GEM — globalquakemodel.org     @GEMwrld     GEMwrld

--
You received this message because you are subscribed to the Google Groups "OpenQuake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openquake-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hyeuk Ryu

unread,
Feb 28, 2018, 3:27:07 AM2/28/18
to OpenQuake Users
Hi Michele,

Thanks for the reply. I did not expect there is a pre-defined function for this purpose, but would you be still able to point me where to look up especially spatial interpolation? Also would you recommend some python books which could help me to better understand the OpenQuake? For your information, I've written a couple of python packages for my research, but there are some parts in the Openquake that I don't quite understand well (e.g, @decorator).
Thank you so much.

Regards,

Hyeuk


Michele Simionato

unread,
Feb 28, 2018, 5:25:20 AM2/28/18
to OpenQuake Users
A recent Python book that I recommend is "Fluent Python". You can by it from O'Reilly, but a rapid Google search gave me also the link to a PDF version of it: http://1.droppdf.com/files/X06AR/fluent-python-2015-.pdf
The decorator module is documented here: http://decorator.readthedocs.io/en/master/
I have updated the example of how to implement a scenario_risk calculator using the engine as a library here: https://github.com/gem/oq-engine/pull/3484
Happy hacking!

    Michele
To unsubscribe from this group and stop receiving emails from it, send an email to openquake-use...@googlegroups.com.

Michele Simionato

unread,
Feb 28, 2018, 5:27:45 AM2/28/18
to OpenQuake Users


On Wednesday, February 28, 2018 at 9:27:07 AM UTC+1, Hyeuk Ryu wrote:
Hi Michele,

Thanks for the reply. I did not expect there is a pre-defined function for this purpose, but would you be still able to point me where to look up especially spatial interpolation? 

I don't know what you mean by that. Care to expand? 

Hyeuk Ryu

unread,
Feb 28, 2018, 5:45:08 PM2/28/18
to OpenQuake Users
Hi Michele,

I mean some sort of interpolation needs to be done to get intensity at asset location if ground motion field is externally generated and the coordinates do not match with asset location. I'd like to know how the OpenQuake processed the user defined ground motion field and get the intensity at asset location, and in which code. 
Thanks.

Regards,

Hyeuk

Michele Simionato

unread,
Mar 1, 2018, 1:05:19 AM3/1/18
to OpenQuake Users
I was working on this just yesterday, see https://github.com/gem/oq-engine/pull/3484/files.
The relevant loop (a bit simplified) is the following:

             for assets in assets_by_site:
                 lon, lat = assets[0].location
                 site, distance = siteobjects.get_closest(lon, lat)
                 if distance <= asset_hazard_distance:
                     # keep the assets, otherwise discard them
                     assets_by_sid += {site.sid: list(assets)}

Assets on the same risk site are collected together; then one gets the closest hazard site to the risk site (within
and asset_hazard_distance which by default is of 5 km) and associates the assets to that hazard site; this is repeated
for all risk sites until the association is complete. Just to be clear on the terminology:

risk site = lon, lat of the asset as in the exposure XML file
hazard site = lon, lat where you have the external GMF defined

Hyeuk Ryu

unread,
Mar 9, 2018, 7:54:28 PM3/9/18
to OpenQuake Users
Hi Michele,

One more question. You said that I need to get the latest source from the github. Can you explain how to use it as a python library without installing the OpenQuake as I don't have admin right at the cluster. Can it be done by simply appending the path? 
Thanks.

Regards,

Hyeuk

Michele Simionato

unread,
Mar 9, 2018, 10:49:18 PM3/9/18
to OpenQuake Users
You must use a virtual environment. See the instructions here:
https://github.com/gem/oq-engine/blob/master/doc/installing/development.md

vpo...@inogs.it

unread,
Mar 19, 2019, 4:41:45 AM3/19/19
to OpenQuake Users
Hi Michele,

I'm resuming this post because, as you probably can remember, I was always interested in the possibility of running OQ as a Python library.
I've seen your examples in #3484, but I'm wondering if there is a more comprehensive documentation on this functionality of perhaps some demo to begin with.

Thank you,
Vale

michele....@globalquakemodel.org

unread,
Mar 19, 2019, 4:56:05 AM3/19/19
to OpenQuake Users


On Saturday, March 10, 2018 at 1:54:28 AM UTC+1, Hyeuk Ryu wrote:
Hi Michele,

One more question. You said that I need to get the latest source from the github. Can you explain how to use it as a python library without installing the OpenQuake as I don't have admin right at the cluster. Can it be done by simply appending the path? 

There is more documentation about how to run large calculations but nothing new about how to implement your own calculator (which is essentially what you want). 
Writing such documentation (and keeping it updated) would be a significant effort, so I do not think that it will happen soon, unless somebody provides funding for that.
Your best option right now is to study the source code.

      Michele
Reply all
Reply to author
Forward
0 new messages