castor_etc.spectra.base

Spectrum Utilities

castor_etc.spectrum provides methods to handle spectral data and normalizations.

Includes:

  • redshifting wavelengths

  • blackbody radiation, power-law spectrum generation

  • user-input spectrum

  • Gaussian and Lorentzian emission/absorption lines

  • generic spiral and elliptical galaxy spectra

  • stellar spectra from the Pickles catalog

  • stellar spectra from the ‘ATLAS9’ and ‘BTSettl’ catalogs

  • normalization functions:

    • normalize a blackbody spectrum to a star of given radius and distance

    • normalize a spectrum to some average value or AB magnitude, either within a passband or over the whole spectrum

    • normalize a spectrum to a given bolometric luminosity and distance

    • calculate the average value of a spectrum (erg/s/cm^2/A or AB mag) either within a passband or over the whole spectrum

The two main classes that implement theres are castor_etc.spectrum.SpectrumMixin and castor_etc.spectrum.NormMixin.

Module Contents

Classes

SpectrumMixin

Mixin for generating spectra. To be used with Source object. Do not use directly!

NormMixin

Mixin for normalizing spectra.

Functions

getStarData

Reads in star data from atlas directory, according to temperature, metallicity, and log(G) values.

interp_EEM_table

Interpolate EEM_table using input Teff

redshift_wavelengths

Apply redshift correction to wavelengths.

Data

fnu

flam

API

castor_etc.spectra.base.fnu = 'def_unit(...)'
castor_etc.spectra.base.flam = 'def_unit(...)'
castor_etc.spectra.base.getStarData(temperature, metallicity, logg, stellar_model_dir, model_grid='ATLAS9')

Reads in star data from atlas directory, according to temperature, metallicity, and log(G) values.

Parameters

temperature :: float
    Temperature of the reference star in kelvin.

metallicity :: 'p/m00','p/m05','p/m10','p/m15','p/m20', where p is plus, m is minus.
    Metallicity of the reference star. Accepted inputs.

logg :: g00,g05,g10,g15,g20,g25,g30,g35,g40,g45,g50
    log(G) value for the reference star.

stellar_model_dir :: str
  Path to the stellar models directory. There are three variations contingent on the working environment.
  Variation 1: stellar_model_dir = "/arc/projects/CASTOR/stellar_models" --> Default path (Working in the CANFAR server).
  Variation 2: stellar_model_dir = <path to local stellar models directory>
  Variation 3: stellar_model_dir = join(DATAPATH,"transit_data/stellar_models") --> This path should be used when building docker container locally.

Returns

wavelengths :: `astropy.Quantity` wavelength
    wavelength of the reference star in AA.

flux :: array of floats
 Flux of the reference star in units erg s^-1 cm^-2 A^-1
castor_etc.spectra.base.interp_EEM_table(Teff=[], Gmag=[], Bpmag=[], Rpmag=[])

Interpolate EEM_table using input Teff

Parameters

  Teff :: array of floats
    Effective temperature of the identified sources

  Gmag :: array of floats
    Gaia G magnitude of the identified sources

  Bpmag :: array of floats
    Gaia BP magnitude of the identifies sources

  Rpmag :: array of floats
    Gaia RP magnitude of the idenitifies sources

Return

  interp_output
    Interpolation result
castor_etc.spectra.base.redshift_wavelengths(wavelengths, redshift)

Apply redshift correction to wavelengths.

Parameters

wavelengths :: int or float or astropy.Quantity or array Wavelengths to redshift.

redshift :: int or float Redshift to apply.

Returns

red_wavelengths :: array of floats
Redshifted wavelengths.
class castor_etc.spectra.base.SpectrumMixin

Mixin for generating spectra. To be used with Source object. Do not use directly!

This class contains various static methods to initialize a spectrum: - generate_uniform - generate_bb - generate_power_law - generate_emission_line -

__spectrum = None
__wavelengths = None
property spectrum
property wavelengths
property _spectrum
property _wavelengths
_check_existing_spectrum(overwrite, quiet=False)

Check for existing spectrum and if the source is a CustomSource instance. If the object is a CustomSource instance, raise an error. If self._wavelengths and/or self._spectrum is not None, raise an error if overwrite is False; otherwise print a message notifying user that the method will overwrite the existing spectrum (unless quiet is True).

Parameters

overwrite :: bool If False and self._wavelengths and/or self._spectrum is not None, raise an error. If True and self._wavelengths and/or self._spectrum is not None, print a message informing the user that the existing spectrum will be overwritten (unless quiet is True).

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Returns

None

spectrum_erg_to_photon()

Convert the spectrum that has units of ergs in the numerator to units of photons in the numerator.

Attributes

spectrum :: array of floats Spectrum that has units of photons in the numerator.

Returns

None

redshift_wavelengths(redshift)

Apply redshift correction to wavelengths. Does not affect the y-axis values of the spectrum.

Parameters

redshift :: int or float Redshift to apply.

Attributes

wavelengths :: astropy.Quantity array The redshifted wavelengths of the spectrum, in angstroms.

Returns

None

generate_uniform(wavelengths, value, unit='ABmag', overwrite=False, quiet=False)

Generate a uniform spectrum equal to a constant value in either flam (erg/s/cm^2/A), fnu (erg/s/cm^2/Hz), ABmag (AB magnitude), or STmag (ST magnitude). Note that the computed (and stored) spectrum will always be in units of flam.

Parameters

wavelengths :: array of scalars or astropy.Quantity array The wavelengths over which to generate the uniform spectrum. If an array of scalars, it should be in angstrom.

value :: int or float The value of the uniform spectrum in the specified unit.

unit :: “flam” or “fnu” or “ABmag” or “STmag” The unit of the value: either flam (erg/s/cm^2/A), fnu (erg/s/cm^2/Hz), ABmag (AB magnitude), or STmag (ST magnitude).

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The given wavelengths of the spectrum, converted into units of angstrom.

spectrum :: array of floats Spectrum, in erg/s/cm^2/A, that is uniform in the specified unit.

Returns

