Flux Calibration API¶
- class aspired.spectral_reduction.FluxCalibration(verbose: bool = True, logger_name: str = 'FluxCalibration', log_level: str = 'INFO', log_file_folder: str = 'default', log_file_name: str = None)[source]¶
For flux calibration using iraf, ING and ESO standards.
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: Callable)[source]¶
- Parameters:
sensitivity_func (callable function) – Interpolated sensivity curve object (in unit of per second).
- add_standard(wavelength: numpy.ndarray | list, count: numpy.ndarray | list, count_err: numpy.ndarray | list = None, count_sky: numpy.ndarray | list = 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_spectrum_oned: SpectrumOneD, inspect: bool = False, wave_min: float = None, wave_max: float = None, display: bool = False, renderer: str = 'default', width: int = 1280, height: int = 720, return_jsonstring: bool = False, save_fig: bool = False, fig_type: str = 'iframe+png', filename: str = None, open_iframe: bool = 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_spectrum_oned.
Note 2: the wave_min and wave_max are for DISPLAY purpose only.
- Parameters:
target_spectrum_oned (SpectrumOneD object) – The spectrum to be flux calibrated.
inspect (bool (Default: False)) – Set to True to create/display/save figure
wave_min (float (Default: None -> 3500)) – Minimum wavelength to display
wave_max (float (Default: None -> 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.
- Return type:
JSON strings if return_jsonstring is set to True.
- create_fits(output: str = 'count+wavelength+sensitivity+flux', empty_primary_hdu: bool = True, recreate: bool = 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 “+”,
- count: 4 HDUs
Count, uncertainty, sky, optimal flag, and weight (pixel)
- wavelength: 1 HDU
Wavelength of each pixel
- sensitivity: 1 HDU
Sensitivity (pixel)
- flux: 4 HDUs
Flux, uncertainty, and sky
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_spectrum_oned(spectrum_oned: SpectrumOneD, merge: bool = False, overwrite: bool = False)[source]¶
This function copies all the info from the spectrum_oned, because users may supply different level/combination of reduction, everything is copied from the spectrum_oned 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 spectrum_oned supplied. By setting merger to True, it copies the data into the SpectrumOneD in the FluxCalibration object.
- Parameters:
spectrum_oned (SpectrumOneD object) – The SpectrumOneD to be referenced or copied.
merge (bool (Default: False)) – Set to True to copy everything over to the local SpectrumOneD, hence FluxCalibration will not be acting on the SpectrumOneD outside.
- get_sensitivity(k: int = 3, method: str = 'interpolate', mask_range: numpy.ndarray | list = [[6850.0, 6960.0], [7580.0, 7700.0]], mask_fit_order: int = 1, mask_fit_size: int = 3, smooth: bool = True, return_function: bool = True, sens_deg: int = 7, use_continuum: bool = False, **kwargs: str)[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.
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 a lowess function with statsmodels
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’.
use_continuum (bool (Default: False)) – Set to True to use continuum for finding the sensitivity function. If used, the smoothing filter will be applied on the continuum.
**kwargs – keyword arguments for passing to the LOWESS function 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_telluric_profile(wave: numpy.ndarray | list, flux: numpy.ndarray | list, continuum: numpy.ndarray | list, mask_range: numpy.ndarray | list = [[6850, 6960], [7580, 7700]], return_function: bool = 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: bool = True, renderer: str = 'default', width: int = 1280, height: int = 720, return_jsonstring: bool = False, save_fig: bool = False, fig_type: str = 'iframe+png', filename: str = None, open_iframe: bool = 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.
- Return type:
JSON strings if return_jsonstring is set to True.
- inspect_telluric_profile(display: bool = True, renderer: str = 'default', width: int = 1280, height: int = 720, return_jsonstring: bool = False, save_fig: bool = False, fig_type: str = 'iframe+png', filename: str = None, open_iframe: bool = 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.
- Return type:
JSON strings if return_jsonstring is set to True.
- load_standard(target: str, library: str = None, ftype: str = 'flux', cutoff: float = 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: Aflux: ergs / cm / cm / s / Amag: 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: str = 'count+wavelength+sensitivity+flux', filename: str = 'fluxcal', overwrite: bool = False, recreate: bool = False)[source]¶
Save the reduced data to disk, with a choice of any combination of the data that are already present in the SpectrumOneD, 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)
- wavelength: 1 HDU
Wavelength of each pixel
- sensitivity: 1 HDU
Sensitivity (pixel)
- flux: 4 HDUs
Flux, uncertainty, and sky
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: str = 'count+wavelength+sensitivity+flux', filename: str = 'fluxcal', empty_primary_hdu: bool = True, overwrite: bool = False, recreate: bool = False)[source]¶
Save the reduced data to disk, with a choice of any combination of the data that are already present in the SpectrumOneD, 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)
- wavelength: 1 HDU
Wavelength of each pixel
- sensitivity: 1 HDU
Sensitivity (pixel)
- flux: 4 HDUs
Flux, uncertainty, and sky
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.