Skip to content

Commit 5d9227d

Browse files
committed
add first version of focal plane visualization
1 parent 63dff2c commit 5d9227d

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed

browse/templates/browse/base_generic.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{% load static %}
2323
{% load active_link_tags %}
2424
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
25-
<a class="navbar-brand" href="#"><img class="img-fluid" src="{% static "browse/logo.png" %}" style="max-width: 6rem"></a>
25+
<a class="navbar-brand" href="#"><img class="img-fluid" src="{% static "browse/logo.svg" %}" style="max-width: 6rem"></a>
2626
<button class="navbar-toggler"
2727
type="button"
2828
data-toggle="collapse"
@@ -51,6 +51,11 @@
5151
Format specifications
5252
</a>
5353
</li>
54+
<li class="nav-item {% active_link 'focal-plane-ui-view' 'active' strict=True %}">
55+
<a class="nav-link" href="{% url 'focal-plane-ui-view' %}">
56+
Focal Plane
57+
</a>
58+
</li>
5459
</ul>
5560
</div>
5661

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{% extends "browse/base_generic.html" %} {% block title %}Focal Plane
2+
UI{%endblock %} {% block body %}
3+
<h1>Focal Plane UI</h1>
4+
<p>This page displays LiteBIRD Focal Plane interactive visualization tool.</p>
5+
6+
<div id="plotly-div"></div>
7+
8+
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
9+
10+
<body>
11+
<div id="myPlot" style="width: 100%; height: 100%"></div>
12+
13+
<script>
14+
document.addEventListener('DOMContentLoaded', function() {
15+
const xValues = {{ x_values|safe }};
16+
const yValues = {{ y_values|safe }};
17+
const uuids = {{ uuids|safe }};
18+
const channel = {{ channel|safe }};
19+
const size = {{ size|safe }};
20+
const pol = {{ pol|safe }};
21+
const colors = channel.map(val =>
22+
val.slice(0, 2) == "L1" ? 'blue' :
23+
val.slice(0, 2) == "L2" ? 'orange' :
24+
val.slice(0, 2) == "M1" ? 'red' :
25+
val.slice(0, 2) == "M2" ? 'black' :
26+
val.slice(0, 2) == "H1" ? 'purple' :
27+
val.slice(0, 2) == "H2" ? 'pink' :
28+
'gray'
29+
);
30+
const pols = pol.map(val =>
31+
val == 0 ? 'circle-cross':
32+
val == 90 ? 'circle-cross' :
33+
val == 45 ? 'circle-x' :
34+
val == 135 ? 'circle-x' :
35+
27
36+
);
37+
38+
39+
40+
const data = [
41+
{
42+
x: xValues,
43+
y: yValues,
44+
type: 'scatter',
45+
mode: 'markers',
46+
marker: { color: colors, symbol: pols, size: size},
47+
customdata: uuids,
48+
}
49+
];
50+
const layout = {
51+
xaxis: { title: 'X_sky' },
52+
yaxis: { title: 'Y_sky' },
53+
margin: { t: 8, b: 40, l: 40, r: 8 },
54+
autosize: true
55+
};
56+
57+
Plotly.newPlot('myPlot', data, layout);
58+
59+
const plotDiv = document.getElementById('myPlot');
60+
plotDiv.on('plotly_click', function(data) {
61+
62+
const point = data.points[0];
63+
if (point) {
64+
const this_uuid = point.customdata;
65+
66+
if (this_uuid) {
67+
const url = `http://127.0.0.1:8000/browse/data_files/${this_uuid}`;
68+
window.open(url, '_blank');
69+
}
70+
}
71+
});
72+
});
73+
</script>
74+
</body>
75+
{% endblock %}

browse/views.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from math import ceil
77
from pathlib import Path
88
from typing import List
9+
import numpy as np
910

1011
from django.contrib.auth import authenticate
1112
from django.contrib.auth.decorators import login_required
@@ -608,3 +609,47 @@ def login_request(request):
608609
},
609610
status=HTTP_200_OK,
610611
)
612+
613+
def focal_plane_ui_view(request):
614+
615+
metadatas = DataFile.objects.filter(name='detector_info').values_list('metadata', flat=True)
616+
uuids = DataFile.objects.filter(name='detector_info').values_list('uuid', flat=True)
617+
uuids = [str(uuid) for uuid in uuids]
618+
pointing_u_v_list = []
619+
channel=[]
620+
pol=[]
621+
ss= [150, 130, 85, 70, 40, 30]
622+
sizes=[]
623+
for metadata_str in metadatas:
624+
metadata_dict = json.loads(metadata_str)
625+
pointing_u_v = metadata_dict['pointing_u_v']
626+
pointing_u_v_list.append(pointing_u_v)
627+
channel.append(metadata_dict['channel'])
628+
pol.append(int(np.rad2deg(metadata_dict['pol_angle_rad'])))
629+
if metadata_dict['channel'][:2]=="L1":
630+
sizes.append(1000/ss[5])
631+
elif metadata_dict['channel'][:2]=="L2":
632+
sizes.append(1000/ss[4])
633+
elif metadata_dict['channel'][:2]=="M1":
634+
sizes.append(1000/ss[3])
635+
elif metadata_dict['channel'][:2]=="M2":
636+
sizes.append(1000/ss[2])
637+
elif metadata_dict['channel'][:2]=="H1":
638+
sizes.append(1000/ss[1])
639+
elif metadata_dict['channel'][:2]=="H2":
640+
sizes.append(1000/ss[0])
641+
642+
643+
x_values = [point[0] for point in pointing_u_v_list]
644+
y_values = [point[1] for point in pointing_u_v_list]
645+
646+
context = {
647+
'x_values': x_values,
648+
'y_values': y_values,
649+
'uuids': uuids,
650+
'channel': channel,
651+
'pol': pol,
652+
'size': sizes,
653+
}
654+
655+
return render(request, 'browse/focalplane_ui.html', context)

instrumentdb/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
ReleaseDownloadView,
4949
UserView,
5050
entity_reference_view,
51+
focal_plane_ui_view,
5152
)
5253

5354
################################################################################
@@ -115,6 +116,12 @@
115116
FormatSpecificationDownloadView.as_view(),
116117
name="format-spec-download-view",
117118
),
119+
path(
120+
"focalplane_ui/",
121+
focal_plane_ui_view,
122+
name="focal-plane-ui-view"
123+
),
124+
118125
re_path(
119126
r"^releases/(?P<rel_name>[\w.-]+)/(?P<reference>[\w./-]+)/$", api_release_view
120127
),

0 commit comments

Comments
 (0)