Skip to content

Commit

Permalink
More spt states (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhales authored Nov 7, 2021
1 parent b175311 commit 7b6dd3d
Show file tree
Hide file tree
Showing 23 changed files with 72,538 additions and 7,385 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Liquefaction Hazard Reference Parameter Lookup Tool
110 changes: 76 additions & 34 deletions tethysapp/lfhazard/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ def home(request):
multiple=False,
options=[
('Alaska', 'Alaska'),
('Arizona', 'Arizona'),
('California', 'California'),
('Connecticut', 'Connecticut'),
('Idaho', 'Idaho'),
('Montana', 'Montana'),
('Nevada', 'Nevada'),
('Oregon', 'Oregon'),
('South Carolina', 'South_Carolina'),
('Utah', 'Utah'),
('Washington', 'Washington'),
],
initial=['Utah', 'Utah']
)
Expand Down Expand Up @@ -127,7 +131,7 @@ def interpolate_idw(a: np.array, loc: tuple, p: int = 1, r: int or float = None,
b = pd.concat((b.loc[(b['x'] >= 0) & (b['y'] > 0)].head(bound),
b.loc[(b['x'] >= 0) & (b['y'] < 0)].head(bound),
b.loc[(b['x'] < 0) & (b['y'] > 0)].head(bound),
b.loc[(b['x'] < 0) & (b['y'] < 0)].head(bound), ))
b.loc[(b['x'] < 0) & (b['y'] < 0)].head(bound),))
if nearest is not None:
b = b.head(nearest)
if r is not None:
Expand Down Expand Up @@ -160,50 +164,88 @@ def query_csv(request):

if model == 'cpt':
# get CSR from the BI_LT_returnperiod csvs
df = pd.read_csv(os.path.join(
csv_base_path, f'BI_LT-{return_period}', f'BI_LT_{return_period}_{state}.csv'))
csr = interpolate_idw(df[['Longitude', 'Latitude', 'CSR']].values, point, bound=1)
try:
df = pd.read_csv(os.path.join(csv_base_path, f'BI_LT-{return_period}', f'BI_LT_{return_period}_{state}.csv'))
csr = interpolate_idw(df[['Longitude', 'Latitude', 'CSR']].values, point, bound=1)
except Exception as e:
csr = ''

# get Qreq from the KU_LT_returnperiod csv files
df = pd.read_csv(os.path.join(
csv_base_path, f'KU_LT-{return_period}', f'KU_LT_{return_period}_{state}.csv'))
qreq = interpolate_idw(df[['Longitude', 'Latitude', 'Qreq']].values, point, bound=1)
try:
df = pd.read_csv(os.path.join(csv_base_path, f'KU_LT-{return_period}', f'KU_LT_{return_period}_{state}.csv'))
qreq = interpolate_idw(df[['Longitude', 'Latitude', 'Qreq']].values, point, bound=1)
except Exception as e:
qreq = ''

# get Ev_ku and Ev_bi from the Set-returnperiod csv files
df = pd.read_csv(os.path.join(
csv_base_path, f'Set-{return_period}', f'Set_{return_period}_{state}.csv'))
ku_strain_ref = interpolate_idw(df[['Longitude', 'Latitude', 'Ku Strain (%)']].values, point, bound=1)
bi_strain_ref = interpolate_idw(df[['Longitude', 'Latitude', 'B&I Strain (%)']].values, point, bound=1)
try:
df = pd.read_csv(os.path.join(csv_base_path, f'Set-{return_period}', f'Set_{return_period}_{state}.csv'))
ku_strain_ref = interpolate_idw(df[['Longitude', 'Latitude', 'Ku Strain (%)']].values, point, bound=1)
bi_strain_ref = interpolate_idw(df[['Longitude', 'Latitude', 'B&I Strain (%)']].values, point, bound=1)
except Exception as e:
ku_strain_ref = ''
bi_strain_ref = ''

