Skip to content

Commit

Permalink
all minor-ish comments
Browse files Browse the repository at this point in the history
  • Loading branch information
debora-pe committed Aug 7, 2024
1 parent 2007398 commit 8169140
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 51 deletions.
8 changes: 4 additions & 4 deletions pypeit/calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def load_pixflat(self):
# If this is a mosaic, we need to construct the pixel flat mosaic
if isinstance(self.det, tuple):
# We need to grab mosaic info from another existing calibration frame.
# We use EdgeTraceSet image to get `tform` and `m_order`. Check if EdgeTraceSet file exists.
# We use EdgeTraceSet image to get `tform` and `msc_ord`. Check if EdgeTraceSet file exists.
edges_file = Path(edgetrace.EdgeTraceSet.construct_file_name(self.flatimages.calib_key,
calib_dir=self.calib_dir)).absolute()
if not edges_file.exists():
Expand All @@ -897,8 +897,8 @@ def load_pixflat(self):
traceimg = edgetrace.EdgeTraceSet.from_file(edges_file, chk_version=self.chk_version).traceimg
det_info = traceimg.detector
# check that the mosaic parameters are defined
if not np.all(np.in1d(['tform', 'm_order'], list(det_info.keys()))) or \
det_info.tform is None or det_info.m_order is None:
if not np.all(np.in1d(['tform', 'msc_ord'], list(det_info.keys()))) or \
det_info.tform is None or det_info.msc_ord is None:
msgs.error('Mosaic parameters are not defined in the Edges frame. Cannot load the pixel flat!')

