Pkg.go.dev is a new destination for Go discovery & docs. Check it out at pkg.go.dev/github.com/wmwv/cosmo and share your feedback.

package cosmo

import "github.com/wmwv/cosmo"

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

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.

cosmo.go flatlcdm.go lambdacdm.go util.go wacdm.go wcdm.go

❖ 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.

❖ 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 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 Code: 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]

Age is the time from redshift ∞ to z

AngularDiameterDistance is the ratio of physical transverse size to angular size

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 (cos FlatLCDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)

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.

ComovingTransverseDistance is the comoving distance at z as seen from z=0

❖ func (cos FlatLCDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)

ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1

DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.

E is the Hubble parameter as a fraction of its present value. E.g., Hogg arXiv:9905116 Eq. 14

Einv is the inverse Hubble parameter

HubbleDistance is the inverse of the Hubble parameter times the speed of light.

LookbackTime is the time from redshift 0 to z.

LuminosityDistance is the radius of effective sphere over which the light has spread out

Ok0 is the curvature density at z=0

❖ 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 Code: 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]

Age is the time from redshift ∞ to z.

AngularDiameterDistance is the ratio of physical transverse size to angular size

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 (cos LambdaCDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)

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

ComovingTransverseDistance is the comoving distance at z as seen from z=0

❖ func (cos LambdaCDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)

ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1

DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.

E is the Hubble parameter as a fraction of its present value. E.g., Hogg arXiv:9905116 Eq. 14

Einv is the inverse Hubble parameter Implementation is just to return E(z)

HubbleDistance is the inverse of the Hubble parameter

distance : [Mpc]

LookbackTime is the time from redshift 0 to z.

LuminosityDistance is the radius of effective sphere over which the light has spread out

Ok0 is the curvature density at z=0

❖ 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 Code: 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]

Age is the time from redshift ∞ to z in Gyr.

AngularDiameterDistance is the ratio of physical transverse size to angular size

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 (cos WACDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)

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

ComovingTransverseDistance is the comoving distance at z as seen from z=0

❖ func (cos WACDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)

ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1

DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.

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

Einv is the inverse Hubble parameter Implementation is just to return E(z)

HubbleDistance is the inverse of the Hubble parameter

distance : [Mpc]

LookbackTime is the time from redshift 0 to z in Gyr.

LuminosityDistance is the radius of effective sphere over which the light has spread out

Ok0 is the curvature density at z=0

❖ 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 Code: 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]

Age is the time from redshift ∞ to z.

AngularDiameterDistance is the ratio of physical transverse size to angular size

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 (cos WCDM) ComovingDistanceZ1Z2(z1, z2 float64) (distanceMpc float64)

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

ComovingTransverseDistance is the comoving distance at z as seen from z=0

❖ func (cos WCDM) ComovingTransverseDistanceZ1Z2(z1, z2 float64) (distanceMpcRad float64)

ComovingTransverseDistanceZ1Z2 is the comoving distance at z2 as seen from z1

DistanceModulus is the magnitude difference between 1 Mpc and the luminosity distance for the given z.

E is the Hubble parameter as a fraction of its present value. E.g., Hogg arXiv:9905116 Eq. 14

Einv is the inverse Hubble parameter Implementation is just to return E(z)

HubbleDistance is the inverse of the Hubble parameter

distance : [Mpc]

LookbackTime is the time from redshift 0 to z.

LuminosityDistance is the radius of effective sphere over which the light has spread out

Ok0 is the curvature density at z=0

Package cosmo imports 5 packages (graph). Updated 2018-02-13. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).