Пример #1
0
def primary_hdu(test_name, test_date, commit_hash):
    '''
http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/rates/ogip_93_003/ogip_93_003.html
http://heasarc.nasa.gov/docs/heasarc/ofwg/ofwg_recomm.html

alternate time stamps:
DATE-OBS= '09/07/93'         / date of observation start (dd/mm/yy)
TIME-OBS= '01:02:26.003'     / time of observation start (hh:mm:ss.ddddd)
DATE-END= '09/07/93'         / date of observation end (dd/mm/yy)
TIME-END= '02:45:02.45'      / time of observation end (hh:mm:ss.ddddd)
    '''

    from pyfits import Card, Header, PrimaryHDU
    cards = [
        Card('SchemaV',0,'Schema Version'),
        Card('TestName',test_name,
             'Name of the test station.'),
        Card('DATE-OBS',test_date.strftime("%Y-%m-%dT%H:%M:%S"),
             'Date test was performed.'),
        Card('Commit',  commit.hexdigest(),   
             'Commit hash.'),
        ]

    header = Header(cards = cards)
    ret = PrimaryHDU(header=header)
    ret.add_checksum()
    return ret
Пример #2
0
def tofits(filename, data, hdr=None, clobber=False):
    """simple pyfits wrapper to make saving fits files easier."""
    from pyfits import PrimaryHDU, HDUList
    hdu = PrimaryHDU(data)
    if not hdr is None: hdu.header = hdr
    hdulist = HDUList([hdu])
    hdulist.writeto(filename, clobber=clobber, output_verify='ignore')
Пример #3
0
def tofits(filename, data, hdr=None,clobber=False):
    """simple pyfits wrapper to make saving fits files easier."""
    from pyfits import PrimaryHDU,HDUList
    hdu = PrimaryHDU(data)
    if not hdr is None: hdu.header = hdr
    hdulist = HDUList([hdu])
    hdulist.writeto(filename, clobber=clobber,output_verify='ignore')
Пример #4
0
def doim(outname, px, py, pz, data):
    f = np.zeros([2 * zw + 1, 2 * yw / binsize + 1, 2 * xw / binsize + 1])
    _x = ((px + xw) / binsize + .5).astype(int)
    _y = ((py + yw) / binsize + .5).astype(int)
    _z = (pz + zwn + .5).astype(int)
    for x, y, z, d in zip(_x, _y, _z, data):
        f[z, y, x] += d
    hdu = PrimaryHDU()
    hdu.data = f
    hdu.writeto(outname, clobber=True)
    hdu.data = np.nansum(f[zw - zw0:zw + zw0 + 1, :, :], 0)
    hdu.writeto(outname.replace('.fits', '.IM.fits'), clobber=True)
Пример #5
0
def cube_to_image(cube, slicepos=None, mean=False):
    """ Make an image out of a cube.
    Both in- and output shoud by pyfits.HDUs"""
    from pyfits import PrimaryHDU
    header = cube.header.copy()
    header['NAXIS'] = 2
    del header['NAXIS3']
    del header['CRVAL3']
    del header['CDELT3']
    if slicepos:
        data = cube.data[slicepos]
    else:
        if mean:
            data = cube.data.mean(0).astype(cube.data.dtype)
        else:
            data = cube.data.sum(0).astype(cube.data.dtype)

    return PrimaryHDU(data, header)