def process_level1(base_folder='/COFE', day='all', use_cc=True):
    """Full processing to produce Level1 data
    
    Parameters
    ----------
    base_folder : str
        path to data
    day : str
        day to be processed
    freq : int
        frequency
    """
    gyro = fits.read(os.path.join(base_folder, 'servo', '%s.fits' % day), 'GYRO_HID')
    offsets = find_clock_offsets_from_gpstime(gyro['COMPUTERCLOCK'], gyro['GPSTIME'])
    if use_cc:
        utcc, ut = create_ut_from_cc(gyro)
    else:
        ut = create_ut_from_gpstime(gyro['GPSTIME'])
        gyro['COMPUTERCLOCK'] = fix_gyro_cc(gyro, ut)
        utcc = gyro['COMPUTERCLOCK']
    servo_file = os.path.join(base_folder,'servo','%s.fits' % day)
    create_utservo(servo_file, offsets, utcc, ut)
    for freq in [10, 15]:
        revcounter = fits.read(os.path.join(base_folder, 'servo', '%s.fits' % day), REVCOUNTER_LABEL[freq])
        sci = create_utscience(os.path.join(base_folder,str(freq),'%s.fits'%day), gyro, revcounter, offsets, utcc, ut, freq)
        create_sync_servo(servo_file, offsets, utcc, ut, sci['TIME']['COMPUTERCLOCK'], freq)
Esempio n. 2
0
def process_level1(base_folder='/COFE', day='all', use_cc=True):
    """Full processing to produce Level1 data
    
    Parameters
    ----------
    base_folder : str
        path to data
    day : str
        day to be processed
    freq : int
        frequency
    """
    gyro = fits.read(os.path.join(base_folder, 'servo', '%s.fits' % day), 'GYRO_HID')
    offsets = find_clock_offsets_from_gpstime(gyro['COMPUTERCLOCK'], gyro['GPSTIME'])
    if use_cc:
        utcc, ut = create_ut_from_cc(gyro)
    else:
        ut = create_ut_from_gpstime(gyro['GPSTIME'])
        gyro['COMPUTERCLOCK'] = fix_gyro_cc(gyro, ut)
        utcc = gyro['COMPUTERCLOCK']
    servo_file = os.path.join(base_folder,'servo','%s.fits' % day)
    create_utservo(servo_file, offsets, utcc, ut)
    for freq in [10, 15]:
        revcounter = fits.read(os.path.join(base_folder, 'servo', '%s.fits' % day), REVCOUNTER_LABEL[freq])
        sci = create_utscience(os.path.join(base_folder,str(freq),'%s.fits'%day), gyro, revcounter, offsets, utcc, ut, freq)
        create_sync_servo(servo_file, offsets, utcc, ut, sci['TIME']['COMPUTERCLOCK'], freq)
Esempio n. 3
0
def create_utservo(servo_file, offsets, utcc, ut):
    """Create file with servo data with fixed CC and UT

    Parameters
    ----------
    servo_file : str
        filename of servo data
    offsets : ndarray
        CC offsets computed from gpstime, see find_clock_offsets_from_gpstime
    utcc : ndarray
        CC array related to UT
    ut : ndarray
        UT array

    Returns
    -------
    writes utservo.fits file to disk
    """
    print("Create UT timestamped servo data")

    utservo = OrderedDict()
    for device in DEVICES:
        print('Processing ' + device)
        utservo[device] = fits.read(servo_file, device)
        utservo[device]['COMPUTERCLOCK'] = apply_cc_offsets(utservo[device]['COMPUTERCLOCK'], offsets)
        utservo[device]['UT'] = np.interp( utservo[device]['COMPUTERCLOCK'], utcc, ut)

    filename = 'utservo.fits'
    print('Writing ' + filename)
    fits.write(filename, utservo)
    return utservo
def create_utservo(servo_file, offsets, utcc, ut):
    """Create file with servo data with fixed CC and UT

    Parameters
    ----------
    servo_file : str
        filename of servo data
    offsets : ndarray
        CC offsets computed from gpstime, see find_clock_offsets_from_gpstime
    utcc : ndarray
        CC array related to UT
    ut : ndarray
        UT array

    Returns
    -------
    writes utservo.fits file to disk
    """
    print("Create UT timestamped servo data")

    utservo = OrderedDict()
    for device in DEVICES:
        print('Processing ' + device)
        utservo[device] = fits.read(servo_file, device)
        utservo[device]['COMPUTERCLOCK'] = apply_cc_offsets(utservo[device]['COMPUTERCLOCK'], offsets)
        utservo[device]['UT'] = np.interp( utservo[device]['COMPUTERCLOCK'], utcc, ut)

    filename = 'utservo.fits'
    print('Writing ' + filename)
    fits.write(filename, utservo)
    return utservo
Esempio n. 5
0
def create_utscience(sci_file, gyro, revcounter, offsets, utcc, ut, freq):
    """Create file with science data with fixed CC and UT
    see create_utservo
    """

    data = fits.read(sci_file)

    splitted_data = OrderedDict()
    splitted_data['TIME'] = OrderedDict()
    for ch_n in range(16):
        ch_name = 'CH%d_' % ch_n
        splitted_data[ch_name] = OrderedDict()
        for comp in 'TQU':
            splitted_data[ch_name][comp] = data[ch_name + comp]
    splitted_data['TIME']['COMPUTERCLOCK'], splitted_data['TIME']['NOREVCOUNTFLAG']= create_science_computerclock(gyro, revcounter, data['REV'], offsets)
    splitted_data['TIME']['UT'] = np.interp(splitted_data['TIME']['COMPUTERCLOCK'], utcc, ut)

    filename = '%s_%dGHz_data.fits' % (os.path.basename(sci_file).split('.')[0], freq)
    print('Writing ' + filename)
    fits.write(filename, splitted_data)

    return splitted_data
def create_utscience(sci_file, gyro, revcounter, offsets, utcc, ut, freq):
    """Create file with science data with fixed CC and UT
    see create_utservo
    """

    data = fits.read(sci_file)

    splitted_data = OrderedDict()
    splitted_data['TIME'] = OrderedDict()
    for ch_n in range(16):
        ch_name = 'CH%d_' % ch_n
        splitted_data[ch_name] = OrderedDict()
        for comp in 'TQU':
            splitted_data[ch_name][comp] = data[ch_name + comp]
    splitted_data['TIME']['COMPUTERCLOCK'], splitted_data['TIME']['NOREVCOUNTFLAG']= create_science_computerclock(gyro, revcounter, data['REV'], offsets)
    splitted_data['TIME']['UT'] = np.interp(splitted_data['TIME']['COMPUTERCLOCK'], utcc, ut)

    filename = '%s_%dGHz_data.fits' % (os.path.basename(sci_file).split('.')[0], freq)
    print('Writing ' + filename)
    fits.write(filename, splitted_data)

    return splitted_data
Esempio n. 7
0
def create_sync_servo(servo_file, offsets, utcc, ut, sci_cc, freq):
    """Create synchronized servo data

    Parameters
    ----------
    servo_file : srt
        filename of servo data
    offsets : ndarray
        CC offsets computed from gpstime, see find_clock_offsets_from_gpstime
    utcc : ndarray
        CC array related to UT
    ut : ndarray
        UT array
    sci_cc : ndarray
        CC array of scientific data
    freq : int
        frequency
    """

    print("Create synchronized servo data to %dGHz" % freq)
    filename = '%s_%dGHz_servo.fits' % (os.path.basename(servo_file).split('.')[0], freq)
    print('Writing ' + filename)
    f = fits.create(filename)
    ext = OrderedDict()
    ext['COMPUTERCLOCK'] = sci_cc
    ext['UT'] = np.interp(sci_cc, utcc, ut)
    f.write_HDU('TIME', ext)
    for device in DEVICES:
        print('Processing ' + device)
        raw_data = fits.read(servo_file, device)
        ext = OrderedDict()
        cc = apply_cc_offsets(raw_data['COMPUTERCLOCK'], offsets)
        for colname, colarray in raw_data.iteritems():
            if colname != 'COMPUTERCLOCK':
                print('Column ' + colname)
                ext[colname] = np.interp(sci_cc, cc, colarray)
        f.write_HDU(device, ext)
    f.close()
