Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

# Spectractor

The goal of Spectractor is to measure the atmospheric transmission and intempt extracting spectra from slitless spectrophotometric images. It has been optimized on CTIO images but can be configured to analyse any kind of slitless data that contains the order 0 and the order 1 of a spectrum. In particular it can be used to estimate the atmospheric transmission of the LSST site using the dedicated Auxiliary Telescope.
The goal of Spectractor is to measure the atmospheric transmission and attempt to extract spectra from slitless spectrophotometric images. It has been optimized on CTIO images but can be configured to analyse any kind of slitless data that contains the order 0 and the order 1 of a spectrum. In particular it can be used to estimate the atmospheric transmission of the LSST site using the dedicated Auxiliary Telescope.

Spectractor is structured in three subpackages:
- `spectractor.extractor`: extracts as most information as possible from a slitless data image, as the amplitude of the spectrum, the PSF evolution with the wavelength, the pixel to wavelength calibration, an estimate of the background under the spectrum, the position of the order 0;
- `spectractor.simulation`: contains all the tools to simulate a spectrogram, as the atmospheric transmission simulation, the inclusion of instrumental throughput, the simulation of mock slitless data images;
Spectractor is structured in three subpackages:
- `spectractor.extractor`: extracts as much information as possible from a slitless data image, such as the amplitude of the spectrum, the PSF evolution with the wavelength, the pixel to wavelength calibration, an estimate of the background under the spectrum, and the position of the order 0;
- `spectractor.simulation`: contains all the tools to simulate a spectrogram, such as atmospheric transmission simulation, the inclusion of instrumental throughput, the simulation of mock slitless data images;
- `spectractor.fit`: compares the extracted data with simulations to estimate the atmospheric transmission and refine the spectral extraction.

Some submodules complete the structures with generic functions:
- `spectractor.parameters`: contains all the global parameters of Spectractor to set its general behaviour, the instrumental characteritics, etc;
Some submodules complete the structure with generic functions:
- `spectractor.parameters`: contains all the global parameters of Spectractor to set its general behaviour, the instrumental characteristics, etc;
- `spectractor.config`: tools to read config `.ini` text files and set the global parameters;
- `spectractor.logbook`: tools to read logbook `.csv` text files and get some metadata relative to the data images that are not contained in the header;
- `spectractor.tools`: contains generic functions shared by all the subpackages (fitting procedures, plotting functions, etc).
- `spectractor.tools`: contains generic functions shared by all the subpackages (fitting procedures, plotting functions, etc).

## Installation