# read the file
Expand All @@ -913,7 +913,7 @@ def load_pixflat(self):
# get the pixel flat images of only the detectors in the mosaic
pixflat_images = np.concatenate([hdu[f'DET{d:02d}-PIXELFLAT_NORM'].data[None,:,:] for d in self.det])
# construct the pixel flat mosaic
pixflat_msc, _,_,_ = build_image_mosaic(pixflat_images, det_info.tform, order=det_info.m_order)
pixflat_msc, _,_,_ = build_image_mosaic(pixflat_images, det_info.tform, order=det_info.msc_ord)
# check that the mosaic has the correct shape
if pixflat_msc.shape != traceimg.image.shape:
msgs.error('The constructed pixel flat mosaic does not have the correct shape. '
Expand Down
9 changes: 6 additions & 3 deletions pypeit/flatfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,10 @@ def __init__(self, rawflatimg, spectrograph, flatpar, slits, wavetilts=None, wv_
self.slitless = slitless # is this a slitless flat?

# get waveimg here if available
self.build_waveimg() # this set self.waveimg
if self.wavetilts is None or self.wv_calib is None:
msgs.warn("Wavelength calib or tilts are not available. Wavelength image not generated.")
else:
self.build_waveimg() # this set self.waveimg

# Completed steps
self.steps = []
Expand Down Expand Up @@ -694,7 +697,7 @@ def build_waveimg(self):
"""
msgs.info("Generating wavelength image")
if self.wavetilts is None or self.wv_calib is None:
msgs.warn("Wavelength calib or tilts are not available. Cannot generate wavelength image.")
msgs.error("Wavelength calib or tilts are not available. Cannot generate wavelength image.")
else:
flex = self.wavetilts.spat_flexure
slitmask = self.slits.slit_img(initial=True, flexure=flex)
Expand Down Expand Up @@ -982,7 +985,7 @@ def fit(self, spat_illum_only=False, doqa=True, debug=False):

# Create the tilts image for this slit
if self.slitless:
tilts = np.outer(np.arange(rawflat.shape[0]) / rawflat.shape[0], np.ones(rawflat.shape[1]))
tilts = np.tile(np.arange(rawflat.shape[0]) / rawflat.shape[0], (rawflat.shape[0], 1)).T
else:
# TODO -- JFH Confirm the sign of this shift is correct!
_flexure = 0. if self.wavetilts.spat_flexure is None else self.wavetilts.spat_flexure
Expand Down
2 changes: 0 additions & 2 deletions pypeit/images/combineimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ def run(self, ignore_saturation=False, maxiters=5):
rn2img_stack *= mscale**2
basev_stack *= mscale**2

#TODO: Update docs

# Coadd them
if self.par['combine'] == 'mean':
weights = np.ones(self.nimgs, dtype=float)/self.nimgs
Expand Down
10 changes: 5 additions & 5 deletions pypeit/images/mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class Mosaic(datamodel.DataContainer):
'tform': dict(otype=np.ndarray, atype=float,
descr='The full transformation matrix for each detector used to '
'construct the mosaic.'),
'm_order': dict(otype=int, descr='Order of the interpolation used to construct the mosaic.')}
'msc_ord': dict(otype=int, descr='Order of the interpolation used to construct the mosaic.')}

name_prefix = 'MSC'
"""
Prefix for the name of the mosaic.
"""

def __init__(self, id, detectors, shape, shift, rot, tform, m_order):
def __init__(self, id, detectors, shape, shift, rot, tform, msc_ord):

args, _, _, values = inspect.getargvalues(inspect.currentframe())
d = dict([(k,values[k]) for k in args[1:]])
Expand Down Expand Up @@ -107,8 +107,8 @@ def _bundle(self):
tbl['rot'] = self.rot
if self.tform is not None:
tbl['tform'] = self.tform
if self.m_order is not None:
tbl.meta['m_order'] = self.m_order
if self.msc_ord is not None:
tbl.meta['msc_ord'] = self.msc_ord
if self.id is not None:
tbl.meta['id'] = self.id
if self.shape is not None:
Expand Down Expand Up @@ -213,5 +213,5 @@ def copy(self):
"""
Return a (deep) copy of the object.
"""
return Mosaic(id=self.id, detectors=np.array([det.copy() for det in self.detectors]), shape=self.shape, shift=self.shift.copy(), rot=self.rot.copy(), tform=self.tform.copy(), m_order=self.m_order)
return Mosaic(id=self.id, detectors=np.array([det.copy() for det in self.detectors]), shape=self.shape, shift=self.shift.copy(), rot=self.rot.copy(), tform=self.tform.copy(), msc_ord=self.msc_ord)

18 changes: 9 additions & 9 deletions pypeit/images/rawimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ def build_mosaic(self):
# Transform the image data to the mosaic frame. This call determines
# the shape of the mosaic image and adjusts the relative transforms to
# the absolute mosaic frame.
self.image, _, _img_npix, _tforms = build_image_mosaic(self.image, self.mosaic.tform, order=self.mosaic.m_order)
self.image, _, _img_npix, _tforms = build_image_mosaic(self.image, self.mosaic.tform, order=self.mosaic.msc_ord)
shape = self.image.shape
# Maintain dimensionality
self.image = np.expand_dims(self.image, 0)
Expand All @@ -1369,7 +1369,7 @@ def build_mosaic(self):

# Transform the BPM and maintain its type
bpm_type = self.bpm.dtype
self._bpm = build_image_mosaic(self.bpm.astype(float), _tforms, mosaic_shape=shape, order=self.mosaic.m_order)[0]
self._bpm = build_image_mosaic(self.bpm.astype(float), _tforms, mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
# Include pixels that have no contribution from the original image in
# the bad pixel mask of the mosaic.
self._bpm[_img_npix < 1] = 1
Expand All @@ -1384,29 +1384,29 @@ def build_mosaic(self):

# Get the pixels associated with each amplifier
self.datasec_img = build_image_mosaic(self.datasec_img.astype(float), _tforms,
mosaic_shape=shape, order=self.mosaic.m_order)[0]
mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
self.datasec_img = np.expand_dims(np.round(self.datasec_img).astype(int), 0)

# Get the pixels associated with each detector
self.det_img = build_image_mosaic(self.det_img.astype(float), _tforms,
mosaic_shape=shape, order=self.mosaic.m_order)[0]
mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
self.det_img = np.expand_dims(np.round(self.det_img).astype(int), 0)

# Transform all the variance arrays, as necessary
if self.rn2img is not None:
self.rn2img = build_image_mosaic(self.rn2img, _tforms, mosaic_shape=shape, order=self.mosaic.m_order)[0]
self.rn2img = build_image_mosaic(self.rn2img, _tforms, mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
self.rn2img = np.expand_dims(self.rn2img, 0)
if self.dark is not None:
self.dark = build_image_mosaic(self.dark, _tforms, mosaic_shape=shape, order=self.mosaic.m_order)[0]
self.dark = build_image_mosaic(self.dark, _tforms, mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
self.dark = np.expand_dims(self.dark, 0)
if self.dark_var is not None:
self.dark_var = build_image_mosaic(self.dark_var, _tforms, mosaic_shape=shape, order=self.mosaic.m_order)[0]
self.dark_var = build_image_mosaic(self.dark_var, _tforms, mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
self.dark_var = np.expand_dims(self.dark_var, 0)
if self.proc_var is not None:
self.proc_var = build_image_mosaic(self.proc_var, _tforms, mosaic_shape=shape, order=self.mosaic.m_order)[0]
self.proc_var = build_image_mosaic(self.proc_var, _tforms, mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
self.proc_var = np.expand_dims(self.proc_var, 0)
if self.base_var is not None:
self.base_var = build_image_mosaic(self.base_var, _tforms, mosaic_shape=shape, order=self.mosaic.m_order)[0]
self.base_var = build_image_mosaic(self.base_var, _tforms, mosaic_shape=shape, order=self.mosaic.msc_ord)[0]
self.base_var = np.expand_dims(self.base_var, 0)

# TODO: Mosaicing means that many of the internals are no longer
Expand Down
24 changes: 12 additions & 12 deletions pypeit/spectrographs/gemini_gmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def get_rawimage(self, raw_file, det):
return detectors[0], array[0], hdu, exptime, rawdatasec_img[0], oscansec_img[0]
return mosaic, array, hdu, exptime, rawdatasec_img, oscansec_img

def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
def get_mosaic_par(self, mosaic, hdu=None, msc_ord=0):
"""
Return the hard-coded parameters needed to construct detector mosaics
from unbinned images.
Expand All @@ -481,7 +481,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
default. BEWARE: If ``hdu`` is not provided, the binning is
assumed to be `1,1`, which will cause faults if applied to
binned images!
m_order (:obj:`int`, optional):
msc_ord (:obj:`int`, optional):
Order of the interpolation used to construct the mosaic.
Returns:
Expand Down Expand Up @@ -535,7 +535,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
msc_tfm[i] = build_image_mosaic_transform(shape, msc_sft[i], msc_rot[i], tuple(reversed(binning)))

return Mosaic(mosaic_id, detectors, shape, np.array(msc_sft), np.array(msc_rot),
np.array(msc_tfm), m_order)
np.array(msc_tfm), msc_ord)

@property
def allowed_mosaics(self):
Expand Down Expand Up @@ -864,7 +864,7 @@ def get_detector_par(self, det, hdu=None):
# Return
return detector_container.DetectorContainer(**detectors[det-1])

def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
def get_mosaic_par(self, mosaic, hdu=None, msc_ord=0):
"""
Return the hard-coded parameters needed to construct detector mosaics
from unbinned images.
Expand All @@ -885,7 +885,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
default. BEWARE: If ``hdu`` is not provided, the binning is
assumed to be `1,1`, which will cause faults if applied to
binned images!
m_order (:obj:`int`, optional):
msc_ord (:obj:`int`, optional):
Order of the interpolation used to construct the mosaic.
Returns:
Expand All @@ -907,7 +907,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
else:
self.detid = 'BI5-36-4k-2,BI11-33-4k-1,BI12-34-4k-1'

return super().get_mosaic_par(mosaic, hdu=hdu, m_order=m_order)
return super().get_mosaic_par(mosaic, hdu=hdu, msc_ord=msc_ord)

@classmethod
def default_pypeit_par(cls):
Expand Down Expand Up @@ -1142,7 +1142,7 @@ def get_detector_par(self, det, hdu=None):
# Return
return detector_container.DetectorContainer(**detectors[det-1])

def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
def get_mosaic_par(self, mosaic, hdu=None, msc_ord=0):
"""
Return the hard-coded parameters needed to construct detector mosaics
from unbinned images.
Expand All @@ -1163,7 +1163,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
default. BEWARE: If ``hdu`` is not provided, the binning is
assumed to be `1,1`, which will cause faults if applied to
binned images!
m_order (:obj:`int`, optional):
msc_ord (:obj:`int`, optional):
Order of the interpolation used to construct the mosaic.
Returns:
Expand All @@ -1174,7 +1174,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
# Detector ID (it is used to identify the correct mosaic geometry)
self.detid = 'BI13-20-4k-1,BI12-09-4k-2,BI13-18-4k-2'

return super().get_mosaic_par(mosaic, hdu=hdu, m_order=m_order)
return super().get_mosaic_par(mosaic, hdu=hdu, msc_ord=msc_ord)

def config_specific_par(self, scifile, inp_par=None):
"""
Expand Down Expand Up @@ -1410,7 +1410,7 @@ def get_detector_par(self, det, hdu=None):
# Return
return detector_container.DetectorContainer(**detectors[det-1])

def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
def get_mosaic_par(self, mosaic, hdu=None, msc_ord=0):
"""
Return the hard-coded parameters needed to construct detector mosaics
from unbinned images.
Expand All @@ -1431,7 +1431,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
default. BEWARE: If ``hdu`` is not provided, the binning is
assumed to be `1,1`, which will cause faults if applied to
binned images!
m_order (:obj:`int`, optional):
msc_ord (:obj:`int`, optional):
Order of the interpolation used to construct the mosaic.
Returns:
Expand All @@ -1443,7 +1443,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
# TODO: Check this is correct
self.detid = 'e2v 10031-23-05,10031-01-03,10031-18-04'

return super().get_mosaic_par(mosaic, hdu=hdu, m_order=m_order)
return super().get_mosaic_par(mosaic, hdu=hdu, msc_ord=msc_ord)

def config_specific_par(self, scifile, inp_par=None):
"""
Expand Down
6 changes: 3 additions & 3 deletions pypeit/spectrographs/keck_deimos.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def get_rawimage(self, raw_file, det):
return detectors[0], image[0], hdu, exptime, rawdatasec_img[0], oscansec_img[0]
return mosaic, image, hdu, exptime, rawdatasec_img, oscansec_img

def get_mosaic_par(self, mosaic, hdu=None, m_order=5):
def get_mosaic_par(self, mosaic, hdu=None, msc_ord=5):
"""
Return the hard-coded parameters needed to construct detector mosaics
from unbinned images.
Expand All @@ -845,7 +845,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=5):
default. BEWARE: If ``hdu`` is not provided, the binning is
assumed to be `1,1`, which will cause faults if applied to
binned images!
m_order (:obj:`int`, optional):
msc_ord (:obj:`int`, optional):
Order of the interpolation used to construct the mosaic.
Returns:
Expand Down Expand Up @@ -892,7 +892,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=5):
msc_tfm[i] = build_image_mosaic_transform(shape, msc_sft[i], msc_rot[i], binning)

