forked from soleti/larnd-display
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevd.py
executable file
·1097 lines (974 loc) · 38.2 KB
/
evd.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
Web-based event display for ArgonCube detectors
"""
import shutil
import atexit
from functools import lru_cache
from os.path import basename
from pathlib import Path
import fire
import h5py
import numpy as np
import dash_bootstrap_components as dbc
import dash_uploader as du
import dash_daq as daq
from dash import no_update
from dash import dcc
from dash import html
from dash.exceptions import PreventUpdate
from dash_extensions.enrich import Output, DashProxy, Input, State, MultiplexerTransform
import plotly.graph_objects as go
from plotly import subplots
from larnd_display.display_utils import (
DetectorGeometry,
plot_geometry,
plot_hits,
plot_light,
plot_tracks,
)
GEOMETRIES = {}
UPLOAD_FOLDER_ROOT = "cache"
DOCKER_MOUNTED_FOLDER = "/mnt/data/"
CORI_FOLDER = "https://portal.nersc.gov/project/dune/data/"
EVENT_BUFFER = 2000 # maximum difference in timeticks between hit and trigger
DEFAULT_COOLNESS_THRESHOLD = 20000 # minimum ADC sum for a "cool" event
app = DashProxy(
__name__,
prevent_initial_callbacks=True,
transforms=[MultiplexerTransform()],
external_stylesheets=[dbc.themes.BOOTSTRAP],
external_scripts=[
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML",
],
title="LArPix event display",
)
server = app.server
def draw_event(
filename,
geometry,
event_dividers,
light_dividers,
event_id,
do_plot_tracks,
do_plot_opids,
):
"""Draw 3D event display of event"""
with h5py.File(filename, "r") as datalog:
packets = datalog["packets"]
start_packet = event_dividers[event_id]
end_packet = event_dividers[event_id + 1]
last_trigger = packets[start_packet]["timestamp"]
event_packets = packets[start_packet:end_packet]
within_buffer = event_packets["timestamp"] - last_trigger < EVENT_BUFFER
event_packets = event_packets[within_buffer]
drawn_objects = plot_hits(geometry, event_packets, start_packet, last_trigger)
if (
do_plot_tracks
and "mc_packets_assn" in datalog.keys()
and "tracks" in datalog.keys()
):
tracks = datalog["tracks"]
mc_packets = datalog["mc_packets_assn"]
track_ids = np.unique(
mc_packets[start_packet:end_packet][within_buffer]["track_ids"]
)[1:]
if len(track_ids) > 0:
drawn_objects.extend(
plot_tracks(tracks, range(track_ids[0], track_ids[-1]), event_id)
)
drawn_objects.extend(plot_geometry(geometry))
if "light_trig" in datalog.keys() and do_plot_opids:
integrals = []
indeces = []
for light_index in range(
light_dividers[event_id], light_dividers[event_id + 1]
):
waveforms = datalog["light_wvfm"][light_index]
try:
indeces.append(datalog["light_trig"][light_index]["op_channel"])
integrals.append(np.sum(waveforms, axis=1))
except ValueError:
break
if integrals:
min_integral = min([min(i) for i in integrals])
for integral, index in zip(integrals, indeces):
drawn_objects.extend(
plot_light(geometry, integral, index, -min_integral)
)
return drawn_objects
@app.callback(
[
Output("event-display", "figure"),
Output("event-display", "style"),
Output("alert-geometry", "is_open"),
Output("alert-geometry", "children"),
Output("unique-url", "children"),
],
[
Input("event-id", "data"),
Input("filename", "data"),
Input("geometry-state", "data"),
Input("plot-tracks-state", "data"),
Input("plot-opids-state", "data"),
],
[
State("event-display", "figure"),
],
)
def update_output(
event_id,
filename,
geometry,
do_plot_tracks,
do_plot_opids,
figure,
):
"""Update 3D event display end event id"""
event_dividers, light_dividers = get_event_dividers(filename)
fig = go.Figure(figure)
if event_dividers is None:
return no_update, no_update, no_update, no_update, no_update
try:
fig.data = []
fig.add_traces(
draw_event(
filename,
GEOMETRIES[geometry],
event_dividers,
light_dividers,
event_id,
do_plot_tracks,
do_plot_opids,
)
)
except IndexError as err:
print("IndexError", err)
return fig, {"display": "none"}, True, no_update, no_update
except KeyError as err:
print("KeyError", err)
return fig, {"display": "none"}, True, "Select a geometry first", no_update
url_filename = filename.replace(DOCKER_MOUNTED_FOLDER, "")
return (
fig,
{"height": "85vh"},
False,
no_update,
f"https://larnddisplay.lbl.gov/{url_filename}?geom={geometry}#{event_id}",
)
@app.callback(Output("light-waveform", "style"), Input("event-id", "data"))
def reset_light(_):
"""Clean the light waveform plot when changing event"""
return {"display": "none"}
@app.callback(
[Output("light-waveform", "figure"), Output("light-waveform", "style")],
Input("event-display", "clickData"),
[
State("event-display", "figure"),
State("event-id", "data"),
State("filename", "data"),
],
)
def light_waveform(click_data, _, event_id, filename):
"""Plot the light waveform for the selected event on the clicked optical detector"""
_event_dividers, light_dividers = get_event_dividers(filename)
if (
click_data
and "id" in click_data["points"][0]
and "opid" in click_data["points"][0]["id"]
):
opid = int(click_data["points"][0]["id"].split("_")[1])
with h5py.File(filename, "r") as datalog:
if "light_wvfm" not in datalog.keys():
return go.Figure(), dict(display="none")
fig = go.Figure(
layout=dict(
title=f"Optical detector {opid}",
margin=dict(l=0, r=0, t=60),
showlegend=True,
template="plotly_white",
legend=dict(x=0.6, y=0),
font=dict(size=10),
),
)
for light_index in range(
light_dividers[event_id], light_dividers[event_id + 1]
):
try:
opid_index = np.argwhere(
datalog["light_trig"][light_index]["op_channel"] == opid
)
if len(opid_index) > 0:
opid_index = opid_index[0][0]
else:
continue
except ValueError:
opid_index = opid
except IndexError as err:
print(err, opid, datalog["light_trig"][light_index]["op_channel"])
fig.add_traces(
go.Scatter(
x=np.arange(0, 256),
y=datalog["light_wvfm"][light_index][opid_index],
name=f"Timestamp: {datalog['light_trig'][light_index]['ts_sync']}",
)
)
fig.update_xaxes(
title_text="Time [timestamp]",
linecolor="lightgray",
matches="x",
mirror=True,
ticks="outside",
showline=True,
)
fig.update_yaxes(
title_text="ADC counts",
linecolor="lightgray",
matches="y",
mirror=True,
ticks="outside",
showline=True,
)
return fig, dict(display="block", height="300px")
return no_update, no_update
@app.callback(
[
Output("object-information", "children"),
Output("time-histogram", "figure"),
Output("time-histogram", "style"),
],
[
Input("event-id", "data"),
Input("filename", "data"),
Input("geometry-detector", "value"),
],
)
def adc_histogram(event_id, filename, geometry):
"""Plot histogram of the adc counts for each drift volume"""
event_dividers, _light_dividers = get_event_dividers(filename)
if event_dividers is not None and geometry is not None:
start_packet = event_dividers[event_id]
end_packet = event_dividers[event_id + 1]
with h5py.File(filename, "r") as datalog:
packets = datalog["packets"]
event_packets = packets[start_packet:end_packet]
event_packets = event_packets[event_packets["packet_type"] == 0]
anodes = []
for io_group, io_channel in zip(
event_packets["io_group"], event_packets["io_channel"]
):
tile_id = GEOMETRIES[geometry].get_tile_id(io_group, io_channel)
if (
tile_id in GEOMETRIES[geometry].tile_map[0][0]
or tile_id in GEOMETRIES[geometry].tile_map[0][1]
):
anodes.append(0)
else:
anodes.append(1)
anodes = np.array(anodes)
n_modules = GEOMETRIES[geometry].module_to_io_groups.keys()
start_t = packets[start_packet]["timestamp"]
active_modules = []
for module_id in n_modules:
query = ((event_packets["io_group"]) + 1) // 2 == module_id
if len(event_packets[query]) == 0:
continue
active_modules.append(module_id)
histos = None
if active_modules:
histos = subplots.make_subplots(
rows=len(active_modules),
cols=2,
subplot_titles=[
"(%i,%i)" % (m, p + 1) for m in active_modules for p in range(2)
],
vertical_spacing=0.25 / len(active_modules)
if len(active_modules) > 0
else 0,
shared_xaxes=True,
shared_yaxes=True,
)
for im, module_id in enumerate(active_modules):
query = (event_packets["io_group"] + 1) // 2 == module_id
histo1 = go.Histogram(
x=event_packets["timestamp"][(anodes == 0) & query] - start_t,
xbins=dict(start=0, end=3200, size=20),
)
histo2 = go.Histogram(
x=event_packets["timestamp"][(anodes == 1) & query] - start_t,
xbins=dict(start=0, end=3200, size=20),
)
if histos:
histos.append_trace(histo1, im + 1, 1)
histos.append_trace(histo2, im + 1, 2)
if histos:
histos.update_annotations(font_size=12)
histos.update_layout(
margin=dict(l=0, r=0, t=50, b=60),
showlegend=False,
template="plotly_white",
title_text="ADC histograms",
)
histos.update_xaxes(
title_text="Time [timestamp]", row=len(active_modules)
)
histos.update_xaxes(
linecolor="lightgray",
matches="x",
mirror=True,
ticks="outside",
showline=True,
)
histos.update_yaxes(
linecolor="lightgray",
matches="y",
mirror=True,
ticks="outside",
showline=True,
)
subplots_height = "%fvh" % (len(active_modules) * 22 + 5)
return "", histos, dict(height=subplots_height, display="block")
return no_update, no_update, no_update
@app.callback(
Output("filename-text", "children"),
Input("filename", "modified_timestamp"),
State("filename", "data"),
)
def update_filename(modified_timestamp, filename):
"""Update the filename text"""
if modified_timestamp is None:
raise PreventUpdate
if filename:
filename = html.Span(
children=[
html.Span("File: ", style={"font-weight": "bold"}),
html.Span(basename(filename), style={"font-family": "monospace"}),
]
)
else:
filename = "No file selected"
return filename
@app.callback(
Output("total-events", "children"),
Input("filename", "modified_timestamp"),
Input("filename", "data")
)
def update_total_events(modified_timestamp, filename):
"""Update the total number of events text"""
event_dividers, _light_dividers = get_event_dividers(filename)
if modified_timestamp is None:
raise PreventUpdate
if len(event_dividers) < 2:
total_events = 0
else:
total_events = len(event_dividers) - 2
return f"/ {total_events}"
@app.callback(
[
Input("input-evid", "value"),
],
[
Output("event-id", "data"),
Output("input-evid", "value"),
],
[
State("filename", "data")
]
)
def update_event_id_click(input_evid, filename):
try:
event_id = int(input_evid)
except TypeError:
return no_update, no_update
event_dividers, _light_dividers = get_event_dividers(filename)
if event_dividers is not None:
if event_id >= len(event_dividers) - 1:
event_id = len(event_dividers) - 2
if event_id < 0:
event_id = 0
return event_id, event_id
else:
return no_update, no_update
@app.callback(
Output("input-evid", "value"),
Input("event-id", "modified_timestamp"),
State("event-id", "data"),
)
def update_event_id(modified_timestamp, event_id):
"""Update the event id input box with the current event id"""
if modified_timestamp is None:
raise PreventUpdate
try:
return int(event_id)
except TypeError:
raise PreventUpdate
def is_cool_event(packets, threshold):
# HACK: threshold doesn't get initialized if it hasn't been changed by the user
# there must be a way to force the state to get initialized
if threshold is None:
threshold = DEFAULT_COOLNESS_THRESHOLD
data_packets = packets[packets['packet_type'] == 0]
total_adc = sum(data_packets['dataword'])
return total_adc > threshold
def find_cool_event(event_id, filename, threshold, direction):
event_dividers, _light_dividers = get_event_dividers(filename)
if event_dividers is not None:
with h5py.File(filename, "r") as datalog:
packets = datalog["packets"]
start = event_id + direction
end = -1 if direction == -1 else len(event_dividers) - 1
for maybe_id in range(start, end, direction):
start_packet = event_dividers[maybe_id]
end_packet = event_dividers[maybe_id + 1]
if is_cool_event(packets[start_packet:end_packet], threshold):
return maybe_id
return no_update
@app.callback(
Output("input-evid", "value"),
Input("prev-cool", "n_clicks"),
State("event-id", "data"),
State("filename", "data"),
State("coolness-threshold", "data")
)
def prev_cool_click(_n_clicks, event_id, filename, threshold):
return find_cool_event(event_id, filename, threshold, -1)
@app.callback(
Output("input-evid", "value"),
Input("next-cool", "n_clicks"),
State("event-id", "data"),
State("filename", "data"),
State("coolness-threshold", "data")
)
def next_cool_click(_n_clicks, event_id, filename, threshold):
return find_cool_event(event_id, filename, threshold, 1)
@app.callback(
Output("input-evid", "value"),
Input("prev-event", "n_clicks"),
State("event-id", "data"),
State("filename", "data")
)
def prev_event(_n_clicks, event_id, filename):
return find_cool_event(event_id, filename, 0, -1)
@app.callback(
Output("input-evid", "value"),
Input("next-event", "n_clicks"),
State("event-id", "data"),
State("filename", "data")
)
def next_event(_n_clicks, event_id, filename):
return find_cool_event(event_id, filename, 0, 1)
@app.callback(
Output("coolness-threshold", "data"),
Input("input-coolness-threshold", "value")
)
def update_coolness_threshold(threshold):
return threshold
@app.callback(
Output("geometry-detector", "value"),
Input("geometry-state", "modified_timestamp"),
State("geometry-state", "data"),
)
def update_geometry(modified_timestamp, detector_geometry):
"""Update the event id input box with the current event id"""
if modified_timestamp is None:
raise PreventUpdate
try:
return detector_geometry
except TypeError:
raise PreventUpdate
@app.callback(
[
Output("filename", "data"),
Output("event-id", "data"),
Output("alert-file-not-found", "is_open"),
Output("alert-file-not-found", "children"),
],
Input("server-filename", "value"),
[
State("event-id", "data"),
State("filepath", "children"),
],
)
def select_file(input_filename, event_id, filepath):
filepath_message = filepath
if event_id is None:
event_id = 0
try:
try:
if filepath["props"]["children"] == CORI_FOLDER:
load_filepath = DOCKER_MOUNTED_FOLDER
filepath_message = CORI_FOLDER
except TypeError:
load_filepath = filepath
if len(input_filename) > 0 and input_filename[0] == "/":
input_filename = input_filename[1:]
if input_filename.startswith(CORI_FOLDER):
input_filename = input_filename[len(CORI_FOLDER):]
h5_file = Path(load_filepath) / input_filename
datalog = h5py.File(h5_file, "r")
except FileNotFoundError:
print(h5_file, "not found")
return (
no_update,
event_id,
True,
f"File {filepath_message}{input_filename} not found",
)
except IsADirectoryError:
return no_update, no_update, no_update, event_id, False, ""
except OSError as err:
print(h5_file, "invalid file", err)
return (
no_update,
event_id,
True,
f"File {filepath_message}{input_filename} is not a valid file",
)
try:
packets = datalog["packets"]
except KeyError:
return no_update, event_id, True, f"No packets dataset in {filepath_message}{input_filename}"
return str(h5_file), 0, False, no_update
@lru_cache(maxsize=64)
def get_event_dividers(path: str):
with h5py.File(path) as datalog:
packets = datalog["packets"]
trigger_mask = packets["packet_type"] == 7
if trigger_mask.any():
if "light_trig" in datalog.keys():
ts, il, ic = np.intersect1d(
datalog["light_trig"]["ts_sync"],
packets[trigger_mask]["timestamp"],
return_indices=True,
)
ic = np.indices(datalog["packets"].shape)[0][trigger_mask][ic]
i_sort = np.argsort(il)
il = il[i_sort]
ic = ic[i_sort]
ts = ts[i_sort]
merge_mask = np.diff(ts.astype(int)) > 200
il = il[np.r_[True, merge_mask]]
ic = ic[np.r_[True, merge_mask]]
ic = np.append(ic, len(packets))
il = np.append(il, len(datalog["light_trig"]))
else:
trigger_packets = np.nonzero(trigger_mask)[0]
ic = trigger_packets[:-1][np.diff(trigger_packets) != 1]
ic = np.append(ic, [trigger_packets[-1], len(packets)])
il = np.array([])
return ic, il
@app.callback(
[
Output("filename", "data"),
Output("event-id", "data"),
Output("server-filename", "value"),
],
Input("select-file", "isCompleted"),
[
State("filename", "data"),
State("select-file", "fileNames"),
State("select-file", "upload_id"),
],
)
def upload_file(is_completed, filename, filenames, upload_id):
"""Upload HDF5 file to cache"""
if not is_completed:
return filename, event_dividers, 0
if filenames is not None:
if upload_id:
root_folder = Path(UPLOAD_FOLDER_ROOT) / upload_id
else:
root_folder = Path(UPLOAD_FOLDER_ROOT)
h5_file = root_folder / filenames[0]
datalog = h5py.File(h5_file, "r")
packets = datalog["packets"]
trigger_packets = np.argwhere(packets["packet_type"] == 7).T[0]
# event_dividers = trigger_packets[:-1][np.diff(trigger_packets) != 1]
# event_dividers = np.append(event_dividers, [trigger_packets[-1], len(packets)])
return str(h5_file), 0, ""
return filename, 0, ""
@app.callback(
Output("geometry-state", "data"),
Input("geometry-detector", "value"),
)
def update_geometry_state(geometry_detector):
return geometry_detector
@app.callback(Output("plot-tracks-state", "data"), Input("plot-tracks", "on"))
def set_plot_true_tracks(on):
return on
@app.callback(Output("plot-opids-state", "data"), Input("plot-opids", "on"))
def set_plot_opids(on):
return on
@app.callback(
[
Output("server-filename", "value"),
Output("event-id", "data"),
Output("geometry-state", "data"),
],
[Input("url", "pathname"), Input("url", "hash"), Input("url", "search")],
)
def display_page(pathname, this_hash, search):
if pathname[1:] and "?geom=" in search:
if this_hash:
try:
event_id = int(this_hash[1:])
except ValueError:
event_id = 0
else:
event_id = 0
geom = search.split("?geom=")[1]
return pathname[1:], event_id, geom
return no_update, no_update, no_update
def run_display(larndsim_dir, host="127.0.0.1", port=5000, filepath="."):
"""Create layout and run Dash app"""
global GEOMETRIES
if filepath[-1] != "/":
filepath += "/"
module0_detector_properties = (
larndsim_dir + "/larndsim/detector_properties/module0.yaml"
)
twobytwo_detector_properties = (
larndsim_dir + "/larndsim/detector_properties/2x2.yaml"
)
tile44_layout = (
larndsim_dir + "/larndsim/pixel_layouts/multi_tile_layout-2.3.16.yaml"
)
GEOMETRIES["Module-0"] = DetectorGeometry(
module0_detector_properties, tile44_layout
)
GEOMETRIES["2x2"] = DetectorGeometry(twobytwo_detector_properties, tile44_layout)
fig = go.Figure()
camera = dict(
eye=dict(x=-2, y=0.3, z=1.1),
center=dict(x=0, y=0, z=-0.2),
)
fig.update_layout(
scene_camera=camera,
uirevision=True,
margin=dict(l=0, r=0, t=4),
legend={"x": 0},
scene=dict(
xaxis=dict(
backgroundcolor="white",
showspikes=False,
showgrid=False,
title="x [mm]",
),
yaxis=dict(
backgroundcolor="white",
showgrid=False,
showspikes=False,
title="z [mm]",
),
zaxis=dict(
backgroundcolor="white",
showgrid=False,
showspikes=False,
title="y [mm]",
),
),
)
app.layout = dbc.Container(
fluid=True,
style={
"padding": "1.5em",
"padding-top": "0",
"background-image": "url('%s')" % app.get_asset_url("logo.png"),
"background-size": "74px 54px",
"background-position": "right 1em top 1em",
"background-repeat": "no-repeat",
},
children=[
dcc.Location(id="url"),
dcc.Store(id="filename", storage_type="session"),
dcc.Store(id="event-id", storage_type="session"),
dcc.Store(id="geometry-state", storage_type="session"),
dcc.Store(id="coolness-threshold", storage_type="session"),
dcc.Store(id="plot-tracks-state", storage_type="session", data=False),
dcc.Store(id="plot-opids-state", storage_type="session", data=False),
html.Div(id="unique-url", style={"display": "none"}),
html.P(id="test"),
html.H1(children="ArgonCube event display", style={"font-size": "x-large"}),
dbc.Row(
[
dbc.Col(
[
du.Upload(
id="select-file",
text="Drag and drop or click here to upload",
max_file_size=10000,
chunk_size=0.5,
default_style={
"width": "15em",
"padding": "0",
"margin": "0",
},
pause_button=True,
filetypes=["h5"],
),
],
width=2,
),
dbc.Col(
[
html.P(
children=["Or specify existing file path here:"],
style={"margin": "0"},
),
html.P(
children=html.A(href=filepath, children=filepath,
target="_blank")
if "https" in filepath
else filepath,
id="filepath",
style={
"display": "inline-block",
"font-family": "monospace",
"font-size": "small",
"margin": "0 0 0.2em 0",
},
),
dcc.Input(
id="server-filename",
type="text",
style={
"font-family": "monospace",
"font-size": "small",
"margin": "0 0 0.2em 0",
},
placeholder="enter file path (or whole URL)...",
size=38,
debounce=True,
),
html.P(
children=[
html.Span(
"Detector geometry: ",
style={"vertical-align": "0.6em"},
),
dcc.Dropdown(
id="geometry-detector",
options=[
{"label": x, "value": x}
for x in ["Module-0", "2x2"]
],
value="Module-0",
style={
"width": "10em",
"display": "inline-block",
"height": "2.5em",
},
),
],
style={"margin": "0"},
),
html.P(
children=[
"Copy unique URL to clipboard ",
dcc.Clipboard(
target_id="unique-url",
title="copy",
style={
"display": "inline-block",
"fontSize": 20,
"verticalAlign": "top",
},
),
],
style={"margin": "0"},
),
dbc.Alert(
children=["File not found"],
id="alert-file-not-found",
is_open=False,
duration=4000,
color="warning",
),
dbc.Alert(
"Error loading the file with this detector geometry",
id="alert-geometry",
duration=4000,
is_open=False,
color="danger",
),
],
width=6,
),
dbc.Col(
[
html.P(
children="",
id="filename-text",
style={"margin": "0"},
),
html.P(
children="Event: ",
style={
"display": "inline-block",
"font-weight": "bold",
},
),
dcc.Input(
id="input-evid",
type="number",
placeholder="0",
debounce=True,
style={
"width": "6em",
"display": "inline-block",
"margin-right": "0.5em",
"margin-left": "0.5em",
},
),
html.Div(
id="total-events",
style={
"padding-right": "1em",
"display": "inline-block",
"text-align": "center",
},
),
dbc.Button("Prev", id="prev-event",
outline=True, color="primary", size="sm",
style={"display": "inline-block",
"margin-right": "0.5em"}),
dbc.Button("Next", id="next-event",
outline=True, color="primary", size="sm",
style={"display": "inline-block"}),
dbc.Row(
[
dbc.Col(
[
html.P(
children=[
"Plot true tracks ",
daq.BooleanSwitch(
id="plot-tracks",
on=False,
style={"display": "inline-block"},
),
],
style={"margin": "0"},
),
html.P(
children=[
"Plot optical detectors ",
daq.BooleanSwitch(
id="plot-opids",
on=False,
style={"display": "inline-block"},
),
],
style={"margin": "0"},
),
]
),
dbc.Col(
[
html.P(
children=[html.Span(children="Cool event min ADC sum: "),
dcc.Input(id="input-coolness-threshold",
type="number", value=DEFAULT_COOLNESS_THRESHOLD,
debounce=True,
style={"display": "inline-block",
"width": "7em"})]
),
html.P(
children=[
dbc.Button("Prev cool event", id="prev-cool",
outline=True, color="primary", size="sm",
style={"display": "inline-block",
"margin-right": "1em"}),
dbc.Button("Next cool event", id="next-cool",