Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

python wrapper for opensha using py4j

License

NotificationsYou must be signed in to change notification settings

GNS-Science/opensha-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

README.md

A python bridge for opensha based onpy4j.org

Taking the example fromhttps://github.com/opensha/opensha-core/blob/master/src/org/opensha/sha/examples/HazardCurveCalcExample.javaand wrapping it with a py4j gateway.

Now, we can do this in python...

#!pythonfrompy4j.java_gatewayimportJavaGatewaygateway=JavaGateway()hazard_calc_app=gateway.entry_pointprint('HazardCurve calculation with default timespan = 30 years')hazard_calc_app.execute(34.2,-118.344)print('HazardCurve calculation with timespan = 50 years')hazard_calc_app.setTimeSpan(50)hazard_calc_app.execute(34.2,-118.344)

1.0 Python setup

prerequisites:

  • python3
  • py4j

2.0 Java compile

Note the opensha-py project is cloned into a folder containing the main opensha repos - seehttps://github.com/opensha/opensha-commons/blob/master/README.md)

The class path includes:

  • the 'fat' opensha Jar file
  • the py4j Jar
  • opensha-py/src/java
export OPENSHA_PY_CLASSPATH=opensha-core/build/libs/opensha-core-all.jar:opensha-py/share/py4j/py4j0.10.9.jar:opensha-py/src/java:.javac -cp$OPENSHA_PY_CLASSPATH opensha-py/src/java/org/opensha/py/HazardCurveCalcGateway.java

3.0 Run the Java gateway server (background)...

java -cp$OPENSHA_PY_CLASSPATH org.opensha.py.HazardCurveCalcGateway

4.0 Call HazardCurveCalc from python client

python opensha-py/src/test_gateway.py

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp