Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maskbits #608

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/mpi_select_mock_targets
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ if rank == 0:
keep = list()
for i, pixnum in enumerate(pixels):
truthspecfile = mockio.findfile('truth', args.nside, pixnum,
basedir=args.output_dir)
basedir=args.output_dir, obscon='dark')
if not os.path.exists(truthspecfile):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely make sure that mock.io.findfile matches how the "real" target catalogs are organized, but I thought we already had a dark/bright organization implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is, but I ran into errors due to a bug on this. I'd have to refresh my memory by comparing to master.

keep.append(i)

log.info('{}/{} pixels remaining to do'.format(len(keep), len(pixels)))
pixels = pixels[keep]

#- pre-create output directories
for pixnum in pixels:
outdir = os.path.dirname(mockio.findfile('blat', args.nside, pixnum,
Expand Down
28 changes: 24 additions & 4 deletions bin/select_mock_targets
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ if args.healpixels is None:
healpixels = desimodel.footprint.tiles2pix(args.nside, tiles)
else:
healpixels = np.array(args.healpixels)

if args.overwrite:
log.info('Processing {} pixel(s).'.format(len(healpixels)))
else:
keep = list()
for i, pixnum in enumerate(healpixels):
truthfile = mockio.findfile('truth', args.nside, pixnum, basedir=args.output_dir)
truthfile = mockio.findfile('truth', args.nside, pixnum, basedir=args.output_dir, obscon='dark')
if not os.path.exists(truthfile):
keep.append(i)

log.info('{}/{} pixels remaining to do'.format(len(keep), len(healpixels)))
log.info('{}/{} pixels remaining to do. {}'.format(len(keep), len(healpixels), healpixels[keep]))
healpixels = healpixels[keep]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the intent of the third number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a lazy way for me know the healpixels to actually be processed, as opposed to the ones I requested, given some had already been generated and were on disk. I was playing games like submitting the second half of that list to a separate job to run in tandem. Obviously, there are more sophisticated approaches and it doesn't need to be kept.


if args.join:
from desitarget.mock.build import join_targets_truth
join_targets_truth(mockdir=args.output_dir, outdir=args.output_dir, overwrite=args.overwrite)
Expand All @@ -96,6 +96,26 @@ log.info('Reading configuration file {}'.format(args.config))
with open(args.config, 'r') as pfile:
params = yaml.safe_load(pfile)

# Set up MASKBITS lookup. Logic check for the necessary files, if not there wget the per brick files for
# all overlapping pixels.
if 'legacy_dir' in params.keys():
# E.g. global/project/projectdirs/cosmo/data/legacysurvey/dr8/
# wget https://portal.nersc.gov/project/cosmo/data/legacysurvey/dr8/north/coadd/338/3380p295/
log.info('Assuming maskbits & depths based on LEGACYDIR={}'.format(params['legacy_dir']))

# Check the survey bricks file exists. We'll use this to ensure that the local files are compelte for
# the healpixels being requested.
legacy_dir = params['legacy_dir']
allbricks = legacy_dir + '/survey-bricks.fits.gz'

if not os.path.isfile(allbricks):
raise RuntimeError('survey-bricks.fits.gz is required under legacy_dir.')

else:
params['legacy_dir'] = None

log.info('Assuming simple homogeneous depths & no masking.')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can realistically expect people to copy over entire brick-sized coadd files to their laptop when all we need are the mean properties at the location of a finite set of random/mock sources.

Copy link
Contributor Author

@michaelJwilson michaelJwilson May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, it'd have been better had we been able to coordinate more at the start. Both I and @geordie666 didn't see this as particularly useful, but we understood that to be the thing that was compatible with "being able to run on a laptop". I.e. we tried to support also running/development the pre-burner on a laptop - by requiring only the minimal number of files given a list of heal pixels. Maybe you're willing to give up on the pre-burner on a laptop, this wasn't clear to me before. I certainly follow the logic of trying to separate the two steps and this probably wouldn't be hard.

My one "concern", which I think you're remembering from the telecon, is that I think you have in mind populating PSF depths etc. for something like the mocks that currently exist, e.g. ~20, including dark sky, etc, to get something desi-like. There is an additional use case of just the mask for ~1000s of (approximate) mocks in the clustering analysis, for which it's less clear that we want redundant information saved to disk in this case. I'd suggest it makes sense to develop select_mock_targets in such a way that it's a one stop shop for both exercises. I.e. in minimal mode, it turns a (ra, dec, z) mock into something accepted by downstream pipeline code, but which has flags etc. that let you dial up the sophistication of effects included. There's a discussion planned on this at the cosmosim group telecon on Thursday.

log.info('Calling targets_truth with survey={} at {}'.format(args.survey, time.asctime()))
targets_truth(params, healpixels=healpixels, nside=args.nside, seed=args.seed,
output_dir=args.output_dir, nproc=args.nproc, verbose=args.verbose,
Expand Down
21 changes: 13 additions & 8 deletions py/desitarget/mock/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def read_mock(params, log=None, target_name='', seed=None, healpixels=None,
magcut = params.get('magcut')
nside_galaxia = params.get('nside_galaxia')
calib_only = params.get('calib_only', False)

# QSO/Lya parameters
nside_lya = params.get('nside_lya')
zmin_lya = params.get('zmin_lya')
Expand All @@ -152,22 +152,25 @@ def read_mock(params, log=None, target_name='', seed=None, healpixels=None,
add_dla = params.get('add_dla', False)
add_metals = params.get('add_metals', False)
add_lyb = params.get('add_lyb', False)

if 'density' in params.keys():
mock_density = True
else:
mock_density = False

log.info('Target: {}, type: {}, format: {}, mockfile: {}'.format(
target_name, target_type, mockformat, mockfile))

if MakeMock is None:
MakeMock = getattr(mockmaker, '{}Maker'.format(target_name))(
seed=seed, nside_chunk=nside_chunk, calib_only=calib_only,
use_simqso=use_simqso, sqmodel=sqmodel, balprob=balprob, add_dla=add_dla,
add_metals=add_metals, add_lyb=add_lyb)
add_metals=add_metals, add_lyb=add_lyb, legacy_dir=legacy_dir)

else:
MakeMock.seed = seed # updated seed

print(target_name, MakeMock.legacy_dir)

data = MakeMock.read(mockfile=mockfile, mockformat=mockformat,
healpixels=healpixels, nside=nside,
Expand All @@ -176,7 +179,7 @@ def read_mock(params, log=None, target_name='', seed=None, healpixels=None,
nside_galaxia=nside_galaxia, mock_density=mock_density)
if not bool(data):
return data, MakeMock

# Add the information we need to incorporate density fluctuations.
if 'density' in params.keys():
if 'MOCK_DENSITY' not in data.keys():
Expand Down Expand Up @@ -854,11 +857,13 @@ def targets_truth(params, healpixels=None, nside=None, output_dir='.',
add_dla = params['targets'][target_name].get('add_dla', False)
add_metals = params['targets'][target_name].get('add_metals', False)
add_lyb = params['targets'][target_name].get('add_lyb', False)
legacy_dir = params['legacy_dir']

AllMakeMock.append(getattr(mockmaker, '{}Maker'.format(target_name))(
seed=seed, nside_chunk=nside_chunk, calib_only=calib_only,
use_simqso=use_simqso, sqmodel=sqmodel, balprob=balprob, add_dla=add_dla,
add_metals=add_metals, add_lyb=add_lyb, no_spectra=no_spectra,
survey=survey))
survey=survey, legacy_dir=legacy_dir))

# Are we adding contaminants? If so, cache the relevant classes here.
if 'contaminants' in params.keys():
Expand All @@ -870,7 +875,7 @@ def targets_truth(params, healpixels=None, nside=None, output_dir='.',
star_name, _ = list(params['contaminants']['stars'].items())[0]
ContamStarsMock = getattr(mockmaker, '{}Maker'.format(star_name))(
seed=seed, nside_chunk=nside_chunk, no_spectra=no_spectra,
survey=survey)
survey=survey, legacy_dir=legacy_dir)
else:
ContamStarsMock = None

Expand All @@ -882,7 +887,7 @@ def targets_truth(params, healpixels=None, nside=None, output_dir='.',
galaxies_name, _ = list(params['contaminants']['galaxies'].items())[0]
ContamGalaxiesMock = getattr(mockmaker, '{}Maker'.format(galaxies_name))(
seed=seed, nside_chunk=nside_chunk, no_spectra=no_spectra,
target_name='CONTAM_GALAXY', survey=survey)
target_name='CONTAM_GALAXY', survey=survey, legacy_dir=legacy_dir)
else:
ContamGalaxiesMock = None

Expand Down
66 changes: 66 additions & 0 deletions py/desitarget/mock/data/select-mock-targets-no-contam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Parameter file for desitarget/bin/select_mock_targets, including contaminants.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contaminants can just be commented out of the configuration file. That said, maybe it'd be worth adding a --no-contaminants optional input to select_mock_targets to overwrite whatever's in the config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always find myself doing this so such a flag, or yaml, would be useful in my opinion.

# legacy_dir: /global/project/projectdirs/cosmo/data/legacysurvey/dr8/
legacy_dir: /global/homes/m/mjwilson/desi/survey-validation/svdc-spring2020g-onepercent/legacydir

targets:
BGS: {
target_type: BGS,
mockfile: '{DESI_ROOT}/mocks/bgs/MXXL/full_sky/v0.0.4/BGS_r20.6.hdf5',
format: durham_mxxl_hdf5,
magcut: 20.3,
}
ELG: {
target_type: ELG,
mockfile: '{DESI_ROOT}/mocks/DarkSky/v1.0.1/elg_0_inpt.fits',
format: gaussianfield,
density: 2200,
}
LRG: {
target_type: LRG,
mockfile: '{DESI_ROOT}/mocks/DarkSky/v1.0.1/lrg_0_inpt.fits',
format: gaussianfield,
density: 480,
}
QSO: {
target_type: QSO,
mockfile: '{DESI_ROOT}/mocks/DarkSky/v1.0.1/qso_0_inpt.fits',
format: gaussianfield,
zmax_qso: 1.8,
use_simqso: True,
density: 120,
}
LYA: {
target_type: QSO,
mockfile: '{DESI_ROOT}/mocks/lya_forest/london/v9.0/v9.0.0/master.fits',
format: CoLoRe,
nside_lya: 16,
zmin_lya: 1.8,
density: 50,
use_simqso: True,
sqmodel: 'default', #Other options are 'lya_simqso_model_develop' and 'lya_simqso_model' (same as quickquasars)
balprob: 0.0,
add_dla: False,
add_metals: False, #If adding metals use 'all', this is to keep the same argument as in quickquasars.
add_lyb: False
}
MWS_MAIN: {
target_type: STAR,
mockfile: '{DESI_ROOT}/mocks/mws/galaxia/alpha/v0.0.6/healpix',
nside_galaxia: 8,
format: galaxia,
}
MWS_NEARBY: {
target_type: STAR,
mockfile: '{DESI_ROOT}/mocks/mws/100pc/v0.0.4/mock_100pc.fits',
format: mws_100pc,
}
WD: {
target_type: WD,
mockfile: '{DESI_ROOT}/mocks/mws/wd/v1.0.0/mock_wd.fits',
format: mws_wd,
}
SKY: {
target_type: SKY,
mockfile: '{DESI_ROOT}/mocks/uniformsky/0.2/uniformsky-2048-0.2.fits',
format: uniformsky,
}
52 changes: 52 additions & 0 deletions py/desitarget/mock/get_legacy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os

from desitarget.geomask import hp_in_box
from desitarget.randoms import dr_extension, _pre_or_post_dr8
from desiutil import brick


nside = 8
bricks = brick.Bricks(bricksize=0.25)
bricktable = bricks.to_table()
lookupdict = {bt["BRICKNAME"]: hp_in_box(nside, [bt["RA1"], bt["RA2"], bt["DEC1"], bt["DEC2"]]) for bt in bricktable}

pixnum = 6195
bricknames = [key for key in lookupdict if pixnum in lookupdict[key]]

print(bricknames)

# bricknames = ['0880p587', '0880p590', '0881p582', '0882p592']

# drdir = '/global/homes/m/mjwilson/desi/survey-validation/svdc-spring2020g-onepercent/legacydir/'
drdir = '/global/project/projectdirs/cosmo/data/legacysurvey/dr8/'

drdirs = _pre_or_post_dr8(drdir)

for drdir in drdirs:
# ADM determine whether the coadd files have extension .gz or .fz based on the DR directory.
extn, extn_nb = dr_extension(drdir)

filt = ['g', 'r', 'z']
qnames = ['nexp', 'depth', 'galdepth', 'psfsize', 'image']

for brickname in bricknames:
brickname = brickname.replace('m', 'p')

rootdir = os.path.join(drdir, 'coadd', brickname[:3], brickname)
fileform = os.path.join(rootdir, 'legacysurvey-{}-{}-{}.fits.{}')

# ADM loop through the filters and store the number of observations
# ADM etc. at the RA and Dec positions of the passed points.
for f in ['g', 'r', 'z']:
# ADM the input file labels, and output column names and output
# ADM formats for each of the quantities of interest.
for q in qnames:
fn = fileform.format(brickname, q, f, extn)

cmd = 'cp {} legacydir/'.format(fn)

# os.system(cmd)

print(cmd)

break
9 changes: 7 additions & 2 deletions py/desitarget/mock/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ def findfile(filetype, nside, pixnum, basedir='.', ext='fits', obscon=None):
obscon: (str) e.g. 'dark', 'bright' to add extra dir grouping
'''
path = get_healpix_dir(nside, pixnum, basedir=basedir)

if obscon is not None:
path = os.path.join(path, obscon.lower())

filename = '{filetype}-{nside}-{pixnum}.{ext}'.format(
filetype=filetype, nside=nside, pixnum=pixnum, ext=ext)
filename = '{filetype}-{obscon}-{nside}-{pixnum}.{ext}'.format(
filetype=filetype, obscon=obscon.lower(), nside=nside, pixnum=pixnum, ext=ext)

else:
filename = '{filetype}-{nside}-{pixnum}.{ext}'.format(
filetype=filetype, nside=nside, pixnum=pixnum, ext=ext)

return os.path.join(path, filename)
Loading