Ejemplo n.º 1
0
    def test_plotFromLog(self):
        # Load sim definition file
        simDef = SimDefinition("MAPLEAF/Examples/Simulations/AdaptTimeStep.mapleaf", silent=True)
        test.testUtilities.setUpSimDefForMinimalRunCheck(simDef)
        simDef.setValue("SimControl.EndConditionValue", "0.03")

        # Generate log file from a simulation
        simDef.setValue("SimControl.loggingLevel", "2")
        simDef.fileName = "test/tempTestFileasdf.txt"
        simRunner =  Main.Simulation(simDefinition=simDef, silent=True)
        _, logfilePaths = simRunner.run()
        
        # Try to plot one of its columns (AeroForce)
        Plotting.plotFromLogFiles(logfilePaths, "Position&^Velocity", showPlot=False)
        # The '^' in front of Velocity is for a Regex match, indicating the start of a line
            # This will prevent it from also plotting the AngularVelocity along with the Position and Velocity columns
        ax = plt.gca()
        nLines = len(ax.lines)
        self.assertEqual(nLines, 6)

        # Try to plot one of its columns (AeroForce)
        Plotting.plotFromLogFiles(logfilePaths, "Position&Velocity", showPlot=False)
        ax = plt.gca()
        nLines = len(ax.lines)
        self.assertEqual(nLines, 9)

        # Delete temp files
        logDirectory = os.path.dirname(logfilePaths[0])
        shutil.rmtree(logDirectory)

        # Clear the plot
        plt.clf()
Ejemplo n.º 2
0
    def test_plotColumn(self):
        # Load sim definition file
        simDef = SimDefinition("MAPLEAF/Examples/Simulations/AdaptTimeStep.mapleaf", silent=True)
        test.testUtilities.setUpSimDefForMinimalRunCheck(simDef)
        simDef.setValue("SimControl.EndConditionValue", "0.03")

        # Generate log file from a simulation
        simDef.setValue("SimControl.loggingLevel", "2")
        simDef.fileName = "test/tempTestFileasdf.txt"
        simRunner = Main.Simulation(simDefinition=simDef, silent=True)
        _, logfilePaths = simRunner.run()
        
        # Try to plot one of its columns (AeroForce)
        Plotting.tryPlottingFromLog(logfilePaths[1], ["AeroF"], showPlot=False)
        ax = plt.gca()
        nLines = len(ax.lines)
        self.assertEqual(nLines, 3)

        Plotting.tryPlottingFromLog(logfilePaths[0], ["Position"], showPlot=False)
        ax = plt.gca()
        nLines = len(ax.lines)
        self.assertEqual(nLines, 3)

        # Delete temp files
        logDirectory = os.path.dirname(logfilePaths[0])
        shutil.rmtree(logDirectory)