rinex-cli 0.9.7

Command line tool parse and analyze RINEX data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
use clap::{Arg, ArgAction, ArgMatches, ColorChoice, Command};
use log::{error, info};

use std::path::Path;
use std::str::FromStr;

use rinex::prelude::*;
use rinex_qc::QcOpts;

use gnss_rtk::prelude::Config;

pub struct Cli {
    /// Arguments passed by user
    matches: ArgMatches,
}

impl Default for Cli {
    fn default() -> Self {
        Self::new()
    }
}

impl Cli {
    /// Build new command line interface
    pub fn new() -> Self {
        Self {
            matches: {
                Command::new("rinex-cli")
                    .author("Guillaume W. Bres, <guillaume.bressaix@gmail.com>")
                    .version(env!("CARGO_PKG_VERSION"))
                    .about("RINEX analysis and processing tool")
                    .arg_required_else_help(true)
                    .color(ColorChoice::Always)
                    .arg(Arg::new("filepath")
                        .short('f')
                        .long("fp")
                        .value_name("FILE")
                        .action(ArgAction::Append)
                        .required_unless_present("directory")
                        .help("Input RINEX file. Can be any kind of RINEX, or an SP3 file,
and you can load as many as you want."))
                    .arg(Arg::new("directory")
                        .short('d')
                        .long("dir")
                        .value_name("DIRECTORY")
                        .action(ArgAction::Append)
                        .required_unless_present("filepath")
                        .help("Load directory recursively. RINEX and SP3 files are identified
and added like they were individually imported with -f.
You can import as many directories as you need."))
                    .arg(Arg::new("quiet")
                        .short('q')
                        .long("quiet")
                        .action(ArgAction::SetTrue)
                        .help("Disable all terminal output. Also disables auto HTML reports opener."))
                    .arg(Arg::new("pretty-json")
                        .short('j')
                        .long("json")
                        .action(ArgAction::SetTrue)
                        .help("Make JSON output more readable."))
                    .arg(Arg::new("workspace")
                        .short('w')
                        .long("workspace")
                        .value_name("FOLDER")
                        .help("Customize workspace location (folder does not have to exist).
The default workspace is rinex-cli/workspace"))
                    .arg(Arg::new("no-graph")
                        .long("no-graph")
                        .action(ArgAction::SetTrue)
                        .help("Disable graphs generation, only text reports are to be generated."))
                .next_help_heading("Data generation")
					.arg(Arg::new("gpx")
						.long("gpx")
                        .action(ArgAction::SetTrue)
						.help("Enable GPX formatting. In RTK mode, a GPX track is generated."))
					.arg(Arg::new("kml")
						.long("kml")
                        .action(ArgAction::SetTrue)
						.help("Enable KML formatting. In RTK mode, a KML track is generated."))
                    .arg(Arg::new("output")
                        .short('o')
                        .long("out")
                        .value_name("FILE")
                        .action(ArgAction::Append)
                        .help("Custom file name to be generated within Workspace.
Allows merged file name to be customized."))
                .next_help_heading("Data identification")
                    .arg(Arg::new("full-id")
                        .short('i')
                        .action(ArgAction::SetTrue)
                        .help("Turn all identifications ON"))
                    .arg(Arg::new("epochs")
                        .long("epochs")
                        .action(ArgAction::SetTrue)
                        .help("Enumerate all epochs"))
                    .arg(Arg::new("gnss")
                        .long("gnss")
                        .short('g')
                        .action(ArgAction::SetTrue)
                        .help("Enumerate GNSS constellations present in entire context."))
                    .arg(Arg::new("sv")
                        .long("sv")
                        .action(ArgAction::SetTrue)
                        .help("Enumerate Sv"))
                    .arg(Arg::new("sampling")
                        .long("sampling")
                        .action(ArgAction::SetTrue)
                        .help("Sample rate analysis."))
                    .arg(Arg::new("header")
                        .long("header")
                        .action(ArgAction::SetTrue)
                        .help("Extracts major header fields"))
                .next_help_heading("Preprocessing")
                    .arg(Arg::new("gps-filter")
                        .short('G')
                        .action(ArgAction::SetTrue)
                        .help("Filters out all GPS vehicles"))
                    .arg(Arg::new("glo-filter")
                        .short('R')
                        .action(ArgAction::SetTrue)
                        .help("Filters out all Glonass vehicles"))
                    .arg(Arg::new("gal-filter")
                        .short('E')
                        .action(ArgAction::SetTrue)
                        .help("Filters out all Galileo vehicles"))
                    .arg(Arg::new("bds-filter")
                        .short('C')
                        .action(ArgAction::SetTrue)
                        .help("Filters out all BeiDou vehicles"))
                    .arg(Arg::new("qzss-filter")
                        .short('J')
                        .action(ArgAction::SetTrue)
                        .help("Filters out all QZSS vehicles"))
                    .arg(Arg::new("irnss-filter")
                        .short('I')
                        .action(ArgAction::SetTrue)
                        .help("Filters out all IRNSS vehicles"))
                    .arg(Arg::new("sbas-filter")
                        .short('S')
                        .action(ArgAction::SetTrue)
                        .help("Filters out all SBAS vehicles"))
					.arg(Arg::new("preprocessing")
						.short('P')
						.num_args(1..)
                        .action(ArgAction::Append)
						.help("Design preprocessing operations, like data filtering or resampling,
prior further analysis. You can stack as many ops as you need.
Preprocessing ops apply prior entering both -q and --rtk modes.
Refer to rinex-cli/doc/preprocessing.md to learn how to operate this interface."))
                .next_help_heading("Observation RINEX")
                    .arg(Arg::new("observables")
                        .long("observables")
                        .long("obs")
                        .action(ArgAction::SetTrue)
                        .help("Identify observables in either Observation Data or Meteo Data contained in context."))
                    .arg(Arg::new("ssi-range")
                        .long("ssi-range")
                        .action(ArgAction::SetTrue)
                        .help("Display SSI (min,max) range, accross all epochs and vehicles"))
                    .arg(Arg::new("lli-mask")
                        .long("lli-mask")
                        .help("Applies given LLI AND() mask. 
Also drops observations that did not come with an LLI flag"))
                    .arg(Arg::new("if")
                        .long("if")
                        .action(ArgAction::SetTrue)
                        .help("Ionosphere Free combination graph"))
                    .arg(Arg::new("gf")
                        .long("gf")
                        .action(ArgAction::SetTrue)
                        .conflicts_with("no-graph")
                        .help("Geometry Free combination graph"))
                    .arg(Arg::new("wl")
                        .long("wl")
                        .action(ArgAction::SetTrue)
                        .conflicts_with("no-graph")
                        .help("Wide Lane combination graph"))
                    .arg(Arg::new("nl")
                        .long("nl")
                        .action(ArgAction::SetTrue)
                        .conflicts_with("no-graph")
                        .help("Narrow Lane combination graph"))
                    .arg(Arg::new("mw")
                        .long("mw")
                        .action(ArgAction::SetTrue)
                        .conflicts_with("no-graph")
                        .help("Melbourne-Wübbena combination graph"))
                    .arg(Arg::new("dcb")
                        .long("dcb")
                        .action(ArgAction::SetTrue)
                        .conflicts_with("no-graph")
                        .help("Differential Code Bias analysis"))
                    .arg(Arg::new("multipath")
                        .long("mp")
                        .action(ArgAction::SetTrue)
                        .conflicts_with("no-graph")
                        .help("Code Multipath analysis"))
                    .arg(Arg::new("anomalies")
                        .short('a')
                        .long("anomalies")
                        .action(ArgAction::SetTrue)
                        .help("Enumerate epochs where anomalies were reported by the receiver"))
                    .arg(Arg::new("cs")
                        .long("cs")
                        .action(ArgAction::SetTrue)
                        .help("Cycle Slip detection (graphical).
Helps visualize what the CS detector is doing and fine tune its operation.
CS do not get repaired with this command.
If you're just interested in CS information, you probably just want `-qc` instead, avoid combining the two."))
                    .arg(Arg::new("antenna-ecef")
                        .long("antenna-ecef")
                        .value_name("\"x,y,z\" coordinates in ECEF [m]")
                        .help("Define the (RX) antenna ground position manualy, in [m] ECEF system.
Some calculations require a reference position.
Ideally this information is contained in the file Header, but user can manually define them (superceeds)."))
                    .arg(Arg::new("antenna-lla")
                        .long("antenna-lla")
                        .value_name("\"lat,lon,alt\" coordinates in ddeg [°]")
                        .help("Define the (RX) antenna ground position manualy, in decimal degrees.
Some calculations require a reference position.
Ideally this information is contained in the file Header, but user can manually define them (superceeds)."))
                    .arg(Arg::new("nav-msg")
                        .long("nav-msg")
                        .action(ArgAction::SetTrue)
                        .help("Identify Navigation frame types. -fp must be a NAV file")) 
                    .arg(Arg::new("clock-bias")
                        .long("clock-bias")
                        .action(ArgAction::SetTrue)
                        .help("Display clock biases (offset, drift, drift changes) per epoch and vehicle.
-fp must be a NAV file"))
                .next_help_heading("Quality Check (QC)")
                    .arg(Arg::new("qc")
                        .long("qc")
                        .action(ArgAction::SetTrue)
                        .help("Enable Quality Check (QC) mode.
Runs thorough analysis on provided RINEX data.
The summary report by default is integrated to the global HTML report."))
					.arg(Arg::new("qc-config")
						.long("qc-cfg")
						.value_name("FILE")
						.help("Pass a QC configuration file."))
                    .arg(Arg::new("qc-only")
                        .long("qc-only")
                        .action(ArgAction::SetTrue)
                        .help("Activates QC mode and disables all other features: quickest qc rendition."))
                .next_help_heading("Positioning")
                    .arg(Arg::new("positioning")
                        .short('p')
                        .action(ArgAction::SetTrue)
                        .help("Activate positioning mode. Disables all other modes.
Use with ${RUST_LOG} env logger for more information.
Refer to the positioning documentation."))
					.arg(Arg::new("config")
						.long("cfg")
                        .short('c')
						.value_name("FILE")
						.help("Pass Positioning configuration, refer to doc/positioning."))
                .next_help_heading("File operations")
                    .arg(Arg::new("merge")
                        .short('m')
                        .long("merge")
                        .value_name("FILE(s)")
                        .action(ArgAction::Append)
                        .help("Merge given RINEX this RINEX into primary RINEX.
Primary RINEX was either loaded with `-f`, or is Observation RINEX loaded with `-d`"))
                    .arg(Arg::new("split")
                        .long("split")
                        .value_name("Epoch")
                        .short('s')
                        .help("Split RINEX into two separate files"))
                    .get_matches()
            },
        }
    }
    /// Returns list of input directories
    pub fn input_directories(&self) -> Vec<&String> {
        if let Some(fp) = self.matches.get_many::<String>("directory") {
            fp.collect()
        } else {
            Vec::new()
        }
    }
    /// Returns individual input filepaths
    pub fn input_files(&self) -> Vec<&String> {
        if let Some(fp) = self.matches.get_many::<String>("filepath") {
            fp.collect()
        } else {
            Vec::new()
        }
    }
    /// Returns output filepaths
    pub fn output_path(&self) -> Option<&String> {
        self.matches.get_one::<String>("output")
    }
    pub fn preprocessing(&self) -> Vec<&String> {
        if let Some(filters) = self.matches.get_many::<String>("preprocessing") {
            filters.collect()
        } else {
            Vec::new()
        }
    }
    pub fn quality_check(&self) -> bool {
        self.matches.get_flag("qc")
    }
    fn qc_config_path(&self) -> Option<&String> {
        if let Some(path) = self.matches.get_one::<String>("qc-config") {
            Some(path)
        } else {
            None
        }
    }
    pub fn qc_config(&self) -> QcOpts {
        if let Some(path) = self.qc_config_path() {
            if let Ok(content) = std::fs::read_to_string(path) {
                let opts = serde_json::from_str(&content);
                if let Ok(opts) = opts {
                    info!("qc parameter file \"{}\"", path);
                    opts
                } else {
                    error!("failed to parse parameter file \"{}\"", path);
                    info!("using default parameters");
                    QcOpts::default()
                }
            } else {
                error!("failed to read parameter file \"{}\"", path);
                info!("using default parameters");
                QcOpts::default()
            }
        } else {
            QcOpts::default()
        }
    }
    pub fn quality_check_only(&self) -> bool {
        self.matches.get_flag("qc-only")
    }
    pub fn gps_filter(&self) -> bool {
        self.matches.get_flag("gps-filter")
    }
    pub fn glo_filter(&self) -> bool {
        self.matches.get_flag("glo-filter")
    }
    pub fn gal_filter(&self) -> bool {
        self.matches.get_flag("gal-filter")
    }
    pub fn bds_filter(&self) -> bool {
        self.matches.get_flag("bds-filter")
    }
    pub fn qzss_filter(&self) -> bool {
        self.matches.get_flag("qzss-filter")
    }
    pub fn sbas_filter(&self) -> bool {
        self.matches.get_flag("sbas-filter")
    }
    pub fn irnss_filter(&self) -> bool {
        self.matches.get_flag("irnss-filter")
    }
    pub fn gf_combination(&self) -> bool {
        self.matches.get_flag("gf")
    }
    pub fn if_combination(&self) -> bool {
        self.matches.get_flag("if")
    }
    pub fn wl_combination(&self) -> bool {
        self.matches.get_flag("wl")
    }
    pub fn nl_combination(&self) -> bool {
        self.matches.get_flag("nl")
    }
    pub fn mw_combination(&self) -> bool {
        self.matches.get_flag("mw")
    }
    pub fn identification(&self) -> bool {
        self.matches.get_flag("sv")
            | self.matches.get_flag("epochs")
            | self.matches.get_flag("header")
            | self.matches.get_flag("observables")
            | self.matches.get_flag("ssi-range")
            | self.matches.get_flag("nav-msg")
            | self.matches.get_flag("anomalies")
            | self.matches.get_flag("sampling")
            | self.matches.get_flag("full-id")
    }
    /// Returns true if Sv accross epoch display is requested
    pub fn sv_epoch(&self) -> bool {
        self.matches.get_flag("sv-epoch")
    }
    /// Phase /PR DCBs analysis requested
    pub fn dcb(&self) -> bool {
        self.matches.get_flag("dcb")
    }
    /// Code Multipath analysis requested
    pub fn multipath(&self) -> bool {
        self.matches.get_flag("multipath")
    }
    /// Returns list of requested data to extract
    pub fn identification_ops(&self) -> Vec<&str> {
        if self.matches.get_flag("full-id") {
            vec![
                "sv",
                "epochs",
                "gnss",
                "observables",
                "ssi-range",
                "nav-msg",
                "anomalies",
                "sampling",
            ]
        } else {
            let flags = [
                "sv",
                "header",
                "sampling",
                "epochs",
                "gnss",
                "observables",
                "ssi-range",
                "nav-msg",
                "anomalies",
            ];
            flags
                .iter()
                .filter(|x| self.matches.get_flag(x))
                .copied()
                .collect()
        }
    }
    fn get_flag(&self, flag: &str) -> bool {
        self.matches.get_flag(flag)
    }
    /// returns true if pretty JSON is requested
    pub fn pretty_json(&self) -> bool {
        self.get_flag("pretty-json")
    }
    /// Returns true if quiet mode is activated
    pub fn quiet(&self) -> bool {
        self.matches.get_flag("quiet")
    }
    pub fn positioning(&self) -> bool {
        self.matches.get_flag("positioning")
    }
    pub fn gpx(&self) -> bool {
        self.matches.get_flag("gpx")
    }
    pub fn kml(&self) -> bool {
        self.matches.get_flag("kml")
    }
    pub fn config(&self) -> Option<Config> {
        if let Some(path) = self.matches.get_one::<String>("config") {
            if let Ok(content) = std::fs::read_to_string(path) {
                let opts = serde_json::from_str(&content);
                if let Ok(opts) = opts {
                    info!("loaded rtk config: \"{}\"", path);
                    return Some(opts);
                } else {
                    panic!("failed to parse config file \"{}\"", path);
                }
            } else {
                error!("failed to read config file \"{}\"", path);
                info!("using default parameters");
            }
        }
        None
    }
    pub fn cs_graph(&self) -> bool {
        self.matches.get_flag("cs")
    }
    /*
     * No graph to be generated
     */
    pub fn no_graph(&self) -> bool {
        self.matches.get_flag("no-graph")
    }
    /*
     * Returns possible file path to merge
     */
    pub fn merge_path(&self) -> Option<&Path> {
        self.matches.get_one::<String>("merge").map(Path::new)
    }
    /// Returns optionnal RINEX file to "merge"
    pub fn to_merge(&self) -> Option<Rinex> {
        if let Some(path) = self.merge_path() {
            let path = path.to_str().unwrap();
            match Rinex::from_file(path) {
                Ok(rnx) => Some(rnx),
                Err(e) => {
                    error!("failed to parse \"{}\", {}", path, e);
                    None
                },
            }
        } else {
            None
        }
    }
    /// Returns split operation args
    pub fn split(&self) -> Option<Epoch> {
        if self.matches.contains_id("split") {
            if let Some(s) = self.matches.get_one::<String>("split") {
                if let Ok(epoch) = Epoch::from_str(s) {
                    Some(epoch)
                } else {
                    panic!("failed to parse [EPOCH]");
                }
            } else {
                None
            }
        } else {
            None
        }
    }
    fn manual_ecef(&self) -> Option<&String> {
        self.matches.get_one::<String>("antenna-ecef")
    }
    fn manual_geodetic(&self) -> Option<&String> {
        self.matches.get_one::<String>("antenna-geo")
    }
    /// Returns Ground Position possibly specified by user
    pub fn manual_position(&self) -> Option<GroundPosition> {
        if let Some(args) = self.manual_ecef() {
            let content: Vec<&str> = args.split(',').collect();
            if content.len() != 3 {
                panic!("expecting \"x, y, z\" description");
            }
            if let Ok(pos_x) = f64::from_str(content[0].trim()) {
                if let Ok(pos_y) = f64::from_str(content[1].trim()) {
                    if let Ok(pos_z) = f64::from_str(content[2].trim()) {
                        return Some(GroundPosition::from_ecef_wgs84((pos_x, pos_y, pos_z)));
                    } else {
                        error!("pos(z) should be f64 ECEF [m]");
                    }
                } else {
                    error!("pos(y) should be f64 ECEF [m]");
                }
            } else {
                error!("pos(x) should be f64 ECEF [m]");
            }
        } else if let Some(args) = self.manual_geodetic() {
            let content: Vec<&str> = args.split(',').collect();
            if content.len() != 3 {
                panic!("expecting \"lat, lon, alt\" description");
            }
            if let Ok(lat) = f64::from_str(content[0].trim()) {
                if let Ok(long) = f64::from_str(content[1].trim()) {
                    if let Ok(alt) = f64::from_str(content[2].trim()) {
                        return Some(GroundPosition::from_geodetic((lat, long, alt)));
                    } else {
                        error!("altitude should be f64 [ddeg]");
                    }
                } else {
                    error!("altitude should be f64 [ddeg]");
                }
            } else {
                error!("altitude should be f64 [ddeg]");
            }
        }
        None
    }
    pub fn workspace(&self) -> Option<&String> {
        self.matches.get_one::<String>("workspace")
    }
}