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
use rinex::{
prelude::*,
navigation,
};
use crate::plot::*;
use std::collections::HashMap;
use plotters::prelude::*;
/// Display vehicules per epoch
pub fn analyze(rnx: &Rinex, nav: &mut Option<Rinex>, dims: (u32,u32)) {
let mut cmap: HashMap<Sv, RGBAColor> = HashMap::new();
let p = build_plot("sv.png", dims);
if let Some(nav) = nav {
// special behavior
// Shared NAV/OBS epochs
if let Some(obs_rec) = rnx.record.as_obs() {
if let Some(nav_rec) = nav.record.as_mut_nav() {
// plot will exhibit both Ephemeris and Observations
let obs_epochs: Vec<Epoch> = obs_rec
.keys()
.map(|(k, _)| *k)
.collect();
let obs_dates: (f64, f64) =
(obs_epochs[0].to_utc_seconds(),
obs_epochs[obs_epochs.len()-1].to_utc_seconds());
let nav_epochs: Vec<Epoch> = nav_rec
.keys()
.map(|k| *k)
.collect();
let nav_dates: (f64, f64) =
(nav_epochs[0].to_utc_seconds(),
nav_epochs[nav_epochs.len()-1].to_utc_seconds());
// determine t_axis for nicer rendering
let mut max_date: f64 = 0.0;
if let Some(e0) = obs_epochs.get(0) {
if let Some(e) = obs_epochs.get(obs_epochs.len()-1) {
max_date = e.to_utc_seconds() - e0.to_utc_seconds();
}
}
if let Some(e0) = nav_epochs.get(0) {
if let Some(e) = nav_epochs.get(nav_epochs.len()-1) {
let t = e.to_utc_seconds() - e0.to_utc_seconds();
if t > max_date {
max_date = t;
}
}
}
// determine largest PRN # encountered
// and a color map per vehicules
let mut max_prn: u8 = 0;
for (_, (_, vehicules)) in obs_rec {
for (sv, _) in vehicules.iter() {
if cmap.get(sv).is_none() {
cmap.insert(*sv, Palette99::pick(sv.prn.into())
.mix(0.99));
}
if sv.prn > max_prn {
max_prn = sv.prn;
}
}
}
// drop non ephemeris frames at the same time
nav_rec.retain(|_e, classes| {
classes.retain(|class, frames| {
if *class == navigation::FrameClass::Ephemeris {
for frame in frames {
let (_, sv, _) = frame.as_eph()
.unwrap();
if cmap.get(sv).is_none() {
cmap.insert(*sv, Palette99::pick(sv.prn.into())
.mix(0.99));
}
if sv.prn > max_prn {
max_prn = sv.prn;
}
}
true
} else {
false
}
});
classes.len() > 0
});
let x_axis = 0.0..max_date;
let y_axis = 0.0..((max_prn +1) as f64);
let mut chart = ChartBuilder::on(&p)
.caption("Vehicules per Epoch", ("sans-serif", 50).into_font())
.margin(40)
.x_label_area_size(30)
.y_label_area_size(40)
.build_cartesian_2d(x_axis, y_axis)
.unwrap();
chart
.configure_mesh()
.x_desc("Timestamp [s]")
.x_labels(30)
.y_desc("Vehicule [Svnn]")
.y_labels(30)
.draw()
.expect("failed to draw mesh");
/*
* Plot Observation vehicules with cross symbol
*/
let data = rnx.space_vehicules_per_epoch();
for (sv, color) in &cmap {
// grab this Svnn data
let data: Vec<_> = data.iter()
.enumerate()
.filter_map(|(index, (epoch, vehicules))| {
if vehicules.contains(&sv) {
if index == 0 {
Some((0.0, sv.prn as f64))
} else {
Some((epoch.to_utc_seconds() - obs_dates.0, sv.prn as f64))
}
} else {
None
}
})
.collect();
chart.draw_series(
data.iter()
.map(|point| {
Cross::new(*point, 4, color.clone())
}))
.expect("failed to draw observation serie")
.label(sv.to_string().to_owned() + "(OBS)")
.legend(|(x, y)| {
Cross::new((x, y), 4, color.clone())
});
}
/*
* Plot Ephemeris vehicules with triangle symbol
*/
let data = nav.space_vehicules_per_epoch();
for (sv, color) in &cmap {
// grab this Svnn data
let data: Vec<_> = data.iter()
.enumerate()
.filter_map(|(index, (epoch, vehicules))| {
if vehicules.contains(&sv) {
if index == 0 {
Some((0.0, sv.prn as f64 +0.5))
} else {
Some((epoch.to_utc_seconds() - nav_dates.0, sv.prn as f64 +0.5))
}
} else {
None
}
})
.collect();
chart.draw_series(
data.iter()
.map(|point| {
TriangleMarker::new(*point, 4, color.clone())
}))
.expect("failed to draw navigation serie")
.label(sv.to_string().to_owned() + "(EPH)")
.legend(|(x, y)| {
TriangleMarker::new((x, y), 4, color.clone())
});
}
chart
.configure_series_labels()
.border_style(&BLACK)
.background_style(WHITE.filled())
.draw()
.expect("failed to draw ssi labels");
}
}
} else { // single file
let data = rnx.space_vehicules_per_epoch();
// y axis offset, per constellation,
// to distinguish nicely
let mut offset = 0.0_f64;
let mut constell_offsets: HashMap<Constellation, f64> = HashMap::new();
let constellations = rnx.list_constellations();
let nb_constell = constellations.len() as f64;
for cst in constellations {
constell_offsets.insert(cst, offset);
offset += 1.0 / nb_constell;
}
let mut dates: (f64,f64) = (0.0, 0.0);
let mut max_prn: u8 = 0;
for (e_index, (epoch, vehicules)) in data.iter().enumerate() {
if e_index == 0 {
dates.0 = epoch.to_utc_seconds()
} else {
dates.1 = epoch.to_utc_seconds() - dates.0;
}
for sv in vehicules.iter() {
if cmap.get(sv).is_none() {
cmap.insert(*sv, Palette99::pick(sv.prn.into())
.mix(0.99));
}
if sv.prn > max_prn {
max_prn = sv.prn;
}
}
}
let t_axis = 0.0..dates.1;
let y_axis = 0.0..((max_prn +1) as f64);
let mut chart = ChartBuilder::on(&p)
.caption("Vehicules per Epoch", ("sans-serif", 50).into_font())
.margin(40)
.x_label_area_size(30)
.y_label_area_size(40)
.build_cartesian_2d(t_axis, y_axis)
.unwrap();
chart
.configure_mesh()
.x_desc("Timestamp [s]")
.x_labels(30)
.y_desc("Vehicule [Svnn]")
.y_labels(30)
.draw()
.expect("failed to draw mesh");
for (sv, color) in cmap.iter() {
// grab this Svnn data
let data: Vec<_> = data.iter()
.enumerate()
.filter_map(|(index, (epoch, vehicules))| {
if vehicules.contains(&sv) {
if index == 0 {
Some((0.0, sv.prn as f64))
} else {
Some(((epoch.to_utc_seconds() - dates.0) as f64, sv.prn as f64))
}
} else {
None
}
})
.collect();
chart.draw_series(
data.iter()
.map(|(x, y)| {
let p = (*x,
y + constell_offsets.get(&sv.constellation).unwrap());
match sv.constellation {
Constellation::GPS
| Constellation::Geo
| Constellation::SBAS(_) => {
Circle::new(p, 4,
Into::<ShapeStyle>::into(&color).filled())
.into_dyn()
},
Constellation::Glonass => {
Cross::new(p, 4,
Into::<ShapeStyle>::into(&color).filled())
.into_dyn()
},
_ => {
TriangleMarker::new(p, 4,
Into::<ShapeStyle>::into(&color).filled())
.into_dyn()
},
}
}))
.expect("failed to draw serie")
.label(sv.to_string())
.legend(|(x, y)| {
match sv.constellation {
Constellation::GPS
| Constellation::Geo
| Constellation::SBAS(_) => {
Circle::new((x,y), 4,
Into::<ShapeStyle>::into(color.clone()).filled())
.into_dyn()
},
Constellation::Glonass => {
Cross::new((x,y), 4,
Into::<ShapeStyle>::into(color.clone()).filled())
.into_dyn()
},
_ => {
TriangleMarker::new((x,y), 4,
Into::<ShapeStyle>::into(color.clone()).filled())
.into_dyn()
},
}
});
chart
.configure_series_labels()
.border_style(&BLACK)
.background_style(WHITE.filled())
.draw()
.expect("failed to draw ssi labels");
}
}
}