def mergeNGAdata( nametrain='/Users/aklimasewski/Documents/data/cybertrainyeti10_residfeb.csv', nametest='/Users/aklimasewski/Documents/data/cybertestyeti10_residfeb.csv', filenamenga='/Users/aklimasewski/Documents/data/NGA_mag2_9.csv', n=13): from sklearn.model_selection import train_test_split train_data1, test_data1, train_targets1, test_targets1, feature_names = readindata( nametrain= '/Users/aklimasewski/Documents/data/cybertrainyeti10_residfeb.csv', nametest= '/Users/aklimasewski/Documents/data/cybertestyeti10_residfeb.csv', n=n) train_data1, test_data1, feature_names = add_az(train_data1, test_data1, feature_names) # filenamenga = '/Users/aklimasewski/Documents/data/NGA_mag2_9.csv' nga_data1, nga_targets1, feature_names = readindataNGA(filenamenga, n) nga_data1, feature_names = add_azNGA(filenamenga, nga_data1, feature_names) # ngatrain, ngatest, ngatrain_targets, ngatest_targets = train_test_split(nga_data1,nga_targets1, test_size=0.2, random_state=1) ngatrain, ngatest, ngatrain_targets, ngatest_targets, ngacells_train, ngacells_test = train_test_split( nga_data1, nga_targets1, cells_nga, test_size=0.2, random_state=1) train_data1 = np.concatenate([train_data1, ngatrain], axis=0) test_data1 = np.concatenate([test_data1, ngatest], axis=0) train_data1 = np.concatenate([train_data1, ngatrain], axis=0) test_data1 = np.concatenate([test_data1, ngatest], axis=0) train_targets1 = np.concatenate([train_targets1, ngatrain_targets], axis=0) test_targets1 = np.concatenate([test_targets1, ngatest_targets], axis=0) return train_data1, test_data1, train_targets1, test_targets1, feature_names
def mergeNGAdata( nametrain='/Users/aklimasewski/Documents/data/cybertrainyeti10_residfeb.csv', nametest='/Users/aklimasewski/Documents/data/cybertestyeti10_residfeb.csv', filenamenga='/Users/aklimasewski/Documents/data/NGA_mag2_9.csv', n=13): ''' Read in NGA data file, train test split and merge with cybershake data Parameters ---------- nametrain: path for cybershake training data csv nametest: path for cybershake testing data csv filenamenga: integer number of hidden layers n: number of model input features Returns ------- train_data1: numpy array of training features test_data1: numpy array of testing features train_targets1: numpy array of training features test_targets1: numpy array of testing features feature_names: numpy array feature names ''' from sklearn.model_selection import train_test_split train_data1, test_data1, train_targets1, test_targets1, feature_names = readindata( nametrain= '/Users/aklimasewski/Documents/data/cybertrainyeti10_residfeb.csv', nametest= '/Users/aklimasewski/Documents/data/cybertestyeti10_residfeb.csv', n=n) train_data1, test_data1, feature_names = add_az(train_data1, test_data1, feature_names) # filenamenga = '/Users/aklimasewski/Documents/data/NGA_mag2_9.csv' nga_data1, nga_targets1, feature_names = readindataNGA(filenamenga, n) nga_data1, feature_names = add_azNGA(filenamenga, nga_data1, feature_names) # ngatrain, ngatest, ngatrain_targets, ngatest_targets = train_test_split(nga_data1,nga_targets1, test_size=0.2, random_state=1) ngatrain, ngatest, ngatrain_targets, ngatest_targets = train_test_split( nga_data1, nga_targets1, test_size=0.2, random_state=1) train_data1 = np.concatenate([train_data1, ngatrain], axis=0) test_data1 = np.concatenate([test_data1, ngatest], axis=0) train_data1 = np.concatenate([train_data1, ngatrain], axis=0) test_data1 = np.concatenate([test_data1, ngatest], axis=0) train_targets1 = np.concatenate([train_targets1, ngatrain_targets], axis=0) test_targets1 = np.concatenate([test_targets1, ngatest_targets], axis=0) return train_data1, test_data1, train_targets1, test_targets1, feature_names
sns.set_context(context='talk', font_scale=0.7) # path of trained model files folder_path = '/Users/aklimasewski/Documents/model_results/base/ANNbase_nga_20ep_50hidden/' folder_pathNGA = folder_path + 'NGAtest/' if not os.path.exists(folder_pathNGA): os.makedirs(folder_pathNGA) n = 13 az = True transform_method = 'Norm' # compare to NGA data filenamenga = '/Users/aklimasewski/Documents/data/NGA_mag2_9.csv' nga_data1, nga_targets1, feature_names = readindataNGA(filenamenga, n) nga_data1, feature_names = add_azNGA(filenamenga, nga_data1, feature_names) # nga_data1,feature_names = add_locfeatNGA(filenamenga,nga_data1,feature_names) if az == True: nga_data1, feature_names = add_azNGA(nga_data1, feature_names) # read in cyber shake trainineg and testing data train_data1, test_data1, train_targets1, test_targets1, feature_names = readindata( nametrain= '/Users/aklimasewski/Documents/data/cybertrainyeti10_residfeb.csv', nametest='/Users/aklimasewski/Documents/data/cybertestyeti10_residfeb.csv', n=n) train_data1, test_data1, feature_names = add_az(train_data1, test_data1, feature_names)
def mergeNGAdata_cells( nametrain='/Users/aklimasewski/Documents/data/cybertrainyeti10_residfeb.csv', nametest='/Users/aklimasewski/Documents/data/cybertestyeti10_residfeb.csv', filenamenga='/Users/aklimasewski/Documents/data/NGA_mag2_9.csv', n=13): ''' Read in NGA data file, train test split and merge with cybershake data Parameters ---------- nametrain: path for cybershake training data csv nametest: path for cybershake testing data csv filenamenga: integer number of hidden layers n: number of model input features Returns ------- train_data1: numpy array of training features test_data1: numpy array of testing features train_targets1: numpy array of training features test_targets1: numpy array of testing features feature_names: numpy array feature names ''' from sklearn.model_selection import train_test_split cells = pd.read_csv(folder_path + 'gridpointslatlon_train.csv', header=0, index_col=0) cells_test = pd.read_csv(folder_path + 'gridpointslatlon_test.csv', header=0, index_col=0) cells_nga = pd.read_csv(folder_path + 'gridpointslatlon_nga.csv', header=0, index_col=0) train_data1, test_data1, train_targets1, test_targets1, feature_names = readindata( nametrain= '/Users/aklimasewski/Documents/data/cybertrainyeti10_residfeb.csv', nametest= '/Users/aklimasewski/Documents/data/cybertestyeti10_residfeb.csv', n=n) train_data1, test_data1, feature_names = add_az(train_data1, test_data1, feature_names) nga_data1, nga_targets1, feature_names = readindataNGA(filenamenga, n) nga_data1, feature_names = add_azNGA(filenamenga, nga_data1, feature_names) nga_data1 = np.concatenate([nga_data1, cells_nga], axis=0) ngatrain, ngatest, ngatrain_targets, ngatest_targets = train_test_split( nga_data1, nga_targets1, test_size=0.2, random_state=1) feature_names = np.concatenate([ feature_names, [ 'eventlat', 'eventlon', 'midlat', 'midlon', 'sitelat', 'sitelon', ] ], axis=0) train_data1 = np.concatenate([train_data1, cells], axis=1) test_data1 = np.concatenate([test_data1, cells_test], axis=1) train_data1 = np.concatenate([train_data1, ngatrain], axis=0) test_data1 = np.concatenate([test_data1, ngatest], axis=0) train_targets1 = np.concatenate([train_targets1, ngatrain_targets], axis=0) test_targets1 = np.concatenate([test_targets1, ngatest_targets], axis=0) return train_data1, test_data1, train_targets1, test_targets1, feature_names