def test_calculation_addition_args(self):
        avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0]
        gmm = GenericGmpeAvgSA(gmpe_name="KothaEtAl2019SERA",
                               avg_periods=avg_periods,
                               corr_func="akkar",
                               sigma_mu_epsilon=1.0)

        rctx = RuptureContext()
        rctx.mag = 6.
        rctx.hypo_depth = 15.
        dctx = DistancesContext()
        dctx.rjb = np.array([1., 10., 30., 70.])

        sctx = SitesContext()
        sctx.vs30 = 500.0 * np.ones(4)
        sctx.vs30measured = np.ones(4, dtype="bool")
        stdt = [const.StdDev.TOTAL]
        expected_mean = np.array(
            [-1.45586338, -1.94419233, -2.91884965, -3.91919928])
        expected_stddev = np.array(
            [0.58317566, 0.58317566, 0.58317566, 0.58317566])
        imtype = imt.AvgSA()
        mean, [stddev] = gmm.get_mean_and_stddevs(sctx, rctx, dctx, imtype,
                                                  stdt)
        np.testing.assert_almost_equal(mean, expected_mean)
        np.testing.assert_almost_equal(stddev, expected_stddev)
    def test_calculation_addition_args(self):
        avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0]
        gmm = GenericGmpeAvgSA(gmpe_name="KothaEtAl2020ESHM20",
                               avg_periods=avg_periods,
                               corr_func="akkar",
                               sigma_mu_epsilon=1.0)

        rctx = RuptureContext()
        rctx.mag = 6.
        rctx.hypo_depth = 15.
        dctx = DistancesContext()
        dctx.rjb = np.array([1., 10., 30., 70.])

        sctx = SitesContext()
        sctx.vs30 = 500.0 * np.ones(4)
        sctx.vs30measured = np.ones(4, dtype="bool")
        sctx.region = np.zeros(4, dtype=int)
        stdt = [const.StdDev.TOTAL]
        expected_mean = np.array(
            [-1.72305707, -2.2178751, -3.20100306, -4.19948242])
        expected_stddev = np.array(
            [0.5532021, 0.5532021, 0.5532021, 0.5532021])
        imtype = imt.AvgSA()
        mean, [stddev] = gmm.get_mean_and_stddevs(sctx, rctx, dctx, imtype,
                                                  stdt)
        np.testing.assert_almost_equal(mean, expected_mean)
        np.testing.assert_almost_equal(stddev, expected_stddev)
