def deletedata(options): if(options.runname == None): print "Specify the rest run name (--runname 01CornerTestRun) " exit() extension = os.path.splitext(options.infile) extension = extension[1] if extension != '.h5': print "Can only lsit .h5 files: " + options.infile exit() theReader = SofiePyTableAccess(options.infile, runName='/') if options.recursive: recursively = ' (recursively enabled) ' else: recursively = ' (recursively disabled)' if theReader.deleteRun(options.runname, options.recursive): print "\n\n===============================" print "===============================" print "RUN: " + options.runname + ' DELETED' + recursively + \ "\n-------------------------------" else: print "\n\n===============================" print "===============================" print "RUN: " + options.runname + ' NOT DELETED' + recursively + \ "\n-------------------------------" theReader.close()
def test_SofiePyTableAccess(self): logging.info('AntPyTableAccess Test') writer = SofiePyTableAccess('simple-test-data.h5', '/test') self.assertIsInstance(writer, SofiePyTableAccess, 'Root Does not exist') writer.close() writer = SofiePyTableAccess('simple-test-data.h5', '/test') self.assertIsInstance(writer, SofiePyTableAccess, 'Root Exists') writer = SofiePyTableAccess('simple-test-data.h5', '/testagain') self.assertIsInstance(writer, SofiePyTableAccess, 'New Root') writer = SofiePyTableAccess('simple-test-data.h5', '/testagain/new') self.assertIsInstance(writer, SofiePyTableAccess, 'New Leaf') writer = SofiePyTableAccess('simple-test-data.h5', '/testagain/new') self.assertIsInstance(writer, SofiePyTableAccess, 'Repeat Leaf') writer.setRunName('test/new2') writer.setRunName('testagain/new3/sub1') writer.setRunName('testagain/new3/sub1') writer.setRunName('testagain/new3/sub2') writer = AntRawDataAccess('simple-test-data.h5', '/test') writerData = ('1', '2', '3', '4', '5', '6', '7', '8', '9', 111111.101221) logging.info('Writing the following data: ' + str(writerData)) writer.write(writerData) logging.info('Came Back from writing.') writer.close() writer = AntRawDataAccess('simple-test-data.h5', '/test/AntRawData') self.assertIsInstance(writer, AntRawDataAccess)
def listdata(options): if(options.runname == None): options.runname = '/' if(options.infile == None): print "Specify the in file (--infile filename)" exit() extension = os.path.splitext(options.infile) extension = extension[1] if extension != '.h5': print "Can only lsit .h5 files: " + options.infile exit() theReader = SofiePyTableAccess(options.infile, runName='/') runs = theReader.getRuns(options.runname) runs.sort() for run in runs: logging.debug('Setting Run: ' + run); splitRun = os.path.split(run); theRun, theNode = splitRun theReader.setRunName(theRun) meta = theReader.getRunMeta(options.runname) if meta: run, description, timestamp = meta[0] else: run, description, timestamp = None, None, None print "\n\n===============================" print "===============================" print "RUN: " + theRun + '/' + theNode + "\n-------------------------------" if theNode == RunMetaName: print "Description: " + str(description) print "Time: " + time.strftime('%D, %H:%M:%S', time.localtime(timestamp)) elif options.verbose: theReader.setTable(theNode, '') x = DUMPLINLINES for row in theReader: print str(row).lstrip('(').rstrip(')') if x == 0: print '.... ONLY THE FIRST ' + \ str(DUMPLINLINES) + ' ENTRIES ARE PRINTED ....' break; x -= 1; else: print "\n\n===============================" print "===============================" print "RUN: " + options.runname + ' DOES NOT EXIST' + \ "\n-------------------------------" theReader.close()
def exportdata(options): """ Function used to export data. """ print '\n-------------------------------\nExporting information' + \ '\n-------------------------------\n' if(options.runname == None): exportpath = '/' else: exportpath = options.runname if(options.infile == None): print "Specify the in file (--infile filename)" exit() if(options.outdir == None): print "Specify the out file (--exportdir directoryname)" exit() extension = os.path.splitext(options.infile) extension = extension[1] if extension != '.h5': print "Can only export .h5 files: " + options.infile exit() else: theReader = SofiePyTableAccess(options.infile, runName='/') theRuns = theReader.getRuns(exportpath) for run in theRuns: exportFile = os.sep.join([options.outdir] + run.split('/')) + '.csv' if not os.path.isdir(os.path.dirname(exportFile)): os.makedirs(os.path.dirname(exportFile)) if os.path.isfile(exportFile): os.unlink(exportFile) print '\n-------------------------------\n' + \ 'Exporting: ' + run + ' to ' + str(exportFile) theReader.setTable(run, '') fieldNames = theReader.getTableStructure(asList=True) csvWriter = SofieCsvAccess(exportFile, fieldNames) for row in theReader: logging.debug("Read New Row") parsed = csv_sample_interpret(row) csvWriter.write(parsed) #aparsedwritercsv = SofieCsvAccess(csvOutParsed) csvWriter.close() theReader.close()
def exportFile(options): """ Function used to export data. """ print '\n-------------------------------\nExporting information' + \ '\n-------------------------------\n' if(options.runname == None): print "Specify the complete node/run to export (--runname runNameOrPath)" exportpath = options.runname if(options.infile == None): print "Specify the in file (--infile filename)" exit() if(options.outfile == None): print "Specify the out file (--outfile theExportedFileName )" exit() extension = os.path.splitext(options.infile) extension = extension[1] if extension != '.h5': print "Can only export .h5 files: " + options.infile exit() else: theReader = SofiePyTableAccess(options.infile) theReader.readFile(options.runname, options.outfile) theReader.close()
def exportFile(filename,runName,outFilename): """ Exports a file node from a sofiehdfformat file. """ theReader = SofiePyTableAccess(filename) theReader.readFile(runName, outFilename) theReader.close()