예제 #1
0
def targets2truthfiles(targets, basedir, nside=64):
    '''
    Return list of mock truth files that contain these targets

    Args:
        targets: table with TARGETID column, e.g. from fiber assignment
        basedir: base directory under which files are found

    Returns (truthfiles, targetids):
        truthfiles: list of truth filenames
        targetids: list of lists of targetids in each truthfile

    i.e. targetids[i] is the list of targetids from targets['TARGETID'] that
        are in truthfiles[i]
    '''
    import healpy
    import desitarget.mock.io as mockio
    assert nside >= 2

    #- TODO: what should be done with assignments without targets?
    targets = targets[targets['TARGETID'] != -1]

    theta = np.radians(90 - targets['DEC'])
    phi = np.radians(targets['RA'])
    pixels = healpy.ang2pix(nside, theta, phi, nest=True)

    truthfiles = list()
    targetids = list()
    for ipix in sorted(np.unique(pixels)):
        filename = mockio.findfile('truth', nside, ipix, basedir=basedir)
        truthfiles.append(filename)
        ii = (pixels == ipix)
        targetids.append(np.asarray(targets['TARGETID'][ii]))

    return truthfiles, targetids
예제 #2
0
        toflux = np.exp(-tau)
        # only add absorption in the forest
        no_forest = (z > z_qso[i])
        toflux[no_forest] = 1.0
        flux[:, i] = toflux

    wave_hdu = fits.ImageHDU(data=wave, name='WAVELENGTH')
    flux_hdu = fits.ImageHDU(data=flux, name='TRANSMISSION')
    hdulist = fits.HDUList([prim_hdu, meta_hdu, wave_hdu, flux_hdu])

    # open file to write
    #filename='test_'+str(pix)+'.fits'
    dirname = mockio.get_healpix_dir(nside, pix, basedir=transmission_base_dir)
    #print('dirname',dirname)
    os.makedirs(dirname, exist_ok=True)
    filename = mockio.findfile('transmission', nside, pix,
                               transmission_base_dir)
    #print('filename',filename)
    #fits = fitsio.FITS(filename,'rw',clobber=True)
    hdulist.writeto(filename)

master_file = transmission_base_dir + "/master.fits"
print('master file', master_file)

#Add a couple of headers to the file.
header = fits.Header()
header['NSIDE'] = nside
header['NQSO'] = Nq

#Construct a table for the meta-data hdu
col_ra = fits.Column(name='RA', array=catalog['RA'], format='E')
col_dec = fits.Column(name='DEC', array=catalog['DEC'], format='E')