# Spectral Tools¶

Class Summary

 source_spectrum(name, sptype, mag_val, bp, …) Model source spectrum planets_sb12([atmo, mass, age, entropy, …]) Exoplanet spectrum from Spiegel & Burrows (2012)

Functions Summary

 stellar_spectrum(sptype, *renorm_args, **kwargs) Stellar spectrum BOSZ_spectrum(Teff, metallicity, log_g[, …]) BOSZ stellar atmospheres (Bohlin et al 2017). sp_accr(mmdot[, rin, dist, truncated, …]) Exoplanet accretion flux values (Zhu et al., 2015). jupiter_spec([dist, waveout, fluxout, base_dir]) Jupiter as an Exoplanet zodi_spec([zfact, ra, dec, thisday]) Zodiacal light spectrum. zodi_euclid(locstr, year, day[, …]) IPAC Euclid Background Model bp_2mass(filter) 2MASS Bandpass bin_spectrum(sp, wave[, waveunits]) Rebin spectrum

Documentation

class pynrc.nrc_utils.source_spectrum(name, sptype, mag_val, bp, votable_file, Teff=None, metallicity=None, log_g=None, Av=None, **kwargs)[source]

Bases: object

Model source spectrum

The class ingests spectral information of a given target and generates pysynphot.spectrum model fit to the known photometric SED. Two model routines can fit. The first is a very simple scale factor that is applied to the input spectrum, while the second takes the input spectrum and adds an IR excess modeled as a modified blackbody function.

Parameters
• name (string) – Source name.

• sptype (string) – Assumed stellar spectral type. Not relevant if Teff, metallicity, and log_g are specified.

• mag_val (float) – Magnitude of input bandpass for initial scaling of spectrum.

• bp (pysynphot.obsbandpass) – Bandpass to apply initial mag_val scaling.

• votable_file (string) – VOTable name that holds the source’s photometry. The user can find the relevant data at http://vizier.u-strasbg.fr/vizier/sed/ and click download data.

Keyword Arguments
• Teff (float) – Effective temperature ranging from 3500K to 30000K.

• metallicity (float) – Metallicity [Fe/H] value ranging from -2.5 to 0.5.

• log_g (float) – Surface gravity (log g) from 0 to 5.

• catname (str) – Catalog name, including ‘bosz’, ‘ck04models’, and ‘phoenix’. Default is ‘bosz’, which comes from BOSZ_spectrum().

• res (str) – Spectral resolution to use (200 or 2000 or 20000).

• interpolate (bool) – Interpolate spectrum using a weighted average of grid points surrounding the desired input parameters.

Example

Generate a source spectrum and fit photometric data

>>> import pynrc
>>> from pynrc.nrc_utils import source_spectrum
>>>
>>> name = 'HR8799'
>>> vot = 'votables/{}.vot'.format(name)
>>> bp_k = pynrc.bp_2mass('k')
>>>
>>> # Read in stellar spectrum model and normalize to Ks = 5.24
>>> src = source_spectrum(name, 'F0V', 5.24, bp_k, vot,
>>>                       Teff=7430, metallicity=-0.47, log_g=4.35)
>>> # Fit model to photometry from 0.1 - 30 micons
>>> # Saves pysynphot spectral object at src.sp_model
>>> src.fit_SED(wlim=[0.1,30])
>>> sp_sci = src.sp_model


Methods Summary

 bb_jy(wave, T) Blackbody function (Jy) model_scale(x[, sp]) Simple model to scale stellar spectrum model_IRexcess(x[, sp]) Model for stellar spectrum with IR excesss func_resid(x[, IR_excess, wlim, use_err]) Calculate model residuals fit_SED([x0, robust, use_err, IR_excess, …]) Fit a model function to photometry plot_SED([ax, return_figax, xr, yr, units])

Methods Documentation

bb_jy(wave, T)[source]

Blackbody function (Jy)

For a given wavelength set (in um) and a Temperature (K), return the blackbody curve in units of Jy.

Parameters
• wave (array_like) – Wavelength array in microns

• T (float) – Temperature of blackbody (K)

model_scale(x, sp=None)[source]

Simple model to scale stellar spectrum

model_IRexcess(x, sp=None)[source]

