Ejemplo n.º 1
0
def write_initial_truth_file(initial_truth_file):
    import desitarget.mock.mockmaker as mb
    from desitarget.targetmask import desi_mask, bgs_mask, mws_mask
    pixweight_file = "/project/projectdirs/desi/target/catalogs/dr8/0.31.1/pixweight/pixweight-dr8-0.31.1.fits"

    is_lya_qso = assign_lya_qso(initial_mtl_file, pixweight_file)
    
    targets = Table.read(initial_mtl_file)
    colnames = list(targets.dtype.names)
    print(colnames)
    nobj = len(targets)
    truth = mb.empty_truth_table(nobj=nobj)[0]
    print(truth.keys())

    for k in colnames:
        if k in truth.keys():
            print(k)
            truth[k][:] = targets[k][:]

    nothing = '          '
    truth['TEMPLATESUBTYPE'] = np.repeat(nothing, nobj)

    masks = ['MWS_ANY', 'BGS_ANY', 'STD_FAINT', 'STD_BRIGHT','ELG', 'LRG', 'QSO', ]
    dict_truespectype = {'BGS_ANY':'GALAXY', 'ELG':'GALAXY', 'LRG':'GALAXY', 'QSO':'QSO', 
                    'MWS_ANY':'STAR', 'STD_FAINT':'STAR', 'STD_BRIGHT':'STAR'}
    dict_truetemplatetype = {'BGS_ANY':'BGS', 'ELG':'ELG', 'LRG':'LRG', 'QSO':'QSO', 
                        'MWS_ANY':'STAR', 'STD_FAINT':'STAR', 'STD_BRIGHT':'STAR'}
    dict_truez = {'BGS_ANY':0.2, 'ELG':1.5, 'LRG':0.7, 'QSO':2.0, 
                        'MWS_ANY':0.0, 'STD_FAINT':0.0, 'STD_BRIGHT':0.0}

    for m in masks:
        istype = (targets['DESI_TARGET'] & desi_mask.mask(m))!=0
        print(m, np.count_nonzero(istype))
        truth['TRUESPECTYPE'][istype] = np.repeat(dict_truespectype[m], np.count_nonzero(istype))
        truth['TEMPLATETYPE'][istype] = np.repeat(dict_truetemplatetype[m], np.count_nonzero(istype))
        truth['MOCKID'][istype] = targets['TARGETID'][istype]
        truth['TRUEZ'][istype] = dict_truez[m]
        
    truth['TRUEZ'][is_lya_qso] = 3.0

    # Check that all targets have been assigned to a class
    iii = truth['MOCKID']==0
    assert np.count_nonzero(iii)==0
    
    print('writing truth')
    truth.write(initial_truth_file, overwrite=True)
    print('done truth')
Ejemplo n.º 2
0
    'BGS_TARGET',
    'MWS_TARGET',
]

#truth file
truthfile = "data/truth.fits"
if not os.path.exists(truthfile):
    import desitarget.mock.mockmaker as mb
    from desitarget.targetmask import desi_mask, bgs_mask, mws_mask

    #targetsfilename = "small_chunk_targets-dr5.0-0.16.2.fits"
    targets = fitsio.read(targetfile, 'TARGETS', columns=columns)
    colnames = list(targets.dtype.names)
    print(colnames)
    nobj = len(targets)
    truth = mb.empty_truth_table(nobj=nobj)
    print(truth.keys())

    for k in colnames:
        if k in truth.keys():
            print(k)
            truth[k][:] = targets[k][:]

    nothing = '          '
    truth['TEMPLATESUBTYPE'] = np.repeat(nothing, nobj)

    masks = ['BGS_ANY', 'ELG', 'LRG', 'QSO', 'STD_FSTAR', 'STD_BRIGHT']
    dict_truespectype = {
        'BGS_ANY': 'GALAXY',
        'ELG': 'GALAXY',
        'LRG': 'GALAXY',
Ejemplo n.º 3
0
def make_global_DR8_truth(global_DR8_mtl_file,
                          output_path='./',
                          program='dark'):
    import desitarget.mock.mockmaker as mb
    from desitarget.targetmask import desi_mask, bgs_mask, mws_mask

    os.makedirs(output_path, exist_ok=True)
    global_DR8_truth_file = os.path.join(
        output_path, 'global_DR8_truth_{}.fits'.format(program))
    if os.path.exists(global_DR8_truth_file):
        print("File {} already exists".format(global_DR8_truth_file))
        return global_DR8_truth_file

    print('Started reading file {}'.format(global_DR8_mtl_file))
    targets = Table.read(global_DR8_mtl_file)
    print('Finished reading file {}'.format(global_DR8_mtl_file))

    # Find what targets will be associated to lya targets
    is_lya_qso = random_assign_lya_qso(targets)

    # Initialized truth Table
    colnames = list(targets.dtype.names)
    print(colnames)
    nobj = len(targets)
    truth = mb.empty_truth_table(nobj=nobj)[0]
    print(truth.keys())

    for k in colnames:
        if k in truth.keys():
            print(k)
            truth[k][:] = targets[k][:]

    nothing = '          '
    truth['TEMPLATESUBTYPE'] = np.repeat(nothing, nobj)

    masks = [
        'MWS_ANY',
        'BGS_ANY',
        'STD_FAINT',
        'STD_BRIGHT',
        'ELG',
        'LRG',
        'QSO',
    ]
    dict_truespectype = {
        'BGS_ANY': 'GALAXY',
        'ELG': 'GALAXY',
        'LRG': 'GALAXY',
        'QSO': 'QSO',
        'MWS_ANY': 'STAR',
        'STD_FAINT': 'STAR',
        'STD_BRIGHT': 'STAR'
    }
    dict_truetemplatetype = {
        'BGS_ANY': 'BGS',
        'ELG': 'ELG',
        'LRG': 'LRG',
        'QSO': 'QSO',
        'MWS_ANY': 'STAR',
        'STD_FAINT': 'STAR',
        'STD_BRIGHT': 'STAR'
    }
    dict_truez = {
        'BGS_ANY': 0.2,
        'ELG': 1.5,
        'LRG': 0.7,
        'QSO': 2.0,
        'MWS_ANY': 0.0,
        'STD_FAINT': 0.0,
        'STD_BRIGHT': 0.0
    }

    for m in masks:
        istype = (targets['DESI_TARGET'] & desi_mask.mask(m)) != 0
        print(m, np.count_nonzero(istype))
        truth['TRUESPECTYPE'][istype] = np.repeat(dict_truespectype[m],
                                                  np.count_nonzero(istype))
        truth['TEMPLATETYPE'][istype] = np.repeat(dict_truetemplatetype[m],
                                                  np.count_nonzero(istype))
        truth['MOCKID'][istype] = targets['TARGETID'][istype]
        truth['TRUEZ'][istype] = dict_truez[m]

    truth['TRUEZ'][is_lya_qso] = 3.0
    truth['RA'] = targets['RA']
    truth['DEC'] = targets['DEC']

    # Check that all targets have been assigned to a class
    iii = truth['MOCKID'] == 0
    assert np.count_nonzero(iii) == 0

    del targets

    print('Started writing to file {}'.format(global_DR8_truth_file))
    truth.write(global_DR8_truth_file, overwrite=True)
    print('Finished writing to file {}'.format(global_DR8_truth_file))

    del truth
    return global_DR8_truth_file