Spectral Energy Distributions
- class galsim.SED(spec, wave_type, flux_type, redshift=0.0, fast=True, interpolant='linear', _blue_limit=0.0, _red_limit=inf, _wave_list=None)[source]
Object to represent the spectral energy distributions of stars and galaxies.
SEDs are callable, usually returning the flux density in photons/nm/cm^2/s as a function of wavelength, though SEDs are also used by GalSim to track dimensionless wavelength-dependent normalizations, and may thus also return dimensionless values. By default, the above wavelength used by __call__ is nanometers, but it’s possible to use other units via the astropy.units module (at least, if the SED keyword argument
fast=False
, see below). For instance,:>>> sed = galsim.SED(...) >>> from astropy import units as u >>> assert sed(500) == sed(5000 * u.AA) # 500 nm == 5000 Angstroms
The python type of the return value depends on the type of the input wavelength(s). A scalar input wavelength yields a scalar flux density, a tuple yields a tuple, a list yields a list, and a numpy.ndarray yields a numpy.ndarray. A scalar astropy.units.Quantity yields a python scalar, and a vector astropy.units.Quantity yields a numpy.ndarray.
SEDs are immutable; all transformative SED methods return new SEDs, and leave their originating SEDs unaltered.
SEDs have
blue_limit
andred_limit
attributes, which indicate the range over which the SED is defined. An exception will be raised if the flux density or normalization is requested outside of this range. Note thatblue_limit
andred_limit
are always in nanometers and in the observed frame whenredshift != 0
.SEDs may be multiplied by scalars or scalar functions of wavelength. In particular, an SED multiplied by a
Bandpass
will yield the appropriately filtered SED. Two SEDs may be multiplied together if at least one of them represents a dimensionless normalization.SEDs may be added together if they are at the same redshift. The resulting SED will only be defined on the wavelength region where both of the operand SEDs are defined.
blue_limit
andred_limit
will be reset accordingly.The input parameter,
spec
, may be one of several possible forms:a regular python function (or an object that acts like a function)
a file from which a
LookupTable
can be read ina string which can be evaluated to a function of
wave
viaeval('lambda wave:'+spec)
, e.g.:spec = '0.8 + 0.2 * (wave-800)'
a python scalar (only possible for dimensionless SEDs)
The argument of
spec
should be the wavelength in units specified bywave_type
, which should be an instance ofastropy.units.Unit
of equivalency classastropy.units.spectral
, or one of the case-insensitive aliases ‘nm’, ‘nanometer’, ‘nanometers’, ‘A’, ‘Ang’, ‘Angstrom’, or ‘Angstroms’. Note thatastropy.units.spectral
includes not only units with dimensions of length, but also frequency, energy, or wavenumber.The return value of
spec
should be a spectral density with units specified byflux_type
, which should be an instance ofastropy.units.Unit
of equivalency classastropy.units.spectral_density
, or one of the case-insensitive aliases:‘flambda’: erg/wave_type/cm^2/s, where wave_type is as above.
‘fnu’: erg/Hz/cm^2/s
‘fphotons’: photons/wave_type/cm^2/s, where wave_type is as above.
‘1’: dimensionless
Note that the
astropy.units.spectral_density
class includes units with dimensions of [energy/time/area/unit-wavelength], [energy/time/area/unit-frequency], [photons/time/area/unit-wavelength], and so on.Finally, the optional
fast
keyword option is used to specify when unit and dimension changes are executed, particularly for SEDs specified by aLookupTable
. Iffast=True
, the default, then the input units/dimensions may be converted to an internal working unit before interpolation in wavelength is performed. Alternatively,fast=False
implies that interpolation should take place in the native units of the inputspec
, and subsequently flux density converted to photons/cm^2/s/nm afterwards. Generally, the former option is faster, but may be less accurate since interpolation and dimensionality conversion do not commute. One consequence of usingfast=True
is that __call__ can not accept anastropy.units.Quantity
in this case.- Parameters:
spec – Function defining the z=0 spectrum at each wavelength. See above for valid options for this parameter.
wave_type – String or astropy.unit specifying units for wavelength input to
spec
.flux_type – String or astropy.unit specifying what type of spectral density or dimensionless normalization
spec
represents. See above for valid options for this parameter.redshift – Optionally shift the spectrum to the given redshift. [default: 0]
fast – Convert units on initialization instead of on __call__. [default: True]
interpolant – If reading from a file, what interpolant to use. [default: ‘linear’]
- __call__(wave)[source]
Return photon flux density or dimensionless normalization at wavelength
wave
.Note that outside of the wavelength range defined by the
blue_limit
andred_limit
attributes, the SED is considered undefined, and this method will raise an exception if a wavelength outside the defined range is passed as an argument.- Parameters:
wave – Wavelength in nanometers at which to evaluate the SED. May be a scalar, a numpy.array, or an astropy.units.Quantity
- Returns:
photon flux density in units of photons/nm/cm^2/s if self.spectral, or dimensionless normalization if self.dimensionless.
- __mul__(other)[source]
Multiply the SED by something.
There are several possibilities:
SED * SED -> SED (at least one must be dimensionless)
SED * GSObject -> ChromaticObject
SED * Bandpass -> SED (treating throughput similarly to dimensionless SED)
SED * callable function -> SED (treating function as dimensionless SED)
SED * scalar -> SED
- calculateDCRMomentShifts(bandpass, **kwargs)[source]
Calculates shifts in first and second moments of PSF due to differential chromatic refraction (DCR).
I.e., equations (1) and (2) from Plazas and Bernstein (2012):
http://arxiv.org/abs/1204.1346).
- Parameters:
bandpass –
Bandpass
through which object is being imaged.zenith_angle –
Angle
from object to zenithparallactic_angle – Parallactic angle, i.e. the position angle of the zenith, measured from North through East. [default: 0]
obj_coord – Celestial coordinates of the object being drawn as a
CelestialCoord
. [default: None]zenith_coord – Celestial coordinates of the zenith as a
CelestialCoord
. [default: None]HA – Hour angle of the object as an
Angle
. [default: None]latitude – Latitude of the observer as an
Angle
. [default: None]pressure – Air pressure in kiloPascals. [default: 69.328 kPa]
temperature – Temperature in Kelvins. [default: 293.15 K]
H2O_pressure – Water vapor pressure in kiloPascals. [default: 1.067 kPa]
- Returns:
The first element is the vector of DCR first moment shifts
The second element is the 2x2 matrix of DCR second (central) moment shifts.
- Return type:
a tuple
- calculateFlux(bandpass)[source]
Return the flux (photons/cm^2/s) of the
SED
through theBandpass
bandpass.
- calculateMagnitude(bandpass)[source]
Return the
SED
magnitude through aBandpass
bandpass
.Note that this requires
bandpass
to have been assigned a zeropoint usingBandpass.withZeropoint
.
- calculateSeeingMomentRatio(bandpass, alpha=-0.2, base_wavelength=500)[source]
Calculates the relative size of a PSF compared to the monochromatic PSF size at wavelength
base_wavelength
.- Parameters:
bandpass –
Bandpass
through which object is being imaged.alpha – Power law index for wavelength-dependent seeing. [default: -0.2, the prediction for Kolmogorov turbulence]
base_wavelength – Reference wavelength in nm from which to compute the relative PSF size. [default: 500]
- Returns:
the ratio of the PSF second moments to the second moments of the reference PSF.
- check_spectral()[source]
Return boolean indicating if SED has units compatible with a spectral density.
- property dimensionless
Whether the object is dimensionless (rather than spectral).
- sampleWavelength(nphotons, bandpass, rng=None, npoints=None)[source]
Sample a number of random wavelength values from the
SED
, possibly as observed through aBandpass
bandpass.- Parameters:
nphotons – Number of samples (photons) to randomly draw.
bandpass – A
Bandpass
object representing a filter, or None to sample over the fullSED
wavelength range.rng – If provided, a random number generator that is any kind of
BaseDeviate
object. Ifrng
is None, one will be automatically created from the system. [default: None]npoints – Number of points
DistDeviate
should use for its internal interpolation tables. [default: None, which uses theDistDeviate
default]
- thin(rel_err=0.0001, trim_zeros=True, preserve_range=True, fast_search=True)[source]
Remove some tabulated values while keeping the integral over the set of tabulated values still accurate to
rel_err
.This is only relevant if the
SED
was initialized with aLookupTable
or from a file (which internally creates aLookupTable
).- Parameters:
rel_err – The relative error allowed in the integral over the
SED
[default: 1.e-4]trim_zeros – Remove redundant leading and trailing points where f=0? (The last leading point with f=0 and the first trailing point with f=0 will be retained). Note that if both trim_leading_zeros and preserve_range are True, then the only the range of
x
after zero trimming is preserved. [default: True]preserve_range – Should the original range (
blue_limit
andred_limit
) of theSED
be preserved? (True) Or should the ends be trimmed to include only the region where the integral is significant? (False) [default: True]fast_search – If set to True, then the underlying algorithm will use a relatively fast O(N) algorithm to select points to include in the thinned approximation. If set to False, then a slower O(N^2) algorithm will be used. We have found that the slower algorithm tends to yield a thinned representation that retains fewer samples while still meeting the relative error requirement. [default: True]
- Returns:
the thinned
SED
.
- withFlux(target_flux, bandpass)[source]
Return a new
SED
with flux through theBandpass
bandpass
set totarget_flux
.See
ChromaticObject
docstring for information about howSED
normalization affectsChromaticObject
normalization.
- withFluxDensity(target_flux_density, wavelength)[source]
Return a new
SED
with flux density set totarget_flux_density
at wavelengthwavelength
.See
ChromaticObject
docstring for information about howSED
normalization affectsChromaticObject
normalization.- Parameters:
target_flux_density – The target normalization in photons/nm/cm^2/s.
wavelength – The wavelength, in nm, at which the flux density will be set.
- Returns:
the new normalized SED.
- withMagnitude(target_magnitude, bandpass)[source]
Return a new
SED
with magnitude through theBandpass
bandpass
set totarget_magnitude
.Note that this requires
bandpass
to have been assigned a zeropoint usingBandpass.withZeropoint
. SeeChromaticObject
docstring for information about howSED
normalization affectsChromaticObject
normalization.
- class galsim.EmissionLine(wavelength, fwhm=1.0, flux=1.0, wave_type='nm', flux_type='fphotons', max_wave=1e+30, **kwargs)[source]
- atRedshift(redshift)[source]
Return a new
EmissionLine
with redshifted wavelengths.- Parameters:
redshift – The redshift for the returned
EmissionLine
- Returns:
the redshifted
EmissionLine
.