Example #1
0
    def test_cadel_ground_motion(self):

        eqrm_dir = determine_eqrm_path()
        cadel_dir = join(eqrm_dir, "..", "test_cadell", "Cadell")
        natcadell_loc = join(cadel_dir, "natcadell.csv")

        # Silently return from the test if the data set does not exist.
        # The data is in python_eqrm
        if not exists(natcadell_loc):
            return
        default_input_dir = join(eqrm_dir, "resources", "data", "")
        sites = Structures.from_csv(
            natcadell_loc, "", "", default_input_dir, eqrm_dir=eqrm_dir, buildings_usage_classification="FCB"
        )

        magnitudes = array([7.2])

        cadell_periods_loc = join(cadel_dir, "Cadell_periods.csv")
        periods = csv.reader(open(cadell_periods_loc)).next()
        periods = array([float(v) for v in periods])
        num_periods = len(periods)
        num_sites = len(sites.latitude)

        assert allclose(periods, [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5])

        cadell_gm_loc = join(cadel_dir, "Cadell_ground_motions_precision.csv")
        SA = self.ground_motions_from_csv(cadell_gm_loc, num_periods, num_sites)
        # SA = SA[0:1,...]

        # set up damage model
        csm_use_variability = None
        csm_standard_deviation = None
        damage_model = Damage_model(sites, SA, periods, magnitudes, csm_use_variability, csm_standard_deviation)
        damage_model.csm_use_variability = False
        damage_model.csm_standard_deviation = 0.3

        point = damage_model.get_building_displacement()
        # point is SA,SD

        # SA should by of shape
        # (number of buildings,number of events,number of samples).
        # print point[0].shape

        # check that SA is the right shape
        assert point[0].shape == (num_sites, 1)

        # check that SD is the same shape as SA
        assert point[1].shape == point[0].shape

        point = (point[0][..., 0], point[1][..., 0])
        # collapse out sample dimension so it matches the shape of matlab

        cadell_bd_loc = join(cadel_dir, "Cadell_building_displacements.csv")
        matlab_point = open(cadell_bd_loc)
        matlab_point = array([[float(p) for p in mpoint.split(",")] for mpoint in matlab_point])
        matlab_point = (matlab_point[:, 1], matlab_point[:, 0])
        assert allclose(point, matlab_point, 5e-3)
        assert allclose(point, matlab_point, 1e-2)
        # check that we are 1% of matlabs SA and SD
        assert allclose(point, matlab_point, 5e-3)
Example #2
0
    def calc_total_loss(self, SA, eqrm_flags, event_set_Mw):
        """
        Calculate the economic loss and damage state at a site.

        eqrm_flags        high level controlling object
        SA                 array of Spectral Acceleration, in g, with axis;
                               sites, events, periods
                           the site axis usually has a size of 1
        event_set_Mw       array of Mw, 1D, dimension (events)
                           (used only by buildings)

        Returns a tuple (total_loss, damage_model) where:
          total_loss    a 4 long list of dollar loss.  The loss categories are;
                        (structure_loss, nsd_loss, accel_loss, contents_loss)
                        These dollar losses have the dimensions of;
                        (site, event)
          damage_model  an instance of the damage model.
                        used in risk.py to get damage states.
        """
        # note: damage_model has an object called capacity_spectrum_model
        #       buried inside, which will now calculate capacity curves
        #       parameters
        # csm_params are parameters for the capacity_spectrum_model
        csm_params = {
            'csm_damping_regimes': eqrm_flags.csm_damping_regimes,
            'csm_damping_modify_Tav': eqrm_flags.csm_damping_modify_Tav,
            'csm_damping_use_smoothing': eqrm_flags.csm_damping_use_smoothing,
            'rtol': eqrm_flags.csm_SDcr_tolerance_percentage / 100.0,
            'csm_damping_max_iterations':
            eqrm_flags.csm_damping_max_iterations,
            'sdtcap':  # FIXME sdt -> std
            eqrm_flags.csm_standard_deviation,
            'csm_use_variability': eqrm_flags.csm_use_variability,
            'csm_variability_method': eqrm_flags.csm_variability_method,
            'csm_hysteretic_damping': eqrm_flags.csm_hysteretic_damping,
            'atten_override_RSA_shape': eqrm_flags.atten_override_RSA_shape,
            'atten_cutoff_max_spectral_displacement':
            eqrm_flags.atten_cutoff_max_spectral_displacement,
            'loss_min_pga': eqrm_flags.loss_min_pga
        }

        damage_model = Damage_model(self,
                                    SA,
                                    eqrm_flags.atten_periods,
                                    event_set_Mw,
                                    eqrm_flags.csm_use_variability,
                                    float(eqrm_flags.csm_standard_deviation),
                                    csm_params=csm_params)

        # Note, aggregate slight, medium, critical damage
        # Compute building damage and loss (LOTS done here!)
        total_loss = \
            damage_model.aggregated_building_loss(
                ci=eqrm_flags.loss_regional_cost_index_multiplier,
                loss_aus_contents=eqrm_flags.loss_aus_contents)

        return (total_loss, damage_model)
