dbsp_drp package
Subpackages
Submodules
dbsp_drp.adjust_splicing module
- dbsp_drp.adjust_splicing.adjust_splicing_GUI(hdul: HDUList, fname: str)[source]
Opens a Matplotlib GUI for users to manually adjust the matching of overall red/blue flux levels, as well as interpolate over detector gaps.
- Parameters:
hdul (fits.HDUList) – HDUList read in from DBSP_DRP final data output file.
fname (str) – Output path and filename to write adjusted spectrum to.
dbsp_drp.coadding module
Automated coadding for P200 DBSP.
- dbsp_drp.coadding.coadd(grouped_spats_list: List[dict], output_path: str, spectrograph: str, user_config_lines: List[str], debug: bool = False) List[str] [source]
Coadds objects specified in grouped_spats_list.
- Parameters:
grouped_spats_list (List[dict]) – a list of dicts mapping
fnames
to a list of filenames andspats
to a list of integer spatial pixel positions.output_path (str) – Coadded files will be written to
output_path/Science
spectrograph (str) – PypeIt name of spectrograph.
user_config_lines (List[str]) – User-provided PypeIt configuration.
debug (bool, optional) – Show debugging output/plots? Defaults to False.
- Returns:
List of filenames of coadded spectra.
- Return type:
List[str]
- dbsp_drp.coadding.coadd_one_object(spec1dfiles: List[str], objids: List[str], coaddfile: str, spectrograph: str, user_config_lines: List[str], debug: bool = False)[source]
Coadds multiple 1D spectra of one object.
- Parameters:
spec1dfiles (List[str]) – List of spec1d files to coadd.
objids (List[str]) – List of object IDs to coadd.
coaddfile (str) – Outpath path and filename for coadd file.
spectrograph (str) – PypeIt name of spectrograph
user_config_lines (List[str]) – User-provided PypeIt configuration
debug (bool, optional) – Show debugging output/plots? Defaults to False.
- dbsp_drp.coadding.group_coadds(fname_to_spats: dict)[source]
Groups coadds. Destroys input.
- Parameters:
fname_to_spats (dict) – maps filenames to a list of integer spatial positions
- Returns:
List of dicts mapping ‘fnames’ to a list of filenames and ‘spats’ to a list of integer spatial positions.
- Return type:
List[Dict[str, Union[List[str], List[int]]]]
dbsp_drp.fix_headers module
- dbsp_drp.fix_headers.main(path_prefix: str, throw_errors: bool, prompt_user: bool) List[str] [source]
Fixes FITS files found in
path_prefix/*.fits
orpath_prefix*.fits
for common DBSP errors: empty file, extra bytes at the end, swapped GRATING/ANGLE values, missing/wrong RA/DEC/AIRMASS.- Parameters:
path_prefix (str) – Where to look for FITS files.
throw_errors (bool) – Raise error when file cannot be automatically fixed?
prompt_user (bool) – Prompt user to fix missing/bad headers?
- Raises:
ValueError – If
throw_errors
, raised when ANGLE and GRATING both cannot be parsed as angles.- Returns:
list of files with headers good enough to start reduction.
- Return type:
List[str]
dbsp_drp.fluxing module
Automated fluxing for P200 DBSP.
- dbsp_drp.fluxing.build_fluxfile(spec1d_to_sensfunc: Dict[str, str], output_path: str, spectrograph: str, user_config_lines: List[str]) str [source]
Writes the fluxfile for fluxing.
Uses archived sensitivity function if no standard was reduced.
- Parameters:
spec1d_to_sensfunc (Dict[str,str]) – maps spec1d filenames to the sensitivity function they should use
output_path (str) – reduction output path
spectrograph (str) – PypeIt name of spectrograph.
user_config_lines (List[str]) – User-provided PypeIt configuration.
- Returns:
path to created fluxfile
- Return type:
str
- dbsp_drp.fluxing.flux(flux_file: str, output_path: str, debug: bool = False) None [source]
Flux spectra.
- Parameters:
flux_file (str) – Path to flux file
output_path (str) – reduction output path
debug (bool, optional) – Show debugging output/plots? Defaults to False.
- dbsp_drp.fluxing.make_sensfunc(standard_file: str, output_path: str, spectrograph: str, user_config_lines: List[str], debug: bool = False) str [source]
Makes a sensitivity function.
- Parameters:
standard_file (str) – Filename of standard exposure.
output_path (str) – Partial path to standard exposure.
spectrograph (str) – PypeIt name of spectrograph.
user_config_lines (List[str]) – User-provided PypeIt configuration.
debug (bool, optional) – Show debugging output/plots? Defaults to False.
- Returns:
Filename of sensitivity function file, or empty string on failure.
- Return type:
str
dbsp_drp.gui_helpers module
Module for classes and functions shared between GUIs.
- class dbsp_drp.gui_helpers.HelpTool(*args, helptext='', **kwargs)[source]
Bases:
ToolBase
Print help text.
- default_keymap = 'h'
Keymap to associate with this tool.
String: List of comma separated keys that will be used to call this tool when the keypress event of
self.figure.canvas
is emitted.
- description = 'Help'
Description of the Tool.
String: If the Tool is included in the Toolbar this text is used as a Tooltip.
- image = 'help'
Filename of the image.
String: Filename of the image to use in the toolbar. If None, the name is used as a label in the toolbar button.
- trigger(*args, **kwargs)[source]
Called when this tool gets used.
This method is called by matplotlib.backend_managers.ToolManager.trigger_tool.
- Parameters:
event (.Event) – The canvas event that caused this tool to be called.
sender (object) – Object that requested the tool to be triggered.
data (object) – Extra data.
dbsp_drp.manual_aperture module
- class dbsp_drp.manual_aperture.ManualApertureGUI(figure: Figure, axes: Axes, target, spec: Spec2DObj, traces, edges, fitted_fwhms, manual_traces, collapse_region)[source]
Bases:
object
GUI for manually selecting background and signal for object traces
- How to use:
to designate background regions, press (b)ackground and then click and drag
left-click and drag blue (manual) traces around
right-click and drag to change FWHM of blue (manual) traces
press (d)elete to delete background regions under the cursor
- delete(event)[source]
Delete a background area under (or nearby) the mouse
The x-tolerance is hardcoded to 5 CCD pixels.
- property mask
dbsp_drp.manual_splice module
dbsp_drp.manual_tracing module
- class dbsp_drp.manual_tracing.ManualTracingGUI(specs_dict)[source]
Bases:
object
GUI for manually identifying object traces
Takes in specs_dict:
specs_dict[target_name] == { 'spec': spectrum_2d, 'edges': [all_left_edges, all_right_edges], 'traces': traces, 'fwhms': fwhms, 'fwhmfit': automatically fit fwhms }
How to use: Displays one spectrum at a time use left and right arrow keys to go back and forth between spectra press m to lay down a (m)anual trace under your cursor press d to (d)elete a manual trace near your cursor press c, then left-click and drag to set the region to view the (c)ollapsed flux
- property edges
- property fwhmfit
- helptext = 'GUI for manually identifying object traces\n Displays one spectrum at a time\n\n How to use:\n - use left and right arrow keys to go back and forth between spectra\n - press m to lay down a (m)anual trace under your cursor\n - press d to (d)elete a manual trace near your cursor\n - press c, then left-click and drag to set the region to view the (c)ollapsed flux\n '
- property mask
- property sky_resid
- property spec
- property target
- property traces
dbsp_drp.p200_redux module
Automatic Reduction Pipeline for P200 DBSP.
- dbsp_drp.p200_redux.interactive_correction(ps: PypeItSetup) None [source]
Allows for human correction of FITS headers and frame typing.
Launches a GUI via dbsp_drp.table_edit, which handles saving updated FITS headers. table_edit depends on the current DBSP headers.
- Parameters:
ps (PypeItSetup) – PypeItSetup object created in dbsp_drp.reduction.setup
dbsp_drp.qa module
Quality Assurance for automated reduction of P200 DBSP.
- dbsp_drp.qa.save_2dspecs(qa_dict: dict, output_spec2ds: List[str], output_path: str, spectrograph: str) dict [source]
Saves PNG images of each spectra at various steps in the reduction process. In one PNG, displayed from left to right are science image, sky model, sky-subtracted image, sky-subtraction residuals, sky- and object-subtraction residuals.
- Parameters:
qa_dict (dict) – Dict mapping target names to a dict containing lists of PNG filenames, airmasses, UTCs, and raw data filenames, from previous call of
save_2dspecs
, or empty dict for first call.output_spec2ds (List[str]) – List of spec2d filenames.
output_path (str) – reduction output path.
spectrograph (str) – PypeIt name of spectrograph.
- Returns:
updated
qa_dict
- Return type:
dict
- dbsp_drp.qa.save_one2dspec(ax: Axes, spec: ndarray, edges: Tuple[ndarray, ndarray], traces: List[ndarray], fwhms: List[ndarray]) None [source]
Displays a 2D spectrum on the input Matplotlib Axes, with slit edges and object traces and extraction FWHMs overplotted.
- Parameters:
ax (plt.Axes) – Axes object for plotting.
spec (np.ndarray) – 2D spectrum to plot.
edges (Tuple[np.ndarray, np.ndarray]) – Left and right slit edges, as arrays of the spatial pixel position of the edge for each pixel in the spectral direction.
traces (List[np.ndarray]) – Object traces as arrays of spatial pixel positions for each pixel in the spectral direction.
fwhms (List[np.ndarray]) – Extraction FWHMs for each object trace.
- dbsp_drp.qa.write_extraction_QA(qa_dict: dict, output_path: str) None [source]
Write Extraction.html page allowing for convenient viewing of PNGs saved in
save_2dspecs
.- Parameters:
qa_dict (dict) – Dict mapping target names to a dict containing lists of PNG filenames, airmasses, UTCs, and raw data filenames.
output_path (str) – reduction output path
dbsp_drp.quicklook module
dbsp_drp.reduction module
Automated reduction steps for P200 DBSP.
- dbsp_drp.reduction.delete_completely_masked_hdus(path: str, base_name: str = '')[source]
Removes
SpecObj
s that are completely masked, i.e. no good pixels/data, from a FITS file containing aSpecObjs
file.- Parameters:
path (str) – Path to FITS file.
base_name (str, optional) – Name of file used for logging. Defaults to “”.
- dbsp_drp.reduction.delete_duplicate_hdus_by_name(path: str, base_name: str = '')[source]
Removes
SpecObj
s with identical names from a FITS file containing aSpecObjs
object, leaving oneSpecObj
with the duplicate name behind.- Parameters:
path (str) – Path to FITS file.
base_name (str, optional) – Name of file used for logging. Defaults to “”.
- dbsp_drp.reduction.manual_extraction(output_spec2ds: List[str], pypeit_file: str, output_path: str) list [source]
wglwk
- Parameters:
output_spec2ds (List[str]) – List of spec2d files to potentially manually extract.
pypeit_file (str) – PypeIt reduction file for initial reduction.
output_path (str) – reduction output path.
- Returns:
List of new PypeIt reduction files for the manually traced targets.
- Return type:
list
- dbsp_drp.reduction.manual_extraction_GUI(output_spec2ds: List[str], output_path: str) dict [source]
Runs the Manual Tracing GUI.
- Parameters:
output_spec2ds (List[str]) – List of spec2d files to inspect in GUI.
output_path (str) – reduction output path
- Returns:
- Maps target names needing manual tracing to a dict specifying how
they should be manually traced.
- Return type:
dict
- dbsp_drp.reduction.parse_pypeit_parameter_file(parameter_file: str, spectrograph: str) List[str] [source]
Grab user-provided PypeIt configuration for
spectrograph
fromparameter_file
, which contains user-provided PypeIt configuration for both arms of DBSP.- Parameters:
parameter_file (str) – User-provided file with their PypeIt config.
spectrograph (str) – PypeIt name of spectrograph.
- Returns:
User-provided PypeIt configuration for
spectrograph
- Return type:
List[str]
- dbsp_drp.reduction.re_redux(pypeit_files: List[str], output_path: str) Tuple[set, set] [source]
Runs multiple reductions, returns the combined sets of output spec1d, spec2d files.
- Parameters:
pypeit_files (List[str]) – List of PypeIt reduction files to run.
output_path (str) – reduction output path
- Returns:
set of filenames of reduced (spec1d, spec2d) files.
- Return type:
Tuple[set, set]
- dbsp_drp.reduction.redux(pypeit_file: str, output_path: str, reuse_masters: bool = True, show: bool = False, calib_only: bool = False) Tuple[set, set] [source]
Runs the reduction
- Parameters:
pypeit_file (str) – Path to PypeIt reduction file.
output_path (str) – reduction output path
reuse_masters (bool, optional) – Reuse master calibration files (if they exist). Defaults to True.
show (bool, optional) – Show debugging/intermediate plots. Defaults to False.
calib_only (bool, optional) – Only perform calibration? Defaults to False.
- Returns:
set of filenames of reduced (spec1d, spec2d) files.
- Return type:
Tuple[set, set]
- dbsp_drp.reduction.search_table_for_arc(row: Row, i: int, table: Table, step: int, max_sep: Angle) Tuple[int, int] [source]
Searches table starting at row
i
in steps ofstep
for frames withinmax_separation
ofrow
. If an arc frame is found, the arc’scalib
is assigned torow
.- Parameters:
row (Row) – starting row
i (int) – index of starting row
table (Table) – table to search in and modify
step (int) – direction to look in. 1 for forwards, -1 for backwards
max_sep (Angle) – maximum separation allowed between frames pointing at the same object
- Returns:
- (distance to arc frame, calib ID) or (-1, -1) if
no arc found.
- Return type:
Tuple[int, int]
- dbsp_drp.reduction.set_calibs(table: Table)[source]
Automagically set ‘calib’ column for .pypeit file.
Bias and flat frames get calib ‘all’ Arcs at airmass 1.0 get calib 0 (default for science/standards) A consecutive set of arcs at airmass > 1.0 get the same calib, starting at 1. Science and standards get the calib of the nearest arc frame, iff the telescope hasn’t changed pointing between the arc and the science/standard. If there is no arc frame with the same pointing, science and standards are assigned calib 0.
- Parameters:
table (Table) – PypeItSetup.fitstbl.table
- dbsp_drp.reduction.setup(file_list: List[str], output_path: str, spectrograph: str) Tuple[PypeItSetup, str] [source]
Does PypeIt setup, without writing the .pypeit file
- Parameters:
file_list (List[str]) – List of raw data files to reduce.
output_path (str) – reduction output path
spectrograph (str) – PypeIt name of spectrograph.
- Returns:
PypeItSetup object, reduction output path
- Return type:
Tuple[PypeItSetup, str]
- dbsp_drp.reduction.verify_spec1ds(output_spec1ds: List[str], verification_counter: int, output_path: str) List[str] [source]
Verifies validity of spec1d files, fixes some, and generates and returns a list of pypeit files for targets that need to be rerun.
- Parameters:
output_spec1ds (List[str]) – List of spec1d filenames
verification_counter (int) – number of times verification has been run
output_path (str) – reduction output path
- Returns:
List of PypeIt files for targets that need to be rereduced.
- Return type:
List[str]
- dbsp_drp.reduction.write_manual_pypeit_files(old_pypeit_file: str, targets_list: List[List[str]], manual_lines_fn: Callable[[List[str]], List[str]], needs_std_fn: Callable[[str], bool]) List[str] [source]
Writes pypeit files based on the default pypeit file for this reduction, but with filtered targets and additional manual parameter lines.
- Parameters:
old_pypeit_file (str) – default pypeit file,
targets_list (List[List[str]]) – [[target1, target2], [target3, target4]] will result in 1 & 2 being reduced together and 3 & 4 being reduced together. The target names are blueNNNN-ZTF21abcd.
manual_lines_fn (Callable[[List[str]], List[str]]) – function mapping [target1, target2] to the cfg lines they need.
needs_std_fn (Callable[[str], bool]) – function mapping target1 -> bool. True if target1 needs a standard star to be reduced alongside it.
- Returns:
- List of new PypeIt reduction files for the manually traced
targets.
- Return type:
List[str]
- dbsp_drp.reduction.write_setup(context: Tuple[PypeItSetup, str], cfg_split: str, spectrograph: str, user_config_lines: List[str]) List[str] [source]
Writes the .pypeit file
- Parameters:
context (Tuple[PypeItSetup, str]) – PypeItSetup object, reduction output path
cfg_split (str) – [description]
spectrograph (str) – PypeIt name of spectrograph.
user_config_lines (List[str]) – User-provided PypeIt configuration.
- Raises:
RuntimeError – Raised if files were not assigned a frame type.
- Returns:
List of PypeIt files generated.
- Return type:
List[str]
dbsp_drp.show_spectrum module
All-purpose interactive spectrum plotter for DBSP_DRP and intermediate PypeIt files.
- dbsp_drp.show_spectrum.main(args: Namespace) None [source]
Attempts to parse input FITS file as
OneSpec
,SpecObjs
, and DBSP_DRP final data output.- Parameters:
args (argparse.Namespace) – input arguments
- Raises:
LookupError – Raised if the input extension is not found in the input FITS file.
IndexError – Raised if the input integer extension is outside of the valid range for indexing the input FITS file’s extensions.
- dbsp_drp.show_spectrum.plot(wave: ndarray, flux: ndarray, err: ndarray, title: str) None [source]
Plots spectrum and error with sensible y-scale limits.
Flux and error have units of \(10^{-17}\mathrm{erg}/\mathrm{s}/\mathrm{cm}^2/\overset{\circ}{\mathrm{A}}\).
- Parameters:
wave (np.ndarray) – Wavelengh array
flux (np.ndarray) – Flux array
err (np.ndarray) – Flux error array
title (str) – Plot title.
- dbsp_drp.show_spectrum.sensible_ylim(wave: ndarray, flux: ndarray) Tuple[float, float] [source]
Returns a tuple of sensible y-axis limits for plotting spectra.
Usage:
>>> plt.step(wave, flux) >>> plt.ylim(sensible_ylim(wave, flux)) >>> plt.show()
- Parameters:
wave (np.ndarray) – wavelength array
flux (np.ndarray) – flux array
- Returns:
bottom, top
- Return type:
Tuple[float, float]
dbsp_drp.splicing module
Automated splicing for P200 DBSP.
- dbsp_drp.splicing.adjust_and_combine_overlap(spec_b: FITS_rec, spec_r: FITS_rec, interpolate_gaps: bool, red_mult: float = 1.0) Tuple[Tuple[ndarray, ndarray, ndarray], Tuple[ndarray, ndarray, ndarray], Tuple[ndarray, ndarray, ndarray]] [source]
Takes in red and blue spectra, adjusts overall flux level by red_mult, and combines overlap region.
In the overlap region, the red spectrum is linearly interpolated to match the blue spectrum’s wavelength spacing.
- Parameters:
spec_b (fits.FITS_rec) – blue spectrum
spec_r (fits.FITS_rec) – red spectrum.
interpolate_gaps (bool) – Interpolate across gaps in wavelength coverage?
red_mult (float, optional) – Factor multiplied into the red spectrum to match overal flux level with the blue spectrum. Defaults to 1.0.
- Raises:
ValueError – Raised when both spec_b and spec_r are empty or None.
- Returns:
- Tuple[
Tuple[np.ndarray, np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray, np.ndarray]
- ]: (blue, red, combined) spectra, where each spectrum is a tuple of
(wavelengths, flux, error)
- dbsp_drp.splicing.get_raw_hdus_from_spec1d(spec1d_list: List[Tuple[str, int]], root: str, output_path: str) List[BinTableHDU] [source]
Returns list of
fits.BinTableHDU
s, each containing the raw header and the 1D spectrum, of the input spec1d files.- Parameters:
spec1d_list (List[Tuple[str, int]]) – List of (spec1d filename, spatial pixel coordinate)
root (str) – Path to raw data files, possibly including filename prefix.
output_path (str) – reduction output path
- Returns:
- List of raw data headers and data from input
spec1d files.
- Return type:
List[fits.BinTableHDU]
- dbsp_drp.splicing.interp_w_error(x: ndarray, xp: ndarray, yp: ndarray, err_yp: ndarray, interpolate_gaps: bool) Tuple[ndarray, ndarray] [source]
Linearly interpolate the data points (
xp
,yp
) witherr_yp
uncertainty onto the gridx
.- Parameters:
x (np.ndarray) – destination x data
xp (np.ndarray) – source x data
yp (np.ndarray) – source y data
err_yp (np.ndarray) – source y error data
interpolate_gaps (bool) – Interpolate across gaps in
xp
?
- Returns:
Interpolated y and error.
- Return type:
Tuple[np.ndarray, np.ndarray]
- dbsp_drp.splicing.splice(splicing_dict: dict, interpolate_gaps: bool, root: str, output_path: str) None [source]
Splices red and blue spectra together.
splicing_dict[target_name][position_along_slit][arm] = { 'spec1ds': [(spec1d_filename_1, spatial_pixel_1), (spec1d_filename_2, spatial_pixel_2)], 'coadd': coadd_filename }
- Parameters:
splicing_dict (dict) – Guides splicing.
interpolate_gaps (bool) – Interpolate across gaps in wavelength coverage?
root (str) – Path to raw data files, possibly including filename prefix.
output_path (str) – reduction output path
dbsp_drp.table_edit module
- class dbsp_drp.table_edit.Delegate(parent, cols: tuple)[source]
Bases:
QStyledItemDelegate
- createEditor(self, parent: PySide2.QtWidgets.QWidget, option: PySide2.QtWidgets.QStyleOptionViewItem, index: PySide2.QtCore.QModelIndex) PySide2.QtWidgets.QWidget [source]
- setEditorData(self, editor: PySide2.QtWidgets.QWidget, index: PySide2.QtCore.QModelIndex) None [source]
- setModelData(self, editor: PySide2.QtWidgets.QWidget, model: PySide2.QtCore.QAbstractItemModel, index: PySide2.QtCore.QModelIndex) None [source]
- staticMetaObject = <PySide2.QtCore.QMetaObject object>
- class dbsp_drp.table_edit.MainWindow(data: Table, cols: tuple | None = None, del_files: list | None = None)[source]
Bases:
QMainWindow
- staticMetaObject = <PySide2.QtCore.QMetaObject object>
- class dbsp_drp.table_edit.TableModel(data: Table, cols: tuple | None = None, del_files: list | None = None)[source]
Bases:
QAbstractTableModel
- columnCount(self, parent: PySide2.QtCore.QModelIndex = Invalid(PySide2.QtCore.QModelIndex)) int [source]
- data(self, index: PySide2.QtCore.QModelIndex, role: int = PySide2.QtCore.Qt.ItemDataRole.DisplayRole) Any [source]
- headerData(self, section: int, orientation: PySide2.QtCore.Qt.Orientation, role: int = PySide2.QtCore.Qt.ItemDataRole.DisplayRole) Any [source]
- removeRows(self, row: int, count: int, parent: PySide2.QtCore.QModelIndex = Invalid(PySide2.QtCore.QModelIndex)) bool [source]
- rowCount(self, parent: PySide2.QtCore.QModelIndex = Invalid(PySide2.QtCore.QModelIndex)) int [source]
- setData(self, index: PySide2.QtCore.QModelIndex, value: Any, role: int = PySide2.QtCore.Qt.ItemDataRole.EditRole) bool [source]
- staticMetaObject = <PySide2.QtCore.QMetaObject object>
- class dbsp_drp.table_edit.TableView(model: QAbstractTableModel, parent=None)[source]
Bases:
QTableView
- staticMetaObject = <PySide2.QtCore.QMetaObject object>
- dbsp_drp.table_edit.get_zenith_ra_dec(time: str) SkyCoord [source]
Returns RA and Dec of the zenith at Palomar at the given time
- Parameters:
time (str) – MJD time
- Returns:
object containing the zenith RA and Dec
- Return type:
astropy.coordinates.SkyCoord
dbsp_drp.telluric module
Telluric correction for P200 DBSP.
- dbsp_drp.telluric.telluric_correct(coadd: str, output_path: str, spectrograph: str, user_config_lines: List[str], debug: bool = False, plot: bool = False)[source]
Telluric correct one coadd file.
- Parameters:
coadd (str) – Coadd filename.
output_path (str) – reduction output path
spectrograph (str) – PypeIt name of spectrograph.
user_config_lines (List[str]) – User-provided PypeIt configuration
debug (bool, optional) – Show debugging output? Defaults to False.
plot (bool, optional) – Show debugging plots? Defaults to False.
dbsp_drp.trim module
Command-line tool for tripping spliced spectrum to a specified wavelength range.