Commit eb84ff27 authored by Tara Evaz Zadeh's avatar Tara Evaz Zadeh
Browse files

Resolved threads from Danijel on the Get_Full_GMFs.py

parent 4feb11b0
#!/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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment