-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lookback time and distance, comoving volume (#1)
* refactoring units, add my cool macro lol * more refactoring * structs for all base units * use CODATA 2018 values for constants * lookback time * lookback distance * comoving volume * add Rust benchmarks * initial profiling improvements * lots of perf improvements * fixins * vectorizing distances * final bits of optimization * changelog
- Loading branch information
1 parent
999e103
commit 2c4e005
Showing
25 changed files
with
673 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# 0.2.0 | ||
|
||
* Adds lookback time and distance calculations. | ||
* Adds comoving volume calculations. | ||
* Updates values for constants based on CODATA 2018. | ||
* Refactors handling of base units. | ||
* Add initial benchmarks. | ||
* Performance improvements. | ||
|
||
# 0.1.0 | ||
|
||
Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use cosmocalc::{cosmology::OmegaFactors, Distances, FLRWCosmology, FloatingPointUnit, Redshift}; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
|
||
pub fn bench_luminosity_distance(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("d_L"); | ||
let omegas = OmegaFactors::new(0.27, 0.73, 0.044).unwrap(); | ||
let cosmology = FLRWCosmology::new(None, None, 70.0, omegas, None, None, None).unwrap(); | ||
|
||
let z_1 = Redshift::new(1.); | ||
group.bench_with_input( | ||
BenchmarkId::new("d_L(z=1)", format!("{:?}", z_1)), | ||
&z_1, | ||
|b, z| b.iter(|| cosmology.luminosity_distance(*z)), | ||
); | ||
let z_2 = Redshift::new(2.); | ||
group.bench_with_input( | ||
BenchmarkId::new("d_L(z=2)", format!("{:?}", z_2)), | ||
&z_2, | ||
|b, z| b.iter(|| cosmology.luminosity_distance(*z)), | ||
); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_luminosity_distance); | ||
criterion_main!(benches); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from astropy.cosmology import FLRW, FlatLambdaCDM, LambdaCDM, Planck18 | ||
import timeit | ||
|
||
def flat_universe_distances_no_relativistic_contribution(): | ||
H0 = 69.6 | ||
Om0 = 0.286 | ||
Ode0 = 0.714 | ||
Ob0 = 0.05 | ||
cosmo = FlatLambdaCDM(H0, Om0, Ode0, 0, Ob0=Ob0) | ||
|
||
print('comoving transverse distance to z=3') | ||
print(cosmo.comoving_transverse_distance(3)) | ||
# 6482.549296743232 Mpc | ||
print('angular diameter distance to z=3') | ||
print(cosmo.angular_diameter_distance(3)) | ||
# 1620.637324185808 Mpc | ||
print('luminosity distance to z=3') | ||
print(cosmo.luminosity_distance(3)) | ||
# 25930.197186972928 Mpc | ||
|
||
|
||
def flat_universe_distances_with_radiation_but_no_neutrinos(): | ||
H0 = 69.6 | ||
Om0 = 0.299 | ||
Ode0 = 0.7 | ||
Ob0 = 0.05 | ||
Tcmb0 = 2.7255 | ||
cosmo = FlatLambdaCDM(H0, Om0, Ode0, 2.7255, 0, Ob0=Ob0) | ||
|
||
print('comoving transverse distance to z=3') | ||
print(cosmo.comoving_transverse_distance(3)) | ||
# 6398.504909397802 Mpc | ||
print('angular diameter distance to z=3') | ||
print(cosmo.angular_diameter_distance(3)) | ||
# 1599.6262273494506 Mpc | ||
print('luminosity distance to z=3') | ||
print(cosmo.luminosity_distance(3)) | ||
# 25594.01963759121 Mpc | ||
|
||
|
||
def lookback_time(): | ||
Om0 = 0.27 | ||
Ode0 = 0.73 | ||
Ob0 = 0.044 | ||
H0 = 70.0 | ||
cosmo = FlatLambdaCDM(H0, Om0, Ode0, 2.7255, 0, Ob0=Ob0) | ||
print('lookback time to z=3') | ||
print(cosmo.lookback_time(3)) | ||
# 11.641584565145552 Gyr | ||
|
||
|
||
def comoving_volume(): | ||
Om0 = 0.27 | ||
Ode0 = 0.73 | ||
Ob0 = 0.044 | ||
H0 = 70.0 | ||
cosmo = FlatLambdaCDM(H0, Om0, Ode0, 2.7255, 0, Ob0=Ob0) | ||
print('hubble distance') | ||
print(cosmo.hubble_distance) | ||
# 4282.749400000001 Mpc | ||
print('comoving volume to z=3') | ||
print(cosmo.comoving_volume(3)) | ||
# 1179374442443.6943 Mpc3 | ||
|
||
|
||
def bench_luminosity_distance(): | ||
Om0 = 0.27 | ||
Ode0 = 0.73 | ||
Ob0 = 0.044 | ||
H0 = 70.0 | ||
cosmo = FlatLambdaCDM(H0, Om0, Ode0, 2.7255, 0, Ob0=Ob0) | ||
n = 10000 | ||
print('d_L(z=1): ', timeit.timeit(lambda: cosmo.luminosity_distance(1), number=n)/n, 's') | ||
# 15us | ||
# Compared to 11us Rust | ||
print('d_L(z=2): ', timeit.timeit(lambda: cosmo.luminosity_distance(2), number=n)/n, 's') | ||
# 15us | ||
# Compared to 22us Rust | ||
|
||
|
||
if __name__=="__main__": | ||
# flat_universe_distances_no_relativistic_contribution() | ||
# flat_universe_distances_with_radiation_but_no_neutrinos() | ||
# lookback_time() | ||
# comoving_volume() | ||
bench_luminosity_distance() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.