rinex-cli 0.4.1

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
RINEX-cli 
=========

Command line tool to parse, analyze and manage RINEX files.  

[![crates.io](https://img.shields.io/crates/v/rinex-cli.svg)](https://crates.io/crates/rinex-cli)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/gwbres/rinex/blob/main/LICENSE-APACHE)
[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/gwbres/rinex/blob/main/LICENSE-MIT) 

The first purpose of this tool is to expose the [library](https://github.com/gwbres/rinex/rinex) 
in a high level and easy to use fashion.  
The application will be able to parse all RINEX formats supported by the library, refer to its documentation.

The application knows a few `teqc` operations, refer to the
[dedicated paragraph](https://github.com/gwbres/rinex/blob/main/rinex-cli/README.md#teqc-operations)
down below.

This tool will eventually be able to perform most common RINEX 
[post-processing](https://github.com/gwbres/rinex/blob/main/rinex-cli/README.md#post-processing).

## File formats

The application can parse and produce all formats supported by the [library](https://github.com/gwbres/rinex) 

### File naming conventions

File names are disregarded by these tools, you can analyze
& parse files that do not follow naming conventions.

When producing data, this tool will eventually help the user to generate RINEX that follows
naming conventions, but that is currently under development.

### Compressed data

This tool supports gzip compressed files, as long as their name is terminated
by `.gz`, so it can detect the need of invoking the decompression routine.

This tool also supports `CRINEX` (V1, v3) natively, as these declinations
are amonsgt supported formats

## `teqc` operations

`teqc` is a well known application to process RINEX.  

Unlike `teqc`, this application is not capable of processing Binary RINEX ("BINEX") and 
proprietary formats in general.

Here is the list of operations that this tool is capable of performing,
that usually people use `teqc` almost exclusively to perform, to this day

- [merge]https://github.com/gwbres/rinex/blob/main/rinex-cli/README.md#merge
several RINEX together into a single file.

- [decimate]https://github.com/gwbres/rinex/blob/main/rinex-cli/README.md#decimate
RINEX record to reduce the quantity of data to analyze

- [split]https://github.com/gwbres/rinex/blob/main/rinex-cli/README.md#split
given file(s) into two

- [ascii-plot]https://github.com/gwbres/rinex/blob/main/rinex-cli/README.md#ascii-plot
to print a very descriptive tiny plot in the terminal,
as contained in reports generated by `teqc`

## Graphical view

Graphical view is currently under development is not available at the moment. 
Only terminal / stdout visualization exists to this day.

## Getting started

This application is managed by `cargo`, therefore `cargo build` is the way to build it.

```bash
cargo build
cargo build --release
```

You have two options to invoke the application (command line interface)

- [1] either, at the root of this repo (/rinex), directly invoke the binary that was generated by the previous step
- [2] or, inside the application folder (/rinex/rinex-cli), using `cargo run`

```bash
# [1]
cd ../
./target/debug/rinex-cli --help
./target/release/rinex-cli --help

# [2]
cd rinex-cli
cargo run -- --help
``` 

Command line arguments order does not matter for the application.   
`filepath` is the only mandatory argument, other flags are optional.

Major arguments have an abbreviation:

```bash
cargo run --filepath /tmp/amel010.21g
cargo run -f /tmp/amel010.21g
```

Some arguments support an array of values to be given.
In this case, we use a comma seperated format to describe the values.
Whitespaces are not allowed in the description

```bash
rinex-cli \
     -f test_resources/OBS/V2/rovn0010.21o,test_resources/OBS/V3/DUTH0630.22O
```

## Tool philosophy

Invoke the tool against one or several files.  
Several files might be required based on the operation to perform (`help`).  
All flags are optionnal and can be combined.  
If you request some operation, usually to inspect the internal data (like `epoch` or `sv`),
the tool will not expose the record but will restrict to the requested information.

For example, this command line will expose identified epochs and identified vehicules

```bash
rinex-cli -f /tmp/amel010.21g --epoch --sv
``` 

If no specific data or fields are requested to be displayed, then we expose the record

```bash
rinex-cli -f /tmp/amel010.21g
``` 

Several filtering operations exist, and they can be conbimed to all other operations.  
This applies to all command line arguments terminated by `-filter`.  
For example running this command
will perform the previous operation but on reduced data

```bash
rinex-cli -f /tmp/amel010.21g --epoch --sv-filter R01,G01
``` 

And this command gives a more meaningful record visualization

```bash
rinex-cli --pretty -f test_resources/OBS/V2/amel010.21g \
      --decimate-interval 00:05:00 \
            --sv-filter G01
``` 

When several files are given through `-fp`, we simply apply the previous
to every single file.

## Output format

This tool uses JSON format to expose data, which makes it easy
to import into other tools. The `--pretty` argument is available
and can be combined to all existing flags, to indent the exposed data,
and make it easier to read

```bash
rinex-cli --pretty -f /tmp/amel010.21g \
      --epoch --sv-filter R01,G01 

rinex-cli -f /tmp/amel010.21g \
      --decimate-interval 00:05:00 \
            --sv-filter G01 --pretty
``` 

## Decimate

To reduce the record size, we use decimation

- either by an integer ratio
- or by a minimum epoch interval ("sampling interval") to respect

With this command, we reduce the record size by 2 :
```bash
# print initial epochs
rinex-cli --epoch --pretty -f test_resources/OBS/V2/zegv0010.21o

# reduce by 2
rinex-cli -f test_resources/OBS/V2/zegv0010.21o \
    --decimate-interval 00:01:00 # 1' interval, 00:00:30 epochs get dropped out

# with is actually equivalent to    
rinex-cli -f test_resources/OBS/V2/zegv0010.21o \
       --decimate-ratio 2 # but no knowledge of the resulting "sample" rate 
```

## Epoch events filter

Some RINEX files like Observation Data 
associate an epoch flag to each epoch.  
Filtering on epoch events is an easy and meaningful way to reduce the record size

* --epoch-ok-filter : will only retain valid epochs
* --epoch-nok-filter : will only retain epochs
where the associated flag is not Ok (> 0)

## Satellite vehicule filter

It is possible to filter by constellation or by vehicule of interest

```bash
# display encountered constellations and space vehicules
rinex-cli --constellations --sv \
       -f test_resources/OBS/V2/zegv0010.21o

# focus on Glonnass
rinex-cli  --pretty  --constellation-filter GLO \
             -f test_resources/OBS/V2/zegv0010.21o

# focus on G10, R09 and R08
crinex-cli  --pretty --sv-filter G10,R09,R08 \
     -f test_resources/OBS/V2/zegv0010.21o
```

## Signal condition filters

Observation data might have an "LLI" flag attached to them.
It is possible to apply an And() mask on this field. In this case,
all epochs that did not come with an LLI flag get also dropped out.

In this example, we focus on epochs where a `Loss of Lock` event happened

```shell
rinex-cli --pretty --lli-mask 1 --sv R01 \ 
          -f test_resources/OBS/V2/zegv0010.21o
```

SSI field is another data field that might come with an observation
and it gives the estimated receiver power / SNR at the sampling instant.

It is possible to filter data on minimum signal strength, which
is equivalent to a data "quality" filter

With the following command, we only retain data with SSI >= 5
that means at least 30 dB SNR. 

```shell
rinex-cli --pretty -f test_resources/OBS/V2/zegv0010.21o \
        --ssi-filter 5 --sv-filter R01
```

## Observables

It is possible to filter on "observables", ie., physics or data of interest.

```bash
# list encountered "observables"
rinex-cli -f test_resources/OBS/V3/CBW100NLD_R_20210010000_01D_MN.rnx --observ

# extract raw phase data and pseudo range only
rinex-cli -f test_resources/OBS/V2/zegv0010.21o  \
    --observ-filter C1
```

## Post processing

Some post processing operations are being developped. People usually perform them with tools like `rtklib`.
This application does not aim at matching what `rtklib` is capable of, but it can be a powerful and efficient
alternative to similarly supported operations

## Differential RINEX

Differential RINEX is the operation rnx(a) - rnx(b) where both are Observation RINEX
assumed to be sampled by stationnary and close to each other different receivers.
This simple operation cancels out ionospheric biases.

Provide at least two OBS files for this operation to work.  
Here we differentiante zegv0010.21o using delf0010.21o.  
This is only a command line example, it does not produce anything meaningful because delf0010.21o does not share
any common epoch with zegv0010.21o

```bash
rinex-cli --diff -f test_resources/OBS/V2/zegv0010.21o,test_resources/OBS/V2/delf0010.21o
```

The operation is described in the API [right here](https://docs.rs/rinex/latest/rinex/struct.Rinex.html#method.diff_mut).

## Double Differential RINEX

Double Differential RINEX is first a rnx(a) - rnx(b) operation, previously described,
then another differentiation where a specific satellite vehicule is defined
as reference, for a given epoch and a given constellation.
We define the reference vehicule as the one closest to zenith.
To determine such information, we need Navigation ephemeris to be provided too.

This operation requires at least 2 OBS files and 1 NAV file to be provided.
The (A) and (B) role in the `diff` operation is determined by order of appearance
of the Observation files in the command line: 
* first encountered is (A)
* last encountered is (B)

The order of appearance of the NAV file does not matter.

For example, this command will expose 
zegv0010.21o - delf0010.21o using NAV.d as reference.

```bash
rinex-cli --ddiff \
    -f zegv0010.21o,delf0010.21o,nav.d
```

But this command will also work
```bash
rinex-cli --ddiff \
    -f zegv0010.21o,nav.d,delf0010.21o
```

While this one will invert roles, and compute
del0010.21o - zegv0010.21o
```bash
rinex-cli --ddiff \
    -f delf0010.21o,zegv0010.21o,nav.d
```

Finally, requesting `ddiff` without providing Ephemeris will cause a panic:
```bash
rinex-cli --ddiff \
    -f delf0010.21o,zegv0010.21o
```

And it is possible to perform N double differentiation at once,
but we currently only support 1 reference Ephemeris to be specified
```bash
rinex-cli --ddiff \
    -f nav.d,obs_a1.o,obs_b1.o,obs_a2.o,obs_b2.o
```

Refer
[to the API](https://docs.rs/rinex/latest/rinex/struct.Rinex.html#method.double_diff_mut).
for more detail about this operation.

## Cycle slips

Possible cycle slip events are described by the GNSS receiver.  
Print such information like this

```bash
rinex-cli --cycle-slips -f test_resources/OBS/V2/zegv0010.21o
```

Cycle slips determination is under development, by adding more data processing on top of the
previously defined Double Differential RINEX algorithm.

## RTK resolution

RTK resolution (rover/base) is under development, by combining the previous double differential RINEX post processing,
and adding a Navigation data analysis on top of it.

## Merge

Merge several RINEX together. We use the `teqc` identifiers to describe the merge operation

```bash
rinex-cli -m -f test_resources/OBS/V2/zegv0010.21o,test_resources/OBS/V2/delf0010.21o
```

This generates a new RINEX file "merged.rnx"

## `Split` special operation

It is possible to split given RINEX files into two.

`Split` has two behaviors

* (1) if given RINEX is a `merged` RINEX (either by `teqc` or this tool),
we split the record at the epoch (timestamps) where records were previously merged

* (2) otherwise, the user is expected to describe a timestamp (`epoch`) 
at which we will split the record.

### Splitting a previously merged record

```bash
# Merge two RINEX together
cargo run -f /tmp/file1.rnx,/tmp/file2.rnx -m --output /tmp/merged.rnx
# Split resulting RINEX
cargon run -f /tmp/merged.rnx --split --output /tmp/split1.rnx,/tmp/split2.rnx 
```

When splitting a merged RINEX, the header section is simply
copied into both results.

### Splitting record

If User provides an `epoch`, the tool will try to locate the
given timestamp and perform `split()` at this date & time.

Two description format are supported, for the user to describe a sampling
timestamp:

* "YYYY-MM-DD HH:MM:SS" : Datetime description and EpochFlag::Ok is assumed
* "YYYY-MM-DD HH:MM:SS X" : Datetime description where X describes the EpochFlag integer value.
Refer to RINEX standards for supported Epoch flag values 

The tool identifies matching timestamp by comparing the datetime field AND
the flag field. They both must match.

Example :

```bash
# Split a previously merged record
cargo run -f /tmp/merged.rnx --split \
    --output /tmp/file1.rnx,/tmp/file2.rnx

# Split a record at specified timestamp,
# don't forget the \" encapsulation \" ;)
cargo run -f /tmp/data.rnx --split "2022-06-03 16:00:00" \
    --output /tmp/file1.rnx,/tmp/file2.rnx

# Split a record at specified timestamp with precise Power Failure event
# don't forget the \" encapsulation \" ;)
cargo run -f /tmp/data.rnx --split "2022-06-03 16:00:00 1" \
    --output /tmp/file1.rnx,/tmp/file2.rnx
```

## ascii-plot

The ascii-plot emulates the quite interesting tiny plot that `teqc` attaches to its verbose report.

The ascii plot is currently generated for every given Observation RINEX file.

```bash
rinex-cli -f test_resources/OBS/V2/zegv0010.21o --ascii-plot

```

Like other requests, this one cancels the record exposure, with the previous command,
a single tiny plot is to be generated.

<img align="center" width="400" src="https://github.com/gwbres/rinex/blob/main/doc/ascii-plot.png">

To understand the meaning of this plot, please currently refer to the `teqc` documentation