Skip to content

Commit

Permalink
Merge branch 'develop' into slitless_flats
Browse files Browse the repository at this point in the history
  • Loading branch information
kbwestfall committed Aug 29, 2024
2 parents 5d653a1 + f864562 commit ead8ddb
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 99 deletions.
16 changes: 16 additions & 0 deletions doc/releases/1.16.1dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ Instrument-specific Updates

- Improved LRIS frame typing, including the typing of slitless flats and sky flats.
- Improved HIRES frame typing and configuration setup.
- Updated X-Shooter detector gain and read noise to come from header, and
updated plate scales to the most recent values from the manual. Detailed
changes are:
- NIR arm:
- Platescale updated from 0.197 to 0.245 arcsec/pixel
- Dark current updated from 0. to 72. e-/pixel/hr
- Gain updated from 2.12 to 2.29 e-/DN
- VIS arm:
- Platescale updated from an order-dependent value, to being 0.154
arcsec/pixel for all orders
- UVB arm:
- Platescale updated from an order-dependent value, to being 0.164
arcsec/pixel for all orders


Script Changes
--------------
Expand All @@ -57,6 +71,8 @@ Script Changes
function (before only optimal extraction was used).
- Added ``pypeit_show_pixflat`` script to inspect the (slitless) pixel flat
generated during the reduction and stored in ``data/pixelflats``.
- Added ``pypeit_chk_flexure`` script to check both spatial and spectral flexure applied to
the reduced data.

