Compare Two Simfiles


In [4]:
import sys,os

import numpy as np
import matplotlib as mpl
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.colors as colors

#this works apparently only for savefig stuff
mpl.rcParams['figure.figsize']=(16.0,8.0)    #(6.0,4.0)
mpl.rcParams['font.size']=12                #10 
mpl.rcParams['savefig.dpi']=100             #72 

mpl.rcParams['figure.subplot.bottom']=.1    #.125


plt.rc('font', family='serif')
plt.rc('text', usetex=True)

#inline Shit
%matplotlib inline
%config InlineBackend.figure_format='svg'
%config InlineBackend.rc = {'figure.facecolor': 'white', 'figure.subplot.bottom': 0.125, 'figure.edgecolor': 'white', 'savefig.dpi': 300, 'figure.figsize': (12.0, 8.0), 'font.size': 10}

#GUi shit
%matplotlib tk

mpl.get_configdir()

%load_ext autoreload
%autoreload 2
# Import General Packages from me
from Tools.Parsers import *
from Tools.BoundingBox import *
from Tools.Transformations import *


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

Plot all states for the two files


In [5]:
def plotBodies():
    
    plt.close('all')
    
    def getMarkesOpt1(colorVal):
        return {    'linestyle': '-', 'marker': '.',
                    'color': colorVal,
                    'linewidth': 2,
                    'markersize':3, 
                     'markeredgecolor' : colorVal, 
                     'markerfacecolor' : colorVal, 
                     'markeredgewidth': 1
                }
    def getMarkesOpt2(colorVal):
        return {    'color': colorVal,
                    'linestyle': ':', 'marker': '.',
                    'linewidth': 2,
                    'markersize':7, 
                     'markeredgecolor' : colorVal, 
                     'markerfacecolor' : 'none', 
                     'markeredgewidth': 1
                }
    
    nBodies = bodyRange[1] - bodyRange[0] + 1
    jet = plt.get_cmap('jet') 
    cNorm  = colors.Normalize(vmin=0, vmax=nBodies)
    scalarMap = cm.ScalarMappable(norm=cNorm, cmap=jet)
    
    fig1 = plt.figure()
    ax10 = plt.subplot(2,1,1);
    # Position
    for i,body in dynState1.bodies.items():             
        ax10.plot(dynState1.t, body[0][:,0:3],  label=label1, **getMarkesOpt1(scalarMap.to_rgba(i)) );
        ax10.plot(dynState2.t, dynState2.bodies[i][0][:,0:3],  label=label2, **getMarkesOpt2(scalarMap.to_rgba(i)) );
    
    ax11 = plt.subplot(2,1,2, sharex= ax10);
    for i,body in dynState1.bodies.items(): 
        ax11.plot(dynState1.t, body[0][:,3:7],  **getMarkesOpt1(scalarMap.to_rgba(i)) );
        ax11.plot(dynState2.t, dynState2.bodies[i][0][:,3:7], **getMarkesOpt2(scalarMap.to_rgba(i)) );
    
    ax10.legend()
    ax10.grid(True)
    ax10.set_title('Position');
    ax10.set_ylabel('\mathbf{r}_S(t)');
    ax10.set_ymargin(0.2)
    ax10.autoscale(True,'both',False)
    
    ax11.grid(True)
    ax11.set_title('Quaternion');
    ax11.set_ylabel('\mathbf{a}_{KI}(t)');
    ax11.set_ymargin(0.2)
    ax11.autoscale(True,'both',False)
    
    # Velocity
    fig2 = plt.figure()
    ax20 = plt.subplot(2,1,1);
    for i,body in dynState1.bodies.items():             
        ax20.plot(dynState1.t, body[1][:,0:3],**getMarkesOpt1(scalarMap.to_rgba(i)) );
        ax20.plot(dynState2.t, dynState2.bodies[i][1][:,0:3],**getMarkesOpt2(scalarMap.to_rgba(i)) );
    ax21 = plt.subplot(2,1,2, sharex=ax20);
    for i,body in dynState1.bodies.items():   
        ax21.plot(dynState1.t, body[1][:,3:6], **getMarkesOpt1(scalarMap.to_rgba(i)) );
        ax21.plot(dynState2.t, dynState2.bodies[i][1][:,3:6], **getMarkesOpt2(scalarMap.to_rgba(i)) );
    
    ax20.grid(True)
    ax20.set_title('Velocity');
    ax20.set_ylabel('\mathbf{v}_S(t)');
    ax20.set_xmargin(0.0)
    ax20.set_ymargin(0.1)
    
    ax21.grid(True)
    ax21.set_title('Angular Velocity');
    ax21.set_ylabel('\mathbf{\omega}_{KI}(t)');
    ax21.set_xmargin(0.0)
    ax21.set_ymargin(0.1)
