From 25a0737a16a77e4a25405fc821ebfe0f9812135a Mon Sep 17 00:00:00 2001 From: rcooke Date: Fri, 20 Sep 2024 19:49:01 +0100 Subject: [PATCH] PR cleanup --- pypeit/core/flexure.py | 4 ++-- pypeit/core/tracewave.py | 39 +++++++----------------------------- pypeit/flatfield.py | 6 ++++-- pypeit/images/pypeitimage.py | 2 +- pypeit/images/rawimage.py | 3 --- pypeit/wavetilts.py | 6 ++---- 6 files changed, 16 insertions(+), 44 deletions(-) diff --git a/pypeit/core/flexure.py b/pypeit/core/flexure.py index 600577de39..6e6c23a8e7 100644 --- a/pypeit/core/flexure.py +++ b/pypeit/core/flexure.py @@ -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 diff --git a/pypeit/core/tracewave.py b/pypeit/core/tracewave.py index 2c8f7c6f8f..e6e0ad325c 100644 --- a/pypeit/core/tracewave.py +++ b/pypeit/core/tracewave.py @@ -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`_ @@ -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') @@ -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. @@ -922,22 +922,14 @@ 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: @@ -945,25 +937,8 @@ def fit2tilts(shape, coeff2, func2d, spec_eval=None, spat_eval=None, spat_shift= 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) diff --git a/pypeit/flatfield.py b/pypeit/flatfield.py index dc0edfb4e1..0113506b58 100644 --- a/pypeit/flatfield.py +++ b/pypeit/flatfield.py @@ -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) diff --git a/pypeit/images/pypeitimage.py b/pypeit/images/pypeitimage.py index 6a62901c3c..a39e951552 100644 --- a/pypeit/images/pypeitimage.py +++ b/pypeit/images/pypeitimage.py @@ -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'), diff --git a/pypeit/images/rawimage.py b/pypeit/images/rawimage.py index 6d6dc20e3b..37c1a4ab25 100644 --- a/pypeit/images/rawimage.py +++ b/pypeit/images/rawimage.py @@ -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) diff --git a/pypeit/wavetilts.py b/pypeit/wavetilts.py index 47dd6f0886..818f5cef72 100644 --- a/pypeit/wavetilts.py +++ b/pypeit/wavetilts.py @@ -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, @@ -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)