Skip to content

Commit 40afba3

Browse files
committed
better tc plots image
1 parent f5c2f57 commit 40afba3

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

adforce/tc_plots.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
Usage:
88
python -m adforce.plotting [--test-single] [--output-name "track_summary.pdf"]
99
"""
10-
10+
from typing import List
1111
import os
1212
import numpy as np
1313
import netCDF4 as nc
1414
import xarray as xr
1515
import pandas as pd
16-
from adcircpy import AdcircMesh
1716
import matplotlib.pyplot as plt
1817
from matplotlib.collections import LineCollection
1918
from matplotlib.colors import ListedColormap, BoundaryNorm
2019
import argparse
21-
from sithom.plot import plot_defaults, get_dim
20+
from sithom.plot import plot_defaults
2221

2322
# --- Assuming constants.py and ibtracs.py are accessible ---
2423
# Use .constants and .ibtracs if running as a module,
@@ -37,31 +36,35 @@
3736
sys.path.append(PROJ_PATH)
3837
from tcpips.ibtracs import na_landing_tcs
3938

40-
from .generate_training_data import _decode_char_array
4139
from .constants import DATA_PATH
4240

4341
plot_defaults()
4442

45-
# --- Saffir-Simpson Scale Definitions (in m/s) ---
43+
# --- Saffir-Simpson Scale Definitions (in m s$^{-1}$) ---
4644
KNOTS_TO_MS = 0.514444
4745

4846
# Original wind speed bins in knots
49-
SS_BINS_KNOTS = [0, 34, 64, 83, 96, 113, 137, 500] # Bin edges
50-
51-
# Convert bins to m/s and round to one decimal
52-
SS_BINS = [np.round(kt * KNOTS_TO_MS, 1) for kt in SS_BINS_KNOTS]
47+
#SS_BINS_KNOTS = [0, 34, 64, 83, 96, 113, 137, 500] # Bin edges
48+
# Convert bins to m s$^{-1}$ and round to one decimal
49+
SS_BINS = [0, 17.5, 33, 43, 50, 58, 70, 86, 500] # in m s$^{-1}$
5350
# Result: [0.0, 17.5, 32.9, 42.7, 49.4, 58.1, 70.5, 257.2]
5451

55-
SS_COLORS = ['blue', 'green', 'yellow', 'orange', 'red', 'darkred', 'magenta']
56-
57-
# Labels updated to reflect m/s
58-
SS_LABELS = [
59-
'TD (<17.5 m/s)', 'TS (17.5-32.8 m/s)', 'Cat 1 (32.9-42.6 m/s)',
60-
'Cat 2 (42.7-49.3 m/s)', 'Cat 3 (49.4-58.0 m/s)',
61-
'Cat 4 (58.1-70.4 m/s)', 'Cat 5 (70.5+ m/s)'
52+
SS_COLORS = ['cyan', 'green', 'yellow', 'orange', 'red', 'darkred', 'magenta', 'black']
53+
54+
# Labels updated to reflect m s$^{-1}$
55+
SS_LABELS: List[str] = [
56+
'TD (<17.5 m s$^{-1}$)',
57+
'TS (17.5-33 m s$^{-1}$)',
58+
'Cat 1 (33-43 m s$^{-1}$)',
59+
'Cat 2 (43-50 m s$^{-1}$)',
60+
'Cat 3 (50-58 m s$^{-1}$)',
61+
'Cat 4 (58-70 m s$^{-1}$)',
62+
'Cat 5 (70-86 m s$^{-1}$)',
63+
'Cat 6 (86.0+ m s$^{-1}$)'
6264
]
65+
6366
SS_CMAP = ListedColormap(SS_COLORS)
64-
SS_NORM = BoundaryNorm(SS_BINS, SS_CMAP.N) # This now uses the m/s bins
67+
SS_NORM = BoundaryNorm(SS_BINS, SS_CMAP.N) # This now uses the m s$^{-1}$ bins
6568

6669

6770
# --- Plotting Function ---
@@ -102,7 +105,7 @@ def plot_all_tc_tracks_on_mesh(
102105
print("Plotting mesh background...")
103106
ax.triplot(
104107
x_nodes, y_nodes, triangles,
105-
color='grey', alpha=0.2, linewidth=0.1, label='ADCIRC Mesh'
108+
color='blue', alpha=0.3, linewidth=0.1, label='ADCIRC Mesh'
106109
)
107110

108111
# Determine storms to plot
@@ -123,20 +126,15 @@ def plot_all_tc_tracks_on_mesh(
123126
tracks_plotted = 0
124127
for i in indices:
125128
storm_ds = all_storms_ds.isel(storm=i)
126-
storm_name = _decode_char_array(storm_ds['name'])
127129

128130
# Extract and clean data
129131
lat = storm_ds['usa_lat'].values
130132
lon = storm_ds['usa_lon'].values
131-
wind = storm_ds['usa_wind'].values * KNOTS_TO_MS # Convert to m/s
133+
wind = storm_ds['usa_wind'].values * KNOTS_TO_MS # Convert to m s$^{-1}$
132134

133135
valid_mask = ~np.isnan(lat) & ~np.isnan(lon) & ~np.isnan(wind)
134136
lat, lon, wind = lat[valid_mask], lon[valid_mask], wind[valid_mask]
135137

136-
# --- CONVERT TO M/S ---
137-
# Data from IBTrACS (via na_landing_tcs) is in knots, convert to m/s
138-
wind = wind * KNOTS_TO_MS
139-
# ----------------------
140138

141139
if len(lat) < 2:
142140
# print(f"Skipping {storm_name} (insufficient data).")
@@ -147,15 +145,18 @@ def plot_all_tc_tracks_on_mesh(
147145
segments = np.concatenate([points[:-1], points[1:]], axis=1)
148146

149147
# Use wind at the start of each segment for coloring
150-
# This is now in m/s
148+
# This is now in m s$^{-1}$
151149
segment_winds = wind[:-1]
152150

153151
# Create a LineCollection
154152
lc = LineCollection(
155-
segments, cmap=SS_CMAP, norm=SS_NORM,
156-
linewidths=0.5, alpha=0.7 # Thinner, semi-transparent lines
153+
segments,
154+
cmap=SS_CMAP,
155+
norm=SS_NORM,
156+
linewidths=0.5,
157+
alpha=0.7 # Thinner, semi-transparent lines
157158
)
158-
lc.set_array(segment_winds) # Set array with m/s values
159+
lc.set_array(segment_winds) # Set array with m s$^{-1}$ values
159160
ax.add_collection(lc)
160161
tracks_plotted += 1
161162

@@ -187,7 +188,7 @@ def plot_all_tc_tracks_on_mesh(
187188
# spacing='proportional'
188189
)
189190
cbar.ax.set_yticklabels(SS_LABELS, fontsize='small')
190-
cbar.set_label("Wind Speed (m/s) - Saffir-Simpson Scale") # Updated label
191+
cbar.set_label("Wind Speed (m s$^{-1}$) - Saffir-Simpson Scale") # Updated label
191192

192193
# Save the figure
193194
os.makedirs(os.path.dirname(output_path), exist_ok=True)
@@ -234,7 +235,7 @@ def plot_all_tc_tracks_on_mesh(
234235
os.makedirs(output_folder, exist_ok=True)
235236
output_plot_path = os.path.join(output_folder, output_file)
236237

237-
# The plotting function will now handle the conversion to m/s
238+
# The plotting function will now handle the conversion to m s$^{-1}$
238239
plot_all_tc_tracks_on_mesh(
239240
all_storms_ds=all_storms_ds,
240241
mesh_path=os.path.join(DATA_PATH, "exp_0049", "fort.63.nc"),

0 commit comments

Comments
 (0)