Skip to content

Commit 1cf3cf9

Browse files
authored
Link to plot web gui in summary, fix plot (#165)
1 parent 12d974b commit 1cf3cf9

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

iop4lib/iop4_night_summary.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
<title>iop4 summary {{night|date:"Y/m/d"}}</title>
44
</head>
55
<style>
6+
7+
* {
8+
box-sizing: border-box;
9+
}
10+
11+
body {
12+
font-size: 14px;
13+
}
14+
615
table {
716
border-collapse: collapse;
817
width: 100%;
@@ -27,6 +36,13 @@
2736
margin: 1em 0;
2837
}
2938

39+
img.source-plot {
40+
min-width: 45em;
41+
width: 49%;
42+
max-width: 49%;
43+
height: auto;
44+
}
45+
3046
</style>
3147
<body>
3248
<h1>IOP4 summary {{night|date:"Y/m/d"}}</h1>
@@ -102,10 +118,17 @@ <h2>Summary of results (band R only)</h2>
102118
</p>
103119
{% endif %}
104120

105-
<p>Some of these plots might include the previous existing night for the source for comparison.</p>
106-
107-
{% for srcname, imgb64 in results_summary_images.items %}
108-
<img src="data:image/png;base64,{{ imgb64 }}" alt="{{ srcname }}"/>
121+
<p>
122+
<small>
123+
Some of these plots might include the previous existing night for the source for comparison.
124+
Click on the plots to go to the interactive plot in the web interface.
125+
</small>
126+
</p>
127+
128+
{% for srcname, val in results_summary_images.items %}
129+
<a href="{{ val.source_plot_url}}">
130+
<img class="source-plot" src="data:image/png;base64,{{ val.imgb64 }}" alt="{{ srcname }}"/>
131+
</a>
109132
{% endfor %}
110133

111134
{% else %}

iop4lib/iop4_night_summary.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import matplotlib.pyplot as plt
3232
from astropy.time import Time
3333
import smtplib, email
34+
from urllib.parse import urlencode, quote_plus
3435

3536
# logging
3637
import coloredlogs, logging
@@ -91,17 +92,20 @@ def gather_context(args):
9192
.filter(astrosource=source, band="R", epoch__night__lt=args.date)
9293
.order_by('-epoch__night')
9394
.values_list('epoch__night', flat=True)
94-
.last())
95+
.first())
9596

96-
# get the results for this source from the previous night, or for this night if there is no previous night
97+
# Get the results for the source in the given night, but if there is only
98+
# one result, get the results from the previous night for comparison
9799

98-
if prev_night is not None:
99-
qs0 = PhotoPolResult.objects.filter(astrosource=source, band="R").filter(epoch__night__gte=args.date).order_by('-juliandate')
100+
qs_today = PhotoPolResult.objects.filter(astrosource=source, band="R").filter(epoch__night=args.date)
101+
102+
if prev_night is not None and qs_today.count() == 1:
103+
qs0 = PhotoPolResult.objects.filter(astrosource=source, band="R").filter(epoch__night__gte=prev_night, epoch__night__lte=args.date).order_by('-juliandate')
100104
else:
101-
qs0 = PhotoPolResult.objects.filter(astrosource=source, band="R").filter(epoch__night=args.date).order_by('-juliandate')
105+
qs0 = qs_today.order_by('-juliandate')
102106

103107

104-
fig = mplt.figure.Figure(figsize=(800/100, 600/100), dpi=100)
108+
fig = mplt.figure.Figure(figsize=(1000/100, 600/100), dpi=100)
105109
axs = fig.subplots(nrows=3, ncols=1, sharex=True, gridspec_kw={'hspace': 0.05})
106110

107111
for instrument, color in zip(instruments, colors):
@@ -118,6 +122,10 @@ def gather_context(args):
118122
axs[1].errorbar(x=vals['datetime'], y=vals['p'], yerr=vals['p_err'], marker=".", color=color, linestyle="none")
119123
axs[2].errorbar(x=vals['datetime'], y=vals['chi'], yerr=vals['chi_err'], marker=".", color=color, linestyle="none")
120124

125+
# x-axis date locator and formatter
126+
from matplotlib.dates import AutoDateLocator
127+
axs[-1].xaxis.set_major_locator(AutoDateLocator(interval_multiples=False, maxticks=7))
128+
121129
# invert magnitude axis
122130
axs[0].invert_yaxis()
123131

@@ -156,7 +164,24 @@ def gather_context(args):
156164
imgbytes = buf.read()
157165
imgb64 = base64.b64encode(imgbytes).decode("utf-8")
158166

159-
results_summary_images[source.name] = imgb64
167+
# build the link to the interactive source plot
168+
169+
url_args = dict()
170+
171+
url_args['srcname'] = source.name
172+
173+
if prev_night is not None:
174+
url_args['from'] = str(prev_night)
175+
176+
# we need 12:00 of the next day
177+
next_day_noon = (datetime.datetime.combine(args.date, datetime.time(12, 0)) + datetime.timedelta(days=1))
178+
url_args['to'] = str(next_day_noon)
179+
180+
source_plot_url = args.site_url + "/iop4/explore/plot/?" + urlencode(url_args, quote_via=quote_plus)
181+
182+
# save the results to the context
183+
184+
results_summary_images[source.name] = dict(imgb64=imgb64, source_plot_url=source_plot_url)
160185

161186
# save vars to context and return it
162187

0 commit comments

Comments
 (0)