BaseSpectrum

class synphot.spectrum.BaseSpectrum(modelclass, clean_meta=False, **kwargs)[source]

Bases: object

Base class to handle spectrum or bandpass.

Note

Until astropy.modeling can handle units, all parameters are converted to pre-defined internal units.

Parameters:
modelclass : cls

Model class from astropy.modeling.models.

clean_meta : bool

Scrub “expr” and “header” entries from input metadata before merging. Set this to True when those entries no longer make sense in self. This is automatically set to True regardless for spectrum arithmetic.

kwargs : dict

Model parameters accepted by modelclass. Each parameter can be either a Quantity or number. If the latter, assume pre-defined internal units.

Raises:
synphot.exceptions.SynphotError

Invalid model.

Attributes:
meta : dict

Metadata associated with the spectrum or bandpass model (warnings, legacy SYNPHOT expression, FITS header, etc).

Attributes Summary

model Model of the spectrum/bandpass.
warnings Dictionary of warning key-value pairs related to spectrum/bandpass.
waverange Range of waveset.
waveset Optimal wavelengths for sampling the spectrum or bandpass.

Methods Summary

__call__(wavelengths) Sample the spectrum or bandpass.
avgwave([wavelengths]) Calculate the average wavelength.
barlam([wavelengths]) Calculate mean log wavelength.
force_extrapolation() Force the underlying model to extrapolate.
integrate([wavelengths]) Perform integration.
pivot([wavelengths]) Calculate pivot wavelength.
plot([wavelengths]) Plot the spectrum.
taper([wavelengths]) Taper the spectrum or bandpass.

Attributes Documentation

model

Model of the spectrum/bandpass.

warnings

Dictionary of warning key-value pairs related to spectrum/bandpass.

waverange

Range of waveset.

waveset

Optimal wavelengths for sampling the spectrum or bandpass.

Methods Documentation

__call__(wavelengths)[source]

Sample the spectrum or bandpass.

Parameters:
wavelengths : array-like or Quantity

Wavelength values for sampling. If not a Quantity, assumed to be in Angstrom.

Returns:
sampled_result : Quantity

Sampled flux or throughput in pre-defined internal unit. Might have negative values.

avgwave(wavelengths=None)[source]

Calculate the average wavelength.

Parameters:
wavelengths : array-like, Quantity, or None

Wavelength values for sampling. If not a Quantity, assumed to be in Angstrom. If None, waveset is used.

Returns:
avg_wave : Quantity

Average wavelength.

barlam(wavelengths=None)[source]

Calculate mean log wavelength.

Parameters:
wavelengths : array-like, Quantity, or None

Wavelength values for sampling. If not a Quantity, assumed to be in Angstrom. If None, waveset is used.

Returns:
bar_lam : Quantity

Mean log wavelength.

force_extrapolation()[source]

Force the underlying model to extrapolate.

An example where this is useful: You create a source spectrum with non-default extrapolation behavior and you wish to force the underlying empirical model to extrapolate based on nearest point.

Note

This is only applicable to Empirical1D model and should still work even if the source spectrum has been redshifted.

Returns:
is_forced : bool

True if the model is successfully forced to be extrapolated, else False.

integrate(wavelengths=None, **kwargs)[source]

Perform integration.

This uses any analytical integral that the underlying model has (i.e., self.model.integral). If unavailable, it uses the default fall-back integrator set in the default_integrator configuration item.

If wavelengths are provided, flux or throughput is first resampled. This is useful when user wants to integrate at specific end points or use custom spacing; In that case, user can pass in desired sampling array generated with numpy.linspace(), numpy.logspace(), etc. If not provided, then waveset is used.

Parameters:
wavelengths : array-like, Quantity, or None

Wavelength values for integration. If not a Quantity, assumed to be in Angstrom. If None, waveset is used.

kwargs : dict

Optional keywords to __call__ for sampling.

Returns:
result : Quantity

Integrated result.

Raises:
NotImplementedError

Invalid default integrator.

synphot.exceptions.SynphotError

waveset is needed but undefined or cannot integrate natively in the given flux_unit.

pivot(wavelengths=None)[source]

Calculate pivot wavelength.

Parameters:
wavelengths : array-like, Quantity, or None

Wavelength values for sampling. If not a Quantity, assumed to be in Angstrom. If None, waveset is used.

Returns:
pivwv : Quantity

Pivot wavelength.

plot(wavelengths=None, **kwargs)[source]

Plot the spectrum.

Note

Uses matplotlib.

Parameters:
wavelengths : array-like, Quantity, or None

Wavelength values for sampling. If not a Quantity, assumed to be in Angstrom. If None, waveset is used.

title : str

Plot title.

xlog, ylog : bool

Plot X and Y axes, respectively, in log scale. Default is linear scale.

left, right : None or number

Minimum and maximum wavelengths to plot. If None, uses the whole range. If a number is given, must be in Angstrom.

bottom, top : None or number

Minimum and maximum flux/throughput to plot. If None, uses the whole range. If a number is given, must be in internal unit.

save_as : str

Save the plot to an image file. The file type is automatically determined by given file extension.

Raises:
synphot.exceptions.SynphotError

Invalid inputs.

taper(wavelengths=None)[source]

Taper the spectrum or bandpass.

The wavelengths to use for the first and last points are calculated by using the same ratio as for the 2 interior points.

Parameters:
wavelengths : array-like, Quantity, or None

Wavelength values for tapering. If not a Quantity, assumed to be in Angstrom. If None, waveset is used.

Returns:
sp : BaseSpectrum

Tapered empirical spectrum or bandpass. self is returned if already tapered (e.g., box model).