Spectral Reduction API

class aspired.spectral_reduction.Spectrum1D(spec_id=None, verbose=True, logger_name='Spectrum1D', log_level='INFO', log_file_folder='default', log_file_name=None)[source]

Base class of a 1D spectral object to hold the information of each extracted spectrum and the raw headers if was provided during the data reduction. The FITS or CSV file output are all done here.

Initialise the object with a logger.

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object. Note that this ID is unique in each reduction only.
  • verbose (boolean (Default: True)) – Set to False to suppress all verbose warnings, except for critical failure.
  • logger_name (str (Default: Spectrum1D)) – This will set the name of the logger, if the name is used already, it will reference to the existing logger. This will be the first part of the default log file name unless log_file_name is provided.
  • log_level (str (Default: 'INFO')) – Four levels of logging are available, in decreasing order of information and increasing order of severity: (1) DEBUG, (2) INFO, (3) WARNING, (4) ERROR and (5) CRITICAL. WARNING means that there is suboptimal operations in some parts of that step. ERROR means that the requested operation cannot be performed, but the software can handle it by either using the default setting or skipping the operation. CRITICAL means that the requested operation cannot be resolved without human interaction, this is most usually coming from missing data.
  • log_file_folder (None or str (Default: "default")) – Folder in which the file is save, set to default to save to the current path.
  • log_file_name (None or str (Default: None)) – File name of the log, set to None to self.logger.warning to screen only.
add_airmass(airmass)[source]

Add the airmass when the observation was carried out. This value can be different from the one in the header as this can be overwritten by an user input, while the header value is raw.

Parameters:airmass (float) – The effective airmass during the exposure.
add_aperture(widthdn, widthup, sepdn, sepup, skywidthdn, skywidthup)[source]

The size of the aperture in which the spectrum is extracted. This is merely the limit where extraction is performed, it does not hold the information of the weighting:

            .................................   ^
Sky         .................................   |   skywidthup
            .................................   v
            .................................     ^
            .................................     | sepup
            .................................     v
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   ^
            ---------------------------------   |   widthup
Spectrum    =================================   v ^
            ---------------------------------     | widthdn
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     v
            .................................   ^
            .................................   |   sepdn
            .................................   v
            .................................     ^
Sky         .................................     | skywidthdn
            .................................     v
Parameters:
  • widthdn (real positive number) – The aperture size on the bottom side of the spectrum.
  • widthup (real positive number) – The aperture size on the top side of the spectrum.
  • sepdn (real positive number) – The gap between the spectrum and the sky region on the bottom side of the spectrum.
  • sepup (real positive number) – The gap between the spectrum and the sky region on the top side of the spectrum.
  • skywidthdn (real positive number) – The sky region on the bottom side of the spectrum.
  • skywidthup (real positive number) – The sky region on the top side of the spectrum.
add_arc_header(header)[source]

Add a header for the arc that it is wavelength calibrated against. Typically put the header of the raw 2D spectral image of the arc here. Some automated operations rely on reading from the header.

Parameters:header (astropy.io.fits.Header object) –
add_arc_spec(arc_spec)[source]

Add the extracted 1D spectrum of the arc.

Parameters:arc_spec (1-d array) – The photoelectron count of the spectrum of the arc lamp.
add_atlas_wavelength_range(min_atlas_wavelength, max_atlas_wavelength)[source]

Add the allowed range of wavelength calibration.

Parameters:
  • min_atlas_wavelength (float) – The minimum wavelength of the atlas.
  • max_atlas_wavelength (float) – The maximum wavelength of the atlas.
add_calibrator(calibrator)[source]

Add a RASCAL Calibrator object.

Parameters:calibrator (rascal.Calibrator()) – A RASCAL Calibrator object.
add_calibrator_properties(num_pix, pixel_list, plotting_library, log_level)[source]

Add the properties of the RASCAL Calibrator.

Parameters:
  • num_pix (int) – The number of pixels in the dispersion direction
  • pixel_list (list or numpy array) – The pixel position of the trace in the dispersion direction. This should be provided if you wish to override the default range(num_pix), for example, in the case of accounting for chip gaps (10 pixels) in a 3-CCD setting, you should provide [0,1,2,…90, 100,101,…190, 200,201,…290]
  • plotting_library (string) – Choose between matplotlib and plotly.
  • log_level (string) – Choose from {CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET}.
add_count(count, count_err=None, count_sky=None)[source]

Add the photoelectron counts and the associated optional uncertainty and sky counts.

Parameters:
  • count (1-d array) – The summed count at each column along the trace.
  • count_err (1-d array) – the uncertainties of the count values
  • count_sky (1-d array) – The integrated sky values along each column, suitable for subtracting from the output of ap_extract
add_count_continuum(count_continuum)[source]

Add the continuum count value (should be the same size as count).

Parameters:count_continuum (list or 1-d array) – The photoelectron count of the continuum.
add_count_resampled(count_resampled, count_err_resampled, count_sky_resampled)[source]

Add the photoelectron counts of the resampled spectrum which has an evenly distributed wavelength spacing.

Parameters:
  • count_resampled (list or 1d-array) – The resampled photoelectron count.
  • count_err_resampled (list or 1d-array) – The uncertainty of the resampled photoelectron count.
  • count_sky_resampled (list or 1d-array) – The background sky level of the resampled photoelectron count.
add_count_resampled_continuum(count_resampled_continuum)[source]

Add the continuum count_resampled value (should be the same size as count_resampled).

Parameters:count_resampled_continuum (list or 1-d array) – The photoelectron count of the continuum at the resampled wavelength.
add_exptime(exptime)[source]

Add the exposure time of the spectral image. This value can be different from the one in the header as this can be overwritten by an user input, while the header value is raw.

Parameters:exptime (float) – The exposure time of the input image.
add_fit_coeff(fit_coeff)[source]

Add the polynomial co-efficients of the pixel-to-wavelength function. Note that this overwrites the wavelength calibrated fit coefficients.

Parameters:fit_coeff (list or 1-d array) – The set of coefficients of the pixel-wavelength function.
add_fit_output_final(fit_coeff, matched_peaks, matched_atlas, rms, residual, peak_utilisation, atlas_utilisation)[source]

Add the final accepted polynomial solution.

Parameters:
  • fit_coeff (list) – Set the baseline of the least square fit. If no fits outform this set of polynomial coefficients, this will be used as the best fit.
  • matched_peaks (list) – List of matched peaks
  • matched_atlas (list) – List of matched atlas lines
  • rms (float) – The root-mean-squared of the fit
  • residual (list) – The residual of each fitted peak
  • peak_utilisation (float) – The fraction of the input peaks used in the fit
  • atlas_utilisation (float) – The fraction of the input atlas used in the fit
add_fit_output_rascal(fit_coeff, matched_peaks, matched_atlas, rms, residual, peak_utilisation, atlas_utilisation)[source]

Add the RASCAL polynomial solution.

Parameters:
  • fit_coeff (list) – Set the baseline of the least square fit. If no fits outform this set of polynomial coefficients, this will be used as the best fit.
  • matched_peaks (list) – List of matched peaks
  • matched_atlas (list) – List of matched atlas lines
  • rms (float) – The root-mean-squared of the fit
  • residual (list) – The residual of each fitted peak
  • peak_utilisation (float) – The fraction of the input peaks used in the fit
  • atlas_utilisation (float) – The fraction of the input atlas used in the fit
add_fit_output_refine(fit_coeff, matched_peaks, matched_atlas, rms, residual, peak_utilisation, atlas_utilisation)[source]

Add the refined RASCAL polynomial solution.

Parameters:
  • fit_coeff (list) – Set the baseline of the least square fit. If no fits outform this set of polynomial coefficients, this will be used as the best fit.
  • matched_peaks (list) – List of matched peaks
  • matched_atlas (list) – List of matched atlas lines
  • rms (float) – The root-mean-squared of the fit
  • residual (list) – The residual of each fitted peak
  • peak_utilisation (float) – The fraction of the input peaks used in the fit
  • atlas_utilisation (float) – The fraction of the input atlas used in the fit
add_fit_type(fit_type)[source]

Add the kind of polynomial used for fitting the pixel-to-wavelength function.

Parameters:fit_type (str) – The type of polynomial for fitting the pixel-wavelength function.
add_flux(flux, flux_err, flux_sky)[source]

Add the flux and the associated uncertainty and sky background in the raw pixel sampling.

Parameters:
  • flux (list or numpy.ndarray) – The flux at each extracted column of pixels.
  • flux_err (list or numpy.ndarray) – The uncertainty in flux at each extracted column of pixels.
  • flux_sky (list or numpy.ndarray) – The flux of the background sky at each extracted column of pixels.
add_flux_continuum(flux_continuum)[source]

Add the continuum flux value (should be the same size as flux).

Parameters:flux_continuum (list or 1-d array) – The flux of the continuum.
add_flux_resampled(flux_resampled, flux_err_resampled, flux_sky_resampled)[source]

Add the flux and the associated uncertainty and sky background of the resampled spectrum.

Parameters:
  • flux (list or numpy.ndarray) – The flux at the resampled wavelenth.
  • flux_err (list or numpy.ndarray) – The uncertainty in flux at the resampled wavelenth.
  • flux_sky (list or numpy.ndarray) – The flux of the background sky at the resampled wavelenth.
add_flux_resampled_continuum(flux_resampled_continuum)[source]

Add the continuum flux_resampled value (should be the same size as flux_resampled).

Parameters:flux_resampled_continuum (list or 1-d array) – The flux of the continuum at the resampled wavelength.
add_gain(gain)[source]

Add the gain value of the spectral image. This value can be different from the one in the header as this can be overwritten by an user input, while the header value is raw.

Parameters:gain (float) – The gain value of the detector.
add_hough_properties(num_slopes, xbins, ybins, min_wavelength, max_wavelength, range_tolerance, linearity_tolerance)[source]

Add the hough transform configuration of the RASCAL Calibrator.

Parameters:
  • num_slopes (int) – Number of slopes to consider during Hough transform
  • xbins (int) – Number of bins for Hough accumulation
  • ybins (int) – Number of bins for Hough accumulation
  • min_wavelength (float) – Minimum wavelength of the spectrum.
  • max_wavelength (float) – Maximum wavelength of the spectrum.
  • range_tolerance (float) – Estimation of the error on the provided spectral range e.g. 3000-5000 with tolerance 500 will search for solutions that may satisfy 2500-5500
  • linearity_tolerance (float) – A toleranceold (Ansgtroms) which defines some padding around the range tolerance to allow for non-linearity. This should be the maximum expected excursion from linearity.
add_literature_standard(wave_literature, flux_literature)[source]

Add the literature wavelength and flux values of the standard star used for calibration.

Parameters:
  • wave_literature (list or 1-d array) – The wavelength values of the literature standard used.
  • flux_literature (list or 1-d array) – The flux values of the literature standard used.
add_min_atlas_distance(min_atlas_distance)[source]

Add the minimum allowed line distance (only consider lines that passed the minimum intensity threshold) that were used for wavelength calibration.

Parameters:min_atlas_distance (float) – Minimum wavelength separation between neighbouring lines.
add_min_atlas_intensity(min_atlas_intensity)[source]

Add the minimum allowed line intensity (theoretical NIST value) that were used for wavelength calibration.

Parameters:min_atlas_intensity (float) – The minimum line strength used to get the atlas.
add_peaks(peaks)[source]

Add the pixel values (int) where arc lines are located.

Parameters:peaks (1-d array) – The pixel value of the identified peaks.
add_peaks_refined(peaks_refined)[source]

Add the refined pixel values (float) where arc lines are located.

Parameters:peaks (1-d array) – The pixel value of the refined peak positions.
add_peaks_wave(peaks_wave)[source]

Add the wavelength (Angstrom) of the arc lines.

Parameters:peaks (1-d array) – The wavelength value of the peaks.
add_pixel_list(pixel_list)[source]

Add the pixel list, which contain the effective pixel values that has accounted for chip gaps and non-integer pixel value.

Parameters:pixel_list (1-d array) – The effective position of the pixel.
add_pixel_mapping_itp(pixel_mapping_itp)[source]

Add the interpolated callable function that convert raw pixel values into effective pixel values.

Parameters:pixel_mapping_itp (callable function) – The mapping function for raw-effective pixel position.
add_profile(profile)[source]

Add the extraction profile.

Parameters:profile (1-d array) – The weight function of the extraction profile.
add_ransac_properties(sample_size, top_n_candidate, linear, filter_close, ransac_tolerance, candidate_weighted, hough_weight, minimum_matches, minimum_peak_utilisation, minimum_fit_error)[source]

Add the RANSAC properties of the RASCAL Calibrator.

Parameters:
  • sample_size (int) – Number of pixel-wavelength hough pairs to be used for each arc line being picked.
  • top_n_candidate (int) – Top ranked lines to be fitted.
  • linear (bool) – True to use the hough transformed gradient, otherwise, use the known polynomial.
  • filter_close (bool) – Remove the pairs that are out of bounds in the hough space.
  • ransac_tolerance (float) – The distance criteria (Angstroms) to be considered an inlier to a fit. This should be close to the size of the expected residuals on the final fit (e.g. 1A is typical)
  • candidate_weighted (bool) – Set to True to down-weight pairs that are far from the fit.
  • hough_weight (float or None) – Set to use the hough space to weigh the fit. The theoretical optimal weighting is unclear. The larger the value, the heavily it relies on the overdensity in the hough space for a good fit.
add_readnoise(readnoise)[source]

Add the readnoise value of the spectral image. This value can be different from the one in the header as this can be overwritten by an user input, while the header value is raw.

Parameters:readnoise (float) – The read noise value of the detector.
add_seeing(seeing)[source]

Add the seeing when the observation was carried out. This value can be different from the one in the header as this can be overwritten by an user input, while the header value is raw.

Parameters:seeing (float) – The effective seeing of the observation.
add_sensitivity(sensitivity)[source]

Add the sensitivity values for each pixel (the list from dividing the literature standard by the photoelectron count).

Parameters:sensitivity (list or 1-d array) – The sensitivity at the effective pixel.
add_sensitivity_func(sensitivity_func)[source]

Add the callable function of the sensitivity curve.

Parameters:sensitivity_func (callable function) – The sensitivity curve as a function of wavelength.
add_sensitivity_resampled(sensitivity_resampled)[source]

Add the sensitivity after the spectrum is resampled.

Parameters:sensitivity (list or 1-d array) – The sensitivity in the reasmpled space.
add_smoothing(smooth, slength, sorder)[source]

