forked from faturita/python-scientific
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathholamundo.py
87 lines (60 loc) · 2.4 KB
/
holamundo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
==================
HolaMundo
==================
Python se puede correr desde 5 lugares
1- X Terminal, ejecutando los comandos con 'python programa.py'
2- X Terminal, de manera interactiva con 'python', 'import programa'
3- X Terminal, con 'ipython', 'run 'holamundo''
4- Jupyter Notebooks.
5- Google Collab (u otros cloud providers).
-------------------------------------------
Un Holamundo de Data Science tiene que tener,
¿ Cómo leer un archivo y cargar un dataset ?
¿ Cómo ploter la info para arrancar un análisis exploratorio ?
¿ Qué pueden hacer para tratar de practicar ?
1- Verifiquen que el campo counter en el archivo es consecutivo. Este campo está asociado
a la frecuencia de sampleo del dispositivo. Si todos los número están presentes entonces está ok.
2- Traten de identificar los picos.
"""
print(__doc__)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import requests
from io import StringIO
# Frecuencia de sampleo 128 Hz
print('Hello Python Scientific World')
print('Objetivo: leer tensores y poder plotear sus valores...')
online = False
if (online == True):
url = requests.get('https://drive.google.com/file/d/117pqjcY15qMGY0HlFaEz195_7uuq6LBv/view?usp=sharing')
csv_raw = StringIO(url.text)
signals = pd.read_csv(csv_raw, delimiter=' ', names = ['timestamp','counter','eeg','attention','meditation','blinking'])
signals = pd.read_csv('data/blinking.dat', delimiter=' ', names = ['timestamp','counter','eeg','attention','meditation','blinking'])
print('Estructura de la informacion:')
print(signals.head())
print('Filtrar segun informacion especifica:')
print(signals[signals.counter > 45])
data = signals.values
print('Ahora tienen un tensor de numpy (data)')
print (data)
print('Forma %2d,%2d:' % (signals.shape))
print('Python slicing...[:,]. El \':\' sirve para indicar el rango desde hasta. Los indices son posiciones segun la forma del tensor.')
eeg = data[:,2]
print(eeg)
# Ojo con el filtro OR.
filteredeeg = eeg[eeg>50]
eegfiltered = np.logical_or(eeg>10,eeg<-40)
plt.plot(eeg,'r', label='EEG')
plt.xlabel('t');
plt.ylabel('eeg(t)');
plt.title(r'EEG Signal') # r'' representa un raw string que no tiene caracteres especiales
plt.ylim([-2000, 2000]);
plt.xlim([0,len(eeg)])
plt.show()
import seaborn as sns
sns.set(style="darkgrid")
sns.lineplot(x="timestamp", y="eeg", hue="attention", data=signals)
import matplotlib.pyplot as plt
plt.show()