Exemplo n.º 1
0
 def on_roses(self, event):
     """TO DO"""
     season = wx.GetSingleChoice("Select a season to analyze:",
                                 "Select season",
                                 ["Winter", "Summer", "Spring", "Fall"])
     if season:
         ms = MONTHS[season]
         str_coords = wx.GetTextFromUser("Coordinates (lon, lat):",
                                         default_value="-74.85,11.11")
         str_lon, str_lat = str_coords.split(",")
         lon = float(str_lon)
         lat = float(str_lat)
         if lon < 0:
             lon = 360 + lon
         progress_dlg = wx.ProgressDialog(
             "Read and analyze", "Reading and analyzing wave data...")
         progress_dlg.Pulse()
         fname = f"tmp/dp-hs-{season}-{lon}-{lat}.tmp"
         try:
             dp_hs = load_obj(fname)
         except FileNotFoundError:
             dp_hs = joint_distribution(["dp", "hs"], ms, lon, lat)
             save_obj(dp_hs, fname)
         progress_dlg.Update(100)
         frm_canvas = FrameCanvas(None, title="Wave Rose")
         ax = frm_canvas.fig.add_subplot(projection="windrose")
         dp, hs = dp_hs
         ax.bar(dp, hs, normed=True)
         ax.set_title("Significant Wave Height Rose")
         ax.set_legend(title="$H_s$ (m)")
         frm_canvas.Show()
Exemplo n.º 2
0
 def on_period_exceedance(self, event):
     """Plots Probability of Exceedance Estimates of mean peak period for a season."""
     season = wx.GetSingleChoice("Select a season to analyze:",
                                 "Select season",
                                 ["Winter", "Summer", "Spring", "Fall"])
     if season:
         ms = MONTHS[season]
         str_coords = wx.GetTextFromUser("Coordinates (lon, lat):",
                                         default_value="-74.85,11.11")
         str_lon, str_lat = str_coords.split(",")
         lon = float(str_lon)
         lat = float(str_lat)
         if lon < 0:
             lon = 360 + lon
         progress_dlg = wx.ProgressDialog(
             "Read and analyze", "Reading and analyzing wave data...")
         progress_dlg.Pulse()
         fname = f"tmp/tp-{season}-{lon}-{lat}.tmp"
         try:
             x, p = load_obj(fname)
         except FileNotFoundError:
             data = frequency_curve("tp", ms, lon, lat)
             save_obj(data, fname)
             x, p = data
         progress_dlg.Update(100)
         frm_canvas = FrameCanvas(
             None, title="Probability of Exceedance for Peak Period")
         ax = frm_canvas.fig.add_subplot()
         ax.semilogy(x, p, "o")
         ax.set_xlabel("Peak Period (s)")
         ax.set_ylabel("Probability of Exceedance")
         ax.set_title(season)
         ax.grid(True)
         frm_canvas.Show()
Exemplo n.º 3
0
 def on_weibull(self, event):
     """Extreme value analysis - Maximum Weibull distribution"""
     season = wx.GetSingleChoice("Select a season to analyze:",
                                 "Select season",
                                 ["Winter", "Summer", "Spring", "Fall"])
     if season:
         ms = MONTHS[season]
         str_coords = wx.GetTextFromUser("Coordinates (lon, lat):",
                                         default_value="-74.85,11.11")
         str_lon, str_lat = str_coords.split(",")
         lon = float(str_lon)
         lat = float(str_lat)
         if lon < 0:
             lon = 360 + lon
         progress_dlg = wx.ProgressDialog(
             "Read and analyze", "Reading and analyzing wave data...")
         progress_dlg.Pulse()
         fname = f"tmp/hs-peaks-{season}-{lon}-{lat}.tmp"
         try:
             peaks_hs = load_obj(fname)
         except FileNotFoundError:
             peaks_hs = weibull_data("hs", ms, lon, lat)
             save_obj(peaks_hs, fname)
         progress_dlg.Update(100)
         analysis = weibull.Analysis(peaks_hs, unit="m")
         analysis.fit()
         analysis.probplot()