Add the SG smoothing parameters for computing the sensitivity curve.

Parameters:
  • smooth (bool) – Indicate if smoothing was applied.
  • slength (int) – The size of the smoothing window.
  • sorder (int) – The order of polynomial used for SG smoothing.
add_spectrum_header(header)[source]

Add a header for the spectrum. Typically put the header of the raw 2D spectral image of the science target(s) here. Some automated operations rely on reading from the header.

Parameters:header (astropy.io.fits.Header object) –
add_standard_header(header)[source]

Add a header for the standard star that it is flux calibrated against. The, if opted for, automatic atmospheric extinction correction is applied based on the airmass found in this header. Typically put the header of the raw 2D spectral image of the standard star here. Some automated operations rely on reading from the header.

Parameters:header (astropy.io.fits.Header object) –
add_standard_star(library, target)[source]

Add the name of the standard star and its source.

Parameters:
  • library (str) – The name of the colelction of standard stars.
  • target (str) – The name of the standard star.
add_telluric_factor(telluric_factor)[source]

Add the Telluric factor.

Parameters:telluric_factor (float) – The multiplier to the telluric profile that minimises the sum of the deviation of corrected spectrum from the continuum spectrum.
add_telluric_factor_resampled(telluric_factor_resampled)[source]

Add the Telluric factor found using the resampled flux.

Parameters:telluric_factor_resampled (float) – The multiplier to the telluric profile that minimises the sum of the deviation of corrected spectrum from the resampled continuum spectrum.
add_telluric_func(telluric_func)[source]

Add the Telluric interpolated function.

Parameters:telluric (Callable function) – A callable function to interpolate the telluric features [0, 1]
add_telluric_profile(telluric_profile)[source]

Add the Telluric profile - relative intensity at each pixel.

Parameters:telluric_profile (list or numpy.ndarray) – The relative intensity of the telluric absorption strength [0, 1]
add_telluric_profile_resampled(telluric_profile_resampled)[source]

Add the Telluric profile - relative intensity at each resampled wavelength.

Parameters:telluric_profile (list or numpy.ndarray) – The relative intensity of the telluric absorption strength [0, 1]
add_trace(trace, trace_sigma, pixel_list=None)[source]

Add the trace of the spectrum.

Parameters:
  • trace (list or numpy.ndarray (N)) – The spatial pixel value (can be sub-pixel) of the trace at each spectral position.
  • trace_sigma (list or numpy.ndarray (N)) – Standard deviation of the Gaussian profile of a trace
  • pixel_list (list or numpy array (Default: None)) – The pixel position of the trace in the dispersion direction. This should be provided if you wish to override the default range (num_pix), for example, in the case of accounting for chip gaps (10 pixels) in a 3-CCD setting, you should provide [0,1,2,…90, 100,101,…190, 200,201,…290]
add_variances(var)[source]

Add the weight map of the extraction.

Parameters:var (2-d array) – The weigh map of the input image for extraction.
add_wavelength(wave)[source]

Add the wavelength of each effective pixel.

Parameters:wave (list or 1d-array) – The wavelength values at each effective pixel.
add_wavelength_resampled(wave_resampled)[source]

Add the wavelength of the resampled spectrum which has an evenly distributed wavelength spacing.

Parameters:wave (list or 1d-array) – The resampled wavelength values.
add_weather_condition(pressure, temperature, relative_humidity)[source]

Add the pressure, temperature and relative humidity when the spectral image was taken. These value can be different from the ones in the header as this can be overwritten by an user input, while the header value is raw.

Parameters:
  • pressure (float) – The air pressure during the observation (in pascal).
  • temperature (float) – The temperature during the observation (in Kelvin).
  • relative_hhumidity (float) – The relative humidity during the observation (between 0 and 1).
create_arc_spec_fits()[source]

Create an ImageHDU for the spectrum of the arc lamp.

create_count_fits()[source]

Create an ImageHDU for the extracted spectrum in photoelectron counts.

create_count_resampled_fits()[source]

Create an ImageHDU for the extracted spectrum in photoelectron count at the resampled wavelengths.

create_fits(output, recreate=False, empty_primary_hdu=True, return_hdu_list=False)[source]

Create a HDU list, with a choice of any combination of the data, see below the ‘output’ parameters for details.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”:

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 3 HDUs
    Count, uncertainty, and sky (pixel)
    weight_map: 1 HDU
    Weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line position (pixel), and arc line effective position (pixel)
    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
    wavelength: 1 HDU
    Wavelength of each pixel
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    sensitivity: 1 HDU
    Sensitivity (pixel)
    flux: 4 HDUs
    Flux, uncertainty, and sky (pixel)
    sensitivity_resampled: 1 HDU
    Sensitivity (wavelength)
    flux_resampled: 4 HDUs
    Flux, uncertainty, and sky (wavelength)
  • recreate (boolean (Default: False)) – Set to True to overwrite the FITS data and header.
  • empty_primary_hdu (boolean (Default: True)) – Set to True to leave the Primary HDU blank.
  • return_hdu_list (boolean (Default: False)) – Set to True to return the HDU List.
create_flux_fits()[source]

Create an ImageHDU for the flux calibrated spectrum at each native pixel.

create_flux_resampled_fits()[source]

Create an ImageHDU for the flux calibrated spectrum at the resampled wavelength.

create_sensitivity_fits()[source]

Create an ImageHDU for the sensitivity at each of the native pixel.

create_sensitivity_resampled_fits()[source]

Create an ImageHDU for the sensitivity at the resampled wavelength.

create_trace_fits()[source]

Create an ImageHDU for the trace.

create_wavecal_fits()[source]

Create an ImageHDU for the polynomial coeffcients of the pixel-wavelength mapping function.

create_wavelength_fits()[source]

Create an ImageHDU for the wavelength at each of the native pixel.

create_weight_map_fits()[source]

Create an ImageHDU for the extraction profile weight function.

merge(spectrum1D, overwrite=False)[source]

This function copies all the info from the supplied spectrum1D to this one, including the spec_id.

Parameters:
  • spectrum1D (Spectrum1D object) – The source Spectrum1D to be deep copied over.
  • overwrite (boolean (Default: False)) – Set to True to overwrite all the data in this Spectrum1D.
modify_arc_spec_header(idx, method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 1 2 Arc spectrum Peaks (pixel) Peaks (sub-pixel)
modify_count_header(idx, method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 1 2 Photoelectron count Photoelectron count uncertainty Photoelectron count (sky)
modify_count_resampled_header(idx, method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 1 2 Photoelectron count Photoelectron count uncertainty Photoelectron count (sky)
modify_flux_header(idx, method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 1 2 Flux Flux uncertainty Flux (sky)
modify_flux_resampled_header(idx, method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 1 2 3 Flux Flux Uncertainty Flux Sky Sensitivity
modify_sensitivity_header(method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 Sensitivity
modify_sensitivity_resampled_header(method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 Sensitivity_resampled
modify_trace_header(idx, method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 1 Trace (pixel) Trace width (pixel)
modify_wavecal_header(method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None wavelength fits only has one ImageHDU so the idx is always 0

HDU Data
0 Best fit coefficients
modify_wavelength_header(method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None wavelength fits only has one ImageHDU so the idx is always 0

HDU Data
0 Wavelength value at each extracted pixel
modify_weight_map_header(method, *args)[source]

for method ‘set’, it takes keyword, value=None, comment=None, before=None, after=None

HDU Data
0 Line spread function
remove_airmass()[source]

Remove the airmass value.

remove_arc_header()[source]

Remove the arc_header.

remove_arc_spec()[source]

Remove the 1D spectrum of the arc.

remove_arc_spec_fits()[source]

Remove the arc_spec FITS HDUList.

remove_atlas_wavelength_range()[source]

Remove the atlas wavelength range.

remove_calibrator()[source]

Remove the Calibrator.

remove_calibrator_properties()[source]

Remove the properties of the RASCAL Calibrator as recorded in ASPIRED. This does NOT remove the calibrator properites INSIDE the calibrator.

remove_count()[source]

Remove the count, count_err and count_sky.

remove_count_continuum()[source]

Remove the continuum count values.

remove_count_fits()[source]

Remove the count FITS HDUList.

remove_count_resampled()[source]

Remove the photoelectron counts of the resampled spectrum.

remove_count_resampled_continuum()[source]

Remove the continuum count_resampled values.

remove_count_resampled_fits()[source]

Remove the count_resampled FITS HDUList.

remove_exptime()[source]

Remove the exptime value.

remove_fit_coeff()[source]

Remove the polynomial co-efficients of the pixel-to-wavelength function.

remove_fit_output_final()[source]

Remove the accepted polynomial solultion.

remove_fit_output_rascal()[source]

Remove the RASCAL polynomial solution.

remove_fit_output_refine()[source]

Remove the refined RASCAL polynomial solution.

remove_fit_type()[source]

Remove the chosen type of polynomial.

remove_flux()[source]

Remove the flux, uncertainty of flux, and background sky flux.

remove_flux_continuum()[source]

Remove the continuum flux values.

remove_flux_fits()[source]

Remove the flux FITS HDUList.

remove_flux_resampled()[source]

Remove the flux, uncertainty of flux, and background sky flux of the resampled spectrum.

remove_flux_resampled_continuum()[source]

Remove the continuum flux_resampled values.

remove_flux_resampled_fits()[source]

Remove the flux_resampled FITS HDUList.

remove_gain()[source]

Remove the gain value.

remove_hough_properties()[source]

Remove the hough transform configuration of the RASCAL Calibrator. This does NOT remove the hough transform configuration INSIDE the calibrator.

remove_literature_standard()[source]

Remove the literature wavelength and flux values of the standard star used for calibration

remove_min_atlas_distance()[source]

Remove the minimum distance between lines to be accepted.

remove_min_atlas_intensity()[source]

Remove the minimum atlas intensity.

remove_peaks()[source]

Remove the list of peaks.

remove_peaks_refined()[source]

Remove the list of refined peaks.

remove_peaks_wave()[source]

Remove the list of wavelengths of the arc lines.

remove_pixel_list()[source]

Remove the pixel list.

remove_pixel_mapping_itp()[source]

Remove the interpolation function that maps the pixel values to the effective pixel value.

remove_profile()[source]

Remove the extraction profile.

remove_ransac_properties()[source]

Remove the RANSAC properties of the RASCAL Calibrator.

remove_readnoise()[source]

Remove the readnoise value.

remove_seeing()[source]

Remove the seeing value.

remove_sensitivity()[source]

Remove the sensitivity values.

remove_sensitivity_func()[source]

Remove the sensitivity curve function.

remove_sensitivity_resampled()[source]

Remove the sensitivity after the spectrum is resampled.

remove_sensitivity_resampled_fits()[source]

Remove the sensitivity_resampled FITS HDUList.

remove_smoothing()[source]

Remove the smoothing parameters for computing the sensitivity curve.

remove_spectrum_header()[source]

Remove the FITS header of the target.

remove_standard_header()[source]

Remove the FITS header of the standard.

remove_standard_star()[source]

Remove the name of the standard star and its source.

remove_telluric_factor()[source]

Remove the Telluric factor.

remove_telluric_factor_resampled()[source]

Remove the Telluric factor for the resampled spectrum.

remove_telluric_func()[source]

Remove the Telluric interpolated function.

remove_telluric_profile()[source]

Remove the Telluric profile.

remove_telluric_profile_resampled()[source]

Remove the Telluric profile at the resampled wavelengths.

remove_trace()[source]

Remove the trace, trace_sigma and len_trace, also remove the pixel_list and the interpolation function that maps the pixel values to the effective pixel values.

remove_trace_fits()[source]

Remove the trace FITS HDUList.

remove_variances()[source]

Remove the variances.

remove_wavecal_fits()[source]

Remove the wavecal FITS HDUList.

remove_wavelength()[source]

Remove the wavelength of each effective pixel.

remove_wavelength_fits()[source]

Remove the wavelength FITS HDUList.

remove_wavelength_resampled()[source]

Add the resampled wavelength.

remove_wavelength_resampled_fits()[source]

Remove the resampled wavelength FITS HDUList.

remove_weather_condition()[source]

Remove the Pressure, Temperature and Humidity.

remove_weight_map_fits()[source]

Remove the weight_map FITS HDUList.

save_csv(output, filename, overwrite, recreate)[source]

Save the reduced data to disk, with a choice of any combination of the 5 sets of data, see below the ‘output’ parameters for details.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 4 HDUs
    Count, uncertainty, sky, and optimal flag (pixel)
    weight_map: 1 HDU
    Weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
    wavelength: 1 HDU
    Wavelength of each pixel
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    sensitivity: 1 HDU
    Sensitivity (pixel)
    flux: 4 HDUs
    Flux, uncertainty, and sky (pixel)
    sensitivity: 1 HDU
    Sensitivity (wavelength)
    flux_resampled: 3 HDUs
    Flux, uncertainty, and sky (wavelength)
  • filename (String) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • overwrite (boolean) – Default is False.
  • recreate (boolean (Default: False)) – Set to True to overwrite the FITS data and header.
save_fits(output, filename, overwrite=False, recreate=False, empty_primary_hdu=True)[source]

Save the reduced data to disk, with a choice of any combination of the data, see below the ‘output’ parameters for details.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 3 HDUs
    Count, uncertainty, and sky (pixel)
    weight_map: 1 HDU
    Weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
    wavelength: 1 HDU
    Wavelength of each pixel
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    sensitivity: 1 HDU
    Sensitivity (pixel)
    flux: 4 HDUs
    Flux, uncertainty, and sky (pixel)
    sensitivity: 1 HDU
    Sensitivity (wavelength)
    flux_resampled: 4 HDUs
    Flux, uncertainty, and sky (wavelength)
  • filename (str) – Filename for the output, all of them will share the same name but will have different extension.
  • overwrite (boolean) – Default is False.
  • recreate (boolean (Default: False)) – Set to True to overwrite the FITS data and header.
  • empty_primary_hdu (boolean (Default: True)) – Set to True to leave the Primary HDU blank (Default: True)
class aspired.spectral_reduction.TwoDSpec(data=None, header=None, verbose=True, logger_name='TwoDSpec', log_level='INFO', log_file_folder='default', log_file_name=None, **kwargs)[source]

This is a class for processing a 2D spectral image.

The constructor takes the data and the header, and the the header infromation will be read automatically. See set_properties() for the detail information of the keyword arguments. The extraction always consider the x-direction as the dispersion direction, while the y-direction as the spatial direction.

Parameters:
  • data (2D numpy array (M x N) OR astropy.io.fits object) – 2D spectral image in either format
  • header (FITS header (deafult: None)) – THIS WILL OVERRIDE the header from the astropy.io.fits object
  • verbose (bool (Default: True)) – Set to False to suppress all verbose warnings, except for critical failure.
  • logger_name (str (Default: TwoDSpec)) – This will set the name of the logger, if the name is used already, it will reference to the existing logger. This will be the first part of the default log file name unless log_file_name is provided.
  • log_level (str (Default: 'INFO')) – Four levels of logging are available, in decreasing order of information and increasing order of severity: (1) DEBUG, (2) INFO, (3) WARNING, (4) ERROR and (5) CRITICAL. WARNING means that there is is_optimal operations in some parts of that step. ERROR means that the requested operation cannot be performed, but the software can handle it by either using the default setting or skipping the operation. CRITICAL means that the requested operation cannot be resolved without human interaction, this is most usually coming from missing data.
  • log_file_folder (None or str (Default: "default")) – Folder in which the file is save, set to default to save to the current path.
  • log_file_name (None or str (Default: None)) – File name of the log, set to None to print to screen only.
  • **kwargs (keyword arguments (Default: see set_properties())) – see set_properties().
add_arc(arc, header=None)[source]

To provide an arc image. Make sure left (small index) is blue, right (large index) is red.

Parameters:
  • arc (numpy.ndarray, PrimaryHDU/ImageHDU, ImageReduction, str) – The image of the arc image.
  • header (FITS header (deafult: None)) – An astropy.io.fits.Header object. This is not used if arc is a PrimaryHDU or ImageHDU.
add_bad_mask(bad_mask=None)[source]

To provide a mask to ignore the bad pixels in the reduction.

Parameters:bad_mask (numpy.ndarray, PrimaryHDU/ImageHDU, ImageReduction, str) – The bad pixel mask of the image, make sure it is of the same size as the image and the right orientation.
add_data(data, header=None)[source]

Adding the 2D image data to be processed. The data can be a 2D numpy array, an AstroPy ImageHDU/Primary HDU object or an ImageReduction object.

Parameters:
  • data (2D numpy array (M x N) OR astropy.io.fits object) – 2D spectral image in either format
  • header (FITS header (deafult: None)) – THIS WILL OVERRIDE the header from the astropy.io.fits object
add_trace(trace, trace_sigma, spec_id=None)[source]

Add user-supplied trace. The trace has to have the size as the 2D spectral image in the spectral direction.

Parameters:
  • trace (list or numpy.ndarray (N)) – The spatial pixel value (can be sub-pixel) of the trace at each spectral position.
  • trace_sigma (list or numpy.ndarray (N)) – Standard deviation of the Gaussian profile of a trace
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
ap_extract(apwidth=7, skysep=3, skywidth=5, skydeg=1, sky_sigma=3.0, spec_id=None, optimal=True, algorithm='horne86', model='lowess', lowess_frac=0.1, lowess_it=3, lowess_delta=0.0, tolerance=1e-06, cosmicray_sigma=4.0, max_iter=99, forced=False, variances=None, npoly=21, polyspacing=1, pord=5, qmode='fast-linear', nreject=100, display=False, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

Extract the spectra using the traces, support tophat or optimal extraction. The sky background is fitted in one dimention only. The uncertainty at each pixel is also computed, but the values are only meaningful if correct gain and read noise are provided.

Tophat extraction: Float is accepted but will be rounded to an int,
which gives the constant aperture size on either side of the trace to extract.
Optimal extraction: Float or 1-d array of the same size as the trace.
If a float is supplied, a fixed standard deviation will be used to construct the gaussian weight function along the entire spectrum. (Choose from horne86 and marsh89 algorithm)

Nothing is returned unless return_jsonstring of the plotly graph is set to be returned. The count, count_sky and count_err are stored as properties of the TwoDSpec object.

count: 1-d array
The summed count at each column about the trace. Note: is not sky subtracted!
count_err: 1-d array
the uncertainties of the count values
count_sky: 1-d array
The integrated sky values along each column, suitable for subtracting from the output of ap_extract
Parameters:
  • apwidth (int or list of int (Default: 7)) – Half the size of the aperature (fixed value for tophat extraction). If a list of two ints are provided, the first element is the lower half of the aperture and the second one is the upper half.
  • skysep (int or list of int (Default: 3)) – The separation in pixels from the aperture to the sky window.
  • skywidth (int or list of int (Default: 5)) – The width in pixels of the sky windows on either side of the aperture. Zero (0) means ignore sky subtraction.
  • skydeg (int (Default: 1)) – The polynomial order to fit between the sky windows.
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • optimal (bool (Default: True)) – Set optimal extraction. (Default is True)
  • algorithm (str (Default: 'horne86')) – Available algorithms are horne86 and marsh89
  • model (str (Default: 'lowess')) – Choice of model: ‘lowess’ and ‘gauss’.
  • lowess_frac (float (Default: 0.1)) – Fraction of “good data” retained for LOWESS fit.
  • lowess_it (int (Default: 3)) – Number of iteration in LOWESS fit – the number of residual-based reweightings to perform.
  • lowess_delta (float (Default: 0.0)) – The delta parameter in LOWESS fit – distance within which to use linear-interpolation instead of weighted regression.
  • tolerance (float (Default: 1e-6)) – The tolerance limit for the convergence of the optimal extraction
  • cosmicray_sigma (float (Deafult: 4.0)) – Cosmic ray sigma clipping limit. This is for rejecting pixels when using horne87 and marsh89 optimal cleaning. Use sigclip in kwargs for configuring cosmicray cleaning with astroscrappy.
  • max_iter (float (Default: 99)) – The maximum number of iterations before optimal extraction fails and return to standard tophot extraction
  • forced (bool (Default: False)) – To perform forced optimal extraction by using the given aperture profile as it is without interation, the resulting uncertainty will almost certainly be wrong. This is an experimental feature.
  • variances (list or numpy.ndarray (Default: None, only used if algorithm) – is horne86) The weight function for forced extraction. It is only used if force is set to True.
  • npoly (int (Default: 21, only used if algorithm is marsh89)) – Number of profile to be use for polynomial fitting to evaluate (Marsh’s “K”). For symmetry, this should be odd.
  • polyspacing (float (Default: 1, only used if algorithm is marsh89)) – Spacing between profile polynomials, in pixels. (Marsh’s “S”). A few cursory tests suggests that the extraction precision (in the high S/N case) scales as S^-2 – but the code slows down as S^2.
  • pord (int (Default: 5, only used if algorithm is marsh89)) – Order of profile polynomials; 1 = linear, etc.
  • qmode (str (Default: 'fast-linear', only used if algorithm is marsh89)) – How to compute Marsh’s Q-matrix. Valid inputs are ‘fast-linear’, ‘slow-linear’, ‘fast-nearest’, and ‘slow-nearest’. These select between various methods of integrating the nearest-neighbor or linear interpolation schemes as described by Marsh; the ‘linear’ methods are preferred for accuracy. Use ‘slow’ if you are running out of memory when using the ‘fast’ array-based methods.
  • nreject (int (Default: 100, only used if algorithm is marsh89)) – Number of outlier-pixels to reject at each iteration.
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json str that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
ap_trace(nspec=1, smooth=False, nwindow=20, spec_sep=5, trace_width=15, resample_factor=4, rescale=False, scaling_min=0.9995, scaling_max=1.0005, scaling_step=0.001, percentile=5, shift_tol=10, fit_deg=3, ap_faint=20, display=False, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

Aperture tracing by first using cross-correlation then the peaks are fitting with a polynomial with an order of floor(nwindow, 10) with a minimum order of 1. Nothing is returned unless return_jsonstring of the plotly graph is set to be returned.

Each spectral slice is convolved with the adjacent one in the spectral direction. Basic tests show that the geometrical distortion from one end to the other in the spectral direction is small. With LT/SPRAT, the linear distortion is less than 0.5%, thus, even provided as an option, the rescale option is set to False by default. Given how unlikely a geometrical distortion correction is needed, higher order correction options are not provided.

A rough estimation on the background level is done by taking the n-th percentile of the slice, a rough guess can improve the cross-correlation process significantly due to low dynamic range in a typical spectral image. The removing of the “background” can massively improve the contrast between the peaks and the relative background, hence the correlation method is more likely to yield a true positive.

The trace(s), i.e. the spatial positions of the spectra (Y-axis), found will be stored as the properties of the TwoDSpec object as a 1D numpy array, of length N, which is the size of the spectrum after applying the spec_mask. The line spread function is stored in trace_sigma, by fitting a gaussian on the shift-corrected stack of the spectral slices. Given the scaling was found to be small, reporting a single value of the averaged gaussian sigma is sufficient as the first guess to be used by the aperture extraction function.

Parameters:
  • nspec (int) – Number of spectra to be extracted.
  • smooth (bool (Default: False)) – Set to true to apply a 3x3 median filter before tracing. Not recommended for use with faint spectrum.
  • nwindow (int) – Number of spectral slices (subspectra) to be produced for cross-correlation.
  • spec_sep (int) – Minimum separation between spectra (only if there are multiple sources on the longslit).
  • trace_width (int) – Distance from trace centre to be taken for profile fitting.
  • resample_factor (int) – Number of times the collapsed 1D slices in the spatial directions are to be upsampled.
  • rescale (bool) – Fit for the linear scaling factor between adjacent slices.
  • scaling_min (float) – Minimum scaling factor to be fitted.
  • scaling_max (float) – Maximum scaling factor to be fitted.
  • scaling_step (float) – Steps of the scaling factor.
  • percentile (float) – The percentile of the flux to be used as the estimate of the background sky level to the first order. [Count]
  • shift_tol (float) – Maximum allowed shift between neighbouring slices, this value is referring to native pixel size without the application of the resampling or rescaling. [pix]
  • fit_deg (int) – Degree of the polynomial fit of the trace.
  • ap_faint (float) – The percentile tolerance of Count aperture to be used for fitting the trace. Note that this percentile is of the Count, not of the number of subspectra.
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json str that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
Returns:

  • JSON-string if return_jsonstring is True, otherwise only an image is
  • displayed

apply_flip_to_arc()[source]

Apply flip to arc.

apply_mask_to_arc()[source]

Apply both the spec_mask and spatial_mask that are already stroed in the object.

apply_rectification()[source]

Accept the dispersion rectification computed.

apply_spatial_mask_to_arc(spatial_mask)[source]

Apply to use only the valid y-range of the chip (i.e. spatial direction)

Parameters:spatial_mask (1D numpy array (N)) – Mask in the spatial direction, can be the indices of the pixels to be included (size <N) or a 1D numpy array of True/False (size N) (Default is (1,) i.e. keep everything)
apply_spec_mask_to_arc(spec_mask)[source]

Apply to use only the valid x-range of the chip (i.e. dispersion direction)

Parameters:spec_mask (1D numpy array (M)) – Mask in the spectral direction, can be the indices of the pixels to be included (size <M) or a 1D numpy array of True/False (size M) (Default is (1,) i.e. keep everything)
apply_transpose_to_arc()[source]

Apply transpose to arc.

create_fits(output, recreate=False, empty_primary_hdu=True)[source]
Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strs are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 3 HDUs
    Count, uncertainty, and sky (pixel)
    weight_map: 1 HDU
    Weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
  • empty_primary_hdu (bool (Default: True)) – Set to True to leave the Primary HDU blank
extract_arc_spec(spec_id=None, spec_width=None, display=False, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

This function applies the trace(s) to the arc image then take median average of the stripe before identifying the arc lines (peaks) with scipy.signal.find_peaks(), where only the distance and the prominence keywords are used. Distance is the minimum separation between peaks, the default value is roughly twice the nyquist sampling rate (i.e. pixel size is 2.3 times smaller than the object that is being resolved, hence, the sepration between two clearly resolved peaks are ~5 pixels apart). A crude estimate of the background can exclude random noise which look like small peaks.

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • spec_width (int (Default: None)) – The number of pixels in the spatial direction used to sum for the arc spectrum
  • display (bool) – Set to True to display disgnostic plot.
  • renderer (str) – plotly renderer options.
  • width (int/float) – Number of pixels in the horizontal direction of the outputs
  • height (int/float) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool) – set to True to return json str that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool) – Open the iframe in the default browser if set to True.
get_rectification(upsample_factor=5, bin_size=6, n_bin=15, spline_order=3, order=2, coeff=None, use_arc=True, apply=False, display=False, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

ONLY possible if there is ONE trace. If more than one trace is provided, only the first one (i.e. spec_id = 0) will get processed.

The retification in the spatial direction depends on ONLY the trace, while that in the dispersion direction depends on the parameters provided here.

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • upsample_factor (float (Default: 10)) – The upsampling rate for the correlation (10 times means precise to 1/10 of a pixel). The upsampling uses cubic spline that is adopted in the scipy.ndimage.zoom() function.
  • bin_size (int (Default: 6)) – Number of rows in a slice.
  • n_bin (int (Default: 10)) – Number of slices parallel to the trace to be correlated to to compute the distortion in the dispersion direction. (i.e. there are 10 // 2 = 5 slices below and above the trace.)
  • spline_order (int (Default: 3)) – The order of spline for resampling.
  • order (int (Default: 2)) – The order of polynomial to fit for the distortion in the dispersion direction
  • coeff (list or numpy.ndarray (Default: None)) – The polynomial coefficients for aligned the dispersion direction as a function of distance from the trace.
  • apply (bool (Default: False)) – Apply the rectification directly without checking.
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json str that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
inspect_extracted_spectrum(spec_id=None, display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]
Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • display (bool) – Set to True to display disgnostic plot.
  • renderer (str) – plotly renderer options.
  • width (int/float) – Number of pixels in the horizontal direction of the outputs
  • height (int/float) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool) – set to True to return json str that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool) – Open the iframe in the default browser if set to True.
inspect_residual(log=True, display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

Display the reduced image with a supported plotly renderer or export as json strings.

Parameters:
  • log (bool) – Log the ADU count per second in the display. Default is True.
  • display (bool) – Set to True to display disgnostic plot.
  • renderer (str) – plotly renderer options.
  • width (int/float) – Number of pixels in the horizontal direction of the outputs
  • height (int/float) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the save_iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

remove_trace(spec_id=None)[source]
Parameters:spec_id (int) – The ID corresponding to the spectrum1D object
save_fits(output='trace+count', filename='TwoDSpecExtracted', overwrite=False, recreate=False, empty_primary_hdu=True)[source]

Save the reduced image to disk.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strs are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 3 HDUs
    Count, uncertainty, and sky (pixel)
    weight_map: 1 HDU
    Weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
  • filename (str) – Filename for the output, all of them will share the same name but will have different extension.
  • overwrite (bool) – Default is False.
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
  • empty_primary_hdu (bool (Default: True)) – Set to True to leave the Primary HDU blank
set_airmass(airmass=None)[source]

Set the airmass of the image.

Parameters:airmass (str, float, int or None (Default: None)) – If a string is provided, it will be treated as a header keyword for the airmass value. Float or int will be used as the airmass value. If None is provided, the header will be searched with the set of default airmass keywords.
set_airmass_keyword(keyword_list, append=False, update=True)[source]

Set the airmass keyword list.

Parameters:
  • keyword_list (list) – List of keyword (string).
  • append (bool (Default: False)) – Set to False to overwrite the current list.
  • update (bool (Default: True)) – Set to True to search for the readnoise after the new list is provided.
set_arc_header(header)[source]

Adding the header for the arc.

Parameters:header (FITS header (deafult: None)) – An astropy.io.fits.Header object. This is not used if arc is a PrimaryHDU or ImageHDU.
set_exptime(exptime=None)[source]

Set the exptime of the image.

Parameters:exptime (str, float, int or None (Default: None)) – If a string is provided, it will be treated as a header keyword for the exptime value. Float or int will be used as the exptime value. If None is provided, the header will be searched with the set of default exptime keywords.
set_exptime_keyword(keyword_list, append=False, update=True)[source]

Set the exptime keyword list.

Parameters:
  • keyword_list (list) – List of keyword (string).
  • append (bool (Default: False)) – Set to False to overwrite the current list.
  • update (bool (Default: True)) – Set to True to search for the readnoise after the new list is provided.
set_gain(gain=None)[source]

Set the gain of the image.

Parameters:gain (str, float, int or None (Default: None)) – If a string is provided, it will be treated as a header keyword for the gain value. Float or int will be used as the gain value. If None is provided, the header will be searched with the set of default gain keywords.
set_gain_keyword(keyword_list, append=False, update=True)[source]

Set the gain keyword list.

Parameters:
  • keyword_list (list) – List of keyword (string).
  • append (bool (Default: False)) – Set to False to overwrite the current list.
  • update (bool (Default: True)) – Set to True to search for the readnoise after the new list is provided.
set_header(header)[source]

Set/replace the header.

Parameters:header (astropy.io.fits.header.Header) – FITS header from a single HDU.
set_properties(saxis=None, variance=None, spatial_mask=None, spec_mask=None, flip=None, cosmicray=None, gain=-1, readnoise=-1, fsmode=None, psfmodel=None, seeing=-1, exptime=-1, airmass=-1, verbose=None, **kwargs)[source]

The read noise, detector gain, seeing and exposure time will be automatically extracted from the FITS header if it conforms with the IAUFWG FITS standard.

Currently, there is no automated way to decide if a flip is needed.

The supplied file should contain 2 or 3 columns with the following structure:

column 1: one of bias, dark, flat or light
column 2: file location
column 3: HDU number (default to 0 if not given)

If the 2D spectrum is

blue red saxis flip
left right 1 False
right left 1 True
top bottom 0 False
bottom top 0 True

Spectra are sorted by their brightness. If there are multiple spectra on the image, and the target is not the brightest source, use at least the number of spectra visible to eye and pick the one required later. The default automated outputs is the brightest one, which is the most common case for images from a long-slit spectrograph.

Parameters:
  • saxis (int (Default: 1)) – Spectral direction, 0 for vertical, 1 for horizontal.
  • variance (2D numpy array (M, N)) – The per-pixel-variance of the frame.
  • spatial_mask (1D numpy array (size: N. Default is (1,))) – Mask in the spatial direction, can be the indices of the pixels to be included (size <N) or a 1D numpy array of True/False (size N)
  • spec_mask (1D numpy array (Size: M. Default: (1,))) – Mask in the spectral direction, can be the indices of the pixels to be included (size <M) or a 1D numpy array of True/False (size M)
  • flip (bool (Deafult: False)) – If the frame has to be left-right flipped, set to True.
  • cosmicray (bool (Default: True)) – Set to True to remove cosmic rays, this directly alter the reduced image data. We only explicitly include the 4 most important parameters in this function: gain, readnoise, fsmode, and psfmodel, the rest can be configured with kwargs.
  • gain (float (Deafult: -1)) – Gain of the detector in unit of electron per photon, not important if noise estimation is not needed. Negative value means “pass”, i.e. do nothing. None means grabbing from the header, though if it is not found, it is set to 1.0.
  • readnoise (float (Deafult: -1)) – Readnoise of the detector in unit of electron, not important if noise estimation is not needed. Negative value means “pass”, i.e. do nothing. None means grabbing from the header, though if it is not found, it is set to 0.0.
  • fsmode (str (Default: None. Use 'convolve' if not set.)) – Method to build the fine structure image: median: Use the median filter in the standard LA Cosmic algorithm. convolve: Convolve the image with the psf kernel to calculate the fine structure image.
  • psfmodel (str (Default: None. Use 'gaussy' if not set.)) – Model to use to generate the psf kernel if fsmode is convolve and psfk is None. The current choices are Gaussian and Moffat profiles. ‘gauss’ and ‘moffat’ produce circular PSF kernels. The gaussx and gaussy produce Gaussian kernels in the x and y directions respectively. gaussxy and gaussyx apply the Gaussian kernels in the x then the y direction, and first y then x direction, respectively.
  • seeing (float (Deafult: -1)) – Seeing in unit of arcsec, use as the first guess of the line spread function of the spectra. Negative value means “pass”, i.e. do nothing. None means grabbing from the header, though if it is not found, it is set to 1.0.
  • exptime (float (Deafult: -1)) – Esposure time for the observation, not important if absolute flux calibration is not needed. Negative value means “pass”, i.e. do nothing. None means grabbing from the header, though if it is not found, it is set to 1.0.
  • airmass (float (Default: -1)) – The airmass where the observation carries out. Negative value means “pass”, i.e. do nothing. None means grabbing from the header, though if it is not found, it is set to 0.0.
  • verbose (bool) – Set to False to suppress all verbose warnings, except for critical failure.
  • **kwargs

    Extra keyword arguments for the astroscrappy.detect_cosmics: https://astroscrappy.readthedocs.io/en/latest/api/ astroscrappy.detect_cosmics.html The default setting is:

    astroscrappy.detect_cosmics(indat, inmask=None, bkg=None,
        var=None, sigclip=4.5, sigfrac=0.3, objlim=5.0, gain=1.0,
        readnoise=6.5, satlevel=65536.0, niter=4, sepmed=True,
        cleantype='meanmask', fsmode='median', psfmodel='gauss',
        psffwhm=2.5, psfsize=7, psfk=None, psfbeta=4.765,
        verbose=False)
    
set_readnoise(readnoise=None)[source]

Set the readnoise of the image.

Parameters:readnoise (str, float, int or None (Default: None)) – If a string is provided, it will be treated as a header keyword for the readnoise value. Float or int will be used as the readnoise value. If None is provided, the header will be searched with the set of default readnoise keywords.
set_readnoise_keyword(keyword_list, append=False, update=True)[source]

Set the readnoise keyword list.

Parameters:
  • keyword_list (list) – List of keyword (string).
  • append (bool (Default: False)) – Set to False to overwrite the current list.
  • update (bool (Default: True)) – Set to True to search for the readnoise after the new list is provided.
set_seeing(seeing=None)[source]

Set the seeing of the image.

Parameters:seeing (str, float, int or None (Default: None)) – If a string is provided, it will be treated as a header keyword for the seeing value. Float or int will be used as the seeing value. If None is provided, the header will be searched with the set of default seeing keywords.
set_seeing_keyword(keyword_list, append=False, update=True)[source]

Set the seeing keyword list.

Parameters:
  • keyword_list (list) – List of keyword (string).
  • append (bool (Default: False)) – Set to False to overwrite the current list.
  • update (bool (Default: True)) – Set to True to search for the readnoise after the new list is provided.
class aspired.spectral_reduction.WavelengthCalibration(verbose=True, logger_name='WavelengthCalibration', log_level='INFO', log_file_folder='default', log_file_name=None)[source]

This is a wrapper for using RASCAL to perform wavelength calibration, which can handle arc lamps containing Xe, Cu, Ar, Hg, He, Th, Fe. This guarantees to provide something sensible or nothing at all. It will require some fine-tuning when using the first time. The more GOOD initial guesses provided, the faster the solution converges and with better fit. Knowing the dispersion, wavelength ranges and one or two known lines will significantly improve the fit. Conversely, wrong values supplied by the user will siginificantly distort the solution as any user supplied information will be treated as the ground truth.

Deatils of how RASCAL works should be referred to

Parameters:
  • verbose (bool (Default: True)) – Set to False to suppress all verbose warnings, except for critical failure.
  • logger_name (str (Default: OneDSpec)) – This will set the name of the logger, if the name is used already, it will reference to the existing logger. This will be the first part of the default log file name unless log_file_name is provided.
  • log_level (str (Default: 'INFO')) – Four levels of logging are available, in decreasing order of information and increasing order of severity: (1) DEBUG, (2) INFO, (3) WARNING, (4) ERROR and (5) CRITICAL. WARNING means that there is suboptimal operations in some parts of that step. ERROR means that the requested operation cannot be performed, but the software can handle it by either using the default setting or skipping the operation. CRITICAL means that the requested operation cannot be resolved without human interaction, this is most usually coming from missing data.
  • log_file_folder (None or str (Default: "default")) – Folder in which the file is save, set to default to save to the current path.
  • log_file_name (None or str (Default: None)) – File name of the log, set to None to self.logger.warning to screen only.
add_arc_lines(peaks)[source]

Provide the pixel locations of the arc lines.

Parameters:peaks (list) – The pixel locations of the arc lines. Multiple traces of the arc can be provided as list of list or list of arrays.
add_arc_spec(arc_spec)[source]

Provide the 1D spectrum of the arc image.

Parameters:arc_spec (list) – The photoelectron count of the 1D arc spectrum.
add_atlas(elements, min_atlas_wavelength=1000.0, max_atlas_wavelength=30000.0, min_intensity=10.0, min_distance=10.0, candidate_tolerance=10.0, constrain_poly=False, vacuum=False, pressure=101325.0, temperature=273.15, relative_humidity=0.0)[source]

Adds an atlas of arc lines to the calibrator, given an element.

Arc lines are taken from a general list of NIST lines and can be filtered using the minimum relative intensity (note this may not be accurate due to instrumental effects such as detector response, dichroics, etc) and minimum line separation.

Lines are filtered first by relative intensity, then by separation. This is to improve robustness in the case where there is a strong line very close to a weak line (which is within the separation limit).

The vacuum to air wavelength conversion is deafult to False because observatories usually provide the line lists in the respective air wavelength, as the corrections from temperature and humidity are small. See https://emtoolbox.nist.gov/Wavelength/Documentation.asp

Parameters:
  • elements (string or list of strings) – Chemical symbol, case insensitive
  • min_atlas_wavelength (float (Default: None)) – Minimum wavelength of the arc lines.
  • max_atlas_wavelength (float (Default: None)) – Maximum wavelength of the arc lines.
  • min_intensity (float (Default: None)) – Minimum intensity of the arc lines. Refer to NIST for the intensity.
  • min_distance (float (Default: None)) – Minimum separation between neighbouring arc lines.
  • candidate_tolerance (float (Default: 10)) – Tolerance (Angstroms) for considering a point to be an inlier during candidate peak/line selection. This should be reasonable small as we want to search for candidate points which are locally linear.
  • constrain_poly (bool (Default: Flase)) – Apply a polygonal constraint on possible peak/atlas pairs
  • vacuum (bool (Default: False)) – Set to True if the light path from the arc lamb to the detector plane is entirely in vacuum.
  • pressure (float (Default: 101325.)) – Pressure when the observation took place, in Pascal. If it is not known, assume 10% decrement per 1000 meter altitude
  • temperature (float (Default: 273.15)) – Temperature when the observation took place, in Kelvin.
  • relative_humidity (float (Default: 0.)) – In percentage.
add_fit_coeff(fit_coeff)[source]

Adding the polynomial coefficients.

Parameters:fit_coeff (list or list of list) – Polynomial fit coefficients.
add_fit_type(fit_type)[source]

Adding the polynomial type.

Parameters:fit_type (str or list of str) – Strings starting with ‘poly’, ‘leg’ or ‘cheb’ for polynomial, legendre and chebyshev fits. Case insensitive.
add_pix_wave_pair(pix, wave)[source]

Adding extra pixel-wavelength pair to the Calibrator for refitting. This DOES NOT work before the Calibrator having fit for a solution yet: use set_known_pairs() for that purpose.

Parameters:
  • pix (float) – pixel position
  • wave (float) – wavelength
add_user_atlas(elements, wavelengths, intensities=None, candidate_tolerance=10.0, constrain_poly=False, vacuum=False, pressure=101325.0, temperature=273.15, relative_humidity=0.0)[source]

Append the user supplied arc lines to the calibrator.

The vacuum to air wavelength conversion is deafult to False because observatories usually provide the line lists in the respective air wavelength, as the corrections from temperature and humidity are small. See https://emtoolbox.nist.gov/Wavelength/Documentation.asp

Parameters:
  • elements (list) – Element (required). Preferably a standard (i.e. periodic table) name for convenience with built-in atlases
  • wavelengths (list) – Wavelength to add (Angstrom)
  • intensities (list) – Relative line intensities
  • candidate_tolerance (float (Default: 10)) – Tolerance (Angstroms) for considering a point to be an inlier during candidate peak/line selection. This should be reasonable small as we want to search for candidate points which are locally linear.
  • constrain_poly (bool (Default: False)) – Apply a polygonal constraint on possible peak/atlas pairs
  • vacuum (bool (Default: False)) – Set to true to convert the input wavelength to air-wavelengths based on the given pressure, temperature and humidity.
  • pressure (float (Default: 101325.)) – Pressure when the observation took place, in Pascal. If it is not known, assume 10% decrement from 1 atm (the default) per 1000 meter altitude.
  • temperature (float (Default: 273.15)) – Temperature when the observation took place, in Kelvin.
  • relative_humidity (float (Default: 0.)) – In percentage.
clear_atlas()[source]

Remove all the lines loaded to the Calibrator.

do_hough_transform(brute_force=False)[source]

** brute_force is EXPERIMENTAL as of 1 Sept 2021 ** The brute force method is supposed to provide all the possible solution, hence given a sufficiently large max_tries, the solution should always be the best possible outcome. However, it does not seem to work in a small fraction of our tests. Use with caution, and it is not the recommended way for now.

Perform Hough transform on the pixel-wavelength pairs with the configuration set by the set_hough_properties().

Parameters:brute_force (bool (Default: False)) – Set to true to compute the gradient and intercept between every two data points
find_arc_lines(arc_spec=None, prominence=5.0, top_n_peaks=None, distance=5.0, refine=True, refine_window_width=5, display=False, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

This function identifies the arc lines (peaks) with scipy.signal.find_peaks(), where only the distance and the prominence keywords are used. Distance is the minimum separation between peaks, the default value is roughly twice the nyquist sampling rate (i.e. pixel size is 2.3 times smaller than the object that is being resolved, hence, the sepration between two clearly resolved peaks are ~5 pixels apart). A crude estimate of the background can exclude random noise which look like small peaks.

Parameters:
  • arc_spec (list, array or None (Default: None)) – If not provided, it will look for the arc_spec in the spectrum1D. Otherwise, the input arc_spec will be used.
  • prominence (float (Default: 5.)) – The minimum prominence to be considered as a peak (% of max).
  • top_n_peaks (int (Default: None)) – The N most prominent peaks. None means keeping all peaks.
  • distance (float (Default: 5.)) – Minimum separation between peaks.
  • refine (bool (Default: True)) – Set to true to fit a gaussian to get the peak at sub-pixel precision.
  • refine_window_width (int (Default: 5)) – The number of pixels (on each side of the existing peaks) to be fitted with gaussian profiles over.
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
  • renderer (string (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs.
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs.
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True. Only used if an iframe is saved.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

fit(max_tries=5000, fit_deg=4, fit_coeff=None, fit_tolerance=5.0, fit_type='poly', candidate_tolerance=2.0, brute_force=False, progress=True, return_jsonstring=False, display=False, renderer='default', save_fig=False, fig_type='iframe+png', filename=None, return_solution=True)[source]

A wrapper function to perform wavelength calibration with RASCAL. As of 14 January 2020, it supports He, Ne, Ar, Cu, Kr, Cd, Xe, Hg and Th from NIST.

Parameters:
  • max_tries (int) – Number of trials of polynomial fitting.
  • fit_deg (int (Default: 4)) – The degree of the polynomial to be fitted.
  • fit_coeff (list (Default: None)) – NOT CURRENTLY USED, as of 17 Jan 2021 Set the baseline of the least square fit. If no fits outform this set of polynomial coefficients, this will be used as the best fit.
  • fit_tolerance (float (Default: 5.0)) – Sets a tolerance on whether a fit found by RANSAC is considered acceptable.
  • fit_type (string (Default: 'poly')) – One of ‘poly’, ‘legendre’ or ‘chebyshev’.
  • candidate_tolerance (float (default: 2.0)) – toleranceold (Angstroms) for considering a point to be an inlier
  • brute_force (bool (Default: False)) – Set to True to try all possible combination in the given parameter space.
  • progress (bool (Default: True)) – Set to show the progress using tdqm (if imported).
  • return_jsonstring ((default: False)) – Set to True to save the plotly figure as json string.
  • display (bool (Default: False)) – Set to show diagnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • save_fig (string (Default: False)) – Set to save figure.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str) – Filename for the output, all of them will share the same name but will have different extension.
from_spectrum1D(spectrum1D, merge=False, overwrite=False)[source]

This function copies all the info from the spectrum1D, because users may supply different level/combination of reduction, everything is copied from the spectrum1D even though in most cases only a None will be passed.

By default, this is passing object by reference by default, so it directly modifies the spectrum1D supplied. By setting merger to True, it copies the data into the Spectrum1D in the FluxCalibration object.

Parameters:
  • spectrum1D (Spectrum1D object) – The Spectrum1D to be referenced or copied.
  • merge (bool (Default: False)) – Set to True to copy everything over to the local Spectrum1D, hence FluxCalibration will not be acting on the Spectrum1D outside.
  • overwrite (bool (Default: False)) – Set to True to make a complete copy of the spectrum1D to the target spectrum1D, that includes all the Nones and other settings. Use with caution, as it removes the properties set before this function call.
get_calibrator()[source]

Get the calibrator object.

get_pix_wave_pairs()[source]

Return the list of matched_peaks and matched_atlas with their position in the array.

Returns:pw_pairs – List of tuples each containing the array position, peak (pixel) and atlas (wavelength).
Return type:list
get_spectrum1D()[source]

Get the spectrum1D object.

initialise_calibrator(peaks=None, arc_spec=None)[source]

Initialise a RASCAL calibrator.

Parameters:
  • peaks (list (Default: None)) – The pixel values of the peaks (start from zero).
  • arc_spec (list) – The spectral intensity as a function of pixel.
list_atlas()[source]

List all the lines loaded to the Calibrator.

manual_refit(matched_peaks=None, matched_atlas=None, degree=None, x0=None, return_solution=True)[source]

Perform a refinement of the matched peaks and atlas lines.

This function takes lists of matched peaks and atlases, along with user-specified lists of lines to add/remove from the lists.

Any given peaks or atlas lines to remove are selected within a user-specified tolerance, by default 1 pixel and 5 atlas Angstrom.

The final set of matching peaks/lines is then matched using a robust polyfit of the desired degree. Optionally, an initial fit x0 can be provided to condition the optimiser.

The parameters are identical in the format in the fit() and match_peaks() functions, however, with manual changes to the lists of peaks and atlas, peak_utilisation and atlas_utilisation are meaningless so this function does not return in the same format.

Parameters:
  • matched_peaks (list (Default: None)) – List of matched peaks
  • matched_atlas (list (Default: None)) – List of matched atlas lines
  • degree (int (Default: None)) – Polynomial fit degree (Only used if x0 is None)
  • x0 (list (Default: None)) – Initial fit coefficients
  • return_solution (bool (Default: True)) – Set to True to return the best fit polynomial coefficients.
plot_search_space(fit_coeff=None, top_n_candidate=3, weighted=True, save_fig=False, fig_type='iframe+png', filename=None, return_jsonstring=False, renderer='default', display=False)[source]

A wrapper function to plot the search space in the Hough space.

If fit fit_coefficients are provided, the model solution will be overplotted.

Parameters:
  • fit_coeff (list (default: None)) – List of best polynomial fit_coefficients
  • top_n_candidate (int (default: 3)) – Top ranked lines to be fitted.
  • weighted ((default: True)) – Draw sample based on the distance from the matched known wavelength of the atlas.
  • save_fig (bool (default: False)) – Save an image if set to True. matplotlib uses the pyplot.save_fig() while the plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename ((default: None)) – The destination to save the image.
  • return_jsonstring ((default: False)) – Set to True to save the plotly figure as json string.
  • renderer ((default: 'default')) – Set the rendered for the plotly display. Ignored if matplotlib is used.
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
Returns:

Return type:

json object if json is True.

remove_arc_lines()[source]

Remove all the refined arc lines.

remove_arc_spec()[source]

Remove the aspectrm of the arc

remove_atlas_lines_range(wavelength, tolerance=10.0)[source]

Remove arc lines within the given wavelength range (tolerance).

Parameters:
  • wavelength (float) – Wavelength to remove (Angstrom)
  • tolerance (float) – Tolerance around this wavelength where atlas lines will be removed
remove_fit_coeff()[source]

To remove the polynomial fit coefficients.

remove_fit_type()[source]

To remove the polynomial fit type.

remove_pix_wave_pair(arg)[source]

Remove fitted pixel-wavelength pair from the Calibrator for refitting. The positions can be found from get_pix_wave_pairs(). One at a time.

Parameters:arg (int) – The position of the pairs in the arrays.
robust_refit(fit_coeff, n_delta=None, refine=False, tolerance=10.0, method='Nelder-Mead', convergence=1e-06, robust_refit=True, fit_deg=None, display=False, renderer='default', filename=None, return_jsonstring=False, save_fig=False, fig_type='iframe+png', return_solution=True)[source]

** refine option is EXPERIMENTAL, as of 17 Jan 2021 ** A wrapper function to robustly refit the wavelength solution with RASCAL when there is already a set of good coefficienes.

Refine the polynomial fit coefficients. Recommended to use in it multiple calls to first refine the lowest order and gradually increase the order of coefficients to be included for refinement. This is be achieved by providing delta in the length matching the number of the lowest degrees to be refined.

Set refine to True to improve on the polynomial solution.

Set robust_refit to True to fit all the detected peaks with the given polynomial solution for a fit using maximal information, with the degree of polynomial = fit_deg.

Set both refine and robust_refit to False will return the list of arc lines are well fitted by the current solution within the tolerance limit provided.

Parameters:
  • fit_coeff (list) – List of polynomial fit coefficients.
  • n_delta (int (Default: None)) – The number of the highest polynomial order to be adjusted
  • refine (bool (Default: False)) – Set to True to refine solution.
  • tolerance (float (Default: 10.)) – Absolute difference between fit and model in the unit of nm.
  • method (string (Default: 'Nelder-Mead')) – scipy.optimize.minimize method.
  • convergence (float (Default: 1e-6)) – scipy.optimize.minimize tol.
  • robust_refit (bool (Default: True)) – Set to True to fit all the detected peaks with the given polynomial solution.
  • fit_deg (int (Default: length of the input coefficients)) – Order of polynomial fit with all the detected peaks.
  • display (bool (Default: False)) – Set to show diagnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • save_fig (string (Default: False)) – Set to save figure.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • return_solution (bool (Default: True)) – Set to True to return the best fit polynomial coefficients.
save_csv(output='wavecal', filename='wavecal', overwrite=False, recreate=False)[source]

Save the reduced data to disk, with a choice of any combination of the data that are already present in the Spectrum1D. Because a WavelengthCalibration only requires a subset of all the data, only ‘wavecal’ is guaranteed to exist.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
  • filename (String) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • overwrite (bool) – Default is False.
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
save_fits(output='wavecal', filename='wavecal', overwrite=False, recreate=False, empty_primary_hdu=True)[source]

Save the reduced data to disk, with a choice of any combination of the data that are already present in the Spectrum1D. Because a WavelengthCalibration only requires a subset of all the data, only ‘wavecal’ is guaranteed to exist.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
  • filename (String) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • overwrite (bool) – Default is False.
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
  • empty_primary_hdu (bool (Default: True)) – Set to True to leave the Primary HDU blank
set_calibrator_properties(num_pix=None, pixel_list=None, plotting_library='plotly', logger_name='Calibrator', log_level='info')[source]

Set the properties of the calibrator.

Parameters:
  • num_pix (int (Default: None)) – The number of pixels in the dispersion direction
  • pixel_list (list or numpy array (Default: None)) – The pixel position of the trace in the dispersion direction. This should be provided if you wish to override the default range(num_pix), for example, in the case of accounting for chip gaps (10 pixels) in a 3-CCD setting, you should provide [0,1,2,…90, 100,101,…190, 200,201,…290]
  • plotting_library (string (Default: 'plotly')) – Choose between matplotlib and plotly.
  • log_level (string (Default: 'info')) – Choose from {CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET}.
set_hough_properties(num_slopes=5000, xbins=500, ybins=500, min_wavelength=3000, max_wavelength=9000, range_tolerance=500, linearity_tolerance=100)[source]

Set the properties of the hough transform.

Parameters:
  • num_slopes (int (Default: 1000)) – Number of slopes to consider during Hough transform
  • xbins (int (Default: 50)) – Number of bins for Hough accumulation
  • ybins (int (Default: 50)) – Number of bins for Hough accumulation
  • min_wavelength (float (Default: 3000)) – Minimum wavelength of the spectrum.
  • max_wavelength (float (Default: 9000)) – Maximum wavelength of the spectrum.
  • range_tolerance (float (Default: 500)) – Estimation of the error on the provided spectral range e.g. 3000-5000 with tolerance 500 will search for solutions that may satisfy 2500-5500
  • linearity_tolerance (float (Default: 100)) – A toleranceold (Ansgtroms) which defines some padding around the range tolerance to allow for non-linearity. This should be the maximum expected excursion from linearity.
set_known_pairs(pix=None, wave=None)[source]

Provide manual pixel-wavelength pair(s), they will be appended to the list of pixel-wavelength pairs after the random sample being drawn from the RANSAC step, i.e. they are ALWAYS PRESENT in the fitting step. Use with caution because it can skew or bias the fit significantly, make sure the pixel value is accurate to at least 1/10 of a pixel.

This can be used, for example, for low intensity lines at the edge of the spectrum.

Parameters:
  • pix (numeric value, list or numpy 1D array (N) (Default: None)) – Any pixel value, can be outside the detector chip and serve purely as anchor points.
  • wave (numeric value, list or numpy 1D array (N) (Default: None)) – The matching wavelength for each of the pix.
set_ransac_properties(sample_size=5, top_n_candidate=5, linear=True, filter_close=False, ransac_tolerance=5, candidate_weighted=True, hough_weight=1.0, minimum_matches=3, minimum_peak_utilisation=0.0, minimum_fit_error=0.0001)[source]

Set the properties of the RANSAC process.

Parameters:
  • sample_size (int (Default: 5)) – Number of pixel-wavelength hough pairs to be used for each arc line being picked.
  • top_n_candidate (int (Default: 5)) – Top ranked lines to be fitted.
  • linear (bool (Default: True)) – True to use the hough transformed gradient, otherwise, use the known polynomial.
  • filter_close (bool (Default: False)) – Remove the pairs that are out of bounds in the hough space.
  • ransac_tolerance (float (Default: 1)) – The distance criteria (Angstroms) to be considered an inlier to a fit. This should be close to the size of the expected residuals on the final fit (e.g. 1A is typical)
  • candidate_weighted (bool (Default: True)) – Set to True to down-weight pairs that are far from the fit.
  • hough_weight (float or None (Default: 1.0)) – Set to use the hough space to weigh the fit. The theoretical optimal weighting is unclear. The larger the value, the heavily it relies on the overdensity in the hough space for a good fit.
  • minimum_matches (int (Default: 3)) – Minimum number of fitted peaks to accept as a solution. This has to be smaller than or equal to the sample size.
  • minimum_peak_utilisation (float (Default: 0.)) – The minimum percentage of peaks used in order to accept as a valid solution.
  • minimum_fit_error (float (Default 1e-4)) – Set to remove overfitted/unrealistic fits.
class aspired.spectral_reduction.FluxCalibration(verbose=True, logger_name='FluxCalibration', log_level='INFO', log_file_folder='default', log_file_name=None)[source]

Initialise a FluxCalibration object.

Parameters:
  • verbose (bool (Default: True)) – Set to False to suppress all verbose warnings, except for critical failure.
  • logger_name (str (Default: FluxCalibration)) – This will set the name of the logger, if the name is used already, it will reference to the existing logger. This will be the first part of the default log file name unless log_file_name is provided.
  • log_level (str (Default: 'INFO')) – Four levels of logging are available, in decreasing order of information and increasing order of severity: CRITICAL, DEBUG, INFO, WARNING, ERROR
  • log_file_folder (None or str (Default: "default")) – Folder in which the file is save, set to default to save to the current path.
  • log_file_name (None or str (Default: None)) – File name of the log, set to None to logging.warning to screen only.
add_sensitivity_func(sensitivity_func)[source]
Parameters:sensitivity_func (callable function) – Interpolated sensivity curve object.
add_standard(wavelength, count, count_err=None, count_sky=None)[source]

Add spectrum (wavelength, count, count_err & count_sky).

Parameters:
  • wavelength (1-d array) – The wavelength at each pixel of the trace.
  • count (1-d array) – The summed count at each column about the trace.
  • count_err (1-d array (Default: None)) – the uncertainties of the count values
  • count_sky (1-d array (Default: None)) – The integrated sky values along each column, suitable for subtracting from the output of ap_extract
apply_flux_calibration(target_spectrum1D, inspect=False, wave_min=3500.0, wave_max=8500.0, display=False, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

Apply the computed sensitivity curve. And resample the spectra to match the highest resolution (the smallest wavelength bin) part of the spectrum.

Note: This function directly modify the target_spectrum1D.

Note 2: the wave_min and wave_max are for DISPLAY purpose only.

Parameters:
  • target_spectrum1D (Spectrum1D object) – The spectrum to be flux calibrated.
  • inspect (bool (Default: False)) – Set to True to create/display/save figure
  • wave_min (float (Default: 3500)) – Minimum wavelength to display
  • wave_max (float (Default: 8500)) – Maximum wavelength to display
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
  • renderer (string (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

create_fits(output='count+count_resampled+flux+flux_resampled', empty_primary_hdu=True, recreate=False)[source]
Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 4 HDUs
    Count, uncertainty, sky, optimal flag, and weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
    wavelength: 1 HDU
    Wavelength of each pixel
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    flux: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (pixel)
    flux_resampled: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (wavelength)
  • empty_primary_hdu (bool (Default: True)) – Set to True to leave the Primary HDU blank (Default: True)
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
from_spectrum1D(spectrum1D, merge=False, overwrite=False)[source]

This function copies all the info from the spectrum1D, because users may supply different level/combination of reduction, everything is copied from the spectrum1D even though in most cases only a None will be passed.

By default, this is passing object by reference by default, so it directly modifies the spectrum1D supplied. By setting merger to True, it copies the data into the Spectrum1D in the FluxCalibration object.

Parameters:
  • spectrum1D (Spectrum1D object) – The Spectrum1D to be referenced or copied.
  • merge (bool (Default: False)) – Set to True to copy everything over to the local Spectrum1D, hence FluxCalibration will not be acting on the Spectrum1D outside.
get_sensitivity(k=3, method='interpolate', mask_range=[[6850, 6960], [7580, 7700]], mask_fit_order=1, mask_fit_size=3, smooth=False, slength=5, sorder=3, return_function=True, sens_deg=7, **kwargs)[source]

The sensitivity curve is computed by dividing the true values by the wavelength calibrated standard spectrum, which is resampled with the spectres.spectres(). The curve is then interpolated with a cubic spline by default and is stored as a scipy interp1d object.

A Savitzky-Golay filter is available for smoothing before the interpolation but it is not used by default.

6850 - 6960, 7575 - 7700, and 8925 - 9050 A are masked by default.

Parameters:
  • k (integer [1,2,3,4,5 only]) – The order of the spline.
  • method (str (Default: interpolate)) – This should be either ‘interpolate’ of ‘polynomial’. Note that the polynomial is computed from the interpolated function. The default is interpolate because it is much more stable at the wavelength limits of a spectrum in an automated system.
  • mask_range (None or list of list) – Masking out regions of Telluric absorption when fitting the sensitivity curve. None for no mask. List of list has the pattern [[min_pix_1, max_pix_1], [min_pix_2, max_pix_2],…]
  • mask_fit_order (int (Default: 1)) – Order of polynomial to be fitted over the masked regions
  • mask_fit_size (int (Default: 3)) – Number of “pixels” to be fitted on each side of the masked regions.
  • smooth (bool (Default: False)) – set to smooth the input spectrum with scipy.signal.savgol_filter
  • slength (int (Default: 5)) – SG-filter window size
  • sorder (int (Default: 3)) – SG-filter polynomial order
  • return_function (bool (Default: True)) – Set to True to explicity return the interpolated function of the sensitivity curve.
  • sens_deg (int (Default: 7)) – The degree of polynomial of the sensitivity curve, only used if the method is ‘polynomial’.
  • **kwargs – keyword arguments for passing to the LOWESS functionj for getting the continuum, see statsmodels.nonparametric.smoothers_lowess.lowess()
Returns:

  • A callable function as a function of wavelength if return_function is
  • set to True.

get_spectrum1D()[source]

Return the spectrum1D object.

get_telluric_profile(wave, flux, continuum, mask_range=[[6850, 6960], [7580, 7700]], return_function=False)[source]

Getting the Telluric absorption profile from the continuum of the standard star spectrum.

Parameters:
  • wave (list or 1-d array (N)) – Wavelength.
  • flux (list or 1-d array (N)) – Flux.
  • continuum (list or 1-d array (N)) – Continuum Flux.
  • mask_range (list of list) – list of lists with 2 values indicating the range marked by each of the Telluric regions.
  • return_function (bool (Default: False)) – Set to True to explicitly return the interpolated function of the Telluric profile.
inspect_sensitivity(display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

Display the computed sensitivity curve.

Parameters:
  • display (bool (Default: True)) – Set to True to display disgnostic plot.
  • renderer (string (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

inspect_telluric_profile(display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

Display the Telluric profile.

Parameters:
  • display (bool (Default: True)) – Set to True to display disgnostic plot.
  • renderer (string (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

load_standard(target, library=None, ftype='flux', cutoff=0.4)[source]

Read the standard flux/magnitude file. And return the wavelength and flux/mag. The units of the data are always in

wavelength: A
flux: ergs / cm / cm / s / A
mag: mag (AB)
Parameters:
  • target (string) – Name of the standard star
  • library (string (Default: None)) – Name of the library of standard star
  • ftype (string (Default: 'flux')) – ‘flux’ or ‘mag’
  • cutoff (float (Default: 0.4)) – The toleranceold for the word similarity in the range of [0, 1].
save_csv(output='sensitivity_resampled+flux_resampled', filename='fluxcal', overwrite=False, recreate=False)[source]

Save the reduced data to disk, with a choice of any combination of the data that are already present in the Spectrum1D, see below the ‘output’ parameters for details.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”. Because a FluxCalibration only requires a subset of all the data, only a few data products are guaranteed to exist.

    count: 4 HDUs
    Count, uncertainty, sky, and weight (pixel)
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    wavelength: 1 HDU
    Wavelength of each pixel
    flux: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (pixel)
    flux_resampled: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (wavelength)
  • filename (String (Default: None)) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • overwrite (bool (Default: False)) – Set to True to allow overwriting the FITS data at the file destination.
  • recreate (bool (Default: False)) – Set to True to regenerate the FITS data and header.
save_fits(output='count_resampled+sensitivity_resampled+flux_resampled', filename='fluxcal', empty_primary_hdu=True, overwrite=False, recreate=False)[source]

Save the reduced data to disk, with a choice of any combination of the data that are already present in the Spectrum1D, see below the ‘output’ parameters for details.

Parameters:
  • output (String) –

    Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”. Because a FluxCalibration only requires a subset of all the data, only a few data products are guaranteed to exist.

    count: 4 HDUs
    Count, uncertainty, sky, optimal flag, and weight (pixel)
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    wavelength: 1 HDU
    Wavelength of each pixel
    flux: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (pixel)
    flux_resampled: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (wavelength)
  • filename (String) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • empty_primary_hdu (bool (Default: True)) – Set to True to leave the Primary HDU blank (Default: True)
  • overwrite (bool) – Default is False.
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
class aspired.spectral_reduction.OneDSpec(verbose=True, logger_name='OneDSpec', log_level='INFO', log_file_folder='default', log_file_name=None)[source]

This class applies the wavelength calibrations and compute & apply the flux calibration to the extracted 1D spectra. The standard TwoDSpec object is not required for data reduction, but the flux calibrated standard observation will not be available for diagnostic.

Parameters:
  • verbose (bool (Default: True)) – Set to False to suppress all verbose warnings, except for critical failure.
  • logger_name (str (Default: 'OneDSpec')) – This will set the name of the logger, if the name is used already, it will reference to the existing logger. This will be the first part of the default log file name unless log_file_name is provided.
  • log_level (str (Default: 'INFO')) – Four levels of logging are available, in decreasing order of information and increasing order of severity: (1) DEBUG, (2) INFO, (3) WARNING, (4) ERROR and (5) CRITICAL. WARNING means that there is suboptimal operations in some parts of that step. ERROR means that the requested operation cannot be performed, but the software can handle it by either using the default setting or skipping the operation. CRITICAL means that the requested operation cannot be resolved without human interaction, this is most usually coming from missing data.
  • log_file_folder (None or str (Default: 'default')) – Folder in which the file is save, set to default to save to the current path.
  • log_file_name (None or str (Default: None)) – File name of the log, set to None to print to screen only.
add_arc_lines(peaks, spec_id=None, stype='science+standard')[source]
Parameters:
  • peaks (list of list or list of arrays) – The pixel locations of the arc lines. Multiple traces of the arc can be provided as list of list or list of arrays.
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_arc_spec(arc_spec, spec_id=None, stype='science+standard')[source]
Parameters:
  • arc_spec (1-d array) – The count of the summed 1D arc spec
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_atlas(elements, spec_id=None, min_atlas_wavelength=3000.0, max_atlas_wavelength=10000.0, min_intensity=10.0, min_distance=10.0, candidate_tolerance=10.0, constrain_poly=False, vacuum=False, pressure=101325.0, temperature=273.15, relative_humidity=0, stype='science+standard')[source]
Parameters:
  • elements (str or list of strings) – Chemical symbol, case insensitive
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • min_atlas_wavelength (float (Default: 3000.)) – Minimum wavelength of the arc lines.
  • max_atlas_wavelength (float (Default: 10000.)) – Maximum wavelength of the arc lines.
  • min_intensity (float (Default: 10.)) – Minimum intensity of the arc lines. Refer to NIST for the intensity.
  • min_distance (float (Default: 10.)) – Minimum separation between neighbouring arc lines.
  • candidate_tolerance (float (Default: 10.)) – toleranceold (Angstroms) for considering a point to be an inlier during candidate peak/line selection. This should be reasonable small as we want to search for candidate points which are locally linear.
  • constrain_poly (bool (Default: False)) – Apply a polygonal constraint on possible peak/atlas pairs
  • vacuum (bool (Default: False)) – Set to true to convert the input wavelength to air-wavelengths based on the given pressure, temperature and humidity.
  • pressure (float (Default: 101325.)) – Pressure when the observation took place, in Pascal. If it is not known, assume 10% decrement per 1000 meter altitude
  • temperature (float (Default: 273.15)) – Temperature when the observation took place, in Kelvin.
  • relative_humidity (float (Default: 0)) – In percentage.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_fit_coeff(fit_coeff, fit_type='poly', spec_id=None, stype='science+standard')[source]
Parameters:
  • fit_coeff (list or numpy array, or a list of them) – Polynomial fit coefficients.
  • fit_type (str or list of str) – Strings starting with ‘poly’, ‘leg’ or ‘cheb’ for polynomial, legendre and chebyshev fits. Case insensitive.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_fluxcalibration(fluxcal)[source]

Provide the pre-calibrated FluxCalibration object.

Parameters:fluxcal (FluxCalibration object) – The true mag/flux values.
add_pix_wave_pair(pix, wave, spec_id=None, stype='science+standard')[source]

Adding extra pixel-wavelength pair to the Calibrator for refitting. This DOES NOT work before the Calibrator having fit for a solution yet: use set_known_pairs() for that purpose.

Parameters:
  • pix (float) – pixel position
  • wave (float) – wavelength
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_science_spectrum1D(spec_id)[source]

Add a new Spectrum1D with the ID spec_id. This overwrite the existing Spectrum1D object if it already exists.

Parameters:spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
add_sensitivity_func(sensitivity_func)[source]

Provide a callable function of the detector sensitivity response.

Parameters:
  • sensitivity_func (str) – Interpolated sensivity curve object.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_spec(count, spec_id=None, count_err=None, count_sky=None, stype='science+standard')[source]
Parameters:
  • count (1-d array) – The summed count at each column about the trace.
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • count_err (1-d array (Default: None)) – the uncertainties of the count values
  • count_sky (1-d array (Default: None)) – The integrated sky values along each column, suitable for subtracting from the output of ap_extract
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_telluric_function(telluric, spec_id=None, stype='science+standard')[source]

** EXPERIMENTAL, as of 1 October 2021 **

Provide a callable function that gives the Telluric profile.

Parameters:
  • telluric (callable function) – A function that gives the absorption profile as a function of wavelength.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_trace(trace, trace_sigma, spec_id=None, pixel_list=None, stype='science+standard')[source]
Parameters:
  • trace (list or numpy.ndarray (N)) – The spatial pixel value (can be sub-pixel) of the trace at each spectral position.
  • trace_sigma (list or numpy.ndarray (N)) – Standard deviation of the Gaussian profile of a trace
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • pixel_list (list or numpy.narray (Default: None)) – The pixel position of the trace in the dispersion direction. This should be provided if you wish to override the default range(len(spec.trace[0])), for example, in the case of accounting for chip gaps (10 pixels) in a 3-CCD setting, you should provide [0,1,2,…90, 100,101,…190, 200,201,…290]
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_user_atlas(elements, wavelengths, spec_id=None, intensities=None, candidate_tolerance=10.0, constrain_poly=False, vacuum=False, pressure=101325.0, temperature=273.15, relative_humidity=0.0, stype='science+standard')[source]

Append the user supplied arc lines to the calibrator.

The vacuum to air wavelength conversion is deafult to False because observatories usually provide the line lists in the respective air wavelength, as the corrections from temperature and humidity are small. See https://emtoolbox.nist.gov/Wavelength/Documentation.asp

Parameters:
  • elements (list) – Element (required). Preferably a standard (i.e. periodic table) name for convenience with built-in atlases
  • wavelengths (list) – Wavelength to add (Angstrom)
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • intensities (list or None (Default: None)) – Relative line intensities
  • candidate_tolerance (float (Default: 10.)) – toleranceold (Angstroms) for considering a point to be an inlier during candidate peak/line selection. This should be reasonable small as we want to search for candidate points which are locally linear.
  • constrain_poly (bool (Default: False)) – Apply a polygonal constraint on possible peak/atlas pairs
  • vacuum (bool (Default: False)) – Set to true to convert the input wavelength to air-wavelengths based on the given pressure, temperature and humidity.
  • pressure (float (Default: 101325.)) – Pressure when the observation took place, in Pascal. If it is not known, assume 10% decrement per 1000 meter altitude
  • temperature (float (Default: 273.15)) – Temperature when the observation took place, in Kelvin.
  • relative_humidity (float (Default: 0.)) – In percentage.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_wavelength(wave, spec_id=None, stype='science+standard')[source]

Three combinations of wave and spec_id shapes are accepted.

Parameter Size
wave 1 1 N
spec_id 1 N N
Parameters:
  • wave (numeric value, list or numpy 1D array (N)) – The wavelength of each pixels of the spectrum.
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_wavelength_resampled(wave_resampled, spec_id=None, stype='science+standard')[source]

Three combinations of wave and spec_id shapes are accepted.

Parameter Size
wave 1 1 N
spec_id 1 N N
Parameters:
  • wave_resampled – The wavelength of the resampled spectrum.
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
add_wavelengthcalibration(wavecal, spec_id=None, stype='science+standard')[source]

Provide the pre-calibrated WavelengthCalibration object.

Parameters:
  • wavecal (list of WavelengthCalibration object) – The WavelengthPolyFit object for the science target, flux will not be calibrated if this is not provided.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
apply_atmospheric_extinction_correction(science_airmass=None, standard_airmass=None, spec_id=None)[source]

** EXPERIMENTAL, as of 1 October 2021 **

This is the first step in allowing atmospheric extinction correction of the spectra. Currently it only works if both the science and standard spectra are present and both airmass values are provided. Towards completion, this function should allow atmospheric extinction correction on any meaningful combination of (1) science and/or standard spectrum/a, and (2) airmass of either or both science and standard observations.

Parameters:
  • science_airmass (float, str or None (Default: None)) –
    • If None, it will look for the airmass in the header, if the keyword AIRMASS is not found, correction will not be performed.
    • A string input will be used as the header keyword of the airmass, if the keyword or header is not found, correction will not be performed.
    • A floatpoint value will override the other two and directly be use as the airmass
  • standard_airmass (float, str or None (Default: None)) – The same as science_airmass.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
apply_flux_calibration(spec_id=None, inspect=False, wave_min=3500.0, wave_max=8500.0, display=False, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False, stype='science+standard')[source]

Apply the computed sensitivity curve. And resample the spectra to match the highest resolution (the smallest wavelength bin) part of the spectrum.

Note: This function directly modify the target_spectrum1D.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • inspect (bool (Default: False)) – Set to True to create/display/save figure
  • wave_min (float (Default: 3500)) – Minimum wavelength to display
  • wave_max (float (Default: 8500)) – Maximum wavelength to display
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
  • renderer (string (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
apply_telluric_correction(factor=1.0, spec_id=None, stype='science+standard')[source]

** EXPERIMENTAL, as of 1 October 2021 **

Apply the telluric correction with the extra multiplier ‘factor’. The ‘factor’ provided in the profile() is NOT propagated to this function, it has to be explicitly provided to this function.

The telluric absorption profile is normalised to 1 at the most absorpted wavelegnth, the factor manually provided can be negative in case of over/under-subtraction.

Parameters:
  • factor (float (Default: None)) – The extra fudge factor multiplied to the telluric profile to manally adjust the strength.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
apply_wavelength_calibration(spec_id=None, wave_start=None, wave_end=None, wave_bin=None, stype='science+standard')[source]

Apply the wavelength calibration. Because the polynomial fit can run away at the two ends, the default minimum and maximum are limited to 1,000 and 12,000 A, respectively. This can be overridden by providing user’s choice of wave_start and wave_end.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • wave_start (float or None (Default: None)) – Provide the minimum wavelength for resampling.
  • wave_end (float or None (Default: None)) – Provide the maximum wavelength for resampling
  • wave_bin (float or None (Default: None)) – Provide the resampling bin size
  • stype (str or None (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
clear_atlas(spec_id=None, stype='science+standard')[source]

Remove all the atlas lines from the calibrator.

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
create_fits(output='arc_spec+wavecal+wavelength+flux+flux_resampled', spec_id=None, stype='science+standard', recreate=True, empty_primary_hdu=True)[source]

Create a HDU list, with a choice of any combination of the data, see below the ‘output’ parameters for details.

Parameters:
  • output (String) –

    (Default: ‘arc_spec+wavecal+wavelength+flux+flux_resampled’) Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 4 HDUs
    Count, uncertainty, sky, optimal flag, and weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
    wavelength: 1 HDU
    Wavelength of each pixel
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    sensitivity: 1 HDU
    Sensitivity (pixel)
    flux: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (pixel)
    sensitivity_resampled: 1 HDU
    Sensitivity (wavelength)
    flux_resampled: 4 HDUs
    Flux, uncertainty, sky, and sensitivity (wavelength)
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
  • recreate (bool (Default: True)) – Set to True to overwrite the FITS data and header.
  • empty_primary_hdu (bool (Default: True)) – Set to True to leave the Primary HDU blank
do_hough_transform(spec_id=None, brute_force=False, stype='science+standard')[source]

** brute_force is EXPERIMENTAL as of 1 Oct 2021 ** The brute force method is supposed to provide all the possible solution, hence given a sufficiently large max_tries, the solution should always be the best possible outcome. However, it does not seem to work in a small fraction of our tests. Use with caution, and it is not the recommended way for now.

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • brute_force (bool (Default: False)) – Set to true to compute the gradient and intercept between every two data points
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
find_arc_lines(spec_id=None, prominence=5.0, top_n_peaks=None, distance=5.0, refine=False, refine_window_width=5, display=False, width=1280, height=720, return_jsonstring=False, renderer='default', save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False, stype='science+standard')[source]
Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • background (int or None (Default: None)) – User-supplied estimated background level
  • percentile (float (Default: 2.)) – The percentile of the flux to be used as the estimate of the background sky level to the first order. Only used if background is None. [Count]
  • prominence (float (Default: 5.)) – The minimum prominence to be considered as a peak (normalised)
  • distance (float (Default: 5.)) – Minimum separation between peaks
  • refine (bool (Default: True)) – Set to true to fit a gaussian to get the peak at sub-pixel precision
  • refine_window_width (int or float (Default: 5)) – The number of pixels (on each side of the existing peaks) to be fitted with gaussian profiles over.
  • display (bool (Default: False)) – Set to True to display disgnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return JSON-string that can be rendered by Plotly in any support language.
  • renderer – plotly renderer options.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str or None (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
Returns:

Return type:

JSON strings if return_jsonstring is set to True

fit(spec_id=None, max_tries=5000, fit_deg=4, fit_coeff=None, fit_tolerance=10.0, fit_type='poly', candidate_tolerance=2.0, brute_force=False, progress=True, return_solution=False, display=False, renderer='default', save_fig=False, fig_type='iframe+png', filename=None, stype='science+standard')[source]

A wrapper function to perform wavelength calibration with RASCAL. As of 14 January 2020, it supports He, Ne, Ar, Cu, Kr, Cd, Xe, Hg and Th from NIST.

Parameters:
  • max_tries (int) – Number of trials of polynomial fitting.
  • fit_deg (int (Default: 4)) – The degree of the polynomial to be fitted.
  • fit_coeff (list (Default: None)) – NOT CURRENTLY USED, as of 17 Jan 2021 Set the baseline of the least square fit. If no fits outform this set of polynomial coefficients, this will be used as the best fit.
  • fit_tolerance (float (Default: 10)) – Sets a tolerance on whether a fit found by RANSAC is considered acceptable.
  • fit_type (string (Default: 'poly')) – One of ‘poly’, ‘legendre’ or ‘chebyshev’.
  • candidate_tolerance (float (default: 2.0)) – toleranceold (Angstroms) for considering a point to be an inlier
  • brute_force (bool (Default: False)) – Set to True to try all possible combination in the given parameter space.
  • progress (bool (Default: True)) – Set to show the progress using tdqm (if imported).
  • return_jsonstring ((default: False)) – Set to True to save the plotly figure as json string.
  • display (bool (Default: False)) – Set to show diagnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • save_fig (string (Default: False)) – Set to save figure.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str or None (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
from_twodspec(twodspec, spec_id=None, stype='science+standard')[source]

To add a TwoDSpec object or numpy array to provide the traces, line spread function of the traces, optionally the pixel values correcponding to the traces. If the arc is provided, the saxis and flip properties of the TwoDSpec will be applied to the arc, and then the spec_mask and the spatial_mask from the TwoDSpec object will be applied.

Parameters:
  • twodspec (TwoDSpec object) – TwoDSpec of the science image containin the trace(s) and trace_sigma(s).
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
get_continuum(spec_id=None, **kwargs)[source]

** EXPERIMENTAL, as of 1 October 2021 **

Get the continnum from the wave, count and flux.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • **kwargs (dictionary) – The keyword arguments to be passed to the lowess function for generating the continuum.
get_pix_wave_pairs(spec_id=None, stype='science+standard')[source]

Return the list of matched_peaks and matched_atlas with their position in the array.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
Returns:

pw_pairs – Dictionary of ‘science’ and/or ‘standard’ where the values are lists of tuples each containing the array position, peak (pixel) and atlas (wavelength) in the order of the given spec_id.

Return type:

dictionary

get_resampled_continuum(spec_id=None, **kwargs)[source]

** EXPERIMENTAL, as of 1 October 2021 **

Get the continnum from the resampled wave, count and flux.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • **kwargs (dictionary) – The keyword arguments to be passed to the lowess function for generating the continuum.
get_sensitivity(k=3, method='interpolate', mask_range=[[6850, 6960], [7580, 7700]], mask_fit_order=1, mask_fit_size=5, smooth=False, slength=5, sorder=3, return_function=False, sens_deg=7, **kwargs)[source]
Parameters:
  • k (integer [1,2,3,4,5 only]) – The order of the spline.
  • method (str (Default: 'interpolate')) – This should be either ‘interpolate’ of ‘polynomial’. Note that the polynomial is computed from the interpolated function. The default is interpolate because it is much more stable at the wavelength limits of a spectrum in an automated system.
  • mask_range (None or list of list) – (Default: 6850-6960, 7575-7700, 8925-9050) Masking out regions not suitable for fitting the sensitivity curve. None for no mask. List of list has the pattern [[min1, max1], [min2, max2],…]
  • mask_fit_order (int (Default: 1)) – Order of polynomial to be fitted over the masked regions
  • mask_fit_size (int (Default: 5)) – Number of “pixels” to be fitted on each side of the masked regions.
  • smooth (bool (Default: False)) – set to smooth the input spectrum with scipy.signal.savgol_filter
  • slength (int (Default:5)) – SG-filter window size
  • sorder (int (Default: 3)) – SG-filter polynomial order
  • return_function (bool (Default: False)) – Set to True to return the callable function of the sensitivity curve.
  • sens_deg (int (Default: 7)) – The degree of polynomial of the sensitivity curve, only used if the method is ‘polynomial’.
  • **kwargs – keyword arguments for passing to the LOWESS function, see statsmodels.nonparametric.smoothers_lowess.lowess()
get_telluric_correction(spec_id=None, factor=1.0, auto_apply=False, **kwargs)[source]

** EXPERIMENTAL, as of 1 October 2021 **

Get the telluric absorption profile from the standard star based on the masked regions given in generating the sensitivity curve. Note that the profile has a “positive” flux so that in the step of applying a correction, a POSITIVE constant is found to multiply with the normalised telluric profile before ADDING to the spectrum for telluric absorption correction (counter-intuitive to the term telluric absorption subtraction).

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • factor (float (Default: 1.0)) – The extra fudge factor multiplied to the telluric profile to manally adjust the strength.
  • auto_apply (bool (Default: False)) – Set to True to accept the computed telluric absorption correction automatically, which is currently an irresversible process through the public API.
get_telluric_profile(spec_id=None, mask_range=[[6850, 6960], [7580, 7700]], return_function=False)[source]

** EXPERIMENTAL, as of 1 October 2021 **

Getting the Telluric absorption profile from the continuum of the standard star spectrum.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • mask_range (list of list) – list of lists with 2 values indicating the range marked by each of the Telluric regions.
  • return_function (bool (Default: False)) – Set to True to explicitly return the interpolated function of the Telluric profile.
initialise_calibrator(spec_id=None, peaks=None, arc_spec=None, stype='science+standard')[source]

If the peaks were found with find_arc_lines(), peaks and spectrum can be None.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • peaks (list, numpy.ndarray or None (Default: None)) – The pixel values of the peaks (start from zero)
  • spectrum (list, numpy.ndarray or None (Default: None)) – The spectral intensity as a function of pixel.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
inspect_reduced_spectrum(spec_id=None, stype='science+standard', wave_min=3500.0, wave_max=8500.0, display=True, renderer='default', width=1280, height=720, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False, return_jsonstring=False)[source]
Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
  • wave_min (float (Default: 3500.)) – Minimum wavelength to display
  • wave_max (float (Default: 8500.)) – Maximum wavelength to display
  • display (bool (Default: True)) – Set to True to display disgnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str or None (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
  • return_jsonstring (bool (Default: False)) – set to True to return JSON-string that can be rendered by Plotly in any support language.
inspect_sensitivity(display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]
Parameters:
  • display (bool (Default: True)) – Set to True to display disgnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json str that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str or None (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
inspect_standard(display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]
Parameters:
  • display (bool (Default: True)) – Set to True to display disgnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json str that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str or None (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

inspect_telluric_correction(factor=1.0, spec_id=None, display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

** EXPERIMENTAL, as of 1 October 2021 **

Inspect the Telluric absorption correction on top of pre-corrected spectra.

Parameters:
  • factor (float (Default: 1.0)) – The extra fudge factor multiplied to the telluric profile to manally adjust the strength.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • display (bool (Default: True)) – Set to True to display disgnostic plot.
  • renderer (string (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

inspect_telluric_profile(display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

** EXPERIMENTAL, as of 1 October 2021 **

Display the Telluric profile.

Parameters:
  • display (bool (Default: True)) – Set to True to display disgnostic plot.
  • renderer (string (Default: 'default')) – plotly renderer options.
  • width (int/float (Default: 1280)) – Number of pixels in the horizontal direction of the outputs
  • height (int/float (Default: 720)) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

list_atlas(spec_id=None, stype='science+standard')[source]

Remove all the atlas lines from the calibrator.

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
load_standard(target, library=None, ftype='flux', cutoff=0.4)[source]

Read the standard flux/magnitude file. And return the wavelength and flux/mag. The units of the data are always in

wavelength: A
flux: ergs / cm / cm / s / A
mag: mag (AB)
Parameters:
  • target (string) – Name of the standard star
  • library (string (Default: None)) – Name of the library of standard star
  • ftype (string (Default: 'flux')) – ‘flux’ or ‘mag’
  • cutoff (float (Default: 0.4)) – The toleranceold for the word similarity in the range of [0, 1].
lookup_standard_libraries(target, cutoff=0.4)[source]
Parameters:
  • target (str) – Name of the standard star
  • cutoff (float (Default: 0.4)) – The similarity tolerance [0=completely different, 1=identical]
manual_refit(matched_peaks=None, matched_atlas=None, degree=None, x0=None, return_solution=False, spec_id=None, stype='science+standard')[source]

Perform a refinement of the matched peaks and atlas lines.

This function takes lists of matched peaks and atlases, along with user-specified lists of lines to add/remove from the lists.

Any given peaks or atlas lines to remove are selected within a user-specified tolerance, by default 1 pixel and 5 atlas Angstrom.

The final set of matching peaks/lines is then matched using a robust polyfit of the desired degree. Optionally, an initial fit x0 can be provided to condition the optimiser.

The parameters are identical in the format in the fit() and match_peaks() functions, however, with manual changes to the lists of peaks and atlas, peak_utilisation and atlas_utilisation are meaningless so this function does not return in the same format.

Parameters:
  • matched_peaks (list (Default: None)) – List of matched peaks
  • matched_atlas (list (Default: None)) – List of matched atlas lines
  • degree (int (Default: None)) – Polynomial fit degree (Only used if x0 is None)
  • x0 (list (Default: None)) – Initial fit coefficients
  • return_solution (bool (Default: False)) – Set to True to return the best fit polynomial coefficients.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_arc_spec_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the arc spectrum header.

Parameters:
  • idx (int) – The HDU number of the arc spectrum FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_count_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the count header.

Parameters:
  • idx (int) – The HDU number of the trace FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_count_resampled_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the count resampled header.

Parameters:
  • idx (int) – The HDU number of the count resampled FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_flux_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the flux header.

Parameters:
  • idx (int) – The HDU number of the flux FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_flux_resampled_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the flux resampled header.

Parameters:
  • idx (int) – The HDU number of the flux resampled FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_sensitivity_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the sensitivity header.

Parameters:
  • idx (int) – The HDU number of the sensitivity FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_sensitivity_resampled_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the sensitivity resampled header.

Parameters:
  • idx (int) – The HDU number of the sensitivity resampled FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_trace_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the trace header.

Parameters:
  • idx (int) – The HDU number of the trace FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_wavecal_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the wavecal header.

Parameters:
  • idx (int) – The HDU number of the wavecal FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_wavelength_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the wavelength header.

Parameters:
  • idx (int) – The HDU number of the wavelength FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
modify_weight_map_header(idx, method, *args, spec_id=None, stype='science+standard')[source]

Wrapper function to modify the weight map header.

Parameters:
  • idx (int) – The HDU number of the weight map FITS
  • method (str) – The operation to modify the header with
  • *args – Extra arguments for the method
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
plot_search_space(spec_id=None, fit_coeff=None, top_n_candidate=3, weighted=True, save_fig=False, fig_type='iframe+png', filename=None, return_jsonstring=False, renderer='default', display=False, stype='science+standard')[source]

A wrapper function to plot the search space in the Hough space.

If fit fit_coefficients are provided, the model solution will be overplotted.

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
remove_atlas_lines_range(wavelength, tolerance=10.0, spec_id=None, stype='science+standard')[source]

Remove arc lines within a certain wavelength range.

Parameters:
  • wavelength (float) – Wavelength to remove (Angstrom)
  • tolerance (float (Default: 10.)) – Tolerance around this wavelength where atlas lines will be removed
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
remove_pix_wave_pair(arg, spec_id=None, stype='science+standard')[source]

Remove fitted pixel-wavelength pair from the Calibrator for refitting. The positions can be found from get_pix_wave_pairs(). One at a time.

Parameters:
  • arg (int) – The position of the pairs in the arrays.
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
robust_refit(spec_id=None, fit_coeff=None, n_delta=None, refine=False, tolerance=10.0, method='Nelder-Mead', convergence=1e-06, robust_refit=True, fit_deg=None, return_solution=False, display=False, renderer='default', save_fig=False, filename=None, stype='science+standard')[source]

** EXPERIMENTAL, as of 1 October 2021 ** Refine the fitted solution with a minimisation method as provided by scipy.optimize.minimize().

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • fit_coeff (list or None (Default: None)) – List of polynomial fit coefficients.
  • n_delta (int (Default: None)) – The number of the highest polynomial order to be adjusted
  • refine (bool (Default: True)) – Set to True to refine solution.
  • tolerance (float (Default: 10.)) – Absolute difference between fit and model in the unit of nm.
  • method (str (Default: 'Nelder-Mead')) – scipy.optimize.minimize method.
  • convergence (float (Default: 1e-6)) – scipy.optimize.minimize tol.
  • robust_refit (bool (Default: True)) – Set to True to fit all the detected peaks with the given polynomial solution.
  • fit_deg (int (Default: length of the input coefficients - 1)) – Order of polynomial fit with all the detected peaks.
  • return_solution (bool (Default: True)) – Set to True to return the best fit polynomial coefficients.
  • display (bool (Default: False)) – Set to show diagnostic plot.
  • renderer (str (Default: 'default')) – plotly renderer options.
  • save_fig (bool (Default: False)) – Set to save figure.
  • filename (str or None (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
save_csv(spec_id=None, output='arc_spec+wavecal+wavelength+flux+flux_resampled', filename='reduced', stype='science+standard', recreate=False, overwrite=False)[source]

Save the reduced data to disk, with a choice of any combination of the 5 sets of data, see below the ‘output’ parameters for details.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • output (String) –

    (Default: ‘arc_spec+wavecal+wavelength+flux+flux_resampled’) Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 4 HDUs
    Count, uncertainty, sky, optimal flag, and weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
    wavelength: 1 HDU
    Wavelength of each pixel
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    sensitivity: 1 HDU
    Sensitivity (pixel)
    flux: 3 HDUs
    Flux, uncertainty, sky, and sensitivity (pixel)
    sensitivity_resampled: 1 HDU
    Sensitivity (wavelength)
    flux_resampled: 3 HDUs
    Flux, uncertainty, sky, and sensitivity (wavelength)
  • filename (String (Default: 'reduced')) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
  • overwrite (bool (Default: False)) – Default is False.
save_fits(spec_id=None, output='arc_spec+wavecal+wavelength+flux+flux_resampled', filename='reduced', stype='science+standard', recreate=False, empty_primary_hdu=True, overwrite=False)[source]

Save the reduced data to disk, with a choice of any combination of the data, see below the ‘output’ parameters for details.

Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • output (String) –

    (Default: ‘arc_spec+wavecal+wavelength+flux+flux_resampled’) Type of data to be saved, the order is fixed (in the order of the following description), but the options are flexible. The input strings are delimited by “+”,

    trace: 2 HDUs
    Trace, and trace width (pixel)
    count: 4 HDUs
    Count, uncertainty, sky, optimal flag, and weight (pixel)
    arc_spec: 3 HDUs
    1D arc spectrum, arc line pixels, and arc line effective pixels
    wavecal: 1 HDU
    Polynomial coefficients for wavelength calibration
    wavelength: 1 HDU
    Wavelength of each pixel
    count_resampled: 3 HDUs
    Resampled Count, uncertainty, and sky (wavelength)
    sensitivity: 1 HDU
    Sensitivity (pixel)
    flux: 3 HDUs
    Flux, uncertainty, and sky (pixel)
    sensitivity_resampled: 1 HDU
    Sensitivity (wavelength)
    flux_resampled: 3 HDUs
    Flux, uncertainty, and sky (wavelength)
  • filename (String (Default: 'reduced')) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
  • recreate (bool (Default: False)) – Set to True to overwrite the FITS data and header.
  • empty_primary_hdu (bool (Default: True)) – Set to True to leave the Primary HDU blank
  • overwrite (bool (Default: False)) – Default is False.
save_sensitivity_func(filename='sensitivity_func.npy')[source]

Not-implemented wrapper.

Parameters:filename (str) – Filename for the output interpolated sensivity curve.
set_atmospheric_extinction(location='orm', extinction_func=None, kind='cubic', fill_value='extrapolate', **kwargs)[source]

** EXPERIMENTAL, as of 1 October 2021 **

The ORM atmospheric extinction correction table is taken from http://www.ing.iac.es/astronomy/observing/manuals/ps/tech_notes/tn031.pdf

The MK atmospheric extinction correction table is taken from Buton et al. (2013A&A…549A…8B)

The CP atmospheric extinction correction table is taken from Patat et al. (2011A&A…527A..91P)

The LS atmospheric extinction correction table is taken from THE ESO USERS MANUAL 1993 https://www.eso.org/public/archives/techdocs/pdf/report_0003.pdf

Parameters:
  • location (str (Default: orm)) – Location of the observatory, currently contains: (1) orm - Roque de los Muchachos Observatory (2420 m) (2) mk - Mauna Kea (4205 m) (3) cp - Cerro Paranal (2635 m) (4) ls - La Silla (2400 m) [up to 9000A only] Only used if extinction_func is None.
  • extinction_func (callable function (Default: None)) – Input wavelength in Angstrom, output magnitude of extinction per airmass. It will override the ‘location’.
set_calibrator_properties(spec_id=None, num_pix=None, pixel_list=None, plotting_library='plotly', logger_name='Calibrator', log_level='info', stype='science+standard')[source]
Parameters:
  • spec_id (int or None (Default: None)) – The ID corresponding to the spectrum1D object
  • num_pix (int (Default: None)) – The number of pixels in the dispersion direction
  • pixel_list (list or numpy array (Default: None)) – The pixel position of the trace in the dispersion direction. This should be provided if you wish to override the default range(num_pix), for example, in the case of accounting for chip gaps (10 pixels) in a 3-CCD setting, you should provide [0,1,2,…90, 100,101,…190, 200,201,…290]
  • plotting_library (str (Default: 'plotly')) – Choose between matplotlib and plotly.
  • logger_name (str (Default: 'Calibrator')) – This will set the name of the logger, if the name is used already, it will reference to the existing logger. This will be the first part of the default log file name unless log_file_name is provided.
  • log_level (str (Default: 'info')) – Choose {critical, error, warning, info, debug, notset}.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
set_hough_properties(spec_id=None, num_slopes=5000, xbins=200, ybins=200, min_wavelength=3000.0, max_wavelength=10000.0, range_tolerance=500, linearity_tolerance=100, stype='science+standard')[source]
Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • num_slopes (int (Default: 5000)) – Number of slopes to consider during Hough transform
  • xbins (int (Default: 200)) – Number of bins for Hough accumulation
  • ybins (int (Default: 200)) – Number of bins for Hough accumulation
  • min_wavelength (float (Default: 3000.)) – Minimum wavelength of the spectrum.
  • max_wavelength (float (Default: 10000.)) – Maximum wavelength of the spectrum.
  • range_tolerance (float (Default: 500)) – Estimation of the error on the provided spectral range e.g. 3000-5000 with tolerance 500 will search for solutions that may satisfy 2500-5500
  • linearity_tolerance (float (Default: 100)) – A toleranceold (Ansgtroms) which defines some padding around the range tolerance to allow for non-linearity. This should be the maximum expected excursion from linearity.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
set_known_pairs(pix=None, wave=None, spec_id=None, stype='science+standard')[source]
Parameters:
  • pix (numeric value, list or numpy 1D array (N) (Default: None)) – Any pixel value, can be outside the detector chip and serve purely as anchor points.
  • wave (numeric value, list or numpy 1D array (N) (Default: None)) – The matching wavelength for each of the pix.
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter
set_ransac_properties(spec_id=None, sample_size=5, top_n_candidate=5, linear=True, filter_close=False, ransac_tolerance=5, candidate_weighted=True, hough_weight=1.0, minimum_matches=3, minimum_peak_utilisation=0.0, minimum_fit_error=0.0001, stype='science+standard')[source]

Configure the Calibrator. This may require some manual twiddling before the calibrator can work efficiently. However, in theory, a large max_tries in fit() should provide a good solution in the expense of performance (minutes instead of seconds).

Parameters:
  • spec_id (int (Default: None)) – The ID corresponding to the spectrum1D object
  • sample_size (int (Default: 5)) – Number of pixel-wavelength hough pairs to be used for each arc line being picked.
  • top_n_candidate (int (Default: 5)) – Top ranked lines to be fitted.
  • linear (bool (Default: True)) – True to use the hough transformed gradient, otherwise, use the known polynomial.
  • filter_close (bool (Default: False)) – Remove the pairs that are out of bounds in the hough space.
  • ransac_tolerance (float (Default: 5)) – The distance criteria (Angstroms) to be considered an inlier to a fit. This should be close to the size of the expected residuals on the final fit (e.g. 1A is typical)
  • candidate_weighted (bool (Default: True)) – Set to True to down-weight pairs that are far from the fit.
  • hough_weight (float or None (Default: 1.0)) – Set to use the hough space to weigh the fit. The theoretical optimal weighting is unclear. The larger the value, the heavily it relies on the overdensity in the hough space for a good fit.
  • minimum_matches (int (Default: 3)) – Minimum number of fitted peaks to accept as a solution. This has to be smaller than or equal to the sample size.
  • minimum_peak_utilisation (float (Default: 0.)) – The minimum percentage of peaks used in order to accept as a valid solution.
  • minimum_fit_error (float (Default 1e-4)) – Set to remove overfitted/unrealistic fits.
  • stype (str (Default: 'science+standard')) – ‘science’ and/or ‘standard’ to indicate type, use ‘+’ as delimiter