How to use decor method in tempest

Best Python code snippet using tempest_python

figS04.py

Source:figS04.py Github

copy

Full Screen

1"""2Figure S4 Caption: 3Basin-scale climatologies with Ifremer SWH (Solid blue) and CCMP2 WSP(Solid red).4Blue shading represents the standard error of the mean. Dotted blue is the annual5cycle weighted least-squares fitted to monthly climatology for mean SWH of the 6hemisphere ocean basin. Basins include (A) North Pacific, (B) North Atlantic, (C)7South Pacific, (D) South Atlantic, and (E) Indian Ocean where marginal seas and 8the equatorial regions across the Pacific and Atlantic oceans not considered.9"""10# Path to access python functions11import sys12sys.path.append("../tools/")13# Path to access intermediate data14data_path_i = "../data/ifremer_swh/"15data_path_c = "../data/ccmp2_wsp/"16data_path_decor = "../data/decor_scales/"17# libraries18import numpy as np19import matplotlib.pyplot as plt20from netCDF4 import Dataset, num2date21import cmocean.cm as cmo22# my functions23from data_processing import import_data24from averaging_stats import clima_mean25from lsf import weighted_least_square_fit, LSF_parameters26from regional_clima_figs import regional_clima, regional_clima_plot27# call IFREMER SWH and CCMP2 WSP processed data:28swh, time_s, lat_s, lon_s = import_data("IFREMER_swh", data_path_i)29wsp, time_w, lat_w, lon_w = import_data("CCMP2_wsp", data_path_c)30# Call decorrelation time scales31nc_swh = Dataset(data_path_decor + "IFREMER_swh_decor_time_scale.nc", "r")32decor_swh = nc_swh.variables["decor_scale"][:]33time_decor_swh = num2date(nc_swh.variables["time"][:], nc_swh.variables["time"].units)34nc_wsp = Dataset(data_path_decor + "CCMP2_wsp_decor_time_scale.nc", "r")35decor_wsp = nc_wsp.variables["decor_scale"][:]36time_decor_wsp = num2date(nc_wsp.variables["time"][:], nc_wsp.variables["time"].units)37# Set partition indices for the world oceans excluding the equatorial regions and marginal seas:38ind_nph_lat, ind_nph_lon = [116, 133], [106, 266]39ind_npl_lat, ind_npl_lon = [75, 117], [106, 275]40ind_nawh_lat, ind_nawh_lon = [116, 133], [295, 361]41ind_nawl_lat, ind_nawl_lon = [77, 117], [274, 361]42ind_nae_lat, ind_nae_lon = [77, 133], [0, 24]43ind_sp_lat, ind_sp_lon = [0, 60], [131, 292]44ind_saw_lat, ind_saw_lon = [0, 68], [291, 360]45ind_sae_lat, ind_sae_lon = [0, 68], [0, 24]46ind_nioh_lat, ind_nioh_lon = [89, 95], [60, 105]47ind_niol_lat, ind_niol_lon = [77, 90], [51, 105]48ind_mioh_lat, ind_mioh_lon = [69, 78], [40, 98]49ind_miol_lat, ind_miol_lon = [59, 70], [59, 70]50ind_sio_lat, ind_sio_lon = [0, 60], [23, 132]51########### CCMP2 WSP ###########52# Calculate monthly climatologies for SWH and WSP data and decorrelation scales:53wsp_clima_dict = clima_mean(date_time=np.ma.array(time_w), data=wsp)54wsp_mean_c = np.ma.array(wsp_clima_dict["mean"])55wsp_var_c = np.ma.array(wsp_clima_dict["var"])56wsp_n_c = np.ma.array(wsp_clima_dict["N"])57decor_clima_dict_w = clima_mean(date_time=time_decor_wsp, data=decor_wsp)58decor_mean_wsp_c = np.ma.array(decor_clima_dict_w["mean"])59# Partition mean, variance, number of observations, and decorrelation scales60####### Mean #######61wsp_nph = wsp_mean_c[62 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]63]64wsp_npl = wsp_mean_c[65 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]66]67wsp_nawh = wsp_mean_c[68 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]69]70wsp_nawl = wsp_mean_c[71 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]72]73wsp_nae = wsp_mean_c[74 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]75]76wsp_sp = wsp_mean_c[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]77wsp_saw = wsp_mean_c[78 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]79]80wsp_sae = wsp_mean_c[81 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]82]83wsp_nioh = wsp_mean_c[84 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]85]86wsp_niol = wsp_mean_c[87 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]88]89wsp_mioh = wsp_mean_c[90 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]91]92wsp_miol = wsp_mean_c[93 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]94]95wsp_sio = wsp_mean_c[96 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]97]98wsp_reg = [99 wsp_nph,100 wsp_npl,101 wsp_nawh,102 wsp_nawl,103 wsp_nae,104 wsp_sp,105 wsp_saw,106 wsp_sae,107 wsp_nioh,108 wsp_niol,109 wsp_mioh,110 wsp_miol,111 wsp_sio,112]113####### Variance #######114wsp_sig_nph = wsp_var_c[115 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]116]117wsp_sig_npl = wsp_var_c[118 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]119]120wsp_sig_nawh = wsp_var_c[121 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]122]123wsp_sig_nawl = wsp_var_c[124 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]125]126wsp_sig_nae = wsp_var_c[127 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]128]129wsp_sig_sp = wsp_var_c[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]130wsp_sig_saw = wsp_var_c[131 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]132]133wsp_sig_sae = wsp_var_c[134 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]135]136wsp_sig_nioh = wsp_var_c[137 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]138]139wsp_sig_niol = wsp_var_c[140 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]141]142wsp_sig_mioh = wsp_var_c[143 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]144]145wsp_sig_miol = wsp_var_c[146 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]147]148wsp_sig_sio = wsp_var_c[149 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]150]151wsp_reg_sig = [152 wsp_sig_nph,153 wsp_sig_npl,154 wsp_sig_nawh,155 wsp_sig_nawl,156 wsp_sig_nae,157 wsp_sig_sp,158 wsp_sig_saw,159 wsp_sig_sae,160 wsp_sig_nioh,161 wsp_sig_niol,162 wsp_sig_mioh,163 wsp_sig_miol,164 wsp_sig_sio,165]166####### Number of data points #######167wsp_n_nph = wsp_n_c[:, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]]168wsp_n_npl = wsp_n_c[:, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]]169wsp_n_nawh = wsp_n_c[170 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]171]172wsp_n_nawl = wsp_n_c[173 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]174]175wsp_n_nae = wsp_n_c[:, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]]176wsp_n_sp = wsp_n_c[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]177wsp_n_saw = wsp_n_c[:, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]]178wsp_n_sae = wsp_n_c[:, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]]179wsp_n_nioh = wsp_n_c[180 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]181]182wsp_n_niol = wsp_n_c[183 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]184]185wsp_n_mioh = wsp_n_c[186 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]187]188wsp_n_miol = wsp_n_c[189 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]190]191wsp_n_sio = wsp_n_c[:, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]]192wsp_reg_n = [193 wsp_nph,194 wsp_n_npl,195 wsp_n_nawh,196 wsp_n_nawl,197 wsp_n_nae,198 wsp_n_sp,199 wsp_n_saw,200 wsp_n_sae,201 wsp_n_nioh,202 wsp_n_niol,203 wsp_n_mioh,204 wsp_n_miol,205 wsp_n_sio,206]207####### Decorrelation time scale #######208decor_mean_wsp_nph = decor_mean_wsp_c[209 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]210]211decor_mean_wsp_npl = decor_mean_wsp_c[212 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]213]214decor_mean_wsp_nawh = decor_mean_wsp_c[215 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]216]217decor_mean_wsp_nawl = decor_mean_wsp_c[218 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]219]220decor_mean_wsp_nae = decor_mean_wsp_c[221 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]222]223decor_mean_wsp_sp = decor_mean_wsp_c[224 :, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]225]226decor_mean_wsp_saw = decor_mean_wsp_c[227 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]228]229decor_mean_wsp_sae = decor_mean_wsp_c[230 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]231]232decor_mean_wsp_nioh = decor_mean_wsp_c[233 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]234]235decor_mean_wsp_niol = decor_mean_wsp_c[236 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]237]238decor_mean_wsp_mioh = decor_mean_wsp_c[239 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]240]241decor_mean_wsp_miol = decor_mean_wsp_c[242 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]243]244decor_mean_wsp_sio = decor_mean_wsp_c[245 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]246]247wsp_reg_dcor = [248 decor_mean_wsp_nph,249 decor_mean_wsp_npl,250 decor_mean_wsp_nawh,251 decor_mean_wsp_nawl,252 decor_mean_wsp_nae,253 decor_mean_wsp_sp,254 decor_mean_wsp_saw,255 decor_mean_wsp_sae,256 decor_mean_wsp_nioh,257 decor_mean_wsp_niol,258 decor_mean_wsp_mioh,259 decor_mean_wsp_miol,260 decor_mean_wsp_sio,261]262# For each partition:263# Compute Mean264wsp_reg_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in wsp_reg]265wsp_reg_m_n = [266 np.ma.mean(np.ma.array([wsp_reg_m[0], wsp_reg_m[1]]), axis=0),267 np.ma.mean(np.ma.array([wsp_reg_m[2], wsp_reg_m[3], wsp_reg_m[4]]), axis=0),268 wsp_reg_m[5],269 np.ma.mean(np.ma.array([wsp_reg_m[6], wsp_reg_m[7]]), axis=0),270 np.ma.mean(271 np.ma.array(272 [wsp_reg_m[8], wsp_reg_m[9], wsp_reg_m[10], wsp_reg_m[11], wsp_reg_m[12]]273 ),274 axis=0,275 ),276]277# Compute average Variance278wsp_reg_var_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in wsp_reg_sig]279wsp_reg_var_m_n = [280 np.ma.mean(np.ma.array([wsp_reg_var_m[0], wsp_reg_var_m[1]]), axis=0),281 np.ma.mean(282 np.ma.array([wsp_reg_var_m[2], wsp_reg_var_m[3], wsp_reg_var_m[4]]), axis=0283 ),284 wsp_reg_var_m[5],285 np.ma.mean(np.ma.array([wsp_reg_var_m[6], wsp_reg_var_m[7]]), axis=0),286 np.ma.mean(287 np.ma.array(288 [289 wsp_reg_var_m[8],290 wsp_reg_var_m[9],291 wsp_reg_var_m[10],292 wsp_reg_var_m[11],293 wsp_reg_var_m[12],294 ]295 ),296 axis=0,297 ),298]299# compute the average of the decorrelation time scale and number of data points for each region:300wsp_reg_dcor_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in wsp_reg_dcor]301wsp_reg_dcor_m_n = [302 np.ma.mean(np.ma.array([wsp_reg_dcor_m[0], wsp_reg_dcor_m[1]]), axis=0),303 np.ma.mean(304 np.ma.array([wsp_reg_dcor_m[2], wsp_reg_dcor_m[3], wsp_reg_dcor_m[4]]), axis=0305 ),306 wsp_reg_dcor_m[5],307 np.ma.mean(np.ma.array([wsp_reg_dcor_m[6], wsp_reg_dcor_m[7]]), axis=0),308 np.ma.mean(309 np.ma.array(310 [311 wsp_reg_dcor_m[8],312 wsp_reg_dcor_m[9],313 wsp_reg_dcor_m[10],314 wsp_reg_dcor_m[11],315 wsp_reg_dcor_m[12],316 ]317 ),318 axis=0,319 ),320]321# compute the average of number of data points for each region:322wsp_reg_n_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in wsp_reg_n]323wsp_reg_n_m_n = [324 np.ma.mean(np.ma.array([wsp_reg_n_m[0], wsp_reg_n_m[1]]), axis=0),325 np.ma.mean(np.ma.array([wsp_reg_n_m[2], wsp_reg_n_m[3], wsp_reg_n_m[4]]), axis=0),326 wsp_reg_n_m[5],327 np.ma.mean(np.ma.array([wsp_reg_n_m[6], wsp_reg_n_m[7]]), axis=0),328 np.ma.mean(329 np.ma.array(330 [331 wsp_reg_n_m[8],332 wsp_reg_n_m[9],333 wsp_reg_n_m[10],334 wsp_reg_n_m[11],335 wsp_reg_n_m[12],336 ]337 ),338 axis=0,339 ),340]341# Compute degrees of freedom or N_effective for stdm calculation:342n_eff_reg = []343for ireg in range(5):344 n_eff_reg.append(wsp_reg_n_m_n[ireg] / wsp_reg_dcor_m_n[0])345# compute the standard error of the mean346wsp_reg_stdm = []347for ireg in range(5):348 wsp_reg_stdm.append(np.sqrt(wsp_reg_var_m_n[ireg]) / np.sqrt(n_eff_reg[ireg]))349# Perform a weighted least squares annual cycle fit to the mean regional data350hfit_reg_wsp = []351for ireg in range(5):352 # Perform weigthed least squares fit353 hfit, x_data, x_data_sigma = weighted_least_square_fit(354 data=np.ma.copy(wsp_reg_m_n[ireg]),355 sigma=np.ma.copy(wsp_reg_stdm[ireg]),356 trend="sinusoidal",357 parameters=3,358 period=12,359 )360 # save data361 hfit_reg_wsp.append(hfit)362# Change order of climatologies variables and fits for SH partitions:363####### Climatology #######364wsp_reg_m_n[2] = np.reshape(365 np.ma.array([wsp_reg_m_n[2][6:13], wsp_reg_m_n[2][0:6]]), (1, 12)366)[0]367wsp_reg_m_n[3] = np.reshape(368 np.ma.array([wsp_reg_m_n[3][6:13], wsp_reg_m_n[3][0:6]]), (1, 12)369)[0]370wsp_reg_m_n[4] = np.reshape(371 np.ma.array([wsp_reg_m_n[4][6:13], wsp_reg_m_n[4][0:6]]), (1, 12)372)[0]373####### stdm #######374wsp_reg_stdm[2] = np.reshape(375 np.ma.array([wsp_reg_stdm[2][6:13], wsp_reg_stdm[2][0:6]]), (1, 12)376)[0]377wsp_reg_stdm[3] = np.reshape(378 np.ma.array([wsp_reg_stdm[3][6:13], wsp_reg_stdm[3][0:6]]), (1, 12)379)[0]380wsp_reg_stdm[4] = np.reshape(381 np.ma.array([wsp_reg_stdm[4][6:13], wsp_reg_stdm[4][0:6]]), (1, 12)382)[0]383####### fits #######384hfit_reg_wsp[2] = np.reshape(385 np.ma.array([hfit_reg_wsp[2][6:13], hfit_reg_wsp[2][0:6]]), (1, 12)386)[0]387hfit_reg_wsp[3] = np.reshape(388 np.ma.array([hfit_reg_wsp[3][6:13], hfit_reg_wsp[3][0:6]]), (1, 12)389)[0]390hfit_reg_wsp[4] = np.reshape(391 np.ma.array([hfit_reg_wsp[4][6:13], hfit_reg_wsp[4][0:6]]), (1, 12)392)[0]393########### IFREMER SWH ###########394# Calculate monthly climatologies for SWH and WSP data and decorrelation scales:395swh_clima_dict = clima_mean(date_time=np.ma.array(time_s), data=swh)396swh_mean_i = np.ma.array(swh_clima_dict["mean"])397swh_var_i = np.ma.array(swh_clima_dict["var"])398swh_n_i = np.ma.array(swh_clima_dict["N"])399decor_clima_dict_s = clima_mean(date_time=time_decor_swh, data=decor_swh)400decor_mean_swh_i = np.ma.array(decor_clima_dict_s["mean"])401# Partition mean, variance, number of observations, and decorrelation scales402####### Mean #######403swh_nph = swh_mean_i[404 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]405]406swh_npl = swh_mean_i[407 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]408]409swh_nawh = swh_mean_i[410 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]411]412swh_nawl = swh_mean_i[413 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]414]415swh_nae = swh_mean_i[416 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]417]418swh_sp = swh_mean_i[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]419swh_saw = swh_mean_i[420 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]421]422swh_sae = swh_mean_i[423 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]424]425swh_nioh = swh_mean_i[426 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]427]428swh_niol = swh_mean_i[429 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]430]431swh_mioh = swh_mean_i[432 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]433]434swh_miol = swh_mean_i[435 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]436]437swh_sio = swh_mean_i[438 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]439]440swh_reg = [441 swh_nph,442 swh_npl,443 swh_nawh,444 swh_nawl,445 swh_nae,446 swh_sp,447 swh_saw,448 swh_sae,449 swh_nioh,450 swh_niol,451 swh_mioh,452 swh_miol,453 swh_sio,454]455####### Variance #######456swh_sig_nph = swh_var_i[457 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]458]459swh_sig_npl = swh_var_i[460 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]461]462swh_sig_nawh = swh_var_i[463 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]464]465swh_sig_nawl = swh_var_i[466 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]467]468swh_sig_nae = swh_var_i[469 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]470]471swh_sig_sp = swh_var_i[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]472swh_sig_saw = swh_var_i[473 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]474]475swh_sig_sae = swh_var_i[476 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]477]478swh_sig_nioh = swh_var_i[479 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]480]481swh_sig_niol = swh_var_i[482 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]483]484swh_sig_mioh = swh_var_i[485 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]486]487swh_sig_miol = swh_var_i[488 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]489]490swh_sig_sio = swh_var_i[491 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]492]493swh_reg_sig = [494 swh_sig_nph,495 swh_sig_npl,496 swh_sig_nawh,497 swh_sig_nawl,498 swh_sig_nae,499 swh_sig_sp,500 swh_sig_saw,501 swh_sig_sae,502 swh_sig_nioh,503 swh_sig_niol,504 swh_sig_mioh,505 swh_sig_miol,506 swh_sig_sio,507]508####### Number of data points #######509swh_n_nph = swh_n_i[:, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]]510swh_n_npl = swh_n_i[:, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]]511swh_n_nawh = swh_n_i[512 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]513]514swh_n_nawl = swh_n_i[515 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]516]517swh_n_nae = swh_n_i[:, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]]518swh_n_sp = swh_n_i[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]519swh_n_saw = swh_n_i[:, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]]520swh_n_sae = swh_n_i[:, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]]521swh_n_nioh = swh_n_i[522 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]523]524swh_n_niol = swh_n_i[525 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]526]527swh_n_mioh = swh_n_i[528 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]529]530swh_n_miol = swh_n_i[531 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]532]533swh_n_sio = swh_n_i[:, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]]534swh_reg_n = [535 swh_nph,536 swh_n_npl,537 swh_n_nawh,538 swh_n_nawl,539 swh_n_nae,540 swh_n_sp,541 swh_n_saw,542 swh_n_sae,543 swh_n_nioh,544 swh_n_niol,545 swh_n_mioh,546 swh_n_miol,547 swh_n_sio,548]549####### Decorrelation time scale #######550decor_mean_swh_nph = decor_mean_swh_i[551 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]552]553decor_mean_swh_npl = decor_mean_swh_i[554 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]555]556decor_mean_swh_nawh = decor_mean_swh_i[557 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]558]559decor_mean_swh_nawl = decor_mean_swh_i[560 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]561]562decor_mean_swh_nae = decor_mean_swh_i[563 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]564]565decor_mean_swh_sp = decor_mean_swh_i[566 :, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]567]568decor_mean_swh_saw = decor_mean_swh_i[569 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]570]571decor_mean_swh_sae = decor_mean_swh_i[572 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]573]574decor_mean_swh_nioh = decor_mean_swh_i[575 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]576]577decor_mean_swh_niol = decor_mean_swh_i[578 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]579]580decor_mean_swh_mioh = decor_mean_swh_i[581 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]582]583decor_mean_swh_miol = decor_mean_swh_i[584 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]585]586decor_mean_swh_sio = decor_mean_swh_i[587 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]588]589swh_reg_dcor = [590 decor_mean_swh_nph,591 decor_mean_swh_npl,592 decor_mean_swh_nawh,593 decor_mean_swh_nawl,594 decor_mean_swh_nae,595 decor_mean_swh_sp,596 decor_mean_swh_saw,597 decor_mean_swh_sae,598 decor_mean_swh_nioh,599 decor_mean_swh_niol,600 decor_mean_swh_mioh,601 decor_mean_swh_miol,602 decor_mean_swh_sio,603]604# For each partition:605# Compute Mean606swh_reg_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg]607swh_reg_m_n = [608 np.ma.mean(np.ma.array([swh_reg_m[0], swh_reg_m[1]]), axis=0),609 np.ma.mean(np.ma.array([swh_reg_m[2], swh_reg_m[3], swh_reg_m[4]]), axis=0),610 swh_reg_m[5],611 np.ma.mean(np.ma.array([swh_reg_m[6], swh_reg_m[7]]), axis=0),612 np.ma.mean(613 np.ma.array(614 [swh_reg_m[8], swh_reg_m[9], swh_reg_m[10], swh_reg_m[11], swh_reg_m[12]]615 ),616 axis=0,617 ),618]619# Compute average Variance620swh_reg_var_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg_sig]621swh_reg_var_m_n = [622 np.ma.mean(np.ma.array([swh_reg_var_m[0], swh_reg_var_m[1]]), axis=0),623 np.ma.mean(624 np.ma.array([swh_reg_var_m[2], swh_reg_var_m[3], swh_reg_var_m[4]]), axis=0625 ),626 swh_reg_var_m[5],627 np.ma.mean(np.ma.array([swh_reg_var_m[6], swh_reg_var_m[7]]), axis=0),628 np.ma.mean(629 np.ma.array(630 [631 swh_reg_var_m[8],632 swh_reg_var_m[9],633 swh_reg_var_m[10],634 swh_reg_var_m[11],635 swh_reg_var_m[12],636 ]637 ),638 axis=0,639 ),640]641# compute the average of the decorrelation time scale and number of data points for each region:642swh_reg_dcor_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg_dcor]643swh_reg_dcor_m_n = [644 np.ma.mean(np.ma.array([swh_reg_dcor_m[0], swh_reg_dcor_m[1]]), axis=0),645 np.ma.mean(646 np.ma.array([swh_reg_dcor_m[2], swh_reg_dcor_m[3], swh_reg_dcor_m[4]]), axis=0647 ),648 swh_reg_dcor_m[5],649 np.ma.mean(np.ma.array([swh_reg_dcor_m[6], swh_reg_dcor_m[7]]), axis=0),650 np.ma.mean(651 np.ma.array(652 [653 swh_reg_dcor_m[8],654 swh_reg_dcor_m[9],655 swh_reg_dcor_m[10],656 swh_reg_dcor_m[11],657 swh_reg_dcor_m[12],658 ]659 ),660 axis=0,661 ),662]663# compute the average of number of data points for each region:664swh_reg_n_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg_n]665swh_reg_n_m_n = [666 np.ma.mean(np.ma.array([swh_reg_n_m[0], swh_reg_n_m[1]]), axis=0),667 np.ma.mean(np.ma.array([swh_reg_n_m[2], swh_reg_n_m[3], swh_reg_n_m[4]]), axis=0),668 swh_reg_n_m[5],669 np.ma.mean(np.ma.array([swh_reg_n_m[6], swh_reg_n_m[7]]), axis=0),670 np.ma.mean(671 np.ma.array(672 [673 swh_reg_n_m[8],674 swh_reg_n_m[9],675 swh_reg_n_m[10],676 swh_reg_n_m[11],677 swh_reg_n_m[12],678 ]679 ),680 axis=0,681 ),682]683# Compute degrees of freedom or N_effective for stdm calculation:684n_eff_reg = []685for ireg in range(5):686 n_eff_reg.append(swh_reg_n_m_n[ireg] / swh_reg_dcor_m_n[0])687# compute the standard error of the mean688swh_reg_stdm = []689for ireg in range(5):690 swh_reg_stdm.append(np.sqrt(swh_reg_var_m_n[ireg]) / np.sqrt(n_eff_reg[ireg]))691# Perform a weighted least squares annual cycle fit to the mean regional data692hfit_reg_swh = []693for ireg in range(5):694 # Perform weigthed least squares fit695 hfit, x_data, x_data_sigma = weighted_least_square_fit(696 data=np.ma.copy(swh_reg_m_n[ireg]),697 sigma=np.ma.copy(swh_reg_stdm[ireg]),698 trend="sinusoidal",699 parameters=3,700 period=12,701 )702 # save data703 hfit_reg_swh.append(hfit)704# Change order of climatologies variables and fits for SH partitions:705####### Climatology #######706swh_reg_m_n[2] = np.reshape(707 np.ma.array([swh_reg_m_n[2][6:13], swh_reg_m_n[2][0:6]]), (1, 12)708)[0]709swh_reg_m_n[3] = np.reshape(710 np.ma.array([swh_reg_m_n[3][6:13], swh_reg_m_n[3][0:6]]), (1, 12)711)[0]712swh_reg_m_n[4] = np.reshape(713 np.ma.array([swh_reg_m_n[4][6:13], swh_reg_m_n[4][0:6]]), (1, 12)714)[0]715####### stdm #######716swh_reg_stdm[2] = np.reshape(717 np.ma.array([swh_reg_stdm[2][6:13], swh_reg_stdm[2][0:6]]), (1, 12)718)[0]719swh_reg_stdm[3] = np.reshape(720 np.ma.array([swh_reg_stdm[3][6:13], swh_reg_stdm[3][0:6]]), (1, 12)721)[0]722swh_reg_stdm[4] = np.reshape(723 np.ma.array([swh_reg_stdm[4][6:13], swh_reg_stdm[4][0:6]]), (1, 12)724)[0]725####### fits #######726hfit_reg_swh[2] = np.reshape(727 np.ma.array([hfit_reg_swh[2][6:13], hfit_reg_swh[2][0:6]]), (1, 12)728)[0]729hfit_reg_swh[3] = np.reshape(730 np.ma.array([hfit_reg_swh[3][6:13], hfit_reg_swh[3][0:6]]), (1, 12)731)[0]732hfit_reg_swh[4] = np.reshape(733 np.ma.array([hfit_reg_swh[4][6:13], hfit_reg_swh[4][0:6]]), (1, 12)734)[0]735# Set variables for plotting736time = np.arange(1, 13, 1)737time_ticks_nh = [738 "Jan",739 "Feb",740 "Mar",741 "Apr",742 "May",743 "Jun",744 "Jul",745 "Aug",746 "Sep",747 "Oct",748 "Nov",749 "Dec",750]751time_ticks_sh = [752 "Jul",753 "Aug",754 "Sep",755 "Oct",756 "Nov",757 "Dec",758 "Jan",759 "Feb",760 "Mar",761 "Apr",762 "May",763 "Jun",764]765xlim = [0, 13]766ylim = [[1, 4], [4, 10]]767# Create figure and axes768fig, axes = plt.subplots(3, 2, figsize=(16, 20))769ax1, ax2, ax3, ax4, ax5, ax6 = axes.flatten()770######## Subplot 1 ########771# North Pacific772regional_clima_plot(773 ax1,774 swh_reg_m_n[0],775 swh_reg_stdm[0],776 hfit_reg_swh[0],777 wsp_reg_m_n[0],778 wsp_reg_stdm[0],779 hfit_reg_wsp[0],780 None,781 None,782 None,783 None,784 time,785 time_ticks_nh,786 xlim,787 ylim,788 subplot_label="A",789 fontsize=20,790 linewidth=1.5,791 task="IC",792 grid=False,793)794######## Subplot 2 ########795# North Atlantic796regional_clima_plot(797 ax2,798 swh_reg_m_n[1],799 swh_reg_stdm[1],800 hfit_reg_swh[1],801 wsp_reg_m_n[1],802 wsp_reg_stdm[1],803 hfit_reg_wsp[1],804 None,805 None,806 None,807 None,808 time,809 time_ticks_nh,810 xlim,811 ylim,812 subplot_label="B",813 fontsize=20,814 linewidth=1.5,815 task="IC",816 grid=False,817)818########### Subplot 3 ###########819# South pacific820regional_clima_plot(821 ax3,822 swh_reg_m_n[2],823 swh_reg_stdm[2],824 hfit_reg_swh[2],825 wsp_reg_m_n[2],826 wsp_reg_stdm[2],827 hfit_reg_wsp[2],828 None,829 None,830 None,831 None,832 time,833 time_ticks_sh,834 xlim,835 ylim,836 subplot_label="C",837 fontsize=20,838 linewidth=1.5,839 task="IC",840 grid=False,841)842########### Subplot 4 ###########843# South Atlantic844regional_clima_plot(845 ax4,846 swh_reg_m_n[3],847 swh_reg_stdm[3],848 hfit_reg_swh[3],849 wsp_reg_m_n[3],850 wsp_reg_stdm[3],851 hfit_reg_wsp[3],852 None,853 None,854 None,855 None,856 time,857 time_ticks_sh,858 xlim,859 ylim,860 subplot_label="D",861 fontsize=20,862 linewidth=1.5,863 task="IC",864 grid=False,865)866########### Subplot 5 ###########867# Indian ocean868regional_clima_plot(869 ax5,870 swh_reg_m_n[4],871 swh_reg_stdm[4],872 hfit_reg_swh[4],873 wsp_reg_m_n[4],874 wsp_reg_stdm[4],875 hfit_reg_wsp[4],876 None,877 None,878 None,879 None,880 time,881 time_ticks_sh,882 xlim,883 ylim,884 subplot_label="E",885 fontsize=20,886 linewidth=1.5,887 task="IC",888 grid=False,889)890########### Subplot 6 ###########891# suppress output for axis 6892ax6.axis("off")893# adjust layout of subplots:894fig.tight_layout()895# adjust spacing for the entire figure896fig.subplots_adjust(wspace=0.35, hspace=0.2)897# save figure:...

