-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchiSquared.py
More file actions
51 lines (35 loc) · 1.21 KB
/
chiSquared.py
File metadata and controls
51 lines (35 loc) · 1.21 KB
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
from __future__ import division, print_function
import numpy as np
from glob import glob
import os
from AIA_tools import *
pathToData ="/home/john/gitRepos/REU/jwaczak/data/correctedSyntheticObservations/"
pathToObs = "/home/john/gitRepos/REU/jwaczak/data/observationData/obs_data.txt"
dataFiles = os.listdir(pathToData)
obs = np.loadtxt(pathToObs, delimiter=',')
data = []
def chiSquared(obs, sim):
X_sq = 0
# NOTE for some reason we have an extra data point in the sims than in the obs data
if len(sim) == len(obs)+1:
sim = sim[:-1]
assert(len(obs) == len(sim))
for i in range(int(len(obs)/2)):
dev = obs[i]-sim[i]
X_sq += (dev)**2/obs[i] # sqrt(obs[i]) measures the error in the observational data
return X_sq
for file_ in dataFiles:
freeParams = 2
d = np.loadtxt(pathToData+file_, delimiter=',')
sum = 0
for i in range(1,6):
X = chiSquared(obs[:,i], d[:,i])
sum += X
sum = sum/(5*(len(d[:,0])/2)-freeParams)
data.append(sum)
data = np.array(data)
try:
min_index = analysis.getNearestValue(data, 1.0)
print("SUM: ", dataFiles[min_index], "\tX2:", data[min_index])
except:
print("Could not find minimum value(s)")