Make sure that context objects are not changed by calling 'get_mean_and_stddevs'

Bug #1291016 reported by Damiano Monelli
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenQuake Hazard Library
Fix Released
High
Damiano Monelli

Bug Description

We need to make sure that context objects (https://github.com/gem/oq-hazardlib/blob/master/openquake/hazardlib/gsim/base.py#L548) are never changed by calling the method get_mean_and_stddevs (https://github.com/gem/oq-hazardlib/blob/master/openquake/hazardlib/gsim/base.py#L118) because this can change the state of the object without the user being aware of it.

For instance the AtkinsonBoore2003SInterNSHMP2008 GMPE is considered, the following happens:

In [1]: from openquake.hazardlib.gsim.atkinson_boore_2003 import AtkinsonBoore2003SInterNSHMP2008
In [2]: from openquake.hazardlib.gsim.base import RuptureContext, SitesContext, DistancesContext
In [3]: from openquake.hazardlib.imt import PGA
In [4]: from openquake.hazardlib.const import StdDev

In [6]: sites = SitesContext()
In [7]: sites.vs30 = array([760.])

In [8]: rup = RuptureContext()
In [9]: rup.mag = 6
In [10]: rup.hypo_depth = 50

In [11]: dists = DistancesContext()
In [12]: dists.rrup = array([40.])

In [13]: gmpe = AtkinsonBoore2003SInterNSHMP2008()

In [14]: gmpe.get_mean_and_stddevs(sites, rup, dists, PGA(), [StdDev.TOTAL])
Out[14]: (array([-3.80923033]), [array([ 0.52959457])])

In [15]: rup.hypo_depth
Out[15]: 20.0

As it can be seen, `rup.hypo_depth` is initially set to 50 but after calling `gmpe.get_mean_and_stddevs` the value is set to 20. This because the GMPE internally changes its value (https://github.com/gem/oq-hazardlib/blob/master/openquake/hazardlib/gsim/atkinson_boore_2003.py#L346)

Changed in oq-hazardlib:
assignee: nobody → Damiano Monelli (monelli)
importance: Undecided → High
status: New → In Progress
Revision history for this message
Michele Simionato (michele-simionato) wrote :
Changed in oq-hazardlib:
status: In Progress → Fix Committed
Changed in oq-hazardlib:
milestone: none → 0.12
Changed in oq-hazardlib:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.