-
Notifications
You must be signed in to change notification settings - Fork 0
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
037 implement eeli wbaccinelli #42
Merged
Merged
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c0e0505
create analyze page
wbaccinelli a338691
refactored to use eit as continuous data
wbaccinelli cd0936f
create analyze page
wbaccinelli 73a7df0
refactored to use eit as continuous data
wbaccinelli 2869ac2
Merge branch '037_implement_eeli_wbaccinelli' of https://github.com/E…
wbaccinelli fd78ecc
small changes
wbaccinelli d53379f
summary cards
wbaccinelli b1f9ae1
adding graph container
wbaccinelli 6d17aaf
create analyze page
wbaccinelli 5380fc6
refactored to use eit as continuous data
wbaccinelli 3f42db5
small changes
wbaccinelli 3dd6494
summary cards
wbaccinelli 67141d8
adding graph container
wbaccinelli 6ff3456
Merge branch '037_implement_eeli_wbaccinelli' of https://github.com/E…
wbaccinelli 1aa4bff
saving derived from and running eeli
wbaccinelli 9369cc3
saving derived from and running eeli
wbaccinelli 00cb323
plotting results
wbaccinelli 43fbaf2
updating data loaded cards
wbaccinelli d051015
Merge branch 'main' into 037_implement_eeli_wbaccinelli
wbaccinelli 4a5d9fe
linting
wbaccinelli 98a0616
linting
wbaccinelli 8dd20c6
pointing to the eeli branch
wbaccinelli 9ee669d
formatting
wbaccinelli 96eae5b
fixing filter
wbaccinelli 8f8fe41
fixing filtered label
wbaccinelli 242c242
updating the manual
wbaccinelli 7cc0717
Update docs/user_manual.md
wbaccinelli 84cf4fd
adding note to manual
wbaccinelli c28463e
Merge branch '037_implement_eeli_wbaccinelli' of https://github.com/E…
wbaccinelli 3c0b3a7
using available data
wbaccinelli d758b17
linting
wbaccinelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import plotly.graph_objects as go | ||
from dash import Input, Output, State, callback, ctx | ||
from eitprocessing.parameters.eeli import EELI | ||
|
||
import eit_dash.definitions.element_ids as ids | ||
import eit_dash.definitions.layout_styles as styles | ||
from eit_dash.app import data_object | ||
from eit_dash.definitions.constants import FILTERED_EIT_LABEL | ||
from eit_dash.utils.common import ( | ||
create_filter_results_card, | ||
create_info_card, | ||
create_selected_period_card, | ||
) | ||
|
||
eeli = [] | ||
|
||
|
||
@callback( | ||
Output(ids.SUMMARY_COLUMN_ANALYZE, "children", allow_duplicate=True), | ||
Output(ids.ANALYZE_SELECT_PERIOD_VIEW, "options"), | ||
[ | ||
Input(ids.ANALYZE_RESULTS_TITLE, "children"), | ||
], | ||
[ | ||
State(ids.SUMMARY_COLUMN_ANALYZE, "children"), | ||
], | ||
# this allows duplicate outputs with initial call | ||
prevent_initial_call="initial_duplicate", | ||
) | ||
def page_setup(_, summary): | ||
"""Setups the page elements when it starts up. | ||
|
||
When the page is loaded, it populates the summary column | ||
with the info about the loaded datasets and the preprocessing steps. | ||
Populates the periods selections element with the loaded periods. | ||
""" | ||
trigger = ctx.triggered_id | ||
options = [] | ||
|
||
if trigger is None: | ||
for d in data_object.get_all_sequences(): | ||
card = create_info_card(d) | ||
summary += [card] | ||
|
||
filter_params = {} | ||
|
||
for period in data_object.get_all_stable_periods(): | ||
if not filter_params: | ||
filter_params = ( | ||
period.get_data() | ||
.continuous_data.data[FILTERED_EIT_LABEL] | ||
.parameters | ||
) | ||
|
||
summary += [ | ||
create_selected_period_card( | ||
period.get_data(), | ||
period.get_dataset_index(), | ||
period.get_period_index(), | ||
False, | ||
), | ||
] | ||
|
||
# populate period selection | ||
options.append( | ||
{ | ||
"label": f"Period {period.get_period_index()}", | ||
"value": period.get_period_index(), | ||
}, | ||
) | ||
|
||
summary += [create_filter_results_card(filter_params)] | ||
|
||
return summary, options | ||
|
||
|
||
@callback( | ||
Output(ids.EELI_RESULTS_GRAPH_DIV, "hidden"), | ||
Input(ids.EELI_APPLY, "n_clicks"), | ||
prevent_initial_call=True, | ||
) | ||
def apply_eeli(_): | ||
"""Apply EELI and store results.""" | ||
global eeli # noqa: PLW0602 | ||
|
||
eeli.clear() | ||
|
||
periods = data_object.get_all_stable_periods() | ||
|
||
for period in periods: | ||
sequence = period.get_data() | ||
eeli_result_filtered = EELI().compute_parameter(sequence, FILTERED_EIT_LABEL) | ||
|
||
# TODO: the results should be stored in the sequence object | ||
eeli_result_filtered["index"] = period.get_period_index() | ||
|
||
eeli.append(eeli_result_filtered) | ||
|
||
return False | ||
|
||
|
||
@callback( | ||
[ | ||
Output(ids.EELI_RESULTS_GRAPH, "figure"), | ||
Output(ids.EELI_RESULTS_GRAPH, "style"), | ||
], | ||
Input(ids.ANALYZE_SELECT_PERIOD_VIEW, "value"), | ||
prevent_initial_call=True, | ||
) | ||
def show_eeli(selected): | ||
"""Show the results of the EELI for the selected period.""" | ||
figure = go.Figure() | ||
|
||
sequence = data_object.get_stable_period(int(selected)).get_data() | ||
for e in eeli: | ||
if e["index"] == int(selected): | ||
result = e | ||
|
||
figure.add_trace( | ||
go.Scatter( | ||
x=sequence.continuous_data[FILTERED_EIT_LABEL].time, | ||
y=sequence.continuous_data[FILTERED_EIT_LABEL].values, | ||
name=FILTERED_EIT_LABEL, | ||
), | ||
) | ||
|
||
figure.add_hline(y=result["mean"], line_color="red", name="Mean") | ||
figure.add_hline(y=result["median"], line_color="red", name="Median") | ||
|
||
figure.add_scatter( | ||
x=sequence.continuous_data[FILTERED_EIT_LABEL].time[result["indices"]], | ||
y=result["values"], | ||
line_color="black", | ||
name="EELIs", | ||
mode="markers", | ||
) | ||
|
||
sd_upper = result["mean"] + result["standard deviation"] | ||
sd_lower = result["mean"] - result["standard deviation"] | ||
|
||
figure.add_trace( | ||
go.Scatter( | ||
x=sequence.continuous_data[FILTERED_EIT_LABEL].time, | ||
y=[sd_upper] * len(sequence.continuous_data[FILTERED_EIT_LABEL].time), | ||
fill=None, | ||
mode="lines", | ||
line_color="rgba(0,0,255,0)", # Set to transparent blue | ||
name="Standard deviation", | ||
), | ||
) | ||
|
||
# Add the lower bound line | ||
figure.add_trace( | ||
go.Scatter( | ||
x=sequence.continuous_data[FILTERED_EIT_LABEL].time, | ||
y=[sd_lower] * len(sequence.continuous_data[FILTERED_EIT_LABEL].time), | ||
fill="tonexty", # Fill area below this line | ||
mode="lines", | ||
line_color="rgba(0,0,255,0.3)", # Set to semi-transparent blue | ||
name="Standard deviation", | ||
), | ||
) | ||
|
||
return figure, styles.GRAPH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a note at the very top asking people to open issues if they encounter anything?