Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to new version #29

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions eit_dash/callbacks/load_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import plotly.graph_objects as go
from dash import ALL, Input, Output, State, callback, ctx, html
from dash.exceptions import PreventUpdate
from eitprocessing.continuous_data import ContinuousData
from eitprocessing.data_collection import DataCollection
from eitprocessing.eit_data import EITData
from eitprocessing.sequence import Sequence

Expand All @@ -26,12 +28,13 @@ def create_info_card(dataset: Sequence, file_type: int) -> dbc.Card:
file_type: Index of the selected type of selected
"""
info_data = {
"Name": dataset.eit_data.path.name,
"n_frames": dataset.eit_data.nframes,
"start_time": dataset.eit_data.time[0],
"end_time": dataset.eit_data.time[-1],
"vendor": dataset.eit_data.vendor,
"path": str(dataset.eit_data.path),
"Name": dataset.eit_data["raw"].path.name,
"n_frames": dataset.eit_data["raw"].nframes,
"start_time": dataset.eit_data["raw"].time[0],
"end_time": dataset.eit_data["raw"].time[-1],
"vendor": dataset.eit_data["raw"].vendor,
"continuous signals": str(list(dataset.continuous_data)),
"path": str(dataset.eit_data["raw"].path),
}

card_list = [
Expand Down Expand Up @@ -86,9 +89,9 @@ def load_selected_data(
int_type = int(file_type)

# check if the file extension is compatible with the file type selected
if (int_type == InputFiletypes.Draeger.value and extension == ".bin") or (
int_type == InputFiletypes.Timpel.value
and extension == ".txt"
if (
(int_type == InputFiletypes.Draeger.value and extension == ".bin")
or (int_type == InputFiletypes.Timpel.value and extension == ".txt")
or (int_type == InputFiletypes.Sentec.value and extension == ".zri")
):
read_data_flag = True
Expand Down Expand Up @@ -141,6 +144,7 @@ def open_data_selector(data, cancel_load, file_type):
eit_data=eit_data,
continuous_data=continuous_data,
sparse_data=sparse_data,
label="selected data",
)

options = get_signal_options(file_data)
Expand All @@ -158,6 +162,7 @@ def open_data_selector(data, cancel_load, file_type):
State(ids.INPUT_TYPE_SELECTOR, "value"),
State(ids.FILE_LENGTH_SLIDER, "relayoutData"),
State(ids.CHECKBOX_SIGNALS, "value"),
State(ids.CHECKBOX_SIGNALS, "options"),
prevent_initial_call=True,
)
def show_info(
Expand All @@ -167,23 +172,41 @@ def show_info(
filetype,
slidebar_stat,
selected_signals,
signals_options,
):
"""Creates the preview for preselecting part of the dataset."""
if file_data:
if slidebar_stat is not None and "xaxis.range" in slidebar_stat:
start_sample = slidebar_stat["xaxis.range"][0]
stop_sample = slidebar_stat["xaxis.range"][1]
else:
start_sample = file_data.eit_data.time[0]
stop_sample = file_data.eit_data.time[-1]
start_sample = file_data.eit_data["raw"].time[0]
stop_sample = file_data.eit_data["raw"].time[-1]

dataset_name = f"Dataset {data_object.get_list_length()}"

# TODO: adapt this to also continuous data
selected_signals = selected_signals or []
# get the name of the selected continuous signals
selected = [signals_options[s]["label"] for s in selected_signals]

# cut the eit data and the continuous data and add them to a new DataCollections

eit_data_cut = DataCollection(data_type=EITData)
continuous_data_cut = DataCollection(data_type=ContinuousData)

for data_type in (data := file_data.eit_data):
eit_data_cut.add(data[data_type].select_by_time(start_sample, stop_sample))

for data_type in (data := file_data.continuous_data):
# add just the selected signals
if data_type in selected:
continuous_data_cut.add(data[data_type].select_by_time(start_sample, stop_sample))

# add all the cut data to the new sequence
cut_data = Sequence(
label=dataset_name,
eit_data=file_data.eit_data.select_by_time(start_sample, stop_sample),
continuous_data=file_data.continuous_data,
eit_data=eit_data_cut,
continuous_data=continuous_data_cut,
)

# save the selected data in the singleton
Expand Down
41 changes: 11 additions & 30 deletions eit_dash/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import plotly.graph_objects as go

from eit_dash.definitions.option_lists import SignalSelections

if TYPE_CHECKING:
from eitprocessing.sequence import Sequence

Expand All @@ -26,30 +24,20 @@ def create_slider_figure(
continuous_data = []
if eit_variants is None:
eit_variants = ["raw"]
traces = []

for eit_variant in eit_variants:
# TODO: This is a patch! Needs to be changed
if eit_variant == "raw":
try:
impedance = dataset.eit_data.variants[eit_variant].global_impedance
except KeyError:
impedance = dataset.eit_data.variants[None].global_impedance
traces.append(
{
"x": dataset.eit_data.time,
"y": impedance,

traces = [{
"x": dataset.eit_data[eit_variant].time,
"y": dataset.eit_data[eit_variant].global_impedance,
"type": "scatter",
"mode": "lines",
"name": "a_level",
},
)
} for eit_variant in eit_variants]

for cont_signal in continuous_data:
traces.append( # noqa: PERF401
{
"x": dataset.continuous_data[cont_signal].time,
"y": dataset.continuous_data[cont_signal].variants["raw"].values, # noqa: PD011
"y": dataset.continuous_data[cont_signal].values, # noqa: PD011
"type": "scatter",
"mode": "lines",
"name": "a_level",
Expand All @@ -63,7 +51,8 @@ def create_slider_figure(
margin={"t": 0, "l": 0, "b": 0, "r": 0},
),
)
for event in dataset.eit_data.events:

for event in dataset.eit_data[eit_variants[0]].events:
annotation = {"text": f"{event.text}", "textangle": -90}
figure.add_vline(
x=event.time,
Expand All @@ -88,19 +77,11 @@ def get_signal_options(dataset: Sequence, show_eit: bool = False) -> list[dict[s
options = []
if show_eit:
# iterate over eit data
for variant in dataset.eit_data.variants:
# TODO: the None check is just a temporary fix.
# The select_by_index should be adjusted instead.

if variant == "raw" or variant is None:
label = SignalSelections.raw.name
value = SignalSelections.raw.value
else:
label = variant
value = max(len(SignalSelections), len(options) + 1)
options.append({"label": label, "value": value})
for eit in dataset.eit_data:
options.append({"label": eit, "value": len(options)})

if dataset.continuous_data:
# iterate over continuous data
for cont in dataset.continuous_data:
options.append({"label": cont, "value": len(options)})

Expand Down
Loading
Loading