Extract hcurves from the datastore and compute their means.

    :returns: curves_by_rlz, mean_curves
431140
def get_hcurves_and_means(dstore):
    
    rlzs_assoc = dstore['csm_info'].get_rlzs_assoc()
    getter = getters.PmapGetter(dstore, rlzs_assoc)
    pmaps = getter.get_pmaps()
    return dict(zip(getter.rlzs, pmaps)), dstore['hcurves/mean']
1191979
def compare_mean_curves(calc_ref, calc, nsigma=3):
    
    dstore_ref = datastore.read(calc_ref)
    dstore = datastore.read(calc)
    imtls = dstore_ref['oqparam'].imtls
    if dstore['oqparam'].imtls != imtls:
        raise RuntimeError('The IMTs and levels are different between '
                           'calculation %d and %d' % (calc_ref, calc))
    sitecol_ref = dstore_ref['sitecol']
    sitecol = dstore['sitecol']
    site_id_ref = {(lon, lat): sid for sid, lon, lat in zip(
        sitecol_ref.sids, sitecol_ref.lons, sitecol_ref.lats)}
    site_id = {(lon, lat): sid for sid, lon, lat in zip(
        sitecol.sids, sitecol.lons, sitecol.lats)}
    common = set(site_id_ref) & set(site_id)
    if not common:
        raise RuntimeError('There are no common sites between calculation '
                           '%d and %d' % (calc_ref, calc))
    pmap_ref = PmapGetter(dstore_ref, sids=[site_id_ref[lonlat]
                                            for lonlat in common]).get_mean()
    pmap = PmapGetter(dstore, sids=[site_id[lonlat]
                                    for lonlat in common]).get_mean()
    for lonlat in common:
        mean, std = pmap[site_id[lonlat]].array.T  # shape (2, N)
        mean_ref, std_ref = pmap_ref[site_id_ref[lonlat]].array.T
        err = numpy.sqrt(std**2 + std_ref**2)
        for imt in imtls:
            sl = imtls(imt)
            ok = (numpy.abs(mean[sl] - mean_ref[sl]) < nsigma * err[sl]).all()
            if not ok:
                md = (numpy.abs(mean[sl] - mean_ref[sl])).max()
                plt.title('point=%s, imt=%s, maxdiff=%.2e' % (lonlat, imt, md))
                plt.loglog(imtls[imt], mean_ref[sl] + std_ref[sl],
                           label=str(calc_ref), color='black')
                plt.loglog(imtls[imt], mean_ref[sl] - std_ref[sl],
                           color='black')
                plt.loglog(imtls[imt], mean[sl] + std[sl], label=str(calc),
                           color='red')
                plt.loglog(imtls[imt], mean[sl] - std[sl], color='red')
                plt.legend()
                plt.show()
845819
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        C = self.COEFFS[imt]
        mean = self._compute_mean(C, rup.mag, dists.rrup)
        if isinstance(imt, SA) or isinstance(imt, PGA):
            # Convert from m/s**2 to g
            mean = mean - np.log(g)
        elif isinstance(imt, PGV):  # Convert from m/s to cm/s
            mean = mean + np.log(100.0)
        stddevs = self._get_stddevs(C, stddev_types, rup.mag,
                                    dists.rrup.shape[0])

        return mean, stddevs
670889
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extracting dictionary of coefficients specific to required
        # intensity measure type.
        C = self.COEFFS[imt]
        # Implements mean model (equation 12)
        mean = (self._compute_magnitude(rup, C) +
                self._compute_distance(dists, C) +
                self._get_site_amplification(sites, rup, C) +
                self._get_mechanism(rup, C))

        stddevs = self._get_stddevs(rup, np.exp(mean), stddev_types, sites)

        return mean, stddevs
375174
def extract_realizations(dstore, dummy):
    
    rlzs = dstore['csm_info'].rlzs
    dt = [('ordinal', U32), ('weight', F32), ('gsims', '<S64')]
    arr = numpy.zeros(len(rlzs), dt)
    arr['ordinal'] = rlzs['ordinal']
    arr['weight'] = rlzs['weight']
    arr['gsims'] = rlzs['branch_path']  # this is used in scenario by QGIS
    return arr
694336
def get_per_pixel_mean(self, names=('train', 'test')):
        
        for name in names:
            assert name in ['train', 'test'], name
        train_files, test_files, _ = get_filenames(self.dir, self.cifar_classnum)
        all_files = []
        if 'train' in names:
            all_files.extend(train_files)
        if 'test' in names:
            all_files.extend(test_files)
        all_imgs = [x[0] for x in read_cifar(all_files, self.cifar_classnum)]
        arr = np.array(all_imgs, dtype='float32')
        mean = np.mean(arr, axis=0)
        return mean
