source: ntrip/trunk/BNC/scripts/compareSP3Plot.pl@ 11209

Last change on this file since 11209 was 11179, checked in by stuerze, 2 weeks ago

structuered logging is added and bug is fixed in SP3 file writing

  • Property svn:executable set to *
File size: 18.1 KB
Line 
1#!/usr/bin/env perl
2# ========================================================================
3# compareSP3Plot.pl
4# ========================================================================
5#
6# Purpose: Script using gnuplot to plot BNC's SP3 Comparison Results
7#
8# Comment: stored values:
9# To compare satellite clocks provided by the two files, BNC first converts
10# coordinate differences dX,dY,dZ into along track, out-of-plane, and radial
11# components.
12# It then corrects the clock differences for the radial components of
13# coordinate differences. RMS values of clock differences are
14# finally calculated after introducing
15# - at first one offset 'per epoch for all satellites' and
16# - secondly one offset 'per satellite for all epochs'.
17# The signal-in-space difference SIS (radial minus clock difference, only the
18# epoch offset removed, i.e. including the satellite offsets) is given in the
19# last column of BNC's epoch lines.
20# ========================================================================
21# Uses
22use strict;
23use warnings;
24use Getopt::Long;
25use Chart::Gnuplot;
26use Data::Dumper qw(Dumper);
27use diagnostics;
28use File::Basename;
29use Date::Manip;
30use Time::Piece 1.30;
31use List::MoreUtils qw( minmax );
32use experimental 'smartmatch';
33
34# -----------------------------------------------------------------------------
35# required to create a pdf
36# -----------------------------------------------------------------------------
37use PDF::API2;
38use constant {mm => 25.4 / 72, inch => 1 / 72,pt => 1,
39};# There are 72 postscript points in an inch and there are 25.4 millimeters in an inch.
40# -----------------------------------------------------------------------------
41# Options
42# -----------------------------------------------------------------------------
43# init options
44my $help = 0;
45my @plotTypes = ();
46my @logFiles = ();
47my $keepImages = 0;
48# read options from command line
49GetOptions(
50 'help' => \$help,
51 'plotTypes=s' => \@plotTypes,
52 'logFiles=s' => \@logFiles,
53 'keepImages' => \$keepImages,
54);
55help() if $help;
56@plotTypes = qw(ALL) unless (@plotTypes);# Default values
57@plotTypes = map {uc} split ( /[, ]/, join ( ',', @plotTypes ) );# Reformat options
58@logFiles = split ( /[, ]/, join ( ',', @logFiles ) );
59unless (@logFiles) {
60 print "ERROR: logfiles missing\n";
61 exit;
62}
63print " plotTpes: @plotTypes\n logfiles: @logFiles\n\n";
64# -----------------------------------------------------------------------------
65# generate data sets for gnuplot
66# -----------------------------------------------------------------------------
67my $epoSec = 0;
68# for pdf generation
69my ($png, $page, $headline, $headline_text);
70my @pngFiles; # images to be deleted after inclusion in the PDF
71my $y0 = 190/mm;
72my ($x, $y, $width, $height) = (40/mm, $y0, 130/mm, 70/mm);
73my $dy = $height+7/mm;
74# file by file ..
75foreach my $file (@logFiles) {
76 my (%COMPARISON);
77 my (@array);
78 my ($sys, $sat, $epo, $radial, $along, $out, $drange, $clk, $clkRed, $sis);
79 # -----------------------------------------------------------------------------
80 # create pdf for plot results
81 # -----------------------------------------------------------------------------
82 my($inputFilename, $inputDir, $inputSuffix) = fileparse($file, '\..*');
83 my $pdf_name = sprintf("%s.pdf", $inputFilename);
84 my $pdf = PDF::API2->new(-file => "$inputDir$pdf_name");
85 my $font1 = $pdf->corefont('Helvetica-Bold');
86 # -----------------------------------------------------------------------------
87 # read file and save data
88 # -----------------------------------------------------------------------------
89 open ( INPUT, "<$file" ) || die $!;
90 print "Parse logfile $file ...\n";
91 while (<INPUT>) {#56985.000000 G01 0.0160 -0.0242 0.0961 0.0082 -0.0077 1
92 if ( $_ !~ /^!/) { #print "$_\n";
93 @array = split(/\s+/, $_);
94 $epo = $array[0]; #print "$epo\n";
95 $epo =~s/(\.\d*)//; #print "$epo\n";
96 $sys = substr $array[1], 0, 1;
97 $sat = $array[1];#print "$sat\n";
98 $radial = $array[2];#print "$radial\n";
99 $along = $array[3];#print "$along\n";
100 $out = $array[4];#print "$out\n";
101 $clk = $array[5];#print "$clk\n";
102 $clkRed = $array[6];#print "$clkRed\n";
103 $sis = $array[8];# not present if the clock comparison is missing
104 if ($out !~ /^\.$/) {
105 push @{$COMPARISON{$sys}{$sat}{EPOCH }}, $epo;
106 push @{$COMPARISON{$sys}{$sat}{RADIAL}}, $radial;
107 push @{$COMPARISON{$sys}{$sat}{ALONG }}, $along;
108 push @{$COMPARISON{$sys}{$sat}{OUT }}, $out;
109 push @{$COMPARISON{$sys}{$sat}{CLK }}, $clk;
110 push @{$COMPARISON{$sys}{$sat}{CLKRED}}, $clkRed;
111 }
112 if (defined $sis && $sis =~ /^-?\d/) {
113 push @{$COMPARISON{$sys}{$sat}{EPOCH_SIS}}, $epo;
114 push @{$COMPARISON{$sys}{$sat}{SIS }}, $sis;
115 }
116 }
117 }
118 close INPUT;
119
120 # -----------------------------------------------------------------------------
121 # plot several data sets
122 # -----------------------------------------------------------------------------
123 ######### RAO #####################
124 if (("ALL" ~~ @plotTypes ) || ("RAO" ~~ @plotTypes)) {
125 print "Plot RADIAL, ALONG TRACK and OUT OF PLANE COMPONENTS ...\n";
126 my $yrange = .6;
127 $page = $pdf->page(); $page->mediabox('A4');
128 $headline = sprintf("Orbit Differences in radial, along-track and out-of-plane component (%s)", $inputFilename);
129 $headline_text = $page->text;
130 $headline_text->font($font1, 11/pt);
131 $headline_text->translate(15/mm, 280/mm);
132 $headline_text->text($headline);
133 $y = $y0+$dy;
134 #SYSTEM
135 foreach my $key_sys (sort keys %COMPARISON) {
136 print " for $key_sys\n";
137 my (@datasets_r, @datasets_a, @datasets_o); # init datasets
138 my $pngName_r = sprintf ("%s_RADIAL_%s.png", $inputFilename, $key_sys);
139 push @pngFiles, $pngName_r;
140 my $pngName_a = sprintf ("%s_ALONG_%s.png", $inputFilename, $key_sys);
141 push @pngFiles, $pngName_a;
142 my $pngName_o = sprintf ("%s_OUT_%s.png", $inputFilename, $key_sys);
143 push @pngFiles, $pngName_o;
144 my $chart_r = Chart::Gnuplot->new(
145 output => $pngName_r, terminal => 'png', title => "Radial component",
146 ylabel => "Orbit Difference [m]", yrange => ["-$yrange", "$yrange"],
147 xlabel => "Time [h]", timeaxis => 'x', xtics => {labelfmt => '%H:%M', rotate => '-270',},
148 legend => { position => "outside right",},
149 grid => 'on',);
150 my $chart_a = Chart::Gnuplot->new(
151 output => $pngName_a, terminal => 'png', title => "Along track component",
152 ylabel => "Orbit Difference [m]", yrange => ["-$yrange", "$yrange"],
153 xlabel => "Time [h]", timeaxis => 'x', xtics => {labelfmt => '%H:%M', rotate => '-270',},
154 legend => { position => "outside right",},
155 grid => 'on',);
156 my $chart_o = Chart::Gnuplot->new(
157 output => $pngName_o, terminal => 'png', title => "Out of plane component",
158 ylabel => "Orbit Difference [m]", yrange => ["-$yrange", "$yrange"],
159 xlabel => "Time [h]", timeaxis => 'x', xtics => {labelfmt => '%H:%M', rotate => '-270',},
160 legend => { position => "outside right",},
161 grid => 'on',);
162 #SATELLITE
163 foreach my $key_sat (sort keys %{$COMPARISON{$key_sys}}) {
164 my $colour = sprintf("%d", (substr $key_sat, -2)+1);
165 #RADIAL
166 my $dataset_r = Chart::Gnuplot::DataSet->new(
167 xdata => \@{$COMPARISON{$key_sys}{$key_sat}{EPOCH}},
168 ydata => \@{$COMPARISON{$key_sys}{$key_sat}{RADIAL}},
169 title => "$key_sat",
170 timefmt => '%Y-%m-%d_%H:%M:%S',
171 linetype => $colour,
172 #style => " linespoints ",);
173 style => " lines ",);
174 push (@datasets_r, $dataset_r);
175 # ALONG TRACK
176 my $dataset_a = Chart::Gnuplot::DataSet->new(
177 xdata => \@{$COMPARISON{$key_sys}{$key_sat}{EPOCH}},
178 ydata => \@{$COMPARISON{$key_sys}{$key_sat}{ALONG}},
179 title => "$key_sat",
180 timefmt => '%Y-%m-%d_%H:%M:%S',
181 linetype => $colour,
182 style => " lines ",);
183 push (@datasets_a, $dataset_a);
184 # OUT OF PLANE
185 my $dataset_o = Chart::Gnuplot::DataSet->new(
186 xdata => \@{$COMPARISON{$key_sys}{$key_sat}{EPOCH}},
187 ydata => \@{$COMPARISON{$key_sys}{$key_sat}{OUT}},
188 title => "$key_sat",
189 timefmt => '%Y-%m-%d_%H:%M:%S',
190 linetype => $colour,
191 style => " lines",);
192 push (@datasets_o, $dataset_o);
193 }
194 $chart_r->plot2d(@datasets_r);
195 $chart_a->plot2d(@datasets_a);
196 $chart_o->plot2d(@datasets_o);
197 # RADIAL
198 $y = $y - $dy;
199 if($y < 30/mm) {
200 $page = $pdf->page(); $page->mediabox('A4');
201 $y = $y0;
202 }
203 $png = $page->gfx(); die("Unable to find image file: $!") unless -e $pngName_r;
204 $png->image($pdf->image_png($pngName_r), $x, $y, $width, $height);
205 # ALONG
206 $y = $y - $dy;
207 if($y < 30/mm) {
208 $page = $pdf->page(); $page->mediabox('A4');
209 $y = $y0;
210 }
211 $png = $page->gfx(); die("Unable to find image file: $!") unless -e $pngName_a;
212 $png->image($pdf->image_png($pngName_a), $x, $y, $width, $height);
213 # OUT
214 $y = $y - $dy;
215 if($y < 30/mm) {
216 $page = $pdf->page(); $page->mediabox('A4');
217 $y = $y0;
218 }
219 $png = $page->gfx(); die("Unable to find image file: $!") unless -e $pngName_o;
220 $png->image($pdf->image_png($pngName_o), $x, $y, $width, $height);
221 }
222 }
223 ######## CLK / CLKRED #####################
224 if (("ALL" ~~ @plotTypes ) || ("CLK" ~~ @plotTypes)) {
225 print "Plot CLOCK and CLOCK REDUCED BY RADIAL COMPONENT ...\n";
226 my $yrange = 0.6;
227 $page = $pdf->page(); $page->mediabox('A4');
228 $headline = sprintf("Clock residuals and reduced clock residuals(%s)", $inputFilename);
229 $headline_text = $page->text;
230 $headline_text->font($font1, 11/pt);
231 $headline_text->translate(15/mm, 280/mm);
232 $headline_text->text($headline);
233 $y = $y0+$dy;
234 #SYSTEM
235 foreach my $key_sys (sort keys %COMPARISON) {
236 print " for $key_sys\n";
237 my (@datasets_c, @datasets_r); # init datasets
238 my $pngName_c = sprintf ("%s_CLK_%s.png", $inputFilename, $key_sys);
239 push @pngFiles, $pngName_c;
240 my $pngName_r = sprintf ("%s_CLKRED_%s.png", $inputFilename, $key_sys);
241 push @pngFiles, $pngName_r;
242 my $chart_c = Chart::Gnuplot->new(
243 output => $pngName_c, terminal => 'png',title => "Clock only",
244 ylabel => "Clock Residuals [m]", yrange => ["-$yrange", "$yrange"],
245 xlabel => "Time [h]", timeaxis => 'x', xtics => {labelfmt => '%H:%M', rotate => '-270',},
246 legend => { position => "outside right",},
247 grid => 'on',);
248 my $chart_r = Chart::Gnuplot->new(
249 output => $pngName_r, terminal => 'png',title => "Clock minus radial component",
250 ylabel => "Clock Residuals [m]", yrange => ["-$yrange", "$yrange"],
251 xlabel => "Time [h]", timeaxis => 'x', xtics => {labelfmt => '%H:%M', rotate => '-270',},
252 legend => { position => "outside right",},
253 grid => 'on',);
254 #SATELLITE
255 foreach my $key_sat (sort keys %{$COMPARISON{$key_sys}}) {
256 my $colour = sprintf("%d", (substr $key_sat, -2)+1);
257 # CLK
258 my $dataset_c = Chart::Gnuplot::DataSet->new(
259 xdata => \@{$COMPARISON{$key_sys}{$key_sat}{EPOCH}},
260 ydata => \@{$COMPARISON{$key_sys}{$key_sat}{CLK}},
261 title => "$key_sat",
262 timefmt => '%Y-%m-%d_%H:%M:%S',
263 linetype => $colour,
264 style => " lines ",);
265 push (@datasets_c, $dataset_c);
266 my ( $min, $max ) = minmax @{$COMPARISON{$key_sys}{$key_sat}{CLK}};
267 if ($max > 1.0) {print "$key_sat: max clk = $max\n"};
268 # CLKRED
269 my $dataset_r = Chart::Gnuplot::DataSet->new(
270 xdata => \@{$COMPARISON{$key_sys}{$key_sat}{EPOCH}},
271 ydata => \@{$COMPARISON{$key_sys}{$key_sat}{CLKRED}},
272 title => "$key_sat",
273 timefmt => '%Y-%m-%d_%H:%M:%S',
274 linetype => $colour,
275 style => " lines ",);
276 push (@datasets_r, $dataset_r);
277 }
278 $chart_c->plot2d(@datasets_c);
279 $chart_r->plot2d(@datasets_r);
280 # CLK
281 $y = $y - $dy;
282 if($y < 30/mm) {
283 $page = $pdf->page(); $page->mediabox('A4');
284 $y = $y0;
285 }
286 $png = $page->gfx(); die("Unable to find image file: $!") unless -e $pngName_c;
287 $png->image($pdf->image_png($pngName_c), $x, $y, $width, $height);
288 # CLKRED
289 $y = $y - $dy;
290 if($y < 30/mm) {
291 $page = $pdf->page(); $page->mediabox('A4');
292 $y = $y0;
293 }
294 $png = $page->gfx(); die("Unable to find image file: $!") unless -e $pngName_r;
295 $png->image($pdf->image_png($pngName_r), $x, $y, $width, $height);
296 }
297 }
298 ######## SIS #####################
299 if (("ALL" ~~ @plotTypes ) || ("SIS" ~~ @plotTypes)) {
300 print "Plot SIGNAL-IN-SPACE DIFFERENCES (RADIAL MINUS CLOCK) ...\n";
301 $page = $pdf->page(); $page->mediabox('A4');
302 $headline = sprintf("Signal-in-space differences, radial minus clock, incl. satellite offsets (%s)", $inputFilename);
303 $headline_text = $page->text;
304 $headline_text->font($font1, 11/pt);
305 $headline_text->translate(15/mm, 280/mm);
306 $headline_text->text($headline);
307 $y = $y0+$dy;
308 #SYSTEM
309 foreach my $key_sys (sort keys %COMPARISON) {
310 my @sats = grep { exists $COMPARISON{$key_sys}{$_}{SIS} } sort keys %{$COMPARISON{$key_sys}};
311 next unless @sats;
312 print " for $key_sys\n";
313 my @datasets_s; # init datasets
314 my $pngName_s = sprintf ("%s_SIS_%s.png", $inputFilename, $key_sys);
315 push @pngFiles, $pngName_s;
316 # SIS contains the satellite offsets: y range from the data
317 my $maxAbs = 0.1;
318 foreach my $key_sat (@sats) {
319 my ( $min, $max ) = minmax @{$COMPARISON{$key_sys}{$key_sat}{SIS}};
320 $maxAbs = abs($min) if abs($min) > $maxAbs;
321 $maxAbs = abs($max) if abs($max) > $maxAbs;
322 }
323 my $chart_s = Chart::Gnuplot->new(
324 output => $pngName_s, terminal => 'png',title => "SIS (radial minus clock)",
325 ylabel => "SIS Difference [m]", yrange => ["-$maxAbs", "$maxAbs"],
326 xlabel => "Time [h]", timeaxis => 'x', xtics => {labelfmt => '%H:%M', rotate => '-270',},
327 legend => { position => "outside right",},
328 grid => 'on',);
329 #SATELLITE
330 foreach my $key_sat (@sats) {
331 my $colour = sprintf("%d", (substr $key_sat, -2)+1);
332 my $dataset_s = Chart::Gnuplot::DataSet->new(
333 xdata => \@{$COMPARISON{$key_sys}{$key_sat}{EPOCH_SIS}},
334 ydata => \@{$COMPARISON{$key_sys}{$key_sat}{SIS}},
335 title => "$key_sat",
336 timefmt => '%Y-%m-%d_%H:%M:%S',
337 linetype => $colour,
338 style => " lines ",);
339 push (@datasets_s, $dataset_s);
340 }
341 $chart_s->plot2d(@datasets_s);
342 $y = $y - $dy;
343 if($y < 30/mm) {
344 $page = $pdf->page(); $page->mediabox('A4');
345 $y = $y0;
346 }
347 $png = $page->gfx(); die("Unable to find image file: $!") unless -e $pngName_s;
348 $png->image($pdf->image_png($pngName_s), $x, $y, $width, $height);
349 }
350 }
351 $pdf->save();
352 $pdf->end();
353 unlink @pngFiles unless $keepImages; # only the images written here
354 @pngFiles = ();
355}
356
357
358#########################################
359sub help {
360 print <<EOI_HILFE;
361CALL:
362 compareSp3Plot.pl [paramter]
363
364PARAMETER:
365
366 --plotTypes possible: ALL (default) => RAO, CLOCK and SIS; CLK => CLOCK and CLOCKRED; RAO => RAO only;
367 SIS => signal-in-space differences (radial minus clock) only
368 --logFiles comma separated list of BNC's SP3 comparison logfiles
369 --keepImages keep the PNG images of the plots (deleted after inclusion in the PDF by default)
370 --help show help contents
371
372DESCRIPTION:
373
374 Script to plot BNC's SP3 Comparison Results
375
376EOI_HILFE
377exit;
378}
Note: See TracBrowser for help on using the repository browser.