-
Notifications
You must be signed in to change notification settings - Fork 5
/
extractors.py
38 lines (27 loc) · 1.15 KB
/
extractors.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
import os.path
import numpy as np
from igor.binarywave import load as loadibw
import util
def ibw2dict(filename):
"""Extract the contents of an *ibw to a dict"""
data = loadibw(filename)
wave = data['wave']
# Get the labels and tidy them up into a list
labels = list(map(bytes.decode,
util.flatten(wave['labels'])))
# Get the notes and process them into a dict
notes = util.process_notes(wave['note'])
# Get the data numpy array and convert to a simple list
wData = np.nan_to_num(wave['wData']).tolist()
# Get the filename from the file - warn if it differs
fname = wave['wave_header']['bname'].decode()
input_fname = os.path.splitext(os.path.basename(filename))[0]
if input_fname != fname:
print("Warning: stored filename differs from input file name")
print("Input filename: {}".format(input_fname))
print("Stored filename: {}".format(str(fname) + " (.ibw)"))
return {"filename": fname, "labels": labels, "notes": notes, "data": wData}
def ibw2stdout(filename):
'''Dump the contents of an *.ibw to stdout'''
data = loadibw(filename)
util.pprint(data)