def loadSingleGmMap(rupt_name):
    #Load station rot dict
    station_rot_dict = pdx.loadRotStationDict('rot_station_dict.csv')

    #Get grid size
    x_grid_max = np.max(np.asarray(list(station_rot_dict.values()))[:, 0])
    y_grid_max = np.max(np.asarray(list(station_rot_dict.values()))[:, 1])

    #Name of IM to save
    IM_name = ['PGA', 'PGV', 'AI', 'pSA_0.5', 'pSA_1.0', 'pSA_3.0']

    #Ensure IM IDs are well sorted
    lbl_IM = pdx.loadGM_CS(rupt_name)[0]
    IM_pos = []
    for i in range(len(lbl_IM)):
        for j in range(len(IM_name)):
            if IM_name[j] == lbl_IM[i]:
                IM_pos.append(i)
                break

    #Initialize array
    GM = np.ones((x_grid_max, y_grid_max, len(IM_name)))
    for i in range(len(IM_name)):
        if IM_name[i] == 'PGV':
            GM[:, :, i] = GM[:, :, i] * (0.25)
        elif IM_name[i] == 'AI':
            GM[:, :, i] = GM[:, :, i] * (-2.)
        elif IM_name[i] == 'pSA_3.0':
            GM[:, :, i] = GM[:, :, i] * (-6.)
        else:
            GM[:, :, i] = GM[:, :, i] * (-5.)

    #Load data
    GM_i = pdx.loadGM_CS(rupt_name)
    unfoundStation = []
    for j in range(1, len(GM_i)):
        for k in range(len(IM_pos)):
            try:
                GM[station_rot_dict[GM_i[j][0]][0],
                   station_rot_dict[GM_i[j][0]][1],
                   k] = np.log(GM_i[j][IM_pos[k]])
            except:
                unfoundStation.append(GM_i[j][0])

    GM = np.transpose(GM, (1, 0, 2))
    '''
	print(unfoundStation)
	print(len(unfoundStation))
	'''

    return GM
def loadGM_1D(str_rupt, realID, IM_ID):
    #Load GM
    GM = pdx.loadGM_CS(str_rupt)

    #Populate matrix
    GM_prep = np.ones((len(realID))) * (-8.0)
    for i in range(len(GM)):
        GM_prep[int(realID[GM[i][0]])] = np.log(GM[i][IM_ID])

    return GM_prep
예제 #3
0
#Initialize dictionary of used stations
station_virt_dict = {}

#Folder and file names
dir_path = './data/'
if not os.path.exists(dir_path):
    os.mkdir(dir_path)

#Initialize list of unfound faults
unfoundFault = []

for i in range(len(rupt_lbl)):
    #Load current GM
    str_GM = './raw_data/' + rupt_lbl[i] + '.csv'
    try:
        GM = pdx.loadGM_CS(str_GM)

        #Remove all non-geometric mean lines
        for j in range(len(GM) - 1, 0, -1):
            if not GM[j][1] == 'geom':
                del GM[j]

        #Add station location
        GM_save = [[GM[0][0], 'easting', 'northing']]
        for j in range(len(GM[0]) - 2):
            GM_save[0].append(GM[0][j + 2])

        for j in range(1, len(GM)):
            GM_save.append(
                [GM[j][0], station_CS[GM[j][0]][0], station_CS[GM[j][0]][1]])
            for k in range(len(GM[j]) - 2):
#Initialize array
GM = np.ones((n_file, x_grid_max, y_grid_max, len(IM_name)))
for i in range(len(IM_name)):
    if IM_name[i] == 'PGV':
        GM[:, :, :, i] = GM[:, :, :, i] * (0.25)
    elif IM_name[i] == 'AI':
        GM[:, :, :, i] = GM[:, :, :, i] * (-2.)
    elif IM_name[i] == 'pSA_3.0':
        GM[:, :, :, i] = GM[:, :, :, i] * (-6.)
    else:
        GM[:, :, :, i] = GM[:, :, :, i] * (-5.)
GM_name = []
GM_lbl = []

#Get IM position given names
lbl_IM = pdx.loadGM_CS(file_name[i])[0]
IM_pos = []
for i in range(len(lbl_IM)):
    for j in range(len(IM_name)):
        if IM_name[j] == lbl_IM[i]:
            IM_pos.append(i)
            break

#Treat map one after another (memory efficiency)
unfoundStation = []
for i in range(n_file):
    GM_i = pdx.loadGM_CS(file_name[i])
    for j in range(1, len(GM_i)):
        for k in range(len(IM_pos)):
            try:
                GM[i, station_rot_dict2[GM_i[j][0]][0],