Full Screen

Full Screen

fig06.py

Source:fig06.py Github

copy

Full Screen

1"""2Figure 6 Caption: 3(left column) Northern Hemisphere wind speed in SWARs, averaged over June, July,4and August. (right column) IFREMER SWH (solid blue) and CCMP2 WSP (solid red) 5climatologies extracted from the outlined 4$^{\circ}$ by 4$^{\circ}$ boxes within6SWARs. Blue shading represents the standard error of the mean, dotted blue is 7the annual cycle weighted least-squares fitted to monthly climatology for mean 8SWH of the hemisphere ocean basin the SWAR is located in, and black solid is the 9residual between SWH regional climatology and annual cycle. SWARs include 10Northern California (A and B), Southern Caribbean Sea (C and D), and North Africa11near the coast of Morocco and western Sahara (E and F). (Comparison plots showing12equivalent quantities for WW3 and IFREMER SWH and CFSR and CCMP2 WSP can be found13in Figure~S9A,C,E of the supplementary material).14"""15# Path to access python functions16import sys17sys.path.append("../tools/")18# Path to access intermediate data19data_path_i = "../data/ifremer_swh/"20data_path_c = "../data/ccmp2_wsp/"21data_path_decor = "../data/decor_scales/"22# libraries23import numpy as np24from netCDF4 import Dataset, num2date25import matplotlib.pyplot as plt26import cartopy.crs as ccrs27import cmocean.cm as cmo28import matplotlib.patches as mpatches29# my functions30from data_processing import import_data31from averaging_stats import clima_mean, stat_moments_temporal32from lsf import weighted_least_square_fit, LSF_parameters33from regional_clima_figs import regional_clima, regional_clima_plot34import cartopy_figs as cart35# call IFREMER SWH and CCMP2 WSP processed data:36swh, time_s, lat_s, lon_s = import_data("IFREMER_swh", data_path_i)37wsp, time_w, lat_w, lon_w = import_data("CCMP2_wsp", data_path_c)38# Call decorrelation time scales39###### SWH ######40nc_swh = Dataset(data_path_decor + "IFREMER_swh_decor_time_scale.nc", "r")41decor_swh = nc_swh.variables["decor_scale"][:]42time_decor_swh = num2date(nc_swh.variables["time"][:], nc_swh.variables["time"].units)43###### WSP ######44nc_wsp = Dataset(data_path_decor + "CCMP2_wsp_decor_time_scale.nc", "r")45decor_wsp = nc_wsp.variables["decor_scale"][:]46time_decor_wsp = num2date(nc_wsp.variables["time"][:], nc_wsp.variables["time"].units)47# Compute WSP statistical moments seasonally48wsp_stats_s = stat_moments_temporal(wsp, time_w, "seasonally", "sample")49wsp_moments_mean = np.ma.array(wsp_stats_s["mean"])50# Calculate monthly climatologies for SWH and WSP data and decorrelation scales:51###### SWH ######52swh_clima_dict = clima_mean(date_time=np.ma.array(time_s), data=swh)53swh_mean_i = np.ma.array(swh_clima_dict["mean"])54swh_var_i = np.ma.array(swh_clima_dict["var"])55swh_n_i = np.ma.array(swh_clima_dict["N"])56decor_clima_dict_s = clima_mean(date_time=time_decor_swh, data=decor_swh)57decor_mean_swh_i = np.ma.array(decor_clima_dict_s["mean"])58###### WSP ######59wsp_clima_dict = clima_mean(date_time=np.ma.array(time_w), data=wsp)60wsp_mean_c = np.ma.array(wsp_clima_dict["mean"])61wsp_var_c = np.ma.array(wsp_clima_dict["var"])62wsp_n_c = np.ma.array(wsp_clima_dict["N"])63decor_clima_dict_w = clima_mean(date_time=time_decor_wsp, data=decor_wsp)64decor_mean_wsp_c = np.ma.array(decor_clima_dict_w["mean"])65## Compute basin-scale annual cycle fit ##66# Set partition indices for the world oceans excluding the equatorial regions and marginal seas:67ind_nph_lat, ind_nph_lon = [116, 133], [106, 266]68ind_npl_lat, ind_npl_lon = [75, 117], [106, 275]69ind_nawh_lat, ind_nawh_lon = [116, 133], [295, 361]70ind_nawl_lat, ind_nawl_lon = [77, 117], [274, 361]71ind_nae_lat, ind_nae_lon = [77, 133], [0, 24]72ind_sp_lat, ind_sp_lon = [0, 60], [131, 292]73ind_saw_lat, ind_saw_lon = [0, 68], [291, 360]74ind_sae_lat, ind_sae_lon = [0, 68], [0, 24]75ind_nioh_lat, ind_nioh_lon = [89, 95], [60, 105]76ind_niol_lat, ind_niol_lon = [77, 90], [51, 105]77ind_mioh_lat, ind_mioh_lon = [69, 78], [40, 98]78ind_miol_lat, ind_miol_lon = [59, 70], [59, 70]79ind_sio_lat, ind_sio_lon = [0, 60], [23, 132]80# Partition mean, variance, number of observations, and decorrelation scales81####### Mean #######82swh_nph = swh_mean_i[83 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]84]85swh_npl = swh_mean_i[86 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]87]88swh_nawh = swh_mean_i[89 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]90]91swh_nawl = swh_mean_i[92 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]93]94swh_nae = swh_mean_i[95 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]96]97swh_sp = swh_mean_i[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]98swh_saw = swh_mean_i[99 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]100]101swh_sae = swh_mean_i[102 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]103]104swh_nioh = swh_mean_i[105 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]106]107swh_niol = swh_mean_i[108 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]109]110swh_mioh = swh_mean_i[111 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]112]113swh_miol = swh_mean_i[114 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]115]116swh_sio = swh_mean_i[117 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]118]119swh_reg = [120 swh_nph,121 swh_npl,122 swh_nawh,123 swh_nawl,124 swh_nae,125 swh_sp,126 swh_saw,127 swh_sae,128 swh_nioh,129 swh_niol,130 swh_mioh,131 swh_miol,132 swh_sio,133]134####### Variance #######135swh_sig_nph = swh_var_i[136 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]137]138swh_sig_npl = swh_var_i[139 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]140]141swh_sig_nawh = swh_var_i[142 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]143]144swh_sig_nawl = swh_var_i[145 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]146]147swh_sig_nae = swh_var_i[148 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]149]150swh_sig_sp = swh_var_i[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]151swh_sig_saw = swh_var_i[152 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]153]154swh_sig_sae = swh_var_i[155 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]156]157swh_sig_nioh = swh_var_i[158 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]159]160swh_sig_niol = swh_var_i[161 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]162]163swh_sig_mioh = swh_var_i[164 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]165]166swh_sig_miol = swh_var_i[167 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]168]169swh_sig_sio = swh_var_i[170 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]171]172swh_reg_sig = [173 swh_sig_nph,174 swh_sig_npl,175 swh_sig_nawh,176 swh_sig_nawl,177 swh_sig_nae,178 swh_sig_sp,179 swh_sig_saw,180 swh_sig_sae,181 swh_sig_nioh,182 swh_sig_niol,183 swh_sig_mioh,184 swh_sig_miol,185 swh_sig_sio,186]187####### Number of data points #######188swh_n_nph = swh_n_i[:, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]]189swh_n_npl = swh_n_i[:, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]]190swh_n_nawh = swh_n_i[191 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]192]193swh_n_nawl = swh_n_i[194 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]195]196swh_n_nae = swh_n_i[:, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]]197swh_n_sp = swh_n_i[:, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]]198swh_n_saw = swh_n_i[:, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]]199swh_n_sae = swh_n_i[:, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]]200swh_n_nioh = swh_n_i[201 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]202]203swh_n_niol = swh_n_i[204 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]205]206swh_n_mioh = swh_n_i[207 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]208]209swh_n_miol = swh_n_i[210 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]211]212swh_n_sio = swh_n_i[:, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]]213swh_reg_n = [214 swh_nph,215 swh_n_npl,216 swh_n_nawh,217 swh_n_nawl,218 swh_n_nae,219 swh_n_sp,220 swh_n_saw,221 swh_n_sae,222 swh_n_nioh,223 swh_n_niol,224 swh_n_mioh,225 swh_n_miol,226 swh_n_sio,227]228####### Decorrelation time scale #######229decor_mean_swh_nph = decor_mean_swh_i[230 :, ind_nph_lat[0] : ind_nph_lat[1], ind_nph_lon[0] : ind_nph_lon[1]231]232decor_mean_swh_npl = decor_mean_swh_i[233 :, ind_npl_lat[0] : ind_npl_lat[1], ind_npl_lon[0] : ind_nph_lon[1]234]235decor_mean_swh_nawh = decor_mean_swh_i[236 :, ind_nawh_lat[0] : ind_nawh_lat[1], ind_nawh_lon[0] : ind_nawh_lon[1]237]238decor_mean_swh_nawl = decor_mean_swh_i[239 :, ind_nawl_lat[0] : ind_nawl_lat[1], ind_nawl_lon[0] : ind_nawl_lon[1]240]241decor_mean_swh_nae = decor_mean_swh_i[242 :, ind_nae_lat[0] : ind_nae_lat[1], ind_nae_lon[0] : ind_nae_lon[1]243]244decor_mean_swh_sp = decor_mean_swh_i[245 :, ind_sp_lat[0] : ind_sp_lat[1], ind_sp_lon[0] : ind_sp_lon[1]246]247decor_mean_swh_saw = decor_mean_swh_i[248 :, ind_saw_lat[0] : ind_saw_lat[1], ind_saw_lon[0] : ind_saw_lon[1]249]250decor_mean_swh_sae = decor_mean_swh_i[251 :, ind_sae_lat[0] : ind_sae_lat[1], ind_sae_lon[0] : ind_sae_lon[1]252]253decor_mean_swh_nioh = decor_mean_swh_i[254 :, ind_nioh_lat[0] : ind_nioh_lat[1], ind_nioh_lon[0] : ind_nioh_lon[1]255]256decor_mean_swh_niol = decor_mean_swh_i[257 :, ind_niol_lat[0] : ind_niol_lat[1], ind_niol_lon[0] : ind_niol_lon[1]258]259decor_mean_swh_mioh = decor_mean_swh_i[260 :, ind_mioh_lat[0] : ind_mioh_lat[1], ind_mioh_lon[0] : ind_mioh_lon[1]261]262decor_mean_swh_miol = decor_mean_swh_i[263 :, ind_miol_lat[0] : ind_miol_lat[1], ind_miol_lon[0] : ind_miol_lon[1]264]265decor_mean_swh_sio = decor_mean_swh_i[266 :, ind_sio_lat[0] : ind_sio_lat[1], ind_sio_lon[0] : ind_sio_lon[1]267]268swh_reg_dcor = [269 decor_mean_swh_nph,270 decor_mean_swh_npl,271 decor_mean_swh_nawh,272 decor_mean_swh_nawl,273 decor_mean_swh_nae,274 decor_mean_swh_sp,275 decor_mean_swh_saw,276 decor_mean_swh_sae,277 decor_mean_swh_nioh,278 decor_mean_swh_niol,279 decor_mean_swh_mioh,280 decor_mean_swh_miol,281 decor_mean_swh_sio,282]283# For each partition:284# Compute Mean285swh_reg_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg]286swh_reg_m_n = [287 np.ma.mean(np.ma.array([swh_reg_m[0], swh_reg_m[1]]), axis=0),288 np.ma.mean(np.ma.array([swh_reg_m[2], swh_reg_m[3], swh_reg_m[4]]), axis=0),289 swh_reg_m[5],290 np.ma.mean(np.ma.array([swh_reg_m[6], swh_reg_m[7]]), axis=0),291 np.ma.mean(292 np.ma.array(293 [swh_reg_m[8], swh_reg_m[9], swh_reg_m[10], swh_reg_m[11], swh_reg_m[12]]294 ),295 axis=0,296 ),297]298# Compute average Variance299swh_reg_var_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg_sig]300swh_reg_var_m_n = [301 np.ma.mean(np.ma.array([swh_reg_var_m[0], swh_reg_var_m[1]]), axis=0),302 np.ma.mean(303 np.ma.array([swh_reg_var_m[2], swh_reg_var_m[3], swh_reg_var_m[4]]), axis=0304 ),305 swh_reg_var_m[5],306 np.ma.mean(np.ma.array([swh_reg_var_m[6], swh_reg_var_m[7]]), axis=0),307 np.ma.mean(308 np.ma.array(309 [310 swh_reg_var_m[8],311 swh_reg_var_m[9],312 swh_reg_var_m[10],313 swh_reg_var_m[11],314 swh_reg_var_m[12],315 ]316 ),317 axis=0,318 ),319]320# compute the average of the decorrelation time scale and number of data points for each region:321swh_reg_dcor_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg_dcor]322swh_reg_dcor_m_n = [323 np.ma.mean(np.ma.array([swh_reg_dcor_m[0], swh_reg_dcor_m[1]]), axis=0),324 np.ma.mean(325 np.ma.array([swh_reg_dcor_m[2], swh_reg_dcor_m[3], swh_reg_dcor_m[4]]), axis=0326 ),327 swh_reg_dcor_m[5],328 np.ma.mean(np.ma.array([swh_reg_dcor_m[6], swh_reg_dcor_m[7]]), axis=0),329 np.ma.mean(330 np.ma.array(331 [332 swh_reg_dcor_m[8],333 swh_reg_dcor_m[9],334 swh_reg_dcor_m[10],335 swh_reg_dcor_m[11],336 swh_reg_dcor_m[12],337 ]338 ),339 axis=0,340 ),341]342# compute the average of number of data points for each region:343swh_reg_n_m = [np.ma.mean(np.ma.mean(ireg, axis=1), axis=1) for ireg in swh_reg_n]344swh_reg_n_m_n = [345 np.ma.mean(np.ma.array([swh_reg_n_m[0], swh_reg_n_m[1]]), axis=0),346 np.ma.mean(np.ma.array([swh_reg_n_m[2], swh_reg_n_m[3], swh_reg_n_m[4]]), axis=0),347 swh_reg_n_m[5],348 np.ma.mean(np.ma.array([swh_reg_n_m[6], swh_reg_n_m[7]]), axis=0),349 np.ma.mean(350 np.ma.array(351 [352 swh_reg_n_m[8],353 swh_reg_n_m[9],354 swh_reg_n_m[10],355 swh_reg_n_m[11],356 swh_reg_n_m[12],357 ]358 ),359 axis=0,360 ),361]362# Compute degrees of freedom or N_effective for stdm calculation:363n_eff_reg = []364for ireg in range(5):365 n_eff_reg.append(swh_reg_n_m_n[ireg] / swh_reg_dcor_m_n[0])366# compute the standard error of the mean367swh_reg_stdm = []368for ireg in range(5):369 swh_reg_stdm.append(np.sqrt(swh_reg_var_m_n[ireg]) / np.sqrt(n_eff_reg[ireg]))370# Perform a weighted least squares annual cycle fit to the mean regional data371hfit_basin_swh, x_data_basin, x_data_sigma_basin = [], [], []372for ireg in range(5):373 # Perform weigthed least squares fit374 hfit, x_data, x_data_sigma = weighted_least_square_fit(375 data=np.ma.copy(swh_reg_m_n[ireg]),376 sigma=np.ma.copy(swh_reg_stdm[ireg]),377 trend="sinusoidal",378 parameters=3,379 period=12,380 )381 # save data382 hfit_basin_swh.append(hfit)383 x_data_basin.append(x_data)384 x_data_sigma_basin.append(x_data_sigma)385# Compute regional climatologies:386####### Northern California #######387# intialize variable388ngrid = 4389lon_grid = 232390lat_grid = 103391location = ["NH", "west"]392# compute SWH regional climatology393(394 swh_mean_nc,395 swh_stdm_nc,396 swh_hfit,397 swh_x_data,398 swh_residual,399 grid_cor_nc,400) = regional_clima(401 swh_mean_i,402 swh_var_i,403 swh_n_i,404 lon_s,405 lat_s,406 lon_grid,407 lat_grid,408 ngrid,409 decor_mean_swh_i,410 location,411 lsf="weighted",412 parameters=5,413)414# compute WSP regional climatology415(416 wsp_mean_nc,417 wsp_stdm_nc,418 wsp_hfit,419 wsp_x_data,420 wsp_residual,421 grid_cor_nc,422) = regional_clima(423 wsp_mean_c,424 wsp_var_c,425 wsp_n_c,426 lon_w,427 lat_w,428 lon_grid,429 lat_grid,430 ngrid,431 decor_mean_wsp_c,432 location,433 lsf="weighted",434 parameters=5,435)436# Perform weigthed least squares fit for basin-scale climatology projected onto regional climatology437hfit_reg_nc, x_data_reg, x_data_sigma_reg = weighted_least_square_fit(438 swh_mean_nc,439 swh_stdm_nc,440 trend="sinusoidal",441 parameters=2,442 period=12,443 phase=np.arctan2(x_data_basin[0][1], x_data_basin[0][2]),444)445####### Southern Caribbean #######446# intialize variable447ngrid = 4448lon_grid = 284449lat_grid = 80450location = ["NH", "west"]451# compute SWH regional climatology452(453 swh_mean_sc,454 swh_stdm_sc,455 swh_hfit,456 swh_x_data,457 swh_residual,458 grid_cor_sc,459) = regional_clima(460 swh_mean_i,461 swh_var_i,462 swh_n_i,463 lon_s,464 lat_s,465 lon_grid,466 lat_grid,467 ngrid,468 decor_mean_swh_i,469 location,470 lsf="weighted",471 parameters=5,472)473# compute WSP regional climatology474(475 wsp_mean_sc,476 wsp_stdm_sc,477 wsp_hfit,478 wsp_x_data,479 wsp_residual,480 grid_cor_sc,481) = regional_clima(482 wsp_mean_c,483 wsp_var_c,484 wsp_n_c,485 lon_w,486 lat_w,487 lon_grid,488 lat_grid,489 ngrid,490 decor_mean_wsp_c,491 location,492 lsf="weighted",493 parameters=5,494)495# Perform weigthed least squares fit for basin-scale climatology projected onto regional climatology496hfit_reg_sc, x_data_reg, x_data_sigma_reg = weighted_least_square_fit(497 swh_mean_sc,498 swh_stdm_sc,499 trend="sinusoidal",500 parameters=2,501 period=12,502 phase=np.arctan2(x_data_basin[1][1], x_data_basin[1][2]),503)504####### North Africa (Morocco) #######505# intialize variable506ngrid = 4507lon_grid = 345508lat_grid = 96509location = ["NH", "west"]510# compute SWH regional climatology511(512 swh_mean_na,513 swh_stdm_na,514 swh_hfit,515 swh_x_data,516 swh_residual,517 grid_cor_na,518) = regional_clima(519 swh_mean_i,520 swh_var_i,521 swh_n_i,522 lon_s,523 lat_s,524 lon_grid,525 lat_grid,526 ngrid,527 decor_mean_swh_i,528 location,529 lsf="weighted",530 parameters=5,531)532# compute WSP regional climatology533(534 wsp_mean_na,535 wsp_stdm_na,536 wsp_hfit,537 wsp_x_data,538 wsp_residual,539 grid_cor_na,540) = regional_clima(541 wsp_mean_c,542 wsp_var_c,543 wsp_n_c,544 lon_w,545 lat_w,546 lon_grid,547 lat_grid,548 ngrid,549 decor_mean_wsp_c,550 location,551 lsf="weighted",552 parameters=5,553)554# Perform weigthed least squares fit for basin-scale climatology projected onto regional climatology555hfit_reg_na, x_data_reg, x_data_sigma_reg = weighted_least_square_fit(556 swh_mean_na,557 swh_stdm_na,558 trend="sinusoidal",559 parameters=2,560 period=12,561 phase=np.arctan2(x_data_basin[1][1], x_data_basin[1][2]),562)563# Set variables for plotting564projection = ccrs.PlateCarree(central_longitude=180.0)565time = np.arange(1, 13, 1)566time_ticks = [567 "Jan",568 "Feb",569 "Mar",570 "Apr",571 "May",572 "Jun",573 "Jul",574 "Aug",575 "Sep",576 "Oct",577 "Nov",578 "Dec",579] # x-axis tick labels for NH580xlim = [0, 13]581ylim = [[-1, 4], [5, 10]]582levels = np.arange(2, 8.1, 0.1)583resolution = "10m"584# initialize subplot axes:585fig = plt.figure(figsize=(22, 28))586############## Subplot 1 ##############587# California coast588ax1 = fig.add_subplot(321, projection=ccrs.PlateCarree(central_longitude=180.0))589cart.set_subplots(590 ax1, projection, resolution, lon_min=44, lon_max=66, lat_min=30, lat_max=44591)592cs1 = ax1.contourf(593 lon_w,594 lat_w,595 wsp_moments_mean[2, :, :],596 levels,597 cmap=cmo.thermal,598 extend="both",599 transform=ccrs.PlateCarree(central_longitude=0.0),600)601cart.grid_lines_rc(602 ax=ax1,603 xticks=[-133, -129, -125, -121, -117],604 yticks=[28, 32, 36, 40, 44],605 fontsize=20,606 linewidth=1,607 color="gray",608 alpha=0.3,609 linestyle="--",610 grid=True,611)612cax1 = plt.axes([0.1, 0.06, 0.4, 0.03])613cart.set_cbar(614 cs1,615 cax1,616 fig,617 orientation="horizontal",618 extend="both",619 cbar_label="$m\,s^{-1}$",620 nbins=7,621 fontsize=20,622 cbar_ticks=[],623 task="regular",624)625cart.subplot_label(626 ax1,627 xdist_label=0.1,628 ydist_label=0.88,629 subplot_label="A",630 form="box",631 fs_shade=28,632 fs_main=20,633 color="black",634)635# Set regional climatology grid box636ax1.add_patch(637 mpatches.Rectangle(638 xy=[-129, 36],639 width=4,640 height=4,641 edgecolor="black",642 facecolor=None,643 linestyle="-",644 linewidth=2,645 fill=False,646 alpha=1,647 transform=ccrs.PlateCarree(),648 )649)650############## Subplot 2 ##############651# California Coast652ax2 = fig.add_subplot(322)653regional_clima_plot(654 ax2,655 swh_mean_nc,656 swh_stdm_nc,657 hfit_reg_nc,658 wsp_mean_nc,659 wsp_stdm_nc,660 None,661 None,662 None,663 None,664 None,665 time,666 time_ticks,667 xlim,668 ylim,669 subplot_label="B",670 fontsize=20,671 linewidth=1.5,672 task="C_I_res",673 grid=False,674)675############## Subplot 3 ##############676# South Caribbean677ax3 = fig.add_subplot(323, projection=ccrs.PlateCarree(central_longitude=180.0))678cart.set_subplots(679 ax3, projection, resolution, lon_min=97, lon_max=119, lat_min=7, lat_max=24680)681cs3 = ax3.contourf(682 lon_w,683 lat_w,684 wsp_moments_mean[2, :, :],685 levels,686 cmap=cmo.thermal,687 extend="both",688 transform=ccrs.PlateCarree(central_longitude=0.0),689)690cart.grid_lines_rc(691 ax=ax3,692 xticks=[-84, -80, -76, -72, -68, -64, -60],693 yticks=[9, 13, 17, 21, 25],694 fontsize=20,695 linewidth=1,696 color="gray",697 alpha=0.3,698 linestyle="--",699 grid=True,700)701cart.subplot_label(702 ax3,703 xdist_label=0.1,704 ydist_label=0.88,705 subplot_label="C",706 form="box",707 fs_shade=28,708 fs_main=20,709 color="black",710)711# Set regional climatology grid box712ax3.add_patch(713 mpatches.Rectangle(714 xy=[-76, 13],715 width=4,716 height=4,717 edgecolor="black",718 facecolor=None,719 linestyle="-",720 linewidth=2,721 fill=False,722 alpha=1,723 transform=ccrs.PlateCarree(),724 )725)726############## Subplot 4 ##############727# South Caribbean Sea728ax4 = fig.add_subplot(324)729regional_clima_plot(730 ax4,731 swh_mean_sc,732 swh_stdm_sc,733 hfit_reg_sc,734 wsp_mean_sc,735 wsp_stdm_sc,736 None,737 None,738 None,739 None,740 None,741 time,742 time_ticks,743 xlim,744 ylim,745 subplot_label="D",746 fontsize=20,747 linewidth=1.5,748 task="C_I_res",749 grid=False,750)751############## Subplot 5 ##############752# North Africa753ax5 = fig.add_subplot(325, projection=ccrs.PlateCarree(central_longitude=180.0))754cart.set_subplots(755 ax5, projection, resolution, lon_min=154, lon_max=174, lat_min=19, lat_max=34756)757cs5 = ax5.contourf(758 lon_w,759 lat_w,760 wsp_moments_mean[2, :, :],761 levels,762 cmap=cmo.thermal,763 extend="both",764 transform=ccrs.PlateCarree(central_longitude=0.0),765)766cart.grid_lines_rc(767 ax5,768 xticks=[-27, -23, -19, -15, -11, -7],769 yticks=[22, 26, 30, 34, 38, 42],770 fontsize=20,771 linewidth=1,772 color="gray",773 alpha=0.3,774 linestyle="--",775 grid=True,776)777cart.subplot_label(778 ax5,779 xdist_label=0.1,780 ydist_label=0.88,781 subplot_label="E",782 form="box",783 fs_shade=28,784 fs_main=20,785 color="black",786)787# Set regional climatology grid box788ax5.add_patch(789 mpatches.Rectangle(790 xy=[-15, 30],791 width=4,792 height=4,793 edgecolor="black",794 facecolor=None,795 linestyle="-",796 linewidth=2,797 fill=False,798 alpha=1,799 transform=ccrs.PlateCarree(),800 )801)802############## Subplot 6 ##############803# North Africa (Morocco)804ax6 = fig.add_subplot(326)805regional_clima_plot(806 ax6,807 swh_mean_na,808 swh_stdm_na,809 hfit_reg_na,810 wsp_mean_na,811 wsp_stdm_na,812 None,813 None,814 None,815 None,816 None,817 time,818 time_ticks,819 xlim,820 ylim,821 subplot_label="F",822 fontsize=20,823 linewidth=1.5,824 task="C_I_res",825 grid=False,826)827# adjust spacing for the entire figure (not the subplot)828fig.subplots_adjust(wspace=0.3, hspace=0.15)829# save figure...