Datamodel Changes
-----------------
Expand Down
1 change: 1 addition & 0 deletions pypeit/core/findobj_skymask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ def ech_objfind(image, ivar, slitmask, slit_left, slit_righ, slit_spat_id, order
det=det,
inmask=inmask,
std_trace=std_trace,
ncoeff=ncoeff,
specobj_dict=specobj_dict,
snr_thresh=snr_thresh,
show_peaks=show_peaks,
Expand Down
77 changes: 76 additions & 1 deletion pypeit/core/flexure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from astropy import stats
from astropy import units
from astropy.io import ascii
from astropy.table import Table
import scipy.signal
import scipy.optimize as opt
from scipy import interpolate
Expand All @@ -36,7 +37,7 @@
from pypeit.datamodel import DataContainer
from pypeit.images.detector_container import DetectorContainer
from pypeit.images.mosaic import Mosaic
from pypeit import specobj, specobjs
from pypeit import specobj, specobjs, spec2dobj
from pypeit import wavemodel

from IPython import embed
Expand Down Expand Up @@ -1394,6 +1395,80 @@ def sky_em_residuals(wave:np.ndarray, flux:np.ndarray,
return dwave[m], diff[m], diff_err[m], los[m], los_err[m]


def flexure_diagnostic(file, file_type='spec2d', flexure_type='spec', chk_version=False):
"""
Print the spectral or spatial flexure of a spec2d or spec1d file
Args:
file (:obj:`str`, `Path`_):
Filename of the spec2d or spec1d file to check
file_type (:obj:`str`, optional):
Type of the file to check. Options are 'spec2d' or 'spec1d'. Default is 'spec2d'.
flexure_type (:obj:`str`, optional):
Type of flexure to check. Options are 'spec' or 'spat'. Default is 'spec'.
chk_version (:obj:`bool`, optional):
If True, raise an error if the datamodel version or type check failed.
If False, throw a warning only. Default is False.
Returns:
:obj:`astropy.table.Table` or :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
"""

# value to return
return_flex = None

if file_type == 'spec2d':
# load the spec2d file
allspec2D = spec2dobj.AllSpec2DObj.from_fits(file, chk_version=chk_version)
# Loop on Detectors
for det in allspec2D.detectors:
print('')
print('=' * 50 + f'{det:^7}' + '=' * 51)
# get and print the spectral flexure
if flexure_type == 'spec':
spec_flex = allspec2D[det].sci_spec_flexure
spec_flex.rename_column('sci_spec_flexure', 'global_spec_shift')
if np.all(spec_flex['global_spec_shift'] != None):
spec_flex['global_spec_shift'].format = '0.3f'
# print the table
spec_flex.pprint_all()
# return the table
return_flex = spec_flex
# get and print the spatial flexure
if flexure_type == 'spat':
spat_flex = allspec2D[det].sci_spat_flexure
# print the value
print(f'Spat shift: {spat_flex}')
# return the value
return_flex = spat_flex
elif file_type == 'spec1d':
# no spat flexure in spec1d file
if flexure_type == 'spat':
msgs.error("Spat flexure not available in the spec1d file, try with a spec2d file")
# load the spec1d file
sobjs = specobjs.SpecObjs.from_fitsfile(file, chk_version=chk_version)
spec_flex = Table()
spec_flex['NAME'] = sobjs.NAME
spec_flex['global_spec_shift'] = sobjs.FLEX_SHIFT_GLOBAL
if np.all(spec_flex['global_spec_shift'] != None):
spec_flex['global_spec_shift'].format = '0.3f'
spec_flex['local_spec_shift'] = sobjs.FLEX_SHIFT_LOCAL
if np.all(spec_flex['local_spec_shift'] != None):
spec_flex['local_spec_shift'].format = '0.3f'
spec_flex['total_spec_shift'] = sobjs.FLEX_SHIFT_TOTAL
if np.all(spec_flex['total_spec_shift'] != None):
spec_flex['total_spec_shift'].format = '0.3f'
# print the table
spec_flex.pprint_all()
# return the table
return_flex = spec_flex

return return_flex


# TODO -- Consider separating the methods from the DataContainer as per calibrations
class MultiSlitFlexure(DataContainer):
"""
Expand Down
7 changes: 4 additions & 3 deletions pypeit/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def connect_to_ginga(host='localhost', port=9000, raise_err=False, allow_new=Fal
# was just instantiated for a maximum number of iterations.
# If the connection is remains unsuccessful, an error is
# thrown stating that the connection timed out.
maxiter = int(1e6)
maxiter = int(3e4)
for i in range(maxiter):
try:
viewer = grc.RemoteClient(host, port)
Expand All @@ -72,8 +72,9 @@ def connect_to_ginga(host='localhost', port=9000, raise_err=False, allow_new=Fal
break
if i == maxiter-1:
msgs.error('Timeout waiting for ginga to start. If window does not appear, type '
'`ginga --modules=RC,SlitWavelength` on the command line. In either case, wait for '
'the ginga viewer to open and try the pypeit command again.')
'`ginga --modules=RC,SlitWavelength` on the command line. In either '
'case, wait for the ginga viewer to open and try the pypeit command '
'again.')
return viewer

if raise_err:
Expand Down
1 change: 1 addition & 0 deletions pypeit/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pypeit.scripts import chk_alignments
from pypeit.scripts import chk_edges
from pypeit.scripts import chk_flats
from pypeit.scripts import chk_flexure
from pypeit.scripts import chk_tilts
from pypeit.scripts import chk_for_calibs
from pypeit.scripts import chk_noise_1dspec
Expand Down
63 changes: 63 additions & 0 deletions pypeit/scripts/chk_flexure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
This script displays the flexure (spatial or spectral) applied to the science data.
.. include common links, assuming primary doc root is up one directory
.. include:: ../include/links.rst
"""

from pypeit.scripts import scriptbase


class ChkFlexure(scriptbase.ScriptBase):

@classmethod
def get_parser(cls, width=None):
parser = super().get_parser(description='Print QA on flexure to the screen',
width=width)

parser.add_argument('input_file', type=str, nargs='+', help='One or more PypeIt spec2d or spec1d file')
inp = parser.add_mutually_exclusive_group(required=True)
inp.add_argument('--spec', default=False, action='store_true', help='Check the spectral flexure')
inp.add_argument('--spat', default=False, action='store_true', help='Check the spatial flexure')
parser.add_argument('--try_old', default=False, action='store_true',
help='Attempt to load old datamodel versions. A crash may ensue..')
return parser

@staticmethod
def main(args):

from IPython import embed
from astropy.io import fits
from pypeit import msgs
from pypeit.core import flexure

chk_version = not args.try_old

# Loop over the input files
for in_file in args.input_file:

msgs.info(f'Checking fluxure for file: {in_file}')

# What kind of file are we??
hdul = fits.open(in_file)
head0 = hdul[0].header
file_type = None
if 'PYP_CLS' in head0.keys() and head0['PYP_CLS'].strip() == 'AllSpec2DObj':
file_type = 'spec2d'
elif 'DMODCLS' in head0.keys() and head0['DMODCLS'].strip() == 'SpecObjs':
file_type = 'spec1d'
else:
msgs.error("Bad file type input!")

# Check the flexure
flexure.flexure_diagnostic(in_file, file_type=file_type, flexure_type='spat' if args.spat else 'spec',
chk_version=chk_version)

# space between files for clarity
print('')






Loading

0 comments on commit ead8ddb

Please sign in to comment.