def test_write_read(self):
     while True:
         second = self.c3dFile.readline()
         if second == False:
             break;
         #outFile.write(second+'\n')
         self.assertIsInstance(second,dict);
         self.cwriter.write(second)
         
     csvWriter = SofieCsvAccess('c3d-test-data.csv')
     numRows = 0
     for row in self.cwriter:
         #logging.debug(row)
         csvWriter.write(row)
         numRows += 1
     self.assertEqual(self.c3dFile.getVideoFrames(),numRows)
Пример #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()
Пример #3
0
    def test_sofiecsvfile_promove(self):
        csvFile = scf.open('test-data/test-promove.csv')
        csvWriter = SofieCsvAccess('output.csv')

        for row in csvFile:
            csvWriter.write(row)

        csvFile.close()
        csvWriter.close()

        csvFile = scf.open('test-data/test-promove.csv')
        csvFileNew = scf.open('output.csv')
        logging.debug(csvFileNew.reader)
        for row, newRow in zip(csvFile, csvFileNew):
            for key in row.keys():
                if row[key] == None:
                    self.assertEqual(newRow[key], '')
                else:
                    self.assertEqual(row[key], newRow[key])
Пример #4
0
    def test_sofiecsvfile_adams(self):
        logging.debug('Creating CSV FILE');
        csvFile = adam.open('test-data/test-adams.tab')
        logging.debug('CSVFILE CREATED.');
        csvWriter = SofieCsvAccess('output.csv')

        for row in csvFile:
            csvWriter.write(row)

        csvFile.close()
        csvWriter.close()

        csvFile = adam.open('test-data/test-adams.tab')
        csvFileNew = scf.open('output.csv')
        logging.debug(csvFileNew.reader)
        for row, newRow in zip(csvFile, csvFileNew):
            for key in row.keys():
                #logging.debug('"'+key+'"')
                self.assertTrue(key == 'Time      ' or  key == 'Roll angle'\
                    or key == 'Steering angle')
                if row[key] == None:
                    self.assertEqual(newRow[key], '')
                else:
                    self.assertEqual(row[key], newRow[key])
Пример #5
0
def importdata(infile, outfile, runName, description, shouldParse, shouldCsv):
    """
    Standard function used to import data into the file
    """
    print '\n-------------------------------\nImporting information' + \
        '\n-------------------------------\n'
    if(infile == None):
        print "Specify the in file (--infile filename)"
        exit()
    if(outfile == None):
        print "Specify the out file (--outfile filename)"
        exit()
    if(runName == None):
        print "Specify the rest run name (--runName 01CornerTestRun) "
        exit()

    extension = os.path.splitext(infile)
    infileName = extension[0]
    extension = extension[1]

    csvOut = infileName + '-sofie.csv'
    csvOutParsed = infileName + '-sofie-parsed.csv'

    if extension == '.gce':
        runNameExtended = getGESubDirectory(runName)
        theOriginalFile = GE.open(infile)
        parser = ant_sample
        parser_interpret = ant_sample_interpret
        theWriter = AntRawDataAccess(outfile,
                                     runName=runNameExtended,
                                     description=description)
    elif extension == '.ant':
        runNameExtended = getSparkSubDirectory(runName)
        theOriginalFile = SF.open(infile)
        parser = ant_sample
        parser_interpret = ant_sample_interpret
        theWriter = AntRawDataAccess(outfile,
                                     runName=runNameExtended,
                                     description=description)
    elif extension == '.c3d' or extension == '.C3D':
        runNameExtended = getC3DSubDirectory(runName)
        theOriginalFile = C3.open(infile)
        parser = c3d_sample
        parser_interpret = c3d_sample_interpret
        theWriter = C3DDataAccess(outfile,
                                  runName=runNameExtended,
                                  description=description,
                                  allowDuplicates=True,
                                  videoSamplingRate=theOriginalFile.getVideoSamplingRate(),
                                  videoFrames=theOriginalFile.getVideoFrames(),
                                  scale=theOriginalFile.getScale())
    elif extension == '.csv':
        runNameExtended = getCSVImportSubDirectory(runName)
        theOriginalFile = scf.open(infile)
        parser = csv_sample
        parser_interpret = csv_sample_interpret
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=theOriginalFile.getTableStructure())
    elif extension == '.tab':
        runNameExtended = getAdamsSubDirectory(runName)
        theOriginalFile = adams.open(infile)
        parser = csv_sample
        parser_interpret = csv_sample_interpret
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=theOriginalFile.getTableStructure())
    elif extension == '.bag':
        runNameExtended = getBagSubDirectory(runName)
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=['A HACK'])
        theWriter.writeFile(infile)
        print '\n-------------------------------\n{0} Saved  to file'.format(outfile)
        theWriter.close()
        return
    else:
        raise FileNotSupportedException('File not Supported: ' + str(extension))
    print '\n-------------------------------\nSaving to file',
    print outfile
    if shouldParse:
        print 'File is going to be parsed'
        print 'CSV Parsed File: ' + csvOutParsed
    if shouldCsv:
        print 'CSV File: ' + csvOut + '\n-----------------------------------\n'
        awritercsv = SofieCsvAccess(csvOut)

    for theLine in theOriginalFile:
        logging.debug(theLine)
        try:
            parsedLine = parser(theLine)

        except Exception, e:
            print 'Parsing Failed: ' + str(e)
            continue
        try:
            logging.debug(parsedLine)
            theWriter.write(parsedLine)
            print '.',
            if shouldCsv:
                awritercsv.write(parsedLine)
                print 'c',
        except AntRawParserLengthNotCorrect, e:
            print 'x'
