diff --git a/Get_Full_GMFs.py b/Get_Full_GMFs.py new file mode 100644 index 0000000000000000000000000000000000000000..00d6310084449e164fb46ca138b0006efc5ffe93 --- /dev/null +++ b/Get_Full_GMFs.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +def Get_Full_GMF(groundMotionField,lons,lats,method): + +# Goal: This function does a 2-dimensional interpolation. + +# INPUTS: groundMotionField,lons,lats +# 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 + + + 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 + #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=method) + fullGroundMotionField = np.column_stack((fullGroundMotionField,gm_value_griddata)) + + return(fullGroundMotionField) + +