Skip to content
Snippets Groups Projects
Select Git revision
  • 12a6155b788e6b2f2862b473b276ef154758f42b
  • master default protected
  • git-annex
  • synced/git-annex
  • simplicity
  • v0.63
  • v0.62
  • v0.61
  • v0.60
  • v0.59
  • v0.58
  • v0.57
  • v0.56
  • v0.55
  • v0.54
  • v0.53
  • v0.52
  • v0.51
  • v0.50
  • v0.49
  • v0.48
  • v0.47
  • v0.46
  • v0.45
  • v0.44
25 results

distribution_function.py

Blame
  • distribution_function.py 4.04 KiB
    #!/usr/bin/env python3
    
    from os import path
    
    import shapefile
    import numpy as np
    
    import jumble_matplotlib
    import util_eddies
    
    
    def read(dirname):
        """Read the three dbf files in dirname and return speed, radius and
        amplitude of outermost contour, radius and amplitude of maximum
        speed contour, as Numpy arrays.
    
        Select valid speed values.
    
        """
        SHPC = util_eddies.SHPC_class(dirname)
        extremum = SHPC.get_reader(0, "Anticyclones", "extremum")
        outerm_cont = SHPC.get_reader(0, "Anticyclones", "outermost_contour")
        max_speed_cont = SHPC.get_reader(0, "Anticyclones", "max_speed_contour")
        speed = []
        rad_outer = []
        rad_speed = []
        amp_outer = []
        amp_speed = []
    
        for rec_extr, rec_outer, rec_max in zip(
            extremum.iterRecords(),
            outerm_cont.iterRecords(),
            max_speed_cont.iterRecords(),
        ):
            if rec_extr.speed != 1e4:
                speed.append(rec_extr.speed)
    
            rad_outer.append(rec_outer.r_eq_area)
            amp_outer.append(rec_extr.ssh - rec_outer.ssh)
    
            if rec_max.r_eq_area != -100:
                rad_speed.append(rec_max.r_eq_area)
                amp_speed.append(rec_extr.ssh - rec_max.ssh)
    
        return {
            "speed": np.array(speed),
            "rad_outer": np.array(rad_outer),
            "rad_speed": np.array(rad_speed),
            "amp_outer": np.abs(np.array(amp_outer)),
            "amp_speed": np.abs(np.array(amp_speed)),
        }
    
    
    def plot_all(dict_list, label=None):
        """dict_list: list of dictionaries. label: list of labels, one label
        for each dictionary.
    
        """
    
        fig_list = []
        fig = jumble_matplotlib.fig_hist(
            "speed, in m s-1", [d["speed"] for d in dict_list], label
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_distr_funct(
            "speed, when positive, in m s-1",
            [d["speed"][d["speed"] >= 0] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_distr_funct(
            "speed, when negative, in m s-1",
            [-d["speed"][d["speed"] < 0] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_hist(
            "equivalent radius of outermost contour, in km",
            [d["rad_outer"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_distr_funct(
            "equivalent radius of outermost contour, in km",
            [d["rad_outer"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_hist(
            "equivalent radius of max-speed contour, in km",
            [d["rad_speed"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_distr_funct(
            "equivalent radius of max-speed contour, in km",
            [d["rad_speed"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_hist(
            "amplitude of outermost contour, in m",
            [d["amp_outer"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_distr_funct(
            "amplitude of outermost contour, in m",
            [d["amp_outer"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_hist(
            "amplitude of max-speed contour, in m",
            [d["amp_speed"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        fig = jumble_matplotlib.fig_distr_funct(
            "amplitude of max-speed contour, in m",
            [d["amp_speed"] for d in dict_list],
            label,
        )
        fig_list.append(fig)
        return fig_list
    
    
    if __name__ == "__main__":
        import argparse
    
        import matplotlib.pyplot as plt
    
        parser = argparse.ArgumentParser()
        parser.add_argument("SHPC", help="directory containing SHPC")
        parser.add_argument("--save", action="store_true")
        args = parser.parse_args()
        d = read(args.SHPC)
        fig_list = plot_all([d])
    
        if args.save:
            for i, fig in enumerate(fig_list):
                fig.savefig(f"figure_{i}.png")
    
            print(f"Created figure_[0-{len(fig_list)-1}].png")
        else:
            plt.show()