pypeit.gui.binospec_ifu_extract module

Matplotlib GUI for interactively selecting fibers from a fiber-fed IFU spec1d file and extracting a combined 1D spectrum.

class pypeit.gui.binospec_ifu_extract.BinospecIFUExtractGUI(fibers, raw_hdr, pyp_spec, outfile)[source]

Bases: object

Matplotlib widget GUI for selecting fibers and extracting spectra.

Displays the IFU as a hexagonal flux map, lets the user select fibers by drawing a region or clicking, and writes the combined selection as a OneSpec FITS file.

Parameters:
  • fibers (list of dict) – Per-fiber records (see pypeit.core.datacube.load_fibers()), each carrying wave, flux, ivar, ra, and dec.

  • raw_hdr (astropy.io.fits.Header) – Primary header of the source spec1d, copied to the output.

  • pyp_spec (str) – Spectrograph short name, written as PYP_SPEC on the output.

  • outfile (str) – Default output OneSpec FITS path.

_apply_spectrum_xlim()[source]

Sync the spectrum axis to the current slider window.

_create_gui()[source]

Build all GUI axes, widgets, and event connections.

_create_hexagon_plot()[source]

Populate ax_image with a hexagonal fiber array flux map.

_default_save_path()[source]

Return a non-clobbering default output path.

Starts from self.outfile (..._<base>.fits) and inserts a two-digit counter before the extension (..._<base>_00.fits), incrementing the counter until a path that does not already exist on disk is found.

Returns:

The first ..._<NN>.fits path (NN starting at 00) that does not yet exist.

Return type:

str

_draw_spectrum()[source]

Redraw the extracted spectrum honoring the current display toggles.

On a log scale, non-positive flux values (e.g. sky-subtraction residuals) are masked so they neither appear in the trace nor distort the axis limits. When sky-line masking is enabled, pixels within _SKY_LINE_MASK_HALFWIDTH of a line in _SKY_LINE_WAVELENGTHS are likewise masked.

_get_fiber_mask()[source]

Return a boolean mask of fibers inside self.selected_region.

Returns:

1D boolean array of length self.nspec, True for fibers whose sky position falls within the currently drawn selection region. Returns all-False if no region is defined.

Return type:

numpy.ndarray

_on_extract(event)[source]
_on_motion(event)[source]
_on_press(event)[source]
_on_release(event)[source]
_on_reset(event)[source]
_on_save(event)[source]
_on_shape_change(label)[source]
_on_skymask_change(label)[source]
_on_wave_change(val)[source]
_on_yscale_change(label)[source]
_selected_indices()[source]
_update_selection_display()[source]

Redraw hexagon edges to highlight selected fibers.

Fibers selected by the drawn region (_get_fiber_mask) or by individual clicks (self.clicked_fibers) are drawn with a thick cyan edge; all others revert to a thin gray edge.

show()[source]

Display the interactive GUI.

pypeit.gui.binospec_ifu_extract.compute_fiber_fluxes(waves, fluxes, wave_min, wave_max)[source]

Per-fiber integrated flux with sky-line masking.

Each fiber is integrated over its own native wavelength grid, with pixels in any sky-line region (see _SKY_LINE_WAVELENGTHS) excluded. Used to colour the fiber-IFU extractor display; the actual extracted spectrum (pypeit.core.datacube.resample_and_combine()) is unaffected.

Parameters:
  • waves (list of numpy.ndarray) – Per-fiber native wavelengths and fluxes (parallel lists).

  • fluxes (list of numpy.ndarray) – Per-fiber native wavelengths and fluxes (parallel lists).

  • wave_min (float) – Integration range, Angstrom.

  • wave_max (float) – Integration range, Angstrom.

Returns:

1D array of integrated fluxes, one per fiber.

Return type:

numpy.ndarray

pypeit.gui.binospec_ifu_extract.sky_line_mask(wave)[source]

Return a boolean mask that is True inside any sky-line region.

Parameters:

wave (numpy.ndarray) – 1D array of wavelengths in Angstrom.

Returns:

1D boolean array, same shape as wave, True where the wavelength falls within _SKY_LINE_MASK_HALFWIDTH of any line in _SKY_LINE_WAVELENGTHS.

Return type:

numpy.ndarray