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 and red_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 that blue_limit and red_limit are always in nanometers and in the observed frame when redshift != 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 and red_limit will be reset accordingly.

The input parameter, spec, may be one of several possible forms:

  1. a regular python function (or an object that acts like a function)

  2. a LookupTable

  3. a file from which a LookupTable can be read in

  4. a string which can be evaluated to a function of wave via eval('lambda wave:'+spec), e.g.:

    spec = '0.8 + 0.2 * (wave-800)'
    
  5. a python scalar (only possible for dimensionless SEDs)

The argument of spec should be the wavelength in units specified by wave_type, which should be an instance of astropy.units.Unit of equivalency class astropy.units.spectral, or one of the case-insensitive aliases ‘nm’, ‘nanometer’, ‘nanometers’, ‘A’, ‘Ang’, ‘Angstrom’, or ‘Angstroms’. Note that astropy.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 by flux_type, which should be an instance of astropy.units.Unit of equivalency class astropy.units.spectral_density, or one of the case-insensitive aliases:

  1. ‘flambda’: erg/wave_type/cm^2/s, where wave_type is as above.

  2. ‘fnu’: erg/Hz/cm^2/s

  3. ‘fphotons’: photons/wave_type/cm^2/s, where wave_type is as above.

  4. ‘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 a LookupTable. If fast=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 input spec, 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 using fast=True is that __call__ can not accept an astropy.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 and red_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:

  1. SED * SED -> SED (at least one must be dimensionless)

  2. SED * GSObject -> ChromaticObject

  3. SED * Bandpass -> SED (treating throughput similarly to dimensionless SED)

  4. SED * callable function -> SED (treating function as dimensionless SED)

  5. SED * scalar -> SED

_mul_sed(other)[source]

Equivalent to self * other when other is an SED, but no sanity checks.

_mul_bandpass(other)[source]

Equivalent to self * other when other is a Bandpass

_mul_scalar(other, spectral)[source]

Equivalent to self * other when other is a scalar

atRedshift(redshift)[source]

Return a new SED with redshifted wavelengths.

Parameters:

redshift – The redshift for the returned SED

Returns:

the redshifted 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:
  • bandpassBandpass through which object is being imaged.

  • zenith_angleAngle from object to zenith

  • parallactic_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 the Bandpass bandpass.

Parameters:

bandpass – A Bandpass object representing a filter, or None to compute the bolometric flux. For the bolometric flux the integration limits will be set to (0, infinity), which implies that the SED needs to be evaluable over this entire range.

Returns:

the flux through the bandpass.

calculateMagnitude(bandpass)[source]

Return the SED magnitude through a Bandpass bandpass.

Note that this requires bandpass to have been assigned a zeropoint using Bandpass.withZeropoint.

Parameters:

bandpass – A Bandpass object representing a filter, or None to compute the bolometric magnitude. For the bolometric magnitude the integration limits will be set to (0, infinity), which implies that the SED needs to be evaluable over this entire range.

Returns:

the bandpass magnitude.

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:
  • bandpassBandpass 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_dimensionless()[source]

Return boolean indicating if SED is dimensionless.

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 a Bandpass bandpass.

Parameters:
  • nphotons – Number of samples (photons) to randomly draw.

  • bandpass – A Bandpass object representing a filter, or None to sample over the full SED wavelength range.

  • rng – If provided, a random number generator that is any kind of BaseDeviate object. If rng 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 the DistDeviate 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 a LookupTable or from a file (which internally creates a LookupTable).

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 and red_limit) of the SED 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 the Bandpass bandpass set to target_flux.

See ChromaticObject docstring for information about how SED normalization affects ChromaticObject normalization.

Parameters:
  • target_flux – The desired flux normalization of the SED.

  • bandpass – A Bandpass object defining a filter bandpass.

Returns:

the new normalized SED.

withFluxDensity(target_flux_density, wavelength)[source]

Return a new SED with flux density set to target_flux_density at wavelength wavelength.

See ChromaticObject docstring for information about how SED normalization affects ChromaticObject 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 the Bandpass bandpass set to target_magnitude.

Note that this requires bandpass to have been assigned a zeropoint using Bandpass.withZeropoint. See ChromaticObject docstring for information about how SED normalization affects ChromaticObject normalization.

Parameters:
  • target_magnitude – The desired magnitude of the SED.

  • bandpass – A Bandpass object defining a filter bandpass.

Returns:

the new normalized SED.

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.