Exemple #3
0
    def test_gm_calculation_hard_rock(self):
        """ Test mean and std calculation - on hard rock using AB06"""
        # Modified gmpe
        mgmpe = NRCan15SiteTermLinear(gmpe_name='AtkinsonBoore2006')
        # Set parameters
        sites = Dummy.get_site_collection(2, vs30=[760, 2010])
        rup = Dummy.get_rupture(mag=7.0)
        dists = DistancesContext()
        dists.rrup = np.array([15., 15.])
        stdt = [const.StdDev.TOTAL]
        gmpe = AtkinsonBoore2006()

        for imt in [PGA(), SA(1.0), SA(5.0)]:
            #
            # Computes results
            mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt,
                                                    stdt)
            # Compute the expected results
            mean_expected, stds_expected = gmpe.get_mean_and_stddevs(
                sites, rup, dists, imt, stdt)
            # Test that for reference soil conditions the modified GMPE gives
            # the same results of the original gmpe
            np.testing.assert_allclose(np.exp(mean),
                                       np.exp(mean_expected),
                                       rtol=1.0e-1)
            np.testing.assert_allclose(stds, stds_expected)
    def test_gm_calculation_soil_reference(self):
        """ Test mean and std calculation - CY14 on reference rock"""

        # Modified gmpe
        mgmpe = CY14SiteTerm(gmpe_name='ChiouYoungs2014')

        # Set parameters
        sites = Dummy.get_site_collection(4,
                                          vs30=1130.,
                                          vs30measured=True,
                                          z1pt0=0.)
        rup = Dummy.get_rupture(mag=6.0)
        rup.dip = 90.
        rup.ztor = 0.
        dists = DistancesContext()
        dists.rrup = np.array([1., 10., 30., 70.])
        dists.rx = np.array([1., 10., 30., 70.])
        dists.rjb = np.array([1., 10., 30., 70.])
        imt = PGA()
        stdt = [const.StdDev.TOTAL]

        # Compute results
        mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt)

        # Compute the expected results
        gmpe = ChiouYoungs2014()
        mean_expected, stds_expected = gmpe.get_mean_and_stddevs(
            sites, rup, dists, imt, stdt)
        # Test that for reference soil conditions the modified GMPE gives the
        # same results of the original gmpe
        np.testing.assert_almost_equal(mean, mean_expected)
        np.testing.assert_almost_equal(stds, stds_expected)
    def test_gm_calculation_hard_rock(self):
        """ Test mean and std calculation - on hard rock using AB06"""
        # Modified gmpe
        mgmpe = NRCan15SiteTermLinear(gmpe_name='AtkinsonBoore2006')
        # Set parameters
        sites = Dummy.get_site_collection(2, vs30=[760, 2010])
        rup = Dummy.get_rupture(mag=7.0)
        dists = DistancesContext()
        dists.rrup = np.array([15., 15.])
        stdt = [const.StdDev.TOTAL]
        gmpe = AtkinsonBoore2006()

        for imt in [PGA(), SA(1.0), SA(5.0)]:
            #
            # Computes results
            mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt,
                                                    stdt)
            # Compute the expected results
            mean_expected, stds_expected = gmpe.get_mean_and_stddevs(sites,
                                                    rup, dists, imt, stdt)
            # Test that for reference soil conditions the modified GMPE gives
            # the same results of the original gmpe
            np.testing.assert_allclose(np.exp(mean), np.exp(mean_expected),
                                 rtol=1.0e-1)
            np.testing.assert_allclose(stds, stds_expected)
Exemple #6
0
 def test01(self):
     filename = os.path.join(DATA_PATH, 'kappa.txt')
     gmm = AlAtikSigmaModel(gmpe_name='BindiEtAl2014Rjb',
                            kappa_file=filename,
                            kappa_val='high')
     sites = Dummy.get_site_collection(4, vs30=760.)
     rup = Dummy.get_rupture(mag=6.0)
     dists = DistancesContext()
     dists.rjb = np.array([1., 10., 30., 70.])
     imt = SA(0.1)
     stdt = [const.StdDev.TOTAL]
     mean_expected, stds_expected = gmm.get_mean_and_stddevs(
         sites, rup, dists, imt, stdt)
Exemple #7
0
 def setUp(self):
     # Set parameters
     self.sites = Dummy.get_site_collection(4, vs30=760.)
     self.rup = Dummy.get_rupture(mag=6.0)
     self.dists = DistancesContext()
     self.dists.rrup = np.array([1., 10., 30., 70.])
     self.dists.rjb = np.array([1., 10., 30., 70.])
     self.imt = PGA()
