示例#1
0
        def make_plot(lengths_2D, lengths_3D, scaled_sources, L_profile_rate,
                      max_L_bin):
            import matplotlib.pyplot as plt
            cmap = 'cubehelix_r'

            fig = plt.figure(figsize=(7.5, 10))
            ax_L = fig.add_subplot(311)
            ax_prof_L = fig.add_subplot(312)
            ax_prof_src = fig.add_subplot(313)

            min_L_bin = 0 * max_L_bin

            src_pm = ax_prof_src.pcolormesh(t_edges,
                                            alt_bins,
                                            scaled_sources,
                                            cmap=cmap,
                                            vmin=min_L_bin,
                                            vmax=max_L_bin)
            src_pm.set_rasterized(True)
            cbar_src = fig.colorbar(src_pm,
                                    ax=ax_prof_src,
                                    orientation='horizontal')
            cbar_src.set_label(
                'Source count per height interval per time\n(scaled to max length, km/km/min)'
            )

            L_pm = ax_prof_L.pcolormesh(t_edges,
                                        alt_bins,
                                        L_profile_rate,
                                        cmap=cmap,
                                        vmin=min_L_bin,
                                        vmax=max_L_bin)
            L_pm.set_rasterized(True)
            cbar_L = fig.colorbar(L_pm, ax=ax_prof_L, orientation='horizontal')
            cbar_L.set_label(
                'Length per height interval per time\n(km/km/min)')

            for ax in (ax_prof_src, ax_prof_L):
                ax.set_ylabel('Altitude (km)')

            ax_L.plot(t_centers, lengths_2D, label='2D Hull Area')
            ax_L.plot(t_centers, lengths_3D, label='3D Hull Volume')
            ax_L.legend()
            ax_L.set_ylabel('Fractal Length (km/min)')

            for ax in (ax_L, ax_prof_L, ax_prof_src):
                ax.xaxis.set_major_formatter(
                    SecDayFormatter(self.basedate, ax.xaxis))
                ax.set_xlabel('Time (UTC)')
                ax.xaxis.set_major_locator(MultipleLocator(3600))
            return fig
示例#2
0
    def plot(self):
        fig = plt.figure(figsize=(11, 8.5))
        starts = np.fromiter(
            ((s - self.basedate).total_seconds() for s in self.t_start),
            dtype=float)
        ends = np.fromiter(
            ((e - self.basedate).total_seconds() for e in self.t_end),
            dtype=float)
        t = (starts + ends) / 2.0
        window_size = (ends - starts) / 60.0  # in minutes
        moments = np.asarray(self.moments)  # N by n_moments

        ax_energy = fig.add_subplot(2, 2, 2)
        ax_energy.plot(t, self.energy / window_size, label='Total energy')
        ax_energy.legend()

        ax_count = fig.add_subplot(2, 2, 1, sharex=ax_energy)
        #ax_count.plot(t, self.energy_per/window_size, label='$E_T$ flash$^{-1}$ min$^{-1}$ ')
        ax_count.plot(t,
                      moments[:, 0] / window_size,
                      label='Flash rate (min$^{-1}$)')
        ax_count.legend()  #location='upper left')

        ax_mean = fig.add_subplot(2, 2, 3, sharex=ax_energy)
        mean, std, skew, kurt = moments[:,
                                        1], moments[:,
                                                    2], moments[:,
                                                                3], moments[:,
                                                                            4]
        sigma = np.sqrt(std)
        ax_mean.plot(t, mean, label='Mean flash size (km)')
        ax_mean.plot(t, sigma, label='Standard deviation (km)')
        ax_mean.set_ylim(0, 20)
        ax_mean.legend()
        #         ax_mean.fill_between(t, mean+sigma, mean-sigma, facecolor='blue', alpha=0.5)

        ax_higher = fig.add_subplot(2, 2, 4, sharex=ax_energy)
        ax_higher.plot(t, skew, label='Skewness')
        ax_higher.plot(t, kurt, label='Kurtosis')
        ax_higher.set_ylim(-2, 10)
        ax_higher.legend()

        for ax in fig.get_axes():
            ax.xaxis.set_major_formatter(
                SecDayFormatter(self.basedate, ax.xaxis))
            ax.set_xlabel('Time (UTC)')
            ax.xaxis.set_major_locator(MultipleLocator(3600))
            ax.xaxis.set_minor_locator(MultipleLocator(1800))
        return fig
