STPSF Tutorials
This article provides a basic python example on how to use STPSF . Users can find a more extensive list of tutorials and examples in the form of Python Jupyter notebooks on the Roman Research Nexus (RRN). Additional information is available from the tool's online documentation.
This documentation is written for STPSF version 2.2.0 (released in December 2025).
In addition to the examples in the RNN, the GitHub repository of STPSF offers many tutorials, including one specific to Roman, to help users get started. The foremost example is a jupyter notebook with a general demonstration of how to simulate, visualize, analyze, and export a point spread function (PSF) for the Roman Wide Field Instrument (WFI). To run the tutorials on your system, please follow the installation instructions from the readthedocs documentation.
The readthedocs dedicated page on the Roman Instrument Model also contains several more detailed examples alongside narrative text explaining how all of the functionality comes together. Readers with previous experience using the JWST modes of STPSF should note the differences highlighted for Roman simulations.
Warning
While the GitHub repository for STPSF also offers a jupyter notebook that demonstrates usage of its class for the Roman Coronagraph Instrument, we warn the reader that the STPSF Coronagraph model was developed as a prototype and has not been actively updated or developed since 2017.
Below is an example of visualizing the PSF with default parameters. This is one of many STPSF examples that are in Roman Research Nexus (RRN). In the dedicated STPSF notebook, users will find:
- Quick PSF Generation: use the
.calc_psf()method to compute a WFI PSF using mostly default settings. - PSF Profile and Encircled Energy: for a given PSF, measure its profile, FWHM, and encircled energy.
- Bulk PSF Generation: generate several individual PSFs in a grid.
Example: PSF with Default Parameters
First, we import the relevant packages:
import stpsf import matplotlib.pyplot as plt plt.rcParams['image.interpolation'] = 'nearest' # Don't blur/smooth image plots wfi = stpsf.roman.WFI() default_psf = wfi.calc_psf(display=True) plt.show()
Importing the stpsf package in python might produce a warning message related to mismatches related to JWST PRD version numbers. Roman users are safe to ignore it.
We can then calculate the default PSF, which is applicable to the F062 optical element. Since we will use the built-in function to plot the results, first we setup a few matplotlib parameters:
plt.rcParams['figure.figsize'] = (8, 10) # Make the default figure size larger plt.rcParams['image.interpolation'] = 'nearest' wfi = stpsf.roman.WFI() # Use Roman models default_psf = wfi.calc_psf(display=True) plt.show()
Which will then show:
Figure of WFI F062 PSF from STPSF
STPSF for Roman: example of PSF with default parameters for the optical element F062. The four panels show the PSF phase at two different positions along the optical path (entrance and exit pupils), the field-dependent aberration for detector WFI01, and the PSF itself as seen right before it hits the detector.
Finally, we can display the simulated PSF in detector pixels and save it in FITS format using the following:
plt.rcParams['figure.figsize'] = (8, 6) # Make the default figure size larger
stpsf.display_psf(default_psf, ext='DET_SAMP')
plt.show()
default_psf.writeto('./test_PSF.fits', overwrite=True)
The previous code block displays the figure below.
Figure of WFI F062 PSF in detector pixels
STPSF for Roman: Displaying the WFI01 F062 PSF in detector pixel space. Axes are in units of arcsec. Pixels are color coded according to the intensity color bar on the right.
References
- STPSF on readthedocs : https://stpsf.readthedocs.io/en/latest/
- Roman Research Nexus: https://roman.science.stsci.edu/hub/
- STPSF on Github: https://github.com/spacetelescope/stpsf
For additional questions not answered in this article, please contact the Roman Help Desk. You may also open an issue at the GitHub repository.


