ace2moonΒΆ

A script to convert the ACE data to Moon position.

This script is a simple way of retrieving the ACE data to Moon position. First, data is read from ACE L2 Merged data. Second, the observation time at ACE is converted to the Moon position using the ACE position and Moon position in the GSE coordinate system. Third, the data is dumped based on the Moon time.

''' A script to convert the ACE data to Moon position.

This script is a simple way of retrieving the ACE data to Moon position.
First, data is read from ACE L2 Merged data.
Second, the observation time at ACE is converted to the Moon position
using the ACE position and Moon position in the GSE coordinate system.
Third, the data is dumped based on the Moon time.
'''

import os,sys
import datetime
import logging
from irfpy.swim.ace import *
from irfpy.util.utc import *
from irfpy.util.julday import *

import pickle as pickle
import gzip

if __name__=='__main__':

    print('###ACE_at_Moon')
    print('#Data_version: 1.0')
    print('#Exec_time_utc: %s'%datetime.datetime.utcnow())
    print('#Exec_path: %s'%os.getcwd())
    print('#Exec: %s'%sys.argv[0])

    logging.basicConfig(level=logging.INFO)
    
    # First, prepare the ACE data.
    ace_archive = Ace()

    t0 = datetime.datetime(2009,1,1,0,0,0)
    dt = datetime.timedelta(1)

    cache=gzip.GzipFile('ace2moon.pic.gz', 'wb')

    for doi in range(213):
        tst = t0 + doi*dt
        ten = tst + dt
        logging.info('*** Calculation time from %s to %s'%(tst,ten))

        logging.info(tst)
        ace_data_array = ace_archive.getList(tst, ten)
        logging.info('* Data retrieved (N=%d)'%ace_data_array.size())

        for ace_data in ace_data_array:
            try:
                ace_elem=ace_data.getData()
                ace_at_moon=AceElemAtMoon(ace_elem)
                logging.info('Time converted: %s -> %s'%( ace_elem.getJulday(), ace_at_moon.getJulday()))
                t_ace=convert(ace_elem.getJulday(), datetime.datetime)
                t_moon=convert(ace_at_moon.getJulday(), datetime.datetime)
                print('%s %s '%(t_ace.strftime('%FT%T'), t_moon.strftime('%FT%T')), end=' ')
                dt_ace=t_ace - datetime.datetime(2009,1,1,0,0,0)
                dt_moon=t_moon - datetime.datetime(2009,1,1,0,0,0)
                doi_ace = dt_ace.days + dt_ace.seconds/86400. + dt_ace.microseconds/86400e6 + 1
                doi_moon = dt_moon.days + dt_moon.seconds/86400. + dt_moon.microseconds/86400e6 + 1
                print('%10.5f %10.5f'%(doi_ace, doi_moon), end=' ')
                print('%7.3f '%(ace_elem.getNp(),), end=' ')
                print('%12.3f '%(ace_elem.getTp(),), end=' ')
                print('%9.3f '%(ace_elem.getAlpha_ratio(),), end=' ')
                print('%9.3f '%(ace_elem.getVp(),), end=' ')
                print('%9.3f '%(ace_elem.getV_gse_x(),), end=' ')
                print('%9.3f '%(ace_elem.getV_gse_y(),), end=' ')
                print('%9.3f '%(ace_elem.getV_gse_z(),), end=' ')
                print('%8.3f '%(ace_elem.getB_gse_x(),), end=' ')
                print('%8.3f '%(ace_elem.getB_gse_y(),), end=' ')
                print('%8.3f '%(ace_elem.getB_gse_z(),), end=' ')
                print('%8.3f '%(ace_elem.getBmag(),), end=' ')
                print('%11.4e '%(ace_elem.getpos_gse_x(),), end=' ')
                print('%11.4e '%(ace_elem.getpos_gse_y(),), end=' ')
                print('%11.4e '%(ace_elem.getpos_gse_z(),), end=' ')
                print()

                pickle.dump(ace_at_moon, cache)

            except ValueError as e:
                logging.warn(e)
                continue
        
        
    cache.close()