Skip to content

Commit bb40595

Browse files
authored
Merge pull request #197 from MBARIMike/main
Add plot of Ah used vs. Distance and Ah/km.
2 parents 0d984d2 + 2bd35b3 commit bb40595

3 files changed

Lines changed: 79 additions & 13 deletions

File tree

‎.vscode/launch.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@
513513
//"args": ["--auv_name", "daphne", "--start", "20260501", "--end", "20260531", "-v", "1", "--clobber"]
514514
// Test stoqs url creation with valid start and end times - problem was that data hadn't loaded into stoqs yet.
515515
//"args": ["--auv_name", "makai", "--start", "20260601", "--end", "20260604", "-v", "1", "--clobber"]
516-
"args": ["--auv_name", "pyxis", "--current_month", "-v", "1"]
516+
"args": ["--auv_name", "pyxis", "--current_month", "-v", "1", "--clobber"]
517517
},
518518
{
519519
"name": "lrauv_deployment_plots",

‎src/data/create_products.py‎

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,8 +3204,71 @@ def plot_engineering_2column(self) -> str: # noqa: C901, PLR0912, PLR0915
32043204
self.logger.info("Saved engineering 2column plot to %s", output_file)
32053205
return str(output_file)
32063206

3207+
def _plot_cbit_time_series(
3208+
self,
3209+
ax: matplotlib.axes.Axes,
3210+
times: pd.DatetimeIndex,
3211+
cbit_vals: np.ndarray,
3212+
ylabel: str,
3213+
) -> None:
3214+
ax.plot(times, cbit_vals, color="tab:red", linewidth=1, marker=".", markersize=3)
3215+
ax.set_xlabel("Time (UTC)")
3216+
ax.set_ylabel(ylabel)
3217+
ax.set_title("Ah Used vs. Time")
3218+
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter("%Y-%m-%d\n%H:%M"))
3219+
plt.setp(ax.get_xticklabels(), rotation=0, ha="center", fontsize=8)
3220+
ax.grid(visible=True, linestyle="--", alpha=0.5)
3221+
3222+
def _plot_cbit_distance(
3223+
self,
3224+
ax: matplotlib.axes.Axes,
3225+
distnav: xr.DataArray,
3226+
cbit_at_nav: np.ndarray,
3227+
ylabel: str,
3228+
) -> None:
3229+
dist_km = distnav.to_numpy() / 1000.0
3230+
inst_rate = np.gradient(cbit_at_nav, dist_km)
3231+
3232+
(line_ah,) = ax.plot(
3233+
dist_km,
3234+
cbit_at_nav,
3235+
color="tab:red",
3236+
linewidth=1,
3237+
marker=".",
3238+
markersize=3,
3239+
label="Ah Used",
3240+
)
3241+
ax_rate = ax.twinx()
3242+
(line_rate,) = ax_rate.plot(
3243+
dist_km,
3244+
inst_rate,
3245+
color="tab:blue",
3246+
linewidth=0.8,
3247+
alpha=0.6,
3248+
label="Instantaneous rate (Ah/km)",
3249+
)
3250+
ax_rate.set_ylabel("Instantaneous rate (Ah/km)", color="tab:blue")
3251+
ax_rate.tick_params(axis="y", labelcolor="tab:blue")
3252+
last_rate = inst_rate[~np.isnan(inst_rate)][-1] if np.any(~np.isnan(inst_rate)) else None
3253+
if last_rate is not None:
3254+
ax_rate.annotate(
3255+
f"{last_rate:.3f}",
3256+
xy=(dist_km[-1], last_rate),
3257+
xytext=(4, 0),
3258+
textcoords="offset points",
3259+
color="tab:blue",
3260+
fontsize=8,
3261+
va="center",
3262+
)
3263+
ax.set_xlabel("Distance along track (km)")
3264+
ax.set_ylabel(ylabel)
3265+
ax.set_title("Ah Used vs. Distance")
3266+
ax.grid(visible=True, axis="x", linestyle="--", alpha=0.5)
3267+
ax_rate.grid(visible=True, axis="y", linestyle="--", alpha=0.5)
3268+
ax.legend(handles=[line_ah, line_rate], loc="upper left", fontsize=8)
3269+
32073270
def plot_cbit_2column(self) -> str:
3208-
"""Create a 3-panel plot for cbit_amphoursused: track map, distance scatter, time series."""
3271+
"""Create a 4-panel plot for cbit_amphoursused: track map, depth section, time series, distance.""" # noqa: E501
32093272
_CBIT_VAR = "cbit_amphoursused"
32103273