Full Screen

Full Screen

figS09.py

Source:figS09.py Github

copy

Full Screen

1"""2Figure S9 Caption:3Regional climatologies with Ifremer SWH (Solid blue), CCMP2 (Solid red), WW3 SWH4(dashed blue), and WW3 WSP (dashed red). Same regions as in Figure~7.5"""6# Path to access python functions7import sys8sys.path.append("../tools/")9# Path to access intermediate data10data_path_i = "../data/ifremer_swh/"11data_path_c = "../data/ccmp2_wsp/"12data_path_ws = "../data/ww3_swh/"13data_path_ww = "../data/ww3_wsp/"14data_path_decor = "../data/decor_scales/"15# libraries16import numpy as np17from netCDF4 import Dataset, num2date18import matplotlib.pyplot as plt19import cartopy.crs as ccrs20import cmocean.cm as cmo21import matplotlib.patches as mpatches22# my functions23from data_processing import import_data24from averaging_stats import clima_mean, stat_moments_temporal25from lsf import weighted_least_square_fit, LSF_parameters26from regional_clima_figs import regional_clima, regional_clima_plot27import cartopy_figs as cart28# call IFREMER SWH, CCMP2 WSP, WW3 SWH, and WW3 WSP processed data:29swh_i, time_i, lat_i, lon_i = import_data("IFREMER_swh", data_path_i)30wsp_c, time_c, lat_c, lon_c = import_data("CCMP2_wsp", data_path_c)31swh_w, time_ws, lat_ws, lon_ws = import_data("WW3_swh", data_path_ws)32wsp_w, time_ww, lat_ww, lon_ww = import_data("WW3_wsp", data_path_ww)33# Call decorrelation time scales34###### IFREMER SWH ######35nc_swh_i = Dataset(data_path_decor + "IFREMER_swh_decor_time_scale.nc", "r")36decor_swh_i = nc_swh_i.variables["decor_scale"][:]37time_decor_swh_i = num2date(38 nc_swh_i.variables["time"][:], nc_swh_i.variables["time"].units39)40###### CCMP2 WSP ######41nc_wsp_c = Dataset(data_path_decor + "CCMP2_wsp_decor_time_scale.nc", "r")42decor_wsp_c = nc_wsp_c.variables["decor_scale"][:]43time_decor_wsp_c = num2date(44 nc_wsp_c.variables["time"][:], nc_wsp_c.variables["time"].units45)46#### WW3 SWH ####47nc_swh_w = Dataset(data_path_decor + "WW3_swh_decor_time_scale.nc", "r")48decor_swh_w = nc_swh_w.variables["decor_scale"][:]49time_decor_swh_w = num2date(50 nc_swh_w.variables["time"][:], nc_swh_w.variables["time"].units51)52#### WW3 WSP ####53nc_wsp_w = Dataset(data_path_decor + "WW3_wsp_decor_time_scale.nc", "r")54decor_wsp_w = nc_wsp_w.variables["decor_scale"][:]55time_decor_wsp_w = num2date(56 nc_wsp_w.variables["time"][:], nc_wsp_w.variables["time"].units57)58# Calculate monthly climatologies for SWH and WSP data and decorrelation scales:59###### IFREMER SWH ######60swh_clima_dict = clima_mean(date_time=np.ma.array(time_i), data=swh_i)61swh_mean_i = np.ma.array(swh_clima_dict["mean"])62swh_var_i = np.ma.array(swh_clima_dict["var"])63swh_n_i = np.ma.array(swh_clima_dict["N"])64decor_clima_dict_s = clima_mean(date_time=time_decor_swh_i, data=decor_swh_i)65decor_mean_swh_i = np.ma.array(decor_clima_dict_s["mean"])66###### CCMP2 WSP ######67wsp_clima_dict = clima_mean(date_time=np.ma.array(time_c), data=wsp_c)68wsp_mean_c = np.ma.array(wsp_clima_dict["mean"])69wsp_var_c = np.ma.array(wsp_clima_dict["var"])70wsp_n_c = np.ma.array(wsp_clima_dict["N"])71decor_clima_dict_w = clima_mean(date_time=time_decor_wsp_c, data=decor_wsp_c)72decor_mean_wsp_c = np.ma.array(decor_clima_dict_w["mean"])73#### WW3 SWH ####74swh_clima_dict = clima_mean(date_time=np.ma.array(time_ws), data=swh_w)75swh_mean_w = np.ma.array(swh_clima_dict["mean"])76swh_var_w = np.ma.array(swh_clima_dict["var"])77swh_n_w = np.ma.array(swh_clima_dict["N"])78decor_clima_dict_s = clima_mean(date_time=time_decor_swh_w, data=decor_swh_w)79decor_mean_swh_w = np.ma.array(decor_clima_dict_s["mean"])80#### WW3 WSP ####81wsp_clima_dict = clima_mean(date_time=np.ma.array(time_ww), data=wsp_w)82wsp_mean_w = np.ma.array(wsp_clima_dict["mean"])83wsp_var_w = np.ma.array(wsp_clima_dict["var"])84wsp_n_w = np.ma.array(wsp_clima_dict["N"])85decor_clima_dict_w = clima_mean(date_time=time_decor_wsp_w, data=decor_wsp_w)86decor_mean_wsp_w = np.ma.array(decor_clima_dict_w["mean"])87# Compute regional climatologies:88####### Northern California #######89# intialize variable90ngrid = 491lon_grid = 23292lat_grid = 10393location = ["NH", "west"]94# compute ifremer swh regional climatology95(96 swh_mean_nc,97 swh_stdm_nc,98 swh_hfit,99 swh_x_data,100 swh_residual,101 grid_cor_nc,102) = regional_clima(103 swh_mean_i,104 swh_var_i,105 swh_n_i,106 lon_i,107 lat_i,108 lon_grid,109 lat_grid,110 ngrid,111 decor_mean_swh_i,112 location,113 lsf="weighted",114 parameters=5,115)116# compute ccmp2 wsp regional climatology117(118 wsp_mean_nc,119 wsp_stdm_nc,120 wsp_hfit,121 wsp_x_data,122 wsp_residual,123 grid_cor_nc,124) = regional_clima(125 wsp_mean_c,126 wsp_var_c,127 wsp_n_c,128 lon_c,129 lat_c,130 lon_grid,131 lat_grid,132 ngrid,133 decor_mean_wsp_c,134 location,135 lsf="weighted",136 parameters=5,137)138# compute ww3 swh regional climatology139(140 swh_m_mean_nc,141 swh_m_stdm_nc,142 swh_m_hfit,143 swh_x_data,144 swh_residual,145 grid_cor_nc,146) = regional_clima(147 swh_mean_w,148 swh_var_w,149 swh_n_w,150 lon_ws,151 lat_ws,152 lon_grid,153 lat_grid,154 ngrid,155 decor_mean_swh_w,156 location,157 lsf="weighted",158 parameters=5,159)160# compute ww3 wsp regional climatology161(162 wsp_m_mean_nc,163 wsp_m_stdm_nc,164 wsp_m_hfit,165 wsp_x_data,166 wsp_residual,167 grid_cor_nc,168) = regional_clima(169 wsp_mean_w,170 wsp_var_w,171 wsp_n_w,172 lon_ws,173 lat_ws,174 lon_grid,175 lat_grid,176 ngrid,177 decor_mean_wsp_w,178 location,179 lsf="weighted",180 parameters=5,181)182####### Southern Caribbean #######183# intialize variable184ngrid = 4185lon_grid = 284186lat_grid = 80187location = ["NH", "west"]188# compute SWH regional climatology189(190 swh_mean_sc,191 swh_stdm_sc,192 swh_hfit,193 swh_x_data,194 swh_residual,195 grid_cor_sc,196) = regional_clima(197 swh_mean_i,198 swh_var_i,199 swh_n_i,200 lon_i,201 lat_i,202 lon_grid,203 lat_grid,204 ngrid,205 decor_mean_swh_i,206 location,207 lsf="weighted",208 parameters=5,209)210# compute WSP regional climatology211(212 wsp_mean_sc,213 wsp_stdm_sc,214 wsp_hfit,215 wsp_x_data,216 wsp_residual,217 grid_cor_sc,218) = regional_clima(219 wsp_mean_c,220 wsp_var_c,221 wsp_n_c,222 lon_c,223 lat_c,224 lon_grid,225 lat_grid,226 ngrid,227 decor_mean_wsp_c,228 location,229 lsf="weighted",230 parameters=5,231)232# compute ww3 swh regional climatology233(234 swh_m_mean_sc,235 swh_m_stdm_sc,236 swh_m_hfit,237 swh_x_data,238 swh_residual,239 grid_cor_sc,240) = regional_clima(241 swh_mean_w,242 swh_var_w,243 swh_n_w,244 lon_ws,245 lat_ws,246 lon_grid,247 lat_grid,248 ngrid,249 decor_mean_swh_w,250 location,251 lsf="weighted",252 parameters=5,253)254# compute ww3 wsp regional climatology255(256 wsp_m_mean_sc,257 wsp_m_stdm_sc,258 wsp_m_hfit,259 wsp_x_data,260 wsp_residual,261 grid_cor_sc,262) = regional_clima(263 wsp_mean_w,264 wsp_var_w,265 wsp_n_w,266 lon_ws,267 lat_ws,268 lon_grid,269 lat_grid,270 ngrid,271 decor_mean_wsp_w,272 location,273 lsf="weighted",274 parameters=5,275)276####### North Africa (Morocco) #######277# intialize variable278ngrid = 4279lon_grid = 345280lat_grid = 96281location = ["NH", "west"]282# compute SWH regional climatology283(284 swh_mean_na,285 swh_stdm_na,286 swh_hfit,287 swh_x_data,288 swh_residual,289 grid_cor_na,290) = regional_clima(291 swh_mean_i,292 swh_var_i,293 swh_n_i,294 lon_i,295 lat_i,296 lon_grid,297 lat_grid,298 ngrid,299 decor_mean_swh_i,300 location,301 lsf="weighted",302 parameters=5,303)304# compute WSP regional climatology305(306 wsp_mean_na,307 wsp_stdm_na,308 wsp_hfit,309 wsp_x_data,310 wsp_residual,311 grid_cor_na,312) = regional_clima(313 wsp_mean_c,314 wsp_var_c,315 wsp_n_c,316 lon_c,317 lat_c,318 lon_grid,319 lat_grid,320 ngrid,321 decor_mean_wsp_c,322 location,323 lsf="weighted",324 parameters=5,325)326# compute ww3 swh regional climatology327(328 swh_m_mean_na,329 swh_m_stdm_na,330 swh_m_hfit,331 swh_x_data,332 swh_residual,333 grid_cor_na,334) = regional_clima(335 swh_mean_w,336 swh_var_w,337 swh_n_w,338 lon_ws,339 lat_ws,340 lon_grid,341 lat_grid,342 ngrid,343 decor_mean_swh_w,344 location,345 lsf="weighted",346 parameters=5,347)348# compute ww3 wsp regional climatology349(350 wsp_m_mean_na,351 wsp_m_stdm_na,352 wsp_m_hfit,353 wsp_x_data,354 wsp_residual,355 grid_cor_na,356) = regional_clima(357 wsp_mean_w,358 wsp_var_w,359 wsp_n_w,360 lon_ws,361 lat_ws,362 lon_grid,363 lat_grid,364 ngrid,365 decor_mean_wsp_w,366 location,367 lsf="weighted",368 parameters=5,369)370####### Western Australia #######371# intialize variable372ngrid = 4373lon_grid = 108374lat_grid = 35375location = ["SH", "east"]376# compute SWH regional climatology377(378 swh_mean_wa,379 swh_stdm_wa,380 swh_hfit,381 swh_x_data,382 swh_residual,383 grid_cor_wa,384) = regional_clima(385 swh_mean_i,386 swh_var_i,387 swh_n_i,388 lon_i,389 lat_i,390 lon_grid,391 lat_grid,392 ngrid,393 decor_mean_swh_i,394 location,395 lsf="weighted",396 parameters=5,397)398# compute WSP regional climatology399(400 wsp_mean_wa,401 wsp_stdm_wa,402 wsp_hfit,403 wsp_x_data,404 wsp_residual,405 grid_cor_wa,406) = regional_clima(407 wsp_mean_c,408 wsp_var_c,409 wsp_n_c,410 lon_c,411 lat_c,412 lon_grid,413 lat_grid,414 ngrid,415 decor_mean_wsp_c,416 location,417 lsf="weighted",418 parameters=5,419)420# compute ww3 swh regional climatology421(422 swh_m_mean_wa,423 swh_m_stdm_wa,424 swh_m_hfit,425 swh_x_data,426 swh_residual,427 grid_cor_wa,428) = regional_clima(429 swh_mean_w,430 swh_var_w,431 swh_n_w,432 lon_ws,433 lat_ws,434 lon_grid,435 lat_grid,436 ngrid,437 decor_mean_swh_w,438 location,439 lsf="weighted",440 parameters=5,441)442# compute ww3 wsp regional climatology443(444 wsp_m_mean_wa,445 wsp_m_stdm_wa,446 wsp_m_hfit,447 wsp_x_data,448 wsp_residual,449 grid_cor_wa,450) = regional_clima(451 wsp_mean_w,452 wsp_var_w,453 wsp_n_w,454 lon_ws,455 lat_ws,456 lon_grid,457 lat_grid,458 ngrid,459 decor_mean_wsp_w,460 location,461 lsf="weighted",462 parameters=5,463)464####### Peru-Chile Coast #######465# intialize variable466ngrid = 4467lon_grid = 283468lat_grid = 30469location = ["SH", "west"]470# compute SWH regional climatology471(472 swh_mean_pc,473 swh_stdm_pc,474 swh_hfit,475 swh_x_data,476 swh_residual,477 grid_cor_pc,478) = regional_clima(479 swh_mean_i,480 swh_var_i,481 swh_n_i,482 lon_i,483 lat_i,484 lon_grid,485 lat_grid,486 ngrid,487 decor_mean_swh_i,488 location,489 lsf="weighted",490 parameters=5,491)492# compute WSP regional climatology493(494 wsp_mean_pc,495 wsp_stdm_pc,496 wsp_hfit,497 wsp_x_data,498 wsp_residual,499 grid_cor_pc,500) = regional_clima(501 wsp_mean_c,502 wsp_var_c,503 wsp_n_c,504 lon_c,505 lat_c,506 lon_grid,507 lat_grid,508 ngrid,509 decor_mean_wsp_c,510 location,511 lsf="weighted",512 parameters=5,513)514# compute ww3 swh regional climatology515(516 swh_m_mean_pc,517 swh_m_stdm_pc,518 swh_m_hfit,519 swh_x_data,520 swh_residual,521 grid_cor_pc,522) = regional_clima(523 swh_mean_w,524 swh_var_w,525 swh_n_w,526 lon_ws,527 lat_ws,528 lon_grid,529 lat_grid,530 ngrid,531 decor_mean_swh_w,532 location,533 lsf="weighted",534 parameters=5,535)536# compute ww3 wsp regional climatology537(538 wsp_m_mean_pc,539 wsp_m_stdm_pc,540 wsp_m_hfit,541 wsp_x_data,542 wsp_residual,543 grid_cor_pc,544) = regional_clima(545 wsp_mean_w,546 wsp_var_w,547 wsp_n_w,548 lon_ws,549 lat_ws,550 lon_grid,551 lat_grid,552 ngrid,553 decor_mean_wsp_w,554 location,555 lsf="weighted",556 parameters=5,557)558####### South Africa (Namibian) #######559# intialize variable560ngrid = 4561lon_grid = 11562lat_grid = 36563location = ["SH", "east"]564# compute SWH regional climatology565(566 swh_mean_sa,567 swh_stdm_sa,568 swh_hfit,569 swh_x_data,570 swh_residual,571 grid_cor_sa,572) = regional_clima(573 swh_mean_i,574 swh_var_i,575 swh_n_i,576 lon_i,577 lat_i,578 lon_grid,579 lat_grid,580 ngrid,581 decor_mean_swh_i,582 location,583 lsf="weighted",584 parameters=5,585)586# compute WSP regional climatology587(588 wsp_mean_sa,589 wsp_stdm_sa,590 wsp_hfit,591 wsp_x_data,592 wsp_residual,593 grid_cor_sa,594) = regional_clima(595 wsp_mean_c,596 wsp_var_c,597 wsp_n_c,598 lon_c,599 lat_c,600 lon_grid,601 lat_grid,602 ngrid,603 decor_mean_wsp_c,604 location,605 lsf="weighted",606 parameters=5,607)608# compute ww3 swh regional climatology609(610 swh_m_mean_sa,611 swh_m_stdm_sa,612 swh_m_hfit,613 swh_x_data,614 swh_residual,615 grid_cor_sa,616) = regional_clima(617 swh_mean_w,618 swh_var_w,619 swh_n_w,620 lon_ws,621 lat_ws,622 lon_grid,623 lat_grid,624 ngrid,625 decor_mean_swh_w,626 location,627 lsf="weighted",628 parameters=5,629)630# compute ww3 wsp regional climatology631(632 wsp_m_mean_sa,633 wsp_m_stdm_sa,634 wsp_m_hfit,635 wsp_x_data,636 wsp_residual,637 grid_cor_sa,638) = regional_clima(639 wsp_mean_w,640 wsp_var_w,641 wsp_n_w,642 lon_ws,643 lat_ws,644 lon_grid,645 lat_grid,646 ngrid,647 decor_mean_wsp_w,648 location,649 lsf="weighted",650 parameters=5,651)652####### Arabian Sea #######653# intialize variable654ngrid = 4655lon_grid = 51656lat_grid = 70657location = ["SH", "east"]658# compute SWH regional climatology659(660 swh_mean_as,661 swh_stdm_as,662 swh_hfit,663 swh_x_data,664 swh_residual,665 grid_cor_as,666) = regional_clima(667 swh_mean_i,668 swh_var_i,669 swh_n_i,670 lon_i,671 lat_i,672 lon_grid,673 lat_grid,674 ngrid,675 decor_mean_swh_i,676 location,677 lsf="weighted",678 parameters=5,679)680# compute WSP regional climatology681(682 wsp_mean_as,683 wsp_stdm_as,684 wsp_hfit,685 wsp_x_data,686 wsp_residual,687 grid_cor_as,688) = regional_clima(689 wsp_mean_c,690 wsp_var_c,691 wsp_n_c,692 lon_c,693 lat_c,694 lon_grid,695 lat_grid,696 ngrid,697 decor_mean_wsp_c,698 location,699 lsf="weighted",700 parameters=5,701)702# compute ww3 swh regional climatology703(704 swh_m_mean_as,705 swh_m_stdm_as,706 swh_m_hfit,707 swh_x_data,708 swh_residual,709 grid_cor_as,710) = regional_clima(711 swh_mean_w,712 swh_var_w,713 swh_n_w,714 lon_ws,715 lat_ws,716 lon_grid,717 lat_grid,718 ngrid,719 decor_mean_swh_w,720 location,721 lsf="weighted",722 parameters=5,723)724# compute ww3 wsp regional climatology725(726 wsp_m_mean_as,727 wsp_m_stdm_as,728 wsp_m_hfit,729 wsp_x_data,730 wsp_residual,731 grid_cor_as,732) = regional_clima(733 wsp_mean_w,734 wsp_var_w,735 wsp_n_w,736 lon_ws,737 lat_ws,738 lon_grid,739 lat_grid,740 ngrid,741 decor_mean_wsp_w,742 location,743 lsf="weighted",744 parameters=5,745)746# Set variables for plotting747time = np.arange(1, 13, 1)748time_ticks_nh = [749 "Jan",750 "Feb",751 "Mar",752 "Apr",753 "May",754 "Jun",755 "Jul",756 "Aug",757 "Sep",758 "Oct",759 "Nov",760 "Dec",761]762time_ticks_sh = [763 "Jul",764 "Aug",765 "Sep",766 "Oct",767 "Nov",768 "Dec",769 "Jan",770 "Feb",771 "Mar",772 "Apr",773 "May",774 "Jun",775]776xlim = [0, 13]777ylim = [[1, 4], [4, 10]]778# Create figure and axes779fig, axes = plt.subplots(4, 2, figsize=(16, 20))780ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8 = axes.flatten()781########### Subplot 1 ###########782# California Coast783regional_clima_plot(784 ax1,785 swh_mean_nc,786 swh_stdm_nc,787 None,788 wsp_mean_nc,789 wsp_stdm_nc,790 None,791 swh_m_mean_nc,792 swh_m_stdm_nc,793 wsp_m_mean_nc,794 wsp_m_stdm_nc,795 time,796 time_ticks_nh,797 xlim,798 ylim,799 subplot_label="A",800 fontsize=20,801 linewidth=1.5,802 task="ww3",803 grid=False,804)805########### Subplot 2 ###########806# West Coast of Australia807regional_clima_plot(808 ax2,809 swh_mean_wa,810 swh_stdm_wa,811 None,812 wsp_mean_wa,813 wsp_stdm_wa,814 None,815 swh_m_mean_wa,816 swh_m_stdm_wa,817 wsp_m_mean_wa,818 wsp_m_stdm_wa,819 time,820 time_ticks_sh,821 xlim,822 ylim,823 subplot_label="B",824 fontsize=20,825 linewidth=1.5,826 task="ww3",827 grid=False,828)829########### Subplot 3 ###########830# South Caribbean Sea831regional_clima_plot(832 ax3,833 swh_mean_sc,834 swh_stdm_sc,835 None,836 wsp_mean_sc,837 wsp_stdm_sc,838 None,839 swh_m_mean_sc,840 swh_m_stdm_sc,841 wsp_m_mean_sc,842 wsp_m_stdm_sc,843 time,844 time_ticks_nh,845 xlim,846 ylim,847 subplot_label="C",848 fontsize=20,849 linewidth=1.5,850 task="ww3",851 grid=False,852)853########### Subplot 4 ###########854# Peru-Chile Coast855regional_clima_plot(856 ax4,857 swh_mean_pc,858 swh_stdm_pc,859 None,860 wsp_mean_pc,861 wsp_stdm_pc,862 None,863 swh_m_mean_pc,864 swh_m_stdm_pc,865 wsp_m_mean_pc,866 wsp_m_stdm_pc,867 time,868 time_ticks_sh,869 xlim,870 ylim,871 subplot_label="D",872 fontsize=20,873 linewidth=1.5,874 task="ww3",875 grid=False,876)877########### Subplot 5 ###########878# North Africa (Morocco)879regional_clima_plot(880 ax5,881 swh_mean_na,882 swh_stdm_na,883 None,884 wsp_mean_na,885 wsp_stdm_na,886 None,887 swh_m_mean_na,888 swh_m_stdm_na,889 wsp_m_mean_na,890 wsp_m_stdm_na,891 time,892 time_ticks_nh,893 xlim,894 ylim,895 subplot_label="E",896 fontsize=20,897 linewidth=1.5,898 task="ww3",899 grid=False,900)901########### Subplot 6 ###########902# South Africa Coast (Namibia)903regional_clima_plot(904 ax6,905 swh_mean_sa,906 swh_stdm_sa,907 None,908 wsp_mean_sa,909 wsp_stdm_sa,910 None,911 swh_m_mean_sa,912 swh_m_stdm_sa,913 wsp_m_mean_sa,914 wsp_m_stdm_sa,915 time,916 time_ticks_sh,917 xlim,918 ylim,919 subplot_label="F",920 fontsize=20,921 linewidth=1.5,922 task="ww3",923 grid=False,924)925########### Subplot 7 ###########926# suppress output for axis 7927ax7.axis("off")928########### Subplot 8 ###########929# Arabian Sea930regional_clima_plot(931 ax8,932 swh_mean_as,933 swh_stdm_as,934 None,935 wsp_mean_as,936 wsp_stdm_as,937 None,938 swh_m_mean_as,939 swh_m_stdm_as,940 wsp_m_mean_as,941 wsp_m_stdm_as,942 time,943 time_ticks_sh,944 xlim,945 ylim=[[0.5, 4], [3, 12]],946 subplot_label="G",947 fontsize=20,948 linewidth=1.5,949 task="ww3",950 grid=False,951)952# make sure the figure looks good:953fig.tight_layout()954# adjust spacing for the entire figure955fig.subplots_adjust(wspace=0.35, hspace=0.2)956# save figure:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful