From d37e93cdd065dacd0930c1e010da42e2f8d074c9 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Wed, 13 Mar 2024 11:18:31 -0400 Subject: [PATCH 1/2] Apply suggestions from code review Co-authored-by: Carlos Paniagua --- .../local_modules/m_general_ph3.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 1f0a9db..3d9e34d 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -78,7 +78,7 @@ def __init__( viewscale = view_scale if view_scale is not None else 0.5 fig_scale = fig_scale if fig_scale is not None else 1 - self.label_letters = iter([i + ") " for i in list(string.ascii_lowercase)]) + self.label_letters = iter(f"{i}) " for i in string.ascii_lowercase) if container: self.fig = plt.figure( @@ -187,14 +187,14 @@ def linear(self, Color="b", fig_scale=2, fax="f"): self.F = FigureAxisXY(fig_scale=fig_scale) if fax == "f": xax = self.fs - xlabelstr = "f (" + self.sample_unit + ")" + xlabelstr = f"f ({self.sample_unit})" elif fax == "w": xax = 2 * np.pi * self.fs - xlabelstr = "w (rad " + self.sample_unit + ")" + xlabelstr = f"w (rad {self.sample_unit})" self.line = plt.plot(xax[1:], (self.Xdata[1:]), Color=Color) - plt.ylabel(("|X|^2/f (" + self.data_unit + "^2/" + self.sample_unit + ")")) + plt.ylabel(f"|X|^2/f ({self.data_unit}^2/{self.sample_unit})") plt.xlabel(xlabelstr) plt.xlim(xax[1], xax[-1]) @@ -213,7 +213,7 @@ def power_linear(self, Color="b", fax="f"): self.line = plt.plot(xax[1:], 10 * np.log10(self.Xdata[1:]), Color=Color) - plt.ylabel(("Power db(" + self.data_unit + "^2/" + self.sample_unit + ")")) + plt.ylabel(f"Power db({self.data_unit}^2/{self.sample_unit})") plt.xlabel(xlabelstr) plt.xlim(xax[1], xax[-1]) self.F.make_clear() @@ -241,10 +241,10 @@ def power(self, Color="b", fig_scale=2, fax="f"): self.F = FigureAxisXY(fig_scale=fig_scale) if fax == "f": xax = self.fs - xlabelstr = "f (" + self.sample_unit + ")" + xlabelstr = f"f ({self.sample_unit})" elif fax == "w": xax = 2 * np.pi * self.fs - xlabelstr = "w (rad " + self.sample_unit + ")" + xlabelstr = f"w (rad {self.sample_unit})" self.line = plt.semilogx(xax[1:], 10 * np.log10(self.Xdata[1:]), Color=Color) @@ -285,8 +285,8 @@ def loglog(self): plt.loglog(self.fs[1:], (self.Xdata[1:])) - plt.ylabel(("|X|^2/f (" + self.data_unit + "^2/" + self.sample_unit + ")")) - plt.xlabel(("f (" + self.sample_unit + ")")) + plt.ylabel(f"|X|^2/f ({self.data_unit}^2/{self.sample_unit})") + plt.xlabel(f"f ({self.sample_unit})") plt.xlim(self.fs[1], self.fs[-1]) self.F.make_clear() @@ -300,12 +300,12 @@ def linear(self): tt = self.time.astype(DT.datetime) self.cs = plt.contourf(tt[:-2], self.fs[:], dd, self.clevs, cmap=self.cmap) print(self.clevs) - plt.ylabel(("Power db(" + self.data_unit + "^2/" + self.sample_unit + ")")) - plt.xlabel(("f (" + self.sample_unit + ")")) + plt.ylabel(f"Power db({self.data_unit}^2/{self.sample_unit})") + plt.xlabel(f"f ({self.sample_unit})") self.cbar = plt.colorbar(self.cs, pad=0.01) self.cbar.ax.aspect = 100 self.cbar.outline.set_linewidth(0) - self.cbar.set_label("(" + self.data_unit + ")") + self.cbar.set_label(f"({self.data_unit})") ax = plt.gca() ax.set_ylim(self.ylim[0], self.ylim[1]) @@ -349,11 +349,11 @@ def power(self, anomalie=False): self.x = np.arange(0, tt[:-1].size) print(self.clevs) plt.xlabel("Time") - plt.ylabel(("f (" + self.sample_unit + ")")) + plt.ylabel(f"f ({self.sample_unit})") self.cbar = plt.colorbar(self.cs, pad=0.01) self.cbar.ax.aspect = 100 self.cbar.outline.set_linewidth(0) - self.cbar.set_label("Power db(" + self.data_unit + "^2/f ") + self.cbar.set_label(f"Power db({self.data_unit}^2/f )") ax = plt.gca() # Set y-lim @@ -531,7 +531,7 @@ def power_imshow( ax.xaxis.set_major_formatter(dfmt) ax.xaxis.set_minor_locator(Day) else: - plt.xlabel("Time (" + self.time_unit + ")") + plt.xlabel(f"Time ({self.time_unit})") ax.set_ylim(self.ylim[0], self.ylim[1]) ax.xaxis.set_major_locator(ticker.MultipleLocator(5)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(1)) From 3b07b312b1ec196fba465d78fcbf8ac592255ce9 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Wed, 13 Mar 2024 11:20:34 -0400 Subject: [PATCH 2/2] More apply suggestions from code review to m_general_ph3.py Co-authored-by: Carlos Paniagua --- .../local_modules/m_general_ph3.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/icesat2waves/local_modules/m_general_ph3.py b/src/icesat2waves/local_modules/m_general_ph3.py index 3d9e34d..e27482d 100644 --- a/src/icesat2waves/local_modules/m_general_ph3.py +++ b/src/icesat2waves/local_modules/m_general_ph3.py @@ -1600,7 +1600,7 @@ def find_max_along_line( if mode is None: mode = "free_limits" - if mode is "free_limits" or mode is "upper_limit": + if mode in ["free_limits", "upper_limit"]: if line_left[0] > time_lin[0]: f_start = 0 print(" left line > time0") @@ -1642,15 +1642,16 @@ def find_max_along_line( plt.plot(time_lin, time_lin * 0 + f1, Color="grey", linewidth=3) plt.plot(time_lin, time_lin * 0 + f2, Color="grey") - STR = dict() - STR["t_pos"] = [] - STR["index"] = index - STR["amp"] = [] - STR["freq"] = [] - STR["out"] = [] - STR["amp_shape"] = list() - STR["left_limit"] = line_left - STR["right_limit"] = line_right + STR = { + "t_pos": [], + "index": index, + "amp": [], + "freq": [], + "out": [], + "amp_shape": [], + "left_limit": line_left, + "right_limit": line_right, + } for i in enumerate(flin[f_start:f_end]): ii = f_start + i[0]