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()
Beispiel #2
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])
Beispiel #3
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])
        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()