def write_aggregate_read_struct(attribute_dic=None,
                       buildings_usage_classification='HAZUS'  ):
        handle, file_name = tempfile.mkstemp('.csv','test_aggregate_struct_')
        os.close(handle)
        file_name2delete, attribute_dic = write_test_file(
            file_name,attribute_dic)
        
        # Let's get the current dir position
        this_dir, tail = path.split( __file__)
        #print "eqrm_dir", eqrm_dir
        if this_dir == '':
            this_dir = '.'
        eqrm_dir = this_dir+sep+'..'

        attribute_conversions_extended = copy.deepcopy(attribute_conversions)
        attribute_conversions_extended['UFI'] = int
        aggregate_building_db(file_name)

        
        # Build lookup table for building parameters
        building_classification_tag = ''
        damage_extent_tag = ''
        
        default_input_dir = join(eqrm_dir,
                                 'resources','data','')
        sites=Structures.from_csv(
            file_name,
            building_classification_tag,
            damage_extent_tag,
            default_input_dir=default_input_dir,
            eqrm_dir=eqrm_dir,
             buildings_usage_classification=buildings_usage_classification
            )
        os.remove(file_name2delete)
        return  attribute_dic, sites
    def not_test_how_it_works(self):
        handle, file_name = tempfile.mkstemp('.csv','test_struct_')
        os.close(handle)
        file_name, attribute_dic = write_test_file(file_name)

        # Let's get the current dir position
        this_dir, tail = path.split( __file__)
        #print "eqrm_dir", eqrm_dir
        if this_dir == '':
            this_dir = '.'
        eqrm_dir = this_dir+sep+'..'
        data_dir = eqrm_dir+sep+'resources'+sep+'data'+sep
        #print "data_dir", data_dir

        ## Build lookup table for building parameters
        building_classification_tag = ''
        damage_extent_tag = ''
        
        sites=Structures.from_csv(
            file_name,
            building_classification_tag,
            damage_extent_tag,
            eqrm_dir
            )
        os.remove(file_name)
Ejemplo n.º 3
0
def write_aggregate_read_struct(attribute_dic=None, buildings_usage_classification="HAZUS"):
    handle, file_name = tempfile.mkstemp(".csv", "test_aggregate_struct_")
    os.close(handle)
    file_name2delete, attribute_dic = write_test_file(file_name, attribute_dic)

    # Let's get the current dir position
    this_dir, tail = path.split(__file__)
    # print "eqrm_dir", eqrm_dir
    if this_dir == "":
        this_dir = "."
    eqrm_dir = this_dir + sep + ".."

    attribute_conversions_extended = copy.deepcopy(attribute_conversions)
    attribute_conversions_extended["UFI"] = int
    aggregate_building_db(file_name)

    # Build lookup table for building parameters
    building_classification_tag = ""
    damage_extent_tag = ""

    default_input_dir = join(eqrm_dir, "resources", "data", "")
    sites = Structures.from_csv(
        file_name,
        building_classification_tag,
        damage_extent_tag,
        default_input_dir=default_input_dir,
        eqrm_dir=eqrm_dir,
        buildings_usage_classification=buildings_usage_classification,
    )
    os.remove(file_name2delete)
    return attribute_dic, sites
Ejemplo n.º 4
0
def write_aggregate_read_struct(attribute_dic=None,
                                buildings_usage_classification='HAZUS'):
    handle, file_name = tempfile.mkstemp('.csv', 'test_aggregate_struct_')
    os.close(handle)
    file_name2delete, attribute_dic = write_test_file(file_name, attribute_dic)

    # Let's get the current dir position
    this_dir, tail = path.split(__file__)
    #print "eqrm_dir", eqrm_dir
    if this_dir == '':
        this_dir = '.'
    eqrm_dir = this_dir + sep + '..'

    attribute_conversions_extended = copy.deepcopy(attribute_conversions)
    attribute_conversions_extended['UFI'] = int
    aggregate_building_db(file_name)

    # Build lookup table for building parameters
    building_classification_tag = ''
    damage_extent_tag = ''

    default_input_dir = join(eqrm_dir, 'resources', 'data', '')
    sites = Structures.from_csv(
        file_name,
        building_classification_tag,
        damage_extent_tag,
        default_input_dir=default_input_dir,
        eqrm_dir=eqrm_dir,
        buildings_usage_classification=buildings_usage_classification)
    os.remove(file_name2delete)
    return attribute_dic, sites
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def not_test_how_it_works(self):
        handle, file_name = tempfile.mkstemp('.csv', 'test_struct_')
        os.close(handle)
        file_name, attribute_dic = write_test_file(file_name)

        # Let's get the current dir position
        this_dir, tail = path.split(__file__)
        #print "eqrm_dir", eqrm_dir
        if this_dir == '':
            this_dir = '.'
        eqrm_dir = this_dir + sep + '..'
        data_dir = eqrm_dir + sep + 'resources' + sep + 'data' + sep
        #print "data_dir", data_dir

        # Build lookup table for building parameters
        building_classification_tag = ''
        damage_extent_tag = ''

        sites = Structures.from_csv(file_name, building_classification_tag,
                                    damage_extent_tag, eqrm_dir)
        os.remove(file_name)
Ejemplo n.º 7
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)