Skip to content
Snippets Groups Projects
Commit 79ba63df authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Extend to handle several input SHPC

This is necessary since we now output separately cyclones and
anticyclones from `inst_eddies.`
parent 6b30c633
No related branches found
No related tags found
No related merge requests found
......@@ -22,32 +22,52 @@ def compute_bbox(ishape_lists, reader_outer):
return bbox
def func(d, ax, ishape_lists, readers, bbox, light):
"""To be passed as argument to the animation function."""
def func(d, ax, ishape_lists_all, readers_all, bbox, light):
"""To be passed as argument to the animation
function. ishape_lists_all and readers_all are lists of
dictionaries.
"""
ax.cla()
ax.set_xlim(bbox[0], bbox[2])
ax.set_ylim(bbox[1], bbox[3])
plot_eddy_contours.snapshot(ax, ishape_lists[d], readers, light = light)
for ishape_lists, readers in zip(ishape_lists_all, readers_all):
plot_eddy_contours.snapshot(ax, ishape_lists[d], readers, light = light)
ax.gridlines(draw_labels = True)
ax.coastlines()
ax.set_title(f"d = {d}", y = 1.05)
def anim_eddies(fig, ax, d_init, ishape_last, readers, window, d_min, d_max,
light):
ishape_lists = {d: plot_eddy_contours.select_ishapes(d, d_init, ishape_last,
readers["extremum"],
window)
for d in range(d_min, d_max + 1)}
def anim_eddies(fig, ax, d_init, open_shpc_return, window, d_min, d_max, light):
"""open_shpc_return is a list of tuples."""
ishape_lists_all = []
readers_all = []
for readers, ishape_last in open_shpc_return:
ishape_lists = {d:
plot_eddy_contours.select_ishapes(d, d_init,
ishape_last,
readers["extremum"],
window)
for d in range(d_min, d_max + 1)}
ishape_lists_all.append(ishape_lists)
readers_all.append(readers)
if window is None:
bbox = compute_bbox(ishape_lists, readers["outermost_contour"])
bbox = None
for readers, ishape_lists in zip(readers_all, ishape_lists_all):
b2 = compute_bbox(ishape_lists, readers["outermost_contour"])
bbox = bbox_union(bbox, b2)
else:
bbox = window
ani = animation.FuncAnimation(fig, func, range(d_min, d_max + 1),
fargs = (ax, ishape_lists, readers, bbox,
light),
fargs = (ax, ishape_lists_all, readers_all,
bbox, light),
interval = 500)
return ani
......@@ -63,8 +83,8 @@ if __name__ == "__main__":
# Process arguments:
parser = argparse.ArgumentParser()
parser.add_argument("shpc_dir", help = "directory containing the "
"collection of shapefiles")
parser.add_argument("shpc_dir", help = "directories containing the "
"collections of shapefiles", nargs = "+")
parser.add_argument("-d", "--dates", type = int, nargs = 2,
metavar = ("d_min", "d_max"))
parser.add_argument("-l", "--light", help = "lighter plot",
......@@ -76,9 +96,11 @@ if __name__ == "__main__":
args = parser.parse_args()
#--
readers, d_init, ishape_last = util_eddies.open_shpc(args.shpc_dir)
if ishape_last is None: sys.exit("Missing ishape_last.txt")
readers, d_init, ishape_last = util_eddies.open_shpc(args.shpc_dir[0])
# Do some checks on first input SHPC:
if ishape_last is None: sys.exit("Missing ishape_last.txt")
if args.dates:
d_min = args.dates[0]
......@@ -89,10 +111,20 @@ if __name__ == "__main__":
else:
d_min = d_init
d_max = d_init + len(ishape_last) - 1
#--
open_shpc_return = [(readers, ishape_last)]
# We assume (and do not check) that ishape_last.txt exists and the
# dates are the same in all other SHPC:
for shpc_dir in args.shpc_dir[1:]:
readers, d_init, ishape_last = util_eddies.open_shpc(shpc_dir)
open_shpc_return.append((readers, ishape_last))
fig = plt.figure()
projection = ccrs.PlateCarree()
ax = plt.axes(projection = projection)
ani = anim_eddies(fig, ax, d_init, ishape_last, readers, args.window, d_min,
ani = anim_eddies(fig, ax, d_init, open_shpc_return, args.window, d_min,
d_max, args.light)
ani.save("eddy_contours.gif", writer = "imagemagick")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment