Esempio n. 1
0
    def classical_damage(self,
                         loss_type,
                         assets,
                         hazard_curve,
                         col=None,
                         rng=None):
        """
        :param loss_type: the loss type
        :param assets: a list of N assets of the same taxonomy
        :param hazard_curve: a dictionary col -> hazard curve
        :returns: an array of N x D elements

        where N is the number of points and D the number of damage states.
        """
        ffl = self.risk_functions[loss_type, 'fragility']
        hazard_imls = self.hazard_imtls[ffl.imt]
        rtime = self.risk_investigation_time or self.investigation_time
        damage = scientific.classical_damage(
            ffl,
            hazard_imls,
            hazard_curve,
            investigation_time=self.investigation_time,
            risk_investigation_time=rtime,
            steps_per_interval=self.steps_per_interval)
        res = numpy.array(
            [a['value-number'] * damage for a in assets.to_records()])
        return res
Esempio n. 2
0
 def test_discrete(self):
     hazard_imls = [0.05, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]
     fragility_functions = scientific.FragilityFunctionList(
         [], imls=hazard_imls, steps_per_interval=None, format='discrete')
     fragility_functions.extend([
         scientific.FragilityFunctionDiscrete(
             'slight', hazard_imls,
             [0.0, 0.771, 0.95, 0.989, 0.997, 0.999, 1., 1.]),
         scientific.FragilityFunctionDiscrete(
             'moderate', hazard_imls,
             [0, 0.5, 0.861, 0.957, 0.985, 0.994, 0.997, 0.999]),
         scientific.FragilityFunctionDiscrete(
             'extreme', hazard_imls,
             [0.0, 0.231, 0.636, 0.837, 0.924, 0.962, .981, .989]),
         scientific.FragilityFunctionDiscrete(
             'complete', hazard_imls,
             [0, 0.097, 0.414, 0.661, 0.806, 0.887, 0.933, 0.959]),
     ])
     hazard_poes = numpy.array([
         0.999999999997518,
         0.077404949,
         0.015530587,
         0.004201327,
         0.001284191,
         0.000389925,
         0.000127992,
         0.000030350,
     ])
     investigation_time = 50.
     risk_investigation_time = 100.
     poos = scientific.classical_damage(
         fragility_functions, hazard_imls, hazard_poes,
         investigation_time, risk_investigation_time)
     aaae(poos, [1.0415184E-09, 1.4577245E-06, 1.9585762E-03, 6.9677521E-02,
                 9.2836244E-01])
Esempio n. 3
0
    def classical_damage(self,
                         loss_type,
                         assets,
                         hazard_curve,
                         eids=None,
                         eps=None):
        """
        :param loss_type: the loss type
        :param assets: a list of N assets of the same taxonomy
        :param hazard_curve: an hazard curve array
        :returns: an array of N x D elements

        where N is the number of points and D the number of damage states.
        """
        ffl = self.risk_functions[loss_type, 'fragility']
        hazard_imls = self.hazard_imtls[ffl.imt]
        debug = False  # assets['id'] == b'a5' to debug case_master
        damage = scientific.classical_damage(
            ffl,
            hazard_imls,
            hazard_curve,
            investigation_time=self.investigation_time,
            risk_investigation_time=self.risk_investigation_time,
            steps_per_interval=self.steps_per_interval,
            debug=debug)
        res = numpy.array([a['number'] * damage for a in assets])
        return res