Exemple #8
0
 def setUp(self):
     # Set parameters
     self.sites = Dummy.get_site_collection(
         4, amplfactor=[-1.0, 1.5, 0.00, -1.99])
     self.rup = Dummy.get_rupture(mag=6.0, hypo_depth=10)
     self.dists = DistancesContext()
     self.dists.rhypo = np.array([1., 10., 30., 70.])
     self.dists.repi = np.array([1., 10., 30., 70.])
     self.imt = MMI()
    def test02(self):
        avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0]
        gmm = gsim.mgmpe.generic_gmpe_avgsa.GenericGmpeAvgSA(
            gmpe_name='AkkarEtAlRepi2014',
            avg_periods=avg_periods,
            corr_func='akkar')
        msg = 'The class name is incorrect'
        self.assertTrue(gmm.__class__.__name__ == 'GenericGmpeAvgSA', msg=msg)

        sites = Dummy.get_site_collection(4, vs30=760.)
        rup = Dummy.get_rupture(mag=6.0)
        dists = DistancesContext()
        dists.repi = np.array([1., 10., 30., 70.])
        imtype = PGA()
        stdt = [const.StdDev.TOTAL]
        # Computes results
        mean, _ = gmm.get_mean_and_stddevs(sites, rup, dists, imtype, stdt)
        expected = np.array([-2.0383581, -2.6548699, -3.767237, -4.7775653])
        np.testing.assert_almost_equal(mean, expected)
Exemple #10
0
    def test02(self):
        # checks if gmpe is always being evaluated at vs30=760
        # see HID 2.6.2
        filename = os.path.join(DATA_PATH, 'kappa.txt')
        gmm = AlAtikSigmaModel(gmpe_name='YenierAtkinson2015ACME2019',
                               kappa_file=filename,
                               kappa_val='high')
        sites = Dummy.get_site_collection(4, vs30=760.)
        rup = Dummy.get_rupture(mag=6.0)
        dists = DistancesContext()
        dists.rjb = np.array([1., 10., 30., 70.])
        dists.rrup = np.array([1., 10., 30., 70.])
        imt = SA(0.1)
        stdt = [const.StdDev.TOTAL]
        mean_760, _ = gmm.get_mean_and_stddevs(sites, rup, dists, imt, stdt)

        sites2 = Dummy.get_site_collection(4, vs30=1500.)
        mean_1500, _ = gmm.get_mean_and_stddevs(sites2, rup, dists, imt, stdt)

        self.assertAlmostEqual(mean_760[-1], mean_1500[-1], 4)