# get gamma_ku_max and gamma_bi_max from the LS_returnperiod csv files
df = pd.read_csv(os.path.join(
csv_base_path, f'LS-{return_period}', f'LS_{return_period}_{state}.csv'))
ku_strain_max = interpolate_idw(df[['Longitude', 'Latitude', 'Ku Strain (%)']].values, point, bound=1)
bi_strain_max = interpolate_idw(df[['Longitude', 'Latitude', 'B&I Strain (%)']].values, point, bound=1)

return JsonResponse({'point_value': [float(csr), float(qreq), float(ku_strain_ref), float(bi_strain_ref),
float(ku_strain_max), float(bi_strain_max)]})
try:
df = pd.read_csv(os.path.join(csv_base_path, f'LS-{return_period}', f'LS_{return_period}_{state}.csv'))
ku_strain_max = interpolate_idw(df[['Longitude', 'Latitude', 'Ku Strain (%)']].values, point, bound=1)
bi_strain_max = interpolate_idw(df[['Longitude', 'Latitude', 'B&I Strain (%)']].values, point, bound=1)
except Exceptions as e:
ku_strain_max = ''
bi_strain_max = ''

return JsonResponse({
"csr": csr,
"qReq": qreq,
"kuStrainRef": ku_strain_ref,
"biStrainRef": bi_strain_ref,
"kuStrainMax": ku_strain_max,
"biStrainMax": bi_strain_max
})

elif model == 'spt':
# Javascript expects return order: logDvalue, Nvalue, CSRvalue, Cetinvalue, InYvalue, RnSvalue, BnTvalue
# read the LS file and get the Log Dh ref value
df = pd.read_csv(os.path.join(csv_base_path, f'LS-{return_period}', f'LS-{return_period}_{state}.csv'))
if year == '2008':
log_D = interpolate_idw(df[['Longitude', 'Latitude', 'D__m_']].values, point, bound=1)
else:
log_D = interpolate_idw(df[['Longitude', 'Latitude', 'log(D)']].values, point, bound=1)
try:
df = pd.read_csv(os.path.join(csv_base_path, f'LS-{return_period}', f'LS-{return_period}_{state}.csv'))
if year == '2008':
log_D = interpolate_idw(df[['Longitude', 'Latitude', 'D__m_']].values, point, bound=1)
else:
log_D = interpolate_idw(df[['Longitude', 'Latitude', 'log(D)']].values, point, bound=1)
except Exception as e:
log_D = ''

# read the LT file and get the N req value and the CSR % value
df = pd.read_csv(os.path.join(csv_base_path, f'LT-{return_period}', f'LT-{return_period}_{state}.csv'))
n_req_cetin = interpolate_idw(df[['Longitude', 'Latitude', 'PB_Nreq_Cetin']].values, point, bound=1)
pb_csr = interpolate_idw(df[['Longitude', 'Latitude', 'PB_CSR_']].values, point, bound=1)
try:
df = pd.read_csv(os.path.join(csv_base_path, f'LT-{return_period}', f'LT-{return_period}_{state}.csv'))
n_req_cetin = interpolate_idw(df[['Longitude', 'Latitude', 'PB_Nreq_Cetin']].values, point, bound=1)
pb_csr = interpolate_idw(df[['Longitude', 'Latitude', 'PB_CSR_']].values, point, bound=1)
except Exception as e:
n_req_cetin = ''
pb_csr = ''

# read the SSD file and get the N req value and the CSR % value
df = pd.read_csv(os.path.join(csv_base_path, f'SSD-{return_period}', f'SSD-{return_period}_{state}.csv'))
epsilon_v_cetin = interpolate_idw(df[['Longitude', 'Latitude', 'Cetin_percent']].values, point, bound=1)
epsilon_v_IandY = interpolate_idw(df[['Longitude', 'Latitude', 'IandY_percent']].values, point, bound=1)
disp_RandS = interpolate_idw(df[['Longitude', 'Latitude', 'PB_Seismic_Slope_Disp_RandS']].values, point, bound=1)
disp_BandT = interpolate_idw(df[['Longitude', 'Latitude', 'PB_Seismic_Slope_Disp_BandT']].values, point, bound=1)

