コード例 #1
0
    def setUp(self):

        #Create MMI object for testing
        self.mmi = imt()
        self.mmi.site_tag = "test_site"
        self.mmi.input_dir = tempfile.mkdtemp()

        self.mmi.raw_xml = """<?xml version="1.0"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.3" xmlns:gml="http://www.opengis.net/gml" gml:id="nrml">
  <vulnerabilityModel>
    <discreteVulnerabilitySet vulnerabilitySetID="HAZUS" assetCategory="buildings" lossCategory="economic_loss">
      <IML IMT="MMI"> 0.00 5.27 6.15 6.67 7.04 7.33 7.56 7.76 7.93 8.08 8.22 8.34 8.45 8.58 8.67 8.76 8.84 8.91 8.99 9.05 9.12 9.18 9.24 9.30 9.35 9.40 9.45 9.50 9.55 9.59 9.63 9.68 9.72 9.75 9.79 9.83 9.87 9.90 9.94 9.98 10.0</IML>
      <discreteVulnerability vulnerabilityFunctionID="W1TIMBERMETAL" probabilisticDistribution="N">
        <lossRatio> 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.01 0.01 0.02 0.03 0.04 0.06 0.08 0.10 0.13 0.15 0.18 0.21 0.24 0.27 0.31 0.34 0.37 0.40 0.43 0.46 0.49 0.52 0.55 0.58 0.60 0.63 0.65 0.67 0.70 0.72 1.00</lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
      <discreteVulnerability vulnerabilityFunctionID="W1BVMETAL" probabilisticDistribution="N">
        <lossRatio> 0.00 0.04 0.15 0.25 0.34 0.42 0.49 0.55 0.60 0.64 0.67 0.71 0.73 0.76 0.78 0.80 0.81 0.83 0.84 0.85 0.87 0.87 0.88 0.89 0.90 0.91 0.91 0.92 0.92 0.93 0.93 0.94 0.94 0.94 0.95 0.95 0.95 0.95 0.96 0.96 1.00</lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
    </discreteVulnerabilitySet>
  </vulnerabilityModel>
</nrml>"""
        f = open(
            os.path.join(self.mmi.input_dir,
                         '%s_vulnerability.xml' % self.mmi.site_tag), 'wb')
        f.write(self.mmi.raw_xml)
        f.close()

        self.mmi.sites_filename = os.path.join(
            self.mmi.input_dir, 'sitedb_%s.csv' % self.mmi.site_tag)

        self.mmi.raw_csv = """BID,LATITUDE,LONGITUDE,STRUCTURE_CLASSIFICATION,STRUCTURE_CATEGORY,HAZUS_USAGE,SUBURB,POSTCODE,PRE1989,HAZUS_STRUCTURE_CLASSIFICATION,CONTENTS_COST_DENSITY,BUILDING_COST_DENSITY,FLOOR_AREA,SURVEY_FACTOR,FCB_USAGE,SITE_CLASS,
2,-6.4125,110.837502,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,344.4451,688.8903,150,9.8,, C, 
3,-6.4125,110.845833,W1BVMETAL, BUILDING,,TURNER,2612,,,430.5564,861.1128,480,1,, C, 
4,-6.4125,110.854164,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,1087.155,1087.155,300,1,, C, 
5,-6.4125,110.845833,W1BVMETAL, BUILDING,,TURNER,2612,,,430.5564,861.1128,480,1,, C, 
6,-6.4125,110.854164,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,1087.155,1087.155,300,1,, C, """
        f = open(self.mmi.sites_filename, 'wb')
        f.write(self.mmi.raw_csv)
        f.close()

        self.mmi.eqrm_flags = Dummy()
        self.mmi.eqrm_flags.site_tag = self.mmi.site_tag
        self.mmi.eqrm_flags.input_dir = self.mmi.input_dir
        self.mmi.eqrm_flags.vulnerability_variability_method = None

        self.mmi.sites = Structures_Vulnerability.from_csv(
            self.mmi.sites_filename, self.mmi.eqrm_flags)

        self.msg = 'Expected %s, got %s'

        #Now set up the object for testing PGA vulnerability files
        self.pga = imt()
        self.pga.site_tag = "test_site2"
        self.pga.input_dir = tempfile.mkdtemp()

        self.pga.raw_xml = """<?xml version="1.0"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.3" xmlns:gml="http://www.opengis.net/gml" gml:id="nrml">
  <vulnerabilityModel>
    <discreteVulnerabilitySet vulnerabilitySetID="HAZUS" assetCategory="buildings" lossCategory="economic_loss">
      <IML IMT="PGA"> 0.00 1.0 2.0 3.0 4.0</IML>
      <discreteVulnerability vulnerabilityFunctionID="W1TIMBERMETAL" probabilisticDistribution="N">
        <lossRatio> 0.00 0.02 0.04 0.06 0.08</lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
      <discreteVulnerability vulnerabilityFunctionID="W1BVMETAL" probabilisticDistribution="N">
        <lossRatio> 0.0 0.01 0.02 0.03 0.04 </lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
    </discreteVulnerabilitySet>
  </vulnerabilityModel>
</nrml>"""
        f = open(
            os.path.join(self.pga.input_dir,
                         '%s_vulnerability.xml' % self.pga.site_tag), 'wb')
        f.write(self.pga.raw_xml)
        f.close()

        self.pga.sites_filename = os.path.join(
            self.pga.input_dir, 'sitedb_%s.csv' % self.pga.site_tag)

        self.pga.raw_csv = """BID,LATITUDE,LONGITUDE,STRUCTURE_CLASSIFICATION,STRUCTURE_CATEGORY,HAZUS_USAGE,SUBURB,POSTCODE,PRE1989,HAZUS_STRUCTURE_CLASSIFICATION,CONTENTS_COST_DENSITY,BUILDING_COST_DENSITY,FLOOR_AREA,SURVEY_FACTOR,FCB_USAGE,SITE_CLASS,
2,-6.4125,110.837502,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,344.4451,688.8903,150,9.8,, C, 
3,-6.4125,110.845833,W1BVMETAL, BUILDING,,TURNER,2612,,,430.5564,861.1128,480,1,, C, 
4,-6.4125,110.854164,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,1087.155,1087.155,300,1,, C, """
        f = open(self.pga.sites_filename, 'wb')
        f.write(self.pga.raw_csv)
        f.close()

        self.pga.eqrm_flags = Dummy()
        self.pga.eqrm_flags.site_tag = self.pga.site_tag
        self.pga.eqrm_flags.input_dir = self.pga.input_dir
        self.pga.eqrm_flags.vulnerability_variability_method = None

        self.pga.sites = Structures_Vulnerability.from_csv(
            self.pga.sites_filename, self.pga.eqrm_flags)

        self.msg = 'Expected %s, got %s'
