NIRSpec MSA Spectral Visualization Tool Help
The JWST MSA Spectral Visualization Tool (MSAViz) allows the user to visualize the layout of MOS spectra on the NIRSpec detectors, given a particular filter, disperser, and MSA shutter configuration (exported from APT). This allows the user to check for shutters whose spectra may fall in or near the detector gap during observations.
A proposal for multi-object spectroscopy (MOS) observations with NIRSpec will be planned to observe a particular wavelength region of interest, depending on the science case of the proposal. A user who designs such an observation with the Astronomers Proposal Tool (APT) and the MSA Planning Tool (MPT) may want to identify the wavelengths that will be obtained from spectra observed with a particular MSA configuration. This could be useful to determine whether a wavelength region or line of interest is likely to be included in the spectra for the associated targets, or if the region instead falls in the detector gap (or beyond the bounds of the detector entirely) for one or more targets.
The NIRSpec MSA Spectral Visualization Tool was created to visualize wavelengths in NIRSpec MOS configurations to permit sanity checks of spectral positions prior to committing a given configuration to be observed. The NIRSpec instrument model (calibrated from ground-test data) is used in the data processing pipeline to establish a world coordinate system (WCS) solution that assigns a wavelength to each pixel on both detectors. The wavelength calibration for each MOS spectrum in open NIRSpec MSA shutters can be accurately estimated using a parameterized prediction algorithm which streamlines these pixel-to-pixel WCS calculations.
Each spectrum acquired in NIRSpec Multi-Object Spectroscopy mode using the NIRSpec MSA can have different wavelength ranges and effects of detector gaps, depending on which MSA shutter is open. The MSA Spectral Visualization Tool described here was created to view the wavelength ranges for each open shutter in a planned MSA configuration.
Installation with Anaconda and pip
These instructions have been tested and vetted on Mac computers, but not on Windows OS or other operating platforms.
These instructions assume that Anaconda has been successfully installed. It is strongly recommended to use MSAViz in conjunction with the Anaconda Python distribution, which greatly simplifies the installation.
Step 1. Create a new conda environment.
You can specify a particular python version when creating the conda environment with
python=3 or something similar; otherwise, it will default to the python version of your Anaconda distribution.
If you prefer to use msaviz in an existing conda environmen, feel free to do so. Just skip the
conda create line, and then
$ source activate <your_environment> instead of
$ source activate msaviz. However, make sure that your environment has sufficiently-new versions of the dependent packages.
Step 2. Install Kivy and its dependencies.
To install the Kivy dependencies, you will need to have the Homebrew package manager installed. If you are trying to install this on a Mac owned by STScI, you will likely run into problems when attempting to install Homebrew. For this reason we provide the the script
install_homebrew.sh to handle this task. Once you run the script, and follow the instructions at the end, simply do
$ brew_activate in advance any time you activate your conda environment.
Step 3. Install MSAViz.The package is currently only hosted on the PyPI test server, so for the moment, use this command instead:
To begin using MSAViz, start the conda environment (if on an STScI Mac, activate Homebrew before the environment; see above) and run the package:
Export an MSA configuration file from APT
In terms of the proposal creation workflow, the use of MSAViz occurs once the MSA Planning Tool (MPT) has generated plans for a given observation. To export an MSA configuration file that can be parsed by MSAViz, follow these steps:
1. Open the JWST proposal with APT, and navigate to the specific observation in the proposal's hierarchical menu. Press on the arrow next to the desired MSA plan, which will open the MPT as shown in Figure 1.
Only configuration files exported from APT should be used in MSAViz. However, users can edit an existing configuration file using the Manual Mode in APT before exporting it.
File Select Screen
When the interface has opened (Figure 4), complete the following steps on the file select screen:
- Choose a working directory (the included
test/directory is the default).
- Select a filter & grating combination using the dropdown menu.
- Choose an MSA configuration file which has been exported from APT.
Parseand wait while the MSA config file is parsed and the wavelengths are calculated.
- The Display spectra from stuck-open shutters checkbox will toggle whether or not spectra from stuck-open shutters will be included in the visualization.
- Once this is complete, press Show the Spectrum Display! to view the visualization.
Spectrum view screen
On the spectrum view screen (Figure 5), the spectrum from each shutter is displayed on a representation of the two detectors. A colorbar at the bottom of the screen shows the displayed wavelengths. To zoom & pan the display, simulate a multi-touch with a right-click (which will leave a small red dot on the screen, which is the focus point for zooming), then click and drag to increase or decrease zoom. After zooming in, click and drag to pan in any direction. You can zoom back out with the same method as zooming in.
Check Wavelength to open the associated dialog (see below).
Export... and choose a filename to export an ascii table showing the open shutters and their wavelength bounds on each detector (including the predicted lost wavelengths due to the detector gap).
Save... and choose a filename to export a PNG image of the spectrum display. This function does not work when the display is zoomed.
Shutters... to move to the shutter view Screen (see below), or
Back to return to the file select Screen.
Check wavelength dialog
On the Check Wavelength dialog (Figure 6), you can identify where a particular wavelength or set of wavelengths will likely fall with respect to the two detectors, for all open shutters at once. Enter a wavelength in the text box and press
Submit to add that wavelength to the list.
Once at least one wavelength has been entered, a scrollable table will appear below, showing the list of open shutter coordinates, and where each wavelength will likely fall for each shutter. This will also warn if a particular wavelength will fall near the edge of one of the two detectors for a given shutter, since that wavelength may fall off of that detector during the actual observation.
Save to File and select a filename and path to save the table of wavelengths to a file. Click
Done to go back to the spectrum view screen.
Shutter view screen
On the shutter view screen (Figure 7), a map of the four MSA quadrants is shown, indicating all closed (black), open (orange), inactive (grey), and stuck open (red) shutters. You can zoom & pan this display in the same way as the spectrum view screen.
Click on any open shutter to select or deselect it; selected shutters turn cyan, and cause the corresponding spectrum on the spectrum view screen to be highlighted. Note that the individual shutters in an MSA slitlet must be selected individually if you want to highlight all of the associated spectra.
Find... to enter a set of shutter coordinates (with the option to select from a dropdown of all shutters which are currently selected shutters), and then automatically zoom and pan to center on the chosen shutter.
Save... and choose a filename to export a PNG image of the shutter display. This function does not work when the display is zoomed. Click
Back to return to the spectrum view screen.
The MSAViz package exposes two classes and three functions, which may be used from the python command line, or from other python scripts. They can be imported like so:
MSA class is the low-level construct used to calculate pixel-to-wavelength mappings for a given filter+disperser combination. This class will generally not be used, and is included for completeness; see the module documentation for details on its invocation and use.
MSAConfig class includes methods to parse an MSA config file, and calculate wavelengths and useful statistics based on the open shutters for that configuration. Instantiate with paired filter and disperser name strings, as well as the path to an MSA config file (a .csv file exported from APT). The filter & disperser can be changed with
MSAConfig.update_instrument(), and the config file can be changed with
MSAConfig.wavelength()method accepts one or more Quadrant, Row, and Column coordinates, and returns a numpy array of wavelength values at each pixel on each detector. Note that these are 0-based indexing, so you must subtract 1 from the usual coordinates and NRS number.
MSAConfig.wavelength_tableproperty returns an
astropy.table.QTableinstance containing the wavelength ranges for each shutter on each detector.
MSAConfig.write_wavelength_table()method writes the above table to an ascii file.
MSAConfig.verify_wavelength()method accepts one or more target wavelengths, and returns a table of flags for each shutter indicating the location of the target wavelengths with respect to the detectors.
MSAConfigclass isn't required, the
calculate_wavelengthsfunction accepts a
dispname, and returns the wavelength table as described above, and optionally writes the table to a given file.
check_wavelengths function accepts a list of target wavelengths, as well as a
dispname, and uses
MSAConfig.verify_wavelength to return (and optionally write to a given file) a table of wavelength flags for each open shutter
parse_msa_config is a utility function which parses an MSA config file and returns a dictionary of shutter coordinates and status. By default, only open and stuck open shutters are included, and the status is a boolean value (True if the shutter is stuck open, False if it is simply open); however, by setting
open_only=False, the function returns a dictionary of every shutter in the MSA, and the status is a single-character code ('x' is inactive, 's' is stuck open, '1' is open, and '0' is closed).