Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
    def test_meta(self):
        writer = SofiePyTableAccess('simple-test-data.h5', '/test')
        self.assertEqual(writer.getRuns('/'), ['/RunMeta'])
        data = writer.getRunMeta('test')
        logging.debug('Meta Data for the table:' + str(data))
        self.assertEqual(len(data),8)
        
        writer.setRunMeta('ourRun', 'The Description')
        data = writer.getRunMeta('ourRun')
        self.assertEqual(len(data), 8)
        logging.debug('The Data:'+str(data))
        self.assertEqual('ourRun', data['runName'])
        self.assertEqual('The Description', data['runNotes'])
        
        self.assertTrue(writer.setRunMeta('ourRun', 'The New Description'))
        data = writer.getRunMeta('ourRun')
        logging.debug(data)
        self.assertEqual(len(data), 8)
        logging.debug('The Data:'+str(data))
        self.assertEqual('ourRun', data['runName'])
        self.assertEqual('The New Description', data['runNotes'])

        data = writer.getRunMeta('test')
        self.assertEqual(len(data), 8)

        writer = SofiePyTableAccess('simple-test-data.h5', runName='/testagain',
        description='our description again')
        data = writer.getRunMeta('/testagain')
        self.assertEqual(len(data), 8)
        self.assertEqual('testagain', data['runName'])
        self.assertEqual('our description again', data['runNotes'])
        data = writer.getRunMeta('testagain')
        self.assertEqual(len(data), 8)
        self.assertEqual('testagain', data['runName'])
        self.assertEqual('our description again', data['runNotes'])

        self.assertIsNone(writer.setRunName('/'));
        self.assertIsNone(writer.setRunName('/'));
        self.assertIsNone(writer.setTable('/', ''));