Input Parameters ---------------- hubble_constant: Hubble constante is the expansion rate today usually given in km/(s*Mpc) radiation_density: relative radiation density today matter_density: relative mass density today dark_energy: relative dark energy density today
(
hubble_constant: float,
radiation_density: float,
matter_density: float,
dark_energy: float,
redshift: float,
)
| 28 | |
| 29 | |
| 30 | def hubble_parameter( |
| 31 | hubble_constant: float, |
| 32 | radiation_density: float, |
| 33 | matter_density: float, |
| 34 | dark_energy: float, |
| 35 | redshift: float, |
| 36 | ) -> float: |
| 37 | """ |
| 38 | Input Parameters |
| 39 | ---------------- |
| 40 | hubble_constant: Hubble constante is the expansion rate today usually |
| 41 | given in km/(s*Mpc) |
| 42 | |
| 43 | radiation_density: relative radiation density today |
| 44 | |
| 45 | matter_density: relative mass density today |
| 46 | |
| 47 | dark_energy: relative dark energy density today |
| 48 | |
| 49 | redshift: the light redshift |
| 50 | |
| 51 | Returns |
| 52 | ------- |
| 53 | result : Hubble parameter in and the unit km/s/Mpc (the unit can be |
| 54 | changed if you want, just need to change the unit of the Hubble constant) |
| 55 | |
| 56 | >>> hubble_parameter(hubble_constant=68.3, radiation_density=1e-4, |
| 57 | ... matter_density=-0.3, dark_energy=0.7, redshift=1) |
| 58 | Traceback (most recent call last): |
| 59 | ... |
| 60 | ValueError: All input parameters must be positive |
| 61 | |
| 62 | >>> hubble_parameter(hubble_constant=68.3, radiation_density=1e-4, |
| 63 | ... matter_density= 1.2, dark_energy=0.7, redshift=1) |
| 64 | Traceback (most recent call last): |
| 65 | ... |
| 66 | ValueError: Relative densities cannot be greater than one |
| 67 | |
| 68 | >>> hubble_parameter(hubble_constant=68.3, radiation_density=1e-4, |
| 69 | ... matter_density= 0.3, dark_energy=0.7, redshift=0) |
| 70 | 68.3 |
| 71 | """ |
| 72 | parameters = [redshift, radiation_density, matter_density, dark_energy] |
| 73 | if any(p < 0 for p in parameters): |
| 74 | raise ValueError("All input parameters must be positive") |
| 75 | |
| 76 | if any(p > 1 for p in parameters[1:4]): |
| 77 | raise ValueError("Relative densities cannot be greater than one") |
| 78 | else: |
| 79 | curvature = 1 - (matter_density + radiation_density + dark_energy) |
| 80 | |
| 81 | e_2 = ( |
| 82 | radiation_density * (redshift + 1) ** 4 |
| 83 | + matter_density * (redshift + 1) ** 3 |
| 84 | + curvature * (redshift + 1) ** 2 |
| 85 | + dark_energy |
| 86 | ) |
| 87 |