Skip to content

Commit 54d2b05

Browse files
authored
Improve web gui and night summary (#168)
- Fix bug in the web log viewer. - Add other source names to web gui list. - Add last night date next to last night mag in admin. - Fix time range of link to interactive plot in night summary. - Fix minor bugs related to web gui (filtering, table creation).
1 parent 32e25b4 commit 54d2b05

File tree

10 files changed

+55
-48
lines changed

10 files changed

+55
-48
lines changed

iop4admin/modeladmins/astrosource.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def get_last_reducedfit(self, obj):
5757

5858
@admin.display(description="LAST MAG")
5959
def get_last_mag_R(self, obj):
60-
mag_r_avg, mag_r_err_avg = obj.last_night_mag_R
60+
mag_r_avg, mag_r_err_avg, night = obj.last_night_mag_R
6161
if mag_r_avg is not None:
62-
return f"{mag_r_avg:.2f}"
62+
return f"{mag_r_avg:.2f} ± {mag_r_err_avg:.2f} ({night})"
6363
else:
6464
return None
6565

@@ -77,7 +77,7 @@ def get_urls(self):
7777

7878
@admin.display(description='T. Andor90')
7979
def get_texp_andor90(self, obj):
80-
last_night_mag_R, _ = obj.last_night_mag_R
80+
last_night_mag_R = obj.last_night_mag_R[0]
8181
texp = obj.texp_andor90
8282

8383
if last_night_mag_R is None:
@@ -90,7 +90,7 @@ def get_texp_andor90(self, obj):
9090

9191
@admin.display(description='T. Andor150')
9292
def get_texp_andor150(self, obj):
93-
last_night_mag_R, _ = obj.last_night_mag_R
93+
last_night_mag_R = obj.last_night_mag_R[0]
9494
texp = obj.texp_andor150
9595

9696
if last_night_mag_R is None:
@@ -103,7 +103,7 @@ def get_texp_andor150(self, obj):
103103

104104
@admin.display(description='T. x N DIPOL')
105105
def get_texp_dipol(self, obj):
106-
last_night_mag_R, _ = obj.last_night_mag_R
106+
last_night_mag_R = obj.last_night_mag_R[0]
107107
texp = obj.texp_dipol
108108
nreps = obj.nreps_dipol
109109

iop4api/static/iop4api/gui.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ Tabulator.extendModule("filter", "filters", {
105105

106106
function make_nice_table() {
107107

108+
var tables = Tabulator.findTable('#tableDiv');
109+
if (tables && tables.length > 0) {
110+
console.log("Destroying old table")
111+
tables[0].destroy();
112+
}
113+
108114
var table = new Tabulator("#tableDiv", {
109115
data: vueApp.$data.tableData.data,
110116
columns: vueApp.$data.tableData.tabulatorjs_coldefs,

iop4api/templates/iop4api/explore.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ <h1>Explore data &nbsp;<span class="material-symbols-outlined">&#xE8B6;</span></
1414
<div id="explore_container" class="tab-container">
1515

1616
<datalist id="source_name_list">
17-
{% for source_name in source_name_list %}
18-
<option value="{{ source_name }}">{{ source_name }}</option>
17+
{% for srcname, altname in source_name_list %}
18+
<option value="{{ srcname }}">
19+
{{ srcname }} {% if altname and srcname != altname %}&nbsp;&nbsp; ({{altname}}){% endif %}
20+
</option>
1921
{% endfor %}
2022
</datalist>
2123

iop4api/templates/iop4api/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ <h2><a href="https://vhega.iaa.es/">VHEGA@IAA-CSIC</a></h2>
305305

306306
if (value === '') { // if empty, null (works with = or != default filters)
307307
value = null;
308-
} else if (type != 'after') { // if values can be numbers, fix type
308+
} else if (type !== 'after' && type !== 'before') { // if values can be numbers, fix type
309309
if (!isNaN(value) && !isNaN(Number(value))) {
310310
value = Number(value);
311311
}

iop4api/views/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def data(request):
2525
source_name = request.POST.get("source_name", None)
2626

2727
if not AstroSource.objects.filter(name=source_name).exists():
28-
return HttpResponseBadRequest(f"Source '{source_name}' does not exist".format(source_name=source_name))
28+
return HttpResponseBadRequest(f"Source '{source_name}' does not exist")
2929

3030
qs = PhotoPolResult.objects.filter(astrosource__name=source_name)
3131

@@ -45,7 +45,7 @@ def data(request):
4545
}
4646
}
4747

48-
# annotate with date fromt the julian date
48+
# annotate with date from the julian date
4949
for r in result["data"]:
5050
r["date"] = Time(r["juliandate"], format='jd').iso
5151
result["columns"].append({"name": "date", "title": "date", "type": "date", "help": "date and time in ISO 8601 format, from the julian date"})

iop4api/views/index.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def index(request, tabs=None):
4747

4848
# if the user is logged, pass source names to the template
4949
if request.user.is_authenticated:
50-
context['source_name_list'] = AstroSource.objects.exclude(is_calibrator=True).values_list('name', flat="True")
50+
source_name_list = list(AstroSource.objects.exclude(is_calibrator=True).values_list('name','other_names'))
51+
source_name_list = [ (name, (other_names.split(';')[0].strip()) if other_names else '') for (name, other_names) in source_name_list]
52+
context['source_name_list'] = source_name_list
5153

5254
# add the hash of the current commit installed
5355
context['git_commit_hash'] = GIT_COMMIT_HASH

iop4api/views/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _log_file_generator():
2727
return _log_file_generator()
2828

2929
@staff_member_required
30-
@permission_required(["iop4api.view_photpolresult", "iop4api.view_astrosource"])
30+
@permission_required(["iop4api.view_photopolresult", "iop4api.view_astrosource"])
3131
def log(request):
3232
r"""Staff member required. Since the log file can be very large, we use a generator to stream it to the client."""
3333

iop4lib/db/astrosource.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# iop4lib imports
1010
from ..enums import *
11+
from iop4lib.utils import get_column_values
1112

1213
# other imports
1314
import os
@@ -18,6 +19,7 @@
1819
from astropy.coordinates import Angle, SkyCoord
1920
import astropy.units as u
2021
import math
22+
import numpy as np
2123

2224
# logging
2325
import logging
@@ -228,20 +230,29 @@ def last_reducedfit(self):
228230
def last_night_mag_R(self):
229231
"""Returns the average magnitude and error of the last night in the R band."""
230232

231-
last_night = self.photopolresults.filter(band=BANDS.R).earliest('-epoch__night').epoch.night
232-
r_avg = self.photopolresults.filter(band=BANDS.R, epoch__night=last_night).aggregate(mag_avg=Avg('mag'), mag_err_avg=Avg('mag_err'))
233+
qs = self.photopolresults.filter(band=BANDS.R).exclude(mag=None).exclude(mag_err=None)
233234

234-
mag_r_avg = r_avg.get('mag_avg', None)
235-
mag_r_err_avg = r_avg.get('mag_err_avg', None)
235+
if not qs:
236+
return None, None, None
237+
238+
last_night = qs.earliest('-epoch__night').epoch.night
239+
240+
qs = qs.filter(epoch__night=last_night)
241+
242+
vals = get_column_values(qs, ['mag', 'mag_err'])
243+
mag_r, mag_r_err = vals['mag'], vals['mag_err']
244+
245+
mag_r_avg = np.average(mag_r, weights=1/mag_r_err**2)
246+
mag_r_avg_err = 1/np.sqrt(np.sum(1/mag_r_err**2))
236247

237-
return mag_r_avg, mag_r_err_avg
248+
return mag_r_avg, mag_r_avg_err, last_night
238249

239250
@property
240251
def texp_andor90(self):
241-
"""Recommneded exposure time for Andor90, based on the last R magnitude and for a SNR of 150."""
252+
"""Recommended exposure time for Andor90, based on the last R magnitude and for a SNR of 150."""
242253

243254
snr = 150
244-
last_night_mag_R, _ = self.last_night_mag_R
255+
last_night_mag_R = self.last_night_mag_R[0]
245256

246257
if last_night_mag_R is None:
247258
return None
@@ -263,10 +274,10 @@ def texp_andor90(self):
263274

264275
@property
265276
def texp_andor150(self):
266-
"""Recommneded exposure time for Andor150, based on the last night R magnitude and for a SNR of 150."""
277+
"""Recommended exposure time for Andor150, based on the last night R magnitude and for a SNR of 150."""
267278

268279
snr = 150
269-
last_night_mag_R, _ = self.last_night_mag_R
280+
last_night_mag_R = self.last_night_mag_R[0]
270281

271282
if last_night_mag_R is None:
272283
return None
@@ -286,10 +297,10 @@ def texp_andor150(self):
286297

287298
@property
288299
def texp_dipol(self):
289-
"""Recommneded exposure time for DIPOL, based on the last night R magnitude and for a SNR of 150."""
300+
"""Recommended exposure time for DIPOL, based on the last night R magnitude and for a SNR of 150."""
290301

291302
snr = 150
292-
last_night_mag_R, _ = self.last_night_mag_R
303+
last_night_mag_R = self.last_night_mag_R[0]
293304

294305
if last_night_mag_R is None:
295306
return None
@@ -305,10 +316,10 @@ def texp_dipol(self):
305316

306317
@property
307318
def nreps_dipol(self):
308-
"""Recommneded number of repetitions for DIPOL, based on the last night R magnitude and for a SNR of 150."""
319+
"""Recommended number of repetitions for DIPOL, based on the last night R magnitude and for a SNR of 150."""
309320

310321
snr = 150
311-
last_night_mag_R, _ = self.last_night_mag_R
322+
last_night_mag_R = self.last_night_mag_R[0]
312323

313324
if last_night_mag_R is None:
314325
return None

iop4lib/db/fitfilemodel.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -307,23 +307,4 @@ def fscale_inv(y):
307307
f.write(imgbytes)
308308

309309
return imgbytes
310-
311-
312-
313-
314-
315-
316-
317-
""" # how it would be done without matplotlib
318-
imgdata = LogNorm(vmin=vmin, vmax=vmax)(imgdata)
319-
320-
imgdata = 256*imgdata
321-
imgdata = imgdata.astype(np.uint8)
322-
image = Image.fromarray(imgdata).resize((width,height))
323-
324-
325-
buf = io.BytesIO()
326-
image.save(buf, format='png')
327-
buf.seek(0)
328-
imgbytes = buf.read()
329-
"""
310+

iop4lib/iop4_night_summary.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ def gather_context(args):
6969
epoch.files_with_error_astrometry_href = args.site_url + "/iop4/admin/iop4api/reducedfit/?id__in=" + ",".join(epoch.files_with_error_astrometry_ids_str_L)
7070
# TODO: include IOP4Admin in Django configure and use reverse as in PhotoPolResult admin for line above
7171

72-
# get list of all sources for which there are results in this night
72+
# get list of all sources for which there are band R results in this night
7373

74-
sources = AstroSource.objects.exclude(is_calibrator=True).filter(photopolresults__epoch__night=args.date).distinct()
74+
sources = AstroSource.objects.exclude(is_calibrator=True).filter(
75+
photopolresults__epoch__night=args.date,
76+
photopolresults__band="R",
77+
).distinct()
7578

7679
# check if some of these sources lack calibrators
7780
sources_without_calibrators = [source for source in sources if not source.calibrators.exists()]
@@ -170,8 +173,10 @@ def gather_context(args):
170173

171174
url_args['srcname'] = source.name
172175

173-
if prev_night is not None:
176+
if prev_night is not None and qs_today.count() == 1:
174177
url_args['from'] = str(prev_night)
178+
else:
179+
url_args['from'] = (qs0.last().datetime - datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')
175180

176181
# we need 12:00 of the next day
177182
next_day_noon = (datetime.datetime.combine(args.date, datetime.time(12, 0)) + datetime.timedelta(days=1))

0 commit comments

Comments
 (0)