Flux Calibration API

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.0, 6960.0], [7580.0, 7700.0]], 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.