Skip to content

Commit

Permalink
add calib_only optional parameter to mock config file
Browse files Browse the repository at this point in the history
  • Loading branch information
moustakas committed Jun 12, 2018
1 parent 8d09f7c commit 5f50bae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
16 changes: 9 additions & 7 deletions py/desitarget/mock/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def read_mock(params, log, dust_dir=None, seed=None, healpixels=None,
magcut = params.get('magcut')
nside_lya = params.get('nside_lya')
nside_galaxia = params.get('nside_galaxia')
calib_only = params.get('calib_only', False)

if 'density' in params.keys():
mock_density = True
Expand All @@ -161,7 +162,8 @@ def read_mock(params, log, dust_dir=None, seed=None, healpixels=None,
log.info('Target: {}, format: {}, mockfile: {}'.format(target_name, mockformat, mockfile))

if MakeMock is None:
MakeMock = getattr(mockmaker, '{}Maker'.format(target_name))(seed=seed, nside_chunk=nside_chunk)
MakeMock = getattr(mockmaker, '{}Maker'.format(target_name))(seed=seed, nside_chunk=nside_chunk,
calib_only=calib_only)
else:
MakeMock.seed = seed # updated seed

Expand Down Expand Up @@ -266,7 +268,7 @@ def get_spectra_onepixel(data, indx, MakeMock, seed, log, ntarget,
if nkeep > 0:
targets.append(chunktargets[keep])
truth.append(chunktruth[keep])
if not no_spectra:
if not no_spectra or not MakeMock.calib_only:
trueflux.append(chunkflux[keep, :])
else:
# Generate the spectra iteratively until we achieve the required
Expand All @@ -289,7 +291,7 @@ def get_spectra_onepixel(data, indx, MakeMock, seed, log, ntarget,

targets.append(chunktargets[keep])
truth.append(chunktruth[keep])
if not no_spectra:
if not no_spectra and not MakeMock.calib_only:
trueflux.append(chunkflux[keep, :])

itercount += 1
Expand All @@ -308,7 +310,7 @@ def get_spectra_onepixel(data, indx, MakeMock, seed, log, ntarget,
if len(targets) > 0:
targets = vstack(targets)
truth = vstack(truth)
if not no_spectra:
if not no_spectra and not MakeMock.calib_only:
trueflux = np.concatenate(trueflux)

return [targets, truth, trueflux]
Expand Down Expand Up @@ -489,7 +491,7 @@ def _update_spectra_status(result):
if sky:
trueflux = []
else:
if no_spectra:
if no_spectra or MakeMock.calib_only:
trueflux = []
else:
good = [len(targ) > 0 for targ in results[0]]
Expand Down Expand Up @@ -550,9 +552,9 @@ def targets_truth(params, healpixels=None, nside=None, output_dir='.',
AllMakeMock = []
for source_name in sorted(params['sources'].keys()):
target_name = params['sources'][source_name].get('target_name')
calib_only = params['sources'][source_name].get('calib_only', False)
AllMakeMock.append(getattr(mockmaker, '{}Maker'.format(target_name))(
seed=seed, nside_chunk=nside_chunk))
print(AllMakeMock[0].seed)
seed=seed, nside_chunk=nside_chunk, calib_only=calib_only))

# Loop over each source / object type.
for healpix, healseed in zip(healpixels, healpixseeds):
Expand Down
12 changes: 7 additions & 5 deletions py/desitarget/mock/mockmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3766,7 +3766,7 @@ class WDMaker(SelectTargets):
wave, da_template_maker, db_template_maker = None, None, None
wd_maggies_da, wd_maggies_db, tree_da, tree_db = None, None, None, None

def __init__(self, seed=None, normfilter='decam2014-g', **kwargs):
def __init__(self, seed=None, normfilter='decam2014-g', calib_only=False, **kwargs):
from scipy.spatial import cKDTree as KDTree
from speclite import filters
from desisim.templates import WD
Expand All @@ -3775,6 +3775,7 @@ def __init__(self, seed=None, normfilter='decam2014-g', **kwargs):

self.seed = seed
self.objtype = 'WD'
self.calib_only = calib_only

if self.wave is None:
WDMaker.wave = _default_wave()
Expand Down Expand Up @@ -3980,7 +3981,7 @@ def make_spectra(self, data=None, indx=None, seed=None, no_spectra=False):
#else:
if self.mockformat == 'mws_wd':
allsubtype = data['TEMPLATESUBTYPE'][indx]
if no_spectra:
if no_spectra or self.calib_only:
meta = empty_metatable(nmodel=nobj, objtype=self.objtype)
flux = []
else:
Expand All @@ -4002,7 +4003,7 @@ def make_spectra(self, data=None, indx=None, seed=None, no_spectra=False):
data['LOGG'][indx][these])).T
_, templateid = self._query(alldata, subtype=subtype)

if no_spectra:
if no_spectra or self.calib_only:
meta1 = self.template_photometry(data, indx[these],
rand, subtype)
meta[these] = meta1
Expand Down Expand Up @@ -4040,8 +4041,9 @@ def select_targets(self, targets, truth, **kwargs):
#mws_wd = np.ones(len(targets)) # select everything!
mws_wd = ((truth['MAG'] >= 15.0) * (truth['MAG'] <= 20.0)) * 1 # SDSS g-band!

targets['MWS_TARGET'] |= (mws_wd != 0) * self.mws_mask.mask('MWS_WD')
targets['DESI_TARGET'] |= (mws_wd != 0) * self.desi_mask.MWS_ANY
if not self.calib_only:
targets['MWS_TARGET'] |= (mws_wd != 0) * self.mws_mask.mask('MWS_WD')
targets['DESI_TARGET'] |= (mws_wd != 0) * self.desi_mask.MWS_ANY

# Select STD_WD; cut just on g-band magnitude (not TEMPLATESUBTYPE!)
std_wd = (truth['MAG'] <= 19.0) * 1 # SDSS g-band!
Expand Down

0 comments on commit 5f50bae

Please sign in to comment.