-
Notifications
You must be signed in to change notification settings - Fork 0
/
cummplotter.py
62 lines (37 loc) · 1.56 KB
/
cummplotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import numpy as np
from starprocessor import StarProcessor
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.path as path
import itertools
import csv
# finds galaxies and stores the corresponding data in the catalogue.
s = StarProcessor()
stars = np.load("catalogue.npy")
#print stars
fluxlist = np.array([[i['flux'], i['fluxerror']] for i in stars])
b = 80 #specifies the number of bins for the historgram
values, base = np.histogram(fluxlist[:,0], bins=b)
fluxlist = np.sort(fluxlist,axis=1)
# print np.where(fluxlist[:,0] == 0, fluxlist[:,0], fluxlist[:,1])
x_error = []
for first, second in itertools.izip(base, base[1:]):
x_error.append(np.std([t[0] for t in fluxlist if ((t[1] >= first) & (t[1] < second))]))
#fluxerror = np.array([[np.where(fluxlist[0] > i[0])] for i in base])
#[t for t in fluxlist if (fluxlist[0] > base[0][0])]
print x_error
cumulative = np.cumsum(values)
#x_error
y_error = cumulative**0.5
cumulative_log=np.log10(cumulative)
y_error_log=y_error*(2*cumulative*np.log(10))**-1
with open('cumplot_data_inc_errors.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamwriter.writerow(['base','x_error','cumulative','y_error','log10(N)','y_error_log'])
for i in range(len(base)-1):
spamwriter.writerow([base[i],x_error[i], cumulative[i], y_error[i], cumulative_log[i], y_error_log[i]])
#print cumulative
#print y_error
plt.errorbar(base[:-1], cumulative,y_error,x_error,c='blue')
plt.semilogy()
plt.show()