Ejemplo n.º 1
0
def _as_fitsrec(val):
    """
    Convert a numpy record into a fits record if it is not one already
    """
    if isinstance(val, fits.FITS_rec):
        return val
    else:
        coldefs = fits.ColDefs(val)
        fits_rec = fits.FITS_rec(val)
        fits_rec._coldefs = coldefs
        return fits_rec
Ejemplo n.º 2
0
def empty_gal_struct(n):
    init_vals = config.INIT_VALS
    columns = config.COLUMNS
    ts = config.COL_TYPES

    dtype = (zip(columns, ts))
    #empty = np.recarray((n,), dtype=dtype)
    empty = pyfits.FITS_rec(n, names=columns, formats=ts)

    for i in range(len(empty)):
        for j in range(len(empty[i])):
            empty[i][j] = init_vals[j]

    return empty
Ejemplo n.º 3
0
def _as_fitsrec(val):
    """
    Convert a numpy record into a fits record if it is not one already
    """
    if isinstance(val, fits.FITS_rec):
        return val
    else:
        coldefs = fits.ColDefs(val)
        uint = any(c._pseudo_unsigned_ints for c in coldefs)
        fits_rec = fits.FITS_rec(val)
        fits_rec._coldefs = coldefs
        # FITS_rec needs to know if it should be operating in pseudo-unsigned-ints mode,
        # otherwise it won't properly convert integer columns with TZEROn before saving.
        fits_rec._uint = uint
        return fits_rec
Ejemplo n.º 4
0
    def write_horn_fits(self, tstamp):
        '''
        write the inductance curve to FITS file
        '''
        npts = len(self.dat)
        startTime = dt.datetime.fromtimestamp(tstamp)
        file_ctr = 0
        outfile = 'hornswitch_%i_%s.fits' % (
            file_ctr, startTime.strftime('%Y%m%dT%H%M%S'))
        while os.path.isfile(outfile):
            file_ctr += 1
            outfile = 'hornswitch_%i_%s.fits' % (
                file_ctr, startTime.strftime('%Y%m%dT%H%M%S'))

        records = np.recarray(formats='>i4', names='amplitude', shape=(npts))
        records.amplitude = self.dat

        # FITS primary header
        prihdr = fits.Header()
        prihdr['INSTRUME'] = 'QUBIC'
        prihdr['EXTNAME'] = 'HORNSWITCH'
        prihdr['DATE-OBS'] = startTime.strftime('%Y-%m-%d %H:%M:%S.%f UT')
        for key in self.header.keys():
            prihdr[key] = self.header[key]
        prihdu = fits.PrimaryHDU(header=prihdr)

        cols = fits.FITS_rec(records)

        hdu1 = fits.BinTableHDU.from_columns(cols)
        hdu1.header['INSTRUME'] = 'QUBIC'
        hdu1.header['EXTNAME'] = 'HORNSWITCH'
        hdu1.header['DATE-OBS'] = startTime.strftime('%Y-%m-%d %H:%M:%S.%f UT')
        for key in self.header.keys():
            hdu1.header[key] = self.header[key]

        hdulist = [prihdu, hdu1]
        thdulist = fits.HDUList(hdulist)
        thdulist.writeto(outfile, overwrite=True)
        thdulist.close()
        print('saved file: %s' % outfile)
        return outfile
Ejemplo n.º 5
0
def write_calsource_fits(t, v):
    '''
    write calsource data to FITS file
    '''
    if len(t) == 0:
        print('ERROR! No data.')
        return None

    npts = len(t)
    startTime = dt.datetime.utcfromtimestamp(t[0])
    outfile = startTime.strftime('calsource_%Y%m%dT%H%M%S.fits')
    if os.path.isfile(outfile):
        print('file exists!  will overwrite: %s' % outfile)

    records = np.recarray(formats='>f8,>i2',
                          names='timestamp,amplitude',
                          shape=(npts))
    records.timestamp = t
    records.amplitude = v

    # FITS primary header
    prihdr = fits.Header()
    prihdr['INSTRUME'] = 'QUBIC'
    prihdr['EXTNAME'] = 'CALSOURCE'
    prihdr['DATE-OBS'] = startTime.strftime('%Y-%m-%d %H:%M:%S UT')
    prihdu = fits.PrimaryHDU(header=prihdr)

    cols = fits.FITS_rec(records)

    hdu1 = fits.BinTableHDU.from_columns(cols)
    hdu1.header['INSTRUME'] = 'QUBIC'
    hdu1.header['EXTNAME'] = 'CALSOURCE'
    hdu1.header['DATE-OBS'] = startTime.strftime('%Y-%m-%d %H:%M:%S UT')

    hdulist = [prihdu, hdu1]
    thdulist = fits.HDUList(hdulist)
    thdulist.writeto(outfile, overwrite=True)
    thdulist.close()

    return outfile