pypeit.coadd2d module
Module for performing two-dimensional coaddition of spectra.
- class pypeit.coadd2d.CoAdd2D(spec2d, spectrograph, par, det=1, offsets=None, weights='auto', spec_samp_fact=1.0, spat_samp_fact=1.0, sn_smooth_npix=None, bkg_redux=False, find_negative=False, show=False, show_peaks=False, debug_offsets=False, debug=False, **kwargs_wave)[source]
Bases:
object
Main routine to run the extraction for 2d coadds.
- Algorithm steps are as follows:
Fill this in.
This performs 2d coadd specific tasks, and then also performs some of the tasks analogous to the pypeit.extract_one method. Docs coming soon….
- check_input(input, type='weights')[source]
Check that the number of input values (weights or offsets) is the same as the number of exposures :param input: User input values (e.g., weights or offsets) :type input:
list
or numpy.ndarray :param type: String defining what the quantities are :type type:str
- Returns
User input values
- Return type
- coadd(only_slits=None, interp_dspat=True)[source]
Construct a 2d co-add of a stack of PypeIt spec2d reduction outputs. This method calls loops over slits/orders and performs the 2d-coadd by calling coadd.compute.coadd2d, which ‘rectifies’ images by coadding them about the reference_trace_stack.
- Parameters
only_slits (list, optional) – List of slits to operate on. Not currently supported, i.e. the code can currently only stack everything because the slit/reduction bitmask checking is not yet implemented. Default = None
interp_dspat (bool, optional) – Interpolate in the spatial coordinate image to faciliate running through core.extract.local_skysub_extract. Default=True
- Returns
coadd_list – List of dictionaries, one for each slit, containing the 2d stack. # TODO Make this a PypeIt object, with data model yada-yada.
- Return type
- compute_offsets(offsets)[source]
Determine self.offsets, the offset of the frames to be coadded with respect to the first frame. This is partially overloaded by the child methods.
- compute_weights(weights)[source]
Determine self.use_weights, the weights to be used in the coadd2d. This is partially overloaded by the child methods.
- create_pseudo_image(coadd_list)[source]
..todo.. see below
THIS UNDOCUMENTED CODE PROBABLY SHOULD GENERATE AND RETURN STANDARD PYPEIT OBJCTS INSTEAD OF SOME UNDEFINED DICT
- static default_basename(spec2d_files)[source]
Construct the base name of the output spec2d file produced by coadding.
- static default_par(spectrograph, inp_cfg=None, det=None, slits=None)[source]
Get the default 2D coadding parameters.
- Parameters
spectrograph (
str
) – The PypeIt-specific name of the spectrograph used to collect the data.inp_cfg (
dict
, optional) – An existing set of parameters to add to.det (
list
,str
,tuple
, optional) – Limit the coadding to this (set of) detector(s)/detector mosaic(s)slits (
list
,str
, optional) – Limit the coadding to this (set of) slit(s)
- Returns
The default set of parameters.
- Return type
- get_brightest_object(specobjs_list, spat_ids)[source]
Dummy method to identify the brightest object. Overloaded by child methods.
- Parameters
specobjs_list –
spat_ids –
- classmethod get_instance(spec2dfiles, spectrograph, par, det=1, offsets=None, weights='auto', spec_samp_fact=1.0, spat_samp_fact=1.0, sn_smooth_npix=None, bkg_redux=False, find_negative=False, show=False, show_peaks=False, debug_offsets=False, debug=False, **kwargs_wave)[source]
Instantiate the subclass appropriate for the provided spectrograph.
The class to instantiate must match the
pypeline
attribute of the providedspectrograph
, and must be a subclass ofCoAdd2D
; see the parent class instantiation for parameter descriptions.
- get_maskdef_dict(slit_idx, ref_trace_stack)[source]
Dummy method to get maskdef info. Overloaded by child methods.
- Parameters
slit_idx –
ref_trace_stack –
Returns:
- get_wave_grid(**kwargs_wave)[source]
Routine to create a wavelength grid for 2d coadds using all of the wavelengths of the extracted objects. Calls
get_wave_grid()
.- Parameters
**kwargs_wave (dict) – Optional argumments for
get_wave_grid()
.- Returns
- Returns the following:
wave_grid (np.ndarray): New wavelength grid, not masked
wave_grid_mid (np.ndarray): New wavelength grid evaluated at the centers of the wavelength bins, that is this grid is simply offset from wave_grid by dsamp/2.0, in either linear space or log10 depending on whether linear or (log10 or velocity) was requested. For iref or concatenate the linear wavelength sampling will be calculated.
dsamp (float): The pixel sampling for wavelength grid created.
- Return type
- good_slitindx(only_slits=None)[source]
This provides an array of index of slits in the un-coadded frames that are considered good for 2d coadding. A bitmask common to all the un-coadded frames is used to determine which slits are good. Also, If the only_slits parameter is provided only those slits are considered good for 2d coadding.
- Parameters
only_slits (
list
, optional) – List of slits to combine. It must be slitord_id- Returns
array of index of good slits in the un-coadded frames
- Return type
- load_coadd2d_stacks(spec2d, chk_version=False)[source]
Routine to read in required images for 2d coadds given a list of spec2d files.
- Parameters
spec2d_files – list List of spec2d filenames
det – int detector in question
- Returns
Dictionary containing all the images and keys required for perfomring 2d coadds.
- Return type
- offset_slit_cen(slitid, offsets)[source]
Offset the slit centers of the slit designated by slitid by the provided offsets
- Parameters
slitid (int) – ID of the slit that is being offset
offsets (list, numpy.ndarray) – A list or array of offsets that are being applied to the slit center
- Returns
A list of reference traces for the 2d coadding that have been offset.
- Return type
- offsets_report(offsets, offsets_method)[source]
Print out a report on the offsets
- Parameters
offsets –
offsets_method –
Returns:
- optimal_weights(slitorderid, objid, const_weights=False)[source]
Determine optimal weights for 2d coadds. This script grabs the information from SpecObjs list for the object with specified slitid and objid and passes to coadd.sn_weights to determine the optimal weights for each exposure.
- Parameters
slitorderid (
int
) – The slit or order id that has the brightest object whose S/N will be used to determine the weight for each frame.objid (numpy.ndarray) – Array of object indices with shape = (nexp,) of the brightest object whose S/N will be used to determine the weight for each frame.
const_weights (
bool
) – Use constant weights for coadding the exposures. Default=False
- Returns
rms_sn (ndarray, shape = (len(specobjs_list),)) – Root mean square S/N value for each input spectra
weights (ndarray, shape (len(specobjs_list),)) – Weights to be applied to the spectra. These are signal-to-noise squared weights.
- static output_paths(spec2d_files, par)[source]
Construct the names and ensure the existence of the science and QA output directories.
- Parameters
spec2d_files (
list
) – The list of PypeIt spec2d files to be coadded. The top-level directory for the coadd2d output directories is assumed to be same as used by the basic reductions. For example, if one of the spec2d files is/path/to/reductions/Science/spec2d_file.fits
, the parent directory for the coadd2d directories is/path/to/reductions/
.par (
PypeItPar
) – Full set of parameters. The only used parameters arepar['rdx']['scidir']
andpar['rdx']['qadir']
. WARNING: This also alters the value ofpar['rdx']['qadir']
!!
- Returns
Two strings with the names of (1) the science output directory and (2) the QA output directory. The function also creates both directories if they do not exist.
- Return type
- reduce(pseudo_dict, show=False, clear_ginga=True, show_peaks=False, show_skysub_fit=False, basename=None)[source]
Method to run the reduction on coadd2d pseudo images
- Parameters
pseudo_dict (dict) – Dictionary containing coadd2d pseudo images
show (bool) – If True, show the outputs to ginga and the screen analogous to run_pypeit with the -s option
show_peaks (bool) – If True, plot the object finding QA to the screen.
basename (str) – The basename for the spec2d output files.
Returns:
- class pypeit.coadd2d.EchelleCoAdd2D(spec2d_files, spectrograph, par, det=1, offsets=None, weights='auto', spec_samp_fact=1.0, spat_samp_fact=1.0, sn_smooth_npix=None, bkg_redux=False, find_negative=False, show=False, show_peaks=False, debug_offsets=False, debug=False, **kwargs_wave)[source]
Bases:
CoAdd2D
Coadd Echelle reductions.
For documentation see
CoAdd2D
.Echelle can either stack with:
input
offsets
or ifoffsets
is None, it will find theobjid
of brightest trace and stack all orders relative to the trace of this object.specified
weights
, or ifweights
is None andauto_weights
is True, it will use wavelength dependent weights determined from the spectrum of the brightest objectsobjid
on each order
- compute_offsets(offsets)[source]
Determine self.offsets, the offset of the frames to be coadded with respect to the first frame
- get_brightest_obj(specobjs_list, nslits)[source]
Utility routine to find the brightest object in each exposure given a specobjs_list for Echelle reductions.
- Parameters
specobjs_list – list List of SpecObjs objects.
echelle – bool, default=True, optional
- Returns
- Returns the following:
objid: ndarray, int, shape (len(specobjs_list),): Array of object ids representing the brightest object in each exposure
snr_bar: ndarray, float, shape (len(list),): Average S/N over all the orders for this object
- Return type
- reference_trace_stack(slitid, offsets=None, objid=None)[source]
Utility function for determining the reference trace about which 2d coadds are performed.
There are two modes of operation to determine the reference trace for the 2d coadd of a given slit/order:
offsets
: We stack about the center of the slit for the slit in question with the input offsets addedojbid
: We stack about the trace of a reference object for this slit given for each exposure by the input objid
Either offsets or objid must be provided, but the code will raise an exception if both are provided.
- Parameters
slitid (int) – The slit or order that we are currently considering
stack_dict (dict) – Dictionary containing all the images and keys required for performing 2d coadds.
offsets (list, numpy.ndarray) – An array of offsets with the same dimensionality as the nexp, the numer of images being coadded.
objid (list, numpy.ndarray) – An array of objids with the same dimensionality as the nexp, the number of images being coadded.
- Returns
A list of reference traces for the 2d coadding that have been offset
- Return type
- class pypeit.coadd2d.MultiSlitCoAdd2D(spec2d_files, spectrograph, par, det=1, offsets=None, weights='auto', spec_samp_fact=1.0, spat_samp_fact=1.0, sn_smooth_npix=None, bkg_redux=False, find_negative=False, show=False, show_peaks=False, debug_offsets=False, debug=False, **kwargs_wave)[source]
Bases:
CoAdd2D
Child of Coadd2d for Multislit and Longslit reductions. For documentation see CoAdd2d parent class above.
# Multislit can coadd with: # 1) input offsets or if offsets is None, it will find the brightest trace and compute them # 2) specified weights, or if weights is None and auto_weights=True, it will compute weights using the brightest object
- compute_offsets(offsets)[source]
Determine self.offsets, the offset of the frames to be coadded with respect to the first frame
- get_brightest_obj(specobjs_list, spat_ids)[source]
Utility routine to find the brightest object in each exposure given a specobjs_list for MultiSlit reductions.
- Parameters
specobjs_list – list List of SpecObjs objects.
spat_ids (numpy.ndarray) –
- Returns
- Returns the following:
objid: ndarray, int, shape (len(specobjs_list),): Array of object ids representing the brightest object in each exposure
slit_idx (int): 0-based index
spat_id (int): SPAT_ID for slit that highest S/N ratio object is on (only for pypeline=MultiSlit)
snr_bar: ndarray, float, shape (len(list),): Average S/N over all the orders for this object
- Return type
- get_maskdef_dict(slit_idx, ref_trace_stack)[source]
- Parameters
slit_idx (
int
) – index of a slit in the uncoadded framesref_trace_stack (numpy.ndarray) – Stack of reference traces about which the images are rectified and coadded. It is the slitcen appropriately
is (shifted according the frames offsets. Shape) –
- Returns
Dictionary containing all the maskdef info. The quantities saved are: maskdef_id, maskdef_objpos, maskdef_slitcen, maskdef_designtab. To learn what they are see
SlitTraceSet
datamodel.- Return type