|
| 1 | +"""Streamlit visualization script to display data acquired by nidaqmx_continuous_analog_input.py.""" |
| 2 | + |
| 3 | +import streamlit as st |
| 4 | +from streamlit_echarts import st_echarts |
| 5 | +from settings_enum import DigitalEdge, PauseWhen, Slopes, AnalogPause |
| 6 | +import time |
| 7 | +import nipanel |
| 8 | + |
| 9 | + |
| 10 | +st.set_page_config(page_title="Analog Input Filtering", page_icon="📈", layout="wide") |
| 11 | +st.title("Analog Input - Filtering") |
| 12 | + |
| 13 | +panel = nipanel.get_panel_accessor() |
| 14 | + |
| 15 | + |
| 16 | +tabs = st.tabs(["Voltage", "Current", "Strain Gage"]) |
| 17 | + |
| 18 | +st.markdown( |
| 19 | + """ |
| 20 | + <style> |
| 21 | + div[data-baseweb="select"] { |
| 22 | + width: 190px !important; /* Adjust the width as needed */ |
| 23 | + } |
| 24 | + </style> |
| 25 | + """, |
| 26 | + unsafe_allow_html=True, |
| 27 | +) |
| 28 | + |
| 29 | +streamlit_style = """ |
| 30 | + <style> |
| 31 | + iframe[title="streamlit_echarts.st_echarts"]{ height: 400px; width:75%;} |
| 32 | + </style> |
| 33 | + """ |
| 34 | +st.markdown(streamlit_style, unsafe_allow_html=True) |
| 35 | + |
| 36 | + |
| 37 | +source = panel.get_value("source", []) |
| 38 | +analog_source = panel.get_value("analog_source", []) |
| 39 | + |
| 40 | +voltage_data = panel.get_value("voltage_data", [0.0]) |
| 41 | +current_data = panel.get_value("current_data", [0.0]) |
| 42 | +strain_data = panel.get_value("strain_data", [0.0]) |
| 43 | + |
| 44 | +sample_rate = panel.get_value("sample_rate", 0.0) |
| 45 | + |
| 46 | +col_chart, settings = st.columns([1,1.5]) # Chart wider than buttons |
| 47 | +with settings: |
| 48 | + tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8 = st.tabs(["No Trigger","Digital Start","Digital Pause","Digital Reference","Analog Start","Analog Pause", "Analog Reference", "Time Start"]) |
| 49 | + with tab1: |
| 50 | + st.write("To enable triggers, select a tab above, and configure the settings. \n Not all hardware supports all trigger types. Refer to your device documentation for more information.") |
| 51 | + with tab2: |
| 52 | + nipanel.enum_selectbox( |
| 53 | + |
| 54 | + ) |
| 55 | + # st.selectbox("Source->", source) |
| 56 | + # edge_digital = st.selectbox( |
| 57 | + # "Edge", |
| 58 | + # options=[(e.name, e.value) for e in DigitalEdge], |
| 59 | + # format_func=lambda x: x[0], |
| 60 | + # index=0, |
| 61 | + # ) |
| 62 | + # edge_digital = DigitalEdge[edge_digital[0]] |
| 63 | + # panel.set_value("edge_digital", edge_digital) |
| 64 | + |
| 65 | + with tab3: |
| 66 | + st.selectbox("Source-", source) |
| 67 | + pause_when = st.selectbox( |
| 68 | + "Pause When", |
| 69 | + options=[(e.name, e.value) for e in PauseWhen], |
| 70 | + format_func=lambda x: x[0], |
| 71 | + index=0, |
| 72 | + ) |
| 73 | + pause_when = PauseWhen[pause_when[0]] |
| 74 | + panel.set_value("pause_when", pause_when) |
| 75 | + with tab4: |
| 76 | + st.write("This trigger type is not supported in continuous sample timing. Refer to your device documentation for more information on which triggers are supported") |
| 77 | + with tab5: |
| 78 | + st.selectbox("Source:", analog_source) |
| 79 | + slope = st.selectbox( |
| 80 | + "Slope", |
| 81 | + options=[(e.name, e.value) for e in Slopes], |
| 82 | + format_func=lambda x: x[0], |
| 83 | + index=0, |
| 84 | + ) |
| 85 | + slope = Slopes[slope[0]] |
| 86 | + panel.set_value("slope", slope) |
| 87 | + |
| 88 | + level = st.number_input("Level") |
| 89 | + panel.set_value("level", level) |
| 90 | + hysteriesis = st.number_input("Hysteriesis") |
| 91 | + panel.set_value("hysteriesis", hysteriesis) |
| 92 | + |
| 93 | + with tab6: |
| 94 | + st.selectbox("source:", analog_source) |
| 95 | + analog_pause = st.selectbox( |
| 96 | + "analog_pause", |
| 97 | + options=[(e.name, e.value) for e in AnalogPause], |
| 98 | + format_func=lambda x: x[0], |
| 99 | + index=0, |
| 100 | + ) |
| 101 | + analog_pause = AnalogPause[analog_pause[0]] |
| 102 | + panel.set_value("analog_pause", analog_pause) |
| 103 | + |
| 104 | + with tab7: |
| 105 | + st.write("This trigger type is not supported in continuous sample timing. Refer to your device documentation for more information on which triggers are supported.") |
| 106 | + with tab8: |
| 107 | + if st.button("Select time Manually"): |
| 108 | + time = st.time_input("When?") |
| 109 | + st.write(time) |
| 110 | + st.write("If time is not manually set, task will begin after 10 seconds") |
| 111 | + |
| 112 | + |
| 113 | +with tabs[0]: |
| 114 | + graph = { |
| 115 | + "animation": False, |
| 116 | + "tooltip": {"trigger": "axis"}, |
| 117 | + "legend": {"data": ["Voltage (V)"]}, |
| 118 | + "xAxis": { |
| 119 | + "type": "category", |
| 120 | + "data": [x / sample_rate for x in range(len(voltage_data))], |
| 121 | + "name": "Time", |
| 122 | + "nameLocation": "center", |
| 123 | + "nameGap": 40, |
| 124 | + }, |
| 125 | + "yAxis": { |
| 126 | + "type": "value", |
| 127 | + "name": "Measurement", |
| 128 | + "nameRotate": 90, |
| 129 | + "nameLocation": "center", |
| 130 | + "nameGap": 40, |
| 131 | + }, |
| 132 | + "series": [ |
| 133 | + { |
| 134 | + "name": "voltage_amplitude", |
| 135 | + "type": "line", |
| 136 | + "data": voltage_data, |
| 137 | + "emphasis": {"focus": "series"}, |
| 138 | + "smooth": True, |
| 139 | + "seriesLayoutBy": "row", |
| 140 | + }, |
| 141 | + ], |
| 142 | +} |
| 143 | + st_echarts(options=graph, height="400px", key="graph", width="50%") |
| 144 | +with tabs[1]: |
| 145 | + graph_2= { |
| 146 | + "animation": False, |
| 147 | + "tooltip": {"trigger": "axis"}, |
| 148 | + "legend": {"data": ["Voltage (V)"]}, |
| 149 | + "xAxis": { |
| 150 | + "type": "category", |
| 151 | + "data": [x / sample_rate for x in range(len(current_data))], |
| 152 | + "name": "Time", |
| 153 | + "nameLocation": "center", |
| 154 | + "nameGap": 40, |
| 155 | + }, |
| 156 | + "yAxis": { |
| 157 | + "type": "value", |
| 158 | + "name": "Measurement", |
| 159 | + "nameRotate": 90, |
| 160 | + "nameLocation": "center", |
| 161 | + "nameGap": 40, |
| 162 | + }, |
| 163 | + "series": [ |
| 164 | + { |
| 165 | + "name": "voltage_amplitude", |
| 166 | + "type": "line", |
| 167 | + "data": current_data, |
| 168 | + "emphasis": {"focus": "series"}, |
| 169 | + "smooth": True, |
| 170 | + "seriesLayoutBy": "row", |
| 171 | + }, |
| 172 | + ], |
| 173 | +} |
| 174 | + st_echarts(options=graph, height="400px", key="graph_2", width="50%") |
| 175 | + |
| 176 | +with tabs[2]: |
| 177 | + graph_3 = { |
| 178 | + "animation": False, |
| 179 | + "tooltip": {"trigger": "axis"}, |
| 180 | + "legend": {"data": ["Voltage (V)"]}, |
| 181 | + "xAxis": { |
| 182 | + "type": "category", |
| 183 | + "data": [x / sample_rate for x in range(len(strain_data))], |
| 184 | + "name": "Time", |
| 185 | + "nameLocation": "center", |
| 186 | + "nameGap": 40, |
| 187 | + }, |
| 188 | + "yAxis": { |
| 189 | + "type": "value", |
| 190 | + "name": "Measurement", |
| 191 | + "nameRotate": 90, |
| 192 | + "nameLocation": "center", |
| 193 | + "nameGap": 40, |
| 194 | + }, |
| 195 | + "series": [ |
| 196 | + { |
| 197 | + "name": "voltage_amplitude", |
| 198 | + "type": "line", |
| 199 | + "data": strain_data, |
| 200 | + "emphasis": {"focus": "series"}, |
| 201 | + "smooth": True, |
| 202 | + "seriesLayoutBy": "row", |
| 203 | + }, |
| 204 | + ], |
| 205 | +} |
| 206 | + st_echarts(options=graph_3, height="400px", key="graph_3", width="50%") |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
0 commit comments