Esempio n. 1
0
    def __call__(self, time, force=False):
        t = np.atleast_1d(time)
        t0 = mex.orbits[np.amin(t)].number
        t1 = mex.orbits[np.amax(t)].number + 1
        if t1 > (t0 + 2):
            if force and (((t1 - t0) / time.shape[0]) < 50):
                raise ValueError("%d orbits, but not many points requested?  force=True disables this check")

        chunks = []
        compute_count = 0
        for o in range(t0, t1):
            try:
                chunk = np.load(self.directory + '%05d/%05d.npy' % (o/1000 * 1000, o))
            except IOError as e:
                compute_count+= 1
                print('Computing for orbit %d' % o)
                o_t = np.arange(-40. * 60., 40. * 60., 5.) + mex.orbits[o].periapsis
                pos = mex.iau_r_lat_lon_position(o_t)
                field = self.field_model(pos)
                # for i in range(o_t.shape[0]):
                #     print o_t[i], field[i,:]
                chunk = np.vstack((o_t, field))
                all_dirs = self.directory + '%05d/' % (o/1000 * 1000)
                if not os.path.exists(all_dirs):
                    os.makedirs(all_dirs)
                np.save(all_dirs + '%05d.npy' % o, chunk)
            chunks.append(chunk)
        data = np.hstack(chunks)

        output = np.empty((3,t.shape[0]))
        for i in (0,1,2):
            output[i,:] = np.interp(t, data[0,:], data[i+1,:], left=np.nan, right=np.nan)

        return output
Esempio n. 2
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.')
Esempio n. 3
0
    def plot_frequency_altitude(self, f=2.0, ax=None, median_filter=False,
        vmin=None, vmax=None, altitude_range=(-99.9, 399.9), colorbar=False, return_image=False, annotate=True):

        if vmin is None:
            vmin = self.vmin

        if vmax is None:
            vmax = self.vmax

        if ax is None:
            ax = plt.gca()

        plt.sca(ax)
        plt.cla()
        freq_extent = (self.extent[0], self.extent[1],
            altitude_range[1], altitude_range[0])

        i = self.ionogram_list[0]
        inx = 1.0E6* (i.frequencies.shape[0] * f) / (i.frequencies[-1] - i.frequencies[0])
        img = self.tser_arr_all[:,int(inx),:]

        new_altitudes = np.arange(altitude_range[0], altitude_range[1], 14.)
        new_img = np.zeros((new_altitudes.shape[0], img.shape[1])) + np.nan

        for i in self.ionogram_list:
            e = int( round((i.time - self.extent[0]) / ais_code.ais_spacing_seconds ))

            pos = mex.iau_r_lat_lon_position(float(i.time))
            altitudes = pos[0] - ais_code.speed_of_light_kms * ais_code.ais_delays * 0.5 - mex.mars_mean_radius_km
            s = np.argsort(altitudes)
            new_img[:, e] = np.interp(new_altitudes, altitudes[s], img[s,e], left=np.nan, right=np.nan)

        plt.imshow(new_img, vmin=vmin, vmax=vmax,
            interpolation='Nearest', extent=freq_extent, origin='upper', aspect='auto')

        plt.xlim(freq_extent[0], freq_extent[1])
        plt.ylim(*altitude_range)

        ax.set_xlim(self.extent[0], self.extent[1])
        ax.xaxis.set_major_locator(celsius.SpiceetLocator())

        celsius.ylabel(r'Alt./km')
        if annotate:
            plt.annotate('f = %.1f MHz' % f, (0.02, 0.9),
                    xycoords='axes fraction', color='cyan', verticalalignment='top', fontsize='small')

        if colorbar:
            old_ax = plt.gca()
            plt.colorbar(cax = celsius.make_colorbar_cax(), ticks=self.cbar_ticks).set_label(r"$Log_{10} V^2 m^{-2} Hz^{-1}$")
            plt.sca(old_ax)

        if return_image:
            return new_img, freq_extent, new_altitudes
Esempio n. 4
0
        orb = mex.orbits[10470]
        et = np.linspace(orb.periapsis-3600., orb.periapsis+3600., 1000.)



        # Duru 06a
        if comparison == 'Duru':
            et = np.linspace(
                celsius.spiceet("2005-224T04:45:00"), celsius.spiceet("2005-224T05:15:00"), 100)

        # Fraenz 10a
        if comparison == 'Fraenz':
            orb = mex.orbits[5009]
            et = np.linspace(-7 * 60., 7 * 60., 100) + orb.periapsis

        pos = mex.iau_r_lat_lon_position(et)
        # pos[0,:] += mex.mars_mean_radius_km
        # pos = np.empty_like(p)
        # pos[2,:] = -np.rad2deg(p[1,:])
        # pos[1,:] = np.rad2deg(p[2,:])
        # pos[0,:] = p[0,:]

        if comparison == 'Duru':
            pos[0,:] = np.zeros_like(pos[0,:]) + mex.mars_mean_radius_km + 150.

        field = a(pos)
        print(field)

        plt.subplot(311)
        plt.plot(et, pos[0,:] - mex.mars_mean_radius_km)
        # plt.plot(et, p[0,:] - mex.mars_mean_radius_km)