示例#3
0
def plot_flash_stat_time_series(basedate,
                                t_edges,
                                stats,
                                major_tick_every=1800):
    t_start, t_end = t_edges[:-1], t_edges[1:]
    fig = plt.figure(figsize=(11, 8.5))
    starts = np.fromiter(((s - basedate).total_seconds() for s in t_start),
                         dtype=float)
    ends = np.fromiter(((e - basedate).total_seconds() for e in t_end),
                       dtype=float)
    t = (starts + ends) / 2.0
    window_size = (ends - starts) / 60.0  # in minutes

    ax_energy = fig.add_subplot(2, 2, 2)
    ax_energy.plot(t, stats['energy'] / window_size, label='Total energy')
    ax_energy.legend()

    ax_count = fig.add_subplot(2, 2, 1, sharex=ax_energy)
    # ax_count.plot(t, stats['energy_per_flash']/window_size, label='$E_T$ flash$^{-1}$ min$^{-1}$ ')
    ax_count.plot(t,
                  stats['number'] / window_size,
                  label='Flash rate (min$^{-1}$)')
    ax_count.legend()  #location='upper left')

    ax_mean = fig.add_subplot(2, 2, 3, sharex=ax_energy)
    mean, std = stats['mean'], stats['variance'],
    skew, kurt = stats['skewness'], stats['kurtosis']
    sigma = np.sqrt(std)
    ax_mean.plot(t, mean, label='Mean flash size (km)')
    ax_mean.plot(t, sigma, label='Standard deviation (km)')
    ax_mean.set_ylim(0, 20)
    ax_mean.legend()
    #         ax_mean.fill_between(t, mean+sigma, mean-sigma, facecolor='blue', alpha=0.5)

    ax_higher = fig.add_subplot(2, 2, 4, sharex=ax_energy)
    ax_higher.plot(t, skew, label='Skewness')
    ax_higher.plot(t, kurt, label='Kurtosis')
    ax_higher.set_ylim(-2, 10)
    ax_higher.legend()

    for ax in fig.get_axes():
        ax.xaxis.set_major_formatter(SecDayFormatter(basedate, ax.xaxis))
        ax.set_xlabel('Time (UTC)')
        ax.xaxis.set_major_locator(MultipleLocator(major_tick_every))
        ax.xaxis.set_minor_locator(MultipleLocator(major_tick_every / 2.0))
    return fig
示例#4
0
    def __init__(self, *args, **kwargs):
        self.names_4D = kwargs.pop('names_4D', ('lon', 'lat', 'alt', 'time'))
        self.figure = kwargs.pop('figure', None)
        self.basedate = kwargs.pop('basedate', None)
        if self.basedate is None:
            self.basedate = datetime.datetime(1970,1,1,0,0,0)

        ctr_lat, ctr_lon, ctr_alt = kwargs.pop('ctr_lat', 33.5), kwargs.pop('ctr_lon', -101.5), kwargs.pop('ctr_alt', 0.0)
        self.cs = CoordinateSystemController(ctr_lat, ctr_lon, ctr_alt)
        
        if self.figure is not None:
            fig = self.figure
            self.panels = {}
            self.panels['xy'] = fig.add_axes(Panels4D.margin_defaults['xy'])
            self.panels['xz'] = fig.add_axes(Panels4D.margin_defaults['xz'], sharex=self.panels['xy'])
            self.panels['zy'] = fig.add_axes(Panels4D.margin_defaults['zy'], sharey=self.panels['xy'])
            self.panels['tz'] = fig.add_axes(Panels4D.margin_defaults['tz'], sharey=self.panels['xz'])
            
            self.panels['xy'].set_xlabel('East distance (km)')
            self.panels['xy'].set_ylabel('North distance (km)')
            self.panels['xz'].set_ylabel('Altitude (km)')
            self.panels['zy'].set_xlabel('Altitude (km)')
            self.panels['tz'].set_xlabel('Time (UTC)')
            self.panels['tz'].set_ylabel('Altitude (km)')
                        
            ax_specs = { self.panels['xy']: (self.names_4D[0], self.names_4D[1]), 
                         self.panels['xz']: (self.names_4D[0], self.names_4D[2]),
                         self.panels['zy']: (self.names_4D[2], self.names_4D[1]),
                         self.panels['tz']: (self.names_4D[3], self.names_4D[2]), }
            kwargs['ax_specs'] = ax_specs
            
            self.panels['tz'].xaxis.set_major_formatter(SecDayFormatter(self.basedate, self.panels['tz'].xaxis))
            
        super(Panels4D, self).__init__(*args, **kwargs)
        
        # The built-in is a good idea. But zooming on a wide, short area in x,y causes the
        # data to subset but the axes to remain zoomed out. There is some sort of
        # problematic interaciton with the interaction-complete notification.
        # self.panels['xy'].set_aspect('equal')
        self.equal_ax.add(self.panels['xy'])

        # Note this won't work in <1.2.x: https://github.com/matplotlib/matplotlib/pull/1585/
        resize_id = self.figure.canvas.mpl_connect('resize_event', self._figure_resized)
