def test_targets_truth(self): configfile = resource_filename('desitarget.mock', 'data/select-mock-targets.yaml') import yaml with open(configfile) as fx: params = yaml.safe_load(fx) for targettype in params['targets'].keys(): mockfile = params['targets'][targettype]['mockfile'].format(**os.environ) self.assertTrue(os.path.exists(mockfile), 'Missing {}'.format(mockfile)) #- Test without spectra targets_truth(params, healpixels=[99737,], nside=256, output_dir=self.outdir, no_spectra=True) targetfile = self.outdir + '/997/99737/targets-256-99737.fits' truthfile = self.outdir + '/997/99737/truth-256-99737.fits' self.assertTrue(os.path.exists(targetfile)) self.assertTrue(os.path.exists(truthfile)) with fitsio.FITS(truthfile) as fx: self.assertTrue('TRUTH' in fx) #- WAVE is there, and FLUX is there but with strange shape (n,0) # self.assertTrue('WAVE' not in fx) # self.assertTrue('FLUX' not in fx) #- Test with spectra shutil.rmtree(self.outdir+'/997') targets_truth(params, healpixels=[99737,], nside=256, output_dir=self.outdir, no_spectra=False) self.assertTrue(os.path.exists(targetfile)) self.assertTrue(os.path.exists(truthfile)) with fitsio.FITS(truthfile) as fx: self.assertTrue('TRUTH' in fx) self.assertTrue('WAVE' in fx) self.assertTrue('FLUX' in fx)
print('output_dir {}'.format(output_dir)) #generate targets if generate_spec: if not os.path.exists(output_dir): nproc = 24 from desitarget.mock.build import targets_truth from desispec.log import get_logger, DEBUG log = get_logger(DEBUG) # Optionally read the "real" target catalog. realtargets_file = '/project/projectdirs/desi/target/catalogs/targets-dr3.1-0.8.1.fits' from astropy.io import fits print('Loading real targets from {}'.format(realtargets_file)) realtargets = fits.getdata(realtargets_file) # Construct Targets and Truth files targets_truth(params, output_dir, realtargets=realtargets, seed=42, verbose=True, nproc=nproc) log.info('All done!') print('n_tiles', n_tiles) print('n_grid', len(grid_list))