Exemplo n.º 4
0
 def on_wind(self, event):
     """TO DO"""
     str_coords = wx.GetTextFromUser(
         "Coordinates (lon1, lon2, lat1, lat2):",
         default_value="-75.3,-74.1,10,11.5")
     lon1, lon2, lat1, lat2 = [float(x) for x in str_coords.split(",")]
     if lon1 < 0:
         lon1 = 360 + lon1
     if lon2 < 0:
         lon2 = 360 + lon2
     progress_dlg = wx.ProgressDialog("Read and analyze",
                                      "Reading and analyzing wind data...")
     progress_dlg.Pulse()
     fname = "tmp/annual-maxima-wind.tmp"
     try:
         maxima = load_obj(fname)
     except FileNotFoundError:
         maxima = load_max("wind")
         save_obj(maxima, fname)
     progress_dlg.Update(100)
     lon = maxima[0].coords["longitude"].values
     lat = maxima[0].coords["latitude"].values
     da_wind_q = xr.DataArray(np.nanquantile(np.stack(maxima), self.q, 0),
                              dims=["latitude", "longitude"],
                              coords={
                                  "latitude": lat,
                                  "longitude": lon
                              })
     data = da_wind_q.sel(latitude=slice(lat2, lat1),
                          longitude=slice(lon1, lon2))
     min_lon = data.coords["longitude"].values.min()
     max_lon = data.coords["longitude"].values.max()
     if min_lon > 180:
         min_lon -= 360
     if max_lon > 180:
         max_lon -= 360
     min_lat = data.coords["latitude"].values.min()
     max_lat = data.coords["latitude"].values.max()
     extent = (min_lon, max_lon, min_lat, max_lat)
     ax = plt.axes(projection=ccrs.PlateCarree())
     ax.set_title(f"Return period (Annual) = {self.pr} years")
     data = interp_idw(interp_idw(data))
     im = ax.imshow(data,
                    origin="upper",
                    extent=extent,
                    transform=ccrs.PlateCarree(),
                    cmap="jet",
                    interpolation="bilinear")
     cbar = plt.colorbar(im)
     cbar.ax.set_ylabel("Wind speed (m/s)")
     ax.add_feature(LAND_10M)
     gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True)
     gl.xlabels_top = False
     gl.ylabels_right = False
     gl.xformatter = LONGITUDE_FORMATTER
     gl.yformatter = LATITUDE_FORMATTER
     plt.tight_layout()
     plt.show()
Exemplo n.º 5
0
 def on_energies_annual(self, event):
     """Analysis of storms ocurrences"""
     ms = MONTHS["All"]
     str_coords = wx.GetTextFromUser("Coordinates (lon, lat):",
                                     default_value="-74.85,11.11")
     str_lon, str_lat = str_coords.split(",")
     lon = float(str_lon)
     lat = float(str_lat)
     if lon < 0:
         lon = 360 + lon
     progress_dlg = wx.ProgressDialog("Read and analyze",
                                      "Reading and analyzing wave data...")
     progress_dlg.Pulse()
     fname = "tmp/dp-hs-tp-all-" + f"{lon}-{lat}.tmp"
     try:
         data = load_obj(fname)
     except FileNotFoundError:
         data = load_data(["dp", "hs", "tp"], ms, lon, lat)
         save_obj(data, fname)
     progress_dlg.Update(100)
     hsall = merge_data(data["hs"])
     p97_hs = np.percentile(hsall, 97)
     p99_hs = np.percentile(hsall, 99)
     hs = {}
     for y, m in data["hs"]:
         if y in hs:
             hs[y].extend(data["hs"][(y, m)])
         else:
             hs[y] = data["hs"][(y, m)]
     n_events_97 = []
     n_events_99 = []
     ys = [*range(min(hs), max(hs) + 1)]
     for y in ys:
         n_events_97.append(sum(h / p97_hs > 1 for h in hs[y]))
         n_events_99.append(sum(h / p97_hs > p99_hs / p97_hs
                                for h in hs[y]))
     frm_canvas = FrameCanvas(
         None,
         title=
         "Mean and maximum annual number of storms with normalized energy")
     x = np.arange(len(ys))
     frm_canvas.fig.suptitle(
         "Mean and maximum annual number of storms with normalized energy")
     ax1 = frm_canvas.fig.add_subplot(2, 1, 1)
     ax1.bar(x, n_events_97, tick_label=[*map(str, ys)])
     ax1.set_title("$E > 1$")
     ax1.grid(True)
     ax2 = frm_canvas.fig.add_subplot(2, 1, 2)
     ax2.bar(x, n_events_99, tick_label=[*map(str, ys)])
     ax2.set_title(f"$E > {p99_hs/p97_hs:3.1f}$")
     ax2.grid(True)
     frm_canvas.Show()
Exemplo n.º 6
0
 def on_energetic(self, event):
     """To DO"""
     ms = MONTHS["All"]
     str_coords = wx.GetTextFromUser("Coordinates (lon, lat):",
                                     default_value="-74.85,11.11")
     str_lon, str_lat = str_coords.split(",")
     lon = float(str_lon)
     lat = float(str_lat)
     if lon < 0:
         lon = 360 + lon
     progress_dlg = wx.ProgressDialog("Read and analyze",
                                      "Reading and analyzing wave data...")
     progress_dlg.Pulse()
     fname = "tmp/dp-hs-tp-all-" + f"{lon}-{lat}.tmp"
     try:
         data = load_obj(fname)
     except FileNotFoundError:
         data = load_data(["dp", "hs", "tp"], ms, lon, lat)
         save_obj(data, fname)
     progress_dlg.Update(100)
     dp = []
     hs = []
     tp = []
     for k in data["dp"]:
         dp += data["dp"][k]
         hs += data["hs"][k]
         tp += data["tp"][k]
     dp = np.array(dp)
     hs = np.array(hs)
     tp = np.array(tp)
     p97_hs = np.percentile(hs, 97)
     i = hs >= p97_hs
     hs = hs[i]
     tp = tp[i]
     dp = dp[i]
     frm_canvas = FrameCanvas(None, title="Energetic Analysis")
     frm_canvas.fig.suptitle("Energetic Analysis")
     ax1 = frm_canvas.fig.add_subplot(1, 2, 1, projection="windrose")
     ax1.bar(dp, tp, normed=True)
     ax1.set_title("Wave period rose calculated energetically by storm")
     ax1.set_legend(title="$T_p$ (s)")
     ax2 = frm_canvas.fig.add_subplot(1, 2, 2, projection="windrose")
     en = hs / p97_hs
     ax2.bar(dp, en, normed=True)
     ax2.set_title(
         "Significant wave height rose calculated energetically by storm")
     ax2.set_legend(title="$E$ (-)")
     frm_canvas.Show()