Exemple #11
0
    def create_distances_context(self):
        '''Creates, initializes and returns a distances context by setting the
        default values of the attributes defined in `self.distances_context_attrs`.
        The returned context is intended to be used in `self.get_contexts`.

        :return:  a :class:`openquake.hazardlib.contexts.DistancesContext`
        '''
        ctx = DistancesContext()
        for _ in self.distances_context_attrs:
            setattr(ctx, _, [])
        return ctx
    def test01(self):
        avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0]
        gmm = gsim.mgmpe.generic_gmpe_avgsa.GenericGmpeAvgSA(
            gmpe_name='ZhaoEtAl2006Asc',
            avg_periods=avg_periods,
            corr_func='akkar')
        msg = 'The class name is incorrect'
        self.assertTrue(gmm.__class__.__name__ == 'GenericGmpeAvgSA', msg=msg)

        sites = Dummy.get_site_collection(4, vs30=760.)
        rup = Dummy.get_rupture(mag=6.0)
        rup.hypo_depth = 10.
        dists = DistancesContext()
        dists.rrup = np.array([1., 10., 30., 70.])
        imtype = PGA()
        stdt = [const.StdDev.TOTAL]
        # Computes results
        mean, _ = gmm.get_mean_and_stddevs(sites, rup, dists, imtype, stdt)
        expected = np.array(
            [-1.33735637, -2.62649473, -3.64500654, -4.60067093])
        np.testing.assert_almost_equal(mean, expected)
 def test_gm_calculationAB06_hard_bedrock(self):
     """ Test mean and std calculation - AB06 on vs30 hard bedrock"""
     # Modified gmpe
     mgmpe = NRCan15SiteTerm(gmpe_name='AtkinsonBoore2006')
     # Set parameters
     sites = Dummy.get_site_collection(4, vs30=1999.0)
     rup = Dummy.get_rupture(mag=6.0)
     dists = DistancesContext()
     dists.rrup = np.array([10., 20., 30., 40.])
     imt = PGA()
     stdt = [const.StdDev.TOTAL]
     # Computes results
     mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt)
     # Compute the expected results
     gmpe = AtkinsonBoore2006()
     mean_expected, stds_expected = gmpe.get_mean_and_stddevs(
         sites, rup, dists, imt, stdt)
     # Test that for reference soil conditions the modified GMPE gives the
     # same results of the original gmpe
     np.testing.assert_almost_equal(mean, mean_expected)
     np.testing.assert_almost_equal(stds, stds_expected)
 def _get_stds(self, within_absolute=None, between_absolute=None):
     if within_absolute is not None:
         gmm = SplitSigmaGMPE(gmpe_name='Campbell2003',
                              within_absolute=within_absolute)
     elif between_absolute is not None:
         gmm = SplitSigmaGMPE(gmpe_name='Campbell2003',
                              between_absolute=between_absolute)
     else:
         raise ValueError('Unknown option')
     # Set parameters
     sites = Dummy.get_site_collection(4, vs30=760.)
     rup = Dummy.get_rupture(mag=6.0)
     dists = DistancesContext()
     dists.rrup = np.array([1., 10., 30., 70.])
     imt = PGA()
     stds_types = [const.StdDev.TOTAL, const.StdDev.INTER_EVENT,
                   const.StdDev.INTRA_EVENT]
     # Compute results
     mean, stds = gmm.get_mean_and_stddevs(sites, rup, dists, imt,
                                           stds_types)
     return stds, stds_types
 def test_gm_calculationBA08_vs30variable(self):
     """ Test mean and std calculation - BA08 - Vs30 variable"""
     # Modified gmpe
     mgmpe = NRCan15SiteTerm(gmpe_name='BooreAtkinson2008')
     # Set parameters
     sites = Dummy.get_site_collection(3, vs30=[400., 600, 1000])
     rup = Dummy.get_rupture(mag=6.0)
     dists = DistancesContext()
     dists.rjb = np.array([10., 10., 10.])
     imt = PGA()
     stdt = [const.StdDev.TOTAL]
     # Computes results
     mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt)
     # Compute the expected results
     gmpe = BooreAtkinson2008()
     mean_expected, stds_expected = gmpe.get_mean_and_stddevs(
         sites, rup, dists, imt, stdt)
     # Test that for reference soil conditions the modified GMPE gives the
     # same results of the original gmpe
     np.testing.assert_almost_equal(mean[:-1], mean_expected[:-1])
     np.testing.assert_almost_equal(stds[:-1], stds_expected[:-1])
    def setUp(self):

        # Set parameters - Setting z1pt0 does not make sense but here we
        # want to make sure that the modified gmm provided GM amplified
        # by the site term exactly as the original model.
        sites = Dummy.get_site_collection(4,
                                          vs30=400.,
                                          vs30measured=True,
                                          z1pt0=0.)
        rup = Dummy.get_rupture(mag=6.0)
        rup.dip = 90.
        rup.ztor = 0.
        dists = DistancesContext()
        dists.rrup = np.array([1., 10., 30., 70.])
        dists.rx = np.array([1., 10., 30., 70.])
        dists.rjb = np.array([1., 10., 30., 70.])
        stdt = [const.StdDev.TOTAL]

        self.rup = rup
        self.dists = dists
        self.stdt = stdt
        self.sites = sites
 def test_gm_calculationBA08_vs30variable(self):
     """ Test mean and std calculation - BA08 - Vs30 variable"""
     # Modified gmpe
     mgmpe = NRCan15SiteTerm(gmpe_name='BooreAtkinson2008')
     # Set parameters
     sites = Dummy.get_site_collection(3, vs30=[400., 600, 1000])
     rup = Dummy.get_rupture(mag=6.0)
     dists = DistancesContext()
     dists.rjb = np.array([10., 10., 10.])
     imt = PGA()
     stdt = [const.StdDev.TOTAL]
     # Computes results
     mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt)
     # Compute the expected results
     gmpe = BooreAtkinson2008()
     mean_expected, stds_expected = gmpe.get_mean_and_stddevs(sites, rup,
                                                              dists, imt,
                                                              stdt)
     # Test that for reference soil conditions the modified GMPE gives the
     # same results of the original gmpe
     np.testing.assert_almost_equal(mean[:-1], mean_expected[:-1])
     np.testing.assert_almost_equal(stds[:-1], stds_expected[:-1])
 def test_gm_calculationAB06_hard_bedrock(self):
     """ Test mean and std calculation - AB06 on vs30 hard bedrock"""
     # Modified gmpe
     mgmpe = NRCan15SiteTerm(gmpe_name='AtkinsonBoore2006')
     # Set parameters
     sites = Dummy.get_site_collection(4, vs30=1999.0)
     rup = Dummy.get_rupture(mag=6.0)
     dists = DistancesContext()
     dists.rrup = np.array([10., 20., 30., 40.])
     imt = PGA()
     stdt = [const.StdDev.TOTAL]
     # Computes results
     mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt)
     # Compute the expected results
     gmpe = AtkinsonBoore2006()
     mean_expected, stds_expected = gmpe.get_mean_and_stddevs(sites, rup,
                                                              dists, imt,
                                                              stdt)
     # Test that for reference soil conditions the modified GMPE gives the
     # same results of the original gmpe
     np.testing.assert_almost_equal(mean, mean_expected)
     np.testing.assert_almost_equal(stds, stds_expected)
 def _get_stds(self, within_absolute=None, between_absolute=None):
     if within_absolute is not None:
         gmm = SplitSigmaGMPE(gmpe_name='Campbell2003',
                              within_absolute=within_absolute)
     elif between_absolute is not None:
         gmm = SplitSigmaGMPE(gmpe_name='Campbell2003',
                              between_absolute=between_absolute)
     else:
         raise ValueError('Unknown option')
     # Set parameters
     sites = Dummy.get_site_collection(4, vs30=760.)
     rup = Dummy.get_rupture(mag=6.0)
     dists = DistancesContext()
     dists.rrup = np.array([1., 10., 30., 70.])
     imt = PGA()
     stds_types = [
         const.StdDev.TOTAL, const.StdDev.INTER_EVENT,
         const.StdDev.INTRA_EVENT
     ]
     # Compute results
     mean, stds = gmm.get_mean_and_stddevs(sites, rup, dists, imt,
                                           stds_types)
     return stds, stds_types
