Documentation ¶
Overview ¶
Package cosmo implements basic cosmology calculations in Go.
FLRW is the basic interface type that defines the key cosmological functions common to all supported cosmologies.
The Friedmann-Lemaître-Robertson-Walker (FLRW) metric is the general form that all homogenous, isotropic, connected cosmologies follow.
https://en.wikipedia.org/wiki/Friedmann-Lema%C3%AEtre-Robertson-Walker_metric
Provides:
FlatLCDM (H0, OM); OL = 1-OM, OK=0 LambdaCDM (H0, OM, OL, OK); w = -1 WCDM (H0, OM, OL, W); w = w0 WACDM (H0, OM, OL, W0, WA); w = w0 + w_a * (1-a)
Equations and numerical formulae based on
Hogg, https://arxiv.org/abs/astro-ph/9905116 Feige, 1992, Astron. Nachr., 313, 139. Eisenstein, 1997, https://arXiv.org/abs/astro-ph/9709054v2 Mészáros & Řípai 2013, A&A, 556, A13. Baes, Camps, Van De Putte, 2017, MNRAS, 468, 927. Kantowski, 2000, https://arxiv.org/abs/astro-ph/0002334 Thomas and Kantowski, 2000, PRD, 62, 103507. Eq. 3
Organizational thoughts based on code in astropy.cosmology
http://docs.astropy.org/en/stable/_modules/astropy/cosmology
Performance Notes:
1. Calculating a single line-of-sight comoving distance takes from 890ns - 260µs, depending on the complexity of the cosmology. Analytic cases take ~1µs, while explicit integration is ~200µs.
FlatLCDM 892ns (analytic for OM<1) LambdaCDM 139µs WCDM 250µs WACDM 261µs
These numbers are based on the output of `go test -bench ComovingDistance` run on a 2015 MacBook Air: dual-core 2.2 GHz Intel Core i7, 8 GB 1600 MHz DDR3; with Mac OS X 10.13.2 and go 1.9.2
2. The current types FlatLCDM, LambdaCDM, WCDM, WACDM implement their methods as value receivers. There's a mild performance hit for using value receivers instead of pointer receivers. This performance penalty is 40% for individual calls to E or Einv but this penalty is only 1-2% for calls to the general *Distance methods.
For now the use case model seems more amenable to value receivers -- conceptually, the cosmologies should be immutable -- and the performance penalty is acceptable.
Index ¶
- Constants
- type FLRW
- type FlatLCDM
- func (cos FlatLCDM) Age(z float64) (timeGyr float64)
- func (cos FlatLCDM) AngularDiameterDistance(z float64) (distanceMpcRad float64)
- func (cos FlatLCDM) ComovingDistance(z float64) (distanceMpc float64)
- func (cos FlatLCDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)
- func (cos FlatLCDM) ComovingTransverseDistance(z float64) (distanceMpcRad float64)
- func (cos FlatLCDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)
- func (cos FlatLCDM) DistanceModulus(z float64) (distanceModulusMag float64)
- func (cos FlatLCDM) E(z float64) (fractionalHubbleParameter float64)
- func (cos FlatLCDM) Einv(z float64) (invFractionalHubbleParameter float64)
- func (cos FlatLCDM) HubbleDistance() (distanceMpc float64)
- func (cos FlatLCDM) LookbackTime(z float64) (timeGyr float64)
- func (cos FlatLCDM) LuminosityDistance(z float64) (distanceMpc float64)
- func (cos FlatLCDM) Ok0() (curvatureDensity float64)
- func (cos FlatLCDM) String() string
- type LambdaCDM
- func (cos LambdaCDM) Age(z float64) (timeGyr float64)
- func (cos LambdaCDM) AngularDiameterDistance(z float64) (distanceMpcRad float64)
- func (cos LambdaCDM) ComovingDistance(z float64) (distanceMpc float64)
- func (cos LambdaCDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)
- func (cos LambdaCDM) ComovingTransverseDistance(z float64) (distanceMpcRad float64)
- func (cos LambdaCDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)
- func (cos LambdaCDM) DistanceModulus(z float64) (distanceModulusMag float64)
- func (cos LambdaCDM) E(z float64) (fractionalHubbleParameter float64)
- func (cos LambdaCDM) Einv(z float64) (invFractionalHubbleParameter float64)
- func (cos LambdaCDM) HubbleDistance() (distanceMpc float64)
- func (cos LambdaCDM) LookbackTime(z float64) (timeGyr float64)
- func (cos LambdaCDM) LuminosityDistance(z float64) (distanceMpc float64)
- func (cos LambdaCDM) Ok0() (curvatureDensity float64)
- func (cos LambdaCDM) String() string
- type WACDM
- func (cos WACDM) Age(z float64) (timeGyr float64)
- func (cos WACDM) AngularDiameterDistance(z float64) (distanceMpcRad float64)
- func (cos WACDM) ComovingDistance(z float64) (distanceMpc float64)
- func (cos WACDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)
- func (cos WACDM) ComovingTransverseDistance(z float64) (distanceMpcRad float64)
- func (cos WACDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)
- func (cos WACDM) DistanceModulus(z float64) (distanceModulusMag float64)
- func (cos WACDM) E(z float64) (fractionalHubbleParameter float64)
- func (cos WACDM) Einv(z float64) (invFractionalHubbleParameter float64)
- func (cos WACDM) HubbleDistance() float64
- func (cos WACDM) LookbackTime(z float64) (timeGyr float64)
- func (cos WACDM) LuminosityDistance(z float64) (distanceMpc float64)
- func (cos WACDM) Ok0() (curvatureDensity float64)
- func (cos WACDM) String() string
- type WCDM
- func (cos WCDM) Age(z float64) (timeGyr float64)
- func (cos WCDM) AngularDiameterDistance(z float64) (distanceMpcRad float64)
- func (cos WCDM) ComovingDistance(z float64) (distanceMpc float64)
- func (cos WCDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)
- func (cos WCDM) ComovingTransverseDistance(z float64) (distanceMpcRad float64)
- func (cos WCDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)
- func (cos WCDM) DistanceModulus(z float64) (distanceModulusMag float64)
- func (cos WCDM) E(z float64) (fractionalHubbleParameter float64)
- func (cos WCDM) Einv(z float64) (invFractionalHubbleParameter float64)
- func (cos WCDM) HubbleDistance() float64
- func (cos WCDM) LookbackTime(z float64) (timeGyr float64)
- func (cos WCDM) LuminosityDistance(z float64) (distanceMpc float64)
- func (cos WCDM) Ok0() (curvatureDensity float64)
- func (cos WCDM) String() string
Examples ¶
Constants ¶
const SpeedOfLightKmS = 299792.458 // km/s
SpeedOfLightKmS is speed of light in kilometers/second Useful in calculating Hubble distance (c/H0), which is the basic prefactor for any distance measure.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FLRW ¶
type FLRW interface { Age(z float64) (timeGyr float64) AngularDiameterDistance(z float64) (distanceMpc float64) ComovingDistance(z float64) (distanceMpc float64) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64) ComovingTransverseDistance(z float64) (distanceMpc float64) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpc float64) DistanceModulus(z float64) (distanceModulusMag float64) E(z float64) (fractionalHubbleParameter float64) Einv(z float64) (invFractionalHubbleParameter float64) HubbleDistance() (distanceMpc float64) LookbackTime(z float64) (timeGyr float64) LuminosityDistance(z float64) (distanceMpc float64) Ok0() (curvatureDensity float64) }
FLRW specifies the cosmological calculations to be available from Friedmann-Lemaître-Robertson-Walker metrics.
type FlatLCDM ¶
type FlatLCDM struct { H0 float64 // Hubble constant at z=0. [km/s/Mpc] Om0 float64 // Matter Density at z=0 W0 float64 // Dark energy equation-of-state parameter Ogamma0 float64 // Photon density Onu0 float64 // Neutrino density }
FlatLCDM provides cosmological distances, age, and look-back time for a flat Universe with a cosmological constant: matter, dark energy, and no curvature, with a w=-1 equation-of-state parameter for dark energy
Example ¶
cos := FlatLCDM{H0: 70, Om0: 0.3} zVec := []float64{0.5, 1.0, 2.0, 3.0} distmodVec := make([]float64, len(zVec)) lumdistVec := make([]float64, len(zVec)) angdistVec := make([]float64, len(zVec)) for i, z := range zVec { distmodVec[i] = cos.DistanceModulus(z) lumdistVec[i] = cos.LuminosityDistance(z) angdistVec[i] = cos.AngularDiameterDistance(z) } fmt.Println(cos) fmt.Println("Ok0: ", cos.Ok0()) fmt.Println("Distance Modulus [mag]") fmt.Println(distmodVec) fmt.Println("Luminosity Distance [Mpc]") fmt.Println(lumdistVec) fmt.Println("Angular Diameter Distance [Mpc]") fmt.Println(angdistVec)
Output: FlatLCDM{H0: 70, Om0: 0.3} Ok0: 0 Distance Modulus [mag] [42.26118542154089 44.10023765554372 45.95719725271018 47.026111928689645] Luminosity Distance [Mpc] [2832.938093900105 6607.65761177494 15539.58622322811 25422.74174518986] Angular Diameter Distance [Mpc] [1259.0835972889354 1651.914402943735 1726.6206914697902 1588.9213590743661]
func (FlatLCDM) AngularDiameterDistance ¶
AngularDiameterDistance is the ratio of physical transverse size to angular size
func (FlatLCDM) ComovingDistance ¶
ComovingDistance is the distance that is constant with the Hubble flow expressed in the physical distance at z=0.
As the scale factor a = 1/(1+z) increases from 0.5 to 1, two objects separated by a proper distance of 10 Mpc at a=0.5 (z=1) will be separated by a proper distance of 10*2 Mpc at a=1.0 (z=0) The comoving distance between these objects is 20 Mpc
func (FlatLCDM) ComovingDistanceZ1Z2 ¶
ComovingDistanceZ1Z2 is the base function for calculation of comoving distances
Here is where the choice of fundamental calculation method is made: Elliptic integral, quadrature integration, or analytic for special cases.
func (FlatLCDM) ComovingTransverseDistance ¶
ComovingTransverseDistance is the comoving distance at z as seen from z=0
func (FlatLCDM) ComovingTransverseDistanceZ1Z2 ¶
ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1
func (FlatLCDM) DistanceModulus ¶
DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.
func (FlatLCDM) E ¶
E is the Hubble parameter as a fraction of its present value. E.g., Hogg arXiv:9905116 Eq. 14
func (FlatLCDM) HubbleDistance ¶
HubbleDistance is the inverse of the Hubble parameter times the speed of light.
func (FlatLCDM) LookbackTime ¶
LookbackTime is the time from redshift 0 to z.
func (FlatLCDM) LuminosityDistance ¶
LuminosityDistance is the radius of effective sphere over which the light has spread out
type LambdaCDM ¶
type LambdaCDM struct { H0 float64 // Hubble constant at z=0. [km/s/Mpc] Om0 float64 // Matter Density at z=0 Ol0 float64 // Vacuum Energy density Lambda at z=0 Ogamma0 float64 // Photon density Onu0 float64 // Neutrino density }
LambdaCDM provides cosmological distances, age, and look-back time for a LCDM cosmology: matter, dark energy, and curvature, with a w=-1 equation-of-state parameter for dark energy
Example ¶
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.7} zVec := []float64{0.5, 1.0, 2.0, 3.0} distmodVec := make([]float64, len(zVec)) lumdistVec := make([]float64, len(zVec)) angdistVec := make([]float64, len(zVec)) for i, z := range zVec { distmodVec[i] = cos.DistanceModulus(z) lumdistVec[i] = cos.LuminosityDistance(z) angdistVec[i] = cos.AngularDiameterDistance(z) } fmt.Println(cos) fmt.Println("Ok0: ", cos.Ok0()) fmt.Println("Distance Modulus [mag]") fmt.Println(distmodVec) fmt.Println("Luminosity Distance [Mpc]") fmt.Println(lumdistVec) fmt.Println("Angular Diameter Distance [Mpc]") fmt.Println(angdistVec)
Output: LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.7} Ok0: 0 Distance Modulus [mag] [42.26118542154089 44.10023765554372 45.95719725271018 47.026111928689645] Luminosity Distance [Mpc] [2832.938093900105 6607.65761177494 15539.58622322811 25422.74174518986] Angular Diameter Distance [Mpc] [1259.0835972889354 1651.914402943735 1726.6206914697902 1588.9213590743661]
func (LambdaCDM) AngularDiameterDistance ¶
AngularDiameterDistance is the ratio of physical transverse size to angular size
func (LambdaCDM) ComovingDistance ¶
ComovingDistance is the distance that is constant with the Hubble flow expressed in the physical distance at z=0.
I.e., as the scale factor a = 1/(1+z) increases from 0.5 to 1, two objects separated by a proper distance of 10 Mpc at a=0.5 (z=1) will be separated by a proper distance of 2*10 Mpc at a=1.0 (z=0). The comoving distance between these objects is 20 Mpc.
func (LambdaCDM) ComovingDistanceZ1Z2 ¶
ComovingDistanceZ1Z2 is the base function for calculation of comoving distances Here is where the choice of fundamental calculation method is made: Fall back to simpler cosmology, or quadature integration
func (LambdaCDM) ComovingTransverseDistance ¶
ComovingTransverseDistance is the comoving distance at z as seen from z=0
func (LambdaCDM) ComovingTransverseDistanceZ1Z2 ¶
ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1
func (LambdaCDM) DistanceModulus ¶
DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.
func (LambdaCDM) E ¶
E is the Hubble parameter as a fraction of its present value. E.g., Hogg arXiv:9905116 Eq. 14
func (LambdaCDM) HubbleDistance ¶
HubbleDistance is the inverse of the Hubble parameter
distance : [Mpc]
func (LambdaCDM) LookbackTime ¶
LookbackTime is the time from redshift 0 to z.
func (LambdaCDM) LuminosityDistance ¶
LuminosityDistance is the radius of effective sphere over which the light has spread out
type WACDM ¶
type WACDM struct { H0 float64 // Hubble constant at z=0. [km/s/Mpc] Om0 float64 // Matter Density at z=0 Ol0 float64 // Dark Energy density Lambda at z=0 W0 float64 // Dark energy equation-of-state parameter, w0 + wa*(1-a) = p/rho WA float64 // Dark energy equation-of-state parameter, w0 + wa*(1-a) = p/rho Ogamma0 float64 // Photon density Onu0 float64 // Neutrino density }
WACDM provides cosmological distances, age, and look-back time for a w(a) cosmology: matter, dark energy, and curvature, with a w = w0 + wa * (1-a) equation-of-state parameter for dark energy.
Example ¶
cos := WACDM{H0: 70, Om0: 0.3, Ol0: 0.7, W0: -0.8, WA: 2.5} zVec := []float64{0.5, 1.0, 2.0, 3.0} distmodVec := make([]float64, len(zVec)) lumdistVec := make([]float64, len(zVec)) angdistVec := make([]float64, len(zVec)) for i, z := range zVec { distmodVec[i] = cos.DistanceModulus(z) lumdistVec[i] = cos.LuminosityDistance(z) angdistVec[i] = cos.AngularDiameterDistance(z) } fmt.Println(cos) fmt.Println("Ok0: ", cos.Ok0()) fmt.Println("Distance Modulus [mag]") fmt.Println(distmodVec) fmt.Println("Luminosity Distance [Mpc]") fmt.Println(lumdistVec) fmt.Println("Angular Diameter Distance [Mpc]") fmt.Println(angdistVec)
Output: WACDM{H0: 70, Om0: 0.3, Ol0: 0.7, W0: -0.8, WA: 2.5} Ok0: 0 Distance Modulus [mag] [42.07480332804884 43.731011211176536 45.31078970620773 46.17487505099648] Luminosity Distance [Mpc] [2599.9240753482904 5574.452795915061 11538.72814084889 17178.09539590076] Angular Diameter Distance [Mpc] [1155.521811265907 1393.6131989787652 1282.0809045387657 1073.6309622437975]
func (WACDM) AngularDiameterDistance ¶
AngularDiameterDistance is the ratio of physical transverse size to angular size
func (WACDM) ComovingDistance ¶
ComovingDistance is the distance that is constant with the Hubble flow expressed in the physical distance at z=0.
As the scale factor a = 1/(1+z) increases from 0.5 to 1, two objects separated by a proper distance of 10 Mpc at a=0.5 (z=1) will be separated by a proper distance of 2*10 Mpc at a=1.0 (z=0). The comoving distance between these objects is 20 Mpc.
func (WACDM) ComovingDistanceZ1Z2 ¶
ComovingDistanceZ1Z2 is the base function for calculation of comoving distances Here is where the choice of fundamental calculation method is made: Fall back to simpler cosmology, or quadature integration
func (WACDM) ComovingTransverseDistance ¶
ComovingTransverseDistance is the comoving distance at z as seen from z=0
func (WACDM) ComovingTransverseDistanceZ1Z2 ¶
ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1
func (WACDM) DistanceModulus ¶
DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.
func (WACDM) E ¶
E is the Hubble parameter as a fraction of its present value. E.g., Hogg arXiv:9905116 Eq. 14 Linder, 2003, PhRvL, 90, 130, Eq. 5, 7
func (WACDM) HubbleDistance ¶
HubbleDistance is the inverse of the Hubble parameter
distance : [Mpc]
func (WACDM) LookbackTime ¶
LookbackTime is the time from redshift 0 to z in Gyr.
func (WACDM) LuminosityDistance ¶
LuminosityDistance is the radius of effective sphere over which the light has spread out
type WCDM ¶
type WCDM struct { H0 float64 // Hubble constant at z=0. [km/s/Mpc] Om0 float64 // Matter Density at z=0 Ol0 float64 // Dark Energy density Lambda at z=0 W0 float64 // Dark energy equation-of-state parameter, w = p/rho Ogamma0 float64 // Photon density Onu0 float64 // Neutrino density }
WCDM provides cosmological distances, age, and look-back time for a constant-w cosmology: matter, dark energy, and curvature, with a w=constant equation-of-state parameter for dark energy
Example ¶
cos := WCDM{H0: 70, Om0: 0.3, Ol0: 0.7, W0: -1.2} zVec := []float64{0.5, 1.0, 2.0, 3.0} distmodVec := make([]float64, len(zVec)) lumdistVec := make([]float64, len(zVec)) angdistVec := make([]float64, len(zVec)) for i, z := range zVec { distmodVec[i] = cos.DistanceModulus(z) lumdistVec[i] = cos.LuminosityDistance(z) angdistVec[i] = cos.AngularDiameterDistance(z) } fmt.Println(cos) fmt.Println("Ok0: ", cos.Ok0()) fmt.Println("Distance Modulus [mag]") fmt.Println(distmodVec) fmt.Println("Luminosity Distance [Mpc]") fmt.Println(lumdistVec) fmt.Println("Angular Diameter Distance [Mpc]") fmt.Println(angdistVec)
Output: WCDM{H0: 70, Om0: 0.3, Ol0: 0.7, W0: -1.2} Ok0: 0 Distance Modulus [mag] [42.32710910996119 44.17957200628159 46.03118143998202 47.092287353314816] Luminosity Distance [Mpc] [2920.2620320966266 6853.531311400255 16078.157845948543 26209.423639506458] Angular Diameter Distance [Mpc] [1297.8942364873897 1713.3828278500637 1786.4619828831712 1638.0889774691536]
func (WCDM) AngularDiameterDistance ¶
AngularDiameterDistance is the ratio of physical transverse size to angular size
func (WCDM) ComovingDistance ¶
ComovingDistance is the distance that is constant with the Hubble flow expressed in the physical distance at z=0.
As the scale factor a = 1/(1+z) increases from 0.5 to 1, two objects separated by a proper distance of 10 Mpc at a=0.5 (z=1) will be separated by a proper distance of 2*10 Mpc at a=1.0 (z=0). The comoving distance between these objects is 20 Mpc.
func (WCDM) ComovingDistanceZ1Z2 ¶
ComovingDistanceZ1Z2 is the base function for calculation of comoving distances Here is where the choice of fundamental calculation method is made: Fall back to simpler cosmology, or quadature integration
func (WCDM) ComovingTransverseDistance ¶
ComovingTransverseDistance is the comoving distance at z as seen from z=0
func (WCDM) ComovingTransverseDistanceZ1Z2 ¶
ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1
func (WCDM) DistanceModulus ¶
DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.
func (WCDM) E ¶
E is the Hubble parameter as a fraction of its present value. E.g., Hogg arXiv:9905116 Eq. 14
func (WCDM) LookbackTime ¶
LookbackTime is the time from redshift 0 to z.
func (WCDM) LuminosityDistance ¶
LuminosityDistance is the radius of effective sphere over which the light has spread out