def prompt(self, dir): '''Called when button is pushed''' root = os.environ['DATA_CHEST_ROOT'] # dir = QtGui.QFileDialog.getOpenFileName(None, "Open Data Set...", # root, "Data Chest Files (*.hdf5)") dir = str(dir) # Get rid of the file namse, use just the path # print "before dir:", dir path = dir.split("/")[0:-1] filename = dir.split("/")[-1] dir = '/'.join(path) # print "selected dir:", dir root = root.replace('\\', '/') # print "datachest root:", root dir = dir.replace(root, '') dir = dir.replace('/', '\\') relpath = dir.split('\\') # print "relative path:", dir # print "current chest directory:", chest.pwd() chest = dataChest(relpath[1]) chest.cd("") if len(relpath) > 2: chest.cd(relpath[2::]) # print "current chest directory:", chest.pwd() chest.openDataset(filename) # print "opened dataset:", chest self.getFrame().setDataSet(chest) self.grapher.deleteLater() self.grapher = MGrapher(self, title=filename) self.BHBox.addWidget(self.grapher) self.grapher.show()
def __init__(self, device): '''Initiallize the dataChest''' # Define the current time now = datetime.datetime.now() # Create a devices reference that can be accessed # outside of this scope. self.device = device # These arrays will hold all dataChest data sets. self.dataSet = None self.hasData = None # The done function must be called when the GUI exits atexit.register(self.done) # The datalogging is executed on its own thread # self.deviceThread = threading.Thread(target = # self.save, args=[]) # # If the main thread stops, stop the child thread # self.deviceThread.daemon = True # # Start the thread # self.deviceThread.start() # for i in range(0, len(self.devices)): # Append a new dataChest object to the end # of the datasets array. Note, no dataset is being created. self.dataSet = dataChest(str( now.year)) self.hasData = False
from dataChest import * import numpy as np import time d1 = dataChest(["dataCorruption2"]) #1D Arbitrary Data (Option 1 Style) #Random Number Generator print "1D Arbitrary Data (Option 1 Style):" #Most inneficient style by far numPoints = 1e6 print "\tNumber of Points =", numPoints d1.createDataset("Histogram1by1", [("indepName1", [1], "float64", "Seconds")], [("depName1", [1], "float64", "Volts")]) d1.addParameter("X Label", "Time") d1.addParameter("Y Label", "Digitizer Noise") d1.addParameter("Plot Title", "Random Number Generator") for ii in range(0, int(numPoints)): d1.addData([[float(ii),1.0]]) time.sleep(1.0)
def __init__(self, parent = None): super(Main, self).__init__(parent) self.setWindowTitle('Data Chest Image Browser') # Add in Rabi plot. self.setWindowIcon(QtGui.QIcon('rabi.jpg')) self.root = os.environ["DATA_CHEST_ROOT"] self.pathRoot=QtCore.QString(self.root) self.filters =QtCore.QStringList() self.filters.append("*.hdf5") self.dataChest = dataChest(None, True) # Directory browser configuration. self.model = QtGui.QFileSystemModel(self) self.model.setRootPath(self.pathRoot) self.model.setNameFilterDisables(False) self.model.nameFilterDisables() self.model.setNameFilters(self.filters) self.indexRoot = self.model.index(self.model.rootPath()) self.directoryBrowserLabel = QtGui.QLabel(self) self.directoryBrowserLabel.setText("Directory Browser:") self.directoryTree = QtGui.QTreeView(self) self.directoryTree.setModel(self.model) self.directoryTree.setRootIndex(self.indexRoot) self.directoryTree.header().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.directoryTree.header().setStretchLastSection(False) self.directoryTree.clicked.connect(self.dirTreeSelectionMade) # Plot types drop down list configuration. self.plotTypesComboBoxLabel = QtGui.QLabel(self) self.plotTypesComboBoxLabel.setText("Available Plot Types:") self.plotTypesComboBox = QtGui.QComboBox(self) self.plotTypesComboBox.activated[str].connect(self.plotTypeSelected) # Configure scrolling widget. self.scrollWidget = QtGui.QWidget(self) self.scrollLayout = QtGui.QHBoxLayout(self) self.scrollWidget.setLayout(self.scrollLayout) self.scrollArea = QtGui.QScrollArea(self) self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.scrollArea.setWidget(self.scrollWidget) self.scrollArea.setWidgetResizable(True) # What happens without? vbox = QtGui.QVBoxLayout() vbox.addWidget(self.directoryBrowserLabel) vbox.addWidget(self.directoryTree) vbox.addWidget(self.plotTypesComboBoxLabel) vbox.addWidget(self.plotTypesComboBox) vbox.addWidget(self.scrollArea) self.mplwindow =QtGui.QWidget(self) self.mplvl = QtGui.QVBoxLayout(self.mplwindow) hbox = QtGui.QHBoxLayout() hbox.addLayout(vbox) hbox.addWidget(self.mplwindow) self.setLayout(hbox) self.currentFig = Figure() self.addFigureToCanvas(self.currentFig) self.filePath = None # redundant self.fileName = None # redundant self.plotType = None # redundant self.varsToIgnore = []
from dataChest import * import numpy as np import time #create array of dataChest objects for data corruption tests dataChestObjArray = [] numObjs = 100 for objIndex in range(0,numObjs): dataChestObjArray.append(dataChest(["dataCorruptionTest"])) d = dataChestObjArray[objIndex] d.createDataset("AllOnes", [("indepName1", [1], "float64", "s")], [("depName1", [1], "float64", "V")]) d.addParameter("X Label", "Time") d.addParameter("Y Label", "All Ones") d.addParameter("Plot Title", "Is Dataset Corrupted") numWrites = 12*60*60 # vary if you like for ii in range(0, numWrites): #will take about ~13 hours since it takes finite time to write to all 100 files for objIndex in range(0,numObjs): d = dataChestObjArray[objIndex] d.addData([[float(ii),1.0]]) time.sleep(1.0) print ii #Check for corrupted files for objIndex in range(0,numObjs): d = dataChestObjArray[objIndex] name = d.getDatasetName() data = d.getData() if len(data) != numWrites: print "Invalid length for dataset with name=", name else:
def __init__(self, parent=None): super(Main, self).__init__(parent) self.setWindowTitle('Data Chest Image Browser') # Add in Rabi plot. self.setWindowIcon(QtGui.QIcon('rabi.jpg')) self.root = os.environ["DATA_ROOT"] if "\\" in self.root: self.root = self.root.replace("\\", '/') self.pathRoot = QtCore.QString(self.root) self.filters = QtCore.QStringList() self.filters.append("*.hdf5") self.dataChest = dataChest("", self.root) self.local_tz = tz.tzlocal() self.utc = tz.gettz('UTC') # Directory browser configuration. self.model = QtGui.QFileSystemModel(self) self.model.setRootPath(QtCore.QString(self.root)) self.model.setNameFilterDisables(False) self.model.nameFilterDisables() self.model.setNameFilters(self.filters) self.indexRoot = self.model.index(self.model.rootPath()) self.directoryBrowserLabel = QtGui.QLabel(self) self.directoryBrowserLabel.setText("Directory Browser:") self.directoryTree = QtGui.QTreeView(self) self.directoryTree.setModel(self.model) self.directoryTree.setRootIndex(self.indexRoot) self.directoryTree.header().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.directoryTree.header().setStretchLastSection(False) self.directoryTree.clicked.connect(self.dirTreeSelectionMade) # Plot types drop down list configuration. self.plotTypesComboBoxLabel = QtGui.QLabel(self) self.plotTypesComboBoxLabel.setText("Available Plot Types:") self.plotTypesComboBox = QtGui.QComboBox(self) self.plotTypesComboBox.activated[str].connect(self.plotTypeSelected) # Configure scrolling widget. self.scrollWidget = QtGui.QWidget(self) self.scrollLayout = QtGui.QHBoxLayout(self) self.scrollWidget.setLayout(self.scrollLayout) self.scrollArea = QtGui.QScrollArea(self) self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.scrollArea.setHorizontalScrollBarPolicy( QtCore.Qt.ScrollBarAsNeeded) self.scrollArea.setWidget(self.scrollWidget) self.scrollArea.setWidgetResizable(True) # What happens without? vbox = QtGui.QVBoxLayout() vbox.addWidget(self.directoryBrowserLabel) vbox.addWidget(self.directoryTree) vbox.addWidget(self.plotTypesComboBoxLabel) vbox.addWidget(self.plotTypesComboBox) vbox.addWidget(self.scrollArea) self.mplwindow = QtGui.QWidget(self) self.mplvl = QtGui.QVBoxLayout(self.mplwindow) hbox = QtGui.QHBoxLayout() hbox.addLayout(vbox) hbox.addWidget(self.mplwindow) self.setLayout(hbox) self.currentFig = Figure() self.addFigureToCanvas(self.currentFig) self.filePath = None # redundant self.fileName = None # redundant self.plotType = None # redundant self.varsToIgnore = []
def configureDataSets(self, **kwargs): """ Initialize the datalogger, if datasets already exist, use them. Otherwise create new ones. """ now = dt.datetime.now() # Force creation of new dataset? force_new = kwargs.get('force_new', False) self.hasData = True # Generate a title for the dataset. NOTE: if # the title of the device is changed in the device's constructor # in the main class, then a different data set will be created. # This is because datasets are stored using the name of # the device, which is what the program looks for when checking # if there are data files that already exist. title = str(self.device.getFrame().DataLoggingInfo()['name']).replace( " ", "_") # Datasets are stored in the folder 'DATA_CHEST_ROOT\year\month\' # Try to access the current month's folder, if it does not # exist, make it. location = self.device.getFrame().DataLoggingInfo()['location'] # print "Location1:", location # root = os.environ['DATA_CHEST_ROOT'] # relativePath = os.path.relpath(root, dir) # print "Configuring datalogging for", str(self.device)+" located at", # location if location != None: root = os.environ['DATA_CHEST_ROOT'] root = root.replace("/", "\\") relativePath = os.path.relpath(location, root) #print "relativePath:", relativePath #if relativePath == '.': # raise IOError( # "Cannot create dataset directly under DATA_CHEST_ROOT.") path = relativePath.split("\\") if force_new: try: print "Could not store in:", path[-1] folder_version = int(path[-1][path[-1].index('__') + 2::]) path[-1] = path[-1][:path[-1].index('__')] folder_version += 1 path[-1] += str('__' + str(folder_version)) except: traceback.print_exc() path[-1] += '__0' #print str(self.device)+":", "New data location forced:", path print "Path:", path self.dataSet = dataChest(str(path[0])) self.dataSet.cd('') # relativepath = os.path.relpath( # location, self.dataSet.pwd().replace("/", "\\")) # path = relativePath.split("\\") #print "path:", str(path) # dateFolderName = time.strftime('%x').replace(' ', '_') # dateFolderName = dateFolderName.replace('/', '_') folder_version = 0 #path[-1]+=str("__"+str(folder_version)) for folder in path[1::]: try: #print "folder:", folder self.dataSet.cd(folder) except: try: self.dataSet.mkdir(folder) self.dataSet.cd(folder) except: print "ERROR: Could not create dataset at:", path #folder_version += 1 #path[-1] = folder[0:folder.index('__')]+str("__"+str(folder_version)) traceback.print_exc() # print "Configuring datalogging for", str(self.device)+" located # at", location if location == None: folderName = time.strftime('%x').replace(' ', '_') folderName = folderName.replace('/', '_') self.dataSet = dataChest(folderName) # try: # self.dataSet.cd(folderName) # except: # self.dataSet.mkdir(folderName) # self.dataSet.cd(folderName) try: self.device.getFrame().DataLoggingInfo( )['location'] = os.path.abspath(self.dataSet.pwd()) except: traceback.print_exc() # Look at the names of all existing datasets and check # if the name contains the title of the current device. existingFiles = self.dataSet.ls() # foundit becomes true if a dataset file already exists. foundit = False # Go through all existing dataset files. for y in range(len(existingFiles[0])): # If the name of the file contains the (persistant) title # generated by the code, open that dataset and use it. if title in existingFiles[0][y]: self.dataSet.openDataset(existingFiles[0][y], modify=True) foundit = True # If the number of variables in the data set has changed since last time, # Then we do not want to use the old dataset. if len(self.dataSet.getVariables()[1]) != len( self.device.getFrame().getNicknames()): foundit = False else: # print("Existing data set found for %s: %s." # %(title, existingFiles[0][y])) pass # If the dataset does not already exist, we must create it. if not foundit: # print("Creating dataset for %s." %title) # Name of the parameter. This is the name of the parameter # displayed on the gui except without spaces or # non-alphanumerical characters. paramName = None # Arrays to hold any variables. depvars = [] indepvars = [] # For each device, assume it is not connected and we should # not log data until the GUI actually gets readings. # Loop through all parameters in the device. # print "Setting up datalogging for device", # self.device.getFrame().getTitle() nicknames = self.device.getFrame().getNicknames() # print "Nicknames:", self.device.getFrame().getNicknames() for y, name in enumerate(nicknames): # If the name of the parameter has not been defined as # None in the constructor, then we want to log it. if name is not None: # The name of the parameter in the dataset is # the same name displayed on the GUI except without # non-alphanumerical characters. Use regular # expressions to do this. paramName = str(name).replace(" ", "_") paramName = re.sub(r'\W+', '', paramName) # Create the tuple that defines the parameter. # print self.device, "device units: ", self.device.getFrame().getUnits() # print "nicknames:", nicknames #print self.device, "datatype:", self.dataType tup = (paramName, [1], self.dataType, str(self.device.getUnit(name))) # Add it to the array of dependent variables. depvars.append(tup) # Get the datestamp from the datachest helper class. dStamp = dateStamp() # Time is the only independent variable. indepvars.append(("time", [1], "utc_datetime", "s")) # The vars variable holds ALL variables. vars = [] vars.extend(indepvars) vars.extend(depvars) # Construct the data set self.dataSet.createDataset(title, indepvars, depvars) # The DataWidth parameter says how many variables # (independent and dependent) make up the dataset. # DataWidth is used internally only. self.dataSet.addParameter("DataWidth", len(vars)) # if self.device.getFrame().getYLabel() is not None: # Configure the label of the y axis given in the # device's constructor. self.device.getFrame().DataLoggingInfo( )['location'] = self.dataSet.pwd() self.device.getFrame().setDataSet(self.dataSet)