return Mosaic(mosaic_id, detectors, shape, np.array(msc_sft), np.array(msc_rot),
np.array(msc_tfm), m_order)
np.array(msc_tfm), msc_ord)

@property
def allowed_mosaics(self):
Expand Down
34 changes: 24 additions & 10 deletions pypeit/spectrographs/keck_hires.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,29 @@ def check_frame_type(self, ftype, fitstbl, exprng=None):

def vet_assigned_ftypes(self, type_bits, fitstbl):
"""
Check the assigned frame types for consistency.
Args:
type_bits (`numpy.ndarray`_):
Array with the frame types assigned to each frame
fitstbl (`PypeItMetaData`_):
Table with the metadata for the frames to check.
NOTE: this function should only be called when running pypeit_setup,
in order to not overwrite any user-provided frame types.
This method checks the assigned frame types for consistency.
For frames that are assigned both the science and standard types,
this method chooses the one that is most likely, by checking if the
frames are within 10 arcmin of a listed standard star.
In addition, for this instrument, if a frame is assigned both a
pixelflat and slitless_pixflat type, the pixelflat type is removed.
NOTE: if the same frame is assigned to multiple configurations, this
method will remove the pixelflat type for all configurations, i.e.,
it is not possible to use slitless_pixflat type for one calibration group
and pixelflat for another.
Returns:
`numpy.ndarray`_: The updated frame types.
"""
type_bits = super().vet_assigned_ftypes(type_bits, fitstbl)

