6060 required = False ,
6161 help = 'Plot state results and differences (same plot).' )
6262
63+ parser .add_argument (
64+ '--compare-to' ,
65+ metavar = 'COMPARE_TO_FILE' ,
66+ dest = 'compare_to' ,
67+ required = False ,
68+ default = None ,
69+ help = 'Plot results versus a previous run.' )
70+
6371#parser.add_argument(
6472# '--plot-norm',
6573# action='store_true',
7381# dest='quiet',
7482# help='Do not show plot(s)')
7583
84+ def loadfn (fn ):
85+ t = []; lx1 = []; ly1 = []; lz1 = [];
86+ lx2 = []; ly2 = []; lz2 = [];
87+ lvx1 = []; lvy1 = []; lvz1 = [];
88+ lvx2 = []; lvy2 = []; lvz2 = [];
89+
90+ with open (fn , 'r' ) as fin :
91+ for line in fin .readlines ():
92+ if line [0 ] != '#' :
93+ try :
94+ sec , x1 , y1 , z1 , vx1 , vy1 , vz1 , x2 , y2 , z2 , vx2 , vy2 , vz2 = [ float (x ) for x in line .split (' ' ) ]
95+ t .append (sec )
96+ lx1 .append (x1 ); ly1 .append (y1 ); lz1 .append (z1 );
97+ lx2 .append (x2 ); ly2 .append (y2 ); lz2 .append (z2 );
98+ lvx1 .append (vx1 ); lvy1 .append (vy1 ); lvz1 .append (vz1 );
99+ lvx2 .append (vx2 ); lvy2 .append (vy2 ); lvz2 .append (vz2 );
100+ except :
101+ pass
102+ return t , lx1 , ly1 , lz1 , lvx1 , lvy1 , lvz1 , lx2 , ly2 , lz2 , lvx2 , lvy2 , lvz2
103+
76104if __name__ == "__main__" :
77105 args = parser .parse_args ()
78106 scale_pos = args .scale_pos
82110 lx2 = []; ly2 = []; lz2 = [];
83111 lvx1 = []; lvy1 = []; lvz1 = [];
84112 lvx2 = []; lvy2 = []; lvz2 = [];
113+ mean_height = 0e0 ; mean_velo = 0e0 ;
114+ N = 0
85115
86116 for line in sys .stdin :
87117 if line [0 ] != '#' :
92122 lx2 .append (x2 ); ly2 .append (y2 ); lz2 .append (z2 );
93123 lvx1 .append (vx1 ); lvy1 .append (vy1 ); lvz1 .append (vz1 );
94124 lvx2 .append (vx2 ); lvy2 .append (vy2 ); lvz2 .append (vz2 );
125+ N += 1
126+ mean_height = mean_height * (N - 1 )/ N + np .linalg .norm (np .array ((x1 ,y1 ,z1 ))* 1e-3 )/ N
127+ mean_velo = mean_velo * (N - 1 )/ N + np .linalg .norm (np .array ((vx1 ,vy1 ,vz1 )))/ N
95128 except :
96129 pass
97130 else :
105138 fig .subplots_adjust (hspace = 0 )
106139 group_labels = []
107140
141+ ## Plot results compared to another file
142+ if args .compare_to is not None :
143+ st , slx1 , sly1 , slz1 , slvx1 , slvy1 , slvz1 , slx2 , sly2 , slz2 , slvx2 , slvy2 , slvz2 = loadfn (args .compare_to )
144+ axs [0 ,0 ].plot (t , [scale_pos * (z [0 ]- z [1 ]) for z in zip (lx1 ,lx2 )] ,label = r'$\delta x$ current' )
145+ axs [1 ,0 ].plot (t , [scale_pos * (z [0 ]- z [1 ]) for z in zip (ly1 ,ly2 )] ,label = r'$\delta y$ current' )
146+ axs [2 ,0 ].plot (t , [scale_pos * (z [0 ]- z [1 ]) for z in zip (lz1 ,lz2 )] ,label = r'$\delta z$ current' )
147+ axs [0 ,1 ].plot (t , [scale_vel * (z [0 ]- z [1 ]) for z in zip (lvx1 ,lvx2 )],label = r'$\delta v_x$ current' )
148+ axs [1 ,1 ].plot (t , [scale_vel * (z [0 ]- z [1 ]) for z in zip (lvy1 ,lvy2 )],label = r'$\delta v_y$ current' )
149+ axs [2 ,1 ].plot (t , [scale_vel * (z [0 ]- z [1 ]) for z in zip (lvz1 ,lvz2 )],label = r'$\delta v_z$ current' )
150+
151+ axs [0 ,0 ].plot (st , [scale_pos * (z [0 ]- z [1 ]) for z in zip (slx1 , slx2 )] ,label = r'$\delta x$ {:}' .format (args .compare_to ))
152+ axs [1 ,0 ].plot (st , [scale_pos * (z [0 ]- z [1 ]) for z in zip (sly1 , sly2 )] ,label = r'$\delta y$ {:}' .format (args .compare_to ))
153+ axs [2 ,0 ].plot (st , [scale_pos * (z [0 ]- z [1 ]) for z in zip (slz1 , slz2 )] ,label = r'$\delta z$ {:}' .format (args .compare_to ))
154+ axs [0 ,1 ].plot (st , [scale_vel * (z [0 ]- z [1 ]) for z in zip (slvx1 ,slvx2 )],label = r'$\delta v_x$ {:}' .format (args .compare_to ))
155+ axs [1 ,1 ].plot (st , [scale_vel * (z [0 ]- z [1 ]) for z in zip (slvy1 ,slvy2 )],label = r'$\delta v_y$ {:}' .format (args .compare_to ))
156+ axs [2 ,1 ].plot (st , [scale_vel * (z [0 ]- z [1 ]) for z in zip (slvz1 ,slvz2 )],label = r'$\delta v_z$ {:}' .format (args .compare_to ))
157+
158+ axs [0 ,0 ].legend (loc = 'upper left' )
159+ axs [1 ,0 ].legend (loc = 'upper left' )
160+ axs [2 ,0 ].legend (loc = 'upper left' )
161+ axs [0 ,1 ].legend (loc = 'upper left' )
162+ axs [1 ,1 ].legend (loc = 'upper left' )
163+ axs [2 ,1 ].legend (loc = 'upper left' )
164+
108165## Plot state results (not differences)
109- if (args .nodif or args .withdif ):
166+ if (args .nodif or args .withdif ) and not args . compare_to :
110167 print ("Plotting state results ..." )
111168 axs [0 ,0 ].plot (t , [scale_pos * z for z in lx1 ])
112169 axs [0 ,0 ].plot (t , [scale_pos * z for z in lx2 ])
113170 axs [0 ,1 ].plot (t , [scale_vel * z for z in lvx1 ])
114171 axs [0 ,1 ].plot (t , [scale_vel * z for z in lvx2 ])
115- #
172+ #
116173 axs [1 ,0 ].plot (t , [scale_pos * z for z in ly1 ])
117174 axs [1 ,0 ].plot (t , [scale_pos * z for z in ly2 ])
118175 axs [1 ,1 ].plot (t , [scale_vel * z for z in lvy1 ])
@@ -137,7 +194,7 @@ def ytextpos(scale, list): return scale * sum(z for z in list[0:5]) / 5
137194 # group_labels.append("acc. group 2")
138195
139196## Plot differences per component
140- if (args .withdif or (not args .nodif )):
197+ if (args .withdif or (not args .nodif )) and not args . compare_to :
141198 print ("Plotting state diffs ..." )
142199 axs [0 ,0 ].plot (t , [scale_pos * (z [0 ]- z [1 ]) for z in zip (lx1 ,lx2 )])
143200 axs [1 ,0 ].plot (t , [scale_pos * (z [0 ]- z [1 ]) for z in zip (ly1 ,ly2 )])
@@ -172,6 +229,7 @@ def ytextpos(scale, list1, list2):
172229
173230 axs [2 ,0 ].set_xlabel ("Sec of Integration (since t0) [sec]" )
174231 axs [2 ,1 ].set_xlabel ("Sec of Integration (since t0) [sec]" )
232+ fig .suptitle ('Mean Altitude is {:.1f}km, mean velocity is {:.1f}m/sec' .format (mean_height - 6378. , mean_velo ), fontsize = 16 )
175233
176234 plt .show ()
177235
0 commit comments