Beispiel #1
0
def ima_coverage(recompute=False):
    """Returns a dictionary, key=orbit number, value = size in MB for the IMA data from that orbit"""

    results = {}
    try:
        with open(mex.data_directory + "nilsson_ima_coverage.pck", "r") as f:
            results = pickle.load(f)
    except Exception as e:
        recompute = True
        print(e)

    if recompute:
        now = celsius.now()
        directory = mex.data_directory + "aspera/nilsson/Mars_mat_files4/"
        results = {}
        for o in mex.orbits:
            t = mex.orbits[o].start
            if t > celsius.now():
                break
            t1 = mex.orbits[o].finish
            size = 0
            while t < t1:
                dt = celsius.spiceet_to_datetime(t)
                fname = directory + "fion" + "%4d%02d%02d%02d00.mat" % (dt.year, dt.month, dt.day, dt.hour)

                if os.path.exists(fname):
                    size += os.path.getsize(fname)
                t += 3600.0
            results[o] = size / (1024 * 1024)  # MB
        with open(mex.data_directory + "nilsson_ima_coverage.pck", "w") as f:
            pickle.dump(results, f)
    return results
Beispiel #2
0
def queue_writer():
    global queue
    # pass
    fh = open(os.getenv("SC_DATA_DIR") + "mex/ais_workflow_output.txt", "w")
    while True:
        g = queue.get()
        fh.write(str(celsius.utcstr(celsius.now())) + ": " + str(g) + "\n")
        fh.flush()
        queue.task_done()
    fh.close()
Beispiel #3
0
def load_kernels(time=None, force=False, verbose=False,
                load_all=False, keep_previous=False):
    """Load spice kernels, with a stateful thing to prevent multiple calls"""
    last_spice_time_window = getattr(spiceypy,
            'last_spice_time_window', 'MVN:NONE')

    if load_all:
        # Launch to now + 10 yrs
        start = celsius.spiceet("2013-11-19T00:00")
        finish = celsius.spiceet(celsius.now() + 10.*86400.*365.)

    if time is None:
        start = None
        finish = None
        start_str = 'NO_TIME_SET'
        finish_str = ''
        start_int=-999999
        finish_int=-999999
    else:
        if hasattr(time, '__len__'):
            start = time[0]
            finish = time[-1]

        else:
            start = time
            finish = time
        start_str = celsius.utcstr(start, 'ISOC')
        finish_str = celsius.utcstr(finish, 'ISOC')
        start_int = int(start_str[2:4] + start_str[5:7] + '01')
        finish_int = int(finish_str[2:4] + finish_str[5:7] + '01')
        start_str = '%06d' % start_int
        finish_str = '%06d' % finish_int

    this_spice_time_window = start_str + finish_str

    if not 'NONE' in last_spice_time_window:
        if last_spice_time_window == this_spice_time_window:
            if verbose:
                print('LOAD_KERNELS [MVN]: Interval unchanged')
            return

        if keep_previous:
            if verbose:
                print('LOAD_KERNELS [MVN]: Keeping loaded kernels')
            return

    spiceypy.last_spice_time_window = 'MVN:' + this_spice_time_window

    spiceypy.kclear()

    try:
        kernel_directory = os.getenv('MAVEN_KERNEL_DIR')
        if verbose:
            print('LOAD_KERNELS [MVN]: Registering kernels:')

        for k in REQUIRED_KERNELS:

            if '*' in k:
                files = glob(kernel_directory + k)
                m = -1
                file_to_load = ''
                for f in files:
                    t = os.path.getmtime(f)
                    if t > m:
                        m = t
                        file_to_load = f
                if verbose:
                    print(file_to_load)
                if file_to_load:
                    spiceypy.furnsh(file_to_load)
                else:
                    raise IOError("No match for %s" % k)

            else:
                spiceypy.furnsh(kernel_directory + k)
                if verbose: print(kernel_directory + k)

        # time sensitive kernels
        load_count = 0

        # used to determine whether or not to load the most recent, unnumbered
        # rolling update kernel
        max_encountered = -99999

        if start_int > -999999:
            # Load time-sensitive kenrels
            for f in iglob(kernel_directory + 'spk/maven_orb_rec_*.bsp'):
                this_start = int(f.split('_')[3])
                this_finish = int(f.split('_')[4])
                if this_finish < start_int: continue
                if this_start > finish_int: continue
                spiceypy.furnsh(f)
                load_count += 1
                if verbose: print(f)

                if this_start > max_encountered: max_encountered = this_start
                if this_finish > max_encountered: max_encountered = this_finish

            if max_encountered < finish_int:
                # load the rolling-update kernel too
                f = kernel_directory + 'spk/maven_orb_rec.bsp'
                # spiceypy.furnsh(f)
                load_count += 1
                if verbose: print(f)

            if load_count == 0:
                raise IOError("No kernels matched for time period")

    except Exception as e:
        spiceypy.kclear()
        spiceypy.last_spice_time_window = 'MVN:NONE_ERROR'
        raise

    print('LOAD_KERNELS [MVN]: Loaded %s' % spiceypy.last_spice_time_window)
Beispiel #4
0
def cleanup(start=None, finish=None):
    if not start: start = celsius.spiceet("2014-09-22T00:00")
    if not finish: finish = celsius.now()

    # Cleanup commands
    load_ngims_l2_summary(start, finish, cleanup=True, verbose=True)
Beispiel #5
0
 def __call__(self, s):
     n = celsius.now()
     print(s + ": %0.3fs" % (n - self._t))
     self._t = n
Beispiel #6
0
 def __init__(self):
     super(DeltaTimer, self).__init__()
     self._t = celsius.now()
Beispiel #7
0
    def __init__(self):
        super(DeltaTimer, self).__init__()
        self._t = celsius.now()

    def __call__(self, s):
        n = celsius.now()
        print(s + ": %0.3fs" % (n - self._t))
        self._t = n


if __name__ == "__main__":

    verbose = False
    save_every = 1
    np.seterr(all="ignore")
    t0 = celsius.now()
    exception_list = {}
    repeat = True

    start = determine_last_processed_orbit() - 50
    # start = 1840
    # start = 14935
    finish = mex.orbits[celsius.now()].number - 10

    if len(sys.argv) > 1:
        start = int(sys.argv[1])
    if len(sys.argv) > 2:
        finish = int(sys.argv[2])

    orbits = list(range(start, finish))