def create_sync_servo(servo_file, offsets, utcc, ut, sci_cc, freq):
    """Create synchronized servo data

    Parameters
    ----------
    servo_file : srt
        filename of servo data
    offsets : ndarray
        CC offsets computed from gpstime, see find_clock_offsets_from_gpstime
    utcc : ndarray
        CC array related to UT
    ut : ndarray
        UT array
    sci_cc : ndarray
        CC array of scientific data
    freq : int
        frequency
    """

    print("Create synchronized servo data to %dGHz" % freq)
    filename = '%s_%dGHz_servo.fits' % (os.path.basename(servo_file).split('.')[0], freq)
    print('Writing ' + filename)
    f = fits.create(filename)
    ext = OrderedDict()
    ext['COMPUTERCLOCK'] = sci_cc
    ext['UT'] = np.interp(sci_cc, utcc, ut)
    f.write_HDU('TIME', ext)
    for device in DEVICES:
        print('Processing ' + device)
        raw_data = fits.read(servo_file, device)
        ext = OrderedDict()
        cc = apply_cc_offsets(raw_data['COMPUTERCLOCK'], offsets)
        for colname, colarray in raw_data.iteritems():
            if colname != 'COMPUTERCLOCK':
                print('Column ' + colname)
                ext[colname] = np.interp(sci_cc, cc, colarray)
        f.write_HDU(device, ext)
    f.close()
Esempio n. 9
0
    freq = 10
    ch_num = 5
    mag = True
    filename = 'data/eq_pointing_%d.fits' % freq
    if mag:
        filename = filename.replace('.fits','_mag.fits')
    f=pyfits.open(filename)
    ch = 'CHANNEL_%d' % ch_num
    p=f[ch].data
    NSIDE = 128
    NPIX = hp.nside2npix(NSIDE)
    pix=hp.ang2pix(NSIDE,p['THETA'],p['PHI'])
    flagsfile = 'data/flags%dghz.fits' % freq
    datafile = 'data/all_%dGHz_data_cal.fits' % freq
    
    data_ut = fits.read(datafile, 'TIME')['UT']
    data_range = slice(data_ut.searchsorted(f['TIME'].data['UT'][0]), data_ut.searchsorted(f['TIME'].data['UT'][-1])+1)
    ch_num -= 1
    flag = fits.read(flagsfile, 'CH%d' % ch_num)['FLAGS'][data_range]
    data = fits.read(datafile, 'CH%d_' % ch_num)
    if True: #FLAG
        pix[flag > 0] = NPIX
    hits=hp.ma(pix2map(pix, NSIDE))
    hits.mask = hits==0
    #hp.mollzoom(hits.filled(),min=0,max=int(hits.mean()*2), title="Hitmap %dGHz %s NSIDE %d" % (freq,ch, NSIDE))
    print "open wmap map"
    m = fits.read_map('wmap/wmap_band_iqumap_r9_7yr_K_v4.fits', field=slice(0,2+1), nest=None)
    qu_wmap = [gal2eq(hp.ud_grade(amap, NSIDE, order_in='NESTED', order_out='RING')) for amap in m]
    qu_wmap = [np.append(amap, [0]) for amap in qu_wmap]

    q_channel_w, u_channel_w = get_qu_weights(p['PSI'])
Esempio n. 10
0
    freq = 10
    ch_num = 5
    mag = True
    filename = 'data/eq_pointing_%d.fits' % freq
    if mag:
        filename = filename.replace('.fits','_mag.fits')
    f=pyfits.open(filename)
    ch = 'CHANNEL_%d' % ch_num
    p=f[ch].data
    NSIDE = 128
    NPIX = hp.nside2npix(NSIDE)
    pix=hp.ang2pix(NSIDE,p['THETA'],p['PHI'])
    flagsfile = 'data/flags%dghz.fits' % freq
    datafile = 'data/all_%dGHz_data_cal.fits' % freq
    
    data_ut = fits.read(datafile, 'TIME')['UT']
    data_range = slice(data_ut.searchsorted(f['TIME'].data['UT'][0]), data_ut.searchsorted(f['TIME'].data['UT'][-1])+1)
    ch_num -= 1
    flag = fits.read(flagsfile, 'CH%d' % ch_num)['FLAGS'][data_range]
    data = fits.read(datafile, 'CH%d_' % ch_num)
    if True: #FLAG
        pix[flag > 0] = NPIX
    hits=hp.ma(pix2map(pix, NSIDE))
    hits.mask = hits==0
    #hp.mollzoom(hits.filled(),min=0,max=int(hits.mean()*2), title="Hitmap %dGHz %s NSIDE %d" % (freq,ch, NSIDE))
    print "open wmap map"
    m = fits.read_map('wmap/wmap_band_iqumap_r9_7yr_K_v4.fits', field=slice(0,2+1), nest=None)
    qu_wmap = [gal2eq(hp.ud_grade(amap, NSIDE, order_in='NESTED', order_out='RING')) for amap in m]
    qu_wmap = [np.append(amap, [0]) for amap in qu_wmap]

    q_channel_w, u_channel_w = get_qu_weights(p['PSI'])