None

generate_bb(T, redshift=0.0, emissivity=1.0, wavelengths=None, limits=[0.09, 1.2] << u.um, resolution=1 << u.nm, radius=1, dist=1 << u.kpc, overwrite=False, quiet=False)

Generate a blackbody (BB) spectrum (in erg/s/cm^2/A) using Planck’s radiation law. The spectral radiance of the BB (erg/s/cm^2/A/sr) is normalized to a star of given radius and distance.

Parameters

T :: int or float or astropy.Quantity Intrinsic blackbody temperature (i.e., the temperature of the BB at redshift=0). If int or float, the unit is assumed to be kelvin.

redshift :: int or float Redshift of the blackbody.

emissivity :: int or float Emissivity of the blackbody. (Technically, emissivity is unity per the definition of a BB).

wavelengths :: array of floats or astropy.Quantity array The wavelengths over which to calculate the spectrum. If an array of floats, the unit is assumed to be in angstroms. If wavelengths is not None, the limits and resolution parameters are ignored. Note that the final wavelengths attribute will be an astropy.Quantity array in units of angstroms regardless of this input’s units.

limits :: list of 2 scalars or list of 2 astropy.Quantity List containing the lower (0th index) and upper (1st index) bounds for the BB spectrum’s restframe wavelengths, inclusive. Limits should be > 0. If list elements are int or float, they are assumed to be in angstroms. This parameter is ignored if wavelengths is provided.

resolution :: int or float or astropy.Quantity The wavelength resolution of the returned spectrum. If a scalar, it is assumed to be in units of angstroms. This parameter is ignored if wavelengths is provided.

radius :: float or astropy.Quantity The radius of the source. If a scalar, it is assumed to be in units of solar radii.

dist :: float or astropy.Quantity The distance to the blackbody. If a scalar, it is assumed to be in units of kpc.

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The redshifted wavelengths of the spectrum, in angstroms.

spectrum :: array of floats BB spectrum in units of flam (erg/s/cm^2/A).

Returns

None

generate_power_law(ref_wavelength, wavelengths, exponent, overwrite=False, quiet=False)

Generate a spectrum with a shape following a power-law in some arbitrary unit. The flux is defined so that it is equal to 1 at the reference wavelength.

The spectrum is calculated using the following formula:

            spectrum = (wavelengths / ref_wavelength)^exponent

where each variable is as defined in the Parameters documentation below.

Parameters

ref_wavelength :: scalar or astropy.Quantity The reference wavelength for the power-law. The spectrum at this wavelength will have a flux of 1. If a scalar, it should be in angstrom.

wavelengths :: array of scalars or astropy.Quantity array The wavelengths over which to calculate the power-law spectrum. If an array of scalars, it should be in angstrom.

exponent :: int or float The exponent for the power-law.

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum, in angstroms.

spectrum :: array of floats Spectrum following the power-law defined above, in arbitary units.

Returns

None

static _generate_gaussian(wavelengths, spectrum, center, fwhm, peak=None, tot_flux=None, add=True, abs_peak=True)

Add/subtract a Gaussian spectrum to/from an existing spectrum. This is useful for representing emission lines (i.e., by adding a Gaussian source) or absorption lines (i.e., by subtracting a Gaussian source). Note that the minimum/maximum wavelengths of the source spectrum will not change.

