README.md
A python bridge for opensha based on py4j.org
Taking the example from https://github.com/opensha/opensha-core/blob/master/src/org/opensha/sha/examples/HazardCurveCalcExample.java and wrapping it with a py4j gateway.
Now, we can do this in python...
#!python
from py4j.java_gateway import JavaGateway
gateway = JavaGateway()
hazard_calc_app = gateway.entry_point
print('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)
prerequisites:
- python3
- py4j
Note the opensha-py project is cloned into a folder containing the main opensha repos - see https://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
java -cp $OPENSHA_PY_CLASSPATH org.opensha.py.HazardCurveCalcGateway
python opensha-py/src/test_gateway.py