def get_phi_ss_at_quantile_ACME(phi_model, quantile): """ Returns the phi_ss values at the specified quantile as an instance of `class`:: openquake.hazardlib.gsim.base.CoeffsTable - applies to the magnitude-dependent cases """ # Setup SA coeffs - the backward compatible Python 2.7 way coeffs = deepcopy(phi_model.sa_coeffs) coeffs.update(phi_model.non_sa_coeffs) for imt in coeffs: if quantile is None: coeffs[imt] = { "a": phi_model[imt]["mean_a"], "b": phi_model[imt]["mean_b"] } else: coeffs[imt] = { "a": _at_percentile(phi_model[imt]["mean_a"], phi_model[imt]["var_a"], quantile), "b": _at_percentile(phi_model[imt]["mean_b"], phi_model[imt]["var_b"], quantile) } return CoeffsTable.fromdict(coeffs, logratio=False)
def _dict_to_coeffs_table(input_dict, name): """ Transform a dictionary of parameters organised by IMT into a coefficient table """ coeff_dict = {} for key in input_dict: coeff_dict[from_string(key)] = {name: input_dict[key]} return {name: CoeffsTable.fromdict(coeff_dict)}
def _get_sigma_at_quantile(self, sigma_quantile): """ Calculates the total standard deviation at the specified quantile """ # Mean mean is found in self.TAU. Get the variance in tau tau_std = TAU_SETUP[self.tau_model]["STD"] # Mean phiss is found in self.PHI_SS. Get the variance in phi phi_std = deepcopy(self.PHI_SS.sa_coeffs) phi_std.update(self.PHI_SS.non_sa_coeffs) for key in phi_std: phi_std[key] = {"a": PHI_SETUP[self.phi_model][key]["var_a"], "b": PHI_SETUP[self.phi_model][key]["var_b"]} if self.ergodic: # IMT list should be taken from the PHI_S2SS_MODEL imt_list = list( PHI_S2SS_MODEL[self.phi_s2ss_model].non_sa_coeffs) imt_list += list(PHI_S2SS_MODEL[self.phi_s2ss_model].sa_coeffs) else: imt_list = list(phi_std) phi_std = CoeffsTable.fromdict(phi_std) tau_bar, tau_std = _get_tau_vector(self, self.TAU, tau_std, imt_list) phi_bar, phi_std = _get_phi_vector(self, self.PHI_SS, phi_std, imt_list) sigma = {} # Calculate the total standard deviation for imt in imt_list: sigma[imt] = {} for i, key in enumerate(self.tau_keys): # Calculates the expected standard deviation sigma_bar = np.sqrt(tau_bar[imt][i] ** 2. + phi_bar[imt][i] ** 2.) # Calculated the variance in the standard deviation sigma_std = np.sqrt(tau_std[imt][i] ** 2. + phi_std[imt][i] ** 2.) # The keys swap from tau to sigma new_key = key.replace("tau", "sigma") if sigma_quantile is not None: sigma[imt][new_key] = _at_percentile( sigma_bar, sigma_std, sigma_quantile) else: sigma[imt][new_key] = sigma_bar self.tau_keys[i] = new_key self.SIGMA = CoeffsTable.fromdict(sigma)
def get_phi_s2ss_at_quantile(phi_model, quantile): """ Returns the phi_s2ss value for all periods at the specific quantile as an instance of `class`::openquake.hazardlib.gsim.base.CoeffsTable """ # Setup SA coeffs - the backward compatible Python 2.7 way coeffs = deepcopy(phi_model.sa_coeffs) coeffs.update(phi_model.non_sa_coeffs) for imt in coeffs: if quantile is None: coeffs[imt] = {"phi_s2ss": phi_model[imt]["mean"]} else: coeffs[imt] = {"phi_s2ss": _at_percentile(phi_model[imt]["mean"], phi_model[imt]["var"], quantile)} return CoeffsTable.fromdict(coeffs)
def __init__(self, gmpe_name, reference_velocity=760., region=None, phi_0=None, **kwargs): super().__init__(**kwargs) if isinstance(gmpe_name, str): self.gmpe = registry[gmpe_name](**kwargs) else: # An instantiated class is passed as an argument self.gmpe = copy.deepcopy(gmpe_name) # Define the reference velocity - set to 760. by default self.rock_vs30 = reference_velocity if reference_velocity else\ self.DEFINED_FOR_REFERENCE_VELOCITY for name in uppernames: setattr(self, name, frozenset(getattr(self, name) | getattr(self.gmpe, name))) stddev_check = (const.StdDev.INTER_EVENT in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES) and\ (const.StdDev.INTRA_EVENT in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES) if not stddev_check: raise ValueError("Input GMPE %s not defined for inter- and intra-" "event standard deviation" % str(self.gmpe)) if isinstance(phi_0, dict): # Input phi_0 model iphi_0 = {from_string(key): {'value': phi_0[key]} for key in phi_0} self.phi_0 = CoeffsTable.fromdict(iphi_0) else: # No input phi_0 model self.phi_0 = None # Regionalisation of the linear site term is possible # check if region is in the set of supported terms and # raise error otherwise if region is not None: if region in REGION_SET: self.region = "ck{:s}".format(region) else: raise ValueError("Region must be one of: %s" % " ".join(REGION_SET)) else: self.region = region
def __init__(self, gmpe_name, branch="central", sigma_mu_epsilon=0.0, homoskedastic_sigma=False, scaling_factor=None, vskappa=None, phi_ds2s=True, **kwargs): super().__init__(gmpe_name=gmpe_name, branch=branch, homoskedastic_sigma=homoskedastic_sigma, scaling_factor=scaling_factor, vskappa=vskappa, phi_ds2s=phi_ds2s, **kwargs) self.gmpe = registry[gmpe_name]() # Update the required_parameters for name in uppernames: setattr(self, name, frozenset(getattr(self, name) | getattr(self.gmpe, name))) # If the scaling factor take the natural log if scaling_factor: self.scaling_factor = np.log(scaling_factor) else: self.scaling_factor = None # If vs-kappa is passed as a dictionary then transform to CoeffsTable if isinstance(vskappa, dict): in_vskappa = {} for key in vskappa: in_vskappa[from_string(key)] = { "vskappa": np.log(vskappa[key]) } self.vskappa = CoeffsTable.fromdict(in_vskappa) else: self.vskappa = None self.branch = branch self.sigma_mu_epsilon = sigma_mu_epsilon self.homoskedastic_sigma = homoskedastic_sigma self.phi_ds2s = phi_ds2s