Coder Social home page Coder Social logo

Comments (4)

micheles avatar micheles commented on July 18, 2024

Using a GSIM is non-obvious. First of all, it should not be instantiated directly, but through the valid.gsim function. Secondly, contexts objects should be instantiated by using a ContextMaker instance, which has to be instantiated carefully. Thirdly, the .compute method should not be called directly. In short, here is how to do what you want:

import numpy as np
from openquake.hazardlib import valid
from openquake.hazardlib.contexts import simple_cmaker

gsim = valid.gsim('''[NGAEastGMPE]
gmpe_table="NGAEast_PEER_EX.hdf5"''')
n = 10
mags = np.linspace(5, 7, n)
cmaker = simple_cmaker([gsim], ['PGA'], mags=['%.2f' % mag for mag in mags])
ctx = cmaker.new_ctx(n)
ctx["mag"] = mags
ctx["vs30"] = np.linspace(200, 300, n)
ctx["rrup"] = np.linspace(1, 100, n)

mean, sigma, tau, phi = cmaker.get_mean_stds([ctx])

from oq-engine.

smithUSGS avatar smithUSGS commented on July 18, 2024

Thank you, I adapted your example and it passed the test. Note that I didn't need to instantiate the GMM using valid.gsim (although I can and it is what you recommend). If you don't mind explaining why using valid.gsim is a good practice, I would appreciate that. Either way, I think this issue can be closed now.

from oq-engine.

micheles avatar micheles commented on July 18, 2024

Using valid.gsim is a good practice because it is the official way the engine convert strings into GMPEs, so it is guaranteed to work forever, while manual instantiation changed in the past and could potentially change again in the future.

from oq-engine.

emthompson-usgs avatar emthompson-usgs commented on July 18, 2024

Thanks @micheles, we weren't aware of this. Good to know.

from oq-engine.

Related Issues (20)

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.