Skip to content

Instantly share code, notes, and snippets.

@Findus23
Created December 17, 2017 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Findus23/b7e0b43f9e96943fd0cfa59e51fa28d5 to your computer and use it in GitHub Desktop.
Save Findus23/b7e0b43f9e96943fd0cfa59e51fa28d5 to your computer and use it in GitHub Desktop.
Astro
import matplotlib.pyplot as plt
def get_data(filename):
with open(filename) as file:
lines = file.readlines()
titles = lines[0].split() # Spaltennamen sind in der ersten Zeile
print(titles)
data = []
for dataline in lines[2:-1]: # ersten zwei Zeilen und die letzte Zeile ignorieren
columns = []
for dataString in dataline.split():
try:
columns.append(int(dataString))
except ValueError:
try:
columns.append(float(dataString))
except ValueError:
columns.append(dataString)
data.append(dict(zip(titles, columns)))
return data
# Aufgabe A
tab1 = get_data("fasano2000_tab1.dat")
tab2 = get_data("fasano2000_tab2.dat")
z = []
s0 = []
for cluster in tab1:
print(cluster)
total_galaxies = 0
s0_galaxies = 0
for galaxy in tab2:
if galaxy["Abel"] == cluster["Abel"]:
total_galaxies += 1
if "S0" in galaxy["Mtype"]:
s0_galaxies += 1
z.append(cluster["z"])
s0.append(s0_galaxies / total_galaxies * 100)
plt.scatter(z, s0)
plt.xlabel("z-index")
plt.ylabel("Anteil der S0 Galaxien in %")
plt.savefig("output/figure.png")
plt.savefig("output/figure.eps", format='eps', dpi=1000)
plt.close()
# Aufgabe B
fdf = get_data("fdf.dat")
BRs = [[], [], []]
Ms = [[], [], []]
labels = ["$0.0<z<0.4$", "$0.4<z<0.7$", "$0.7<z<1.7$"]
for galaxy in fdf:
BR = galaxy["B"] - galaxy["R"]
if galaxy["z"] < 0.4:
group = 0
elif galaxy["z"] < 0.7:
group = 1
else:
group = 2
BRs[group].append(BR)
Ms[group].append(galaxy["M_B"])
for i in range(3):
plt.scatter(BRs[i], Ms[i], label=labels[i], c="C{N}".format(N=i),s=4)
plt.xlabel("$B-R$")
plt.ylabel("$M_B$")
plt.legend()
plt.savefig("output/figure{i}.png".format(i=i))
plt.savefig("output/figure{i}.eps".format(i=i), format='eps', dpi=1000)
plt.close()
for i in range(3):
plt.scatter(BRs[i], Ms[i], label=labels[i], c="C{N}".format(N=i),s=4)
plt.xlabel("$B-R$")
plt.ylabel("$M_B$")
plt.legend()
plt.savefig("output/figure_all.png")
plt.savefig("output/figure_all.eps", format='eps', dpi=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment