-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_live.py
88 lines (76 loc) · 2.71 KB
/
app_live.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
import os
import dash_mantine_components as dmc
import numpy as np
from dash import Dash, html
from dash_extensions import WebSocket
from tiled.client import from_uri
from callbacks.streamed_reduction import *
# from components.scan_summary import layout
# Initialize the Dash app
app = Dash(
__name__,
requests_pathname_prefix="/reduction_viewer/",
)
app.title = "Live View"
application = app.server
# Initialize the Tiled server
TILED_URI = os.getenv("TILED_URI")
TILED_API_KEY = os.getenv("TILED_API_KEY")
# TILED_EXPERIMENT_URI = "http://127.0.0.1:8888/api/v1/metadata/processed/NaCl_1_10_2"
TILED_EXPERIMENT_URI = (
"http://127.0.0.1:8888/api/v1/metadata/processed/Autonomous/NaCl_1_10_C"
)
def extract_full_scan(experiment_uri):
client = from_uri(experiment_uri, api_key=TILED_API_KEY)
num_keys = len(client.keys())
x_data = np.zeros(num_keys)
y_data = np.zeros(num_keys)
feature_data = np.zeros(num_keys)
reduction_uris = [None] * num_keys
feature_name = "max_intensity"
# feature_name = "max_intensity"
# feature_name = "area_under_curve"
counter = 0
for scan_key in client.keys():
scan_client = client[scan_key]
if counter >= num_keys:
break
for reduction_key in scan_client:
if "integration-azimuthal" in reduction_key:
reduction_client = scan_client[reduction_key]
reduction_metadata = reduction_client.metadata
reduction_uris[counter] = reduction_client.uri
# Get feature from the meta data
feature = reduction_metadata[feature_name]
feature_data[counter] = feature
# Get motor positions from the input_uri
input_metadata = from_uri(reduction_metadata["input_uri"]).metadata
x = input_metadata["Sample X Stage"]
y = input_metadata["Sample Y Stage"]
x_data[counter] = x
y_data[counter] = y
counter = counter + 1
app.layout = dmc.MantineProvider(
theme={"colorScheme": "light"},
children=[
dmc.Grid(
# grow=True,
children=[
dmc.Col(
html.Div(
children=[
dmc.Text(id="reduction_update_message"),
WebSocket(
id="ws-reduction-update",
url="ws://127.0.0.1:5001/ws/reduction_update",
),
]
),
span=6,
),
],
),
],
)
if __name__ == "__main__":
app.run(debug=True, host="127.0.0.1", port="8075")