Skip to content

Commit

Permalink
PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rcooke-ast committed Sep 20, 2024
1 parent e4f42d1 commit 25a0737
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 44 deletions.
4 changes: 2 additions & 2 deletions pypeit/core/flexure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,11 +1425,11 @@ def flexure_diagnostic(file, file_type='spec2d', flexure_type='spec', chk_versio
failed. If False, throw a warning only. Default is False.
Returns:
:obj:`astropy.table.Table`, :obj:`float`, None: If file_type is 'spec2d' and
:obj:`astropy.table.Table`, :obj:`float`: If file_type is 'spec2d' and
flexure_type is 'spec', return a table with the spectral flexure. If
file_type is 'spec2d' and flexure_type is 'spat', return the spatial
flexure. If file_type is 'spec1d', return a table with the spectral
flexure.
flexure. If the file_type is neither 'spec2d' nor 'spec1d', return None.
"""

# value to return
Expand Down
39 changes: 7 additions & 32 deletions pypeit/core/tracewave.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,12 @@ def fit_tilts(trc_tilt_dict, thismask, slit_cen, spat_order=3, spec_order=4, max
# msgs.info("RMS/FWHM: {}".format(rms_real/fwhm))


def fit2tilts_prepareSlit(img_shape, slit_left, slit_right, thismask_science, spat_flexure=None):
def fit2tilts_prepareSlit(slit_left, slit_right, thismask_science, spat_flexure=None):
"""
Prepare the slit for the fit2tilts function
Parameters
----------
img_shape : :obj:`tuple`
Shape of the science image
slit_left : `numpy.ndarray`_
Left slit edge
slit_right : `numpy.ndarray`_
Expand All @@ -876,6 +874,8 @@ def fit2tilts_prepareSlit(img_shape, slit_left, slit_right, thismask_science, sp
Tuple containing the spectral and spatial coordinates of the slit, including spatial flexure.
These variables are to be used in the fit2tilts function.
"""
# Get the image shape
img_shape = thismask_science.shape
# Check the spatial flexure input
if spat_flexure is not None and len(spat_flexure) != 2:
msgs.error('Spatial flexure must be a two element array')
Expand All @@ -900,7 +900,7 @@ def fit2tilts_prepareSlit(img_shape, slit_left, slit_right, thismask_science, sp
return _spec_eval, _spat_eval


def fit2tilts(shape, coeff2, func2d, spec_eval=None, spat_eval=None, spat_shift=None):
def fit2tilts(shape, coeff2, func2d, spec_eval=None, spat_eval=None):
"""
Evaluate the wavelength tilt model over the full image.
Expand All @@ -922,48 +922,23 @@ def fit2tilts(shape, coeff2, func2d, spec_eval=None, spat_eval=None, spat_shift=
spec_eval : `numpy.ndarray`_, optional
1D array indicating how spectral pixel locations move across the
image. If spec_eval is provided, spat_eval must also be provided.
spat_shift : float, `numpy.ndarray`_, optional
Spatial shift to be added to image pixels before evaluation
If you are accounting for flexure, then you probably wish to
input -1*flexure_shift into this parameter. Note that this
should either be a float or a 1D array with two elements
(and both of these elements must be equal).
Returns
-------
tilts : `numpy.ndarray`_, float
Image indicating how spectral pixel locations move across the image.
"""
# Determine which mode to run this function
# Determine if coordinates have been supplied that include the spatial flexure.
if spec_eval is not None and spat_eval is not None:
if spat_shift is not None:
msgs.warn('spat_shift is ignored when spec_eval and spat_eval are provided.')
_spec_eval = spec_eval
_spat_eval = spat_eval
else:
# Print a warning just in case only one was provided
if (spec_eval is None and spat_eval is not None) or (spec_eval is not None and spat_eval is None):
msgs.warn('Both spec_eval and spat_eval must be provided.' + msgs.newline() +
'Only one variable provided, so a new (full) grid will be generated.')
# Check the flexure
if spat_shift is None:
_spat_shift = 0.
elif isinstance(spat_shift, (int, float)):
_spat_shift = spat_shift
elif isinstance(spat_shift, np.ndarray):
if spat_shift.size != 2:
msgs.error('spat_shift must be a 2-element array.')
elif spat_shift[0] != spat_shift[1]:
msgs.error('The two elements of spat_shift must be equal.' + msgs.newline() +
'To include different spatial shifts at the two ends of the slit, ' + msgs.newline() +
'you must provide the variables spec_eval and spat_eval instead of spat_shift.')
else:
_spat_shift = spat_shift[0]
else:
msgs.error('spat_shift must be either None, a float, or a 1D array with two identical elements.' + msgs.newline() +
'To include different spatial shifts at the two ends of the slit, ' + msgs.newline() +
'you must provide the variables spec_eval and spat_eval instead of spat_shift.')

msgs.warn("Assuming no spatial flexure.")
_spat_shift = 0.0
# Setup the evaluation grid
nspec, nspat = shape
xnspecmin1 = float(nspec - 1)
Expand Down
6 changes: 4 additions & 2 deletions pypeit/flatfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,12 @@ def fit(self, spat_illum_only=False, doqa=True, debug=False):
if self.slitless:
tilts = np.tile(np.arange(rawflat.shape[0]) / (rawflat.shape[0]-1), (rawflat.shape[1], 1)).T
else:
# TODO -- JFH Confirm the sign of this shift is correct!
_flexure = np.zeros(2) if self.wavetilts.spat_flexure is None else self.wavetilts.spat_flexure[slit_idx,:]
_spec_eval, _spat_eval = tracewave.fit2tilts_prepareSlit(self.slits.left_init[:, slit_idx],
self.slits.right_init[:, slit_idx],
onslit_init, _flexure)
tilts = tracewave.fit2tilts(rawflat.shape, self.wavetilts['coeffs'][:,:,slit_idx],
self.wavetilts['func2d'], spat_shift=-1*_flexure)
self.wavetilts['func2d'], spec_eval=_spec_eval, spat_eval=_spat_eval)
# Convert the tilt image to an image with the spectral pixel index
spec_coo = tilts * (nspec-1)

Expand Down
2 changes: 1 addition & 1 deletion pypeit/images/pypeitimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PypeItImage(datamodel.DataContainer):
# TODO These docs are confusing. The __init__ method needs to be documented just as it is for
# every other class that we have written in PypeIt, i.e. the arguments all need to be documented. They are not
# documented here and instead we have the odd Args documentation above.
version = '1.3.0'
version = '1.3.1'
"""Datamodel version number"""

datamodel = {'PYP_SPEC': dict(otype=str, descr='PypeIt spectrograph name'),
Expand Down
3 changes: 0 additions & 3 deletions pypeit/images/rawimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,6 @@ def process(self, par, bpm=None, scattlight=None, flatimages=None, bias=None, sl
maxlag=self.par['spat_flexure_maxlag']) \
if self.par['spat_flexure_correct'] != "none" else None

# self.spat_flexure_shift = self.spatial_flexure_shift(slits, maxlag=self.par['spat_flexure_maxlag']) \
# if self.par['spat_flexure_correct'] else None

# - Subtract scattered light... this needs to be done before flatfielding.
if self.par['subtract_scattlight']:
self.subtract_scattlight(scattlight, slits)
Expand Down
6 changes: 2 additions & 4 deletions pypeit/wavetilts.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ def fit2tiltimg(self, slitmask, slits_left, slits_right, spat_flexure=None):
coeff_out = self.coeffs[:self.spec_order[slit_idx]+1, :self.spat_order[slit_idx]+1, slit_idx]
# Extract the spectral and spatial coordinates for this slit
thismask_science = (slitmask == slit_spat)
_spec_eval, _spat_eval = tracewave.fit2tilts_prepareSlit(slitmask.shape,
slits_left[:, slit_idx], slits_right[:, slit_idx],
_spec_eval, _spat_eval = tracewave.fit2tilts_prepareSlit(slits_left[:, slit_idx], slits_right[:, slit_idx],
thismask_science, _spat_flexure[slit_idx, :])
# Calculate the tilts
final_tilts[thismask_science] = tracewave.fit2tilts(final_tilts.shape, coeff_out, self.func2d,
Expand Down Expand Up @@ -796,8 +795,7 @@ def run(self, doqa=True, debug=False, show=False):
# which corresonds to the same binning as the science
# images, trace images, and pixelflats etc.
thismask_science = self.slitmask_science == slit_spat
_spec_eval, _spat_eval = tracewave.fit2tilts_prepareSlit(self.slitmask_science.shape,
slits_left[:, slit_idx], slits_right[:, slit_idx],
_spec_eval, _spat_eval = tracewave.fit2tilts_prepareSlit(slits_left[:, slit_idx], slits_right[:, slit_idx],
thismask_science, self.spat_flexure[slit_idx, :])
self.final_tilts[thismask_science] = tracewave.fit2tilts(self.slitmask_science.shape, coeff_out, self.par['func2d'],
spec_eval=_spec_eval, spat_eval=_spat_eval)
Expand Down

0 comments on commit 25a0737

Please sign in to comment.