-
Notifications
You must be signed in to change notification settings - Fork 4
/
plog.py
203 lines (161 loc) · 6.5 KB
/
plog.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
import sys
import os
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import hipercam as hcam
from hipercam import cline, utils
from hipercam.cline import Cline
##########################################
#
# plog -- simple plots of reduce log files
#
##########################################
def plog(args=None):
"""``plog log [device width height] ccd1 aper1 param1 ccd2 (aper2 param2
scheme) [title]``
Provides quick-look plots of HiPERCAM |reduce| logs.
Parameters:
log : string
name of |reduce| ASCII log file (text file with loads of columns)
device : string [hidden, defaults to 'term']
'term' for interactive plot, file name such as 'plot.pdf'
for a hardcopy.
width : float [hidden]
plot width (inches). Set = 0 to let the program choose.
height : float [hidden]
plot height (inches). Set = 0 to let the program choose. BOTH
width AND height must be non-zero to have any effect
ccd1 : str
first CCD to consider, e.g. '1'
aper1 : str
first aperture to consider
param1 : str
first parameter to consider. Choices are 'x' = X position,
'y' = Y position, 'f' = FWHM, 'b' = Moffat beta, 's' = sky.
ccd2 : str
second CCD to consider; '!' to ignore. Can be (and typically
would be) the same as ccd1.
aper2 : str [if ccd2 != '!']
second aperture to consider
param2 : str [if ccd2 != '!']
second parameter. See param1 for choices
scheme : str [if ccd2 != '!']
how to plot if both apertures are chosen. Choices:
| 'd' = difference, i.e. plot 1-2
| 'b' = both plotted on same panel
| 'r' = ratio, i.e. 1 / 2, good for relative photom
| 's' = scatter plot, 2 vs 1.
title : str [hidden]
plot title. Defaults to the run number if not specified
.. Note::
Points marked bad, or flagged as having bad times or junk are
ignored. i.e. bitmask = BAD_TIME | JUNK is passed to every
invocation of Tseries.mplot. Be careful with linked apertures
where all x, y, FWHM, beta automatically have negative errors
since they are not fitted. See |flagcloud| for how to flag up
junk data.
"""
command, args = utils.script_args(args)
# get input section
with Cline("HIPERCAM_ENV", ".hipercam", command, args) as cl:
# register parameters
cl.register("log", Cline.LOCAL, Cline.PROMPT)
cl.register("device", Cline.LOCAL, Cline.HIDE)
cl.register("width", Cline.LOCAL, Cline.HIDE)
cl.register("height", Cline.LOCAL, Cline.HIDE)
cl.register("ccd1", Cline.LOCAL, Cline.PROMPT)
cl.register("aper1", Cline.LOCAL, Cline.PROMPT)
cl.register("param1", Cline.LOCAL, Cline.PROMPT)
cl.register("ccd2", Cline.LOCAL, Cline.PROMPT)
cl.register("aper2", Cline.LOCAL, Cline.PROMPT)
cl.register("param2", Cline.LOCAL, Cline.PROMPT)
cl.register("scheme", Cline.LOCAL, Cline.PROMPT)
cl.register("title", Cline.LOCAL, Cline.HIDE)
# get inputs
log = cl.get_value(
"log", "reduce log file to plot", cline.Fname("hcam", hcam.LOG)
)
device = cl.get_value("device", "plot device name", "term")
width = cl.get_value("width", "plot width (inches)", 0.0)
height = cl.get_value("height", "plot height (inches)", 0.0)
ccd1 = cl.get_value("ccd1", "first CCD to plot", "1")
aper1 = cl.get_value("aper1", "first aperture", "1")
param1 = cl.get_value(
"param1",
"first parameter [x, y, f(whm), b(eta), c(ounts), s(ky)]",
"c",
lvals=("x", "y", "f", "b", "c", "s"),
)
lab1 = "[CCD={:s},ap={:s},p={:s}]".format(ccd1, aper1, param1)
ccd2 = cl.get_value("ccd2", "second CCD to plot ['!' to ignore]", ccd1)
if ccd2 != "!":
aper2 = cl.get_value("aper2", "second aperture", "1")
param2 = cl.get_value(
"param2",
"second parameter [x, y, f(whm), b(eta), c(ounts), s(ky)]",
"c",
lvals=("x", "y", "f", "b", "c", "s"),
)
lab2 = "[CCD={:s},ap={:s},p={:s}]".format(ccd2, aper2, param2)
# map to names used in reduce log files
MAP = {"x": "x", "y": "y", "f": "fwhm", "b": "beta", "c": "counts", "s": "sky"}
pname1 = MAP[param1]
if ccd2 != "!":
pname2 = MAP[param2]
scheme = cl.get_value(
"scheme",
"b(oth), d(ifference), r(atio), s(catter)",
"b",
lvals=("b", "d", "r", "s"),
)
cl.set_default("title", log)
title = cl.get_value("title", "plot title", "Plot Title")
# load the reduce log
hlog = hcam.hlog.Hlog.read(log)
if width > 0 and height > 0:
fig = plt.figure(figsize=(width, height))
else:
fig = plt.figure()
dat1 = hlog.tseries(ccd1, aper1, pname1)
if ccd2 != "!":
dat2 = hlog.tseries(ccd2, aper2, pname2)
if scheme == "b":
# plots both together
dat1.mplot(plt, "b", bitmask=hcam.BAD_TIME|hcam.JUNK)
dat2.mplot(plt, "r", bitmask=hcam.BAD_TIME|hcam.JUNK)
xlabel = "Time [MJD]"
ylabel = "{:s} & {:s}".format(lab1, lab2)
elif scheme == "r":
# ratio
ratio = dat1 / dat2
ratio.mplot(plt, "b", bitmask=hcam.BAD_TIME|hcam.JUNK)
xlabel = "Time [MJD]"
ylabel = "{:s} / {:s}".format(lab1, lab2)
elif scheme == "d":
# difference
diff = dat1 - dat2
diff.mplot(plt, "b", bitmask=hcam.BAD_TIME|hcam.JUNK)
xlabel = "Time [MJD]"
ylabel = "{:s} - {:s}".format(lab1, lab2)
elif scheme == "s":
mask1 = dat1.get_mask(bitmask=hcam.BAD_TIME|hcam.JUNK, invert=True)
mask2 = dat1.get_mask(bitmask=hcam.BAD_TIME|hcam.JUNK, invert=True)
ok = ~mask1 & ~mask2
plt.errorbar(
dat1.y[ok], dat2.y[ok], dat2.ye[ok], dat1.ye[ok], ".", capsize=0
)
xlabel = lab1
ylabel = lab2
else:
# just one
dat1.mplot(plt, bitmask=hcam.BAD_TIME|hcam.JUNK)
xlabel = "Time [MJD]"
ylabel = lab1
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.title(title)
if device == "term":
plt.show()
else:
plt.savefig(device)