Exemplo n.º 7
0
 def on_storms_monthly(self, event):
     """TO DO"""
     ms = MONTHS["All"]
     str_coords = wx.GetTextFromUser("Coordinates (lon, lat):",
                                     default_value="-74.85,11.11")
     str_lon, str_lat = str_coords.split(",")
     lon = float(str_lon)
     lat = float(str_lat)
     if lon < 0:
         lon = 360 + lon
     progress_dlg = wx.ProgressDialog("Read and analyze",
                                      "Reading and analyzing wave data...")
     progress_dlg.Pulse()
     fname = "tmp/dp-hs-tp-all-" + f"{lon}-{lat}.tmp"
     try:
         data = load_obj(fname)
     except FileNotFoundError:
         data = load_data(["dp", "hs", "tp"], ms, lon, lat)
         save_obj(data, fname)
     progress_dlg.Update(100)
     hsall = merge_data(data["hs"])
     p97_hs = np.percentile(hsall, 97)
     p99_hs = np.percentile(hsall, 99)
     hs = {}
     for y, m in data["hs"]:
         if m in hs:
             hs[m].extend(data["hs"][(y, m)])
         else:
             hs[m] = data["hs"][(y, m)]
     n_events_97 = []
     n_events_99 = []
     for m in ms:
         n_events_97.append(sum(x > p97_hs for x in hs[m]))
         n_events_99.append(sum(x > p99_hs for x in hs[m]))
     frm_canvas = FrameCanvas(
         None, title="Monthly mean and maximum number of storms")
     x = np.arange(12)
     frm_canvas.fig.suptitle("Monthly mean and maximum number of storms")
     ax1 = frm_canvas.fig.add_subplot(2, 1, 1)
     ax1.bar(x, n_events_97, tick_label=STR_MONTHS)
     ax1.grid(True)
     ax1.set_title("$H_s > H_{s,97}$")
     ax2 = frm_canvas.fig.add_subplot(2, 1, 2)
     ax2.bar(x, n_events_99, tick_label=STR_MONTHS)
     ax2.set_title("$H_s > H_{s,99}$")
     ax2.grid(True)
     frm_canvas.Show()
Exemplo n.º 8
0
 def on_height_joint(self, event):
     """TO DO"""
     season = wx.GetSingleChoice("Select a season to analyze:",
                                 "Select season",
                                 ["Winter", "Summer", "Spring", "Fall"])
     if season:
         ms = MONTHS[season]
         str_coords = wx.GetTextFromUser("Coordinates (lon, lat):",
                                         default_value="-74.85,11.11")
         str_lon, str_lat = str_coords.split(",")
         lon = float(str_lon)
         lat = float(str_lat)
         if lon < 0:
             lon = 360 + lon
         progress_dlg = wx.ProgressDialog(
             "Read and analyze", "Reading and analyzing wave data...")
         progress_dlg.Pulse()
         fname = f"tmp/dp-hs-{season}-{lon}-{lat}.tmp"
         try:
             dp_hs = load_obj(fname)
         except FileNotFoundError:
             dp_hs = joint_distribution(["dp", "hs"], ms, lon, lat)
             save_obj(dp_hs, fname)
         progress_dlg.Update(100)
         frm_canvas = FrameCanvas(None, title="Joint Probability of Hs - θ")
         ax = frm_canvas.fig.add_subplot()
         kernel = stats.gaussian_kde(dp_hs)
         dp, hs = dp_hs
         dp, hs = np.meshgrid(np.linspace(dp.min(), dp.max(), N),
                              np.linspace(hs.min(), hs.max(), N // 2))
         p = np.reshape(kernel(np.vstack([dp.flatten(),
                                          hs.flatten()])), (N // 2, N))
         im = ax.imshow(p,
                        origin="lower",
                        extent=(0, 360, hs.min(), hs.max()),
                        aspect="auto",
                        cmap="jet")
         cbar = frm_canvas.fig.colorbar(im)
         cbar.ax.set_ylabel("Probability")
         cs = ax.contour(dp, hs, p, colors="k", levels=4, linewidths=1)
         ax.clabel(cs, inline_spacing=0.1)
         ax.set_xlabel("Average direction at the peak period (deg)")
         ax.set_ylabel("Significant Wave Height (m)")
         ax.set_title(season)
         ax.grid(True)
         frm_canvas.Show()