Example #3
0
    def test_building_response(self):
        #Test that building response is the same as matlab

        periods=array([0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5,
                       0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7,
                       1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9,
                       3])

        SA = array([0.017553049, 0.028380350, 0.036142210, 0.037701113,
                    0.039325398, 0.038083417, 0.036880517, 0.036190107,
                    0.035512489, 0.035088679, 0.034669917, 0.033162774,
                    0.030871523, 0.027841184, 0.025094836, 0.022850476,
                    0.021322256, 0.019895084, 0.018562342, 0.017317833,
                    0.016160874, 0.015195155, 0.014287144, 0.013433394,
                    0.012630662, 0.011875899, 0.011166239, 0.010498986,
                    0.009871606, 0.009281717, 0.008727078, 0.008140645,
                    0.007593619, 0.007083352, 0.006607374, 0.006163380])

        SA = SA[newaxis, newaxis, :]

        magnitudes = array([6.5])

        Btype = 'RM2L'

        eqrm_dir = determine_eqrm_path()
        default_input_dir = join(eqrm_dir, 'resources', 'data', '')
        building_parameters = \
            building_params_from_csv(building_classification_tag = '',
                                     damage_extent_tag = '',
                                     default_input_dir=default_input_dir)

        # Pull the parameters out:
        b_index = where([(bt == Btype) for bt in
                             building_parameters['structure_classification']])
        new_bp = {}
        for key in building_parameters:
            try:
                new_bp[key] = building_parameters[key][b_index]
            except:
                new_bp[key] = building_parameters[key]

        structures = Structures(latitude=[-31], longitude=[150],
                                building_parameters=new_bp,
                                #bridge_parameters={},
                                FCB_USAGE=array([111]),
                                STRUCTURE_CLASSIFICATION=array([Btype]),
                                STRUCTURE_CATEGORY=array(['BUILDING']))
        building_parameters = structures.building_parameters

        # All the same for this type anyway
        csm_use_variability = None
        csm_standard_deviation = None
        damage_model = Damage_model(structures, SA, periods, magnitudes,
                                    csm_use_variability, csm_standard_deviation)

        # set up the capacity model
        capacity_spectrum_model = Capacity_spectrum_model(periods, magnitudes,
                                                          building_parameters)

        capacity_spectrum_model.smooth_damping = True
        capacity_spectrum_model.use_displacement_corner_period = True
        capacity_spectrum_model.damp_corner_periods = True
        capacity_spectrum_model.use_exact_area = True
        capacity_spectrum_model.rtol = 0.01
        capacity_spectrum_model.csm_damping_max_iterations = 7

        ###########################################################

        damage_model.capacity_spectrum_model = capacity_spectrum_model

        # Warning, point is not used
        point = damage_model.get_building_displacement()

        # matlab values
        SAcr = 0.032208873
        SDcr = 0.97944026
        assert allclose(point[0], SAcr)
        assert allclose(point[1], SDcr)
        assert allclose(point, [[[SAcr]], [[SDcr]]])
