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

Resolved 3 threads from Danijel on the Get_Full_GMFs.py

parent eb84ff27
#!/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)
......
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