Commit 2db6e5de authored by Tara Evaz Zadeh's avatar Tara Evaz Zadeh
Browse files

Added a file

parent bf51d1e2
#!/usr/bin/env python
#interpolate GMFs and we can have enough rows as in exposures because there can be fewlines in exposure for the same location and use SDC_006.py or have the script to the read the lines it needs from gmf file that contains only unique locations.
def interp_gm_at_location(lon,lat,shakemap_path,gm_type):
print
import pandas as pd
from scipy import interpolate
shakemapFile=pd.read_csv(shakemap_path)
PGAs=shakemapFile[gm_type]
#data=pd.read_csv('interp_grid.csv')
#lons=data.lon
#lats=data.lat
#pga=data['gmv_PGA']
shake_lons=shakemapFile.lon
shake_lats=shakemapFile.lat
#z=[23.7875]
if lon in shake_lons and lat in shake_lats:
gm_value=shakemapFile.loc[(shakemapFile['lon'] == lon) & (shakemapFile['lat'] == lat), gm_type].iloc[0]
#print('gmf exists')
else:
intrp_pga=interpolate.interp2d(shake_lons, shake_lats, PGAs, kind = 'linear')
lon_new=[lon]
lat_new=[lat]
[gm_value]=intrp_pga(lon_new,lat_new)
return(gm_value)
#################################################
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.spatial.distance import cdist
def get_gm_at_location(lon,lat,shakemap_path,gm_type):
################################################ Path2Files ################################################
#exposures_path="/home/tara/Desktop/OQCalculatorScripts/1356_1357Computations/gmf_TEST/Exposure_test_g_5deci.csv"
#shakemap_path="/home/tara/Desktop/OQCalculatorScripts/1356_1357Computations/gmf_TEST/shakemap_test_g.csv"
################################################ Read Files ################################################
#exposures = pd.read_csv(exposures_path)
shakemapFile=pd.read_csv(shakemap_path)
################################################ Read Columns ################################################
#lons=exposures.lon
#lats=exposures.lat
shake_lons=shakemapFile.lon
shake_lats=shakemapFile.lat
#points=shakemapFile[shakemapFile.columns[1:3]]
points=list(zip(shake_lons,shake_lats))
#type(points)
#print('points=', points)
###############################################
def closest_point(point, points):
""" Find closest point from a list of points. """
return points[cdist(point, points).argmin()]
################################################ COMPUTATION ################################################
#print(asset)
#lon=lons[asset]
#lat=lats[asset]
point=[(lon, lat)]
#print(point)
#type(point)
#print(points)
if lon in shake_lons and lat in shake_lats:
gm_value=shakemapFile.loc[(shakemapFile['lon'] == lon) & (shakemapFile['lat'] == lat), gm_type].iloc[0]
#print('gmf exists')
else:
(ln,lt)=closest_point(point, points)
gm_value=shakemapFile.loc[(shakemapFile['lon'] == ln) & (shakemapFile['lat'] == lt), gm_type].iloc[0]
#print('gmf interp')
return(gm_value)
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