32113274
if "pytest" in sys.modules:
@@ -3236,11 +3299,15 @@ def plot_cbit_2column(self) -> str:
32363299
times = pd.to_datetime(cbit.coords["time"].to_numpy())
32373300
cbit_vals = cbit.to_numpy()
32383301

3239-
fig = plt.figure(figsize=(18, 8))
3240-
gs = matplotlib.gridspec.GridSpec(2, 2, figure=fig, hspace=0.35, wspace=0.15)
3302+
fig = plt.figure(figsize=(18, 11))
3303+
gs = matplotlib.gridspec.GridSpec(
3304+
3, 2, figure=fig, hspace=0.45, wspace=0.15, height_ratios=[3, 2, 3]
3305+
)
3306+
fig.subplots_adjust(left=0.06)
32413307
ax_map = fig.add_subplot(gs[0, 0])
32423308
ax_section = fig.add_subplot(gs[0, 1])
32433309
ax_time = fig.add_subplot(gs[1, :])
3310+
ax_dist = fig.add_subplot(gs[2, :])
32443311

32453312
# Track map colored by Ah Used
32463313
self._plot_track_map(
@@ -3272,13 +3339,8 @@ def plot_cbit_2column(self) -> str:
32723339
)
32733340
ax_section.set_xlabel("Distance along track (km)")
32743341

3275-
# Time series
3276-
ax_time.plot(times, cbit_vals, color="tab:red", linewidth=1, marker=".", markersize=3)
3277-
ax_time.set_xlabel("Time (UTC)")
3278-
ax_time.set_ylabel(ylabel)
3279-
ax_time.set_title("Ah Used vs. Time")
3280-
ax_time.xaxis.set_major_formatter(matplotlib.dates.DateFormatter("%Y-%m-%d\n%H:%M"))
3281-
plt.setp(ax_time.get_xticklabels(), rotation=0, ha="center", fontsize=8)
3342+
self._plot_cbit_time_series(ax_time, times, cbit_vals, ylabel)
3343+
self._plot_cbit_distance(ax_dist, distnav, cbit_at_nav, ylabel)
32823344

32833345
out_dir = (
32843346
self.output_dir

‎src/data/lrauv_deployment_plots.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,8 @@ def _other_plots_line(
884884
return ""
885885
if not links:
886886
return ""
887-
return "<p>Other plots for this deployment: " + " | ".join(links) + "</p>\n"
887+
context = "month" if any("sbdlogs" in f for f in (other_png_paths or [])) else "deployment"
888+
return f"<p>Other plots for this {context}: " + " | ".join(links) + "</p>\n"
888889

889890
def _write_per_png_html( # noqa: C901, PLR0913
890891
self,
@@ -1032,20 +1033,23 @@ def _write_per_png_html( # noqa: C901, PLR0913
10321033
"2column_biolume",
10331034
"2column_planktivore",
10341035
"2column_engineering",
1036+
"2column_cbit",
10351037
)
10361038
# (kind_substring, column_index) — biolume and planktivore are mutually exclusive
1037-
# so they share column 2, keeping the table at 3 columns maximum.
1039+
# so they share column 2, keeping the cbit column at index 3.
10381040
_PLOT_COLUMN_ORDER = (
10391041
("2column_cmocean", 0),
10401042
("2column_engineering", 1),
10411043
("2column_biolume", 2),
10421044
("2column_planktivore", 2),
1045+
("2column_cbit", 3),
10431046
)
10441047
_PLOT_KIND_LABELS = {
10451048
"2column_cmocean": "Standard",
10461049
"2column_biolume": "Bioluminescence",
10471050
"2column_planktivore": "Planktivore",
10481051
"2column_engineering": "Engineering",
1052+
"2column_cbit": "Cbit",
10491053
}
10501054

10511055
def _png_urls_for_nc(self, nc_url: str) -> list[str]:

0 commit comments

Comments
 (0)