Example #1
0
    def _store_dsc_fmodel(self):
        [ism] = models.inputs4job(self.job.id, input_type="fragility")

        fmodel = models.FragilityModel(
            owner=ism.owner, input=ism, imls=[0.1, 0.3, 0.5, 0.7],
            imt="mmi", lss=["LS1", "LS2"], format="discrete",
            no_damage_limit=0.05)

        fmodel.save()

        models.Ffd(
            fragility_model=fmodel, taxonomy="RC",
            ls="LS2", poes=[0.00, 0.05, 0.20, 0.50], lsi=2).save()

        models.Ffd(
            fragility_model=fmodel, taxonomy="RC",
            ls="LS1", poes=[0.05, 0.20, 0.50, 1.00], lsi=1).save()

        models.Ffd(
            fragility_model=fmodel, taxonomy="RM",
            ls="LS2", poes=[0.02, 0.07, 0.25, 0.60], lsi=2).save()

        models.Ffd(
            fragility_model=fmodel, taxonomy="RM",
            ls="LS1", poes=[0.03, 0.12, 0.42, 0.90], lsi=1).save()

        return fmodel
Example #2
0
 def test_ffd_with_duplicate_ls_and_taxonomy(self):
     # discrete fragility function with duplicate limit state and taxonomy
     #   -> exception
     ffd = models.Ffd(fragility_model=self.mdl,
                      ls="b",
                      taxonomy="T2",
                      poes=[0.5, 0.6],
                      lsi=2)
     ffd.save()
     self.assertIs(self.mdl, ffd.fragility_model)
     self.assertEqual("T2", ffd.taxonomy)
     self.assertEqual("b", ffd.ls)
     self.assertEqual(2, ffd.lsi)
     self.assertEqual([0.5, 0.6], ffd.poes)
     ffd2 = models.Ffd(fragility_model=self.mdl,
                       ls="b",
                       taxonomy="T2",
                       poes=[0.51, 0.62],
                       lsi=2)
     try:
         ffd2.save()
     except DatabaseError, de:
         self.assertTrue(
             'duplicate key value violates unique constraint '
             '"ffd_fragility_model_id_taxonomy_lsi_key"' in de.args[0])
         transaction.rollback()
Example #3
0
    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.

        [ism] = models.inputs4job(self.job.id, input_type="fragility")

        fmodel = models.FragilityModel(
            owner=ism.owner, input=ism, imls=[0.1, 0.3, 0.5, 0.7],
            imt="mmi", lss=["LS1"], format="discrete", no_damage_limit=0.05)

        fmodel.save()

        func = models.Ffd(
            fragility_model=fmodel, taxonomy="RC",
            ls="LS1", poes=[0.05, 0.20, 0.50, 1.00], lsi=1)

        func.save()

        self._close_to([1.0, 0.0],
            compute_gmv_fractions([func], 0.02))
Example #4
0
    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)

        [ism] = models.inputs4job(self.job.id, input_type="fragility")

        fmodel = models.FragilityModel(
            owner=ism.owner, input=ism, imls=[0.1, 0.3, 0.5, 0.7],
            imt="mmi", lss=["LS1"], format="discrete")

        fmodel.save()

        func = models.Ffd(
            fragility_model=fmodel, taxonomy="RC",
            ls="LS1", poes=[0.05, 0.20, 0.50, 1.00], lsi=1)

        func.save()

        self._close_to(compute_gmv_fractions([func], 0.7),
                compute_gmv_fractions([func], 0.8))
Example #5
0
 def test_ffd_with_wrong_num_of_poes(self):
     # discrete fragility function and wrong #poes -> exception
     ffd = models.Ffd(fragility_model=self.mdl, ls="a", poes=[0.5], lsi=1)
     try:
         ffd.save()
     except DatabaseError, de:
         self.assertTrue('#poes differs from #imls (1 != 2)' in de.args[0])
         transaction.rollback()
Example #6
0
 def test_ffd_with_no_ls(self):
     # discrete fragility function and no limit state -> exception
     ffd = models.Ffd(fragility_model=self.mdl, poes=[0.5, 0.6], lsi=-1)
     try:
         ffd.save()
     except DatabaseError, de:
         self.assertTrue('Invalid limit state' in de.args[0])
         transaction.rollback()
Example #7
0
 def test_ffd_with_discrete_model(self):
     # discrete fragility function and discrete model -> exception
     ffd = models.Ffd(fragility_model=self.continuous_mdl, ls="d", lsi=1)
     try:
         ffd.save()
     except DatabaseError, de:
         self.assertTrue('mismatch: continuous model but discrete function'
                         in de.args[0])
         transaction.rollback()
Example #8
0
 def test_ffd_with_invalid_ls_not_int(self):
     # discrete fragility function and invalid limit state -> exception
     ffd = models.Ffd(fragility_model=self.mdl,
                      ls="xyz",
                      lsi="blah",
                      poes=[0.5, 0.6])
     try:
         ffd.save()
     except ValueError, de:
         self.assertTrue('invalid literal for int' in de.args[0])
         transaction.rollback()
Example #9
0
 def test_ffd(self):
     # discrete fragility function with good data is inserted OK.
     ffd = models.Ffd(fragility_model=self.mdl,
                      ls="b",
                      taxonomy="T2",
                      poes=[0.5, 0.6],
                      lsi=2)
     ffd.save()
     self.assertIs(self.mdl, ffd.fragility_model)
     self.assertEqual("T2", ffd.taxonomy)
     self.assertEqual("b", ffd.ls)
     self.assertEqual(2, ffd.lsi)
     self.assertEqual([0.5, 0.6], ffd.poes)
Example #10
0
 def test_ffd_with_invalid_sli(self):
     # discrete fragility function with with invalid limit state index
     #   -> exception
     ffd = models.Ffd(fragility_model=self.mdl,
                      ls="b",
                      taxonomy="T2",
                      poes=[0.5, 0.6],
                      lsi=len(self.mdl.lss) * 2)
     try:
         ffd.save()
     except DatabaseError, de:
         self.assertTrue(
             'Invalid limit state index (6) for ffd(T2, b)' in de.args[0])
         transaction.rollback()