diff --git a/Analysis/plot_snapshot.py b/Analysis/plot_snapshot.py index 2a05b9c38c1899b0ec63ba38c0eb974f7958eee6..3fe83c4fe3c95da17da9e916786f4e8aded58356 100755 --- a/Analysis/plot_snapshot.py +++ b/Analysis/plot_snapshot.py @@ -25,6 +25,7 @@ import numpy as np import math import cartopy.crs as ccrs from os import path +from matplotlib import animation def select_ishapes(k, k1, ishape_last, reader_extr, window = None): assert k >= k1 @@ -140,6 +141,44 @@ def plot_grid_bb(shp_tr_dir, ax): fill=False) ax.add_patch(rect) +def func(k, ax, ishape_lists, reader_extr, reader_outer, reader_m_s, bbox): + ax.cla() + ax.set_xlim(bbox[0], bbox[2]) + ax.set_ylim(bbox[1], bbox[3]) + ax.gridlines(draw_labels = True) + ax.coastlines() + snapshot(k, ax, ishape_lists[k], reader_extr, reader_outer, reader_m_s) + +def bbox_union(b1, b2): + if b1 is None: + return b2 + else: + return [min(b1[0], b2[0]), min(b1[1], b2[1]), max(b1[2], b2[2]), + max(b1[3], b2[3])] + +def compute_bbox(ishape_lists, reader_outer): + bbox = None + + for ishape_list in ishape_lists.values(): + for ishape in ishape_list: + try: + bbox = bbox_union(bbox, reader_outer.shape(ishape).bbox) + except AttributeError: + pass + + return bbox + +def make_animation(fig, ax, k1, ishape_last, reader_extr, reader_outer, + reader_m_s, window, k_min, k_max): + ishape_lists = {k: select_ishapes(k, k1, ishape_last, reader_extr, window) + for k in range(k_min, k_max + 1)} + bbox = compute_bbox(ishape_lists, reader_outer) + ani = animation.FuncAnimation(fig, func, range(k_min, k_max + 1), + fargs = (ax, ishape_lists, reader_extr, + reader_outer, reader_m_s, bbox), + interval = 1000, repeat = False) + return ani + if __name__ == "__main__": import matplotlib.pyplot as plt import argparse