Model for stellar spectrum with IR excesss

Model of a stellar spectrum plus IR excess, where the excess is a modified blackbody. The final model follows the form:

$x_0 BB(\lambda, x_1) \lambda^{x_2}$
func_resid(x, IR_excess=False, wlim=[0.1, 30], use_err=True)[source]

Calculate model residuals

Parameters
• x (array_like) – Model parameters for either model_scale or model_IRexcess. See these two functions for more details.

• IR_excess (bool) – Include IR excess in model fit? This is a simple modified blackbody.

• wlim (array_like) – Min and max limits for wavelengths to consider (microns).

• use_err (bool) – Should we use the uncertainties in the SED photometry for weighting?

fit_SED(x0=None, robust=True, use_err=True, IR_excess=False, wlim=[0.3, 10], verbose=True)[source]

Fit a model function to photometry

Use scipy.optimize.least_squares() to find the best fit model to the observed photometric data. If not parameters passed, then defaults are set.

Keyword Arguments
• x0 (array_like) – Initial guess of independent variables.

• robust (bool) – Perform an outlier-resistant fit.

• use_err (bool) – Should we use the uncertainties in the SED photometry for weighting?

• IR_excess (bool) – Include IR excess in model fit? This is a simple modified blackbody.

• wlim (array_like) – Min and max limits for wavelengths to consider (microns).

• verbose (bool) – Print out best-fit model parameters. Defalt is True.

plot_SED(ax=None, return_figax=False, xr=[0.3, 30], yr=None, units='Jy', **kwargs)[source]
class pynrc.nrc_utils.planets_sb12(atmo='hy1s', mass=1, age=100, entropy=10.0, distance=10, accr=False, mmdot=None, mdot=None, accr_rin=2.0, truncated=False, base_dir=None, **kwargs)[source]

Bases: object

Exoplanet spectrum from Spiegel & Burrows (2012)

This contains 1680 files, one for each of 4 atmosphere types, each of 15 masses, and each of 28 ages. Wavelength range of 0.8 - 15.0 um at moderate resolution (R ~ 204).

The flux in the source files are at 10 pc. If the distance is specified, then the flux will be scaled accordingly. This is also true if the distance is changed by the user. All other properties (atmo, mass, age, entropy) are not adjustable once loaded.

Parameters
• atmo (str) –

A string consisting of one of four atmosphere types:

• ‘hy1s’ = hybrid clouds, solar abundances

• ‘hy3s’ = hybrid clouds, 3x solar abundances

• ‘cf1s’ = cloud-free, solar abundances

• ‘cf3s’ = cloud-free, 3x solar abundances

• mass (float) – A number 1 to 15 Jupiter masses.

• age (float) – Age in millions of years (1-1000)

• entropy (float) – Initial entropy (8.0-13.0) in increments of 0.25

• distance (float) – Assumed distance in pc (default is 10pc)

• accr (bool) – Include accretion (default: False)?

• mmdot (float) – From Zhu et al. (2015), the Mjup^2/yr value. If set to None then calculated from age and mass.

• mdot (float) – Or use mdot (Mjup/yr) instead of mmdot.

• accr_rin (float) – Inner radius of accretion disk (units of RJup; default: 2)

• truncated (bool) – Full disk or truncated (ie., MRI; default: False)?

• base_dir (str, None) – Location of atmospheric model sub-directories.

Attributes Summary

 age Age in millions of years atmo Atmosphere type distance Assumed distance to source (pc) entropy Initial entropy (8.0-13.0) flux Spectral flux fluxunits Flux units mass Mass of planet (MJup) mdot Accretion rate in MJup/yr wave Wavelength of spectrum waveunits Wavelength units

Methods Summary

 export_pysynphot([waveout, fluxout]) Output to pysynphot.spectrum object

Methods Documentation

export_pysynphot(waveout='angstrom', fluxout='flam')[source]

Output to pysynphot.spectrum object

Export object settings to a pysynphot.spectrum.

Parameters
• waveout (str) – Wavelength units for output

• fluxout (str) – Flux units for output

pynrc.nrc_utils.stellar_spectrum(sptype, *renorm_args, **kwargs)[source]

Stellar spectrum

