From 20c136e1ad801d32348b6c22178f0df9ab684069 Mon Sep 17 00:00:00 2001 From: Marshall Perrin Date: Tue, 10 Dec 2024 00:50:32 -0500 Subject: [PATCH] add outfile option to calc_datacube. Fixes https://github.com/spacetelescope/webbpsf/issues/929 --- poppy/instrument.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/poppy/instrument.py b/poppy/instrument.py index fbfeac4f..c1b38c7a 100644 --- a/poppy/instrument.py +++ b/poppy/instrument.py @@ -298,7 +298,7 @@ def calc_psf(self, outfile=None, source=None, nlambda=None, monochromatic=None, else: return result - def calc_datacube(self, wavelengths, progressbar=False, *args, **kwargs): + def calc_datacube(self, wavelengths, progressbar=False, outfile=None, overwrite=True, *args, **kwargs): """Calculate a spectral datacube of PSFs Parameters @@ -311,7 +311,12 @@ def calc_datacube(self, wavelengths, progressbar=False, *args, **kwargs): while iterating over wavelengths. Note, this requires the optional dependency package 'tqdm', which is not included as a requirement. + outfile : string + Filename to write. If None, then result is returned as an HDUList + overwrite : bool + overwrite output FITS file if it already exists? + Additional parameters are passed through to calc_datacube """ # Allow up to 10,000 wavelength slices. The number matters because FITS @@ -355,6 +360,11 @@ def wavelength_as_meters(wavelength): cube[ext].header.add_history(h) cube[0].header['NWAVES'] = nwavelengths + if outfile is not None: + cube[0].header["FILENAME"] = (os.path.basename(outfile), "Name of this file") + cube.writeto(outfile, overwrite=overwrite) + poppy_core._log.info("Saved result to " + outfile) + return cube def _calc_psf_format_output(self, result, options):