I am not sure if this is a right place to mention this issue, but because I had previously talked to @moustakas and @dstndstn about the DR2 Tractor files and desitarget, I thought it would be good to mention it here (we can delete it later).
When I tried to use the desitarget package to combine the tractor files of DECaLs data (namely DR2), I got the TypeError: invalid type promotion when the script wanted to do
targets = np.concatenate(targets)
in the select_targets function that is defined in desitarget/py/cuts.py.
Which make the code fail during target selection. Finally, after looking into these two files, I realized there were no data in them (they are empty bricks!?)
from __future__ import division
import os, sys
import numpy as np
from time import time
sys.path.append('/global/homes/m/mehdi/github/desitarget/py')
from desitarget import io
from desitarget.internal import sharedmem
# check different files in parallel
def test_targets(infiles, numproc=4, verbose=False, psfmag=False):
#- Convert single file to list of files
if isinstance(infiles,str):
infiles = [infiles,]
#- Sanity check that files exist before going further
for filename in infiles:
if not os.path.exists(filename):
raise ValueError("{} doesn't exist".format(filename))
#- function to run on every brick/sweep file
def _select_targets_file(filename):
'''check if filename has the same dtype as the user-defined one'''
from desitarget import io
# user-defined columns
tscolsn = dtlist = ['BRICKID','BRICKNAME', 'OBJID',
'BRICK_PRIMARY', 'TYPE','RA','DEC','DCHISQ',
'DECAM_FLUX', 'DECAM_FLUX_IVAR', 'DECAM_MW_TRANSMISSION',
'DECAM_FRACFLUX','DECAM_FRACMASKED','DECAM_PSFSIZE',
'WISE_FLUX', 'WISE_FLUX_IVAR',
'WISE_MW_TRANSMISSION','DECAM_DEPTH']
#
#
dtlist = np.array([('BRICKID', '>i4'), ('BRICKNAME', '|S8'), ('OBJID', '>i4'),
('BRICK_PRIMARY', '|b1'), ('TYPE', '|S4'), ('RA', '>f8'), ('DEC', '>f8'),
('DCHISQ', '>f4', (5,)), ('DECAM_FLUX', '>f4', (6,)), ('DECAM_FLUX_IVAR', '>f4', (6,)),
('DECAM_MW_TRANSMISSION', '>f4', (6,)), ('DECAM_FRACFLUX', '>f4', (6,)),
('DECAM_FRACMASKED', '>f4', (6,)), ('DECAM_PSFSIZE', '>f4', (6,)),
('WISE_FLUX', '>f4', (4,)), ('WISE_FLUX_IVAR', '>f4', (4,)),
('WISE_MW_TRANSMISSION', '>f4', (4,)), ('DECAM_DEPTH', '>f4', (6,))])
#
fn = io.read_tractor(filename, columns=tscolsn)
ndtypes = fn.dtype.descr
diffrnc = np.setdiff1d(np.array(ndtypes), dtlist).flatten().tolist()
if len(diffrnc) != 0:
print "%s : %s"%(filename.rsplit('tractor/')[1], str(diffrnc))
return 0
#- Parallel process input files
if numproc > 1:
pool = sharedmem.MapReduce(np=numproc)
with pool:
targets = pool.map(_select_targets_file, infiles)
else:
targets = list()
for x in infiles:
targets.append(_select_targets_file(x))
# program starts
src = sys.argv[1]
infiles = io.list_sweepfiles(src)
if len(infiles) == 0:
infiles = io.list_tractorfiles(src)
if len(infiles) == 0:
print('FATAL: no sweep or tractor files found')
sys.exit(1)
import multiprocessing
nproc = multiprocessing.cpu_count() // 2
test_targets(infiles, numproc=nproc)