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 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]]])
    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 #4
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]]])