-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDataset.py
82 lines (71 loc) · 2.96 KB
/
Dataset.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
'''
Parent class for datasets
'''
from twisted.internet.defer import inlineCallbacks, returnValue, DeferredLock, Deferred
from PyQt4 import QtCore
from twisted.internet.threads import deferToThread
import numpy as np
class Dataset(QtCore.QObject):
def __init__(self, data_vault, context, dataset_location,reactor):
super(Dataset, self).__init__()
self.data = None
self.accessingData = DeferredLock()
self.reactor = reactor
self.dataset_location = dataset_location
self.data_vault = data_vault
self.updateCounter = 0
self.context = context
self.connectDataVault()
self.setupListeners()
@inlineCallbacks
def connectDataVault(self):
yield self.data_vault.cd(self.dataset_location[0], context = self.context)
path, dataset_name = yield self.data_vault.open(self.dataset_location[1], context = self.context)
self.dataset_name = dataset_name
@inlineCallbacks
def setupListeners(self):
yield self.data_vault.signal__data_available(11111, context = self.context)
yield self.data_vault.addListener(listener = self.updateData, source = None, ID = 11111, context = self.context)
@inlineCallbacks
def openDataset(self):
yield self.data_vault.cd(self.dataset_location[0], context = self.context)
yield self.data_vault.open(self.dataset_location[1], context = self.context)
@inlineCallbacks
def getParameters(self):
parameters = yield self.data_vault.parameters(context = self.context)
parameterValues = []
for parameter in parameters:
parameterValue = yield self.data_vault.get_parameter(parameter, context = self.context)
parameterValues.append( (parameter, parameterValue) )
returnValue(parameterValues)
def updateData(self,x,y):
self.updateCounter += 1
self.getData()
@inlineCallbacks
def getData(self):
Data = yield self.data_vault.get(100, context = self.context)
if (self.data is None):
yield self.accessingData.acquire()
try:
self.data = Data.asarray
except:
self.data = Data
self.accessingData.release()
else:
yield self.accessingData.acquire()
try:
self.data = np.append(self.data, Data.asarray, 0)
except:
self.data = np.append(self.data, Data, 0)
self.accessingData.release()
@inlineCallbacks
def getLabels(self):
labels = []
yield self.openDataset()
variables = yield self.data_vault.variables(context = self.context)
for i in range(len(variables[1])):
labels.append(variables[1][i][1] + ' - ' + self.dataset_name)
returnValue(labels)
@inlineCallbacks
def disconnectDataSignal(self):
yield self.data_vault.removeListener(listener = self.updateData, source = None, ID = 11111, context = self.context)