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:
- modelclasscls
Model class from
astropy.modeling
.- clean_metabool
Scrub “expr” and “header” entries from input metadata before merging. Set this to
True
when those entries no longer make sense inself
. This is automatically set toTrue
regardless for spectrum arithmetic.- kwargsdict
Model parameters accepted by
modelclass
. Each parameter can be either a Quantity or number. If the latter, assume pre-defined internal units.
- Attributes:
- metadict
Metadata associated with the spectrum or bandpass model (warnings, legacy SYNPHOT expression, FITS header, etc).
- Raises:
- synphot.exceptions.SynphotError
Invalid model.
Attributes Summary
Model of the spectrum/bandpass.
Dictionary of warning key-value pairs related to spectrum/bandpass.
Range of
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 the underlying model to extrapolate.
from_spectrum1d
(spec[, keep_neg])Create a spectrum from
specutils.Spectrum1D
object.integrate
([wavelengths, integration_type])Perform integration.
pivot
([wavelengths])Calculate pivot wavelength.
plot
([wavelengths])Plot the spectrum.
taper
([wavelengths])Taper the spectrum or bandpass.
to_spectrum1d
([wavelengths])Create a
specutils.Spectrum1D
object from spectrum.Attributes Documentation
- model¶
Model of the spectrum/bandpass.
- warnings¶
Dictionary of warning key-value pairs related to spectrum/bandpass.
- waveset¶
Optimal wavelengths for sampling the spectrum or bandpass.
Methods Documentation
- avgwave(wavelengths=None)[source]¶
Calculate the average wavelength.
- barlam(wavelengths=None)[source]¶
Calculate 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.
- classmethod from_spectrum1d(spec, keep_neg=False)[source]¶
Create a spectrum from
specutils.Spectrum1D
object.- Parameters:
- spec
specutils.Spectrum1D
- keep_negbool
See
Empirical1D
.
- spec
- Returns:
- sp
BaseSourceSpectrum
Empirical spectrum.
- sp
- integrate(wavelengths=None, integration_type=None, **kwargs)[source]¶
Perform integration.
When integration is not analytical and 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, thenwaveset
is used.When integration is analytical, wavelengths provided are only used if applicable for the particular model. If the model does not support analytical integration, it will fall back to simple trapezoid integration.
- Parameters:
- wavelengthsarray-like,
Quantity
, orNone
Wavelength values for integration. This is ignored by analytical integration if not applicable. If not a Quantity, assumed to be in Angstrom. If
None
,waveset
is used.- integration_type{None, ‘trapezoid’, ‘analytical’}
Defines how the integration is done, either by simple trapezoid integration or analytical formula. If
None
, the option is pulled fromsynphot.config.conf.default_integrator
. If analytical integration is requested but no possible, trapezoid integration is done anyway.- flux_unitstr,
Unit
, orNone
This option is only available for source spectrum. For trapezoid integration, flux is converted to this unit for sampling before integration. For analytical integration, while calculation is done differently, providing this option would result in equivalent behavior as trapezoid integration, where possible, for consistency. If not given, internal unit is used.
- kwargsdict
This option is only available for source spectrum. Other optional keywords besides
flux_unit
to__call__
for sampling when integration type is not analytical.
- wavelengthsarray-like,
- Returns:
- result
Quantity
Integrated result.
- result
- Raises:
- NotImplementedError
Invalid integration type.
- synphot.exceptions.SynphotError
waveset
is needed but undefined or cannot integrate natively in the givenflux_unit
.
- pivot(wavelengths=None)[source]¶
Calculate pivot wavelength.
- plot(wavelengths=None, **kwargs)[source]¶
Plot the spectrum.
Note
Uses
matplotlib
.- Parameters:
- wavelengthsarray-like,
Quantity
, orNone
Wavelength values for sampling. If not a Quantity, assumed to be in Angstrom. If
None
,waveset
is used.- titlestr
Plot title.
- xlog, ylogbool
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_asstr
Save the plot to an image file. The file type is automatically determined by given file extension.
- wavelengthsarray-like,
- 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:
- Returns:
- sp
BaseSpectrum
Tapered empirical spectrum or bandpass.
self
is returned if already tapered (e.g., box model).
- sp
- to_spectrum1d(wavelengths=None, **kwargs)[source]¶
Create a
specutils.Spectrum1D
object from spectrum.- Parameters:
- wavelengthsarray-like,
Quantity
, orNone
Wavelength values for sampling. If not a Quantity, assumed to be in Angstrom. If
None
,self.waveset
is used.- flux_unitstr,
Unit
, orNone
This option is not applicable to unitless spectrum like bandpass. Flux is converted to this unit before written out. If not given, internal unit is used. Count and magnitudes are not supported.
- wavelengthsarray-like,
- Returns:
- Raises:
- ImportError
specutils
is not installed.