The goal of this notebook is to assess the signal-to-noise ratio and redshift efficiency of BGS targets observed in "nominal" observing conditions (which are defined here and discussed here, among other places). Specifically, the nominal BGS observing conditions we adopt (note the 5-minute exposure time is with the moon down!) are:
{'AIRMASS': 1.0,
'EXPTIME': 300,
'SEEING': 1.1,
'MOONALT': -60,
'MOONFRAC': 0.0,
'MOONSEP': 180}
During the survey itself, observations with the moon up (i.e., during bright time) will be obtained with longer exposure times according to the bright-time exposure-time model (see here).
Because we fix the observing conditions, we only consider how redshift efficiency depends on galaxy properties (apparent magnitude, redshift, 4000-A break, etc.). However, note that the code is structured such that we could (now or in the future) explore variations in seeing, exposure time, and lunar parameters.
For code to generate large numbers of spectra over significant patches of sky and to create a representative DESI dataset (with parallelism), see desitarget/bin/select_mock_targets
and desitarget.mock.build.targets_truth
.
Finally, note that the various python Classes instantiated here (documented in desitarget.mock.mockmaker
) are easily extensible to other mock catalogs and galaxy/QSO/stellar physics.
In [1]:
import os
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from astropy.table import Table, vstack
from astropy.io import fits
In [2]:
from desispec.io.util import write_bintable
from desiutil.log import get_logger, DEBUG
log = get_logger()
from desitarget.cuts import isBGS_bright, isBGS_faint
## Following not yet available in the master branch
from desitarget.mock.mockmaker import BGSMaker
from desitarget.mock.mockmaker import SKYMaker
In [3]:
import multiprocessing
nproc = multiprocessing.cpu_count() // 2
import seaborn as sns
sns.set(style='white', font_scale=1.1, palette='deep')
In [4]:
# Specify if using this from command line as a .py or as an ipynb
using_py = False
class arg:
pass
In [5]:
simnames = ['sim46']#['sim13','sim14','sim16','sim17','sim18'] #'sim12',
In [6]:
if using_py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--sim', type=int, default=None, help='Simulation number (see documentation)')
parser.add_argument('--part', type=str, default=None, help='Which part of the simulation to run. Options are all, newexp, group, zfit')
args = parser.parse_args()
if args.sim is None:
parser.print_help()
sys.exit(1)
else:
%matplotlib inline
%load_ext autoreload
%autoreload 2
args = arg()
args.sim = 1
args.part = 'all'
In [7]:
simdir = os.path.join(os.getenv('DESI_ROOT'), 'spectro', 'sim', 'bgs', 'kremin', 'flat_priors')
if not os.path.exists(simdir):
os.makedirs(simdir)
In [8]:
seed = 626
In [9]:
overwrite_spectra = True
#overwrite_templates = overwrite_spectra
overwrite_redshifts = True
overwrite_results = True
In [10]:
rand = np.random.RandomState(seed)
Here we use the mock to capture the correct distribution of apparent magnitudes, galaxy properties, and redshifts.
Note that if use_mock=False
then rmagmin, rmagmax, zmin, and zmax are required. For example, here's another possible simulation of 1000 spectra in which the magnitude (r=19.5) and redshift (z=0.2) are held fixed while moonfrac and moonsep are varied (as well as intrinsic galaxy properties):
sim2 = dict(suffix='sim02',
use_mock=False,
nsim=10,
nspec=100,
seed=22,
zmin=0.2, zmax=0.2,
rmagmin=19.5, rmagmax=19.5,
moonfracmin=0.0, moonfracmax=1.0,
moonsepmin=0.0, moonsepmax=120.0,
)
In [11]:
from desistudy import get_predefined_sim_dict, get_predefined_obs_dict
all_sims = []
all_obsconds = []
for simname in simnames:
all_sims.append(get_predefined_sim_dict(simname))
all_obsconds.append(get_predefined_obs_dict(simname))
print(all_obsconds)
sims = np.atleast_1d(all_sims)
conditions = np.atleast_1d(all_obsconds)
In [16]:
from desistudy import bgs_sim_spectra
if overwrite_spectra:
for sim,cond in zip(sims,conditions):
log.info("\n\n\n\nNow performing sim {}".format(sim['suffix']))
bgs_sim_spectra(sim, cond, simdir, verbose=False, overwrite=overwrite_spectra)
log.info("\n\nFinished simulating templates\n\n")
In [13]:
from desistudy import bgs_redshifts
if overwrite_redshifts:
for sim in sims:
log.info("\n\n\n\nNow performing sim {}".format(sim['suffix']))
bgs_redshifts(sim, simdir=simdir, overwrite=overwrite_redshifts)
log.info("\n\n\n\n\nFinished redshift fitting\n\n\n")
In [14]:
from desistudy import bgs_gather_results
if overwrite_results:
for sim in sims:
log.info("\n\n\n\nNow performing sim {}".format(sim['suffix']))
bgs_gather_results(sim, simdir=simdir, overwrite=overwrite_results)
log.info("Finished gathering results")
In [15]:
# from desistudy import bgs_sim_spectra
# from desistudy import bgs_redshifts
# from desistudy import bgs_gather_results
# for sim,cond in zip(sims,conditions):
# log.info("\n\n\n\nNow performing sim {}".format(sim['suffix']))
# if overwrite_spectra:
# bgs_sim_spectra(sim, cond, simdir, verbose=False, overwrite=overwrite_spectra)
# log.info("Finished simulating templates")
# if overwrite_redshifts:
# bgs_redshifts(sim, simdir=simdir, overwrite=overwrite_redshifts)
# log.info("Finished redshift fitting")
# if overwrite_results:
# bgs_gather_results(sim, simdir=simdir, overwrite=overwrite_results)
# log.info("Finished gathering results")