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 inself
. This is automatically set toTrue
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.
-
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.
- wavelengths : array-like or
-
avgwave
(wavelengths=None)[source]¶ Calculate the average wavelength.
Parameters: Returns: - avg_wave :
Quantity
Average wavelength.
- avg_wave :
-
barlam
(wavelengths=None)[source]¶ Calculate mean log wavelength.
Parameters: Returns: - bar_lam :
Quantity
Mean log wavelength.
- bar_lam :
-
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:
-
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 thedefault_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, thenwaveset
is used.Parameters: Returns: - result :
Quantity
Integrated result.
Raises: - NotImplementedError
Invalid default integrator.
- synphot.exceptions.SynphotError
waveset
is needed but undefined or cannot integrate natively in the givenflux_unit
.
- result :
-
pivot
(wavelengths=None)[source]¶ Calculate pivot wavelength.
Parameters: Returns: - pivwv :
Quantity
Pivot wavelength.
- pivwv :
-
plot
(wavelengths=None, **kwargs)[source]¶ Plot the spectrum.
Note
Uses
matplotlib
.Parameters: - wavelengths : array-like,
Quantity
, orNone
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.
- wavelengths : array-like,
-
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 :