def test_dda_iml_above_range(self): # corner case where we have a ground motion value # (that corresponds to the intensity measure level in the # fragility function) that is higher than the highest # intensity measure level defined in the model (in this # particular case 0.7). Given this condition, to compute # the fractions of buildings we use the highest intensity # measure level defined in the model (0.7 in this case) ffns = [scientific.FragilityFunctionDiscrete( [0.1, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00])] * 2 self._close_to(scientific.scenario_damage(ffns, [0.7]), scientific.scenario_damage(ffns, [0.8]))
def test_dda_iml_above_range(self): # corner case where we have a ground motion value # (that corresponds to the intensity measure level in the # fragility function) that is higher than the highest # intensity measure level defined in the model (in this # particular case 0.7). Given this condition, to compute # the fractions of buildings we use the highest intensity # measure level defined in the model (0.7 in this case) ffns = [ scientific.FragilityFunctionDiscrete( 'LS1', [0.1, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00]), scientific.FragilityFunctionDiscrete( 'LS2', [0.1, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00]) ] self._close_to(scientific.scenario_damage(ffns, [0.7]), scientific.scenario_damage(ffns, [0.8]))
def __call__(self, loss_type, assets, gmvs_eids, _eps=None): """ :param loss_type: the loss type :param assets: a list of N assets of the same taxonomy :param gmvs_eids: pairs (gmvs, eids), each one with E elements :param _eps: dummy parameter, unused :returns: N arrays of E x D elements where N is the number of points, E the number of events and D the number of damage states. """ ffs = self.risk_functions[loss_type] damages = scientific.scenario_damage(ffs, gmvs_eids[0]) # shape (D, E) return [damages.T] * len(assets)
def test_dda_iml_below_range_damage_limit_defined(self): # corner case where we have a ground motion value # (that corresponds to the intensity measure level in the # fragility function) that is lower than the lowest # intensity measure level defined in the model (in this # particular case 0.1) and lower than the no_damage_limit # attribute defined in the model. Given this condition, the # fractions of buildings is 100% no_damage and 0% for the # remaining limit states defined in the model. ffns = [scientific.FragilityFunctionDiscrete( [0.05, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00], 0.5)] * 2 self._close_to([[1.0, 0.0, 0.0]], scientific.scenario_damage(ffns, [0.02]))
def scenario_damage(self, loss_type, assets, gmvs, eids=None, eps=None): """ :param loss_type: the loss type :param assets: a list of A assets of the same taxonomy :param gmvs: an array of E ground motion values :param eids: an array of E event IDs :param eps: dummy parameter, unused :returns: an array of shape (A, E, D) elements where N is the number of points, E the number of events and D the number of damage states. """ ffs = self.risk_functions[loss_type, 'fragility'] damages = scientific.scenario_damage(ffs, gmvs).T return numpy.array([damages] * len(assets))
def scenario_damage(self, loss_type, assets, gmf_df, col, rng=None): """ :param loss_type: the loss type :param assets: a list of A assets of the same taxonomy :param gmf_df: a DataFrame of GMFs :param epsilons: dummy parameter, unused :returns: an array of shape (A, E, D) elements where N is the number of points, E the number of events and D the number of damage states. """ gmvs = gmf_df[col].to_numpy() ffs = self.risk_functions[loss_type, 'fragility'] damages = scientific.scenario_damage(ffs, gmvs).T return numpy.array([damages] * len(assets))
def __call__(self, loss_type, assets, gmfs, _epsilons=None, _tags=None): """ :param loss_type: the loss type :param assets: a list of N assets of the same taxonomy :param gmfs: an array of N x E elements :returns: an array of N assets and an array of N x E x D elements where N is the number of points, E the number of events and D the number of damage states. """ ffs = self.risk_functions[loss_type] damages = numpy.array( [[scientific.scenario_damage(ffs, gmv) for gmv in gmvs] for gmvs in gmfs]) return scientific.Output(assets, loss_type, damages=damages)
def __call__(self, loss_type, assets, gmfs, _epsilons=None): """ :param loss_type: the string 'damage' :param assets: a list of N assets of the same taxonomy :param gmfs: an array of N x R elements :returns: an array of N assets and an array of N x R x D elements where N is the number of points, R the number of realizations and D the number of damage states. """ ffs = self.risk_functions['damage'] damages = numpy.array( [[scientific.scenario_damage(ffs, gmv) for gmv in gmvs] for gmvs in gmfs]) return assets, damages
def __call__(self, loss_type, assets, gmvs, _eps=None): """ :param loss_type: the loss type :param assets: a list of N assets of the same taxonomy :param gmvs: an array of E elements :param _eps: dummy parameter, unused :returns: an array of N assets and an array of N x E x D elements where N is the number of points, E the number of events and D the number of damage states. """ n = len(assets) ffs = self.risk_functions[loss_type] damages = numpy.array( [scientific.scenario_damage(ffs, gmv) for gmv in gmvs]) return scientific.Output(assets, loss_type, damages=[damages] * n)
def test_gmv_between_no_damage_limit_and_first_iml(self): # corner case where we have a ground motion value # (that corresponds to the intensity measure level in the # fragility function) that is lower than the lowest # intensity measure level defined in the model (in this # particular case 0.1) but bigger than the no_damage_limit # attribute defined in the model. Given this condition, the # fractions of buildings is 97.5% no_damage and 2.5% for the # remaining limit states defined in the model. ffs = [ scientific.FragilityFunctionDiscrete( [0.05, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00], 0.05), scientific.FragilityFunctionDiscrete( [0.05, 0.1, 0.3, 0.5, 0.7], [0, 0.00, 0.05, 0.20, 0.50], 0.05)] self._close_to([[0.975, 0.025, 0.]], scientific.scenario_damage(ffs, [0.075]))
def test_gmv_between_no_damage_limit_and_first_iml(self): # corner case where we have a ground motion value # (that corresponds to the intensity measure level in the # fragility function) that is lower than the lowest # intensity measure level defined in the model (in this # particular case 0.1) but bigger than the no_damage_limit # attribute defined in the model. Given this condition, the # fractions of buildings is 97.5% no_damage and 2.5% for the # remaining limit states defined in the model. ffs = [ scientific.FragilityFunctionDiscrete( 'LS1', [0.05, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00], 0.05), scientific.FragilityFunctionDiscrete( 'LS2', [0.05, 0.1, 0.3, 0.5, 0.7], [0, 0.00, 0.05, 0.20, 0.50], 0.05)] self._close_to([0.975, 0.025, 0], scientific.scenario_damage(ffs, 0.075))
def test_dda_iml_below_range_damage_limit_defined(self): # corner case where we have a ground motion value # (that corresponds to the intensity measure level in the # fragility function) that is lower than the lowest # intensity measure level defined in the model (in this # particular case 0.1) and lower than the no_damage_limit # attribute defined in the model. Given this condition, the # fractions of buildings is 100% no_damage and 0% for the # remaining limit states defined in the model. ffns = [ scientific.FragilityFunctionDiscrete( 'LS1', [0.05, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00], 0.5), scientific.FragilityFunctionDiscrete( 'LS2', [0.05, 0.1, 0.3, 0.5, 0.7], [0, 0.05, 0.20, 0.50, 1.00], 0.5), ] self._close_to([[1.0], [0.0], [0.0]], scientific.scenario_damage(ffns, [0.02]))
def scenario_damage(self, loss_type, assets, gmvs, eids=None, eps=None): """ :param loss_type: the loss type :param assets: a list of A assets of the same taxonomy :param gmvs_eids: pairs (gmvs, eids), each one with E elements :param _eps: dummy parameter, unused :returns: an array of shape (A, E, D + 1) elements where N is the number of points, E the number of events and D the number of damage states. """ ffs = self.risk_functions[loss_type, 'fragility'] damages = scientific.scenario_damage(ffs, gmvs).T E, D = damages.shape dmg_csq = numpy.zeros((E, D + 1)) dmg_csq[:, :D] = damages c_model = self.risk_functions.get((loss_type, 'consequence')) if c_model: # compute consequences means = [0] + [par[0] for par in c_model.params] # NB: we add a 0 in front for nodamage state dmg_csq[:, D] = damages @ means # consequence ratio return numpy.array([dmg_csq] * len(assets))