Esempio n. 4
0
 def test_discrete(self):
     hazard_imls = [0.05, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]
     fragility_functions = scientific.FragilityFunctionList(
         [], imls=hazard_imls, format='discrete')
     fragility_functions.extend([
         scientific.FragilityFunctionDiscrete(
             'slight', hazard_imls,
             [0.0, 0.771, 0.95, 0.989, 0.997, 0.999, 1., 1.]),
         scientific.FragilityFunctionDiscrete(
             'moderate', hazard_imls,
             [0, 0.5, 0.861, 0.957, 0.985, 0.994, 0.997, 0.999]),
         scientific.FragilityFunctionDiscrete(
             'extreme', hazard_imls,
             [0.0, 0.231, 0.636, 0.837, 0.924, 0.962, .981, .989]),
         scientific.FragilityFunctionDiscrete(
             'complete', hazard_imls,
             [0, 0.097, 0.414, 0.661, 0.806, 0.887, 0.933, 0.959]),
     ])
     hazard_poes = numpy.array([
         0.999999999997518,
         0.077404949,
         0.015530587,
         0.004201327,
         0.001284191,
         0.000389925,
         0.000127992,
         0.000030350,
     ])
     investigation_time = 50.
     risk_investigation_time = 100.
     poos = scientific.classical_damage(
         fragility_functions, hazard_imls, hazard_poes,
         investigation_time, risk_investigation_time)
     aaae(poos, [1.0415184E-09, 1.4577245E-06, 1.9585762E-03, 6.9677521E-02,
                 9.2836244E-01])
Esempio n. 5
0
    def __call__(self,
                 loss_type,
                 assets,
                 hazard_curve,
                 _epsilons=None,
                 _eids=None):
        """
        :param loss_type: the loss type
        :param assets: a list of N assets of the same taxonomy
        :param hazard_curve: an hazard curve array
        :returns: an array of N assets and an array of N x D elements

        where N is the number of points and D the number of damage states.
        """
        ffl = self.risk_functions[loss_type]
        hazard_imls = self.hazard_imtls[ffl.imt]
        damage = scientific.classical_damage(
            ffl,
            hazard_imls,
            hazard_curve,
            investigation_time=self.investigation_time,
            risk_investigation_time=self.risk_investigation_time)
        return scientific.Output(assets,
                                 loss_type,
                                 damages=[a.number * damage for a in assets])
Esempio n. 6
0
 def test_continuous(self):
     hazard_imls = numpy.array([
         0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6,
         0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2,
         1.25, 1.3, 1.35, 1.4
     ])
     fragility_functions = scientific.FragilityFunctionList(
         [
             scientific.FragilityFunctionContinuous('slight', 0.160, 0.104),
             scientific.FragilityFunctionContinuous('moderate', 0.225,
                                                    0.158),
             scientific.FragilityFunctionContinuous('extreme', 0.400,
                                                    0.300),
             scientific.FragilityFunctionContinuous('complete', 0.600,
                                                    0.480),
         ],
         imls=hazard_imls,
         steps_per_interval=None)
     hazard_poes = numpy.array([
         0.5917765421,
         0.2482053921,
         0.1298604374,
         0.07718928965,
         0.04912904516,
         0.03262871528,
         0.02226628376,
         0.01553639696,
         0.01101802934,
         0.007905366815,
         0.005741833876,
         0.004199803178,
         0.003088785556,
         0.00229291494,
         0.001716474683,
         0.001284555773,
         0.0009583846496,
         0.0007102377096,
         0.0005201223961,
         0.0003899464723,
         0.0002997724582,
         0.0002287788496,
         0.0001726083994,
         0.0001279544769,
         0.00009229282594,
         0.00006368651249,
         0.00004249201524,
         0.00003033694903,
     ])
     investigation_time = 50.
     risk_investigation_time = 100.
     poos = scientific.classical_damage(fragility_functions, hazard_imls,
                                        hazard_poes, investigation_time,
                                        risk_investigation_time)
     aaae(poos, [0.56652127, 0.12513401, 0.1709355, 0.06555033, 0.07185889])
