The SKIRT project
advanced radiative transfer for astrophysics
Functions
pts.simulation.units Namespace Reference

Handling SKIRT units. More...

Functions

def _flavor (flavorunit)
 This helper function returns a numeric code corresponding to the specified flavor or unit: More...
 
def convertToFlavor (wavelength, flux, flavor)
 This function accepts a flux density, surface brightness, spectral radiance, or spectral luminosity (generically called "flux" for the purposes of this function), converts this flux from an arbitrary unit in any "flavor" (neutral, per wavelength, per frequency, or per energy) to an equivalent unit in the specified flavor, and returns the result. More...
 
def hasReverseWavelengthOrder (unitlike)
 This function returns True if the units represented by the "unit-like" input are those for frequency ( \(\nu\)) or energy ( \(E\)), and False if not (including for wavelength ( \(\lambda\)). More...
 
def latexForSpectralFlux (unitlike)
 This function returns a latex-formatted string representation for a flux density ( \(\lambda F_\lambda\), \(F_\lambda\), \(F_\nu\), or \(F_E\)) or a surface brightness ( \(\lambda f_\lambda\), \(f_\lambda\), \(f_\nu\), or \(f_E\)) that has the units represented by the "unit-like" input (the latex string does not include the unit itself). More...
 
def latexForSpectralFluxWithUnit (unitlike)
 This function returns the result of latexForSpectralFlux() + latexForUnit() with the same argument. More...
 
def latexForSpectralLuminosity (unitlike)
 This function returns a latex-formatted string representation for the spectral luminosity ( \(\lambda L_\lambda\), \(L_\lambda\), \(L_\nu\), or \(L_E\)) that has the units represented by the "unit-like" input (the latex string does not include the unit itself). More...
 
def latexForSpectralLuminosityWithUnit (unitlike)
 This function returns the result of latexForSpectralLuminosity() + latexForUnit() with the same argument. More...
 
def latexForSpectralRadiance (unitlike)
 This function returns a latex-formatted string representation for the mean intensity or spectral radiance ( \(\lambda J_\lambda\), \(J_\lambda\), \(J_\nu\), or \(J_E\)) that has the units represented by the "unit-like" input (the latex string does not include the unit itself). More...
 
def latexForSpectralRadianceWithUnit (unitlike)
 This function returns the result of latexForSpectralRadiance() + latexForUnit() with the same argument. More...
 
def latexForUnit (unitlike)
 This function returns a latex-formatted string representation for the "unit-like" input, enclosed in square brackets and preceded by a short space. More...
 
def latexForWavelength (unitlike)
 This function returns a latex-formatted string representation for wavelength ( \(\lambda\)), frequency ( \(\nu\)), or energy ( \(E\)), depending on the units represented by the "unit-like" input (the latex string does not include the unit itself). More...
 
def latexForWavelengthWithUnit (unitlike)
 This function returns the result of latexForWavelength() + latexForUnit() with the same argument. More...
 
def unit (unitlike)
 This function returns an astropy unit for any of the following "unit-like" inputs: More...
 

Detailed Description

Handling SKIRT units.

This module offers functions for converting SKIRT units to astropy units, and for handling conversions that may not be trivial to perform using pure astropy.

Function Documentation

◆ _flavor()

def pts.simulation.units._flavor (   flavorunit)
private

This helper function returns a numeric code corresponding to the specified flavor or unit:

  • 1 for the string "neutral" and for units that have a neutral flavor.
  • 2 for the string "wavelength" and for units that have a per wavelength flavor.
  • 3 for the string "frequency" and for units that have a per frequency flavor.
  • 4 for the string "energy" and for units that have a per energy flavor.

◆ convertToFlavor()

def pts.simulation.units.convertToFlavor (   wavelength,
  flux,
  flavor 
)

This function accepts a flux density, surface brightness, spectral radiance, or spectral luminosity (generically called "flux" for the purposes of this function), converts this flux from an arbitrary unit in any "flavor" (neutral, per wavelength, per frequency, or per energy) to an equivalent unit in the specified flavor, and returns the result.

Both the wavelength and the flux must be astropy quantities in one of the following shape combinations:

  • The wavelength is a scalar: this wavelength is used to convert all values in the flux argument, which can be a scalar or an array of arbitrary shape (e.g. a 2D data frame) containing flux values at the same wavelength.
  • The wavelength is a 1D array: the length of this array must match the last (or only) axis of the flux argument which can be, for example an 1D spectrum or a 3D data cube. The wavelengths are broad-casted to the other axes.

The target flavor can be specified in one of two ways:

  • As one of the strings "neutral", "wavelength", "frequency", or "energy": the result will have the unit that follows from the conversion calculation and thus depends on the incoming units of both flux and wavelength. This option is useful in case the incoming flux type (density, brightness, luminosity) is not known a priori.
  • As an astropy unit instance (such as the return value of the sm.unit() function): the flavor is derived from this unit, and the result is explicitly converted to it before being returned. The unit must be compatible with the incoming flux type (density, brightness, luminosity), after flavor conversion.

◆ hasReverseWavelengthOrder()

def pts.simulation.units.hasReverseWavelengthOrder (   unitlike)

This function returns True if the units represented by the "unit-like" input are those for frequency ( \(\nu\)) or energy ( \(E\)), and False if not (including for wavelength ( \(\lambda\)).

The input argument is interpreted as described for the unit() function in this module.

◆ latexForSpectralFlux()

def pts.simulation.units.latexForSpectralFlux (   unitlike)

This function returns a latex-formatted string representation for a flux density ( \(\lambda F_\lambda\), \(F_\lambda\), \(F_\nu\), or \(F_E\)) or a surface brightness ( \(\lambda f_\lambda\), \(f_\lambda\), \(f_\nu\), or \(f_E\)) that has the units represented by the "unit-like" input (the latex string does not include the unit itself).

The input argument is interpreted as described for the unit() function in this module. If no match is found, the function returns an empty string.

◆ latexForSpectralFluxWithUnit()

def pts.simulation.units.latexForSpectralFluxWithUnit (   unitlike)

This function returns the result of latexForSpectralFlux() + latexForUnit() with the same argument.

◆ latexForSpectralLuminosity()

def pts.simulation.units.latexForSpectralLuminosity (   unitlike)

This function returns a latex-formatted string representation for the spectral luminosity ( \(\lambda L_\lambda\), \(L_\lambda\), \(L_\nu\), or \(L_E\)) that has the units represented by the "unit-like" input (the latex string does not include the unit itself).

The input argument is interpreted as described for the unit() function in this module. If no match is found, the function returns an empty string.

◆ latexForSpectralLuminosityWithUnit()

def pts.simulation.units.latexForSpectralLuminosityWithUnit (   unitlike)

This function returns the result of latexForSpectralLuminosity() + latexForUnit() with the same argument.

◆ latexForSpectralRadiance()

def pts.simulation.units.latexForSpectralRadiance (   unitlike)

This function returns a latex-formatted string representation for the mean intensity or spectral radiance ( \(\lambda J_\lambda\), \(J_\lambda\), \(J_\nu\), or \(J_E\)) that has the units represented by the "unit-like" input (the latex string does not include the unit itself).

The input argument is interpreted as described for the unit() function in this module. If no match is found, the function returns an empty string.

◆ latexForSpectralRadianceWithUnit()

def pts.simulation.units.latexForSpectralRadianceWithUnit (   unitlike)

This function returns the result of latexForSpectralRadiance() + latexForUnit() with the same argument.

◆ latexForUnit()

def pts.simulation.units.latexForUnit (   unitlike)

This function returns a latex-formatted string representation for the "unit-like" input, enclosed in square brackets and preceded by a short space.

The input argument is interpreted as described for the unit() function in this module.

◆ latexForWavelength()

def pts.simulation.units.latexForWavelength (   unitlike)

This function returns a latex-formatted string representation for wavelength ( \(\lambda\)), frequency ( \(\nu\)), or energy ( \(E\)), depending on the units represented by the "unit-like" input (the latex string does not include the unit itself).

The input argument is interpreted as described for the unit() function in this module. If no match is found, the function returns an empty string.

◆ latexForWavelengthWithUnit()

def pts.simulation.units.latexForWavelengthWithUnit (   unitlike)

This function returns the result of latexForWavelength() + latexForUnit() with the same argument.

◆ unit()

def pts.simulation.units.unit (   unitlike)

This function returns an astropy unit for any of the following "unit-like" inputs:

  • a string representing a valid SKIRT unit: returns the corresponding astropy unit.
  • a string representing a valid astropy unit in generic format: returns the corresponding astropy unit.
  • an astropy quantity: returns the unit of the quantity.
  • an astropy unit: simply returns the unit itself.

While the function is mainly intended for converting SKIRT units to astropy units, supporting the other input types is useful when the function is invoked directly or indirectly from some other context.