Hazard Winds
Contents
Hazard Winds#
from datetime import datetime
print("execution start: {0}".format(datetime.today().strftime('%Y-%m-%d %H:%M:%S')))
execution start: 2022-09-02 23:58:09
import os
import os.path as op
import sys
import pandas as pd
import numpy as np
import xarray as xr
# raster tools
from rasterio.crs import CRS
import json
import rioxarray
# kepler
from keplergl import KeplerGl
# bluemath
sys.path.insert(0, op.join(op.abspath(''), '..', '..'))
sys.path.insert(0, op.join(op.abspath(''), '..'))
# operational utils
from operational.util import read_config_args
Warning: ecCodes 2.21.0 or higher is recommended. You are running version 2.16.0
Forecast Parameters#
# project database
p_data = r'/media/administrador/HD2/SamoaTonga/data'
p_db = r'/media/administrador/HD1/DATABASES'
#site = 'Upolu' # Savaii / Upolu / Tongatapu
# (optional) get site from config file
nb_args = read_config_args(op.abspath(''), '10b_hazard')
site = nb_args['site']
print('Study site: {0}'.format(site))
Study site: Upolu
# site related parameteres
if site == 'Savaii':
# reforecast track
n, tc_name = 166, 'amos' # AMOS 2016
tif_fn = 'hr_FINAL_track_AMOS_lonlat.tif'
elif site == 'Upolu':
# reforecast track
n, tc_name = 166, 'amos' # AMOS 2016
tif_fn = 'hr_FINAL_track_AMOS_lonlat.tif'
elif site == 'Tongatapu':
# reforecast track
n, tc_name = 180, 'gita'
tif_fn = 'hr_FINAL_track_GITA_lonlat.tif'
Database#
p_site = op.join(p_data, site)
# riskscape folder
p_riskscape = op.join(p_data, 'riskscape_projects')
p_riskscape_site = op.join(p_riskscape, site)
# kepler config files
p_kepler_config = op.join(p_riskscape_site, 'config_files', 'config_hazard_rain_{0}.json'.format(site.lower()))
Reforecast#
date = 'reforecast_{0}'.format(tc_name)
print('forecast execution: {0}'.format(date))
forecast execution: reforecast_amos
Forecast Output Folder#
p_forecast = op.join(p_site, 'forecast', '10_wind_damage')
# forecast folder
p_fore_date = op.join(p_forecast, date)
print('forecast date code: {0}'.format(date))
forecast date code: reforecast_amos
# tc forecast
p_fore_tc = op.join(p_fore_date, tc_name + '_forecast')
# wind hazard files
p_final_track_tif = op.join(p_fore_tc, 'hr_FINAL_track_{0}_lonlat.tif'.format(tc_name))
Hazard Winds#
data_sim = xr.open_rasterio(p_final_track_tif).rename('z') # this is the wind
data_sim_84 = data_sim.copy()
data_sim_84 = data_sim_84.where((data_sim_84>=0.2) & (data_sim_84<=100))
df_sim_84 = data_sim_84.to_dataframe().reset_index().dropna()\
.rename(columns={'x':'Lon', 'y':'Lat'}).drop(columns=['band'])
Plot Hazard - SWATH winds#
a_file = open(p_kepler_config, "rb")
config_winds = json.load(a_file)
# Hazard - flooding depth
map_1 = KeplerGl(height=700, data={"Winds - SWATH": df_sim_84}, config=config_winds, show_docs=False)
map_1
print("execution end: {0}".format(datetime.today().strftime('%Y-%m-%d %H:%M:%S')))
execution end: 2022-09-02 23:58:11