Skip to content

Commit

Permalink
- Change use of desitarget.io.mockio.findfile to desitarget.io.find_…
Browse files Browse the repository at this point in the history
…target_files, to construct the correct

	path to look for existing truth files.

	- Add an optional parameter to allow to check for only dark or
	brigth existing truth files.

	- Finish If there are no healpixels to process.
  • Loading branch information
alxogm committed Feb 6, 2020
1 parent a3ee88e commit 7d05641
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions bin/select_mock_targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ from desitarget.mock.build import targets_truth
from desiutil.log import get_logger, DEBUG
import desimodel
import desitarget.mock.io as mockio
from desitarget.io import find_target_files

import multiprocessing
nproc = multiprocessing.cpu_count() // 2
Expand All @@ -33,6 +34,8 @@ parser.add_argument('--join', action='store_true', help='Join the target and tru
parser.add_argument('-v','--verbose', action='store_true', help='Enable verbose output.')
parser.add_argument('--no-spectra', action='store_true', help='Do not generate spectra.')
parser.add_argument('--overwrite', action='store_true', help='Overwrite existing files.')
#Adding this parameters since there will be times in which we only care to check for dark or bright.
parser.add_argument('--check-obscon',type=str,choices=['dark','bright'],help='Check if the truth file of a given observation condition exists, otherwise it will process the pixel.')

args = parser.parse_args()

Expand Down Expand Up @@ -70,35 +73,44 @@ if args.healpixels is None:
else:
healpixels = np.array(args.healpixels)

if not args.check_obscon:
obscon_=['dark','bright'] #Needed to check if truth files from previous runs exists.
else:
obscon_=[args.check_obscon]

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)
if not os.path.exists(truthfile):
keep.append(i)

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

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)

# Construct Targets and Truth files
if not os.path.exists(args.config):
log.fatal('No configuration file {} found.'.format(args.config))
raise Exception()

# Read parameters from yaml file.
log.info('Reading configuration file {}'.format(args.config))
with open(args.config, 'r') as pfile:
params = yaml.safe_load(pfile)

log.info('Calling targets_truth with survey={} at {}'.format(args.survey, time.asctime()))
targets_truth(params, healpixels=healpixels, nside=args.nside, seed=args.seed,
#truthfile = mockio.findfile('truth', args.nside, pixnum, basedir=args.output_dir)
for obscon in obscon_:
truthfile = find_target_files(args.output_dir, flavor="truth", obscon=obscon,
hp=pixnum, nside=args.nside, mock=True)
if (not os.path.exists(truthfile)) and (i not in keep):
keep.append(i)

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

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)

# Construct Targets and Truth files
if not os.path.exists(args.config):
log.fatal('No configuration file {} found.'.format(args.config))
raise Exception()

# Read parameters from yaml file.
log.info('Reading configuration file {}'.format(args.config))
with open(args.config, 'r') as pfile:
params = yaml.safe_load(pfile)

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,
no_spectra=args.no_spectra, survey=args.survey)
log.info('All done at {}'.format(time.asctime()))

log.info('All done at {}'.format(time.asctime()))

0 comments on commit 7d05641

Please sign in to comment.