Similar to specFromSpectralType() in WebbPSF/Poppy, this function uses a dictionary of fiducial values to determine an appropriate spectral modelself. If the input spectral type is not found, this function interpolates the effective temperature, metallicity, and log g values .

You can also specify renormalization arguments to pass to sp.renorm(). The order (after sptype) should be (value, units, bandpass):

>>> sp = stellar_spectrum('G2V', 10, 'vegamag', bp)


Flat spectrum (in photlam) are also allowed via the ‘flat’ string.

Use catname='bosz' for BOSZ stellar atmosphere (ATLAS9) (default) Use catname='ck04models' keyword for ck04 models Use catname='phoenix' keyword for Phoenix models

Keywords exist to directly specify Teff, metallicity, an log_g rather than a spectral type.

Parameters
• sptype (str) – Spectral type, such as ‘A0V’ or ‘K2III’.

• renorm_args (tuple) – Renormalization arguments to pass to sp.renorm(). The order (after sptype) should be (value, units, bandpass) Bandpass should be a pysynphot.obsbandpass type.

Keyword Arguments
• catname (str) – Catalog name, including ‘bosz’, ‘ck04models’, and ‘phoenix’. Default is ‘bosz’, which comes from BOSZ_spectrum().

• Teff (float) – Effective temperature ranging from 3500K to 30000K.

• metallicity (float) – Metallicity [Fe/H] value ranging from -2.5 to 0.5.

• log_g (float) – Surface gravity (log g) from 0 to 5.

• res (str) – BOSZ spectral resolution to use (200 or 2000 or 20000).

• interpolate (bool) – Interpolate BOSZ spectrum using a weighted average of grid points surrounding the desired input parameters. Default is True.

pynrc.nrc_utils.BOSZ_spectrum(Teff, metallicity, log_g, res=2000, interpolate=True, **kwargs)[source]

BOSZ stellar atmospheres (Bohlin et al 2017).

Read in a spectrum from the BOSZ stellar atmosphere models database. Returns a Pysynphot spectral object. Wavelength values range between 1000-32000 Angstroms. Teff range from 3500K to 36000K.

This function interoplates the model grid by reading in those models closest in temperature, metallicity, and log g to the desired parameters, then takes the weighted average of these models based on their relative offsets. Can also just read in the closest model by setting interpolate=False.

Different spectral resolutions can also be specified, currently only res=200 or 2000 or 20000.

Parameters
• Teff (float) – Effective temperature ranging from 3500K to 30000K.

• metallicity (float) – Metallicity [Fe/H] value ranging from -2.5 to 0.5.

• log_g (float) – Surface gravity (log g) from 0 to 5.

Keyword Arguments
• res (str) – Spectral resolution to use (200 or 2000 or 20000).

• interpolate (bool) – Interpolate spectrum using a weighted average of grid points surrounding the desired input parameters.

References

https://archive.stsci.edu/prepds/bosz/

pynrc.nrc_utils.sp_accr(mmdot, rin=2, dist=10, truncated=False, waveout='angstrom', fluxout='flam', base_dir=None)[source]

Exoplanet accretion flux values (Zhu et al., 2015).

Calculated the wavelength-dependent flux of an exoplanet accretion disk/shock from Zhu et al. (2015). A

Note

This function only uses the table of photometric values to calculate photometric brightness from a source, so not very useful for simulating spectral observations.

Parameters
• mmdot (float) – Product of the exoplanet mass and mass accretion rate (MJup^2/yr). Values range from 1e-7 to 1e-2.

• rin (float) – Inner radius of accretion disk (units of RJup; default: 2).

• dist (float) – Distance to object (pc).

• truncated (bool) – If True, then the values are for a disk with Rout=50 RJup, otherwise, values were calculated for a full disk (Rout=1000 RJup). Accretion from a “tuncated disk” is due mainly to MRI. Luminosities for full and truncated disks are very similar.

• waveout (str) – Wavelength units for output

• fluxout (str) – Flux units for output

• base_dir (str, None) – Location of accretion model sub-directories.

pynrc.nrc_utils.jupiter_spec(dist=10, waveout='angstrom', fluxout='flam', base_dir=None)[source]

Jupiter as an Exoplanet