Example #4
0
    def calc_total_loss(self, SA, eqrm_flags, event_set_Mw):
        """
        Calculate the economic loss and damage state at a site.

        eqrm_flags        high level controlling object
        SA                 array of Spectral Acceleration, in g, with axis;
                               sites, events, periods
                           the site axis usually has a size of 1
        event_set_Mw       array of Mw, 1D, dimension (events)
                           (used only by buildings)

        Returns a tuple (total_loss, damage_model) where:
          total_loss    a 4 long list of dollar loss.  The loss categories are;
                        (structure_loss, nsd_loss, accel_loss, contents_loss)
                        These dollar losses have the dimensions of;
                        (site, event)
          damage_model  an instance of the damage model.
                        used in risk.py to get damage states.
        """
        # note: damage_model has an object called capacity_spectrum_model
        #       buried inside, which will now calculate capacity curves
        #       parameters
        # csm_params are parameters for the capacity_spectrum_model
        csm_params = {'csm_damping_regimes':
                      eqrm_flags.csm_damping_regimes,
                      'csm_damping_modify_Tav':
                      eqrm_flags.csm_damping_modify_Tav,
                      'csm_damping_use_smoothing':
                      eqrm_flags.csm_damping_use_smoothing,
                      'rtol':
                      eqrm_flags.csm_SDcr_tolerance_percentage / 100.0,
                      'csm_damping_max_iterations':
                      eqrm_flags.csm_damping_max_iterations,
                      'sdtcap':  # FIXME sdt -> std
                      eqrm_flags.csm_standard_deviation,
                      'csm_use_variability':
                      eqrm_flags.csm_use_variability,
                      'csm_variability_method':
                      eqrm_flags.csm_variability_method,
                      'csm_hysteretic_damping':
                      eqrm_flags.csm_hysteretic_damping,
                      'atten_override_RSA_shape':
                      eqrm_flags.atten_override_RSA_shape,
                      'atten_cutoff_max_spectral_displacement':
                      eqrm_flags.atten_cutoff_max_spectral_displacement,
                      'loss_min_pga': eqrm_flags.loss_min_pga}

        damage_model = Damage_model(self, SA, eqrm_flags.atten_periods,
                                    event_set_Mw,
                                    eqrm_flags.csm_use_variability,
                                    float(eqrm_flags.csm_standard_deviation),
                                    csm_params=csm_params)

        # Note, aggregate slight, medium, critical damage
        # Compute building damage and loss (LOTS done here!)
        total_loss = \
            damage_model.aggregated_building_loss(
                ci=eqrm_flags.loss_regional_cost_index_multiplier,
                loss_aus_contents=eqrm_flags.loss_aus_contents)

        return (total_loss, damage_model)
    def test_cadel_ground_motion(self):   
        
        eqrm_dir = determine_eqrm_path()
        cadel_dir = join(eqrm_dir,'..','test_cadell', 'Cadell')
        natcadell_loc = join(cadel_dir, 'natcadell.csv')

        # Silently return from the test if the data set does not exist.
        # The data is in python_eqrm
        if not exists(natcadell_loc):
            return
        default_input_dir = join(eqrm_dir,'resources',
                                 'data', '')
        sites=Structures.from_csv(natcadell_loc,
                                  '',
                                  '',
                                  default_input_dir,
                                  eqrm_dir=eqrm_dir,
                                  buildings_usage_classification='FCB')

        magnitudes=array([7.2])                     

        cadell_periods_loc = join(cadel_dir, 'Cadell_periods.csv')
        periods=csv.reader(open(cadell_periods_loc)).next()
        periods=array([float(v) for v in periods])
        num_periods=len(periods)
        num_sites=len(sites.latitude)

        assert allclose(periods,[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,
                                 0.9,1,1.5,2,2.5,3,3.5,4,4.5,5])
        
        cadell_gm_loc = join(cadel_dir, 'Cadell_ground_motions_precision.csv')
        SA=self.ground_motions_from_csv(cadell_gm_loc,
            num_periods,num_sites)
        #SA = SA[0:1,...]

        # set up damage model
        csm_use_variability = None
        csm_standard_deviation = None
        damage_model=Damage_model(sites,SA,periods,magnitudes,
                 csm_use_variability, csm_standard_deviation)
        damage_model.csm_use_variability=False
        damage_model.csm_standard_deviation=0.3
        
        point=damage_model.get_building_displacement()
        # point is SA,SD 
        
        # SA should by of shape
        # (number of buildings,number of events,number of samples).
        # print point[0].shape

        # check that SA is the right shape
        assert point[0].shape==(num_sites,1)
        
        # check that SD is the same shape as SA
        assert point[1].shape== point[0].shape 

        point = (point[0][...,0],point[1][...,0])
        #collapse out sample dimension so it matches the shape of matlab
     
        cadell_bd_loc = join(cadel_dir, 'Cadell_building_displacements.csv')
        matlab_point=open(cadell_bd_loc)
        matlab_point=array([[float(p) for p in mpoint.split(',')]
                            for mpoint in matlab_point])        
        matlab_point=(matlab_point[:,1],matlab_point[:,0])
        assert allclose(point,matlab_point,5e-3)
        assert allclose(point,matlab_point,1e-2)
        # check that we are 1% of matlabs SA and SD
        assert allclose(point,matlab_point,5e-3)