コード例 #2
0
    def setUp(self):
        
        #Create MMI object for testing 
        self.mmi=imt()
        self.mmi.site_tag = "test_site"
        self.mmi.input_dir = tempfile.mkdtemp()
        
        self.mmi.raw_xml = """<?xml version="1.0"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.3" xmlns:gml="http://www.opengis.net/gml" gml:id="nrml">
  <vulnerabilityModel>
    <discreteVulnerabilitySet vulnerabilitySetID="HAZUS" assetCategory="buildings" lossCategory="economic_loss">
      <IML IMT="MMI"> 0.00 5.27 6.15 6.67 7.04 7.33 7.56 7.76 7.93 8.08 8.22 8.34 8.45 8.58 8.67 8.76 8.84 8.91 8.99 9.05 9.12 9.18 9.24 9.30 9.35 9.40 9.45 9.50 9.55 9.59 9.63 9.68 9.72 9.75 9.79 9.83 9.87 9.90 9.94 9.98 10.0</IML>
      <discreteVulnerability vulnerabilityFunctionID="W1TIMBERMETAL" probabilisticDistribution="N">
        <lossRatio> 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.01 0.01 0.02 0.03 0.04 0.06 0.08 0.10 0.13 0.15 0.18 0.21 0.24 0.27 0.31 0.34 0.37 0.40 0.43 0.46 0.49 0.52 0.55 0.58 0.60 0.63 0.65 0.67 0.70 0.72 1.00</lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
      <discreteVulnerability vulnerabilityFunctionID="W1BVMETAL" probabilisticDistribution="N">
        <lossRatio> 0.00 0.04 0.15 0.25 0.34 0.42 0.49 0.55 0.60 0.64 0.67 0.71 0.73 0.76 0.78 0.80 0.81 0.83 0.84 0.85 0.87 0.87 0.88 0.89 0.90 0.91 0.91 0.92 0.92 0.93 0.93 0.94 0.94 0.94 0.95 0.95 0.95 0.95 0.96 0.96 1.00</lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
    </discreteVulnerabilitySet>
  </vulnerabilityModel>
</nrml>"""
        f = open(os.path.join(self.mmi.input_dir, 
                              '%s_vulnerability.xml' % self.mmi.site_tag), 'wb')
        f.write(self.mmi.raw_xml)
        f.close()
        
        self.mmi.sites_filename = os.path.join(self.mmi.input_dir,
                                           'sitedb_%s.csv' % self.mmi.site_tag)
        
        self.mmi.raw_csv = """BID,LATITUDE,LONGITUDE,STRUCTURE_CLASSIFICATION,STRUCTURE_CATEGORY,HAZUS_USAGE,SUBURB,POSTCODE,PRE1989,HAZUS_STRUCTURE_CLASSIFICATION,CONTENTS_COST_DENSITY,BUILDING_COST_DENSITY,FLOOR_AREA,SURVEY_FACTOR,FCB_USAGE,SITE_CLASS,
2,-6.4125,110.837502,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,344.4451,688.8903,150,9.8,, C, 
3,-6.4125,110.845833,W1BVMETAL, BUILDING,,TURNER,2612,,,430.5564,861.1128,480,1,, C, 
4,-6.4125,110.854164,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,1087.155,1087.155,300,1,, C, 
5,-6.4125,110.845833,W1BVMETAL, BUILDING,,TURNER,2612,,,430.5564,861.1128,480,1,, C, 
6,-6.4125,110.854164,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,1087.155,1087.155,300,1,, C, """
        f = open(self.mmi.sites_filename, 'wb')
        f.write(self.mmi.raw_csv)
        f.close()
        
        self.mmi.eqrm_flags = Dummy()
        self.mmi.eqrm_flags.site_tag = self.mmi.site_tag
        self.mmi.eqrm_flags.input_dir = self.mmi.input_dir
        self.mmi.eqrm_flags.vulnerability_variability_method = None
        
        self.mmi.sites = Structures_Vulnerability.from_csv(self.mmi.sites_filename, 
                                                       self.mmi.eqrm_flags)
        
        self.msg = 'Expected %s, got %s'
        
        
        #Now set up the object for testing PGA vulnerability files
        self.pga=imt()
        self.pga.site_tag = "test_site2"
        self.pga.input_dir = tempfile.mkdtemp()
        
        self.pga.raw_xml = """<?xml version="1.0"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.3" xmlns:gml="http://www.opengis.net/gml" gml:id="nrml">
  <vulnerabilityModel>
    <discreteVulnerabilitySet vulnerabilitySetID="HAZUS" assetCategory="buildings" lossCategory="economic_loss">
      <IML IMT="PGA"> 0.00 1.0 2.0 3.0 4.0</IML>
      <discreteVulnerability vulnerabilityFunctionID="W1TIMBERMETAL" probabilisticDistribution="N">
        <lossRatio> 0.00 0.02 0.04 0.06 0.08</lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
      <discreteVulnerability vulnerabilityFunctionID="W1BVMETAL" probabilisticDistribution="N">
        <lossRatio> 0.0 0.01 0.02 0.03 0.04 </lossRatio>
        <coefficientsVariation> 0.30 0.30 0.30 0.30 0.30</coefficientsVariation>
      </discreteVulnerability>
    </discreteVulnerabilitySet>
  </vulnerabilityModel>
</nrml>"""
        f = open(os.path.join(self.pga.input_dir, 
                              '%s_vulnerability.xml' % self.pga.site_tag), 'wb')
        f.write(self.pga.raw_xml)
        f.close()
        
        self.pga.sites_filename = os.path.join(self.pga.input_dir,
                                           'sitedb_%s.csv' % self.pga.site_tag)
        
        self.pga.raw_csv = """BID,LATITUDE,LONGITUDE,STRUCTURE_CLASSIFICATION,STRUCTURE_CATEGORY,HAZUS_USAGE,SUBURB,POSTCODE,PRE1989,HAZUS_STRUCTURE_CLASSIFICATION,CONTENTS_COST_DENSITY,BUILDING_COST_DENSITY,FLOOR_AREA,SURVEY_FACTOR,FCB_USAGE,SITE_CLASS,
2,-6.4125,110.837502,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,344.4451,688.8903,150,9.8,, C, 
3,-6.4125,110.845833,W1BVMETAL, BUILDING,,TURNER,2612,,,430.5564,861.1128,480,1,, C, 
4,-6.4125,110.854164,W1TIMBERMETAL, BUILDING,,TURNER,2612,,,1087.155,1087.155,300,1,, C, """
        f = open(self.pga.sites_filename, 'wb')
        f.write(self.pga.raw_csv)
        f.close()
        
        self.pga.eqrm_flags = Dummy()
        self.pga.eqrm_flags.site_tag = self.pga.site_tag
        self.pga.eqrm_flags.input_dir = self.pga.input_dir
        self.pga.eqrm_flags.vulnerability_variability_method = None
        
        self.pga.sites = Structures_Vulnerability.from_csv(self.pga.sites_filename, 
                                                       self.pga.eqrm_flags)
        
        self.msg = 'Expected %s, got %s'