-
Notifications
You must be signed in to change notification settings - Fork 1
/
bestset.py
executable file
·89 lines (63 loc) · 3.27 KB
/
bestset.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Filename: bestset.py
# Author: Pedro H. A. Hasselmann
# Escrevendo em python3 e usando python2.6:
from __future__ import print_function, unicode_literals, absolute_import, division
from os import path
from collections import deque
def fit(where_data, q1_range, m_range):
import Gmode as Gm
from numpy import arange
gmode = Gm.Gmode()
gmode.load_data(filename=where_data)
gmode.grid = 2
form = "{0:.2f} {1:.2f} {2:3} {3:4} {4:.4f}".format
report = deque(["q1 mlim Nc E R"])
for mlim in arange(*m_range):
for q1 in arange(*q1_range):
gmode.q1 = q1
gmode.mlim = mlim
gmode.run(realtime_map='n', save='n')
report.append(form(q1, mlim, len(gmode.cluster_stats), len(gmode.excluded), gmode.robust))
out = open(path.join("TESTS","tests.txt"),"w+")
text = '\n'.join(list(report))
out.write(text)
def plot(highlight=None, tests="tests.txt", **lim):
import matplotlib.pyplot as plt
from numpy import loadtxt
q1, mlim, Nc, excluded, robust = loadtxt(path.join("TESTS",tests), unpack=True, dtype=None, skiprows=1)
name = ['({0:.2f}, {1:.2f})'.format(*item) for item in zip(q1, mlim)]
plt.figure(figsize=(10,10),dpi=100)
# Robustness vs Nc
plt.subplot(210)
plt.plot(Nc, robust, "ko", markersize=4, alpha=0.7, label="Gmode Tests ($G_{q_{1}}, minlimit$)")
for n, texto in enumerate(name):
#if any([True if item[0] == q1[n] and item[1] == mlim[n] else False for item in highlight]):
if Nc[n] >= lim["Nc"][0] and Nc[n] <= lim["Nc"][1] and robust[n] <= lim["robust"] \
and excluded[n] >= lim["excluded"][0] and excluded[n] <= lim["excluded"][1]:
highl = plt.plot(Nc[n], robust[n], color="red", marker="o", markersize=7)
plt.text(Nc[n], robust[n], texto, fontsize=8, fontweight='black', style='italic')
highl[0].set_label(texto)
plt.xlabel("$N_{c}$")
plt.ylabel("Robustness")
plt.legend(loc=0, numpoints=1, scatterpoints=1, fontsize=9)
# Excluded number vs Nc
plt.subplot(211)
plt.plot(robust, excluded, "ko", markersize=4, alpha=0.7, label="Gmode Tests ($G_{q_{1}}, minlimit$)")
for n, texto in enumerate(name):
#if any([True if item[0] == q1[n] and item[1] == mlim[n] else False for item in highlight]):
if Nc[n] >= lim["Nc"][0] and Nc[n] <= lim["Nc"][1] and robust[n] <= lim["robust"] \
and excluded[n] >= lim["excluded"][0] and excluded[n] <= lim["excluded"][1]:
highl = plt.plot(robust[n], excluded[n], color="red", marker="o", markersize=7)
plt.text(robust[n], excluded[n], texto, fontsize=8, fontweight='black', style='italic')
highl[0].set_label(texto)
plt.xlabel("Robustness")
plt.ylabel("Number of Excluded")
plt.legend(loc=0, numpoints=1, scatterpoints=1, fontsize=9)
plt.show()
plt.clf()
if __name__ == "__main__":
data_path = path.join("SDSSMOC","lists","MOC4_2quartile_refl.dat")
fit(data_path, [1.2,2.5,0.1],[0.05,0.4,0.05])
#plot(tests="tests_mlim_moc2q.txt", Nc=[20,50], excluded=[0, 700], robust=0.1)