# If both pixelflat and slitless_pixflat are assigned in the same configuration, remove pixelflat
# If both pixelflat and slitless_pixflat are assigned to the same frame, remove pixelflat

# where slitless_pixflat is assigned
slitless_idx = fitstbl.type_bitmask.flagged(type_bits, flag='slitless_pixflat')
Expand All @@ -454,6 +463,11 @@ def vet_assigned_ftypes(self, type_bits, fitstbl):
def parse_raw_files(self, fitstbl, det=1, ftype=None):
"""
Parse the list of raw files with given frame type and detector.
This is spectrograph-specific, and it is not defined for all
spectrographs.
Since different slitless_pixflat frames are usually taken for
each of the three detectors, this method parses the slitless_pixflat
frames and returns the correct one for the requested detector.
Args:
fitstbl (`astropy.table.Table`_):
Expand Down Expand Up @@ -619,7 +633,7 @@ def get_rawimage(self, raw_file, det, spectrim=20):
return mosaic, image, hdu, exptime, rawdatasec_img, oscansec_img


def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
def get_mosaic_par(self, mosaic, hdu=None, msc_ord=0):
"""
Return the hard-coded parameters needed to construct detector mosaics
from unbinned images.
Expand All @@ -640,7 +654,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
default. BEWARE: If ``hdu`` is not provided, the binning is
assumed to be `1,1`, which will cause faults if applied to
binned images!
m_order (:obj:`int`, optional):
msc_ord (:obj:`int`, optional):
Order of the interpolation used to construct the mosaic.
Returns:
Expand Down Expand Up @@ -691,7 +705,7 @@ def get_mosaic_par(self, mosaic, hdu=None, m_order=0):
msc_tfm[i] = build_image_mosaic_transform(shape, msc_sft[i], msc_rot[i], tuple(reversed(binning)))

return Mosaic(mosaic_id, detectors, shape, np.array(msc_sft), np.array(msc_rot),
np.array(msc_tfm), m_order)
np.array(msc_tfm), msc_ord)


@property
Expand Down
Loading

0 comments on commit 8169140

Please sign in to comment.