Expand Down Expand Up @@ -50,9 +50,9 @@ Spectractor is able to perform parameter fits using the MCMC library [emcee](htt
## Basic extraction

The main file is `spectractor/extractor/extractor.py` with the function `Spectractor`. It extracts the spectrum from a science data image (deflatted, debiased), given:
- the path to the FITS image from which to extract the image,
- 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 it does not exist yet),
- the rough pr exact position of the object in the image (in pixels),
- the rough or exact position of the object in the image (in pixels),
- 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).
Expand All @@ -66,7 +66,7 @@ config = "./config/ctio.ini"
target = "HD111980"
```

Then the spectrum is simply extracted from the image and saved in a new fits file using the `Spectractor` function:
Then the spectrum is simply extracted from the image and saved in a new FITS file using the `Spectractor` function:
```
spectrum = Spectractor(filename, output_directory, guess=guess, target_label=target, disperser_label=disperser_label, config=config)
```
Expand Down
8 changes: 4 additions & 4 deletions spectractor/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def load_gaia_catalog_around_target(self):
def load_sources_from_file(self):
"""Load the sources from the class associated self.sources_file_name file.

By default, the creation of an Astrometry class instance try to load the default
By default, the creation of an Astrometry class instance tries to load the default
source file if it exists.

Returns
Expand All @@ -397,7 +397,7 @@ def load_sources_from_file(self):
return sources

def get_target_pixel_position(self):
"""Gives the principal targetted object position in pixels in the image given the WCS.
"""Gives the principal targeted object position in pixels in the image given the WCS.
The object proper motion is taken into account.

Returns
Expand Down Expand Up @@ -495,7 +495,7 @@ def get_quad_stars_pixel_positions(self):
if np.sum(coord) > 0:
coords.append(coord)
if len(coords) < 4:
self.my_logger.warning(f"\n\tOnly {len(coords)} calibration stars has been extracted from "
self.my_logger.warning(f"\n\tOnly {len(coords)} calibration stars have been extracted from "
f"{self.match_file_name}, with positions {coords}. "
f"A quad of at least 4 stars is expected. "
f"Please check {self.match_file_name}.")
Expand Down Expand Up @@ -754,7 +754,7 @@ def plot_astrometry_shifts(self, vmax=3, margin=parameters.CCD_IMSIZE):

def set_constraints(self, min_stars=100, flux_log10_threshold=0.1, min_range=3 * u.arcsec, max_range=5 * u.arcmin,
max_sep=1 * u.arcsec):
"""Gives a boolean array for sources that respect certain criterai (see below).
"""Gives a boolean array for sources that respect certain criteria (see below).

Parameters
----------
Expand Down
3 changes: 1 addition & 2 deletions spectractor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def from_config_to_dict(path):
"""Convert config file keywords into dictionnary.
"""Convert config file keywords into dictionary.
Parameters
----------
Expand Down Expand Up @@ -243,7 +243,6 @@ def set_logger(logger):
>>> parameters.DEBUG = True
>>> test = Test()
>>> test.log()
"""
my_logger = logging.getLogger(logger)
my_format = "%(asctime)-20s %(name)-10s %(funcName)-20s %(levelname)-6s %(message)s"
Expand Down
4 changes: 2 additions & 2 deletions spectractor/config/auxtel.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ OBS_EPOCH = J2000.0
# observed object to choose between STAR, HG-AR, MONOCHROMATOR
OBS_OBJECT_TYPE = STAR
# full instrument transmission file
OBS_FULL_INSTRUMENT_TRANSMISSON = multispectra_holo4_003_HD142331_AuxTel_throughput.txt
OBS_FULL_INSTRUMENT_TRANSMISSION = multispectra_holo4_003_HD142331_AuxTel_throughput.txt
# systematics on the instrument transmission
OBS_TRANSMISSION_SYSTEMATICS = 0.005
# Camera (x,y) rotation angle with respect to (north-up, east-left) system
Expand Down Expand Up @@ -121,7 +121,7 @@ PSF_PIXEL_STEP_TRANSVERSE_FIT = 50
PSF_FWHM_CLIP = 2

[detection line algorithm parameters]
# order of the background polynome to fit
# order of the background polynomial to fit
CALIB_BGD_ORDER = 3
# half range to look for local extrema in pixels around tabulated line values
CALIB_PEAK_WIDTH = 7
Expand Down
4 changes: 2 additions & 2 deletions spectractor/config/auxtel_quicklook.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ OBS_EPOCH = J2000.0
# observed object to choose between STAR, HG-AR, MONOCHROMATOR
OBS_OBJECT_TYPE = STAR
# full instrument transmission file
OBS_FULL_INSTRUMENT_TRANSMISSON = multispectra_holo4_003_HD142331_AuxTel_throughput.txt
OBS_FULL_INSTRUMENT_TRANSMISSION = multispectra_holo4_003_HD142331_AuxTel_throughput.txt
# systematics on the instrument transmission
OBS_TRANSMISSION_SYSTEMATICS = 0.005
# Camera (x,y) rotation angle with respect to (north-up, east-left) system
Expand Down Expand Up @@ -109,7 +109,7 @@ PSF_FIT_REG_PARAM = 1
PSF_PIXEL_STEP_TRANSVERSE_FIT = 50

[detection line algorithm parameters]
# order of the background polynome to fit
# order of the background polynomial to fit
CALIB_BGD_ORDER = 3
# half range to look for local extrema in pixels around tabulated line values
CALIB_PEAK_WIDTH = 7
Expand Down
4 changes: 2 additions & 2 deletions spectractor/config/ctio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OBS_EPOCH = J2000.0
# observed object to choose between STAR, HG-AR, MONOCHROMATOR
OBS_OBJECT_TYPE = STAR
# full instrument transmission file
OBS_FULL_INSTRUMENT_TRANSMISSON = multispectra_Thor300_HD111980_CTIO_throughput_prod7.5.4.txt
OBS_FULL_INSTRUMENT_TRANSMISSION = multispectra_Thor300_HD111980_CTIO_throughput_prod7.5.4.txt
# systematics on the instrument transmission
OBS_TRANSMISSION_SYSTEMATICS = 0.0
# Camera (x,y) rotation angle with respect to (north-up, east-left) system
Expand Down Expand Up @@ -113,7 +113,7 @@ PSF_PIXEL_STEP_TRANSVERSE_FIT = 10
PSF_FWHM_CLIP = 2

[detection line algorithm parameters]
# order of the background polynome to fit
# order of the background polynomial to fit
CALIB_BGD_ORDER = 3
# half range to look for local extrema in pixels around tabulated line values
CALIB_PEAK_WIDTH = 7
Expand Down
4 changes: 2 additions & 2 deletions spectractor/config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ OBS_EPOCH = J2000.0
# observed object to choose between STAR, HG-AR, MONOCHROMATOR
OBS_OBJECT_TYPE = STAR
# full instrument transmission file
OBS_FULL_INSTRUMENT_TRANSMISSON = ctio_throughput_300517_v2.txt
OBS_FULL_INSTRUMENT_TRANSMISSION = ctio_throughput_300517_v2.txt
# systematics on the instrument transmission
OBS_TRANSMISSION_SYSTEMATICS = 0

Expand Down Expand Up @@ -125,7 +125,7 @@ PSF_FIT_REG_PARAM = 0.01
PSF_POLY_TYPE = polynomial

[detection line algorithm parameters]
# order of the background polynome to fit
# order of the background polynomial to fit
CALIB_BGD_ORDER = 3
# half range to look for local extrema in pixels around tabulated line values
CALIB_PEAK_WIDTH = 7
Expand Down
2 changes: 1 addition & 1 deletion spectractor/config/lpnhe.ini
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ PSF_FIT_REG_PARAM = 0.01
PSF_PIXEL_STEP_TRANSVERSE_FIT = 10

[detection line algorithm parameters]
# order of the background polynome to fit
# order of the background polynomial to fit
CALIB_BGD_ORDER = 3
# half range to look for local extrema in pixels around tabulated line values
CALIB_PEAK_WIDTH = 3
Expand Down
4 changes: 2 additions & 2 deletions spectractor/config/stardice.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OBS_EPOCH = J2000.0
# observed object to choose between STAR, HG-AR, MONOCHROMATOR
OBS_OBJECT_TYPE = STAR
# full instrument transmission file
OBS_FULL_INSTRUMENT_TRANSMISSON = StarDice_EMPTY_response_75um_pinhole.txt
OBS_FULL_INSTRUMENT_TRANSMISSION = StarDice_EMPTY_response_75um_pinhole.txt
# systematics on the instrument transmission
OBS_TRANSMISSION_SYSTEMATICS = 0.005
# Camera (x,y) rotation angle with respect to (north-up, east-left) system
Expand Down Expand Up @@ -117,7 +117,7 @@ PSF_PIXEL_STEP_TRANSVERSE_FIT = 10
PSF_FWHM_CLIP = 2

[detection line algorithm parameters]
# order of the background polynome to fit
# order of the background polynomial to fit
CALIB_BGD_ORDER = 3
# half range to look for local extrema in pixels around tabulated line values
CALIB_PEAK_WIDTH = 7
Expand Down
14 changes: 7 additions & 7 deletions spectractor/extractor/chromaticpsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def init_from_table(self, table, saturation=None):
self.saturation = saturation
if saturation is None:
self.saturation = 1e20
self.my_logger.warning(f"\n\tSaturation level should be given to instanciate the ChromaticPSF "
self.my_logger.warning(f"\n\tSaturation level should be given to instantiate the ChromaticPSF "
f"object. self.saturation is set arbitrarily to 1e20. Good luck.")
for name in self.psf.params.labels:
if "amplitude" in name:
Expand Down Expand Up @@ -619,8 +619,8 @@ def convolve_psf_cube_masked(psf_cube_masked):

@staticmethod
def set_rectangular_boundaries(psf_cube_masked):
"""Compute the ChromaticPSF computation boundaries, as a dictionnary of integers giving
the `"xmin"`, `"xmax"`, `"ymin"` and `"ymax"` edges where to compute the PSF for each wavelength.
"""Compute the ChromaticPSF computation boundaries, as a dictionary of integers giving
the `"xmin"`, `"xmax"`, `"ymin"` and `"ymax"` edges where the PSF is computed for each wavelength.
True regions are rectangular after this operation. The `psf_cube_masked` cube is updated accordingly and returned.

Parameters
Expand All @@ -631,7 +631,7 @@ def set_rectangular_boundaries(psf_cube_masked):
Returns
-------
boundaries: dict
The dictionnary of PSF edges per wavelength.
The dictionary of PSF edges per wavelength.
psf_cube_masked: np.ndarray
Updated cube of boolean values where `psf_cube` cube is positive, eventually convolved.

Expand Down Expand Up @@ -684,12 +684,12 @@ def set_rectangular_boundaries(psf_cube_masked):
return boundaries, psf_cube_masked

def get_sparse_indices(self, boundaries):
"""Methods that returns the indices to build sparse matrices from rectangular `boundaries`.
"""Method that returns the indices to build sparse matrices from rectangular `boundaries`.

Parameters
----------
boundaries: dict
The dictionnary of PSF edges per wavelength.
The dictionary of PSF edges per wavelength.

Returns
-------
Expand Down Expand Up @@ -1813,7 +1813,7 @@ def fit_chromatic_psf(self, data, mask=None, bgd_model_func=None, data_errors=No
# first fit order 0 terms
w.my_logger.info("\n\tFit order 0 parameters...")
fixed_default = np.copy(w.params.fixed)
# fix higher order coefficients of polynomes
# fix higher-order coefficients of polynomials
for k in range(w.params.ndim):
if "_0" not in w.params.labels[k] and not w.params.fixed[k]:
w.params.fixed[k] = True # _k parameters that are yet fixed
Expand Down
2 changes: 1 addition & 1 deletion spectractor/extractor/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, spectrum, amplitude_priors_method="noprior", verbose=False, p
params.fixed[params.get_index("A2")] = (not spectrum.disperser.flat_ratio_order_2over1) and (not ("A2_T" in spectrum.header))
if spectrum.spectrogram_starfield is None:
params.fixed[params.get_index("A_star")] = True # Astar
params.fixed[params.get_index("D_CCD [mm]")] = True # D2CCD: spectrogram can not tell something on this parameter: rely on calibrate_spectrum
params.fixed[params.get_index("D_CCD [mm]")] = True # D2CCD: spectrogram cannot constrain this parameter: rely on calibrate_spectrum
params.fixed[params.get_index("shift_x [pix]")] = True # delta x: if False, extracted spectrum is biased compared with truth
params.fixed[params.get_index("shift_y [pix]")] = False # delta y
params.fixed[params.get_index("angle [deg]")] = False # angle
Expand Down
Loading