<jupyter_start><jupyter_text>Spectractor tutorialThe goal of this notebook is to demonstrate the capabilities of the Spectractor pipeline.<jupyter_code>from spectractor.extractor.extractor import Spectractor
from spectractor.extractor.spectrum import Spectrum
from spectractor import parameters<jupyter_output><empty_output><jupyter_text>Basic usage The basic use of the extraction pipeline consists first to define: - the path to the fits image from which to extract the image, - the path of the output directory to save the extracted spectrum (created automatically if does not exist yet),- the rough or exect position of the object in the image,- the name of the disperser (as it is named in the `spectractor/extractor/dispersers/` folder),- the name of the config .ini file,- optionally the name of the target (to search for the extra-atmospheric spectrum if available).<jupyter_code>filename="../tests/data/reduc_20170530_134.fits"
output_directory="./outputs/"
guess = [745,643]
disperser_label = "HoloAmAg"
config = "../config/ctio.ini"
target_label = "HD111980"<jupyter_output><empty_output><jupyter_text>Then the spectrum is simply extracted from the image and saved in a new fits file using the command (it can take up to 5 minutes):<jupyter_code>spectrum = Spectractor(filename, output_directory, guess=guess, target_label=target_label, disperser_label=disperser_label, config=config)
spectrum.plot_spectrogram()<jupyter_output><empty_output><jupyter_text>Advanced usage  Verbose and debug modesThe default usage of the Spectractor function only prints warning on the screen. The format of the logging message gives first the time of execution, the class involved, the class method involved, the logging level, and a message.To show more details on the process followed by Spectractor, simply set VERBOSE variable to True. This also permit to plot the output spectrum on the screen:<jupyter_code>parameters.VERBOSE=True
Spectractor(filename, output_directory, guess=guess, target_label=target_label, disperser_label=disperser_label=disperser_label, config=config)<jupyter_output>2019-09-22 17:10:31  spectractor.extractor.extractor Spectractor          INFO   
	Start SPECTRACTOR
2019-09-22 17:10:31  Image      load_CTIO_image      INFO   
	Loading CTIO image ../tests/data/reduc_20170530_134.fits...
2019-09-22 17:10:31  Image      load_CTIO_image      INFO   
	Image ../tests/data/reduc_20170530_134.fits loaded.
2019-09-22 17:10:31  Image      load_image           INFO   
	Loading disperser HoloAmAg...<jupyter_text>In case of a suspected bug, user can enter the DEBUG mode, that gives more plots and outputs to check where the code may do something wrong. Note that VERBOSE mode is included in the DEBUG mode.<jupyter_code>parameters.DEBUG=True<jupyter_output><empty_output><jupyter_text>Image and Spectrum classes The Image and Spectrum classes have methods to load, save and plot images/spectra, and specific methods to extract the spectrum from the image. For instance, to load and plot the output spectrum, one can use:<jupyter_code>spec = Spectrum('./outputs/reduc_20170530_134_spectrum.fits')
spec.plot_spectrum()<jupyter_output>2019-09-22 17:12:34  Star       load                 INFO   
	Simbad:  MAIN_ID        RA           DEC      ... SP_QUAL_3     SP_BIBCODE_3   
             "h:m:s"       "d:m:s"    ...                              
--------- ------------- ------------- ... --------- -------------------
HD 111980 12 53 15.0528 -18 31 20.009 ...         C 1988MSS...C04....0H
2019-09-22 17:12:34  Spectrum   load_spectrum        INFO   
	Loading disperser HoloAmAg...
2019-09-22 17:12:34  Spectrum   load_spectrum        INFO   
	Spectrum loaded from ./outputs/reduc_20170530_134_spectrum.fits
2019-09-22 17:12:34  Spectrum   load_spectrogram     INFO   
	Spectrogram loaded from ./outputs/reduc_20170530_134_spectrogram.fits
2019-09-22 17:12:34  Spectrum   load_chromatic_psf   INFO   
	Spectrogram loaded from ./outputs/reduc_20170530_134_table.csv<jupyter_text>Spectractor settingsSome settings parameters are defined in the XWINDOW python file. For instance the half-width (in pixel) of the search windows to find the object in the images are set by:<jupyter_code>print('Width of search window along X in pixels:',parameters.XWINDOW)
print('Width of search window along Y in pixels:',parameters.YWINDOW)<jupyter_output>Width of search window along X in pixels: 100
Width of search window along Y in pixels: 100<jupyter_text>and in the rotated images by:<jupyter_code>print('Width of search window along X in pixels:',parameters.XWINDOW_ROT)
print('Width of search window along Y in pixels:',parameters.YWINDOW_ROT)<jupyter_output>Width of search window along X in pixels: 50
Width of search window along Y in pixels: 50<jupyter_text>The edges of the output spectrum are floats specified by the LAMBDA_MIN and LAMBDA_MAX parameters (in nanometers):<jupyter_code>print('Minimum wavelenght:',parameters.LAMBDA_MIN,'nm')
print('Maximum wavelenght:',parameters.LAMBDA_MAX,'nm')<jupyter_output>Minimum wavelenght: 300 nm
Maximum wavelenght: 1100 nm
{'fraction_non_alphanumeric': 0.08326771653543306, 'fraction_numerical': 0.05255905511811024, 'mean_word_length': 4.3092998955067925, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '180739', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1472, 'n_words': 517, 'path': 'notebooks/Spectractor tutorial.ipynb', 'repo_name': 'lsst/Spectractor', 'size': '5080'}