Exemple #20
0
    def extrapolate_in_PSA(self, sites, rup, dists, imt_high, set_imt,
                           stds_types, imt):

        extrap_mean = []
        t_log10 = np.log10([im for im in set_imt])
        for d in np.arange(0, len(dists.rjb)):
            dist = DistancesContext()
            if hasattr(dists, 'rjb'):
                dist.rjb = np.array([dists.rjb[d]])
            if hasattr(dists, 'rrup'):
                dist.rrup = np.array([dists.rrup[d]])
            means_log10 = []
            for im in set_imt:
                mean_ln, _ = self.gmpe.get_mean_and_stddevs(
                    sites, rup, dist, SA(im), stds_types)
                mean = np.exp(mean_ln[0])
                means_log10.append(np.log10(mean))

            mb = np.polyfit(t_log10, means_log10, 1)
            mean_imt_log10 = mb[0] * np.log10(imt) + mb[1]
            extrap_mean.append(np.log(10**mean_imt_log10))

        return extrap_mean
Exemple #21
0
    def build_sites_distances_contexts(self,
                                       event,
                                       sites,
                                       vs30measured=False,
                                       backarc=False):
        """
        Builds the contexts from the event and sites
        """
        # Get distances
        mesh = Mesh(sites["lon"], sites["lat"])
        mshape = mesh.lons.shape
        dctx = DistancesContext()
        for param in self.context.REQUIRES_DISTANCES:
            setattr(dctx, param, get_distances(event.get_rupture(), mesh,
                                               param))
        # Get sites context
        sctx = SitesContext()
        for key in self.site_attribs:
            if key.startswith("z1pt0") and not "z1pt0" in sites:
                setattr(sctx, "z1pt0",
                        vs30_to_z1pt0_cy14(sites["vs30"], japan=False))

            elif key.startswith("z2pt5") and not "z5pt5" in sites:
                setattr(sctx, "z2pt5",
                        vs30_to_z2pt5_cb14(sites["vs30"], japan=False))

            elif key.startswith(
                    "vs30measured") and not "vs30measured" in sites:
                if vs30measured:
                    setattr(sctx, "vs30measured", np.ones(mshape, dtype=bool))
                else:
                    setattr(sctx, "vs30measured", np.zeros(mshape, dtype=bool))
            elif key.startswith(
                    "vs30measured") and not "vs30measured" in sites:
                if vs30measured:
                    setattr(sctx, "vs30measured", np.ones(mshape, dtype=bool))
                else:
                    setattr(sctx, "vs30measured", np.zeros(mshape, dtype=bool))
            elif key.startswith("backarc") and not "backarc" in sites:
                if vs30measured:
                    setattr(sctx, "backarc", np.ones(mshape, dtype=bool))
                else:
                    setattr(sctx, "backarc", np.zeros(mshape, dtype=bool))
            else:
                setattr(sctx, key, sites[key])
        return sctx, dctx
