-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelephant_data.py
More file actions
executable file
·88 lines (79 loc) · 3.25 KB
/
elephant_data.py
File metadata and controls
executable file
·88 lines (79 loc) · 3.25 KB
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
87
88
#!/usr/bin/env python
import time, json, os
import numpy as np
"""
These are several routines to handle the data output by the elephant GUI.
Max, August 2015
"""
# Could do something slicker here, maybe make a dictionary from the keys of
# each nested dictionary... but I'll leave that for another day.
class Data(object):
def __init__(self, pathToFile=None):
self.roll = []
self.pitch = []
self.countsA = []
self.countsB = []
self.gunVoltage = []
self.keithleyData = []
self.pressure = []
if pathToFile != None:
try:
f = open(pathToFile)
data = json.load(f)
for d in data:
self.roll.append(d['roll'])
self.pitch.append(d['pitch'])
self.countsA.append(d['countsA'])
self.countsB.append(d['countsB'])
self.gunVoltage.append(d['gunVoltage'])
self.keithley.append(d['keithley'])
self.pressure.append(d['pressure'])
self.countsA = np.array(self.countsA)
self.countsB = np.array(self.countsB)
except:
print("Data file not loaded, did you use the wrong path?")
def makeJSONFile(dataSet, i = None, fileName = None, matlab=False):
if fileName == None:
if i == None:
hour = time.localtime().tm_hour; mins = time.localtime().tm_min
month = time.localtime().tm_mon; day = time.localtime().tm_mday
year = time.localtime().tm_year
stamp = "%s-%s-%s-%s-%s" %(month, day, year, hour, mins)
pathToDataFolder = '/Users/elephant/Dropbox/Elephant Shared Folder/Data/'
path = pathToDataFolder+'dataFile('+stamp+').json'
else:
path = 'TempData/tempDataFile%s.json' %format(i, "04")
else:
path = fileName + '.json'
f = open(path, 'w')
json.dump(dataSet, f)
f.close()
# Combines all the JSON file made by makeJSONFile into one
# Note the order is based on the file name!
def combineJSONFiles(path = 'TempData/'):
allData = []
for file in os.listdir(path):
if file[-4:] == 'json':
allData.append(json.load(open(path+file)))
makeJSONFile(allData, matlab=False) # Set to true to make matlab file
# Remove all the file from the temporary folder
for file in os.listdir(path):
if file[-4:] == 'json':
os.remove(path+file)
def dataObjectToJSONFile(data, fileName=None):
dataset = []
for i, c in enumerate(data.countsA):
sweep = {}
sweep["roll"] = data.roll[i]
sweep["pitch"] = data.pitch[i]
sweep["countsA"] = list(c)
sweep["countsB"] = data.countsB[i]
sweep["gunVoltage"] = data.gunVoltage[i]
sweep["keithleyTime"] = data.keithleyTime[i]
sweep["keithleyVoltage"] = data.keithleyVoltage[i]
sweep["keithleyCurrent"] = data.keithleyCurrent[i]
sweep["keithleyResistance"] = data.keithleyResistance[i]
dataset.append(sweep)
if fileName == None:
fileName = "dataObject"
makeJSONFile(dataset, fileName=fileName) # Write data to file in case of crash