Skip to content

extract_spectrum_easyspec

Trace and extract a 1D spectrum from a 2D frame via easyspec.

Category Extraction (2-D to 1-D)
Backend easyspec - wraps the EasySpec reduction library (optional extra reduction)
Version 2.0.0
Reads -
Writes spectrum

Gaussian-weighted aperture extraction with Monte-Carlo error estimation. Pair the resulting pixel-index spectrum with wavelength_calibrate_easyspec (or the native polynomial calibrator) to get a proper wavelength solution. The pixel axis is 0-based (numpy.arange(npix)), like every other extractor. v2.0.0: when ctx.image is staged to disk, BZERO/BSCALE/BITPIX are no longer copied onto the float64 staging HDU — a uint16-headered frame ([100, 200, …] with BZERO=32768) used to be read back by easyspec as [32868, 32968, …]; the extracted flux is now correct for such inputs. easyspec sessions are serialised behind a process-wide lock (they chdir into a temporary directory).

Parameters

Parameter Default Required Description
target_path None - 2D science FITS to extract; falls back to ctx.image.
target_name 'target' - Label used internally by easyspec for diagnostics.
exposure_seconds None - Exposure time (seconds); null reads it from the FITS header.
airmass None - Airmass; null reads it from the FITS header.
exposure_header_entry 'AVEXP' - Header keyword for exposure when 'exposure_seconds' is null.
airmass_header_entry 'AVAIRMAS' - Header keyword for airmass when 'airmass' is null.
trace_method 'argmax' - Trace-finding method (easyspec: 'argmax' or 'fit').
trace_poly_order 2 - Polynomial order of the trace fit.
trace_half_width 7 - Half-width of the aperture (pixels).
trace_y_pixel_range 15 - Half-window for trace centroiding (pixels).
trace_n_slices 20 - Number of detector columns sampled to fit the trace.
trace_peak_height 100 - Minimum peak height when searching for the trace.
trace_peak_distance 50 - Minimum separation between peaks (pixels).
mc_steps 25 - Monte-Carlo realisations for the per-pixel flux error.
extraction_weights 'gaussian' - Aperture weighting: 'gaussian' or 'uniform'.
shift_y_pixels 30 - Allowed shift between tracing and extracting (pixels).

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("extract_spectrum_easyspec", ctx, {
    "target_path": None,
    "target_name": "target",
    "exposure_seconds": None,
    "airmass": None,
    "exposure_header_entry": "AVEXP",
    "airmass_header_entry": "AVAIRMAS",
    "trace_method": "argmax",
    "trace_poly_order": 2,
    "trace_half_width": 7,
    "trace_y_pixel_range": 15,
    "trace_n_slices": 20,
    "trace_peak_height": 100,
    "trace_peak_distance": 50,
    "mc_steps": 25,
    "extraction_weights": "gaussian",
    "shift_y_pixels": 30
})
spectro run extract_spectrum_easyspec --input spectrum.fits \
  --param target_path=none \
  --param target_name=target \
  --param exposure_seconds=none \
  --param airmass=none \
  --param exposure_header_entry=AVEXP \
  --param airmass_header_entry=AVAIRMAS \
  --param trace_method=argmax \
  --param trace_poly_order=2 \
  --param trace_half_width=7 \
  --param trace_y_pixel_range=15 \
  --param trace_n_slices=20 \
  --param trace_peak_height=100 \
  --param trace_peak_distance=50 \
  --param mc_steps=25 \
  --param extraction_weights=gaussian \
  --param shift_y_pixels=30
{
  "tool": "extract_spectrum_easyspec",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "target_path": null,
      "target_name": "target",
      "exposure_seconds": null,
      "airmass": null,
      "exposure_header_entry": "AVEXP",
      "airmass_header_entry": "AVAIRMAS",
      "trace_method": "argmax",
      "trace_poly_order": 2,
      "trace_half_width": 7,
      "trace_y_pixel_range": 15,
      "trace_n_slices": 20,
      "trace_peak_height": 100,
      "trace_peak_distance": 50,
      "mc_steps": 25,
      "extraction_weights": "gaussian",
      "shift_y_pixels": 30
    }
  }
}

Every algorithm is an MCP tool of the same name; describe_algorithm returns this page's metadata as JSON.

References

  • easyspec.extraction.extraction.{import_data, tracing, extracting}.