# # Debug t= 0.83 # dynState1.t[83] # print(dynState1.t[83]) # print(dynState1.bodies[2][0][83]) # r_sM =dynState1.bodies[2][0][83][0:3] + 0.5*0.01*dynState1.bodies[2][1][83][0:3] # #y axis Collide with wall # print(r_sM[1] + 1.29768) # over 3 collides with wall # #z axis Collide with wall # print(r_sM[2] + 1.29768) # over 3 collides with wall
# # Debug t= 0.83 # dynState2.t[83] # print(dynState2.t[83]) # print(dynState2.bodies[2][0][83]) # r_sM =dynState2.bodies[2][0][83][0:3] + 0.5*0.01*dynState2.bodies[2][1][83][0:3] # print(r_sM[1] + 1.29768) # over 3 collides with wall # print(r_sM[2] + 1.29768) # over 3 collides with wall

Load the two Simfiles


In [6]:
scriptpath = "./"
# Add the directory containing your module to the Python path (wants absolute paths)
sys.path.append(os.path.abspath(scriptpath))  

bodyRange = [0,1]
label1='GUI';
label2='MPI';


timeRange = [0,50]

folderNumber = 0
#For single file which contains multiple bodies
dynState1 = SimFileReader.ReadInSimFile("./../SimFiles/SimDataRECORDGUI_%d/SimState.sim" % folderNumber ,timeRange,bodyRange,False)
print(dynState1)
#print(dynState1.bodies)

folderNumber = 2
dynState2 = SimFileReader.ReadInSimFile("./../SimFiles/SimDataRECORDGUI_%d/SimState.sim" % folderNumber ,timeRange,bodyRange,False)
#dynState2 = SimFileReader.("./../GlobalFolder/SimFiles/SimDataRECORDMPI_%d/SimState.sim" % folderNumber, timeRange , bodyRange , False)
print(dynState2)
#print(dynState2.bodies)

plotBodies();


Read in SimFile at: ./../SimFiles/SimDataRECORDGUI_0/SimState.sim
--> File has: 57.2207145690918 mb
--> SimFile signature: b'MBSF' found
--> SimFile version: 2
--> nSimBodies: 1
--> nDofqObj: 7
--> nDofuObj: 6
--> Add. Bytes Type: 0
--> Add. Bytes Per Body: 0
--> nBytesHeader: 28
--> nBytesBodyState: 112
--> nBytesState: 120
--> nStates: 500002
--> nAdditionalWrongBytes: 0
--> minTime: 0.0
--> maxTime: 5.000009999979879
Filtering Simfile: t = [0, 5.000009999979879]
--> readNStates: 500002
--> Time t: [  0.00000000e+00   1.00000000e-05   2.00000000e-05 ...,   4.99999000e+00
   5.00000000e+00   5.00001000e+00]
--> BodyIds: min/max  0 0
--> Number of BodyIds:  1
DynamicsState id:140003864620112
nSimBodies: 1
minTime: 0.0
maxTime: 5.00000999998
body ids: [0]
Read in SimFile at: ./../SimFiles/SimDataRECORDGUI_2/SimState.sim
--> File has: 0.5723457336425781 mb
--> SimFile signature: b'MBSF' found
--> SimFile version: 2
--> nSimBodies: 1
--> nDofqObj: 7
--> nDofuObj: 6
--> Add. Bytes Type: 0
--> Add. Bytes Per Body: 0
--> nBytesHeader: 28
--> nBytesBodyState: 112
--> nBytesState: 120
--> nStates: 5001
--> nAdditionalWrongBytes: 0
--> minTime: 0.0
--> maxTime: 5.000000000000004
Filtering Simfile: t = [0, 5.000000000000004]
--> readNStates: 5001
--> Time t: [  0.00000000e+00   1.00000000e-03   2.00000000e-03 ...,   4.99800000e+00
   4.99900000e+00   5.00000000e+00]
--> BodyIds: min/max  0 0
--> Number of BodyIds:  1
DynamicsState id:140003864620896
nSimBodies: 1
minTime: 0.0
maxTime: 5.0
body ids: [0]

In [ ]: