Waves Hindcast
Contents
Waves Hindcast#
# common
import warnings
warnings.filterwarnings('ignore')
import os
import os.path as op
import sys
import pickle as pk
import time
import datetime
# pip
import xarray as xr
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# DEV: bluemath
sys.path.insert(0, op.join(op.abspath(''), '..', '..', '..', '..'))
# bluemath modules
from bluemath.binwaves.reconstruction import reconstruct_kmeans_clusters_hindcast, obtain_wave_metrics_grid
from bluemath.binwaves.reconstruction import get_hindcast_snapshot
from bluemath.binwaves.nino34 import n34_format
from bluemath.binwaves.plotting.hindcast import Plot_hindcast_series_point, Plot_hindcast_snapshot, Plot_hindcast_maps
from bluemath.binwaves.plotting.hindcast import Plot_hindcast_seasonality, Plot_hindcast_elnino
from bluemath.binwaves.plotting.nino34 import Plot_n34
Warning: cannot import cf-json, install "metocean" dependencies for full functionality
Methodology#
Hindcast
Once we have reconstructed the K-Means clusters for the KMA clusters, and validated the results against instrumental data, we can efficiently reconstruct the hindcast following the steps below
Database and site parameters#
# database
p_data = r'/media/administrador/HD2/SamoaTonga/data'
site = 'Samoa'
p_site = op.join(p_data, site)
# deliverable folder
p_deliv = op.join(p_site, 'd05_swell_inundation_forecast')
p_kma = op.join(p_deliv, 'kma')
p_swan = op.join(p_deliv, 'swan')
# nino34 dataset
p_n34 = op.join(p_data, 'ninho34.txt')
# SWAN simulation parameters
name = 'binwaves'
p_swan_subset = op.join(p_swan, name, 'subset.nc')
p_swan_output = op.join(p_swan, name, 'out_main_binwaves.nc')
p_swan_input_spec = op.join(p_swan, name, 'input_spec.nc')
# SuperPoint KMeans
num_clusters = 2000
p_superpoint_kma = op.join(p_kma, 'Spec_KMA_{0}_NS.nc'.format(num_clusters))
# output files
p_site_out = op.join(p_deliv, 'reconstruction')
p_reco_hnd = op.join(p_site_out, 'hindcast') # hindcast reconstruction folder
p_hindcast_stats = op.join(p_reco_hnd, 'hindcast_stats.nc') # hindcast reconstruction metrics
p_hindcast_monthly = op.join(p_reco_hnd, 'hindcast_monthly.nc') # hindcast monthly mean
# hindcast reconstruction
recon_hindcast = False
wave_metrics = True
wave_metrics_perc = [25, 50, 75, 90, 95, 99]
# hindcast snapshot
hindcast_snapshot = True
time_snapshot = '1993-05-12-00:00:00'
# aux functions
def load_hindcast_recon(point, out_sim, p_reco):
'''
Load hindcast reconstruction for a choosen point
point - point to load [lon, lat] (find nearest)
out_sim - SWAN simulation output
'''
# find point
ilon = np.argmin(np.abs(out_sim.lon.values - point[0]))
ilat = np.argmin(np.abs(out_sim.lat.values - point[1]))
# load coefficient
fn = 'reconst_hind_lon_{0}_lat_{1}.nc'.format(out_sim.lon.values[ilon], out_sim.lat.values[ilat])
p_cf = op.join(p_reco, fn)
return xr.open_dataset(p_cf)
# Load SWAN simulation output and kmeans clusters
out_sim_swan = xr.open_dataset(p_swan_output)
sp_kma = xr.open_dataset(p_superpoint_kma)
Here we need to define the area for the extraction and the resample factor
The plot is an example of the area that has been cut
# this will reduce memory usage
area_extraction = [-172.92+360, -171.3+360, -14.14, -13.3]
resample_factor = 2
# cut area
out_sim = out_sim_swan.sel(
lon = slice(area_extraction[0], area_extraction[1]),
lat = slice(area_extraction[2], area_extraction[3]),
)
# resample extraction points
out_sim = out_sim.isel(
lon = np.arange(0, len(out_sim.lon), resample_factor),
lat = np.arange(0, len(out_sim.lat), resample_factor),
)
# check that the area is OK
plt.figure(figsize = [12, 5])
out_sim.isel(case = 10).Hsig.plot(cmap='RdBu', vmin=0, vmax=2);
Reconstruct Hindcast#
# reconstruct model data for that area
if recon_hindcast:
reconstruct_kmeans_clusters_hindcast(
p_site_out, out_sim, sp_kma,
reconst_hindcast = True,
override = False,
)
Obtain wave metrics#
if wave_metrics:
# calculate wave metrics
hindcast_stats, hindcast_monthly = obtain_wave_metrics_grid(
p_reco_hnd,
out_sim,
perc = wave_metrics_perc,
)
# store metrics and monthly mean
hindcast_stats.to_netcdf(p_hindcast_stats)
hindcast_monthly.to_netcdf(p_hindcast_monthly)
else:
# load metrics and monthly mean
hindcast_stats = xr.open_dataset(p_hindcast_stats)
hindcast_monthly = xr.open_dataset(p_hindcast_monthly)
Preprocessing efth and stats...: 100%|██████████████████████████████| 36846/36846 [19:36:46<00:00, 1.92s/it]
hindcast_monthly
<xarray.Dataset> Dimensions: (lat: 138, lon: 267, time: 502) Coordinates: * lat (lat) float64 -14.14 -14.13 -14.13 -14.12 ... -13.33 -13.32 -13.32 * lon (lon) float64 187.1 187.1 187.1 187.1 ... 188.7 188.7 188.7 188.7 * time (time) datetime64[ns] 1979-01-31 1979-02-28 ... 2020-10-31 Data variables: hs (lon, lat, time) float64 1.623 1.677 1.651 ... 2.11 1.912 1.481 tp (lon, lat, time) float64 9.679 13.95 14.32 ... 9.45 8.775 8.461 tm (lon, lat, time) float64 6.437 7.345 8.069 ... 6.3 6.054 5.752 dm (lon, lat, time) float64 159.4 184.9 191.2 ... 108.6 108.9 87.7 dp (lon, lat, time) float64 205.1 263.8 248.9 ... 123.4 139.2 82.5 dspr (lon, lat, time) float64 68.23 61.66 63.1 ... 41.84 44.72 38.43
xarray.Dataset
- lat: 138
- lon: 267
- time: 502
- lat(lat)float64-14.14 -14.13 ... -13.32 -13.32
array([-14.137378, -14.131378, -14.125378, -14.119378, -14.113378, -14.107378, -14.101378, -14.095378, -14.089378, -14.083378, -14.077378, -14.071378, -14.065378, -14.059378, -14.053378, -14.047378, -14.041378, -14.035378, -14.029378, -14.023378, -14.017378, -14.011378, -14.005378, -13.999378, -13.993378, -13.987378, -13.981378, -13.975378, -13.969378, -13.963378, -13.957378, -13.951378, -13.945378, -13.939378, -13.933378, -13.927378, -13.921378, -13.915378, -13.909378, -13.903378, -13.897378, -13.891378, -13.885378, -13.879378, -13.873378, -13.867378, -13.861378, -13.855378, -13.849378, -13.843378, -13.837378, -13.831378, -13.825378, -13.819378, -13.813378, -13.807378, -13.801378, -13.795378, -13.789378, -13.783378, -13.777378, -13.771378, -13.765378, -13.759378, -13.753378, -13.747378, -13.741378, -13.735378, -13.729378, -13.723378, -13.717378, -13.711378, -13.705378, -13.699378, -13.693378, -13.687378, -13.681378, -13.675378, -13.669378, -13.663378, -13.657378, -13.651378, -13.645378, -13.639378, -13.633378, -13.627378, -13.621378, -13.615378, -13.609378, -13.603378, -13.597378, -13.591378, -13.585378, -13.579378, -13.573378, -13.567378, -13.561378, -13.555378, -13.549378, -13.543378, -13.537378, -13.531378, -13.525378, -13.519378, -13.513378, -13.507378, -13.501378, -13.495378, -13.489378, -13.483378, -13.477378, -13.471378, -13.465378, -13.459378, -13.453378, -13.447378, -13.441378, -13.435378, -13.429378, -13.423378, -13.417378, -13.411378, -13.405378, -13.399378, -13.393378, -13.387378, -13.381378, -13.375378, -13.369378, -13.363378, -13.357378, -13.351378, -13.345378, -13.339378, -13.333378, -13.327378, -13.321378, -13.315378])
- lon(lon)float64187.1 187.1 187.1 ... 188.7 188.7
array([187.080835, 187.086835, 187.092835, ..., 188.664835, 188.670835, 188.676835])
- time(time)datetime64[ns]1979-01-31 ... 2020-10-31
array(['1979-01-31T00:00:00.000000000', '1979-02-28T00:00:00.000000000', '1979-03-31T00:00:00.000000000', ..., '2020-08-31T00:00:00.000000000', '2020-09-30T00:00:00.000000000', '2020-10-31T00:00:00.000000000'], dtype='datetime64[ns]')
- hs(lon, lat, time)float641.623 1.677 1.651 ... 1.912 1.481
array([[[1.62280521, 1.67739152, 1.65103555, ..., 1.97448808, 1.92622232, 1.40960799], [1.62486365, 1.67988842, 1.65294426, ..., 1.97487391, 1.92640331, 1.41040011], [1.6299005 , 1.68631986, 1.6576011 , ..., 1.98070676, 1.93082504, 1.41560272], ..., [1.75292167, 1.93399386, 1.788094 , ..., 1.97446133, 1.9568753 , 1.53997634], [1.75020865, 1.93309514, 1.785309 , ..., 1.96971126, 1.95177113, 1.54030991], [1.74818321, 1.93348723, 1.78322149, ..., 1.9699783 , 1.94988115, 1.54461025]], [[1.61460542, 1.67179443, 1.64576169, ..., 1.97242641, 1.92417005, 1.40745911], [1.61550705, 1.67236815, 1.64644831, ..., 1.97032868, 1.92239504, 1.40609962], [1.62015384, 1.67809077, 1.6506077 , ..., 1.97505941, 1.92602265, 1.41057491], ... [1.80774178, 1.8834398 , 1.76098341, ..., 2.10747841, 1.90812885, 1.47903525], [1.80775137, 1.88389997, 1.76152363, ..., 2.10779755, 1.90843332, 1.47947675], [1.80802882, 1.88434676, 1.76202365, ..., 2.10827392, 1.90873017, 1.4814829 ]], [[1.79561302, 2.05509217, 1.92094555, ..., 2.33299932, 2.22132174, 1.72949717], [1.80177367, 2.05809495, 1.92684052, ..., 2.33305216, 2.22142704, 1.7296685 ], [1.80705428, 2.06309066, 1.93707378, ..., 2.33328615, 2.22175408, 1.72996246], ..., [1.81049503, 1.88558062, 1.76249865, ..., 2.11074534, 1.91326661, 1.48015511], [1.81005739, 1.88516876, 1.76217297, ..., 2.11023844, 1.91250815, 1.48042223], [1.80994576, 1.88499744, 1.76219233, ..., 2.11005094, 1.91198285, 1.48145604]]])
- tp(lon, lat, time)float649.679 13.95 14.32 ... 8.775 8.461
array([[[ 9.67911785, 13.95141818, 14.31857939, ..., 11.76761331, 12.52992517, 11.56991383], [ 9.68041049, 13.95031473, 14.31845846, ..., 11.76735623, 12.52824433, 11.57603728], [ 9.68477349, 13.94768458, 14.31711439, ..., 11.76271533, 12.52431511, 11.57787363], ..., [ 9.11373764, 12.65944761, 14.46083152, ..., 11.67847799, 11.89874072, 11.55380027], [ 9.11579894, 12.66012469, 14.46216172, ..., 11.67826445, 11.896352 , 11.55732837], [ 9.11648635, 12.65892114, 14.46316354, ..., 11.75187091, 11.89440896, 11.55514406]], [[ 9.67120995, 13.96100596, 14.32048605, ..., 11.76833851, 12.53056881, 11.57108215], [ 9.67165987, 13.9600113 , 14.32068728, ..., 11.76917635, 12.52952948, 11.57844965], [ 9.67552263, 13.95742554, 14.31978843, ..., 11.76621042, 12.52650491, 11.58065323], ... [ 8.76462572, 10.8320278 , 11.29697188, ..., 9.44983522, 8.77643115, 8.45569469], [ 8.76478164, 10.9078819 , 11.29810874, ..., 9.4506926 , 8.83179585, 8.460306 ], [ 8.7648572 , 10.90841403, 11.29900155, ..., 9.45093991, 8.832446 , 8.46041146]], [[ 8.92557151, 12.38400365, 12.7805953 , ..., 11.00894945, 11.58596264, 8.79595112], [ 8.92883915, 12.3956998 , 12.76665392, ..., 11.00932557, 11.58574358, 8.80096147], [ 8.95399418, 12.41350055, 12.9757341 , ..., 11.00924499, 11.5849199 , 8.80447565], ..., [ 8.76435666, 10.83271686, 11.29698521, ..., 9.45004498, 8.77442667, 8.45687133], [ 8.76412703, 10.83262447, 11.29647834, ..., 9.44971452, 8.77469777, 8.46052535], [ 8.7637049 , 10.83240573, 11.29729628, ..., 9.44983668, 8.77491234, 8.46067811]]])
- tm(lon, lat, time)float646.437 7.345 8.069 ... 6.054 5.752
array([[[6.43739212, 7.34520324, 8.06891583, ..., 7.01579818, 6.93514777, 6.85704827], [6.43378516, 7.33091943, 8.05596546, ..., 7.00200551, 6.92283987, 6.83672905], [6.43311899, 7.31497596, 8.03928538, ..., 6.98914816, 6.91098976, 6.81544865], ..., [6.71493217, 7.45154775, 7.85182867, ..., 6.86749384, 6.95102656, 6.5862712 ], [6.71524686, 7.44805465, 7.84809426, ..., 6.85863966, 6.94517591, 6.58098563], [6.71672737, 7.44465944, 7.84450578, ..., 6.85608865, 6.94310648, 6.58108291]], [[6.43393595, 7.35276149, 8.08251222, ..., 7.02298844, 6.94215826, 6.86963644], [6.43166867, 7.34524012, 8.07533378, ..., 7.01415762, 6.93431153, 6.85718325], [6.4290531 , 7.32614921, 8.05623223, ..., 6.99858966, 6.92022912, 6.83240554], ... [6.50368168, 6.61518423, 7.22417669, ..., 6.30492384, 6.05929433, 5.75065469], [6.50462173, 6.6169556 , 7.2262586 , ..., 6.30698911, 6.0617848 , 5.75202531], [6.50535336, 6.61808842, 7.22747827, ..., 6.30877577, 6.06366901, 5.75731717]], [[6.52530026, 7.02355139, 7.63125384, ..., 6.7038487 , 6.64018124, 6.36904943], [6.52398155, 7.02802654, 7.63914381, ..., 6.70388038, 6.64010055, 6.36938996], [6.52512941, 7.03943466, 7.65926548, ..., 6.7042036 , 6.64052935, 6.37001927], ..., [6.49595829, 6.61064335, 7.2171037 , ..., 6.2979475 , 6.05302457, 5.74768177], [6.49634303, 6.61057334, 7.21719594, ..., 6.29834996, 6.05331628, 5.74870557], [6.49699064, 6.61109187, 7.21817557, ..., 6.29958031, 6.05427676, 5.75204781]]])
- dm(lon, lat, time)float64159.4 184.9 191.2 ... 108.9 87.7
array([[[159.43413106, 184.86126793, 191.17105566, ..., 153.2533941 , 163.85253619, 161.70215525], [159.22035956, 184.58779992, 190.95867493, ..., 153.19173091, 163.83450399, 161.57971671], [158.78583921, 183.71641373, 190.27678659, ..., 152.71667698, 163.4287214 , 160.77682825], ..., [ 95.23577151, 88.70569928, 132.73904924, ..., 126.98217795, 141.41595181, 111.76366767], [ 94.85926869, 88.39273382, 132.15742587, ..., 126.66939638, 141.11080763, 111.47759712], [ 94.55132973, 88.19298628, 131.6375137 , ..., 126.21238471, 140.56283863, 110.93434819]], [[164.8901096 , 185.04954985, 191.32127825, ..., 153.34594829, 163.92508457, 161.85014148], [163.69438329, 185.06987934, 191.33009392, ..., 153.47340408, 164.08589587, 162.06404905], [162.36896694, 184.35545236, 190.79566976, ..., 153.08703697, 163.75876356, 161.39024639], ... [115.66108383, 63.84765614, 78.26403899, ..., 108.46050043, 108.60289783, 87.5559276 ], [115.65039377, 63.88922145, 78.3293705 , ..., 108.48927364, 108.63414874, 87.57900172], [115.60861074, 63.91247405, 78.36443577, ..., 108.50726659, 108.64031937, 87.67748423]], [[ 93.46864239, 93.18482711, 110.11251874, ..., 128.30011977, 137.88046238, 115.51023023], [ 92.85169818, 92.74561948, 113.3632326 , ..., 128.29142883, 137.86710381, 115.47789406], [ 92.08551822, 91.92789267, 111.42014492, ..., 128.2762426 , 137.84222456, 115.44042824], ..., [115.92495279, 64.05899629, 78.42428236, ..., 108.66694836, 108.98140935, 87.63946228], [115.89806537, 64.02066938, 78.37652762, ..., 108.63122146, 108.91853473, 87.64874749], [115.83873977, 63.99581937, 78.3646316 , ..., 108.61728265, 108.87575447, 87.70114587]]])
- dp(lon, lat, time)float64205.1 263.8 248.9 ... 139.2 82.5
array([[[205.10080645, 263.83729569, 248.9295302 , ..., 176.76845638, 199.85783634, 217.5 ], [205.10080645, 263.83729569, 248.9295302 , ..., 176.76845638, 199.85783634, 217.5 ], [205.10080645, 263.83729569, 248.9295302 , ..., 176.76845638, 199.85783634, 217.5 ], ..., [200.46370968, 253.9858841 , 244.82214765, ..., 171.17114094, 196.36269071, 217.5 ], [200.46370968, 253.9858841 , 244.82214765, ..., 171.17114094, 196.36269071, 217.5 ], [200.46370968, 253.9858841 , 244.82214765, ..., 171.17114094, 196.36269071, 217.5 ]], [[282.54032258, 263.83729569, 248.9295302 , ..., 176.76845638, 199.85783634, 217.5 ], [282.54032258, 263.83729569, 248.9295302 , ..., 176.76845638, 199.85783634, 217.5 ], [282.54032258, 263.83729569, 248.9295302 , ..., 176.76845638, 199.85783634, 217.5 ], ... [172.94354839, 190.17459138, 221.2852349 , ..., 123.39261745, 139.21289875, 82.5 ], [172.94354839, 190.17459138, 221.2852349 , ..., 123.39261745, 139.35852982, 82.5 ], [172.94354839, 190.17459138, 221.2852349 , ..., 123.39261745, 139.35852982, 82.5 ]], [[163.97177419, 180.79123328, 236.1442953 , ..., 173.40604027, 186.00208044, 217.5 ], [163.97177419, 207.09138187, 241.94295302, ..., 173.40604027, 186.00208044, 217.5 ], [176.63306452, 247.74517088, 248.9295302 , ..., 173.40604027, 186.00208044, 217.5 ], ..., [172.94354839, 190.17459138, 221.2852349 , ..., 123.39261745, 139.21289875, 82.5 ], [172.94354839, 190.17459138, 221.2852349 , ..., 123.39261745, 139.21289875, 82.5 ], [172.94354839, 190.17459138, 221.2852349 , ..., 123.39261745, 139.21289875, 82.5 ]]])
- dspr(lon, lat, time)float6468.23 61.66 63.1 ... 44.72 38.43
array([[[68.22689803, 61.65828202, 63.10013269, ..., 40.91652645, 43.86859534, 55.24282268], [68.20971594, 61.826695 , 63.22626246, ..., 41.05138657, 43.98313654, 55.38358188], [68.18506384, 62.12902573, 63.46562116, ..., 41.4072479 , 44.32017699, 55.73365719], ..., [61.96154437, 68.13086103, 69.56362347, ..., 56.22054198, 58.86542561, 68.1437527 ], [61.79074131, 68.07848022, 69.44851026, ..., 56.29304916, 58.97984769, 68.11792717], [61.59220406, 67.99218907, 69.31343788, ..., 56.2632306 , 59.04120971, 67.92267936]], [[68.17589076, 61.18452309, 62.72227937, ..., 40.67087451, 43.62379989, 54.99608652], [68.17616754, 61.28998957, 62.80037882, ..., 40.70221182, 43.63480936, 55.03456749], [68.14777511, 61.59199115, 63.03429864, ..., 41.02987491, 43.94303976, 55.36627935], ... [59.61398146, 55.20825636, 58.73945609, ..., 41.75404298, 44.61197507, 38.0842223 ], [59.60461645, 55.23703664, 58.76806944, ..., 41.77201973, 44.62907666, 38.16940787], [59.59038463, 55.25661851, 58.78937395, ..., 41.80103046, 44.64838143, 38.50746286]], [[62.55678996, 64.86656953, 67.35602144, ..., 49.77229408, 53.17408543, 60.35019634], [62.67694587, 64.92395792, 67.48367799, ..., 49.78559078, 53.19429634, 60.36834795], [62.7984115 , 64.97869609, 67.69580138, ..., 49.80909483, 53.22802147, 60.39211123], ..., [59.79135132, 55.31578549, 58.81072847, ..., 41.83715471, 44.73704954, 38.15924249], [59.76497342, 55.29325469, 58.79342984, ..., 41.83030961, 44.72364746, 38.22836114], [59.73983459, 55.28511089, 58.79392904, ..., 41.83761688, 44.7194697 , 38.42774669]]])
# Plot hindcast at selected point
point = [187.8, -13.88]
# Load hindcast reconstruction at nearest point
recon_data = load_hindcast_recon(point, out_sim, p_reco_hnd)
# monthly hindcast at point
ilon = np.argmin(np.abs(hindcast_monthly.lon.values - point[0]))
ilat = np.argmin(np.abs(hindcast_monthly.lat.values - point[1]))
month_data = hindcast_monthly.isel(lon=ilon, lat=ilat)
# plot hs, tp and dm time series
Plot_hindcast_series_point(recon_data, month_data, 'hs');
Plot_hindcast_series_point(recon_data, month_data, 'tp');
Plot_hindcast_series_point(recon_data, month_data, 'dm');
Wave climate#
Snapshot analysis#
if hindcast_snapshot:
data_snapshot = get_hindcast_snapshot(p_reco_hnd, out_sim, time_snapshot)
# plot hindcast snapshot
Plot_hindcast_snapshot(data_snapshot)
Average climate#
Plot_hindcast_maps(
hindcast_stats, 'Dir_m',
vmin = 0, vmax = 360,
quiv_color = 'palevioletred',
figsize = [15, 15],
);
Plot_hindcast_maps(
hindcast_stats, 'Hs',
percentile = 50,
vmin = 0, vmax = 2,
quiv_fact = 8, figsize = [15, 15],
);
Plot_hindcast_maps(
hindcast_stats, 'Hs',
percentile = 90,
vmin = 0, vmax = 3.5,
quiv_fact = 8, figsize = [15, 15],
);
Plot_hindcast_maps(
hindcast_stats, 'Hs',
percentile = 99,
vmin = 0, vmax = 3.5,
quiv_fact = 8, quiv_color = 'teal',
figsize = [15, 15],
);
Plot_hindcast_maps(
hindcast_stats, 'Tm',
percentile = 50,
vmin = 5, vmax = 10,
quiv_fact = 8, quiv_color = 'cornsilk',
figsize = [15, 15],
);
Seasonality#
seasons = hindcast_monthly.groupby('time.season').mean()
Plot_hindcast_seasonality(seasons, var_s = 'hs', vmin = 0, vmax = 2.7);
Plot_hindcast_seasonality(seasons, var_s = 'tm', vmin = 4, vmax = 10, quiv_color = 'cornsilk');
Plot_hindcast_seasonality(seasons, var_s = 'tp', vmin = 6.5, vmax = 16, quiv_color = 'cornsilk');
Interannual variability#
# load ninho34 data
n34 = np.loadtxt(p_n34,skiprows=1, max_rows=74)
n34 = n34_format(n34, rolling_mean=True)
n34 = n34.sel(time = hindcast_monthly.time)
# plot ninho34 and thresholds
thr1 = 1 # over this value, years are classified as El Nino (1)
thr2 = -1 # under this value, years are classified as La Nina (3)
Plot_n34(n34, l1 = thr1, l2 = thr2, figsize=[19, 6]);
# add ninho34 classification to monthly hindcast data
hindcast_monthly['n34'] = (('time'), n34.classification.values) # 1:El Nino, 2:Neutral, 3:La Nina
Average waves 50% percentile#
def Plot_hindcast_elnino(data, quant=None, var_s = 'hs', vmin=0, vmax=2.5,
quiv_color = 'teal', figsize = [26, 20]):
'''
Plot hindcast El Nino events. Needs "n34" index variable inside data with values
"1,2,3" for "ElNino, Neutral, LaNina"
data - xarray.Dataset with "n34" index values
p_coastfile - path to .shp file from GSHHS
quant - quantile, None for mean, float to calculate quantile
var_s - variable to plot
vmin - minimun value for colormap
vmax - maximun value for colormap
'''
# generate figure and gridsizer
fig = plt.figure(figsize=figsize)
gs = gridspec.GridSpec(1, 3, hspace=0.01, wspace=0.01)
# years type
# TODO enhe en el label
years = ['El Niño', 'Neutral', 'La Niña']
for s in range(len(years)):
# add subplot and select year type
ax = fig.add_subplot(
gs[s],
projection = ccrs.PlateCarree(central_longitude=180),
)
# mean or quantile
if quant == None:
s_p = data.isel(time = np.where(data.n34.values==s)[0]).mean(dim = 'time')
else:
s_p = data.isel(time = np.where(data.n34.values==s)[0]).quantile(0.99, dim = 'time')
# plot season hindcast
Plot_hindcast_maps(
s_p, var_s,
vmin = vmin, vmax = vmax,
quiv_fact = 10, quiv_color = quiv_color,
ax = ax,
)
ax.set_title(years[s], fontsize=16, color='firebrick', fontweight='bold')
return fig
Plot_hindcast_elnino(hindcast_monthly, var_s = 'hs', vmin = 0, vmax = 2.5, figsize=[25,10]);
Extreme waves: 99% percentile#
Plot_hindcast_elnino(hindcast_monthly, quant = 0.99, var_s = 'hs', vmin = 0, vmax = 3, figsize=[25,10]);