Skip to content

Commit

Permalink
working on elgs
Browse files Browse the repository at this point in the history
  • Loading branch information
moustakas committed Dec 11, 2018
1 parent e2e4dc8 commit 9f1d6fc
Showing 1 changed file with 65 additions and 59 deletions.
124 changes: 65 additions & 59 deletions py/desitarget/mock/mockmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,65 +785,65 @@ def KDTree_query(self, matrix, return_dist=False, south=True, subtype=''):
else:
return indx.astype('i4')

def sample_gmm_nospectra(self, meta, rand=None, target=None):
"""Sample from one of the Gaussian mixture models generated by
desitarget/doc/nb/gmm-quicksurvey.ipynb.
Note: Any changes to the quantities fitted in that notebook need to be
updated here!
"""
if rand is None:
rand = np.random.RandomState()

nsample = len(meta)

# For contaminants, sample from the appropriate Gaussian mixture model.
if type(self.GMM_nospectra) == dict:
data = self.GMM_nospectra[target].sample(nsample, random_state=rand)
else:
target = meta['OBJTYPE'][0].upper()
data = self.GMM_nospectra.sample(nsample, random_state=rand)

alltags = dict()
alltags['ELG'] = ('r', 'g - r', 'r - z', 'z - W1', 'W1 - W2', 'oii')
alltags['LRG'] = ('z', 'g - r', 'r - z', 'z - W1', 'W1 - W2')
alltags['BGS'] = ('r', 'g - r', 'r - z', 'z - W1', 'W1 - W2')
alltags['QSO'] = ('g', 'g - r', 'r - z', 'z - W1', 'W1 - W2')
alltags['LYA'] = ('g', 'g - r', 'r - z', 'z - W1', 'W1 - W2')

tags = alltags[target]
sample = np.empty( nsample, dtype=np.dtype( [(tt, 'f4') for tt in tags] ) )
for ii, tt in enumerate(tags):
sample[tt] = data[:, ii]

if target == 'ELG' or target == 'BGS':
rmag = sample['r']
zmag = rmag - sample['r - z']
gmag = sample['g - r'] + rmag
normmag = rmag
elif target == 'LRG':
zmag = sample['z']
rmag = sample['r - z'] + zmag
gmag = sample['g - r'] + rmag
normmag = zmag
elif target == 'QSO' or target == 'LYA':
gmag = sample['g']
rmag = gmag - sample['g - r']
zmag = rmag - sample['r - z']
normmag = gmag

W1mag = zmag - sample['z - W1']
W2mag = W1mag - sample['W1 - W2']

meta['MAG'][:] = normmag
meta['FLUX_G'][:] = 1e9 * 10**(-0.4 * gmag)
meta['FLUX_R'][:] = 1e9 * 10**(-0.4 * rmag)
meta['FLUX_Z'][:] = 1e9 * 10**(-0.4 * zmag)
meta['FLUX_W1'][:] = 1e9 * 10**(-0.4 * W1mag)
meta['FLUX_W2'][:] = 1e9 * 10**(-0.4 * W2mag)

return meta
#def sample_gmm_nospectra(self, meta, rand=None, target=None):
# """Sample from one of the Gaussian mixture models generated by
# desitarget/doc/nb/gmm-quicksurvey.ipynb.
#
# Note: Any changes to the quantities fitted in that notebook need to be
# updated here!
#
# """
# if rand is None:
# rand = np.random.RandomState()
#
# nsample = len(meta)
#
# # For contaminants, sample from the appropriate Gaussian mixture model.
# if type(self.GMM_nospectra) == dict:
# data = self.GMM_nospectra[target].sample(nsample, random_state=rand)
# else:
# target = meta['OBJTYPE'][0].upper()
# data = self.GMM_nospectra.sample(nsample, random_state=rand)
#
# alltags = dict()
# alltags['ELG'] = ('r', 'g - r', 'r - z', 'z - W1', 'W1 - W2', 'oii')
# alltags['LRG'] = ('z', 'g - r', 'r - z', 'z - W1', 'W1 - W2')
# alltags['BGS'] = ('r', 'g - r', 'r - z', 'z - W1', 'W1 - W2')
# alltags['QSO'] = ('g', 'g - r', 'r - z', 'z - W1', 'W1 - W2')
# alltags['LYA'] = ('g', 'g - r', 'r - z', 'z - W1', 'W1 - W2')
#
# tags = alltags[target]
# sample = np.empty( nsample, dtype=np.dtype( [(tt, 'f4') for tt in tags] ) )
# for ii, tt in enumerate(tags):
# sample[tt] = data[:, ii]
#
# if target == 'ELG' or target == 'BGS':
# rmag = sample['r']
# zmag = rmag - sample['r - z']
# gmag = sample['g - r'] + rmag
# normmag = rmag
# elif target == 'LRG':
# zmag = sample['z']
# rmag = sample['r - z'] + zmag
# gmag = sample['g - r'] + rmag
# normmag = zmag
# elif target == 'QSO' or target == 'LYA':
# gmag = sample['g']
# rmag = gmag - sample['g - r']
# zmag = rmag - sample['r - z']
# normmag = gmag
#
# W1mag = zmag - sample['z - W1']
# W2mag = W1mag - sample['W1 - W2']
#
# meta['MAG'][:] = normmag
# meta['FLUX_G'][:] = 1e9 * 10**(-0.4 * gmag)
# meta['FLUX_R'][:] = 1e9 * 10**(-0.4 * rmag)
# meta['FLUX_Z'][:] = 1e9 * 10**(-0.4 * zmag)
# meta['FLUX_W1'][:] = 1e9 * 10**(-0.4 * W1mag)
# meta['FLUX_W2'][:] = 1e9 * 10**(-0.4 * W2mag)
#
# return meta

def _nospectra_photometry(self, meta, rand, data, indx, target_name, contaminants=False):
"""Populate the photometry in meta in no-spectra mode."""
Expand Down Expand Up @@ -3433,6 +3433,8 @@ class LRGMaker(SelectTargets):
"""
wave, KDTree_north, KDTree_south, template_maker = None, None, None, None
GMM_LRG, GMM_nospectra = None, None

here remove gmm_nospectra

def __init__(self, seed=None, nside_chunk=128, **kwargs):
from desisim.templates import LRG
Expand Down Expand Up @@ -3581,6 +3583,10 @@ def make_spectra(self, data=None, indx=None, seed=None, no_spectra=False):
if no_spectra:
flux = []
meta, objmeta = empty_metatable(nmodel=nobj, objtype=self.objtype)
self._nospectra_photometry(meta, rand, data, indx, data['TARGET_NAME'])

here!

meta['SEED'][:] = rand.randint(2**31, size=nobj)
meta['REDSHIFT'][:] = data['Z'][indx]
self.sample_gmm_nospectra(meta, rand=rand) # noiseless photometry from pre-computed GMMs
Expand Down

0 comments on commit 9f1d6fc

Please sign in to comment.