Skip to content

Commit

Permalink
Move lampstat check
Browse files Browse the repository at this point in the history
  • Loading branch information
rcooke-ast committed Jun 29, 2024
1 parent 634f27c commit 1deaeb3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 44 deletions.
27 changes: 25 additions & 2 deletions pypeit/images/buildimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
.. include:: ../include/links.rst
"""

import os

from IPython import embed

import numpy as np
Expand Down Expand Up @@ -253,15 +255,36 @@ def buildimage_fromlist(spectrograph, det, frame_par, file_list, bias=None, bpm=
mosaic = isinstance(det, tuple) and frame_par['frametype'] not in ['bias', 'dark']

rawImage_list = []
lampstat = [None] * len(file_list)
# Loop on the files
for ifile in file_list:
for ii, ifile in enumerate(file_list):
# Load raw image
rawImage = rawimage.RawImage(ifile, spectrograph, det)
# Process
rawImage_list.append(rawImage.process(
frame_par['process'], scattlight=scattlight, bias=bias,
bpm=bpm, dark=dark, flatimages=flatimages, slits=slits, mosaic=mosaic))


# Save the lamp status
# TODO: Is there a way we can get this from fitstbl instead?
lampstat[ii] = spectrograph.get_lamps_status(rawImage_list[ii].rawheadlist)

# Check that the lamps being combined are all the same:
if not lampstat[1:] == lampstat[:-1]:
msgs.warn("The following files contain different lamp status")
# Get the longest strings
maxlen = max([len("Filename")]+[len(os.path.split(x)[1]) for x in file_list])
maxlmp = max([len("Lamp status")]+[len(x) for x in lampstat])
strout = "{0:" + str(maxlen) + "} {1:s}"
# Print the messages
print(msgs.indent() + '-'*maxlen + " " + '-'*maxlmp)
print(msgs.indent() + strout.format("Filename", "Lamp status"))
print(msgs.indent() + '-'*maxlen + " " + '-'*maxlmp)
for ff, file in enumerate(file_list):
print(msgs.indent()
+ strout.format(os.path.split(file)[1], " ".join(lampstat[ff].split("_"))))
print(msgs.indent() + '-'*maxlen + " " + '-'*maxlmp)

# Do it
combineImage = combineimage.CombineImage(rawImage_list, spectrograph, frame_par['process'])
pypeitImage = combineImage.run(maxiters=maxiters, ignore_saturation=ignore_saturation)
Expand Down
28 changes: 2 additions & 26 deletions pypeit/images/combineimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
.. include:: ../include/links.rst
"""

import os

from IPython import embed

import numpy as np
Expand All @@ -18,6 +16,7 @@
from pypeit.images import pypeitimage
from pypeit.images import imagebitmask


class CombineImage:
"""
Process and combine detector images.
Expand Down Expand Up @@ -165,13 +164,8 @@ def run(self, ignore_saturation=False, maxiters=5):
rn2img_stack = np.zeros(shape, dtype=float)
basev_stack = np.zeros(shape, dtype=float)
gpm_stack = np.zeros(shape, dtype=bool)
lampstat = [None]*self.nimgs
exptime = np.zeros(self.nimgs, dtype=float)

# Save the lamp status
# TODO: As far as I can tell, this is the *only* place rawheadlist
# is used. Is there a way we can get this from fitstbl instead?
lampstat[kk] = self.spectrograph.get_lamps_status(rawImage.rawheadlist)
# Save the exposure time to check if it's consistent for all images.
exptime[kk] = rawImage.exptime
# Processed image
Expand All @@ -195,25 +189,7 @@ def run(self, ignore_saturation=False, maxiters=5):
gpm_stack[kk] = rawImage.select_flag(invert=True)
file_list.append(rawImage.filename)

# TODO JFH: This should not be here, but rather should be done in the Calibrations class. Putting in calibration specific
# lamp checking in an image combining class is not ideal.
# Check that the lamps being combined are all the same:
if not lampstat[1:] == lampstat[:-1]:
msgs.warn("The following files contain different lamp status")
# Get the longest strings
maxlen = max([len("Filename")]+[len(os.path.split(x)[1]) for x in self.files])
maxlmp = max([len("Lamp status")]+[len(x) for x in lampstat])
strout = "{0:" + str(maxlen) + "} {1:s}"
# Print the messages
print(msgs.indent() + '-'*maxlen + " " + '-'*maxlmp)
print(msgs.indent() + strout.format("Filename", "Lamp status"))
print(msgs.indent() + '-'*maxlen + " " + '-'*maxlmp)
for ff, file in enumerate(self.files):
print(msgs.indent()
+ strout.format(os.path.split(file)[1], " ".join(lampstat[ff].split("_"))))
print(msgs.indent() + '-'*maxlen + " " + '-'*maxlmp)

# Do a similar check for exptime
# Check that all exposure times are consistent
if np.any(np.absolute(np.diff(exptime)) > 0):
# TODO: This should likely throw an error instead!
msgs.warn('Exposure time is not consistent for all images being combined! '
Expand Down
16 changes: 0 additions & 16 deletions pypeit/spectrographs/jwst_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,6 @@ def allowed_mosaics(self):
``PypeIt``.
"""
return [(1,2)]



def get_lamps_status(self, headarr):
"""
Return a string containing the information on the lamp status.
Args:
headarr (:obj:`list`):
A list of 1 or more `astropy.io.fits.Header`_ objects.
Returns:
:obj:`str`: A string that uniquely represents the lamp status.
"""
# TODO: JFH This is a hack to deal with the usage of this method in combineimage, which is not where it should be.
return None

def get_rawimage(self, raw_file, det):
"""
Expand Down

0 comments on commit 1deaeb3

Please sign in to comment.