Editing Talk:2853: Redshift
Please sign your posts with ~~~~ |
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 17: | Line 17: | ||
<tt><pre><nowiki> | <tt><pre><nowiki> | ||
− | from scipy.special import hyp2f1 # hypergeometric function | + | from scipy.special import hyp2f1 # hypergeometric 2F1 function is in integral solution |
from numpy import format_float_positional | from numpy import format_float_positional | ||
Line 26: | Line 26: | ||
#Om = 0.317 # Density parameter for matter, Omega_mass | #Om = 0.317 # Density parameter for matter, Omega_mass | ||
Om = 0.286 # From https://arxiv.org/pdf/1406.1718.pdf page 8 | Om = 0.286 # From https://arxiv.org/pdf/1406.1718.pdf page 8 | ||
− | OL = 1.0 - Om - 0.4165/(H0**2) # | + | OL = 1.0 - Om - 0.4165/(H0**2) # from https://www.astro.ucla.edu/~wright/CosmoCalc.html |
− | |||
#print(f"{OL=:.3F}") # 0.714 | #print(f"{OL=:.3F}") # 0.714 | ||
− | # Age of universe at redshift z as a closed-form solution to its integral definition, | + | # Age of universe at redshift z as a closed-form solution to its integral definition, ... |
− | def age_at_z(z): # ...which is 27 times faster than the original numeric integration | + | def age_at_z(z): # ...which is 27 times faster than the original numeric integration. |
hypergeom = hyp2f1(0.5, 0.5, 1.5, -OL / (Om * (z + 1)**3)) | hypergeom = hyp2f1(0.5, 0.5, 1.5, -OL / (Om * (z + 1)**3)) | ||
return (2/3) * hypergeom / (Om**0.5 * (z + 1)**1.5) * (977.8 / H0) # 977.8 for Gyr | return (2/3) * hypergeom / (Om**0.5 * (z + 1)**1.5) * (977.8 / H0) # 977.8 for Gyr | ||
Line 62: | Line 61: | ||
</nowiki></pre></tt> | </nowiki></pre></tt> | ||
− | And should you wish to make [https://i.ibb.co/ | + | And should you wish to make [https://i.ibb.co/v4nt6GM/time-by-redshift.png this quick reference chart for interpreting observations in the JWST era:] |
{{cot|Supplemental code for Look-back Time by Redshift chart}} | {{cot|Supplemental code for Look-back Time by Redshift chart}} | ||
Line 69: | Line 68: | ||
import matplotlib.ticker as ticker | import matplotlib.ticker as ticker | ||
− | + | redshifts = [z * 20 / 299 for z in range(300)] # 0 to 20 in 300 steps | |
− | + | look_back_times = [zt(z) for z in redshifts] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | plt.plot(redshifts, look_back_times) | ||
plt.title('Look-back Time by Redshift') | plt.title('Look-back Time by Redshift') | ||
− | plt.xlabel('z | + | plt.xlabel('z') |
plt.ylabel('Billion Years Ago') | plt.ylabel('Billion Years Ago') | ||
plt.xticks(range(21)) | plt.xticks(range(21)) | ||
plt.yticks(list(range(14)) + [age0]) | plt.yticks(list(range(14)) + [age0]) | ||
− | |||
plt.gca().yaxis.set_major_formatter(ticker.FormatStrFormatter('%.1f')) | plt.gca().yaxis.set_major_formatter(ticker.FormatStrFormatter('%.1f')) | ||
plt.grid(True, color='lightgray') | plt.grid(True, color='lightgray') | ||
Line 91: | Line 83: | ||
for t in range(0, 13): | for t in range(0, 13): | ||
− | z = | + | z = redshifts[min(range(len(look_back_times)), |
+ | key=lambda i: abs(look_back_times[i]-t))] | ||
plt.text(z, t, f" z = {z:.2f}", ha='left', va='center', fontsize='small') | plt.text(z, t, f" z = {z:.2f}", ha='left', va='center', fontsize='small') | ||
Line 103: | Line 96: | ||
plt.savefig('time_by_redshift.png', bbox_inches='tight') | plt.savefig('time_by_redshift.png', bbox_inches='tight') | ||
− | #plt.show() # https://i.ibb.co/ | + | #plt.show() # https://i.ibb.co/v4nt6GM/time-by-redshift.png |
</nowiki></pre></tt> | </nowiki></pre></tt> | ||
{{cob}} | {{cob}} | ||
− | Or [https://i.ibb.co/ | + | Or [https://i.ibb.co/yybQpjL/age-by-redshift.png this one showing the age of the universe from redshift:] |
{{cot|Supplemental code for Age of Universe by Redshift chart}} | {{cot|Supplemental code for Age of Universe by Redshift chart}} | ||
<tt><pre><nowiki> | <tt><pre><nowiki> | ||
− | plt.clf() # | + | plt.clf() # reset plot |
− | |||
− | |||
− | |||
− | + | redshifts = [z * 15 / 299 + 5 for z in range(300)] # 5 to 20 in 300 steps | |
− | + | ages = [age_at_z(z) * 1000 for z in redshifts] | |
− | |||
− | |||
+ | plt.plot(redshifts, ages) | ||
plt.title('Age of Universe by Redshift') | plt.title('Age of Universe by Redshift') | ||
− | plt.xlabel('z | + | plt.xlabel('z') |
plt.ylabel('Million Years') | plt.ylabel('Million Years') | ||
plt.xticks(range(5, 21)) | plt.xticks(range(5, 21)) | ||
Line 131: | Line 120: | ||
plt.savefig('age_by_redshift.png', bbox_inches='tight') | plt.savefig('age_by_redshift.png', bbox_inches='tight') | ||
− | #plt.show() # https://i.ibb.co/ | + | #plt.show() # https://i.ibb.co/yybQpjL/age-by-redshift.png |
</nowiki></pre></tt> | </nowiki></pre></tt> | ||
{{cob}} | {{cob}} | ||
− | + | Enjoy! [[Special:Contributions/172.69.22.12|172.69.22.12]] 08:50, 12 November 2023 (UTC) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |