Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added export dataset(s) function to tracelistwidget #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GUIConfig.py
*.pyc
GUIConfig.py
*.pyc
110 changes: 55 additions & 55 deletions DataVaultListWidget.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
from PyQt4 import QtGui
from twisted.internet.defer import inlineCallbacks
import socket


class DataVaultList(QtGui.QWidget):

def __init__(self, tracename, parent=None):
super(DataVaultList, self).__init__()
self.tracename = tracename
self.connect()

@inlineCallbacks
def connect(self):
from labrad.wrappers import connectAsync
self.cxn = yield connectAsync(name=socket.gethostname() + ' Data Vault Client')
self.grapher = yield self.cxn.grapher
self.dv = yield self.cxn.data_vault
self.initializeGUI()

def initializeGUI(self):
mainLayout = QtGui.QVBoxLayout()
self.dataListWidget = QtGui.QListWidget()
self.dataListWidget.doubleClicked.connect(self.onDoubleclick)
mainLayout.addWidget(self.dataListWidget)
self.setWindowTitle('Data Vault')
self.setLayout(mainLayout)
self.populate()
self.show()

@inlineCallbacks
def populate(self):
self.dataListWidget.clear()
ls = yield self.dv.dir()
self.dataListWidget.addItem('...')
self.dataListWidget.addItems(sorted(ls[0]))
if ls[1] is not None:
self.dataListWidget.addItems(sorted(ls[1]))

@inlineCallbacks
def onDoubleclick(self, item):
item = self.dataListWidget.currentItem().text()
if item == '...':
yield self.dv.cd(1)
self.populate()
else:
try:
yield self.dv.cd(str(item))
self.populate()
except:
path = yield self.dv.cd()
yield self.grapher.plot((path, str(item)), self.tracename, False)

def closeEvent(self, event):
self.cxn.disconnect()
from PyQt5 import QtWidgets
from twisted.internet.defer import inlineCallbacks
import socket
class DataVaultList(QtWidgets.QWidget):
def __init__(self, tracename, parent=None):
super(DataVaultList, self).__init__()
self.tracename = tracename
self.connect()
@inlineCallbacks
def connect(self):
from labrad.wrappers import connectAsync
self.cxn = yield connectAsync(name=socket.gethostname() + ' Data Vault Client')
self.grapher = yield self.cxn.grapher
self.dv = yield self.cxn.data_vault
self.initializeGUI()
def initializeGUI(self):
mainLayout = QtWidgets.QVBoxLayout()
self.dataListWidget = QtWidgets.QListWidget()
self.dataListWidget.doubleClicked.connect(self.onDoubleclick)
mainLayout.addWidget(self.dataListWidget)
self.setWindowTitle('Data Vault')
self.setLayout(mainLayout)
self.populate()
self.show()
@inlineCallbacks
def populate(self):
self.dataListWidget.clear()
ls = yield self.dv.dir()
self.dataListWidget.addItem('...')
self.dataListWidget.addItems(sorted(ls[0]))
if ls[1] is not None:
self.dataListWidget.addItems(sorted(ls[1]))
@inlineCallbacks
def onDoubleclick(self, item):
item = self.dataListWidget.currentItem().text()
if item == '...':
yield self.dv.cd(1)
self.populate()
else:
try:
yield self.dv.cd(str(item))
self.populate()
except:
path = yield self.dv.cd()
yield self.grapher.plot((path, str(item)), self.tracename, False)
def closeEvent(self, event):
self.cxn.disconnect()
167 changes: 85 additions & 82 deletions Dataset.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,85 @@
'''
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)
'''
Parent class for datasets
'''
from twisted.internet.defer import inlineCallbacks, returnValue, DeferredLock, Deferred
from PyQt5 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()
_, all_dep = yield self.data_vault.variables(context = self.context)
for i in range(len(all_dep)):
label_tmp = all_dep[i][0] + ' - ' + self.dataset_name
if label_tmp in labels:
label_tmp += ' (' + str(i) + ')'
labels.append(label_tmp)
returnValue(labels)

@inlineCallbacks
def disconnectDataSignal(self):
yield self.data_vault.removeListener(listener = self.updateData, source = None, ID = 11111, context = self.context)
Loading