forked from DanielMartinezMiravete/Axion_Limits_Memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AxionPlot.py
296 lines (265 loc) · 9.06 KB
/
AxionPlot.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import matplotlib.pyplot as plt
import matplotlib as mpl
from XPlotter import BasePlot, ExPltItem
import DataBaseClass as db
def extract_kwargs(arguments_str):
"""Extracts kwargs from a string of arguments.
Example: extract_kwargs("a=1, b=2, c=3") returns {'a':1, 'b':2, 'c':3}
extract_kwargs("a=1, b="red", c=3,") returns {'a':1, 'b':'red', 'c':3}"""
kwargs = {}
for arg in arguments_str.split(","):
if arg.strip() != "":
key, value = arg.split("=")
kwargs[key.strip()] = eval(value.strip())
return kwargs
# ==============================================================================#
# renormalize data, to plot C_ag instead of g_ag
#
def RenormItem(item):
for i in range(len(item.data)):
# print(item.name)
item.data[i, 1] = item.data[i, 1] / item.data[i, 0] * 5.172e9
# print(item.data[i,0],item.data[i,1])
# C_ag = g_ag / m_a * 5.172e9
class AxionGagPlot:
ListOfPlotTypes = {
"large_panorama",
"panorama",
"LSWexps",
"haloscopes",
"haloscopes_zoom",
"haloscopes_radeszoom",
"helioscopes",
}
def __init__(
self,
database: db.DataBaseGag,
labels: db.DataBaseLabels,
plottype="",
projections=False,
showplot=True,
saveplotname=None,
figx=None,
figy=None,
ymin=None,
ymax=None,
xmin=None,
xmax=None,
ticksopt_x=None,
ticksopt_y=None,
labelx="$m_a$ (eV)",
labely=r"$|g_{a\gamma}|$ (GeV$^{-1}$)",
):
if plottype not in self.ListOfPlotTypes:
print(
"Warning: "
+ plottype
+ " not a known plot type. Using default values and wildType column in database"
)
# default values for the plot (with no specified type)
if (plottype in ["large_panorama"]) or (plottype not in self.ListOfPlotTypes):
if figx is None:
figx = 6.5
if figy is None:
figy = 5
if ymin is None:
ymin = 1e-18
if ymax is None:
ymax = 1e-4
if xmin is None:
xmin = 1e-11
if xmax is None:
xmax = 1e9
if ticksopt_x is None:
ticksopt_x = "dense"
if ticksopt_y is None:
ticksopt_y = "normal"
# default values for the plot (with specified type)
if plottype == "panorama":
if figx is None:
figx = 6.5
if figy is None:
figy = 6
if ymin is None:
ymin = 1e-17
if ymax is None:
ymax = 1e-6
if xmin is None:
xmin = 1e-9
if xmax is None:
xmax = 10
if ticksopt_x is None:
ticksopt_x = "normal"
if ticksopt_y is None:
ticksopt_y = "normal"
if plottype == "helioscopes":
if figx is None:
figx = 8
if figy is None:
figy = 6
if ymin is None:
ymin = 1e-13
if ymax is None:
ymax = 1e-8
if xmin is None:
xmin = 1e-11
if xmax is None:
xmax = 1
if ticksopt_x is None:
ticksopt_x = "normal"
if ticksopt_y is None:
ticksopt_y = "normal"
if plottype == "LSWexps":
if figx is None:
figx = 6.5
if figy is None:
figy = 5
if ymin is None:
ymin = 1e-13
if ymax is None:
ymax = 1e-6
if xmin is None:
xmin = 1e-10
if xmax is None:
xmax = 1e-2
if ticksopt_x is None:
ticksopt_x = "normal"
if ticksopt_y is None:
ticksopt_y = "normal"
if plottype in ["haloscopes", "haloscopes_zoom", "haloscopes_radeszoom"]:
if figx is None:
figx = 8
if figy is None:
figy = 5
if ymin is None:
ymin = 1e-1
if ymax is None:
ymax = 1e3
if xmin is None:
if plottype in ["haloscopes"]:
xmin = 1e-9
if plottype in ["haloscopes_zoom"]:
xmin = 3e-7
if plottype in ["haloscopes_radeszoom"]:
xmin = 3.4e-5
if xmax is None:
if plottype in ["haloscopes"]:
xmax = 1
if plottype in ["haloscopes_zoom"]:
xmax = 3e-2
if plottype in ["haloscopes_radeszoom"]:
xmax = 4.5e-5
if ticksopt_x is None:
ticksopt_x = "normal"
if ticksopt_y is None:
ticksopt_y = "normal"
labely = r"$|C_{a\gamma}|\tilde{\rho}_a^{1/2}$"
# plot the background
self.axplot = BasePlot(
xlab=labelx,
ylab=labely,
figsizex=figx,
figsizey=figy,
y_min=ymin,
y_max=ymax,
x_min=xmin,
x_max=xmax,
ticksopt_x=ticksopt_x,
ticksopt_y=ticksopt_y,
)
self.axionDB = database
self.labelsDB = labels
# print(self.axionDB.get_rows())
# Plotting Data & Labels
self.PlotData(plottype, projections)
self.PlotLabels(projections)
if showplot:
self.axplot.ShowPlot()
if type(saveplotname) == str:
if len(saveplotname) > 0:
print("saving...")
self.axplot.SavePlot(saveplotname)
print("done")
def PlotData(self, plottype, projections=False):
print("projections = ", projections)
if plottype not in self.ListOfPlotTypes:
plottype = "wildType"
if "haloscopes" in plottype:
plottype = "haloscopes" # all haloscopes have the same column assigned ("haloscopes") in the database
data = self.axionDB.get_rows(f"{plottype}==1")
if projections:
data = data + self.axionDB.get_rows(
f"projection==1 AND {plottype}==0"
) # get projections not already included
for row in data:
pltItem = ExPltItem(row[0], row[1], row[2], **extract_kwargs(row[3]))
if "haloscopes" in plottype:
RenormItem(pltItem) # Its done in Haloscopes exclusively
pltItem.DrawItem(self.axplot)
def PlotLabels(self, projections=False):
labels = self.labelsDB.get_rows(f"onoff==1 AND projection==0")
if projections:
labels = labels + self.labelsDB.get_rows(f"onoff==1 AND projection==1")
for row in labels:
plt.text(row[1], row[2], row[0], **extract_kwargs(row[3]))
class AxionGaePlot:
ListOfPlotTypes = {} # No plottypes for Gae yet
def __init__(
self,
database: db.DataBaseGae,
labels: db.DataBaseLabels,
plottype="",
projections=False,
showplot=True,
saveplotname=None,
figx=6,
figy=5,
xmin=1.0e-4,
xmax=1.0,
ymin=1.0e-13,
ymax=1.0e-10,
labelfontsize=13,
labelx="$m_a$ (eV)",
labely=r"$|g_{ae}g_{a\gamma}|^{1/2}$ (GeV$^{-1/2}$)",
):
self.axplot = BasePlot(
xlab=labelx,
ylab=labely,
figsizex=figx,
figsizey=figy,
y_min=ymin,
y_max=ymax,
x_min=xmin,
x_max=xmax,
labelfontsize=labelfontsize,
)
self.axionDB = database
self.labelsDB = labels
# print(self.axionDB.get_rows())
self.PlotData(plottype, projections)
self.PlotLabels(projections)
if showplot:
self.axplot.ShowPlot()
if type(saveplotname) == str:
if len(saveplotname) > 0:
print("saving...")
self.axplot.SavePlot(saveplotname)
print("done")
def PlotData(self, plottype, projections=False):
print("projections = ", projections)
if plottype not in self.ListOfPlotTypes:
plottype = "wildType"
data = self.axionDB.get_rows(f"{plottype}==1")
if projections:
data = data + self.axionDB.get_rows(
f"projection==1 AND {plottype}==0"
) # get projections not already included
for row in data:
pltItem = ExPltItem(row[0], row[1], row[2], **extract_kwargs(row[3]))
pltItem.DrawItem(self.axplot)
def PlotLabels(self, projections=False):
labels = self.labelsDB.get_rows(f"onoff==1 AND projection==0")
if projections:
labels = labels + self.labelsDB.get_rows(f"onoff==1 AND projection==1")
for row in labels:
plt.text(row[1], row[2], row[0], **extract_kwargs(row[3]))