Skip to content

Commit

Permalink
update pylive | live_plotter
Browse files Browse the repository at this point in the history
  • Loading branch information
tongplw committed Jul 17, 2020
1 parent 920f874 commit 529e63f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
8 changes: 4 additions & 4 deletions dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from tqdm import tqdm
from src.muse import MuseMonitor
from src.pylive import plot_attention
from src.pylive import live_plot

if __name__ == "__main__":

Expand All @@ -18,13 +18,13 @@

for i in tqdm(range(len(df))):
waves = df.iloc[i].to_dict()
attention = headset._attention(waves)
attention = headset._attention(waves) * 100
atts += [attention]
meditation = headset._meditation(waves)
meditation = headset._meditation(waves) * 100
meds += [meditation]

# plt.hist(atts, bins=200)
# plt.hist(meds, bins=200, alpha=0.5)
plt.plot(atts)
plt.plot(meds, alpha=0.5)
plt.plot(meds)
plt.show()
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from datetime import datetime
from src.muse import MuseMonitor
from src.pylive import plot_attention
from src.pylive import live_plot


if __name__ == "__main__":
Expand All @@ -16,4 +16,5 @@
while True:
time.sleep(1)
attention = headset.attention.value
plot_attention(attention)
meditation = headset.meditation.value
live_plot(attention)
2 changes: 1 addition & 1 deletion src/muse.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _calibrate(self, key, val):

self._running_stats[key].update(val)
if self._running_stats[key].get_count() > 5:
val = (val - self._running_stats[key].get_mean()) / self._running_stats[key].get_std() * 0.25 + 0.5
val = (val - self._running_stats[key].get_mean()) / self._running_stats[key].get_std() * 0.23 + 0.5
return min(1, max(1e-5, val))

def _convert_to_mindwave(self, band, value):
Expand Down
22 changes: 13 additions & 9 deletions src/pylive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

size = 100
x_vec = np.linspace(0, 1, size + 1)[:-1]
y_vec = np.zeros(size)
line1 = []
y_vecs = []
lines = []

def live_plotter(x_vec, y1_data, line1, title='', pause_time=1e-2):
if line1 == []:
Expand All @@ -22,10 +22,14 @@ def live_plotter(x_vec, y1_data, line1, title='', pause_time=1e-2):
plt.pause(pause_time)
return line1

def plot_attention(att):
global x_vec, y_vec, line1
y_vec = np.append(y_vec[1:], att)
try:
line1 = live_plotter(x_vec, y_vec, line1)
except:
pass
def live_plot(*args):
global x_vec, y_vecs, lines, size
while len(y_vecs) < len(args):
y_vecs += [np.zeros(size)]
lines += [[]]
for i, v in enumerate(args):
y_vecs[i] = np.append(y_vecs[i][1:], v)
try:
lines[i] = live_plotter(x_vec, y_vecs[i], lines[i])
except:
pass

0 comments on commit 529e63f

Please sign in to comment.