Commit 69b66444 authored by Tara Evaz Zadeh's avatar Tara Evaz Zadeh
Browse files

Added a new file

parent 2db6e5de
#!/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)
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