========
Overview
========

A JWST NIRCam ETC and Simulator
===============================

.. image:: https://img.shields.io/pypi/v/pynrc.svg
        :target: https://pypi.python.org/pypi/pynrc
        :alt: Badge showing current released PyPI version
        
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.5829553.svg
        :target: https://doi.org/10.5281/zenodo.5829553
        :alt: Zenodo DOI
   
.. image:: https://readthedocs.org/projects/pynrc/badge/?version=latest
        :target: https://pynrc.readthedocs.io/en/latest/?badge=latest
        :alt: Documentation Status

*Authors:* `Jarron Leisenring <https://github.com/JarronL>`_ 
(U. of Arizona, Steward Observatory)

*Contributors:* `Everett Schlawin <https://github.com/eas342>`_, 
`Jonathan Fraine <https://github.com/exowanderer>`_, 
`Jonathan Aguilar <https://github.com/aggle>`_

pyNRC is a set of Python-based tools for planning observations with JWST NIRCam, such as an ETC, a simple slope image simulator, and an enhanced data simulator compatible with the JWST pipeline.

While special attention has been placed on NIRCam coronagraphic modes, this package also works for a variety of NIRCam observing modes including:

- direct imaging 
- coronagraphic imaging
- weak lens imaging
- slitless grism spectroscopy
- DHS observations (TBI)

All PSFs are generated by `WebbPSF <https://webbpsf.readthedocs.io>`_ as implemented by the `WebbPSF Extensions <https://github.com/JarronL/webbpsf_ext>`_ package to reproduce realistic JWST images and spectra.

Documentation can be found at https://pynrc.readthedocs.io.

Similar to some of its dependencies, pyNRC requires input data files in order to generate simulations. Due to the size of these files, they are not included with this source distribution. Please see the documentation for instructions on how to to download the required data files.

.. warning:: 

  pyNRC enables more modes than are officially allowed by the Observatory, (ie., filter + coronagraphic combinations, subarray sizes, etc.). Just because you can do something with pyNRC does not mean it will be supported in flight. Check out `JDocs`_ for more information.


.. _JDocs: https://jwst-docs.stsci.edu/jwst-near-infrared-camera/nircam-observing-modes


Simulating PSFs
===============

Simulating PSFs with WebbPSF can become computationally expensive if generating new ones on the fly, especially considering JWST PSFs vary with respect to wavelength, field position, and time-dependent wavefront error drift. In an effort to speed up this process, pyNRC uses WebbPSF to generate a series of monochromatic PSF simulations, then produces polynomial fits to each oversampled pixel. Storing the coefficients rather than a library of PSFS allows for quick creation (via matrix multiplication) of PSF images for an arbitrary number of wavelengths (subject to hardware memory limitations, of course). The applications range from quickly creating PSFs for many different stellar types over wide bandpasses to generating a large number of monochromatic PSFs for spectral dispersion.

In addition, each science instrument PSF is dependent on the detector position due to field-dependent wavefront errors. Such changes are tracked in WebbPSF, but it becomes burdensome to generate new PSFs from scratch at each location, especially for large starfields. Instead, these changes can be stored by the fitting the residuals of the PSF coefficients across an instrument's field of view, then interpolating for an arbitrary location. A similar scheme can be achieved for coronagraphic occulters, where the PSF changes as the source position moves with respect to the mask.

JWST's thermal evolution (e.g., changing the angle of the sunshield after slewing to a new target) causes small but significant distortions to the telescope backplane. WebbPSF has tools to modify OPDs, but high-fidelity simulations take time to calculate. Since the change to the PSF coefficients varies smoothly with respect to WFE drift components, it's simple to parameterize the coefficient residuals in a fashion similar to the field-dependence.
