Skip to content

Commit

Permalink
poly deg conditions
Browse files Browse the repository at this point in the history
Fixed a bug where the default degrees for unsaved polynomial fits were
not matching those of the saved psf coefficients. Added a `quick`
keyword for that feature instead of tying it to the `save` keyword.
  • Loading branch information
JarronL committed Jan 10, 2018
1 parent 9c7e073 commit 8a3ace5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
21 changes: 14 additions & 7 deletions pynrc/nrc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def psf_coeff(filter_or_bp, pupil=None, mask=None, module='A',
fov_pix=11, oversample=None, npsf=None, ndeg=None, tel_pupil=None,
offset_r=None, offset_theta=None, jitter=None, jitter_sigma=0.007,
opd=None, wfe_drift=None, drift_file=None, include_si_wfe=True,
detector=None, detector_position=None, force=False,
detector=None, detector_position=None, force=False, quick=False,
save=True, save_name=None, return_save_name=False, **kwargs):
"""Generate PSF coefficients
Expand Down Expand Up @@ -1003,7 +1003,8 @@ def psf_coeff(filter_or_bp, pupil=None, mask=None, module='A',
produce 20 PSFs/um. The wavelength range is determined by
choosing those wavelengths where throughput is >0.001.
ndeg : int
Polynomial degree for PSF fitting. Default = 10.
Polynomial degree for PSF fitting.
Default = 10 (7 if quick=True).
offset_r : float
Radial offset from the center in arcsec.
offset_theta :float
Expand Down Expand Up @@ -1038,10 +1039,16 @@ def psf_coeff(filter_or_bp, pupil=None, mask=None, module='A',
save_name : str, None
Full path name of FITS file to save/load coefficents.
If None, then a name is automatically generated.
quick : bool
Only perform a fit over the filter bandpass with a smaller default
polynomial degree fit. Not compatible with save.
return_save_name : bool
"""

if (save and quick):
raise ValueError("Keywords `save` and `quick` cannot both be set to True.")

grism_obs = (pupil is not None) and ('GRISM' in pupil)
dhs_obs = (pupil is not None) and ('DHS' in pupil)
Expand Down Expand Up @@ -1231,14 +1238,14 @@ def psf_coeff(filter_or_bp, pupil=None, mask=None, module='A',
inst.pupilopd = opd

# By default, WebbPSF has wavelength limits depending on the channel
# We don't care about this, so set these to low/high values
# which can interfere with pynrc calculations, so set these to low/high values
inst.SHORT_WAVELENGTH_MIN = inst.LONG_WAVELENGTH_MIN = 1e-7
inst.SHORT_WAVELENGTH_MAX = inst.LONG_WAVELENGTH_MAX = 10e-6

# Select which wavelengths to use
# When saving the data, we want the full channel wavelength
# However, if doing a "quick" PSF, only fit the filter wavelength range
if save:
# If doing a "quick" PSF, only fit the filter wavelength range.
# Otherwise, we fit the full channel wavelength.
if quick:
w1,w2 = (0.5,2.5) if 'SW' in chan_str else (2.4,5.1)
else:
w1 = bp.wave.min() / 1e4
Expand Down Expand Up @@ -1311,7 +1318,7 @@ def psf_coeff(filter_or_bp, pupil=None, mask=None, module='A',
# Simultaneous polynomial fits to all pixels using linear least squares
# 7th-degree polynomial seems to do the trick
if ndeg is None:
ndeg = 10 if save else 7
ndeg = 10 if quick else 7
coeff_all = jl_poly_fit(waves, images, ndeg)

if save:
Expand Down
14 changes: 7 additions & 7 deletions pynrc/obs_nircam.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, sp_sci, sp_ref, distance, wfe_ref_drift=10, offset_list=None,
if verbose: print("Generating oversampled PSFs...")
_, psf = self.gen_psf(return_oversample=True, use_bg_psf=False)
self.psf_center_over = psf
if self.mask is not None:
if self.mask is None:
self.psf_offaxis_over = self.psf_center_over
else:
_, psf = self.gen_psf(return_oversample=True, use_bg_psf=True)
Expand Down Expand Up @@ -725,7 +725,7 @@ class (``self.nrc_ref.update_detectors()``).
-------
tuple
Three arrays in a tuple: the radius in arcsec, n-sigma contrast,
and n-sigma magnitude limit (vega mag).
and n-sigma magnitude sensitivity limit (vega mag).
"""
from astropy.convolution import convolve, Gaussian1DKernel

Expand Down Expand Up @@ -779,7 +779,7 @@ class (``self.nrc_ref.update_detectors()``).
im_mask = pad_or_cut_to_size(im_mask, data.shape)

nx = im_mask.shape[0]
xv = (np.arange(nx) - nx/2) * pixscale_over
xv = (np.arange(nx) - nx/2) * pixscale

# a and b coefficients at each offset location
avals = np.interp(rr, xv, im_mask[nx//2,:]**2)
Expand Down Expand Up @@ -1014,11 +1014,11 @@ def saturation_levels(self, full_size=True, ngroup=0, **kwargs):
If False, use fov_pix size.
ngroup : int
How many group times to determine saturation level?
If this number is higher than the total groups in ramp,
then a warning is produced.
The default is ngroup=0, which corresponds to the
so-called "zero-frame." This is the very first frame
that is read-out and saved separately. If this number
is higher than the total groups in ramp, then a
warning is produced.
so-called "zero-frame," which is the very first frame
that is read-out and saved separately.
"""

Expand Down
7 changes: 5 additions & 2 deletions pynrc/pynrc_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,9 @@ class NIRCam(object):
Save the resulting PSF coefficients to a file? (default: True)
force : bool
Forces a recalcuation of PSF even if saved PSF exists. (default: False)
quick : bool
Only perform a fit over the filter bandpass with a smaller default
polynomial degree fit. Not compatible with save.
Examples
--------
Expand Down Expand Up @@ -1472,7 +1475,7 @@ def update_psf_coeff(self, fov_pix=None, oversample=None,
Tuple (file, slice) or filename or HDUList specifying OPD.
wfe_drift : float
Wavefront error drift amplitude in nm.
Updates :attr:`wfe_drift` attribute.
Updates :attr:`wfe_drift` attribute and coefficients appropriately.
tel_pupil : str
File name or HDUList specifying telescope entrance pupil.
jitter : str or None
Expand Down Expand Up @@ -1552,7 +1555,7 @@ def update_psf_coeff(self, fov_pix=None, oversample=None,

# WFE Drift is handled differently than the rest of the parameters
# This is because we use wfed_coeff() to determine the resid values
# for the PSF coefficients to generated a drifted PSF.
# for the PSF coefficients to generate a drifted PSF.
if wfe_drift is not None:
self._wfe_drift = wfe_drift

Expand Down

0 comments on commit 8a3ace5

Please sign in to comment.