Exemple #22
0
def _parse_csv_line(headers, values):
    """
    Parse a single line from data file.

    :param headers:
        A list of header names, the strings from the first line of csv file.
    :param values:
        A list of values of a single row to parse.
    :returns:
        A tuple of the following values (in specified order):

        sctx
            An instance of :class:`openquake.hazardlib.gsim.base.SitesContext`
            with attributes populated by the information from in row in a form
            of single-element numpy arrays.
        rctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.RuptureContext`.
        dctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.DistancesContext`.
        stddev_types
            An empty list, if the ``result_type`` column says "MEAN"
            for that row, otherwise it is a list with one item --
            a requested standard deviation type.
        expected_results
            A dictionary mapping IMT-objects to one-element arrays of expected
            result values. Those results represent either standard deviation
            or mean value of corresponding IMT depending on ``result_type``.
        result_type
            A string literal, one of ``'STDDEV'`` or ``'MEAN'``. Value
            is taken from column ``result_type``.
    """
    rctx = RuptureContext()
    sctx = SitesContext()
    dctx = DistancesContext()
    expected_results = {}
    stddev_types = result_type = damping = None

    for param, value in zip(headers, values):
        if param == 'result_type':
            value = value.upper()
            if value.endswith('_STDDEV'):
                # the row defines expected stddev results
                result_type = 'STDDEV'
                stddev_types = [getattr(const.StdDev, value[:-len('_STDDEV')])]
            else:
                # the row defines expected exponents of mean values
                assert value == 'MEAN'
                stddev_types = []
                result_type = 'MEAN'
        elif param == 'damping':
            damping = float(value)
        elif param.startswith('site_'):
            # value is sites context object attribute
            if (param == 'site_vs30measured') or (param == 'site_backarc'):
                value = float(value) != 0
            else:
                value = float(value)
            setattr(sctx, param[len('site_'):], numpy.array([value]))
        elif param.startswith('dist_'):
            # value is a distance measure
            value = float(value)
            setattr(dctx, param[len('dist_'):], numpy.array([value]))
        elif param.startswith('rup_'):
            # value is a rupture context attribute
            value = float(value)
            setattr(rctx, param[len('rup_'):], value)
        elif param == 'component_type':
            pass
        else:
            # value is the expected result (of result_type type)
            value = float(value)
            if param == 'pga':
                imt = PGA()
            elif param == 'pgv':
                imt = PGV()
            elif param == 'pgd':
                imt = PGD()
            elif param == 'cav':
                imt = CAV()
            elif param == 'mmi':
                imt = MMI()
            elif param == "arias":
                imt = IA()
            elif param == "rsd595":
                imt = RSD595()
            elif param == "rsd575":
                imt = RSD575()
            elif param == "rsd2080":
                imt = RSD2080()
            else:
                period = float(param)
                assert damping is not None
                imt = SA(period, damping)

            expected_results[imt] = numpy.array([value])

    assert result_type is not None
    return sctx, rctx, dctx, stddev_types, expected_results, result_type
