def onSave(self): logger = logging.getLogger(__name__) logger.info("Saving config") filename, _ = DataDirectory.DataDirectory().sequencefile( "InstrumentLogger-configuration.db") self.saveConfig() self.config.saveConfig(filename)
def prepare(self, pulseProgramUi, maxUpdatesToWrite=None): logger = logging.getLogger(__name__) self.maxUpdatesToWrite = maxUpdatesToWrite address, data, self.gateSequenceSettings = self.scan.gateSequenceUi.gateSequenceScanData( ) self.gateSequenceAttributes = self.scan.gateSequenceUi.gateSequenceAttributes( ) parameter = self.gateSequenceSettings.startAddressParam logger.debug("GateSequenceScan {0} {1}".format(address, parameter)) self.scan.list = address self.scan.index = list(range(len(self.scan.list))) if self.scan.scantype == 1: self.scan.list.reverse() self.scan.index.reverse() elif self.scan.scantype == 2: zipped = list(zip(self.scan.index, self.scan.list)) random.shuffle(zipped) self.scan.index, self.scan.list = list(zip(*zipped)) self.scan.code = pulseProgramUi.pulseProgram.variableScanCode( parameter, self.scan.list) self.numVariablesPerUpdate = 1 logger.debug("GateSequenceScanCode {0} {1}".format( self.scan.list, self.scan.code)) if self.scan.gateSequenceSettings.debug: dumpFilename, _ = DataDirectory.DataDirectory().sequencefile( "fpga_sdram.bin") with open(dumpFilename, 'wb') as f: f.write( bytearray( numpy.array(data, dtype=numpy.int32).view(dtype=numpy.int8))) codeFilename, _ = DataDirectory.DataDirectory().sequencefile( "start_address.txt") with open(codeFilename, 'w') as f: for a in self.scan.code[1::2]: f.write("{0}\n".format(a)) codeFilename, _ = DataDirectory.DataDirectory().sequencefile( "start_address_sorted.txt") with open(codeFilename, 'w') as f: for index, a in enumerate(sorted(self.scan.code[1::2])): f.write("{0} {1}\n".format(index, a)) if len(self.scan.code) > self.maxWordsToWrite: self.nextIndexToWrite = self.maxWordsToWrite return (self.scan.code[:self.maxWordsToWrite], data) self.nextIndexToWrite = len(self.scan.code) return (self.scan.code, data)
def _add(self, data, datatype): if not self.datafile: self.datafilename, _ = DataDirectory.DataDirectory().sequencefile( "RawData.bin") self.datafile = open(self.datafilename, 'wb') data_array = array(datatype, data) self.hash.update(data_array) data_array.tofile(self.datafile)
def save(self, name=None): if name and not self.filenametemplate: # we are currently on a temp file self.datafile.close() newdatafilename, _ = DataDirectory.DataDirectory().sequencefile( name) shutil.move(self.datafilename, newdatafilename) self.datafilename = newdatafilename self.datafile = open(self.datafilename, 'wb+') self.filenametemplate = name return self.datafilename, self.hash.hexdigest()
def traceFilename(self, pattern): directory = DataDirectory.DataDirectory() path, _ = QtWidgets.QFileDialog.getSaveFileName(self, 'Save file', directory.path()) return path
def delete(self): pass def hexdigest(self): return self.hash.hexdigest() def close(self): if self.datafile: self.datafile.close() return self.hash.hexdigest() if __name__ == "__main__": DataDirectory.DefaultProject = "testproject" rd = RawData() rd.addFloat(list(range(200))) print(rd.save("Peter.txt")) print(rd.close()) filename, components = DataDirectory.DataDirectory().sequencefile( "TestTrace.txt") from trace import TraceCollection tr = TraceCollection.TraceCollection() tr.x = list(range(200)) tr.y = list(range(200)) tr.rawdata = RawData() tr.rawdata.addInt(list(range(200))) tr.saveTrace(filename)