Skip to content

Commit

Permalink
Merge pull request #633 from mandli/add-track-plotting
Browse files Browse the repository at this point in the history
Add storm track plotting
  • Loading branch information
mandli authored Nov 14, 2024
2 parents 00e7eed + 818543e commit 3551c96
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 212 deletions.
248 changes: 120 additions & 128 deletions src/python/geoclaw/surge/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,33 @@ def days_figure_title(cd, land_fall=0.0, new_time=False):


def surge_afteraxes(current_data, track, land_fall=0.0, plot_direction=False,
style='ro', kwargs={}):
plot_track=False, style='ro', track_style='k',
new_time=False, kwargs={}):
"""Default surge plotting after axes function
Includes changing the title to something relative to landfall and plotting
the location of the storm eye according to the track object.
the location of the storm eye according to the track object. Optional
plotting includes the direction of the storm with *plot_direction* and
*plot_track* which plots the entire track of the storm.
"""
track_data = track.get_track(current_data.frameno)

if track_data[0] is not None and track_data[1] is not None:
axes = plt.gca()
axes.plot(track_data[0], track_data[1], style, **kwargs)
ax = plt.gca()
ax.plot(track_data[0], track_data[1], style, **kwargs)
# Plot direction
if plot_direction:
axes.quiver(track_data[0], track_data[1],
ax.quiver(track_data[0], track_data[1],
np.cos(track_data[2]), np.sin(track_data[2]))
days_figure_title(current_data, land_fall)
# Plot full track
if plot_track:
# TO DO: Could add categorization but really should use storm object
# for this
for i in range(1, track._data.shape[0]):
ax.plot(track._data[i-1:i+1, 1], track._data[i-1:i+1, 2],
track_style)

days_figure_title(current_data, land_fall=land_fall, new_time=new_time)


def friction(cd):
Expand Down Expand Up @@ -484,38 +496,38 @@ def sec2days(seconds):
return seconds / (60.0**2 * 24.0)


def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None):
r"""Plot hurricane track given a storm.data file"""
# def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None):
# r"""Plot hurricane track given a storm.data file"""

if name is None:
name = ""
else:
name = " - %s" % name
# if name is None:
# name = ""
# else:
# name = " - %s" % name

colors = ['r', 'b']
divide = (np.max(Pc) + np.min(Pc)) / 2.0
# colors = ['r', 'b']
# divide = (np.max(Pc) + np.min(Pc)) / 2.0

fig = plt.figure(1)
axes = fig.add_subplot(111)
indices = Pc < divide
axes.scatter(x[indices], y[indices], color='r', marker='o')
indices = Pc >= divide
axes.scatter(x[indices], y[indices], color='b', marker='o')
axes.set_title("Track%s" % name)
# fig = plt.figure(1)
# axes = fig.add_subplot(111)
# indices = Pc < divide
# axes.scatter(x[indices], y[indices], color='r', marker='o')
# indices = Pc >= divide
# axes.scatter(x[indices], y[indices], color='b', marker='o')
# axes.set_title("Track%s" % name)

fig = plt.figure(2, figsize=(24, 6))
axes = fig.add_subplot(131)
axes.plot(sec2days(t), wind_speed)
axes.set_title("Maximum Wind Speed%s" % name)
# fig = plt.figure(2, figsize=(24, 6))
# axes = fig.add_subplot(131)
# axes.plot(sec2days(t), wind_speed)
# axes.set_title("Maximum Wind Speed%s" % name)

axes = fig.add_subplot(132)
axes.plot(sec2days(t), wind_radius)
axes.set_title("Maximum Wind Radius%s" % name)
# axes = fig.add_subplot(132)
# axes.plot(sec2days(t), wind_radius)
# axes.set_title("Maximum Wind Radius%s" % name)

axes = fig.add_subplot(133)
axes.plot(sec2days(t), Pc)
axes.plot(sec2days(t), np.ones(t.shape) * divide, 'k--')
axes.set_title("Central Pressure%s" % name)
# axes = fig.add_subplot(133)
# axes.plot(sec2days(t), Pc)
# axes.plot(sec2days(t), np.ones(t.shape) * divide, 'k--')
# axes.set_title("Central Pressure%s" % name)


