Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ repos:
rev: v3.5.1
hooks:
- id: prettier
exclude: "docs/user-guide/developer-content/parcels-meeting-Nov2025/presentation/.*" # these quarto files break prettier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make more generic?

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import csv
import subprocess
import time

import psutil

DIRS = ["CTD", "plus_CTD_BGC", "plus_DRIFTER", "plus_ARGO", "plus_UNDERWAY"]
RESULTS_FILE = "performance_results.csv"

# Write header once at the start
with open(RESULTS_FILE, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Directory", "Time (s)", "Peak RAM (MB)"])


def run_and_trace(cmd):
start_time = time.time()
process = subprocess.Popen(cmd, shell=True)
proc = psutil.Process(process.pid)
peak_mem = 0

while process.poll() is None:
try:
mem = proc.memory_info().rss / (1024 * 1024) # MB
if mem > peak_mem:
peak_mem = mem
except psutil.NoSuchProcess:
break
time.sleep(0.1)

end_time = time.time()
return end_time - start_time, peak_mem


for dir_name in DIRS:
cmd = f"virtualship run ../{dir_name}"
print(f"Running: {cmd}")
elapsed, peak_mem = run_and_trace(cmd)
# Write result after each iteration
with open(RESULTS_FILE, "a", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow([dir_name, f"{elapsed:.2f}", f"{peak_mem:.2f}"])

print(f"\nResults written to {RESULTS_FILE}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import csv
import subprocess
import time

import psutil

DIRS = ["CTD", "plus_CTD_BGC", "plus_DRIFTER", "plus_ARGO", "plus_UNDERWAY"]
RESULTS_FILE = "performance_results_fromdata.csv"

# Write header once at the start
with open(RESULTS_FILE, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Directory", "Time (s)", "Peak RAM (MB)"])


def run_and_trace(cmd):
start_time = time.time()
process = subprocess.Popen(cmd, shell=True)
proc = psutil.Process(process.pid)
peak_mem = 0

while process.poll() is None:
try:
mem = proc.memory_info().rss / (1024 * 1024) # MB
if mem > peak_mem:
peak_mem = mem
except psutil.NoSuchProcess:
break
time.sleep(0.1)

end_time = time.time()
return end_time - start_time, peak_mem


for dir_name in DIRS:
cmd = f"virtualship run ../{dir_name} --from-data ../data"
print(f"Running: {cmd}")
elapsed, peak_mem = run_and_trace(cmd)
# Write result after each iteration
with open(RESULTS_FILE, "a", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow([dir_name, f"{elapsed:.2f}", f"{peak_mem:.2f}"])

print(f"\nResults written to {RESULTS_FILE}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

# data
df_default = pd.read_csv("results/performance_results.csv")
df_fromdata = pd.read_csv("results/performance_results_fromdata.csv")

## plot
fig, ax = plt.subplots(1, 1, figsize=(12, 7), dpi=96)

MARKERSIZE = 75
LINEWIDTH = 2.5
ymin, ymax, interval = 0, 800, 100

FROM_DATA = True
LAST_POINT = True

SHOW_UNDERWAY_FROMDATA = False

xticks = [
"Just CTD",
"CTD + CTD_BGC",
"CTD + CTD_BGC \n+ Drifters",
"CTD + CTD_BGC \n+ Drifters + Argo Floats",
"CTD + CTD_BGC \n+ Drifters + Argo Floats \n+ ADCP/Underway S/T",
]

# default
ax.scatter(
df_default["Directory"],
df_default["Time (s)"],
label="on-the-fly (via copernicusmarine)",
color="dodgerblue",
s=MARKERSIZE,
zorder=3,
)
ax.plot(
df_default["Directory"],
df_default["Time (s)"],
lw=LINEWIDTH,
ls="dotted",
color="dodgerblue",
zorder=3,
)

# fromdata
if FROM_DATA:
ax.scatter(
df_fromdata["Directory"] if LAST_POINT else df_fromdata["Directory"][:-1],
df_fromdata["Time (s)"] if LAST_POINT else df_fromdata["Time (s)"][:-1],
label="from-data (pre-downloaded data)",
color="crimson",
s=MARKERSIZE,
zorder=3,
)
ax.plot(
df_fromdata["Directory"] if LAST_POINT else df_fromdata["Directory"][:-1],
df_fromdata["Time (s)"] if LAST_POINT else df_fromdata["Time (s)"][:-1],
lw=LINEWIDTH,
ls="dotted",
color="crimson",
zorder=3,
)

# x/y ticks/lims
if not SHOW_UNDERWAY_FROMDATA:
ax.set_ylim(ymin, ymax + interval)
yticks = np.arange(ymin, ymax + 1, interval)
elif SHOW_UNDERWAY_FROMDATA:
ax.set_ylim(ymin, ymax * 5 + interval)
yticks = np.arange(ymin, ymax * 5 + 1, 5 * interval)
ax.set_yticks(yticks)
ax.set_yticklabels([round(val, 0) for val in yticks / 60.0]) # [minutes]
ax.set_xticks(range(len(xticks)))
ax.set_xticklabels(xticks, rotation=45, ha="right")

# axes labels
ax.set_ylabel("Time (minutes)")

# grid
ax.set_facecolor("gainsboro")
ax.grid(True, alpha=1.0, color="white")

# title
# ax.set_title("MHW expedition performance [64GB RAM, 8 cores]")

plt.legend(loc="upper left")

plt.tight_layout()
plt.show()


# TODO: add machine spec info to plot (annotate or whatever)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Directory,Time (s),Peak RAM (MB)
CTD,39.49,0.95
plus_CTD_BGC,132.87,0.93
plus_DRIFTER,155.63,0.95
plus_ARGO,506.98,0.96
plus_UNDERWAY,796.10,0.97
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Directory,Time (s),Peak RAM (MB)
CTD,13.73,0.98
plus_CTD_BGC,24.85,0.99
plus_DRIFTER,32.48,0.95
plus_ARGO,96.63,0.95
plus_UNDERWAY,3969.64,0.99
Loading