Beispiel #1
0
 def key_0(self):
     fig = plt.figure()
     ax = plt.subplot(111)
     self.current_ionogram.plot(ax=ax, overplot_digitization=False, vmin=self.vmin, vmax=self.vmax, overplot_model=False)
     fname = 'Ionogram-O%d_%s.png' % (mex.orbits[float(self.current_ionogram.time)].number,
         celsius.spiceet_to_utcstr(self.current_ionogram.time, fmt='C'))
     plt.title(celsius.spiceet_to_utcstr(self.current_ionogram.time,
             fmt='C'))
     plt.savefig(fname.replace(':',''))
     plt.close(fig)
Beispiel #2
0
    def update(self):
        """ This redraws the various axes """
        plt.sca(self.ig_ax)
        plt.cla()

        if debug:
            print('DEBUG: Plotting ionogram...')

        alpha = 0.5
        self.current_ionogram.interpolate_frequencies() # does nothing if not required
        self.current_ionogram.plot(ax=self.ig_ax, colorbar=False,
            vmin=self.vmin, vmax=self.vmax,
            color='white', verbose=debug,
            overplot_digitization=True,alpha=alpha,errors=False,
            overplot_model=False, overplot_expected_ne_max=True)
        if debug:
            print('DEBUG: ... done')
        plt.colorbar(cax=self.cbar_ax, orientation='horizontal',
            ticks=mpl.ticker.MultipleLocator())
        plt.sca(self.cbar_ax)
        plt.xlabel(r'spec. dens. / $V^2m^{-2}Hz^{-1}$')
        plt.sca(self.ig_ax)

        # Plasma and cyclotron lines
        if len(self.selected_plasma_lines) > 0:
            extent = plt.ylim()
            for v in self.selected_plasma_lines:
                plt.vlines(v, extent[0], extent[1], 'red',alpha=alpha)

        if len(self.selected_cyclotron_lines) > 0:
            extent = plt.xlim()
            for v in self.selected_cyclotron_lines:
                plt.hlines(v, extent[0], extent[1], 'red',alpha=alpha)

        f = self.current_ionogram.digitization.morphology_fp_local
        if np.isfinite(f):
            plt.vlines(
                np.arange(1., 5.) * f / 1E6, plt.ylim()[0],
                plt.ylim()[1],
                color='red', lw=1.,alpha=alpha)

        # If current digitization is invertible, do it and plot it
        if self.current_ionogram.digitization:
            if debug:
                print('DEBUG: Inverting, computing model...')

            d = self.current_ionogram.digitization
            plt.sca(self.ne_ax)
            plt.cla()
            if d.is_invertible():
                winning = d.invert()
                if winning & np.all(d.density > 0.) & np.all(d.altitude > 0.):
                    plt.plot(d.density, d.altitude, color='k')
            plt.xlim(5.E1, 5E5)
            plt.ylim(0,499)
            alt = np.arange(0., 499., 5.)
            if self.current_ionogram.sza < 89.9:
                plt.plot(self.ionospheric_model(alt,
                        np.deg2rad(self.current_ionogram.sza)), alt, color='green')
            plt.grid()
            plt.xscale('log')
            plt.xlabel(r'$n_e / cm^{-3}$')
            plt.ylabel('alt. / km')
            fname = self.digitization_db.filename
            if len(fname) > 30: fname = fname[:10] + '...' + fname[-20:]
            plt.title('Database: ' + fname)

        if debug:
            print('DEBUG: Plotting timeseries....')

        # Timeseries integrated bar
        plt.sca(self.tser_ax)
        plt.cla()
        plt.imshow(self.tser_arr[::-1,:], vmin=self.vmin, vmax=self.vmax,
            interpolation='Nearest', extent=self.extent, origin='upper',aspect='auto')
        plt.xlim(self.extent[0], self.extent[1])
        plt.ylim(self.extent[2], self.extent[3])
        plt.ylim(0., 5.5)
        plt.vlines(self.current_ionogram.time,
            self.extent[2], self.extent[3], self.stored_color)
        plt.hlines(self.timeseries_frequency, self.extent[0],  self.extent[1],
            self.stored_color, 'dashed')
        plt.ylabel('f / MHz')

        # Frequency bar
        plt.sca(self.freq_ax)
        plt.cla()
        freq_extent = (self.extent[0], self.extent[1],
            ais.ais_max_delay*1E3, ais.ais_min_delay*1E3)
        inx = 1.0E6 * (self.current_ionogram.frequencies.shape[0] *
            self.timeseries_frequency) /\
            (self.current_ionogram.frequencies[-1] - self.current_ionogram.frequencies[0])

        self._freq_bar_data = self.tser_arr_all[:,int(inx),:]
        plt.imshow(self.tser_arr_all[:,int(inx),:], vmin=self.vmin, vmax=self.vmax,
            interpolation='Nearest', extent=freq_extent, origin='upper',aspect='auto')
        plt.xlim(freq_extent[0], freq_extent[1])
        plt.ylim(freq_extent[2], freq_extent[3])
        plt.vlines(self.current_ionogram.time,
            freq_extent[2],freq_extent[3], self.stored_color)
        plt.ylabel(r'$\tau_D / ms$')

        title = "AISTool v%s, Orbit = %d, Ionogram=%s " % (__version__,
            self.orbit, celsius.spiceet_to_utcstr(self.current_ionogram.time,
            fmt='C'))

        if self.browsing:
            title += '[Browsing] '
        if self.minimum_interaction_mode:
            title += '[Quick] '
        if self._digitization_saved == False:
            title += 'UNSAVED '
        if self.get_status() is not None:
            title += '[Status = %s] ' % self.get_status()

        pos, sza = mex.mso_r_lat_lon_position(float(self.current_ionogram.time),
            sza=True)

        title += '\nMSO: Altitude = %.1f km, Elevation = %.1f, Azimuth = %.1f deg, SZA = %.1f' % (pos[0] - mex.mars_mean_radius_km, mex.modpos(pos[1]), mex.modpos(pos[2]), sza)

        pos = mex.iau_pgr_alt_lat_lon_position(float(self.current_ionogram.time))
        title += '\nIAU: Altitude = %.1f km, Latitude = %.1f, Longitude = %.1f deg' % (
            pos[0], pos[1], mex.modpos(pos[2]))

        plt.sca(self.tser_ax)
        plt.title(title)

        # Message history:
        if len(self._messages):
            txt = ''
            for i, s in enumerate(self._messages):
                txt += str(i + self._message_counter) + ': ' + s + '\n'
            plt.annotate(txt, (0.05, 0.995), xycoords='figure fraction',
                fontsize=8, horizontalalignment='left', verticalalignment='top')

        # Axis formatters need redoing after each cla()
        nf = mpl.ticker.NullFormatter

        loc_f = celsius.SpiceetLocator()
        loc_t = celsius.SpiceetLocator()
        self.freq_ax.xaxis.set_major_formatter(celsius.SpiceetFormatter(loc_f))
        self.tser_ax.xaxis.set_major_formatter(nf())

        self.freq_ax.xaxis.set_major_locator(loc_f)
        self.tser_ax.xaxis.set_major_locator(loc_t)
        if debug:
            print('DEBUG: drawing...')

        self.figure.canvas.draw()
        return self