Exemple #23
0
def _parse_csv_line(headers, values, req_site_params):
    """
    Parse a single line from data file.

    :param headers:
        A list of header names, the strings from the first line of csv file.
    :param values:
        A list of values of a single row to parse.
    :returns:
        A tuple of the following values (in specified order):

        sctx
            An instance of :class:`openquake.hazardlib.gsim.base.SitesContext`
            with attributes populated by the information from in row in a form
            of single-element numpy arrays.
        rctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.RuptureContext`.
        dctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.DistancesContext`.
        stddev_types
            An empty list, if the ``result_type`` column says "MEAN"
            for that row, otherwise it is a list with one item --
            a requested standard deviation type.
        expected_results
            A dictionary mapping IMT-objects to one-element arrays of expected
            result values. Those results represent either standard deviation
            or mean value of corresponding IMT depending on ``result_type``.
        result_type
            A string literal, one of ``'STDDEV'`` or ``'MEAN'``. Value
            is taken from column ``result_type``.
    """
    rctx = RuptureContext()
    sctx = SitesContext(slots=req_site_params)
    dctx = DistancesContext()
    expected_results = {}
    stddev_types = result_type = damping = None

    for param, value in zip(headers, values):

        if param == 'result_type':
            value = value.upper()
            if value.endswith('_STDDEV'):
                # the row defines expected stddev results
                result_type = 'STDDEV'
                stddev_types = [getattr(const.StdDev, value[:-len('_STDDEV')])]
            else:
                # the row defines expected exponents of mean values
                assert value == 'MEAN'
                stddev_types = []
                result_type = 'MEAN'
        elif param == 'damping':
            damping = float(value)
        elif param.startswith('site_'):
            # value is sites context object attribute
            if param == 'site_vs30measured' or param == 'site_backarc':
                value = float(value) != 0
            elif param in ('site_siteclass', 'site_ec8', 'site_ec8_p18',
                           'site_geology'):
                value = numpy.string_(value)
            else:
                value = float(value)
            # site_lons, site_lats, site_depths -> lon, lat, depth
            if param.endswith(('lons', 'lats', 'depths')):
                attr = param[len('site_'):-1]
            else:  # vs30s etc
                attr = param[len('site_'):]
            setattr(sctx, attr, numpy.array([value]))
        elif param.startswith('dist_'):
            # value is a distance measure
            value = float(value)
            setattr(dctx, param[len('dist_'):], numpy.array([value]))
        elif param.startswith('rup_'):
            # value is a rupture context attribute
            try:
                value = float(value)
            except ValueError:
                if value != 'undefined':
                    raise

            setattr(rctx, param[len('rup_'):], value)
        elif param == 'component_type':
            pass
        else:
            # value is the expected result (of result_type type)
            value = float(value)

            if param == 'arias':  # ugly legacy corner case
                param = 'ia'
            if param == 'avgsa':
                imt = from_string('AvgSA')
            else:
                try:  # The title of the column should be IMT(args)
                    imt = from_string(param.upper())
                except KeyError:  # Then it is just a period for SA
                    imt = registry['SA'](float(param), damping)

            expected_results[imt] = numpy.array([value])

    assert result_type is not None
    return sctx, rctx, dctx, stddev_types, expected_results, result_type