16824
def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types):
        
        # Prepare sites
        sites_rock = copy.deepcopy(sites)
        sites_rock.vs30 = np.ones_like(sites_rock.vs30) * 760.
        # compute mean and standard deviation
        mean, stddvs = self.gmpe.get_mean_and_stddevs(sites_rock, rup, dists,
                                                      imt, stds_types)
        if not str(imt) == 'PGA':
            # compute mean and standard deviation on rock
            mean_rock, stddvs_rock = self.gmpe.get_mean_and_stddevs(
                sites_rock, rup, dists, imt, stds_types)
        else:
            mean_rock = mean
        fa = self.BA08_AB06(sites.vs30, imt, np.exp(mean_rock))
        mean = np.log(np.exp(mean) * fa)
        return mean, stddvs
271528
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        mean, stddevs = super().get_mean_and_stddevs(sites, rup, dists, imt,
                                                     stddev_types)
        delta = self._get_delta(imt, rup.mag)
        return mean-delta, stddevs
170094
def get_perceval_params_from_url(cls, urls):
        
        params = []

        dparam = cls.get_arthur_params_from_url(urls)
        params.append(dparam["url"])

        return params
414232
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        C = self.COEFFS[imt]

        mag = rup.mag - 6
        d = np.sqrt(dists.rjb ** 2 + C['c7'] ** 2)
        mean = np.zeros_like(d)

        mean += C['c1'] + C['c2'] * mag + C['c3'] * mag ** 2 + C['c6']

        idx = d <= 100.
        mean[idx] = mean[idx] + C['c5'] * np.log10(d[idx])

        idx = d > 100.
        mean[idx] = (mean[idx] + C['c5'] * np.log10(100.) -
                     np.log10(d[idx] / 100.) + C['c4'] * (d[idx] - 100.))

        # convert from log10 to ln and from cm/s**2 to g
        mean = np.log((10.0 ** (mean - 2.0)) / g)

        stddevs = self._get_stddevs(C, stddev_types,  dists.rjb.shape[0])

        return mean, stddevs
544395
def get_mean(self, C, rup, sites, dists):
        
        # W2 needs to be a 1 by 5 matrix (not a vector
        w_2 = np.array([
            [C["W_21"], C["W_22"], C["W_23"], C["W_24"], C["W_25"]]
            ])
        # Gets the style of faulting dummy variable
        sof = self._get_sof_dummy_variable(rup.rake)
        # Get the normalised coefficients
        p_n = self.get_pn(rup, sites, dists, sof)
        mean = np.zeros_like(dists.rjb)
        # Need to loop over sites - maybe this can be improved in future?
        # ndenumerate is used to allow for application to 2-D arrays
        for idx, rval in np.ndenumerate(p_n[0]):
            # Place normalised coefficients into a single array
            p_n_i = np.array([rval, p_n[1], p_n[2][idx], p_n[3], p_n[4]])
            # Executes the main ANN model
            mean_i = np.dot(w_2, np.tanh(np.dot(self.W_1, p_n_i) + self.B_1))
            mean[idx] = (0.5 * (mean_i + C["B_2"] + 1.0) *
                         (C["tmax"] - C["tmin"])) + C["tmin"]
        return mean
517671
def queryables(self):
        

        # compute the values_axes queryables
        return dict(
            [(a.cname, a) for a in self.index_axes] +
            [(self.storage_obj_type._AXIS_NAMES[axis], None)
             for axis, values in self.non_index_axes] +
            [(v.cname, v) for v in self.values_axes
             if v.name in set(self.data_columns)]
        )
695855
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        C = self.COEFFS[imt]
        mean = (np.log(self.get_magnitude_term(C, rup) +
                       self.get_distance_term(C, dists.rrup)) +
                self.get_site_amplification(C, sites))
        stddevs = self.get_stddevs(C, sites.vs30.shape, rup.mag, stddev_types)
        return mean, stddevs
714720
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        C = self.COEFFS[imt]
        mean = (self._get_magnitude_scaling(C, rup.mag) +
                self._get_distance_scaling(C, rup.mag, dists.rhypo))
        if imt.name in "SA PGA":
            mean = np.log(np.exp(mean) / (100.0 * g))
        stddevs = self._compute_std(C, stddev_types, len(dists.rhypo))
        return mean, stddevs
173999
def view_global_hcurves(token, dstore):
    
    oq = dstore['oqparam']
    nsites = len(dstore['sitecol'])
    rlzs_assoc = dstore['csm_info'].get_rlzs_assoc()
    mean = getters.PmapGetter(dstore, rlzs_assoc).get_mean()
    array = calc.convert_to_array(mean, nsites, oq.imtls)
    res = numpy.zeros(1, array.dtype)
    for name in array.dtype.names:
        res[name] = array[name].mean()
    return rst_table(res)
496117
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        

        # get mean and std using the superclass
        mean, stddevs = super().get_mean_and_stddevs(
            sites, rup, dists, imt, stddev_types)
        
        A08 = self.A08_COEFFS[imt]
        f_ena = 10.0 ** (A08["c"] + A08["d"] * dists.rjb)

        return np.log(np.exp(mean)*f_ena), stddevs
959621
def extract_means_or_values(cls, observation, prediction, key=None):
        

        obs_mv = cls.extract_mean_or_value(observation, key)
        pred_mv = cls.extract_mean_or_value(prediction, key)
        return obs_mv, pred_mv