def _convert_pes_to_pos(hazard_curve, imls): """For each IML (Intensity Measure Level) compute the PoOs (Probability of Occurence) from the PoEs (Probability of Exceendance) defined in the given hazard curve. :param hazard_curve: the hazard curve used to compute the PoOs. :type hazard_curve: :py:class:`openquake.shapes.Curve` :param imls: the IMLs (Intensity Measure Level) of the vulnerability function used to interpolate the hazard curve. :type imls: :py:class:`list` """ return collect(loop(_compute_pes_from_imls(hazard_curve, imls), lambda x, y: subtract(array(x), array(y))))
def _convert_pes_to_pos(hazard_curve, imls): """For each IML (Intensity Measure Level) compute the PoOs (Probability of Occurence) from the PoEs (Probability of Exceendance) defined in the given hazard curve. :param hazard_curve: the hazard curve used to compute the PoOs. :type hazard_curve: :py:class:`openquake.shapes.Curve` :param imls: the IMLs (Intensity Measure Level) of the vulnerability function used to interpolate the hazard curve. :type imls: :py:class:`list` """ return collect( loop(_compute_pes_from_imls(hazard_curve, imls), lambda x, y: subtract(array(x), array(y))))
def _split_loss_ratios(loss_ratios, steps): """Split the loss ratios, producing a new set of loss ratios. :param loss_ratios: the loss ratios to be splitted. :type loss_ratios: list :param steps: the number of steps we make to go from one loss ratio to the next. For example, if we have [1.0, 2.0]: steps = 1 produces [1.0, 2.0] steps = 2 produces [1.0, 1.5, 2.0] steps = 3 produces [1.0, 1.33, 1.66, 2.0] :type steps: integer """ splitted_ratios = set() for interval in loop(array(loss_ratios), linspace, steps + 1): splitted_ratios.update(interval) return array(sorted(splitted_ratios))
def _compute_imls(vuln_function): """Compute the mean IMLs (Intensity Measure Level) for the given vulnerability function. :param vuln_function: the vulnerability function where the IMLs (Intensity Measure Level) are taken from. :type vuln_function: :py:class:`openquake.shapes.VulnerabilityFunction` """ imls = vuln_function.imls # "special" cases for lowest part and highest part of the curve lowest_iml_value = imls[0] - ((imls[1] - imls[0]) / 2) # if the calculated lowest_curve_value goes < 0 we have to force the 0 # IMLs have to be >= 0 if lowest_iml_value < 0: lowest_iml_value = 0 highest_iml_value = imls[-1] + ((imls[-1] - imls[-2]) / 2) between_iml_values = collect(loop(imls, lambda x, y: mean([x, y]))) return [lowest_iml_value] + between_iml_values + [highest_iml_value]