|
| 1 | +.. _extraction_quickstart: |
| 2 | + |
| 3 | +Spectral Extraction Quick Start |
| 4 | +=============================== |
| 5 | + |
| 6 | +Specreduce provides flexible functionality for extracting a 1D spectrum from a 2D spectral image, |
| 7 | +including steps for determining the trace of a spectrum, background subtraction, and extraction. |
| 8 | + |
| 9 | + |
| 10 | +Tracing |
| 11 | +------- |
| 12 | + |
| 13 | +The `specreduce.tracing` module defines the trace of a spectrum on the 2D image. These |
| 14 | +traces can either be determined semi-automatically or manually, and are provided as the inputs for |
| 15 | +the remaining steps of the extraction process. Supported trace types include: |
| 16 | + |
| 17 | +* `~specreduce.tracing.ArrayTrace` |
| 18 | +* `~specreduce.tracing.FlatTrace` |
| 19 | +* `~specreduce.tracing.KosmosTrace` |
| 20 | + |
| 21 | + |
| 22 | +Each of these trace classes takes the 2D spectral image as input, as well as additional information |
| 23 | +needed to define or determine the trace (see the API docs above for required parameters for each |
| 24 | +of the available trace classes):: |
| 25 | + |
| 26 | + trace = specreduce.tracing.FlatTrace(image, 15) |
| 27 | + |
| 28 | + |
| 29 | +Background |
| 30 | +---------- |
| 31 | + |
| 32 | +The `specreduce.background` module generates and subtracts a background image from |
| 33 | +the input 2D spectral image. The `~specreduce.background.Background` object is defined by one |
| 34 | +or more windows, and can be generated with: |
| 35 | + |
| 36 | +* `~specreduce.background.Background` |
| 37 | +* `Background.one_sided <specreduce.background.Background.one_sided>` |
| 38 | +* `Background.two_sided <specreduce.background.Background.two_sided>` |
| 39 | + |
| 40 | +The center of the window can either be passed as a float/integer or as a trace:: |
| 41 | + |
| 42 | + bg = specreduce.tracing.Background.one_sided(image, trace, separation=5, width=2) |
| 43 | + |
| 44 | + |
| 45 | +or, equivalently:: |
| 46 | + |
| 47 | + bg = specreduce.tracing.Background.one_sided(image, 15, separation=5, width=2) |
| 48 | + |
| 49 | + |
| 50 | +The background image can be accessed via `~specreduce.background.Background.bkg_image` and the |
| 51 | +background-subtracted image via `~specreduce.background.Background.sub_image` (or ``image - bg``). |
| 52 | + |
| 53 | +The background and trace steps can be done iteratively, to refine an automated trace using the |
| 54 | +background-subtracted image as input. |
| 55 | + |
| 56 | +Extraction |
| 57 | +---------- |
| 58 | + |
| 59 | +The `specreduce.extract` module extracts a 1D spectrum from an input 2D spectrum (likely a |
| 60 | +background-extracted spectrum from the previous step) and a defined window, using one of the |
| 61 | +implemented methods: |
| 62 | + |
| 63 | +* `~specreduce.extract.BoxcarExtract` |
| 64 | +* `~specreduce.extract.HorneExtract` |
| 65 | + |
| 66 | +Each of these takes the input image and trace as inputs (see the API above for other required |
| 67 | +and optional parameters):: |
| 68 | + |
| 69 | + extract = specreduce.extract.BoxcarExtract(image-bg, trace, width=3) |
| 70 | + spectrum = extract.spectrum |
| 71 | + |
| 72 | +The returned ``extract`` object contains all the set options. The extracted 1D spectrum can be |
| 73 | +accessed via the ``spectrum`` property or by calling the ``extract`` object (which also allows |
| 74 | +temporarily overriding any values):: |
| 75 | + |
| 76 | + spectrum2 = extract(width=6) |
| 77 | + |
| 78 | +Example Workflow |
| 79 | +---------------- |
| 80 | + |
| 81 | +This will produce a 1D spectrum, with flux in units of the 2D spectrum. The wavelength units will |
| 82 | +be pixels. Wavelength and flux calibration steps are not included here. |
| 83 | + |
| 84 | +Putting all these steps together, a simple extraction process might look something like:: |
| 85 | + |
| 86 | + from specreduce.trace import FlatTrace |
| 87 | + from specreduce.background import Background |
| 88 | + from specreduce.extract import BoxcarExtract |
| 89 | + |
| 90 | + trace = FlatTrace(image, 15) |
| 91 | + bg = Background.two_sided(image, trace, separation=5, width=2) |
| 92 | + extract = BoxcarExtract(image-bg, trace, width=3) |
| 93 | + spectrum = extract.spectrum |
0 commit comments