Beispiel #3
0
    def main(self, fname=None, show=False,
                figurename=None, save=False, along_orbit=False, set_cmap=True):

        # if len(a.digitization_list) < 100:
        #     return
        if set_cmap:
            plt.hot()
        fig = plt.figure(figsize=(8.27, 11.69), dpi=70)

        n = 8 + 4 + 1 + 1 + 1
        hr = np.ones(n)
        hr[-4:] = 0.5
        g = mpl.gridspec.GridSpec(n,1, hspace=0.1, height_ratios=hr,
                        bottom=0.06, right=0.89)

        axes = []
        prev = None
        for i in range(n):
            axes.append(plt.subplot(g[i], sharex=prev))
            axes[i].set_xlim(self.extent[0], self.extent[1])
            axes[i].yaxis.set_major_locator(
                            mpl.ticker.MaxNLocator(prune='upper', nbins=5,
                            steps=[1,2,5,10]))
            l = celsius.SpiceetLocator()
            axes[i].xaxis.set_major_locator(l)
            axes[i].xaxis.set_major_formatter(
                        celsius.SpiceetFormatter(locator=l))

            prev = axes[-1]

        axit = iter(axes)

        self.plot_aspera_ima(ax=next(axit), inverted=False)
        self.plot_aspera_els(ax=next(axit))
        self.plot_mod_b(ax=next(axit))
        self.plot_ne(ax=next(axit))
        self.plot_timeseries(ax=next(axit))

        self.plot_frequency_range(ax=next(axit), f_min=0.0, f_max=0.2,
                                    colorbar=True)
        # self.plot_frequency_range(ax=axit.next(), f_min=0.2, f_max=0.5)
        self.plot_frequency(ax=next(axit), f=0.5)
        # self.plot_frequency(ax=axit.next(), f=0.75)
        self.plot_frequency(ax=next(axit), f=1.)
        # self.plot_frequency(ax=axit.next(), f=1.52)
        self.plot_frequency(ax=next(axit), f=2.)

        self.plot_tec(ax=next(axit))
        # twx = plt.twinx()
        # t = mex.sub_surface.read_tec(self.start_time, self.finish_time)
        # good = t['FLAG'] == 1
        # plt.plot(t['EPHEMERIS_TIME'][good], t['TEC'][good], 'k.', mew=0.)
        # plt.ylabel(r'$TEC / m^{-2}$')
        # plt.yscale('log')
        # plt.ylim(3E13, 2E16)

        # self.plot_profiles(ax=axit.next())
        # self.plot_profiles_delta(ax=axit.next())
        # self.plot_peak_altitude(ax=axit.next())
        # self.plot_peak_density(ax=axit.next())

        self.plot_profiles(ax=next(axit))
        # self.plot_tec(ax=axit.next())

        self.plot_altitude(ax=next(axit))
        self.plot_lat(ax=next(axit))
        self.plot_lon(ax=next(axit))
        self.plot_sza(ax=next(axit))

        # axes[-1].xaxis.set_major_formatter(celsius.SpiceetFormatter())

        for i in range(n-1):
            plt.setp( axes[i].get_xticklabels(), visible=False )
            axes[i].set_xlim(self.extent[0], self.extent[1])
            l = celsius.SpiceetLocator()
            axes[i].xaxis.set_major_locator(l)
            axes[i].xaxis.set_major_formatter(
                    celsius.SpiceetFormatter(locator=l))

        plt.annotate("Orbit %d, plot start: %s, newest digitization: %s" % (
                self.orbit,
                celsius.spiceet_to_utcstr(self.extent[0],fmt='C')[0:17], self._newest),
            (0.5, 0.93), xycoords='figure fraction', ha='center')

        if save:
            if figurename is None:
                fname = mex.locate_data_directory() + ('ais_plots/v0.9/%05d/%d.pdf' % ((self.orbit // 1000) * 1000, self.orbit))
            else:
                fname = figurename
            print('Writing %s' % fname)
            d = os.path.dirname(fname)
            if not os.path.exists(d) and d:
                os.makedirs(d)
            plt.savefig(fname)



        if show:
            plt.show()
        else:
            plt.close(fig)
            plt.close('all')

        if along_orbit:
            # fig = plt.figure()
            fig, ax = plt.subplots(2, 1, squeeze=True, figsize=(4,4), dpi=70, num=plt.gcf().number + 1)
            plt.subplots_adjust(hspace=0.3,wspace=0.0, right=0.85)

            self.density_along_orbit(ax[0], vmax=4.)
            self.modb_along_orbit(ax[1], vmax=100.)

            if save:
                fname = mex.locate_data_directory() + ('ais_plots/A0_v0.9/%05d/%d.pdf' % ((self.orbit // 1000) * 1000, self.orbit))
                print('Writing %s' % fname)
                d = os.path.dirname(fname)
                if not os.path.exists(d):
                    os.makedirs(d)
                plt.savefig(fname)

            if show:
                plt.show()
            else:
                plt.close(fig)
                plt.close('all')
Beispiel #4
0
def stacked_f_plots(start=7894, finish=None, show=True,
            frequencies=[0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 2.0, 3.0]):
    gc.enable()
    if finish is None:
        finish = start + 1
    plt.close("all")
    fig = plt.figure(figsize = celsius.paper_sizes['A4'])
    orbits = list(range(start, finish))

    if len(orbits) > 1:
        show = False

    # plt.hot()

    for o in orbits:
        plt.clf()
        gc.collect()
        fname = mex.locate_data_directory() + 'marsis/ais_digitizations/%05d/%05d.dig' % ((o // 1000) * 1000, o)
        try:
            a = AISReview(o, debug=True, db_filename=fname)
        except Exception as e:
            print(e)
            continue


        n = len(frequencies) + 4
        hr = np.ones(n)
        hr[0] = 2.
        g = mpl.gridspec.GridSpec(n,1, hspace=0.1, height_ratios=hr)

        axes = []
        prev = None
        for i in range(n):
            axes.append(plt.subplot(g[i], sharex=prev))
            axes[i].set_xlim(a.extent[0], a.extent[1])
            axes[i].yaxis.set_major_locator(mpl.ticker.MaxNLocator(prune='upper', nbins=5, steps=[1,2,5,10]))
            axes[i].xaxis.set_major_locator(celsius.SpiceetLocator())
            axes[i].xaxis.set_major_formatter(celsius.SpiceetFormatter())
            prev = axes[-1]

        ax = iter(axes)

        a.plot_timeseries(ax=next(ax))
        a.plot_frequency_range(ax=next(ax), f_min=0.0, f_max=0.2)

        for i, f in enumerate(frequencies):
            a.plot_frequency_altitude(ax=next(ax), f=f)

        plt.sca(next(ax))
        b = a.quick_field_model(a.t)
        plt.plot(a.t, np.sqrt(np.sum(b**2., 0)), 'k-')
        plt.plot(a.t, b[0], 'r-')
        plt.plot(a.t, b[1], 'g-')
        plt.plot(a.t, b[2], 'b-')
        celsius.ylabel(r'$B_{SC} / nT$')

        plt.sca(next(ax))
        ion_pos = a.iau_pos
        ion_pos[0,:] = 150.0 + mex.mars_mean_radius_km
        bion = a.field_model(ion_pos)
        plt.plot(a.t, np.sqrt(np.sum(bion**2., 0)), 'k-')
        plt.plot(a.t, bion[0], 'r-')
        plt.plot(a.t, bion[1], 'g-')
        plt.plot(a.t, bion[2], 'b-')
        celsius.ylabel(r'$B_{150} / nT$')

        for i in range(n-1):
            ax = axes[i]
            plt.setp( ax.get_xticklabels(), visible=False )
            ax.xaxis.set_major_formatter(celsius.SpiceetFormatter())

        plt.annotate("Orbit %d, plot start: %s" % (o, celsius.spiceet_to_utcstr(a.extent[0])[0:14]),
            (0.5, 0.93), xycoords='figure fraction', ha='center')

        if show:
            plt.show()

        gc.collect()