Read in theoretical Jupiter spectrum from Irwin et al. 2014 and output as a pysynphot.spectrum.

Parameters
• dist (float) – Distance to Jupiter (pc).

• waveout (str) – Wavelength units for output.

• fluxout (str) – Flux units for output.

• base_dir (str, None) – Location of tabulated file irwin_2014_ref_spectra.txt.

pynrc.nrc_utils.zodi_spec(zfact=None, ra=None, dec=None, thisday=None, **kwargs)[source]

Zodiacal light spectrum.

New: Use ra, dec, and thisday keywords to call jwst_backgrounds to obtain more accurate predictions of the background.

Creates a spectrum of the zodiacal light emission in order to estimate the in-band sky background flux. This is primarily the addition of two blackbodies at T=5300K (solar scattered light) and T=282K (thermal dust emission) that have been scaled to match literature flux values.

In reality, the intensity of the zodiacal dust emission varies as a function of viewing position. In this case, we have added the option to scale the zodiacal level (or each component individually) by some user-defined factor ‘zfact’. The user can set zfact as a scalar in order to scale the entire spectrum. If defined as a list, tuple, or np array, then the each component gets scaled where T=5300K corresponds to the first elements and T=282K is the second element of the array.

The zfact parameter has no effect if jwst_backgrounds is called. Representative values for zfact:

• 0.0 - No zodiacal emission

• 1.0 - Minimum zodiacal emission from JWST-CALC-003894

• 1.2 - Required NIRCam performance

• 2.5 - Average (default)

• 5.0 - High

• 10.0 - Maximum

Parameters
• zfact (float) – Factor to scale Zodiacal spectrum (default 2.5).

• ra (float) – Right ascension in decimal degrees

• dec (float) – Declination in decimal degrees

• thisday (int) – Calendar day to use for background calculation. If not given, will use the average of visible calendar days.

Returns

pysynphot.spectrum – Output is a Pysynphot spectrum with default units of flam (erg/s/cm^2/A/sr). Note: Pysynphot doesn’t recognize that it’s per steradian, but we must keep that in mind when integrating the flux per pixel.

Notes

Added the ability to query the Euclid background model using zodi_euclid() for a specific location and observing time. The two blackbodies will be scaled to the 1.0 and 5.5 um emission. This functionality is deprecated in favor of jwst_backgrounds.

Keyword Arguments
• locstr – Object name or RA/DEC (decimal degrees or sexigesimal). Queries the IPAC Euclid Background Model

• year (int) – Year of observation.

• day (float) – Day of observation.

pynrc.nrc_utils.zodi_euclid(locstr, year, day, wavelengths=[1, 5.5], ido_viewin=0, **kwargs)[source]

IPAC Euclid Background Model

Queries the IPAC Euclid Background Model in order to get date and position-specific zodiacal dust emission.

The program relies on urllib2 to download the page in XML format. However, the website only allows single wavelength queries, so this program implements a multithreaded procedure to query multiple wavelengths simultaneously. However, due to the nature of urllib2 library, only so many requests are allowed to go out at a time, so this process can take some time to complete. Testing shows about 500 wavelengths in 10 seconds as a rough ballpark.

Recommended to grab only a few wavelengths for normalization purposes.

References

See the Euclid Help Website for more details.

pynrc.nrc_utils.bp_2mass(filter)[source]

2MASS Bandpass

Create a 2MASS J, H, or Ks filter bandpass used to generate synthetic photometry.

Parameters

filter (str) – Filter ‘j’, ‘h’, or ‘k’.

Returns

pysynphot.obsbandpass – A Pysynphot bandpass object.

pynrc.nrc_utils.bin_spectrum(sp, wave, waveunits='um')[source]

Rebin spectrum

Rebin a pysynphot.spectrum to a lower wavelength grid. This function first converts the input spectrum to units of counts then combines the photon flux onto the specified wavelength grid.

Output spectrum units are the same as the input spectrum.

Parameters
• sp (pysynphot.spectrum) – Spectrum to rebin.

• wave (array_like) – Wavelength grid to rebin onto.

• waveunits (str) – Units of wave input. Must be recognizeable by Pysynphot.

Returns

pysynphot.spectrum – Rebinned spectrum in same units as input spectrum.