From d4252a113272988133b4c17c846ed0f01b6c198f Mon Sep 17 00:00:00 2001 From: Marshall Perrin Date: Mon, 8 Jul 2024 15:36:34 -0400 Subject: [PATCH 1/2] more strict units handling; fixes some issues for astropy 6.0.0 compatibility --- webbpsf/webbpsf_core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webbpsf/webbpsf_core.py b/webbpsf/webbpsf_core.py index ed536cd2..c70dd901 100644 --- a/webbpsf/webbpsf_core.py +++ b/webbpsf/webbpsf_core.py @@ -1869,7 +1869,7 @@ def calc_datacube_fast(self, wavelengths, compare_methods=False, outfile=None, # Set up cube and initialize structure based on PSF at a representative wavelength _log.info('Starting fast/simplified multiwavelength data cube calculation.') ref_wave = np.mean(wavelengths) - MIN_REF_WAVE = 2e-6 # This must not be too short, to avoid phase wrapping for the C3 bump + MIN_REF_WAVE = 2e-6 * units.meter # This must not be too short, to avoid phase wrapping for the C3 bump if ref_wave < MIN_REF_WAVE: ref_wave = MIN_REF_WAVE log_message = ( @@ -1897,7 +1897,7 @@ def calc_datacube_fast(self, wavelengths, compare_methods=False, outfile=None, ext = 0 cubefast[ext].data = np.zeros((nwavelengths, psf[ext].data.shape[0], psf[ext].data.shape[1])) cubefast[ext].data[0] = psf[ext].data - cubefast[ext].header[label_wavelength(nwavelengths, 0)] = wavelengths[0] + cubefast[ext].header[label_wavelength(nwavelengths, 0)] = wavelengths[0].to_value(units.meter) # Fast way. Assumes wavelength-independent phase and amplitude at the exit pupil!! if compare_methods: @@ -1928,7 +1928,7 @@ def calc_datacube_fast(self, wavelengths, compare_methods=False, outfile=None, wl = wavelengths[i] psfw = quickosys.calc_psf(wavelength=wl, normalize='None') cubefast[0].data[i] = psfw[0].data - cubefast[ext].header[label_wavelength(nwavelengths, i)] = wavelengths[i] + cubefast[ext].header[label_wavelength(nwavelengths, i)] = wavelengths[i].to_value(units.meter) cubefast[0].header['NWAVES'] = nwavelengths From 15f5374786256415b53a5a3b6ab51ca43808064c Mon Sep 17 00:00:00 2001 From: Marshall Perrin Date: Mon, 8 Jul 2024 16:09:29 -0400 Subject: [PATCH 2/2] some additional units handling --- webbpsf/webbpsf_core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webbpsf/webbpsf_core.py b/webbpsf/webbpsf_core.py index c70dd901..292f6f1c 100644 --- a/webbpsf/webbpsf_core.py +++ b/webbpsf/webbpsf_core.py @@ -1813,6 +1813,7 @@ def load_wss_opd_by_date(self, date=None, choice='closest', verbose=True, plot=F opd_fn = webbpsf.mast_wss.get_opd_at_time(date, verbose=verbose, choice=choice, **kwargs) self.load_wss_opd(opd_fn, verbose=verbose, plot=plot, **kwargs) + @poppy.utils.quantity_input(wavelengths=units.meter) def calc_datacube_fast(self, wavelengths, compare_methods=False, outfile=None, add_distortion=True, *args, **kwargs): """Calculate a spectral datacube of PSFs: Simplified, much MUCH faster version. @@ -1945,7 +1946,7 @@ def calc_datacube_fast(self, wavelengths, compare_methods=False, outfile=None, for ext in range(len(psf)): cube[ext].data = np.zeros((nwavelengths, psf[ext].data.shape[0], psf[ext].data.shape[1])) cube[ext].data[0] = psf[ext].data - cube[ext].header[label_wavelength(nwavelengths, 0)] = wavelengths[0] + cube[ext].header[label_wavelength(nwavelengths, 0)] = wavelengths[0].to_value(units.meter) # iterate rest of wavelengths print('Running standard way') @@ -1954,7 +1955,7 @@ def calc_datacube_fast(self, wavelengths, compare_methods=False, outfile=None, psf = self.calc_psf(*args, monochromatic=wl, **kwargs) for ext in range(len(psf)): cube[ext].data[i] = psf[ext].data - cube[ext].header[label_wavelength(nwavelengths, i)] = wl + cube[ext].header[label_wavelength(nwavelengths, i)] = wl.to_value(units.meter) cube[ext].header.add_history('--- Cube Plane {} ---'.format(i)) for h in psf[ext].header['HISTORY']: cube[ext].header.add_history(h)