Skip to content

Commit

Permalink
Merge pull request #1870 from pypeit/spatflex_improve
Browse files Browse the repository at this point in the history
Improvement to spatial flexure
  • Loading branch information
debora-pe authored Dec 20, 2024
2 parents 016fc30 + 3e5a48e commit eb54214
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 64 deletions.
28 changes: 28 additions & 0 deletions doc/calibrations/flexure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ of :ref:`processimagespar`.
We have made our own determinations for which instruments to enable this as the
default. Inspect the :ref:`instr_par` list to see if your instrument is included
(search for the value of ``spat_flexure_correct``).
A QA plot is generated for each frame for which the spatial flexure correction
is applied. We recommend the user to inspect these plots to ensure the flexure
correction is reasonable. See :ref:`qa-spat-flex` for more information.

Depending on what frame types you choose to correct, the
code will behave somewhat differently. Here we describe
Expand Down Expand Up @@ -315,4 +318,29 @@ HDU Name HDU Type Data Type Description
``FLEXURE`` `astropy.io.fits.BinTableHDU`_ ... All data from the :class:`~pypeit.core.flexure.MultiSlitFlexure` datamodel
===================== ============================== ========= ==========================================================================

Inspecting
==========

PypeIt provides the ``pypeit_chk_flexure`` script to inspect both the
spatial and spectral flexure corrections.

The script usage can be displayed by calling the script with the
``-h`` option:

.. include:: ../help/pypeit_chk_flexure.rst

The script takes as input one or multiple `spec2d*.fits` or `spec1d*.fits` files
and print to screen the flexure correction applied to each file.

Here is a typical call to print the spatial flexure correction:

.. code-block:: console
pypeit_chk_flexure Science/spec2d_r230417_01033-frb22022_LRISr_20230417T082242.672.fits --spat
and to print the spectral flexure correction:

.. code-block:: console
pypeit_chk_flexure Science/spec1d_r230417_01033-frb22022_LRISr_20230417T082242.672.fits --spec
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 21 additions & 3 deletions doc/qa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,26 @@ Exposure QA
For each processed, science exposure there are a series of
PNGs generated, per detector and (sometimes) per slit.

.. _qa-spat-flex:

Flexure QA
----------
Spatial Flexure QA
------------------

If a flexure correction was performed (default), the fit to the
If a spatial flexure correction was performed, the result of the correction
is shown in a plot like the one below. The plot shows a few snippets of the
science/standard spectral image with overlaid the slit edges as traced in the
``trace`` image (dashed lines) and after applying the spatial flexure correction
(solid lines). The value of the shift is also reported on the top of the plot.

.. figure:: figures/r230417_01033_DET01_spat_flex_corr.png
:align: center

.. _qa-spec-flex:

Spectral Flexure QA
-------------------

If a spectral flexure correction was performed (default), the fit to the
correlation lags per object
is shown and the adopted shift is listed. Here is
an example:
Expand All @@ -133,3 +148,6 @@ Here is an example:
.. figure:: figures/qa/flex_sky_armlsd.jpg
:align: center




5 changes: 5 additions & 0 deletions doc/releases/1.17.2dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Functionality/Performance Improvements and Additions
- The WCS for datacubes now adopts the convention of North
is up and East is left. In previous version of PypeIt,
East was right.
- Improved the code to compute the spatial flexure correction and added a QA
plot to inspect the results. Two new parset parameters, `spat_flexure_sigdetect`
and `spat_flexure_vrange`, were added to control the detection of the slit edges
(used to compute the flexure) and the stretching of the image in the QA plot,
respectively.

Instrument-specific Updates
---------------------------
Expand Down
24 changes: 24 additions & 0 deletions doc/scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,30 @@ The script usage can be displayed by calling the script with the

.. include:: help/pypeit_show_pixflat.rst

.. _pypeit_chk_flexure:

pypeit_chk_flexure
--------------------

This script takes as input one or multiple `spec2d*.fits` or `spec1d*.fits` files
and print to screen the spatial or spectral flexure correction applied to each file.
Standard command-line calls are:

.. code-block:: console
pypeit_chk_flexure Science/spec2d_r230417_01033-frb22022_LRISr_20230417T082242.672.fits --spat
or:

.. code-block:: console
pypeit_chk_flexure Science/spec1d_r230417_01033-frb22022_LRISr_20230417T082242.672.fits --spec
The script usage can be displayed by calling the script with the
``-h`` option:

.. include:: help/pypeit_chk_flexure.rst

pypeit_show_2dspec
------------------

Expand Down
7 changes: 4 additions & 3 deletions pypeit/core/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,10 @@ def detect_lines(censpec, sigdetect=5.0, fwhm=4.0, fit_frac_fwhm=1.25, input_thr
(mean, med, stddev) = stats.sigma_clipped_stats(arc[cont_mask & np.logical_not(bpm_out)],
sigma_lower=3.0, sigma_upper=3.0, cenfunc= np.nanmedian,
stdfunc = np.nanstd)
thresh = med + sigdetect*stddev
if stddev == 0.0:
msgs.warn('stddev = 0.0, so resetting to 1.0')
stddev = 1.0
msgs.warn('stddev = 0.0, so resetting to 0.1')
stddev = 0.1
thresh = med + sigdetect * stddev
else:
med = 0.0
if isinstance(input_thresh,(float, int)):
Expand Down Expand Up @@ -1055,6 +1055,7 @@ def detect_lines(censpec, sigdetect=5.0, fwhm=4.0, fit_frac_fwhm=1.25, input_thr
tampl_true = tampl_true[ikeep]
tampl = tampl[ikeep]
tcent = tcent[ikeep]
pixt = pixt[ikeep]
twid = twid[ikeep]
centerr = centerr[ikeep]
ww = np.where(good[ikeep])[0]
Expand Down
Loading

0 comments on commit eb54214

Please sign in to comment.