Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
push:
branches: [main]
tags: '*'
pull_request:
branches: [main]

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- "min"
- "1"
- "pre"
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- 'default'
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
test_args: '--verbose'
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v5
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Documentation

on:
push:
branches: [main]
tags: '*'
pull_request:
branches: [main]

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
docs:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: "1"
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GKSwstype: "100" # fix GKS socket error for plots made in @example blocks
42 changes: 0 additions & 42 deletions .github/workflows/ci.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/docs.yml

This file was deleted.

12 changes: 4 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name = "Cosmology"
uuid = "76746363-e552-5dba-9a5a-cef6fa9cc5ab"
version = "1.0.4"

[workspace]
projects = ["test", "docs"]

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Expand All @@ -13,11 +16,4 @@ DocStringExtensions = "0.9"
QuadGK = "0.1.1, 0.2, 0.3, 2"
Unitful = "1.2"
UnitfulAstro = "1.1"
julia = "1"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Documenter"]
julia = "1.10"
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Cosmology.jl

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaastro.github.io/Cosmology.jl/stable)
[![Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://juliaastro.github.io/Cosmology.jl/dev)
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaastro.org/Cosmology/stable/)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaastro.org/Cosmology.jl/dev/)

[![CI](https://github.com/JuliaAstro/Cosmology.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaAstro/Cosmology.jl/actions/workflows/ci.yml)
[![Coverage Status](http://img.shields.io/coveralls/JuliaAstro/Cosmology.jl.svg?style=flat-square)](https://coveralls.io/r/JuliaAstro/Cosmology.jl?branch=master)
[![CI](https://github.com/JuliaAstro/Cosmology.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaAstro/Cosmology.jl/actions/workflows/CI.yml)
[![codecov](https://codecov.io/gh/JuliaAstro/Cosmology.jl/graph/badge.svg)](https://codecov.io/gh/JuliaAstro/Cosmology.jl)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A cosmology calculator for Julia.

Expand Down
6 changes: 0 additions & 6 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f"

[sources]
Cosmology = {path = ".."}

[compat]
Documenter = "1"
2 changes: 1 addition & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ julia> comoving_volume(c, 0.6)
49.3633436631307 Gpc^3

julia> comoving_volume(u"ly^3", c, 0.6)
1.7127035381753e30 ly^3
1.7127035381752996e30 ly^3
```

## Times
Expand Down
3 changes: 0 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Cosmology.jl

[![CI](https://github.com/JuliaAstro/Cosmology.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaAstro/Cosmology.jl/actions/workflows/ci.yml)
[![Coverage Status](http://img.shields.io/coveralls/JuliaAstro/Cosmology.jl.svg?style=flat-square)](https://coveralls.io/r/JuliaAstro/Cosmology.jl?branch=master)

[`Cosmology.jl`](https://github.com/JuliaAstro/Cosmology.jl) provides functions for quick cosmological calculations, written in pure Julia.

## Installation
Expand Down
8 changes: 8 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Cosmology = "76746363-e552-5dba-9a5a-cef6fa9cc5ab"
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f"
149 changes: 8 additions & 141 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,144 +1,11 @@
using Cosmology
using Test, Unitful, UnitfulAstro, QuadGK
using Documenter
using ParallelTestRunner: runtests, find_tests, parse_args
import Cosmology

@testset "Cosmology" begin

# values from http://icosmos.co.uk/

dist_rtol = 1e-6
age_rtol = 2e-4
# Integrating a unitful function would require UnitfulIntegration.jl. Without using it, we
# strip the units away from the integrand function
integrand(c, z) = 4pi*ustrip(comoving_volume_element(c, z))

@testset "FlatLCDM" begin
c = cosmology(h=0.7, OmegaM=0.3, OmegaR=0)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1651.9145u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 625.3444u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_radial_dist(c,1,rtol=dist_rtol) ≈ 3303.829u"Mpc" rtol = dist_rtol
@test comoving_volume(c,1,rtol=dist_rtol) ≈ 151.0571u"Gpc^3" rtol = dist_rtol
@test quadgk(z -> integrand(c, z), 0, 2.5)[1] ≈ ustrip(comoving_volume(c, 2.5))
@test luminosity_dist(c,1,rtol=dist_rtol) ≈ 6607.6579u"Mpc" rtol = dist_rtol
@test distmod(c,1,rtol=dist_rtol) ≈ 44.1002 rtol = dist_rtol
@test age(c,0,rtol=age_rtol) ≈ 13.4694u"Gyr" rtol = age_rtol
@test age(c,1,rtol=age_rtol) ≈ 5.7527u"Gyr" rtol = age_rtol
@test lookback_time(c,1,rtol=age_rtol) ≈ (13.4694-5.7527)u"Gyr" rtol = age_rtol
@test age(c, 1) + lookback_time(c, 1) ≈ age(c, 0)
end

@testset "OpenLCDM" begin
c = cosmology(h=0.7, OmegaK=0.1, OmegaM=0.3, OmegaR=0)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1619.9588u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 598.9118u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_radial_dist(c,1,rtol=dist_rtol) ≈ 3209.784u"Mpc" rtol = dist_rtol
@test comoving_volume(c,1,rtol=dist_rtol) ≈ 140.0856u"Gpc^3" rtol = dist_rtol
@test quadgk(z -> integrand(c, z), 0, 2.5)[1] ≈ ustrip(comoving_volume(c, 2.5))
@test luminosity_dist(c,1,rtol=dist_rtol) ≈ 6479.8352u"Mpc" rtol = dist_rtol
@test distmod(c,1,rtol=dist_rtol) ≈ 44.0578 rtol = dist_rtol
@test age(c,0,rtol=age_rtol) ≈ 13.064u"Gyr" rtol = age_rtol
@test age(c,1,rtol=age_rtol) ≈ 5.5466u"Gyr" rtol = age_rtol
@test lookback_time(c,1,rtol=age_rtol) ≈ (13.064-5.5466)u"Gyr" rtol = age_rtol
@test age(c, 1) + lookback_time(c, 1) ≈ age(c, 0)
end

@testset "ClosedLCDM" begin
c = cosmology(h=0.7, OmegaK=-0.1, OmegaM=0.3, OmegaR=0)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1686.5272u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 655.6019u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_radial_dist(c,1,rtol=dist_rtol) ≈ 3408.937u"Mpc" rtol = dist_rtol
@test comoving_volume(c,1,rtol=dist_rtol) ≈ 163.8479u"Gpc^3" rtol = dist_rtol
@test quadgk(z -> integrand(c, z), 0, 2.5)[1] ≈ ustrip(comoving_volume(c, 2.5))
@test luminosity_dist(c,1,rtol=dist_rtol) ≈ 6746.1088u"Mpc" rtol = dist_rtol
@test distmod(c,1,rtol=dist_rtol) ≈ 44.1453 rtol = dist_rtol
@test age(c,0,rtol=age_rtol) ≈ 13.925u"Gyr" rtol = age_rtol
@test age(c,1,rtol=age_rtol) ≈ 5.9868u"Gyr" rtol = age_rtol
@test lookback_time(c,1,rtol=age_rtol) ≈ (13.925-5.9868)u"Gyr" rtol = age_rtol
@test age(c, 1) + lookback_time(c, 1) ≈ age(c, 0)
end

@testset "FlatWCDM" begin
c = cosmology(h=0.7, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1612.0585u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 607.6802u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_radial_dist(c,1,rtol=dist_rtol) ≈ 3224.1169u"Mpc" rtol = dist_rtol
@test comoving_volume(c,1,rtol=dist_rtol) ≈ 140.3851u"Gpc^3" rtol = dist_rtol
@test quadgk(z -> integrand(c, z), 0, 2.5)[1] ≈ ustrip(comoving_volume(c, 2.5))
@test luminosity_dist(c,1,rtol=dist_rtol) ≈ 6448.2338u"Mpc" rtol = dist_rtol
@test distmod(c,1,rtol=dist_rtol) ≈ 44.0472 rtol = dist_rtol
@test age(c,0,rtol=age_rtol) ≈ 13.1915u"Gyr" rtol = age_rtol
@test age(c,1,rtol=age_rtol) ≈ 5.6464u"Gyr" rtol = age_rtol
@test lookback_time(c,1,rtol=age_rtol) ≈ (13.1915-5.6464)u"Gyr" rtol = age_rtol
@test age(c, 1) + lookback_time(c, 1) ≈ age(c, 0)
end

@testset "OpenWCDM" begin
c = cosmology(h=0.7, OmegaK=0.1, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1588.0181u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 585.4929u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_radial_dist(c,rtol=dist_rtol,1) ≈ 3147.6227u"Mpc" rtol = dist_rtol
@test comoving_volume(c,1,rtol=dist_rtol) ≈ 132.0466u"Gpc^3" rtol = dist_rtol
@test quadgk(z -> integrand(c, z), 0, 2.5)[1] ≈ ustrip(comoving_volume(c, 2.5))
@test luminosity_dist(c,1,rtol=dist_rtol) ≈ 6352.0723u"Mpc" rtol = dist_rtol
@test distmod(c,1,rtol=dist_rtol) ≈ 44.0146 rtol = dist_rtol
@test age(c,0,rtol=age_rtol) ≈ 12.8488u"Gyr" rtol = age_rtol
@test age(c,1,rtol=age_rtol) ≈ 5.4659u"Gyr" rtol = age_rtol
@test lookback_time(c,1,rtol=age_rtol) ≈ (12.8488-5.4659)u"Gyr" rtol = age_rtol
@test age(c, 1) + lookback_time(c, 1) ≈ age(c, 0)
end

@testset "ClosedWCDM" begin
c = cosmology(h=0.7, OmegaK=-0.1, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1637.5993u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 632.5829u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_radial_dist(c,1,rtol=dist_rtol) ≈ 3307.9932u"Mpc" rtol = dist_rtol
@test comoving_volume(c,1,rtol=dist_rtol) ≈ 149.8301u"Gpc^3" rtol = dist_rtol
@test quadgk(z -> integrand(c, z), 0, 2.5)[1] ≈ ustrip(comoving_volume(c, 2.5))
@test luminosity_dist(c,1,rtol=dist_rtol) ≈ 6550.3973u"Mpc" rtol = dist_rtol
@test distmod(c,1,rtol=dist_rtol) ≈ 44.0813 rtol = dist_rtol
@test age(c,0,rtol=age_rtol) ≈ 13.5702u"Gyr" rtol = age_rtol
@test age(c,1,rtol=age_rtol) ≈ 5.8482u"Gyr" rtol = age_rtol
@test lookback_time(c,1,rtol=age_rtol) ≈ (13.5702-5.8482)u"Gyr" rtol = age_rtol
@test age(c, 1) + lookback_time(c, 1) ≈ age(c, 0)
end

@testset "Non-Float64" begin
# Test that FlatLCDM works with non-Float64 (BigFloat in this example)
c = cosmology(h=0.7, OmegaM=big(0.3), OmegaR=0)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1651.9145u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 625.3444u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_volume_element(c, big(1.41)) ≈ 3.4030879e10u"Mpc^3" rtol = dist_rtol
# Test that FlatWCDM works with non-Float64 (BigFloat in this example)
c = cosmology(h=big(0.7), OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1)
@test angular_diameter_dist(c,1,rtol=dist_rtol) ≈ 1612.0585u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,1,2,rtol=dist_rtol) ≈ 607.6802u"Mpc" rtol = dist_rtol
@test angular_diameter_dist(c,pi,rtol=dist_rtol) ≈ angular_diameter_dist(c,0,pi,rtol=dist_rtol) rtol = dist_rtol
@test comoving_volume_element(c, big(1.41)) ≈ 3.1378625e10u"Mpc^3" rtol = dist_rtol
end
const init_code = quote
# Shared code here
end

@testset "Unit conversion" begin
c = cosmology(h=0.9, OmegaM=0.5, OmegaR=0)
for u in (u"m", u"pc", u"ly")
@test unit(luminosity_dist(u, c, 1)) == u
@test unit(angular_diameter_dist(u, c, 2)) == u
end
for u in (u"s", u"yr")
@test unit(age(u, c, 3)) == u
@test unit(lookback_time(u, c, 4)) == u
end
end
args = parse_args(Base.ARGS)
testsuite = find_tests(@__DIR__)

@testset "Utilities" begin
c = cosmology(h = 0.7)
@test hubble_time(c, 0) ≈ Cosmology.hubble_time0(c)
@test hubble_dist(c, 0) ≈ Cosmology.hubble_dist0(c)
@test H(c, 0) ≈ 70u"km/s/Mpc"
end
end
runtests(Cosmology, args; testsuite, init_code)
8 changes: 8 additions & 0 deletions test/test_aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Aqua

@testset "Aqua tests" begin
using Cosmology
using Aqua

Aqua.test_all(Cosmology)
end
Loading
Loading