GithubHelp home page GithubHelp logo

gns-science / opensha-py Goto Github PK

View Code? Open in Web Editor NEW
0.0 18.0 0.0 20 KB

python wrapper for opensha using py4j

License: Apache License 2.0

Python 11.91% Java 88.09%
python java template-project py4j nshm-nz

opensha-py's Introduction

README.md

opensha-py

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)

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 - 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 

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 

opensha-py's People

Contributors

chrisbc avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.