\documentclass[modern, linenumbers]{aastex62}
\usepackage{amsmath}

\usepackage{epsfig}
\usepackage{rotate}
%\usepackage{lscape}
%\usepackage{setspace}
\usepackage{outlines}

\newcommand{\myemail}{jarronl@email.arizona.edu}

%\usepackage{hyperref}
\usepackage[capitalize,noabbrev]{cleveref}
\crefname{section}{\S}{\S\S}
\Crefname{section}{\S}{\S\S}
% patch for emulateapj
\makeatletter
\usepackage{etoolbox}
\patchcmd\H@refstepcounter{\protected@edef}{\protected@xdef}{}{}
\makeatother


\usepackage{xargs}  % Use more than one optional parameter in a new commands
\usepackage{xcolor}  % Coloured text etc.
\usepackage[colorinlistoftodos,prependcaption,textsize=footnotesize]{todonotes}
\newcommandx{\unsure}[2][1=]{\todo[linecolor=red,backgroundcolor=red!25,bordercolor=red,#1]{#2}}
\newcommandx{\change}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=blue,#1]{#2}}
\newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}
\newcommandx{\improvement}[2][1=]{\todo[linecolor=Plum,backgroundcolor=Plum!25,bordercolor=Plum,#1]{#2}}
\newcommandx{\thiswillnotshow}[2][1=]{\todo[disable,#1]{#2}}


% Custom definitions and commands
\def\arcsec{{$^{\prime\prime}$}}
\def\arcmin{{$^{\prime}$}}
\def\ptsec{$^{\prime\prime}\mskip-7.6mu.\,$}
\def\ptmin{$^{\prime}\mskip-4.0mu.$}
\def\ptdeg{$^\circ\mskip-7.6mu.\,$}
\def\code#1{\texttt{#1}}

\newcommand{\um}{$\mu$m}
\newcommand{\msun}{M$_{\sun}$}
\newcommand{\acet}{C$_2$H$_2$}
\newcommand{\water}{H$_2$O}
\newcommand{\neii}{[Ne~{\scshape II}]}
\newcommand{\neiii}{[Ne~{\scshape III}]}
\newcommand{\hi}{H~{\scshape I}}
\newcommand{\ctemp}{$[6.0]-[13.5]$}

\newcommand{\pynrc}{\texttt{\MakeLowercase{py}NRC}}

\newcounter{qcounter}
% A nice bulleted list
\newcommand{\squishlist}{
 \begin{list}{$\bullet$}
  { \setlength{\itemsep}{2pt}
     \setlength{\parsep}{0pt}
     \setlength{\topsep}{3pt}
     \setlength{\partopsep}{0pt}
     \setlength{\leftmargin}{2.5em}
     \setlength{\labelwidth}{1em}
     \setlength{\labelsep}{0.5em} } }
\newcommand{\squishlisttwo}{
 \begin{list}{$\bullet$}
  { \setlength{\itemsep}{0pt}
     \setlength{\parsep}{0pt}
     \setlength{\topsep}{0pt}
     \setlength{\partopsep}{0pt}
     \setlength{\leftmargin}{2em}
     \setlength{\labelwidth}{1em}
     \setlength{\labelsep}{0.5em} } }
\newcommand{\squishnum}{
 \begin{list}{\arabic{qcounter}.}
  {  \usecounter{qcounter}
     \setlength{\itemsep}{2pt}
     \setlength{\parsep}{0pt}
     \setlength{\topsep}{3pt}
     \setlength{\partopsep}{0pt}
     \setlength{\leftmargin}{2.5em}
     \setlength{\labelwidth}{1em}
     \setlength{\labelsep}{0.5em} } }
\newcommand{\squishend}{
  \end{list}  }


  \shorttitle{\pynrc}
  \shortauthors{Leisenring \emph{et al.}}

\NewPageAfterKeywords
\begin{document}

\title{\pynrc: A NIRCam ETC and Simulation Toolset}

\author[0000-0002-0834-6140]{Jarron M.\ Leisenring}
\affiliation{Steward Observatory, University of Arizona, 933 N.\ Cherry Ave., Tucson, AZ 85721}

\author{Everett Schlawin}
\affiliation{Steward Observatory, University of Arizona, 933 N.\ Cherry Ave., Tucson, AZ 85721}

% \author{Jonathan Fraine}
% \affiliation{Space Telescope Science Institute, Baltimore, MD 21218}

\author{Thomas Greene}
\affiliation{NASA Ames Research Center, Space Science and Astrobiology Division, M.S. 245-6, Moffett Field, CA 94035}

\author{Karl Misselt}
\affiliation{Steward Observatory, University of Arizona, 933 N.\ Cherry Ave., Tucson, AZ 85721}

\author{Marcia Rieke}
\affiliation{Steward Observatory, University of Arizona, 933 N.\ Cherry Ave., Tucson, AZ 85721}

\author{Christopher Willmer}
\affiliation{Steward Observatory, University of Arizona, 933 N.\ Cherry Ave., Tucson, AZ 85721}


\correspondingauthor{Jarron M.\ Leisenring}
\email{jarronl@email.arizona.edu}

%\doublespace
\begin{abstract}
% \todo[indine]{}
With the approaching launch of the James Webb Space Telescope (JWST), the astronomical community requires easily accessible software tools to assist in the development of observing proposals. 
Each science instrument aboard JWST offers a variety of observing modes with a range of flexibility and complexity often confusing to an uninitiated user. 
As the observatory's primary near-IR imager, NIRCam is no exception, offering simultaneous wide-field imaging of two wavelength channels, coronagraphic imaging over small fields of view, wide-field slitless spectroscopy at two perpendicular orientations, and time-series observations in both imaging and spectroscopic modes. 
We present the open-source Python package \pynrc, a NIRCam-specific exposure time calculator (ETC) and simulator to help choose optimal instrument settings for specific science cases. 
At its core, \pynrc\ uses point-spread-function (PSF) information generated by WebbPSF to create two-dimensional signal and noise images. 
The package incorporates realistic filter bandpasses, detector effects, and MULTIACCUM ramp sampling schemes with results verified and validated by the NIRCam science instrument team. 
Building off of this framework, \pynrc\ also provides capabilities to generate realistic simulations of complex astronomical scenes, enabling end-to-end testing of the JWST data management system, reduction pipelines, and analysis techniques.\end{abstract}

% Up to 6 keywords in alphabetical order
\keywords{Coronagraphy, Detectors, JWST, NIRCam, Python Simulations}

\section{Introduction}

NIRCam acts as the primary near-infrared (NIR) camera for the James Webb Space Telescope (JWST). With wavelength coverage from $\lambda=0.6$ to 5.0~\um, NIRCam offers multiple observing modes such as wide-field imaging, coronagraphic imaging (20\arcsec~$\times$~20\arcsec), and slitless spectroscopy spanning $\lambda=2.4$ to 5.0~\um\ \citep{beic12, kris07, riek05, gree07, gree17}. In addition, future proposal cycles may expand the allowed science modes, presenting users the opportunity to observe with NIRCam's dispersed Hartmann sensors (DHSs), which provides spectral coverage at $\lambda=1$ to 2~\um\ with $R \equiv \lambda/\delta\lambda \simeq 300$ \citep{schl17}.

As the main instrument responsible for wavefront sensing and primary segment phasing, NIRCam was constructed with multiple redundant systems to minimize risk of critical failures. Specifically, the instrument consists of two identical modules (A and B), each with an independent 2\ptmin2~$\times$~2\ptmin2 field of view (FOV) adjacently aligned. Each module further houses two wavelength channels separated by a dichroic beamsplitter and occupying the same FOV. The short-wavelength (SW) channel images $\lambda<2.4$~\um\ light onto a grid of four HAWAII-2RG \citep[H2RG;][]{bele08} detectors (32~mas/pixel), whereas the long-wavelength (LW) channel utilizes a single H2RG with approximately twice the pixel scale (65~mas/pixel). This allows simultaneous observations with the SW and LW channels of the same NIRCam field in each module.

While a boon for observers, the expanded instrument modes and built-in flexibility also burdens users with added complexity and potential confusion. 
For instance, it may not be obvious which observational mode and detector readout setting will optimize the scientific return, especially when taking into account instrument and observatory overheads and efficiency. 
Initially devised as a guide for Guaranteed Time Observations (GTO) science program, the NIRCam instrument team developed an exposure time calculator (ETC) to better understand the relative instrument performance and trade-off between different operating modes. 
This software evolved into \pynrc, a Python-based toolset that includes a simple ETC for quick calculations, a rudimentary slope image generator, and a full-featured simulator to produce realistic raw data for testing data reduction pipelines and analysis software. 
Simulation components, such as instrument throughputs and detector characteristics, are based on as-built performance tests wherever possible and observatory design parameters otherwise. 
All PSFs are generated via WebbPSF\footnote{\url{https://webbpsf.readthedocs.io}} \citep{perr12,perr14} to reproduce realistic NIRCam images and spectra.

%Much of \pynrc was designed specifically to address the needs of the NIRCam Extragalactic survey, as at the time coding was initiated (∼ April 2011) no other simulator existed. Since then other simulators that can generate NIRCam images have been written or are under development. Of note are pyNRC2 by Jarron Leisenring, which can generate scenes using the full field or the NIRCam coronagraph for direct imaging or slitless spectroscopy; the Space Telescope Image Product Simulator (STIPS)3, which can generate scenes using Sersic models and adding a mix of stellar population models; mirage4 (Hilbert et al. 2017), which also generates imaging and slitless spectroscopy scenes for NIRCam and NIRISS and PHOSIM5 originally developed for LSST, which is being adapted for JWST+NIRCam by the original developers and Eiichi Egami of the NIRCam Team; PHOSIM differs from the other simulators in its use ofoptical modeling of JWST and NIRCam for the instrument characteristics.

\section{Program Structure}



\section{Exposure Time Calculator}



\section{Generating Realistic PSFs}

While \pynrc\ is meant as a multipurpose tool for the general astronomical community, we placed significant effort on development of coronagraphic imaging in order to better represent the instrument's contrast performance. 
This was driven in part during the planning stage of the NIRCam GTO exoplanet and disk programs to investigate trade-offs between different operational modes, such as direct imaging compared to the various coronagraphic occulters.

Detection of faint objects in high contrast observations is generally limited by our ability to optimally remove the PSF of the host star and minimize residual speckle noise within the subtracted stellar halo. 
A number of physical factors can affect the contrast performance of segmented, diffraction-limited telescopes \citep{perr18}. For instance, in the regime of a static telescope (i.e., constant wavefront error), we must consider the impact on contrast of spectral type mismatches between science and reference observations, target acquisition uncertainties, field-dependent WFE differences, and fundamental noise limits (e.g., photon and detector read noise). Further dynamic, time-variable factors include pointing jitter, thermal distortions of the OTE, and fast pseudo-random oscillations of the OTE wavefront due to state changes in onboard electronics.
Generating realistic simulations therefore requires high-fidelity PSFs that encode range of variations to the optical state of the instrument.
% in order to generate representative synthetic observations. 

WebbPSF offers the capabilities to input arbitrary OPD maps where each mirror segment consists of a unique set of WFE Zernike coefficients.
During ISIM CV3 at GSFC, prior to integration with the telescope OTE, we derived the NIRCam WFE for a number of positions across the instrument FoV. 
These low-order Zernike components of the measured field points match particularly well to the finalized optical model as represented in CODEV and Zemax.
\todo{Add references}
Because the wavefront retrieval optics our housed in the same wheel as the Lyot stops, we were measure the WFE maps for NIRCam's coronagraphic mode; WFE measurements from Zemax are used instead.
\todo{Major Zernike and WFE RMS differences between coronagraphy and imaging.}
The NIRCam optical model as implemented in \pynrc\ assumes the science instrument Zernike components for each field point stays constant while varying the overall telescope OPD map with time.
A series of nominal OTE OPD maps have been built based on ground-based OTIS cryo testing at JSC, allowing segment-level manipulation of the anticipated OTE state over time. 
\todo{Add image of OTE OPD.}

Many simulators, such as \todo[indine]{names of software}, utilize a large library of pre-computed PSFs to simulate observations of some astronomical scene.
However, our goals require generating a wide variety of PSFs that depend on wavelength, field position, and time, which would produce a prohibitively large set of PSFs.  
Rather than hosting a library of oversampled monochromatic PSFs that vary with time and field position, \pynrc\ fits and saves a set of wavelength-dependent polynomial coefficients across the channel's wavelength range. 
With the coefficients in hand, it is a simple matter to quickly generate an arbitrary number of monochromatic PSFs. 
These sets of coefficients are saved to disk the first time a PSF is requested and can be recalled at any later instance. This approach limits the amount of information stored on the host machine and produces only those PSFs that a user is interested in (ie., imaging vs coronagraphy vs spectroscopy).

%Realistic simulations must consider a number of factors in order to probe the extent of PSF variations for the expected instrument performance \citep{perr18}.


% Things to consider for realistic simulations:\\
% 1. spectral type mismatch between science and reference targets
% 2. photon and detector noise limits
% 3. pointing mismatch (5~mas uncertainty in each axis) 
% 4. pointing jitter
% 5. 


High fidelity PSFs that take into account the as-built telescope OPD map and science instrument WFE figures, which vary over the field of view and can change over time due to differential thermal load.

We also wanted the process of generating, storing, and loading PSFs to be expedient and efficient.

\section{Example Simulations}

\subsection{LMC Astrometric Field}

\subsection{HR8799 Coronagraphy}

\subsection{Debris Disk Coronagraphy}


\section{Summary}

\acknowledgments

We thank some people and organizations (STScI); NASA grant and other things

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bibliography
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\clearpage


% \bibliographystyle{aasjournal}

\bibliography{refs}


\end{document}




