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)
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 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 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 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)
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)
def test_calc_total_loss_OS_bug_search(self): blocking_block_comments = True """plugging in results from TS_risk57.par""" SA =array([[[0.14210731, 0.29123634, 0.23670422, 0.13234554, 0.08648546, 0.06338455, 0.04945741, 0.04140068, 0.03497466, 0.02969136, 0.02525473, 0.02151188, 0.018371, 0.01571802, 0.01344816, 0.01148438, 0.00980236, 0.00836594, 0.00714065, 0.00609482], [0.2093217, 0.30976405, 0.16232743, 0.06989206, 0.03216174, 0.01945677, 0.01347719, 0.00987403, 0.00799221, 0.00660128, 0.00547129, 0.0045463, 0.0042072, 0.00418348, 0.0041599, 0.00413222, 0.00410333, 0.00407463, 0.00404614, 0.00401785], [0.01450217, 0.02750284, 0.02231209, 0.01127933, 0.00793098, 0.00621618, 0.0051103, 0.00430777, 0.00364714, 0.0031542, 0.00279411, 0.00247654, 0.0022153, 0.001994, 0.0017948, 0.00161223, 0.00144737, 0.00129929, 0.00117312, 0.00105988]]]) event_set = array([6.0201519, 6.0201519, 6.0201519]) eqrm_flags = Dummy() eqrm_flags.csm_variability_method = 3 eqrm_flags.atten_periods = array([0., 0.17544,0.35088, 0.52632, 0.70175, 0.87719, 1.0526, 1.2281, 1.4035, 1.5789, 1.7544, 1.9298, 2.1053, 2.2807, 2.4561, 2.6316, 2.807, 2.9825, 3.1579, 3.3333 ]) eqrm_flags.csm_use_variability = True eqrm_flags.csm_standard_deviation = 0.3 eqrm_flags.csm_damping_regimes = CSM_DAMPING_REGIMES_USE_ALL eqrm_flags.csm_damping_modify_Tav = CSM_DAMPING_MODIFY_TAV eqrm_flags.csm_damping_use_smoothing = CSM_DAMPING_USE_SMOOTHING eqrm_flags.csm_SDcr_tolerance_percentage = 1 eqrm_flags.csm_damping_max_iterations = 7 eqrm_flags.csm_hysteretic_damping = 'trapezoidal' eqrm_flags.bridges_functional_percentages = None eqrm_flags.atten_override_RSA_shape = None eqrm_flags.atten_pga_scaling_cutoff = False eqrm_flags.atten_cutoff_max_spectral_displacement = False eqrm_flags.loss_min_pga = 0.05 eqrm_flags.loss_regional_cost_index_multiplier = 1.4516 eqrm_flags.loss_aus_contents = 0 building_parameters = {'residential_drift_threshold': array([[21.9456, 43.8912, 109.728 ,164.592]]), 'structure_class': array(['BUILDING'], dtype='|S8'), 'height': array([7315.2]), 'nsd_a_ratio': array([0.7254902]), 'design_strength': array([0.033]), 'non_residential_drift_threshold': array([[5.4864, 43.8912, 82.296, 137.16]]), 'damping_Be': array([0.1]), 'fraction_in_first_mode': array([0.8]), 'ultimate_to_yield': array([3.]), 'acceleration_threshold': array([[0.2, 0.4, 0.8, 1.6]]), 'nsd_d_ratio': array([0.11764706]), 'structure_ratio': array([0.15686275]), 'structural_damage_threshold': array([[26.33472, 41.69664, 88.87968, 219.456]]), 'natural_elastic_period': array([0.5]), 'damping_s': array([0.4]), 'drift_threshold': array([[5.4864, 43.8912, 82.296, 137.16]]), 'yield_to_design': array([1.5]), 'structure_classification': array(['S1L'], dtype='|S13'), 'height_to_displacement': array([0.75]), 'ductility': array([5.]), 'damping_l': array([0.]), 'damping_m': array([0.2])} # Note, this lats and longs are wrong sites = Structures(latitude=[-31],longitude=[150], building_parameters=building_parameters) sites.attributes = {'FCB_USAGE': array([311]), 'SURVEY_FACTOR': array([1.]), 'HAZUS_STRUCTURE_CLASSIFICATION': array(['S1L'], dtype='|S4'), 'SITE_CLASS': array(['D'], dtype='|S1'), 'FLOOR_AREA': array([3000.]), 'CONTENTS_COST_DENSITY': array([823.4392]), 'STRUCTURE_CATEGORY': array(['BUILDING'], dtype='|S8'), 'STRUCTURE_CLASSIFICATION': array(['S1L'], dtype='|S13'), 'SUBURB': array(['LAMBTON'], dtype='|S19'), 'HAZUS_USAGE': array(['IND3'], dtype='|S4'), 'POSTCODE': array([2299]), 'BUILDING_COST_DENSITY': array([548.9594]), 'BID': array([3562]), 'PRE1989': array([0])} reset_seed(True) total_loss, _ = sites.calc_total_loss(SA, eqrm_flags, event_set) total_loss_windows = (array([[5.56013748, 0.00899564, 0.]]), array([[4059.31954558, 1473.71938878, 0.]]), array([[9423.06584855, 1181.40856505, 0.]]), array([[9978.48421213, 1226.05473008, 0.]])) assert allclose(asarray(total_loss), asarray(total_loss_windows))
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)
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]]])