The Gaussian spectrum can be represented by the following formulae (from https://pysynphot.readthedocs.io/en/latest/spectrum.html#gaussian-emission):

            gaussian = peak / exp[(wavelengths - center)^2 / (2 * sigma^2)]

and

            sigma = fwhm / [2 * sqrt(2 * ln2)]

and

            peak = tot_flux / sqrt(2 * pi * sigma^2) <-- see Gaussian integral

where:

  • gaussian is the Gaussian spectrum’s flux in some arbitrary unit

  • peak is the flux at the center of the Gaussian (i.e., the central wavelength)

  • center is the central wavelength of the Gaussian

  • wavelengths is the array of wavelengths over which to calculate the spectrum

  • fwhm is the full-width at half-maximum of the Gaussian

  • tot_flux is the total flux of the Gaussian under the curve

Parameters

wavelengths :: array of floats or astropy.Quantity array The wavelengths over which to calculate the Gaussian spectrum.

spectrum :: array of floats The spectrum to/from which to add/subtract the Gaussian spectrum.

center :: scalar or astropy.Quantity The central wavelength of the Gaussian. If a scalar, it is assumed to be in angstrom.

fwhm :: scalar or astropy.Quantity The full-width at half-maximum of the Gaussian. If a scalar, it is assumed to be in angstrom.

peak :: int or float The peak flux of the Gaussian (i.e., the flux at the center wavelength). Exactly one of peak or tot_flux must be specified.

tot_flux :: int or float The total flux under the curve. Exactly one of peak or tot_flux must be specified.

add :: bool If True, add the Gaussian spectrum to the existing spectrum. If False, subtract the Gaussian from the existing spectrum.

abs_peak :: bool If True, ensure that the peak of the emission line or dip of the absorption line is at the given value. Otherwise, just add/subtract the given Gaussian peak to/from the continuum.

Returns

sorted_wavelengths :: array of floats or astropy.Quantity array The wavelengths of the new spectrum. The shape of this array will be different from the input wavelengths array.

sorted_spectrum :: array of floats The spectrum with the Gaussian added/subtracted. The shape of this array will be different from the input spectrum array.

static _generate_lorentzian(wavelengths, spectrum, center, fwhm, peak=None, tot_flux=None, add=True, abs_peak=True)

Add/subtract a Lorentzian spectrum to/from an existing spectrum. This is useful for representing emission lines (i.e., by adding a Lorentzian source) or absorption lines (i.e., by subtracting a Lorentzian source). Note that the minimum/maximum wavelengths of the source spectrum will not change.

The Lorentzian spectrum can be represented by the following formulae:

            lorentzian = peak / (1 + num_half_widths^2)

and

            num_half_widths = (wavelengths - center) / probable_error

and

            peak = tot_flux / (pi * probable_error) <-- see Cauchy distribution

and

            probable_error = fwhm / 2

where:

  • lorentzian is the Lorentzian spectrum’s flux in some arbitrary unit

  • peak is the flux at the center (i.e., central wavelength) of the Lorentzian

  • center is the central wavelength of the Lorentzian

  • wavelengths is the array of wavelengths over which to calculate the spectrum

  • fwhm is the full-width at half-maximum of the Lorentzian

  • tot_flux is the total flux of the Lorentzian under the curve

Parameters

wavelengths :: array of floats or astropy.Quantity array The wavelengths over which to calculate the Lorentzian spectrum.

spectrum :: array of floats The spectrum to/from which to add/subtract the Lorentzian spectrum.

center :: scalar or astropy.Quantity The central wavelength of the Lorentzian. If a scalar, it is assumed to be in angstrom.

fwhm :: scalar or astropy.Quantity The full-width at half-maximum of the Lorentzian. If a scalar, it is assumed to be in angstrom.

peak :: int or float The peak flux of the Lorentzian (i.e., the flux at the center wavelength). Exactly one of peak or tot_flux must be specified.

tot_flux :: int or float The total flux under the curve. Exactly one of peak or tot_flux must be specified.

add :: bool If True, add the Lorentzian spectrum to the existing spectrum. If False, subtract the Lorentzian from the existing spectrum.

abs_peak :: bool If True, ensure that the peak of the emission line or dip of the absorption line is at the given value. Otherwise, just add/subtract the given Lorentzian peak to/from the continuum.

Returns

sorted_wavelengths :: array of floats or astropy.Quantity array The wavelengths of the new spectrum. The shape of this array will be different from the input wavelengths array.

sorted_spectrum :: array of floats The spectrum with the Lorentzian added/subtracted. The shape of this array will be different from the input spectrum array.

add_emission_line(center, fwhm, peak=None, tot_flux=None, shape='gaussian', abs_peak=False)

Add a well-sampled emission line to the spectrum. Note that the minimum/maximum wavelengths of the source spectrum will not change.

For generating an emission line spectrum (i.e., not adding/subtracting an emission line to/from a spectrum), see the generate_emission_line() method instead.

N.B. the order in which emission/absorption lines are added will affect the final spectrum if using the abs_peak/abs_dip flag. For instance, adding an emission line on top of a continuum then specifying an absorption line with an absolute dip is not the same as specifying an absorption line with an absolute dip then adding an emission line on top of the new continuum.

Parameters

center :: scalar or astropy.Quantity The central wavelength of the emission line. If a scalar, it is assumed to be in angstrom.

fwhm :: scalar or astropy.Quantity The full-width at half-maximum of the emission line. If a scalar, it is assumed to be in angstrom.

peak :: int or float The peak flux of the emission line (i.e., the flux at the center wavelength). Exactly one of peak or tot_flux must be specified.

tot_flux :: int or float The total flux under the curve. Exactly one of peak or tot_flux must be specified.

shape :: “gaussian” or “lorentzian” The emission line profile.

abs_peak :: bool If True, ensure that the peak of the emission line is at the given value. Otherwise, just add the given emission line to the spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum including the emission line, in angstroms. This wavelengths array will have a different shape than the previous wavelengths array.

spectrum :: array of floats The spectrum with the emission line added. This spectrum array will have a different shape than the previous spectrum array.

Returns

None

add_absorption_line(center, fwhm, dip=None, tot_flux=None, shape='gaussian', abs_dip=False)

Add a well-sampled absorption line to the spectrum. Note that the minimum/maximum wavelengths of the source spectrum will not change.

N.B. the order in which emission/absorption lines are added will affect the final spectrum if using the abs_peak/abs_dip flag. For instance, adding an emission line on top of a continuum then specifying an absorption line with an absolute dip is not the same as specifying an absorption line with an absolute dip then adding an emission line on top of the new continuum.

Parameters

center :: scalar or astropy.Quantity The central wavelength of the absorption line. If a scalar, it is assumed to be in angstrom.

fwhm :: scalar or astropy.Quantity The full-width at half-maximum of the absorption line. If a scalar, it is assumed to be in angstrom.

dip :: int or float The minimum flux of the absorption line (i.e., the flux at the center wavelength). Exactly one of dip or tot_flux must be specified.

tot_flux :: int or float The total flux under (above) the curve. Exactly one of dip or tot_flux must be specified.

shape :: “gaussian” or “lorentzian” The absorption line profile.

abs_dip :: bool If True, ensure that the dip of the absorption line is at the given value. Otherwise, just subtract the given absorption line from the spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum including the absorption line, in angstroms. This wavelengths array will have a different shape than the previous wavelengths array.

spectrum :: array of floats The spectrum with the absorption line subtracted. This spectrum array will have a different shape than the previous spectrum array.

Returns

None

generate_emission_line(center, fwhm, peak=None, tot_flux=None, shape='gaussian', limits=[100, 1200] << u.nm, overwrite=False, quiet=False)

Generate a spectrum representing a single emission line. The resolution of the spectrum is at least 1% of the wavelength range.

To add/subtract a spectral line to/from a spectrum, see the add_emission_line() and add_absorption_line() methods instead.

Parameters

center :: scalar or astropy.Quantity The central wavelength of the emission line. If a scalar, it is assumed to be in angstrom.

fwhm :: scalar or astropy.Quantity The full-width at half-maximum of the emission line. If a scalar, it is assumed to be in angstrom.

peak :: int or float The peak flux of the emission line (i.e., the flux at the center wavelength). Exactly one of peak or tot_flux must be specified.

tot_flux :: int or float The total flux under the curve. Exactly one of peak or tot_flux must be specified.

shape :: “gaussian” or “lorentzian” The emission line profile.

limits :: 2-element 1D array of astropy.Quantity or scalars The [min, max] wavelengths of the spectrum. If the elements are scalars, it is assumed to be in angstrom. The center of the emission line must be within these limits.

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum, in angstroms.

spectrum :: array of floats The emission line spectrum in units of flam (erg/s/cm^2/A).

Returns

None

set_spectrum(wavelengths, spectrum, unit, overwrite=False, quiet=False)

Set the spectrum of the source based on the input arrays. To use a spectrum from a file, see the use_custom_spectrum() method.

The input spectrum should have units of either flam (erg/s/cm^2/A), fnu (erg/s/cm^2/Hz), ABmag (AB magnitude), or STmag (ST magnitude). Note that the computed (and stored) spectrum will always be in units of flam.

Parameters

wavelengths :: array of scalars or astropy.Quantity array The wavelengths over which to generate the uniform spectrum. If an array of scalars, it should be in angstrom. This should be a 1D array with the same length as the spectrum array.

specturm :: array of scalars The value of the spectrum at the given wavelengths, in units of unit. This should be a 1D array with the same length as the wavelengths array.

unit :: “flam” or “fnu” or “ABmag” or “STmag” The unit of the spectrum array: either flam (erg/s/cm^2/A), fnu (erg/s/cm^2/Hz), ABmag (AB magnitude), or STmag (ST magnitude).

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity` array The given wavelengths of the spectrum, converted into units of angstrom.

spectrum :: array of floats The given spectrum, converted into units of erg/s/cm^2/A.

Returns

None

use_custom_spectrum(filepath, wavelength_unit=u.AA, overwrite=False, quiet=False)

Use custom spectrum from an ASCII or FITS file. To use a spectrum from an array, use the set_spectrum() method.

Parameters

filepath :: str The absolute path to the file containing the spectrum. If the file is in ASCII format, the first column should contain the wavelengths in wavelength_units and the second column containing the spectrum in flam (erg/s/cm^2/A); the columns should be separated by a constant number of spaces. Lines starting with a hash (#) will be ignored. The file extension must not be .fit or .fits. If the file is in FITS format, the first field (index 0) should contain the wavelengths in wavelength_units and the second field (index 1) should contain the spectrum in flam (erg/s/cm^2/A). The file extension must be .fit or .fits.

wavelength_unit :: astropy.Quantity length unit The unit of the wavelengths in the file (e.g., u.AA for angstrom, u.nm for nanometer, u.um for micrometer, etc.)

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum, in angstroms.

spectrum :: array of floats Source spectrum in units of flam (erg/s/cm^2/A).

Returns

None

use_galaxy_spectrum(gal_type, overwrite=False, quiet=False)

Use one of the predefined galaxy spectra. These non-uniformly sampled spectra are from Fioc & Rocca-Volmerange (1997) https://ui.adsabs.harvard.edu/abs/1997A%26A…326..950F/abstract. In particular, the data files were downloaded from the Gemini Observatory Control Software (OCS) GitHub repository: https://github.com/gemini-hlsw/ocs/blob/develop/bundle/edu.gemini.itc/src/main/resources/sed/non_stellar/elliptical-galaxy.nm and https://github.com/gemini-hlsw/ocs/blob/develop/bundle/edu.gemini.itc/src/main/resources/sed/non_stellar/spiral-galaxy.nm.

Parameters

gal_type :: “elliptical” or “spiral” The galaxy morphology. The elliptical galaxy (class T=-5, -4) and spiral galaxy (type Sc, class T=5) spectra both run from 22-9698 nm.

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum, in angstroms.

spectrum :: array of floats Galaxy spectrum in arbitrary units, normalized such that it is equal to 1 at 550 nm.

Returns

None

_calc_xy()

Internal function that converts (ra, dec) of the identified Gaia sources to pixel positions on the CCD.

Attributes

gaia :: dict of arrays Dictionary containing the interpolated parameters of the queried Gaia sources.

Return

None
_search_gaia()

Internal Function. Search Gaia catalog for target and background stars.

Parameters

TelescopeObj :: `castor_etc.Telescope` instance
  The `Telescope` object passed down to the _calc_xy function.

Attributes

gaia :: dict of arrays Dictionary containing the interpolated parameters of the queried Gaia sources.

Returns

None

_specify_target_parameters(run_gaia_search=True)

Internal function. Used to specify target Gaia parameters and populate the gaia attribute of the PointSource. If temperature, Teff, and Gaia G magnitude, Gmag, of the target are specified, then Gaia catalog query will not run.

Parameters

run_gaia_search :: bool If Teff and Gmag of the target are specified, then this attributes is set to False and gaia query run is called off.

Attributes

gaia :: dict of arrays Dictionary containing the interpolated parameters of the queried Gaia sources.

Returns

None

use_gaia_spectrum(TelescopeObj, ra=None, dec=None, srch_Gmax=21.0, srch_nmax=100, srch_rad=None, Teff=None, Gmag=None, logg=None, radius=None, metallicity=None, Bpmag=None, Rpmag=None, stellar_model_grid='ATLAS9', stellar_model_dir=None, bkg_sources=True, fov=None, fov_pa=0 * u.deg, overwrite=False, quiet=False)

Use a spectrum from either the ATLAS9 catalog or the Bt-Sett1 catalog containing flux spectra for numerous stellar model atmospheres.

Parameters

TelescopeObj :: castor_etc.Telescope instance ‘The Telescope object containing the field of view (FoV) value required to calculate the search radius for querying the Gaia database.

ra :: astropy.Quantity int or float Right ascension of the target in degree

dec :: astropy.Quantity int or float Declination of the target in degree

srch_Gmax :: int or float Maximum Gaia G magnitude for Gaia catalog query (applies to both the target and the guide stars)

srch_nmax :: int Maximum Gaia sources to include.

srch_rad :: astropy.Quantity Search radius, in degree, for Gaia catalog query (applies to both the target and the guide stars)

Teff :: int or float Effective temperature of the target in Kelvin

Gmag :: int or float Gaia G magnitude of the target used to query the Gaia catalog

logg :: int or float log(g) value of the target

radius :: int or float radius of the target

metallicity :: int or float metallicity of the target

Bpmag :: int or float Gaia BP magnitude of the target

Rpmag :: int or float Gaia RP magnitude of the target

stellar_model_grid :: str Stellar model grid, ‘ATLAS9’ or ‘BTSettl’, for selecting spectrum of the source according to the interpolated stellar atmosphere model.

stellar_model_dir :: str Path to the stellar models directory used by the getStarData function to calculate spectrum of stars.

bkg_sources :: bool If True, then background Gaia sources are included during the transit simulation calculation. If False, nmax is set to 1.

fov :: int or float Full width FoV in degree

fov_pa :: astropy.Quantity Field of view position angle

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum, in angstroms,

spectrum :: array of floats Stellar spectrum in flam units

ra :: astropy.Quantity angle Right ascension of the target in degree

dec :: astropy.Quantity angle Declination of the target in degree

srch_Gmax :: int or float Maximum Gaia G magnitude for Gaia catalog query (applies to both the target and the guide stars)

srch_nmax :: int Maximum Gaia sources to include.

srch_rad :: astropy.Quantity Search radius, in degree, for Gaia catalog query (applies to both the target and the guide stars)

Teff :: int or float Effective temperature of the target in Kelvin

Gmag :: int or float Gaia G magnitude of the target used to query the Gaia catalog

logg :: int or float log(g) value of the target

radius :: int or float radius of the target

metallicity :: int or float metallicity of the target

Bpmag :: int or float Gaia BP magnitude of the target

Rpmag :: int or float Gaia RP magnitude of the target

stellar_model_grid :: str Stellar model grid, ‘ATLAS9’ or ‘BTSettl’, for selecting spectrum of the source according to the interpolated stellar atmosphere model.

stellar_model_dir :: str Path to the stellar models directory used by the getStarData function to calculate spectrum of stars.

bkg_sources :: bool If True, then background Gaia sources are included during the transit simulation calculation. If False, nmax is set to 1.

fov :: int or float Full width FoV in degree

fov_pa :: astropy.Quantity Field of view position angle

ccd_dim :: int list CCD dimesions adopted from TelescopeObj

Returns

None
use_pickles_spectrum(spectral_class, overwrite=False, quiet=False)

Use a spectrum from the Pickles catalog (https://ui.adsabs.harvard.edu/abs/1998PASP..110..863P/abstract) containing spectra for numerous stellar spectral classes.

A table containing valid spectral_class inputs is at the end of this docstring.

Parameters

spectral_class :: str from the “Table of valid spectral_class inputs” below The spectral type of the star.

overwrite :: bool If True, overwrite any existing wavelengths/spectrum. If False, raise an error if wavelengths or spectrum is not None.

quiet :: bool If True, do not print a message when overwriting an existing spectrum.

Attributes

wavelengths :: astropy.Quantity array The wavelengths of the spectrum, in angstroms.

spectrum :: array of floats Stellar spectrum in arbitrary units, normalized such that it is equal to 1 at 5556 angstrom.

Returns

None

Table of valid spectral_class inputs

  spectral_class      Description (& wavelength range)
  --------------      --------------------------------
  "a0i"               A0 I     (1150-10620 A)
  "a0iii"             A0 III   (1150-10620 A)
  "a0iv"              A0 IV    (1150-10620 A)
  "a0v"               A0 V     (1150-10620 A)
  "a2i"               A2 I     (1150-10620 A)
  "a2v"               A2 V     (1150-10620 A)
  "a3iii"             A3 III   (1150-10620 A)
  "a3v"               A3 V     (1150-10620 A)
  "a47iv"             A4-7 IV  (1150-10620 A)
  "a5iii"             A5 III   (1150-10620 A)
  "a5v"               A5 V     (1150-10620 A)
  "a7iii"             A7 III   (1150-10620 A)
  "a7v"               A7 V     (1150-10620 A)
  "b0i"               B0 I     (1150-10620 A)
  "b0v"               B0 V     (1150-10620 A)
  "b12iii"            B1-2 III (1150-10620 A)
  "b1i"               B1 I     (1150-10620 A)
  "b1v"               B1 V     (1150-10620 A)
  "b2ii"              B2 II    (1150-10620 A)
  "b2iv"              B2 IV    (1150-10620 A)
  "b3i"               B3 I     (1150-10620 A)
  "b3iii"             B3 III   (1150-10620 A)
  "b3v"               B3 V     (1150-10620 A)
  "b57v"              B5-7 V   (1150-10620 A)
  "b5i"               B5 I     (1150-10620 A)
  "b5ii"              B5 II    (1150-10620 A)
  "b5iii"             B5 III   (1150-10620 A)
  "b6iv"              B6 IV    (1150-10620 A)
  "b8i"               B8 I     (1150-10620 A)
  "b8v"               B8 V     (1150-10620 A)
  "b9iii"             B9 III   (1150-10620 A)
  "b9v"               B9 V     (1150-10620 A)
  "f02iv"             F0-2 IV  (1150-10620 A)
  "f0i"               F0 I     (1150-10620 A)
  "f0ii"              F0 II    (1150-10620 A)
  "f0iii"             F0 III   (1150-10620 A)
  "f0v"               F0 V     (1150-10620 A)
  "f2ii"              F2 II    (1150-10620 A)
  "f2iii"             F2 III   (1150-10620 A)
  "f2v"               F2 V     (1150-10620 A)
  "f5i"               F5 I     (1150-10620 A)
  "f5iii"             F5 III   (1150-10620 A)
  "f5iv"              F5 IV    (1150-10620 A)
  "f5v"               F5 V     (1150-10620 A)
  "f6v"               F6 V     (1150-10620 A)
  "f8i"               F8 I     (1150-10620 A)
  "f8iv"              F8 IV    (1150-10620 A)
  "f8v"               F8 V     (1150-10620 A)
  "g0i"               G0 I     (1150-10620 A)
  "g0iii"             G0 III   (1150-10620 A)
  "g0iv"              G0 IV    (1150-10620 A)
  "g0v"               G0 V     (1150-10620 A)
  "g2i"               G2 I     (1150-10620 A)
  "g2iv"              G2 IV    (1150-10620 A)
  "g2v"               G2 V     (1150-10620 A)
  "g5i"               G5 I     (1150-10620 A)
  "g5ii"              G5 II    (1150-10620 A)
  "g5iii"             G5 III   (1150-10620 A)
  "g5iv"              G5 IV    (1150-10620 A)
  "g5v"               G5 V     (1150-10620 A)
  "g8i"               G8 I     (1150-10620 A)
  "g8iii"             G8 III   (1150-10620 A)
  "g8iv"              G8 IV    (1150-10620 A)
  "g8v"               G8 V     (1150-10620 A)
  "k01ii"             K0-1 II  (1150-10620 A)
  "k0iii"             K0 III   (1150-10620 A)
  "k0iv"              K0 IV    (1150-10620 A)
  "k0v"               K0 V     (1150-10620 A)
  "k1iii"             K1 III   (1150-10620 A)
  "k1iv"              K1 IV    (1150-10620 A)
  "k2i"               K2 I     (1150-10620 A)
  "k2iii"             K2 III   (1150-10620 A)
  "k2v"               K2 V     (1150-10620 A)
  "k34ii"             K3-4 II  (1150-10620 A)
  "k3i"               K3 I     (1150-10620 A)
  "k3iii"             K3 III   (1150-10620 A)
  "k3iv"              K3 IV    (1150-10620 A)
  "k3v"               K3 V     (1150-10620 A)
  "k4i"               K4 I     (1150-10620 A)
  "k4iii"             K4 III   (1150-10620 A)
  "k4v"               K4 V     (1150-10620 A)
  "k5iii"             K5 III   (1150-10620 A)
  "k5v"               K5 V     (1150-10620 A)
  "k7v"               K7 V     (1150-10620 A)
  "m0iii"             M0 III   (1150-10620 A)
  "m0v"               M0 V     (1150-10620 A)
  "m10iii"            M10 III  (1150-10620 A)
  "m1iii"             M1 III   (1150-10620 A)
  "m1v"               M1 V     (1150-10620 A)
  "m2i"               M2 I     (1150-10620 A)
  "m2iii"             M2 III   (1150-10620 A)
  "m2p5v"             M2.5 V   (1150-10620 A)
  "m2v"               M2 V     (1150-10620 A)
  "m3ii"              M3 II    (1150-10620 A)
  "m3iii"             M3 III   (1150-10620 A)
  "m3v"               M3 V     (1150-10620 A)
  "m4iii"             M4 III   (1150-10620 A)
  "m4v"               M4 V     (1150-10620 A)
  "m5iii"             M5 III   (1150-10620 A)
  "m5v"               M5 V     (1150-10620 A)
  "m6iii"             M6 III   (1150-10620 A)
  "m6v"               M6 V     (1150-10620 A)
  "m7iii"             M7 III   (1150-10620 A)
  "m8iii"             M8 III   (1150-10620 A)
  "m9iii"             M9 III   (1150-10620 A)
  "o5v"               O5 V     (1150-10620 A)
  "o8iii"             O8 III   (1150-10620 A)
  "o9v"               O9 V     (1150-10620 A)
  "rf6v"              metal-rich F6 V    (1150-10620 A)
  "rf8v"              metal-rich F8 V    (1150-10620 A)
  "rg0v"              metal-rich G0 V    (1150-10620 A)
  "rg5iii"            metal-rich G5 III  (1150-10620 A)
  "rg5v"              metal-rich G5 V    (1150-10620 A)
  "rk0iii"            metal-rich K0 III  (1150-10620 A)
  "rk0v"              metal-rich K0 V    (1150-10620 A)
  "rk1iii"            metal-rich K1 III  (1150-10620 A)
  "rk2iii"            metal-rich K2 III  (1150-10620 A)
  "rk3iii"            metal-rich K3 III  (1150-10620 A)
  "rk4iii"            metal-rich K4 III  (1150-10620 A)
  "rk5iii"            metal-rich K5 III  (1150-10620 A)
  "uka0i"             A0 I     (1150-25000 A)
  "uka0iii"           A0 III   (1150-25000 A)
  "uka0iv"            A0 IV    (1150-25000 A)
  "uka0v"             A0 V     (1150-25000 A)
  "uka2i"             A2 I     (1150-25000 A)
  "uka2v"             A2 V     (1150-25000 A)
  "uka3iii"           A3 III   (1150-25000 A)
  "uka3v"             A3 V     (1150-25000 A)
  "uka47iv"           A4-7 IV  (1150-25000 A)
  "uka5iii"           A5 III   (1150-25000 A)
  "uka5v"             A5 V     (1150-25000 A)
  "uka7iii"           A7 III   (1150-25000 A)
  "uka7v"             A7 V     (1150-25000 A)
  "ukb0i"             B0 I     (1150-25000 A)
  "ukb0v"             B0 V     (1150-25000 A)
  "ukb12iii"          B1-2 III (1150-25000 A)
  "ukb1i"             B1 I     (1150-25000 A)
  "ukb1v"             B1 V     (1150-25000 A)
  "ukb2ii"            B2 II    (1150-25000 A)
  "ukb2iv"            B2 IV    (1150-25000 A)
  "ukb3i"             B3 I     (1150-25000 A)
  "ukb3iii"           B3 III   (1150-25000 A)
  "ukb3v"             B3 V     (1150-25000 A)
  "ukb57v"            B5-7 V   (1150-25000 A)
  "ukb5i"             B5 I     (1150-25000 A)
  "ukb5ii"            B5 II    (1150-25000 A)
  "ukb5iii"           B5 III   (1150-25000 A)
  "ukb6iv"            B6 IV    (1150-25000 A)
  "ukb8i"             B8 I     (1150-25000 A)
  "ukb8v"             B8 V     (1150-25000 A)
  "ukb9iii"           B9 III   (1150-25000 A)
  "ukb9v"             B9 V     (1150-25000 A)
  "ukf02iv"           F0-2 IV  (1150-25000 A)
  "ukf0i"             F0 I     (1150-25000 A)
  "ukf0ii"            F0 II    (1150-25000 A)
  "ukf0iii"           F0 III   (1150-25000 A)
  "ukf0v"             F0 V     (1150-25000 A)
  "ukf2ii"            F2 II    (1150-25000 A)
  "ukf2iii"           F2 III   (1150-25000 A)
  "ukf2v"             F2 V     (1150-25000 A)
  "ukf5i"             F5 I     (1150-25000 A)
  "ukf5iii"           F5 III   (1150-25000 A)
  "ukf5iv"            F5 IV    (1150-25000 A)
  "ukf5v"             F5 V     (1150-25000 A)
  "ukf6v"             F6 V     (1150-25000 A)
  "ukf8i"             F8 I     (1150-25000 A)
  "ukf8iv"            F8 IV    (1150-25000 A)
  "ukf8v"             F8 V     (1150-25000 A)
  "ukg0i"             G0 I     (1150-25000 A)
  "ukg0iii"           G0 III   (1150-25000 A)
  "ukg0iv"            G0 IV    (1150-25000 A)
  "ukg0v"             G0 V     (1150-25000 A)
  "ukg2i"             G2 I     (1150-25000 A)
  "ukg2iv"            G2 IV    (1150-25000 A)
  "ukg2v"             G2 V     (1150-25000 A)
  "ukg5i"             G5 I     (1150-25000 A)
  "ukg5ii"            G5 II    (1150-25000 A)
  "ukg5iii"           G5 III   (1150-25000 A)
  "ukg5iv"            G5 IV    (1150-25000 A)
  "ukg5v"             G5 V     (1150-25000 A)
  "ukg8i"             G8 I     (1150-25000 A)
  "ukg8iii"           G8 III   (1150-25000 A)
  "ukg8iv"            G8 IV    (1150-25000 A)
  "ukg8v"             G8 V     (1150-25000 A)
  "ukk01ii"           K0-1 II  (1150-25000 A)
  "ukk0iii"           K0 III   (1150-25000 A)
  "ukk0iv"            K0 IV    (1150-25000 A)
  "ukk0v"             K0 V     (1150-25000 A)
  "ukk1iii"           K1 III   (1150-25000 A)
  "ukk1iv"            K1 IV    (1150-25000 A)
  "ukk2i"             K2 I     (1150-25000 A)
  "ukk2iii"           K2 III   (1150-25000 A)
  "ukk2v"             K2 V     (1150-25000 A)
  "ukk34ii"           K3-4 II  (1150-25000 A)
  "ukk3i"             K3 I     (1150-25000 A)
  "ukk3iii"           K3 III   (1150-25000 A)
  "ukk3iv"            K3 IV    (1150-25000 A)
  "ukk3v"             K3 V     (1150-25000 A)
  "ukk4i"             K4 I     (1150-25000 A)
  "ukk4iii"           K4 III   (1150-25000 A)
  "ukk4v"             K4 V     (1150-25000 A)
  "ukk5iii"           K5 III   (1150-25000 A)
  "ukk5v"             K5 V     (1150-25000 A)
  "ukk7v"             K7 V     (1150-25000 A)
  "ukm0iii"           M0 III   (1150-25000 A)
  "ukm0v"             M0 V     (1150-25000 A)
  "ukm10iii"          M10 III  (1150-25000 A)
  "ukm1iii"           M1 III   (1150-25000 A)
  "ukm1v"             M1 V     (1150-25000 A)
  "ukm2i"             M2 I     (1150-25000 A)
  "ukm2iii"           M2 III   (1150-25000 A)
  "ukm2p5v"           M2.5 V   (1150-25000 A)
  "ukm2v"             M2 V     (1150-25000 A)
  "ukm3ii"            M3 II    (1150-25000 A)
  "ukm3iii"           M3 III   (1150-25000 A)
  "ukm3v"             M3 V     (1150-25000 A)
  "ukm4iii"           M4 III   (1150-25000 A)
  "ukm4v"             M4 V     (1150-25000 A)
  "ukm5iii"           M5 III   (1150-25000 A)
  "ukm5v"             M5 V     (1150-25000 A)
  "ukm6iii"           M6 III   (1150-25000 A)
  "ukm6v"             M6 V     (1150-25000 A)
  "ukm7iii"           M7 III   (1150-25000 A)
  "ukm8iii"           M8 III   (1150-25000 A)
  "ukm9iii"           M9 III   (1150-25000 A)
  "uko5v"             O5 V     (1150-25000 A)
  "uko8iii"           O8 III   (1150-25000 A)
  "uko9v"             O9 V     (1150-25000 A)
  "ukrf6v"            metal-rich F6 V    (1150-25000 A)
  "ukrf8v"            metal-rich F8 V    (1150-25000 A)
  "ukrg0v"            metal-rich G0 V    (1150-25000 A)
  "ukrg5iii"          metal-rich G5 III  (1150-25000 A)
  "ukrg5v"            metal-rich G5 V    (1150-25000 A)
  "ukrk0iii"          metal-rich K0 III  (1150-25000 A)
  "ukrk0v"            metal-rich K0 V    (1150-25000 A)
  "ukrk1iii"          metal-rich K1 III  (1150-25000 A)
  "ukrk2iii"          metal-rich K2 III  (1150-25000 A)
  "ukrk3iii"          metal-rich K3 III  (1150-25000 A)
  "ukrk4iii"          metal-rich K4 III  (1150-25000 A)
  "ukrk5iii"          metal-rich K5 III  (1150-25000 A)
  "ukwf5v"            metal-weak F5 V    (1150-25000 A)
  "ukwf8v"            metal-weak F8 V    (1150-25000 A)
  "ukwg0v"            metal-weak G0 V    (1150-25000 A)
  "ukwg5iii"          metal-weak G5 III  (1150-25000 A)
  "ukwg5v"            metal-weak G5 V    (1150-25000 A)
  "ukwg8iii"          metal-weak G8 III  (1150-25000 A)
  "ukwk0iii"          metal-weak K0 III  (1150-25000 A)
  "ukwk1iii"          metal-weak K1 III  (1150-25000 A)
  "ukwk2iii"          metal-weak K2 III  (1150-25000 A)
  "ukwk3iii"          metal-weak K3 III  (1150-25000 A)
  "ukwk4iii"          metal-weak K4 III  (1150-25000 A)
  "wf5v"              metal-weak F5 V    (1150-10620 A)
  "wf8v"              metal-weak F8 V    (1150-10620 A)
  "wg0v"              metal-weak G0 V    (1150-10620 A)
  "wg5iii"            metal-weak G5 III  (1150-10620 A)
  "wg5v"              metal-weak G5 V    (1150-10620 A)
  "wg8iii"            metal-weak G8 III  (1150-10620 A)
  "wk0iii"            metal-weak K0 III  (1150-10620 A)
  "wk1iii"            metal-weak K1 III  (1150-10620 A)
  "wk2iii"            metal-weak K2 III  (1150-10620 A)
  "wk3iii"            metal-weak K3 III  (1150-10620 A)
  "wk4iii"            metal-weak K4 III  (1150-10620 A)
use_flare_simulator()
show_spectrum(plot=True)

Plot the spectrum (which should be in units of flam).

Parameters

plot :: bool If True, plot the source weights and return None. If False, return the figure and axis instance associated with the plot.

Returns

None (if plot is True)

fig, ax (if plot is False) :: matplotlib.figure.Figure, matplotlib.axes.Axes The figure and axis instance associated with the plot.

calc_redleak_frac(TelescopeObj, quiet=False)

Calculate a source’s red leak fraction. The red leak fraction is defined to be the ratio of the electron rate (i.e., electron/s) induced by red leak flux to the total electron rate induced by the entire spectrum.

Parameters

TelescopeObj :: castor_etc.Telescope instance The Telescope object containing the passband response curves to use for the red leak calculation.

quiet :: bool If True, suppress warnings from red leak fraction calculations.

Returns

redleak_fracs :: dict of floats Dictionary containing the red leak fraction in each passband.

class castor_etc.spectra.base.NormMixin

Mixin for normalizing spectra.

TODO: Make normalization to a specific value at a given wavelength?

static norm_to_star(spectrum, radius=1, dist=1 << u.kpc)

Normalize the blackbody spectrum to a star of given radius and distance. By default, normalizes the flux to a star of 1 solar radius at 1 kpc. Reference: https://github.com/spacetelescope/pysynphot/blob/925cdbac35a7851cee1bddaa2b47651235c44851/pysynphot/spectrum.py#L40.

Note that the spectrum’s units should have a unit of steradian (sr) in the denominator, which will be multiplied out (e.g., erg/s/cm^2/A/sr).

Parameters

spectrum :: array of floats The spectrum to normalize. It should have a unit of steradian in the denominator.

radius :: float or astropy.Quantity length The radius of the source. If a scalar, it is assumed to be in units of solar radii.

dist :: float or astropy.Quantity length The distance to the blackbody. If a scalar, it is assumed to be in units of kpc.

Returns

norm_spectrum :: array of floats Spectrum normalized such that the unit of steradian in the denominator vanishes.

norm_to_AB_mag(ab_mag, passband=None, TelescopeObj=None)

Normalize a spectrum to a given AB magnitude in a specified passband or to a given bolometric AB magnitude. The spectrum should be in units of flam (erg/s/cm^2/A). The bolometric magnitude calculation assumes a perfect (unity) passband response.

WARNING: if the spectrum does not vanish at the edges (e.g., a uniform spectrum), then the bolometric magnitude will depend on the length of the spectrum! This is because the area under the curve does not converge!

Parameters

ab_mag :: int or float The desired AB magnitude.

passband :: valid Telescope passband string (e.g., “uv”, “u”, “g”) or None If not None, normalize the spectrum such that it has the desired AB magnitude in this passband; TelescopeObj must also be provided. If None, normalize the spectrum such that the spectrum’s bolometric magnitude equals the given AB magnitude; TelescopeObj must not be provided.

TelescopeObj :: Telescope object or None The Telescope object containing the limits and response curves of the different passbands. If not None, passband must also be provided. If None, passband must not be provided.

Attributes

spectrum :: array of floats The renormalized spectrum in units of erg/s/cm^2/A (identical to the previous spectrum units).

Returns

None

norm_luminosity_dist(luminosity, dist)

Normalize the spectrum to a source of given (bolometric) luminosity and distance. The Source object should have its spectrum in units of flam (erg/s/cm^2/A) and wavelengths in angstrom. (Technically it is okay as long as the wavelengths are in some unit and the spectrum is in units of erg/s/cm^2/.)

Parameters

luminosity :: scalar or astropy.Quantity unit of power The desired bolometric luminosity. If a scalar, this is assumed to be in units of solar luminosities. If an astropy.Quantity, it must be a unit of power (e.g., erg/s).

dist :: float or astropy.Quantity length The distance to the source. If a scalar, it is assumed to be in units of kpc.

Attributes

spectrum :: array Normalized spectrum in original flux density units (e.g., erg/s/cm^2/A).

Returns

None

get_AB_mag(TelescopeObj=None)

Calculate the AB magnitude of the source either through the telescope’s passbands or over the whole spectrum (bolometric magnitude). Note that the source spectrum should be in units of erg/s/cm^2/A. The bolometric magnitude calculation assumes a perfect (unity) passband response.

WARNING: if the spectrum does not vanish at the edges (e.g., a uniform spectrum), then the bolometric magnitude will depend on the length of the spectrum! This is because the area under the curve does not converge!

Parameters

TelescopeObj :: Telescope object or None If provided, will calculate the AB magnitude of the source in each of the telescope’s passbands. Otherwise will calculate the source’s bolometric AB magnitude.

Returns

ab_mags :: scalar or dict of scalars If TelescopeObj is None, the result is a scalar equal to the bolometric AB magnitude of the source. If TelescopeObj is not None, the result is a dict of scalars representing the source’s AB magnitude through each of the telescope’s passbands.