diff --git a/Inst_eddies/Analysis/anim_eddy_contours.py b/Inst_eddies/Analysis/anim_eddy_contours.py index 0b7df81dc37f81727e78c2f004bb7bdb0a47a603..213157c24e2575a1d9712eb292b379f7fec16798 100755 --- a/Inst_eddies/Analysis/anim_eddy_contours.py +++ b/Inst_eddies/Analysis/anim_eddy_contours.py @@ -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")