"""Plot the track and optionally the intensity of the storm
Expand Down Expand Up @@ -545,99 +557,79 @@ def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None):
# ========================================================================


def add_track(Storm, axes, plot_package=None, category_color=None, legend_loc='best',
intensity=False, categorization="NHC", limits=None, track_color='red'):

if category_color is None:
category_color = {5: 'red',
4: 'orange',
3: 'yellow',
2: 'blue', # edit color
1: 'violet',
0: 'black',
-1: 'gray'}
category = Storm.category(categorization=categorization)

# make it if intensity = true

# basic plotting
longitude = Storm.eye_location[:, 0]
latitude = Storm.eye_location[:, 1]
for i in range(len(longitude)):
if intensity:
color = category_color[category[i]]
else:
color = track_color
axes.plot(longitude[i:i + 2], latitude[i:i + 2], color=color)

axes.set_xlabel("Longitude")
axes.set_ylabel("Latitude")

categories_legend = []

if intensity and categorization == "NHC":
categories_legend = []
# plotitem = plotaxes.new_plotitem(name='category', plot_type='1d_plot')

if (-1 in category):
negativeone = mlines.Line2D(
[], [], color=category_color[-1], marker='s', ls='', label="Tropical Depression")
categories_legend.append(negativeone)

if (0 in category):
zero = mlines.Line2D(
[], [], color=category_color[0], marker='s', ls='', label="Tropical Storn")
categories_legend.append(zero)

if (1 in category):
one = mlines.Line2D([], [], color=category_color[1],
marker='s', ls='', label="Category 1")
categories_legend.append(one)

if (2 in category):
two = mlines.Line2D([], [], color=category_color[2],
marker='s', ls='', label="Category 2")
categories_legend.append(two)

if (3 in category):
three = mlines.Line2D(
[], [], color=category_color[3], marker='s', ls='', label="Category 3")
categories_legend.append(three)

if (4 in category):
four = mlines.Line2D(
[], [], color=category_color[4], marker='s', ls='', label="Category 4")
categories_legend.append(four)

if (5 in category):
five = mlines.Line2D(
[], [], color=category_color[5], marker='s', ls='', label="Category 5")
categories_legend.append(five)

plt.legend(handles=categories_legend, loc=legend_loc)

# if bounds is not None:
# plotitem.pcolor_cmin = bounds[0]
# plotitem.pcolor_cmax = bounds[1]

return axes

# if plot_type == 'pcolor' or plot_type == 'imshow':
# plotitem = plotaxes.new_plotitem(name='wind', plot_type='2d_pcolor')
# plotitem.plot_var = wind_speed
# plotitem.pcolor_cmap = wind_cmap
# if bounds is not None:
# plotitem.pcolor_cmin = bounds[0]
# plotitem.pcolor_cmax = bounds[1]
# plotitem.add_colorbar = True
# plotitem.colorbar_shrink = shrink
# plotitem.colorbar_label = "Wind Speed (m/s)"
# plotitem.amr_celledges_show = [0] * 10
# plotitem.amr_patchedges_show = [1, 1, 1, 1, 1, 0, 0]

# elif plot_type == 'contour':
# plotitem = plotaxes.new_plotitem(name='wind', plot_type='2d_contour')
# plotitem.plot_var = wind_speed
# plotitem.contour_nlevels = len(surge_data.wind_refine)
# plotitem.countour_min = surge_data.wind_refine[0]
# plotitem.patchedges_show = 1
# def add_track(Storm, axes, plot_package=None, category_color=None, legend_loc='best',
# intensity=False, categorization="NHC", limits=None, track_color='red'):

# if category_color is None:
# category_color = {5: 'red',
# 4: 'orange',
# 3: 'yellow',
# 2: 'blue', # edit color
# 1: 'violet',
# 0: 'black',
# -1: 'gray'}
# category = Storm.category(categorization=categorization)

# # make it if intensity = true

# # basic plotting
# longitude = Storm.eye_location[:, 0]
# latitude = Storm.eye_location[:, 1]
# for i in range(len(longitude)):
# if intensity:
# color = category_color[category[i]]
# else:
# color = track_color
# axes.plot(longitude[i:i + 2], latitude[i:i + 2], color=color)

# axes.set_xlabel("Longitude")
# axes.set_ylabel("Latitude")

# categories_legend = []

# if intensity and categorization == "NHC":
# categories_legend = []
# # plotitem = plotaxes.new_plotitem(name='category', plot_type='1d_plot')

# if (-1 in category):
# negativeone = mlines.Line2D(
# [], [], color=category_color[-1], marker='s', ls='', label="Tropical Depression")
# categories_legend.append(negativeone)

# if (0 in category):
# zero = mlines.Line2D(
# [], [], color=category_color[0], marker='s', ls='', label="Tropical Storn")
# categories_legend.append(zero)

# if (1 in category):
# one = mlines.Line2D([], [], color=category_color[1],
# marker='s', ls='', label="Category 1")
# categories_legend.append(one)

# if (2 in category):
# two = mlines.Line2D([], [], color=category_color[2],
# marker='s', ls='', label="Category 2")
# categories_legend.append(two)

# if (3 in category):
# three = mlines.Line2D(
# [], [], color=category_color[3], marker='s', ls='', label="Category 3")
# categories_legend.append(three)

# if (4 in category):
# four = mlines.Line2D(
# [], [], color=category_color[4], marker='s', ls='', label="Category 4")
# categories_legend.append(four)

# if (5 in category):
# five = mlines.Line2D(
# [], [], color=category_color[5], marker='s', ls='', label="Category 5")
# categories_legend.append(five)

# plt.legend(handles=categories_legend, loc=legend_loc)

# # if bounds is not None:
# # plotitem.pcolor_cmin = bounds[0]
# # plotitem.pcolor_cmax = bounds[1]

# return axes
Loading

0 comments on commit 3551c96

Please sign in to comment.