Пример #6
0
            parsedWriter = AntParsedDataAccess(outfile,
                                               runNameExtended)
        elif extension == '.ant':
            parsedWriter = AntParsedDataAccess(outfile,
                                               runNameExtended)
        elif extension == '.c3d':
            parsedWriter = None
        elif extension == '.csv':
            parsedWriter = None
        else:
            raise FileNotSupportedException('File not Supported: ' + extension)

        print '\n-------------------------------\nParsing Data\n'

        if shouldCsv:
            aparsedwritercsv = SofieCsvAccess(csvOutParsed)
        previousParsedLine = None
        for row in theWriter:
            parsedLine = parser_interpret(row, previousParsedLine)
            logging.debug('The parsedLine: ' + str(row))
            if shouldCsv:
                aparsedwritercsv.write(parsedLine)
                print 'c',
            if parsedWriter:
                parsedWriter.write(parsedLine)
                print 'p',
            previousParsedLine = parsedLine

    print 'DUPLICATE WRITES: ' + str(theWriter.getDuplicateWrites())
    theWriter.close()
    
Пример #7
0
        data.pose.pose.orientation.w,
        data.pose.pose.orientation.x,
        data.pose.pose.orientation.y,
        data.pose.pose.orientation.z,
        data.header.stamp.to_time()))

    
def sofieArduinoWriterCallback(data):
    '''
    Implements a simple writer to CSV file for angle data.
    '''
    timestamp = time.time()
    rospy.logdebug(rospy.get_name() + ": Received Angle")
    rospy.logdebug(data)
    data = data.data
    csvWriterArduino.write((data,timestamp))

if __name__ == '__main__':
    csvfilename = getFileInfo()
    rospy.loginfo('Logging to file: {0}'.format(csvfilename))
    csvWriter = SofieCsvAccess(csvfilename, defaultQuaternionTableStructure)
    csvWriterArduino = SofieCsvAccess(getFileInfo(waitParam='/sofie/arduinocsvfilename'),
                                       defaultAngleTableStructure)
    try:
        rospy.init_node('sofiehdfformatwriter', anonymous=True)
        rospy.Subscriber("/ar_pose_marker", AlvarMarkers, sofieWriterCallback)
        rospy.Subscriber("/angle", Int16, sofieArduinoWriterCallback)
        rospy.spin()
    except:
          csvWriter.close()
          csvWriterArduino.close()