From 69b66444e9940bf88fe1d4252a7b15710346f1ed Mon Sep 17 00:00:00 2001 From: Tara Evaz Zadeh Date: Wed, 19 Aug 2020 19:48:57 +0430 Subject: [PATCH 1/4] Added a new file --- Get_Full_GMFs.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Get_Full_GMFs.py diff --git a/Get_Full_GMFs.py b/Get_Full_GMFs.py new file mode 100644 index 0000000..d2f6b6d --- /dev/null +++ b/Get_Full_GMFs.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +#This function does a 2-dimensional interpolation. + + ################################# INPUTS: shakemapFile,lons,lats ################################# +#lons : Column of longitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) +#lats : Column of latitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) +#ShakemapFile: Numpy nd-array of the file with headers of X,Y,value_1,value_2....value_n ; This file must contain longitude values as the first column, latitude values as the second column and ground motion values as the 3rd. (type : m*n numpy-ndarray with shape of (a, n)) +# Please note that if there are more than 3 columns, This function will do interpolation multiple times and each time using (X,Y,value) (value changes in range of value_1 to value_n each time up to last column). + + ################################# OUTPUTS: shakemapFile,lons,lats ################################# +#Complete_shakemap : a numpy-ndarray + + #TODO : #add titles of the result in SDC + + + +def Get_Full_GMFs(shakemapFile,lons,lats): + + import pandas as pd + from scipy import interpolate + import numpy as np + from csv import writer + import csv + import os + from scipy.interpolate import griddata + + #### Defining the Inputs ### + shake_lons = shakemapFile[:,0] + shake_lats = shakemapFile[:,1] + points_given = np.vstack((shake_lons,shake_lats)).transpose() + points_todo = np.vstack((lons,lats)).transpose() + Complete_shakemap = np.vstack((np.array(lons),np.array(lats))).transpose() + + ############# Griddata Interpolation ##################### + ##### This for loop changes the value_n column so that the interpolation over lons and lats is done each time using one of the columns (3rd column to the last one and ) + for colmn in range(2,shakemapFile.shape[1],1): + shake_gmvs = shakemapFile[:,colmn] + print(shake_gmvs) + gm_value_griddata = griddata(points_given,shake_gmvs,points_todo, method='linear') + Complete_shakemap = np.column_stack((Complete_shakemap,gm_value_griddata)) + + return(Complete_shakemap) + + -- GitLab From 4feb11b019a601ab625a5bdb589780c0c091c3f5 Mon Sep 17 00:00:00 2001 From: Tara Evaz Zadeh Date: Wed, 19 Aug 2020 23:58:00 +0430 Subject: [PATCH 2/4] Edited a file --- Get_Full_GMFs.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/Get_Full_GMFs.py b/Get_Full_GMFs.py index d2f6b6d..efbc589 100644 --- a/Get_Full_GMFs.py +++ b/Get_Full_GMFs.py @@ -1,44 +1,35 @@ #!/usr/bin/env python #This function does a 2-dimensional interpolation. - ################################# INPUTS: shakemapFile,lons,lats ################################# +#INPUTS: groundMotionField,lons,lats #lons : Column of longitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) #lats : Column of latitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) -#ShakemapFile: Numpy nd-array of the file with headers of X,Y,value_1,value_2....value_n ; This file must contain longitude values as the first column, latitude values as the second column and ground motion values as the 3rd. (type : m*n numpy-ndarray with shape of (a, n)) +#groundMotionField: Numpy nd-array of the file with headers of X,Y,value_1,value_2....value_n ; This file must contain longitude values as the first column, latitude values as the second column and ground motion values as the 3rd. (type : m*n numpy-ndarray with shape of (a, n)) # Please note that if there are more than 3 columns, This function will do interpolation multiple times and each time using (X,Y,value) (value changes in range of value_1 to value_n each time up to last column). - ################################# OUTPUTS: shakemapFile,lons,lats ################################# +#OUTPUTS: groundMotionField,lons,lats #Complete_shakemap : a numpy-ndarray - #TODO : #add titles of the result in SDC - - -def Get_Full_GMFs(shakemapFile,lons,lats): +def Get_Full_GMF(groundMotionField,lons,lats): import pandas as pd - from scipy import interpolate import numpy as np - from csv import writer - import csv - import os from scipy.interpolate import griddata - #### Defining the Inputs ### - shake_lons = shakemapFile[:,0] - shake_lats = shakemapFile[:,1] - points_given = np.vstack((shake_lons,shake_lats)).transpose() + # Defining the Inputs + points_given = np.vstack((groundMotionField[:,0],groundMotionField[:,1])).transpose() points_todo = np.vstack((lons,lats)).transpose() Complete_shakemap = np.vstack((np.array(lons),np.array(lats))).transpose() - ############# Griddata Interpolation ##################### - ##### This for loop changes the value_n column so that the interpolation over lons and lats is done each time using one of the columns (3rd column to the last one and ) - for colmn in range(2,shakemapFile.shape[1],1): - shake_gmvs = shakemapFile[:,colmn] - print(shake_gmvs) + # Griddata Interpolation + # The for loop changes over the different columns of the ground motion field that contain ground-motion-values one by one. + #This enables us to have interpolation for all different different given ground motion types. + for gmType in range(2,groundMotionField.shape[1],1): + shake_gmvs = groundMotionField[:,gmType] gm_value_griddata = griddata(points_given,shake_gmvs,points_todo, method='linear') - Complete_shakemap = np.column_stack((Complete_shakemap,gm_value_griddata)) + fullGroundMotionField = np.column_stack((fullGroundMotionField,gm_value_griddata)) - return(Complete_shakemap) + return(fullGroundMotionField) -- GitLab From eb84ff27d99b9af86f25dca4f9086ccb438fa573 Mon Sep 17 00:00:00 2001 From: Tara Evaz Zadeh Date: Sat, 22 Aug 2020 15:22:52 +0430 Subject: [PATCH 3/4] Resolved threads from Danijel on the Get_Full_GMFs.py --- Get_Full_GMFs.py | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/Get_Full_GMFs.py b/Get_Full_GMFs.py index efbc589..9b6854d 100644 --- a/Get_Full_GMFs.py +++ b/Get_Full_GMFs.py @@ -1,35 +1,39 @@ #!/usr/bin/env python -#This function does a 2-dimensional interpolation. + +def Get_Full_GMF(groundMotionField,lons,lats): + +# Goal : This function does a 2-dimensional interpolation. -#INPUTS: groundMotionField,lons,lats -#lons : Column of longitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) -#lats : Column of latitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) -#groundMotionField: Numpy nd-array of the file with headers of X,Y,value_1,value_2....value_n ; This file must contain longitude values as the first column, latitude values as the second column and ground motion values as the 3rd. (type : m*n numpy-ndarray with shape of (a, n)) +# INPUTS: groundMotionField,lons,lats +# lons : Column of longitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) +# lats : Column of latitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) +# groundMotionField: Numpy nd-array of the file with headers of X,Y,value_1,value_2....value_n ; This file must contain longitude values as the first column, latitude values as the second column and ground motion values as the 3rd. (type : m*n numpy-ndarray with shape of (a, n)) # Please note that if there are more than 3 columns, This function will do interpolation multiple times and each time using (X,Y,value) (value changes in range of value_1 to value_n each time up to last column). -#OUTPUTS: groundMotionField,lons,lats -#Complete_shakemap : a numpy-ndarray +# OUTPUTS: groundMotionField,lons,lats +# fullGroundMotionField : a numpy-ndarray containing logitudes,latitudes along with the interpolated values. -def Get_Full_GMF(groundMotionField,lons,lats): + import pandas as pd + import numpy as np + from scipy.interpolate import griddata - import pandas as pd - import numpy as np - from scipy.interpolate import griddata + # points_given : the input points for interpolation + points_given = np.vstack((groundMotionField[:,0],groundMotionField[:,1])).transpose() + # points_todo : points to do interpolation over + points_todo = np.vstack((lons,lats)).transpose() + fullGroundMotionField = np.vstack((np.array(lons),np.array(lats))).transpose() + + # Griddata Interpolation + # The for loop changes over the columns of the ground motion field. + # This enables us to have interpolation for all different given ground motion types. + # gmvs_given : the input ground motion values for interpolation. + # gm_value_griddata : interpolated values foe each ground motion type. + for gmType in range(2,groundMotionField.shape[1],1): + gmvs_given = groundMotionField[:,gmType] + gm_value_griddata = griddata(points_given,gmvs_given,points_todo, method='linear') + fullGroundMotionField = np.column_stack((fullGroundMotionField,gm_value_griddata)) - # Defining the Inputs - points_given = np.vstack((groundMotionField[:,0],groundMotionField[:,1])).transpose() - points_todo = np.vstack((lons,lats)).transpose() - Complete_shakemap = np.vstack((np.array(lons),np.array(lats))).transpose() - - # Griddata Interpolation - # The for loop changes over the different columns of the ground motion field that contain ground-motion-values one by one. - #This enables us to have interpolation for all different different given ground motion types. - for gmType in range(2,groundMotionField.shape[1],1): - shake_gmvs = groundMotionField[:,gmType] - gm_value_griddata = griddata(points_given,shake_gmvs,points_todo, method='linear') - fullGroundMotionField = np.column_stack((fullGroundMotionField,gm_value_griddata)) - - return(fullGroundMotionField) + return(fullGroundMotionField) -- GitLab From f6aa31df6a9bf41f6282998c025e85f910496c49 Mon Sep 17 00:00:00 2001 From: Tara Evaz Zadeh Date: Sat, 22 Aug 2020 17:13:13 +0430 Subject: [PATCH 4/4] Resolved 3 threads from Danijel on the Get_Full_GMFs.py --- Get_Full_GMFs.py | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/Get_Full_GMFs.py b/Get_Full_GMFs.py index 9b6854d..00d6310 100644 --- a/Get_Full_GMFs.py +++ b/Get_Full_GMFs.py @@ -1,37 +1,52 @@ #!/usr/bin/env python -def Get_Full_GMF(groundMotionField,lons,lats): +def Get_Full_GMF(groundMotionField,lons,lats,method): -# Goal : This function does a 2-dimensional interpolation. +# Goal: This function does a 2-dimensional interpolation. # INPUTS: groundMotionField,lons,lats -# lons : Column of longitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) -# lats : Column of latitudes of the locations we want to interpolate over.(type: pandas.DataFrame(series) OR numpy-1darray of len a) -# groundMotionField: Numpy nd-array of the file with headers of X,Y,value_1,value_2....value_n ; This file must contain longitude values as the first column, latitude values as the second column and ground motion values as the 3rd. (type : m*n numpy-ndarray with shape of (a, n)) -# Please note that if there are more than 3 columns, This function will do interpolation multiple times and each time using (X,Y,value) (value changes in range of value_1 to value_n each time up to last column). +# lons: longitudes of the locations we want to interpolate over +#(pandas.DataFrame(series) OR numpy-1darray of len a) +# lats: latitudes of the locations we want to interpolate over +#(pandas.DataFrame(series) OR numpy-1darray of len a) +# groundMotionField: Numpy nd-array of the file with headers of +#X,Y,value_1,value_2....value_n +# This file must contain longitude values as the first column, +#latitude values as the second column and ground motion values +#as the 3rd. (numpy-ndarray with shape of (m, n)) +# Please note that if there are more than 3 columns, +#This function will do interpolation multiple times +#and each time using (X,Y,value) +#(value changes in range of value_1 to +#value_n each time up to last column). # OUTPUTS: groundMotionField,lons,lats -# fullGroundMotionField : a numpy-ndarray containing logitudes,latitudes along with the interpolated values. +# fullGroundMotionField: a numpy-ndarray containing +#logitudes, latitudes along with the interpolated values import pandas as pd import numpy as np from scipy.interpolate import griddata - # points_given : the input points for interpolation + # points_given: the input points for interpolation points_given = np.vstack((groundMotionField[:,0],groundMotionField[:,1])).transpose() - # points_todo : points to do interpolation over + # points_todo: points to do interpolation over points_todo = np.vstack((lons,lats)).transpose() fullGroundMotionField = np.vstack((np.array(lons),np.array(lats))).transpose() # Griddata Interpolation - # The for loop changes over the columns of the ground motion field. - # This enables us to have interpolation for all different given ground motion types. - # gmvs_given : the input ground motion values for interpolation. - # gm_value_griddata : interpolated values foe each ground motion type. + # The for loop changes over the columns + # of the ground motion field. + # This enables us to have interpolation for all + #different given ground motion types. + # gmvs_given: the input ground motion + #values for interpolation. + # gm_value_griddata : interpolated values + #for each ground motion type. for gmType in range(2,groundMotionField.shape[1],1): gmvs_given = groundMotionField[:,gmType] - gm_value_griddata = griddata(points_given,gmvs_given,points_todo, method='linear') + gm_value_griddata = griddata(points_given,gmvs_given,points_todo, method=method) fullGroundMotionField = np.column_stack((fullGroundMotionField,gm_value_griddata)) return(fullGroundMotionField) -- GitLab