Exemplo n.º 1
0
 def generate_position(self):
     if not hasattr(self, 't'):
         print("Generating position information...")
         self.t = np.arange(float(self.extent[0]), float(self.extent[1]), ais_code.ais_spacing_seconds)
         if self.debug: print("%d points..." % self.t.size)
         self.pos, self.mso_pos, self.sza = mex.mso_r_lat_lon_position(self.t, sza=True, mso=True)
         if self.debug: print("...stage 2")
         self.iau_pos = mex.iau_r_lat_lon_position(self.t)
         self.mso_rho = np.sqrt(self.mso_pos[1,:]**2. + self.mso_pos[2,:]**2.)
         if self.debug: print('...done.')
Exemplo n.º 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