示例#5
0
def plot_tot_energy_stats(size_stats, basedate, t_edges, outdir):
    t_start, t_end = t_edges[:-1], t_edges[1:]
    starts = np.fromiter(((s - basedate).total_seconds() for s in t_start),
                         dtype=float)
    ends = np.fromiter(((e - basedate).total_seconds() for e in t_end),
                       dtype=float)
    t = (starts + ends) / 2.0

    specific_energy = np.abs(size_stats)

    figure = plt.figure(figsize=(15, 10))
    ax = figure.add_subplot(111)
    ax.plot(t, specific_energy, 'k-', label='Total Energy', alpha=0.6)
    plt.legend()
    # ax.set_xlabel('Time UTC')
    ax.set_ylabel('Total Energy (J)')

    for axs in figure.get_axes():
        axs.xaxis.set_major_formatter(SecDayFormatter(basedate, axs.xaxis))
        axs.set_xlabel('Time (UTC)')
        axs.xaxis.set_major_locator(MultipleLocator(1800))
        axs.xaxis.set_minor_locator(MultipleLocator(1800 / 2))

    return figure
示例#6
0
    def make_time_series_plot(self,
                              basedate,
                              t_edges,
                              lengths_2D,
                              lengths_3D,
                              scaled_sources,
                              L_profile_rate,
                              max_L_bin,
                              label_t_every=3600.,
                              figsize=(7.5, 10)):
        """ Arguments: 
            t_edges: N+1 bin boundaries corresponding to the N time series values in the
                    other arguments. Units: seconds since start of day.
            lengths_2D, lengths_3D, scaled_sources, L_profile_rate, max_L_bin: 
                    The values returned by normalize_profiles
            label_t_every: interval in seconds at which to label the time axis
            figsize: (width, height) of figure in inches (passed to matplotlib.figure)
            
        """
        import matplotlib.pyplot as plt
        cmap = 'cubehelix_r'

        fig = plt.figure(figsize=figsize)
        ax_L = fig.add_subplot(311)
        ax_prof_L = fig.add_subplot(312)
        ax_prof_src = fig.add_subplot(313)

        min_L_bin = 0 * max_L_bin

        starts, ends = t_edges[:-1], t_edges[1:]
        t_centers = (starts + ends) / 2.0

        src_pm = ax_prof_src.pcolormesh(t_edges,
                                        self.alt_bins,
                                        scaled_sources,
                                        cmap=cmap,
                                        vmin=min_L_bin,
                                        vmax=max_L_bin)
        src_pm.set_rasterized(True)
        cbar_src = fig.colorbar(src_pm,
                                ax=ax_prof_src,
                                orientation='horizontal')
        cbar_src.set_label(
            'Source count per height interval per time\n(scaled to max length, km/km/min)'
        )

        L_pm = ax_prof_L.pcolormesh(t_edges,
                                    self.alt_bins,
                                    L_profile_rate,
                                    cmap=cmap,
                                    vmin=min_L_bin,
                                    vmax=max_L_bin)
        L_pm.set_rasterized(True)
        cbar_L = fig.colorbar(L_pm, ax=ax_prof_L, orientation='horizontal')
        cbar_L.set_label('Length per height interval per time\n(km/km/min)')

        for ax in (ax_prof_src, ax_prof_L):
            ax.set_ylabel('Altitude (km)')

        ax_L.plot(t_centers, lengths_2D, label='2D Hull Area')
        ax_L.plot(t_centers, lengths_3D, label='3D Hull Volume')
        ax_L.legend()
        ax_L.set_ylabel('Fractal Length (km/min)')

        for ax in (ax_L, ax_prof_L, ax_prof_src):
            ax.xaxis.set_major_formatter(SecDayFormatter(basedate, ax.xaxis))
            ax.set_xlabel('Time (UTC)')
            ax.xaxis.set_major_locator(MultipleLocator(label_t_every))
        return fig