Esempio n. 7
0
 def test_continuous(self):
     hazard_imls = numpy.array(
         [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6,
          0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2,
          1.25, 1.3, 1.35, 1.4])
     fragility_functions = scientific.FragilityFunctionList(
         [], imls=hazard_imls, steps_per_interval=None, format='continuous')
     fragility_functions.extend([
         scientific.FragilityFunctionContinuous(
             'slight', 0.160, 0.104),
         scientific.FragilityFunctionContinuous(
             'moderate', 0.225, 0.158),
         scientific.FragilityFunctionContinuous(
             'extreme', 0.400, 0.300),
         scientific.FragilityFunctionContinuous(
             'complete', 0.600, 0.480),
     ])
     hazard_poes = numpy.array([
         0.5917765421,
         0.2482053921,
         0.1298604374,
         0.07718928965,
         0.04912904516,
         0.03262871528,
         0.02226628376,
         0.01553639696,
         0.01101802934,
         0.007905366815,
         0.005741833876,
         0.004199803178,
         0.003088785556,
         0.00229291494,
         0.001716474683,
         0.001284555773,
         0.0009583846496,
         0.0007102377096,
         0.0005201223961,
         0.0003899464723,
         0.0002997724582,
         0.0002287788496,
         0.0001726083994,
         0.0001279544769,
         0.00009229282594,
         0.00006368651249,
         0.00004249201524,
         0.00003033694903,
         ])
     investigation_time = 50.
     risk_investigation_time = 100.
     poos = scientific.classical_damage(
         fragility_functions, hazard_imls, hazard_poes,
         investigation_time, risk_investigation_time)
     aaae(poos, [0.56652127, 0.12513401, 0.1709355, 0.06555033, 0.07185889])
Esempio n. 8
0
    def __call__(self, loss_type, assets, hazard_curve, eids=None, eps=None):
        """
        :param loss_type: the loss type
        :param assets: a list of N assets of the same taxonomy
        :param hazard_curve: an hazard curve array
        :returns: an array of N assets and an array of N x D elements

        where N is the number of points and D the number of damage states.
        """
        ffl = self.fragility_functions[loss_type, self.kind]
        hazard_imls = self.hazard_imtls[ffl.imt]
        damage = scientific.classical_damage(
            ffl, hazard_imls, hazard_curve,
            investigation_time=self.investigation_time,
            risk_investigation_time=self.risk_investigation_time)
        return [a['number'] * damage for a in assets]
Esempio n. 9
0
    def classical_damage(
            self, loss_type, assets, hazard_curve, eids=None, eps=None):
        """
        :param loss_type: the loss type
        :param assets: a list of N assets of the same taxonomy
        :param hazard_curve: an hazard curve array
        :returns: an array of N assets and an array of N x D elements

        where N is the number of points and D the number of damage states.
        """
        ffl = self.risk_functions[loss_type, 'fragility']
        hazard_imls = self.hazard_imtls[ffl.imt]
        damage = scientific.classical_damage(
            ffl, hazard_imls, hazard_curve,
            investigation_time=self.investigation_time,
            risk_investigation_time=self.risk_investigation_time)
        return [a['number'] * damage for a in assets]
Esempio n. 10
0
    def __call__(self, loss_type, assets, hazard_curves, _epsilons=None,
                 _tags=None):
        """
        :param loss_type: the loss type
        :param assets: a list of N assets of the same taxonomy
        :param hazard_curves: an array of N x E elements
        :returns: an array of N assets and an array of N x D elements

        where N is the number of points and D the number of damage states.
        """
        damages = [
            asset.number * scientific.classical_damage(
                self.risk_functions[loss_type], self.hazard_imls, curve,
                investigation_time=self.investigation_time,
                risk_investigation_time=self.risk_investigation_time)
            for asset, curve in zip(assets, hazard_curves)]
        return scientific.Output(assets, loss_type, damages=damages)
Esempio n. 11
0
    def __call__(self,
                 loss_type,
                 assets,
                 hazard_curves,
                 _epsilons=None,
                 _tags=None):
        """
        :param loss_type: the loss type
        :param assets: a list of N assets of the same taxonomy
        :param hazard_curves: an array of N x E elements
        :returns: an array of N assets and an array of N x D elements

        where N is the number of points and D the number of damage states.
        """
        damages = [
            asset.number * scientific.classical_damage(
                self.risk_functions[loss_type],
                self.hazard_imls,
                curve,
                investigation_time=self.investigation_time,
                risk_investigation_time=self.risk_investigation_time)
            for asset, curve in zip(assets, hazard_curves)
        ]
        return scientific.Output(assets, loss_type, damages=damages)