return JsonResponse({'point_value': [float(log_D), float(n_req_cetin), float(pb_csr), float(epsilon_v_cetin),
float(epsilon_v_IandY), float(disp_RandS), float(disp_BandT)]})
try:
df = pd.read_csv(os.path.join(csv_base_path, f'SSD-{return_period}', f'SSD-{return_period}_{state}.csv'))
epsilon_v_cetin = interpolate_idw(df[['Longitude', 'Latitude', 'Cetin_percent']].values, point, bound=1)
epsilon_v_IandY = interpolate_idw(df[['Longitude', 'Latitude', 'IandY_percent']].values, point, bound=1)
disp_RandS = interpolate_idw(df[['Longitude', 'Latitude', 'PB_Seismic_Slope_Disp_RandS']].values, point,
bound=1)
disp_BandT = interpolate_idw(df[['Longitude', 'Latitude', 'PB_Seismic_Slope_Disp_BandT']].values, point,
bound=1)
except Exception as e:
epsilon_v_cetin = ''
epsilon_v_IandY = ''
disp_RandS = ''
disp_BandT = ''

return JsonResponse({
"logD": log_D,
"nReqCetin": n_req_cetin,
"pbCSR": pb_csr,
"epsVCetin": epsilon_v_cetin,
"epsVIY": epsilon_v_IandY,
"dispRS": disp_RandS,
"dispBY": disp_BandT
})
30 changes: 24 additions & 6 deletions tethysapp/lfhazard/public/js/leafletmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $.ajaxSetup({
}
}
});
function getStateBoundaries() {
const getStateBoundaries = () => {
$.ajax({
type: 'GET',
async: true,
Expand Down Expand Up @@ -74,19 +74,37 @@ function submitButton() {
query_csv(parseFloat($("#lon-input").val()), parseFloat($("#lat-input").val()), $("#select_year").val(), $("#select_state").val(), $("#select_return_period").val(), $("#select_model").val())
}
function query_csv(lon, lat, year, state, returnPeriod, model) {
let data = {lon: lon, lat: lat, year: year, state: state, returnPeriod: returnPeriod, model: model};
const data = {lon: lon, lat: lat, year: year, state: state, returnPeriod: returnPeriod, model: model};

$.ajax({
type: 'GET',
url: URL_querycsv,
dataType: 'json',
data: data,
success: function (results) {
let point_value = results.point_value;
if (model === 'spt'){
addSptTableRow(lon.toFixed(4), lat.toFixed(4), point_value[0], point_value[1], point_value[2], point_value[3], point_value[4], point_value[5], point_value[6])
addSptTableRow(
lon.toFixed(4),
lat.toFixed(4),
results.logD,
results.nReqCetin,
results.pbCSR,
results.epsVCetin,
results.epsVIY,
results.dispRS,
results.dispBY,
)
} else {
addCptTableRow(lon.toFixed(4), lat.toFixed(4), point_value[0], point_value[1], point_value[2], point_value[3], point_value[4], point_value[5], point_value[6])
addCptTableRow(
lon.toFixed(4),
lat.toFixed(4),
results.csr,
results.qReq,
results.kuStrainRef,
results.biStrainRef,
results.kuStrainMax,
results.biStrainMax
)
}
},
});
Expand Down Expand Up @@ -152,7 +170,7 @@ function addCptTableRow(lon, lat, csr, qreq, ev_ku_ref, ev_bi_ref, gv_ku_max, gv
cell8.innerHTML = (parseFloat(gv_ku_max).toFixed(3));
cell9.innerHTML = (parseFloat(gv_bi_max).toFixed(3));





Expand Down
Loading

0 comments on commit 7b6dd3d

Please sign in to comment.