-
Notifications
You must be signed in to change notification settings - Fork 0
/
mprReader.py
executable file
·40 lines (32 loc) · 1.03 KB
/
mprReader.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
import pandas as pd
from galvani.BioLogic import MPRfile
def sanitize_labels(label):
return label.split('/')[0].lower().lstrip('-').translate(dict.fromkeys(map(ord, " ,|()-"),'_')).rstrip('_')
def mprReader(filename, cycle=0):
# Import data using MPRfile and flatten
mpr = MPRfile(filename)
data = mpr.data
data.flatten()
# produce Pandas dataframe
x = []
for row in data:
x.append(list(row))
df = pd.DataFrame(x,columns=['Flags', 'time', 'control', 'Eve', 'I', 'cycle_number', '(Q-Q0)/C', 'I_Range', 'Ecv'])
df_reduced = df.loc[df['cycle_number'] == cycle]
return df_reduced
def mprReader_full(filename):
# Import data using MPRfile and flatten
"""
mpr = MPRfile(filename)
data = mpr.data
data.flatten()
# produce Pandas dataframe
x = []
for row in data:
x.append(list(row))
df = pd.DataFrame(x,columns=['Flags', 'time', 'control', 'Eve', 'I', 'cycle_number', '(Q-Q0)/C', 'I_Range', 'Ecv'])
"""
mpr = MPRfile(filename)
df = pd.DataFrame(mpr.data)
df.columns = [sanitize_labels(label) for label in df.columns]
return df