Example #6
0
    def test_building_response(self):
        #Test that building response is the same as matlab

        periods=array([0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5,
                       0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7,
                       1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9,
                       3])

        SA = array([0.017553049, 0.028380350, 0.036142210, 0.037701113,
                    0.039325398, 0.038083417, 0.036880517, 0.036190107,
                    0.035512489, 0.035088679, 0.034669917, 0.033162774,
                    0.030871523, 0.027841184, 0.025094836, 0.022850476,
                    0.021322256, 0.019895084, 0.018562342, 0.017317833,
                    0.016160874, 0.015195155, 0.014287144, 0.013433394,
                    0.012630662, 0.011875899, 0.011166239, 0.010498986,
                    0.009871606, 0.009281717, 0.008727078, 0.008140645,
                    0.007593619, 0.007083352, 0.006607374, 0.006163380])

        SA = SA[newaxis, newaxis, :]

        magnitudes = array([6.5])

        Btype = 'RM2L'

        eqrm_dir = determine_eqrm_path()
        default_input_dir = join(eqrm_dir, 'resources', 'data', '')
        building_parameters = \
            building_params_from_csv(building_classification_tag = '',
                                     damage_extent_tag = '',
                                     default_input_dir=default_input_dir)

        # Pull the parameters out:
        b_index = where([(bt == Btype) for bt in
                             building_parameters['structure_classification']])
        new_bp = {}
        for key in building_parameters:
            try:
                new_bp[key] = building_parameters[key][b_index]
            except:
                new_bp[key] = building_parameters[key]

        structures = Structures(latitude=[-31], longitude=[150],
                                building_parameters=new_bp,
                                #bridge_parameters={},
                                FCB_USAGE=array([111]),
                                STRUCTURE_CLASSIFICATION=array([Btype]),
                                STRUCTURE_CATEGORY=array(['BUILDING']))
        building_parameters = structures.building_parameters

        # All the same for this type anyway
        csm_use_variability = None
        csm_standard_deviation = None
        damage_model = Damage_model(structures, SA, periods, magnitudes,
                                    csm_use_variability, csm_standard_deviation)

        # set up the capacity model
        capacity_spectrum_model = Capacity_spectrum_model(periods, magnitudes,
                                                          building_parameters)

        capacity_spectrum_model.smooth_damping = True
        capacity_spectrum_model.use_displacement_corner_period = True
        capacity_spectrum_model.damp_corner_periods = True
        capacity_spectrum_model.use_exact_area = True
        capacity_spectrum_model.rtol = 0.01
        capacity_spectrum_model.csm_damping_max_iterations = 7

        ###########################################################

        damage_model.capacity_spectrum_model = capacity_spectrum_model

        # Warning, point is not used
        point = damage_model.get_building_displacement()

        # matlab values
        SAcr = 0.032208873
        SDcr = 0.97944026
        assert allclose(point[0], SAcr)
        assert allclose(point[1], SDcr)
        assert allclose(point, [[[SAcr]], [[SDcr]]])