Skip to content

Commit bd79724

Browse files
Fix 209 eeg signals appears flat in the dashboard (lina-usc#219)
* Fix issue lina-usc#119 * Improving example plot_10 * Fix issue lina-usc#209. * Fix CSS error.
1 parent 0ae96c6 commit bd79724

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

examples/plot_10_run_pipeline.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
In this notebook, we will run the pyLossless pipeline on a publicly available dataset.
77
"""
88

9+
# %%
10+
# Installation (in the terminal or through Jupyter)
11+
# -------
12+
#!pip install -q pylossless
13+
#!pip install -q openneuro-py
14+
15+
916
# %%
1017
# Imports
1118
# -------
@@ -14,7 +21,12 @@
1421
import pylossless as ll
1522

1623
# %%
17-
# Get the data
24+
# Get the data.
25+
#
26+
# Note: If you are testing this examples in Google Colab, the
27+
# openneuro-py download function does not always work flawlessly. You may have
28+
# to run this cell twice for the files to be properly downloaded and usable by
29+
# the next cell.
1830
# ------------
1931
raw, config, bids_path = ll.datasets.load_openneuro_bids()
2032

pylossless/dash/css_defaults.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
DEFAULT_LAYOUT_XAXIS = {
2020
"zeroline": False,
2121
"showgrid": True,
22-
"title": "time (seconds)",
22+
"title": {"text": "time (seconds)", "font": {"color": "#ADB5BD"}},
2323
"gridcolor": "white",
2424
"fixedrange": True,
2525
"showline": True,
26-
"titlefont": dict(color="#ADB5BD"),
2726
"tickfont": dict(color="#ADB5BD"),
2827
"automargin": True,
2928
}
@@ -35,7 +34,7 @@
3534
"autorange": False, # 'reversed',
3635
"scaleratio": 0.5,
3736
"tickmode": "array",
38-
"titlefont": dict(color="#ADB5BD"),
37+
"title": {"font": {"color": "#ADB5BD"}},
3938
"tickfont": dict(color="#ADB5BD"),
4039
"fixedrange": True,
4140
"automargin": True,

pylossless/dash/mne_visualizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ def inst(self, inst):
215215
)
216216
if self.scalings_arg == "auto":
217217
for kind in np.unique(self.inst.get_channel_types()):
218-
self.scalings[kind] = np.percentile(self.inst.get_data(), 99.5)
218+
data = self.inst.get_data(picks=kind)
219+
self.scalings[kind] = np.percentile(data, 99.5)
219220
else:
220221
self.scalings.update(self.scalings_arg)
221222

pylossless/dash/qcannotations.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ def __init__(self, onset, duration, description_str, layout):
3535
self._duration = duration
3636
self._description = description_str
3737

38-
self._dash_layout = layout
3938
self._dash_shape = dict(
40-
name=self.id,
39+
name=self._id,
4140
type="rect",
4241
xref="x",
4342
yref="y",
4443
x0=self.onset,
45-
y0=self._dash_layout.yaxis["range"][0],
44+
y0=layout.yaxis["range"][0],
4645
x1=self.onset + self.duration,
47-
y1=self._dash_layout.yaxis["range"][1],
46+
y1=layout.yaxis["range"][1],
4847
fillcolor="red",
4948
opacity=0.25 if self.duration else 0.75,
5049
line_width=1,
@@ -53,13 +52,20 @@ def __init__(self, onset, duration, description_str, layout):
5352
)
5453
self._dash_description = dict(
5554
x=self.onset + self.duration / 2,
56-
y=self._dash_layout.yaxis["range"][1],
55+
y=layout.yaxis["range"][1],
5756
text=self.description,
5857
showarrow=False,
5958
yshift=10,
6059
font={"color": "#F1F1F1"},
6160
)
6261

62+
def to_dict(self):
63+
"""Return a dict representation of the EEGAnnotation object."""
64+
return {"_id": self._id, "_onset": self._onset,
65+
"_duration": self._duration, "_description": self._description,
66+
"_dash_description": self._dash_description,
67+
"_dash_shape": self._dash_shape}
68+
6369
def update_dash_objects(self):
6470
"""Update plotly shape/annotations.
6571
@@ -174,6 +180,14 @@ def __init__(self, annotations=None):
174180
else:
175181
self.annotations = pd.Series()
176182

183+
def to_plotly_json(self):
184+
"""Return a dict representation of the EEGAnnotation object.
185+
186+
Implementing this function is necessary for Plotly/Dash to serialize
187+
EEGAnnotationList objects.
188+
"""
189+
return {key: value.to_dict() for key, value in self.annotations.items()}
190+
177191
def __get_series(self, attr):
178192
return pd.Series(
179193
{annot.id: getattr(annot, attr) for annot in self.annotations.values}

0 commit comments

Comments
 (0)