From d31b44111e2c85d27f29cdba7003d699dd613d4d Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Sat, 23 Sep 2023 09:53:52 +0200 Subject: [PATCH] improve map plotting Signed-off-by: Guillaume W. Bres --- rinex-cli/src/plot/context.rs | 12 +++- rinex-cli/src/plot/mod.rs | 14 +++- rinex-cli/src/plot/record/ionex.rs | 100 ++++++++++++++--------------- 3 files changed, 71 insertions(+), 55 deletions(-) diff --git a/rinex-cli/src/plot/context.rs b/rinex-cli/src/plot/context.rs index 01e597d0f..6ebaa4502 100644 --- a/rinex-cli/src/plot/context.rs +++ b/rinex-cli/src/plot/context.rs @@ -30,8 +30,16 @@ impl PlotContext { pub fn add_polar2d_plot(&mut self, title: &str) { self.plots.push(build_default_polar_plot(title)); } - pub fn add_world_map(&mut self, style: MapboxStyle, center: (f64, f64), zoom: u8) { - self.plots.push(build_world_map(style, center, zoom)); + pub fn add_world_map( + &mut self, + title: &str, + show_legend: bool, + map_style: MapboxStyle, + center: (f64, f64), + zoom: u8, + ) { + self.plots + .push(build_world_map(title, show_legend, map_style, center, zoom)); } pub fn add_trace(&mut self, trace: Box) { let len = self.plots.len() - 1; diff --git a/rinex-cli/src/plot/mod.rs b/rinex-cli/src/plot/mod.rs index 596805715..bbc3bcae1 100644 --- a/rinex-cli/src/plot/mod.rs +++ b/rinex-cli/src/plot/mod.rs @@ -279,14 +279,22 @@ pub fn build_default_polar_plot(title: &str) -> Plot { * centered on given locations, in decimal degrees, * zoom factor */ -pub fn build_world_map(style: MapboxStyle, center: (f64, f64), zoom: u8) -> Plot { +pub fn build_world_map( + title: &str, + show_legend: bool, + map_style: MapboxStyle, + center: (f64, f64), + zoom: u8, +) -> Plot { let mut p = Plot::new(); let layout = Layout::new() + .title(Title::new(title).font(Font::default())) .drag_mode(DragMode::Zoom) .margin(Margin::new().top(0).left(0).bottom(0).right(0)) + .show_legend(show_legend) .mapbox( Mapbox::new() - .style(style) + .style(map_style) .center(Center::new(center.0, center.1)) .zoom(zoom), ); @@ -377,7 +385,7 @@ pub fn build_chart_epoch_axis( let txt: Vec = epochs.iter().map(|e| e.to_string()).collect(); Scatter::new(epochs.iter().map(|e| e.to_utc_seconds()).collect(), data_y) .mode(mode) - .web_gl_mode(true) + //.web_gl_mode(true) .name(name) .hover_text_array(txt) .hover_info(HoverInfo::All) diff --git a/rinex-cli/src/plot/record/ionex.rs b/rinex-cli/src/plot/record/ionex.rs index 5a9ca7d49..bc5625381 100644 --- a/rinex-cli/src/plot/record/ionex.rs +++ b/rinex-cli/src/plot/record/ionex.rs @@ -16,58 +16,58 @@ pub fn plot_tec_map( plot_ctx: &mut PlotContext, ) { let _cmap = colorous::TURBO; - plot_ctx.add_world_map(MapboxStyle::StamenTerrain, (32.5, -40.0), 1); + /* + * TEC map visualization + * plotly-rs has no means to animate plots at the moment + * therefore.. we create one plot for all existing epochs + */ + for (index, epoch) in ctx.primary_data().epoch().enumerate() { + let content: Vec<_> = ctx + .primary_data() + .tec() + .filter_map(|(t, lat, lon, h, tec)| { + if t == epoch { + Some((lat, lon, h, tec)) + } else { + None + } + }) + .collect(); - let first_epoch = ctx - .primary_data() - .first_epoch() - .expect("failed to determine first epoch"); + plot_ctx.add_world_map( + &epoch.to_string(), + true, + MapboxStyle::StamenTerrain, + (32.5, -40.0), + 1, + ); - let first_epoch_content: Vec<_> = ctx - .primary_data() - .tec() - .filter_map(|(t, lat, lon, h, tec)| { - if t == first_epoch { - Some((lat, lon, h, tec)) - } else { - None - } - }) - .collect(); + let mut lat: Vec = Vec::new(); + let mut lon: Vec = Vec::new(); + let mut z: Vec = Vec::new(); + for (tec_lat, tec_lon, _, tec) in content { + lat.push(tec_lat); + lon.push(tec_lon); + z.push(tec); + } - let mut lat: Vec = Vec::new(); - let mut lon: Vec = Vec::new(); - let mut z: Vec = Vec::new(); - for (tec_lat, tec_lon, _, tec) in first_epoch_content { - lat.push(tec_lat); - lon.push(tec_lon); - z.push(tec); - // println!("({}, {}): {}", tec_lat, tec_lon, tec); - } - - let grid = ScatterMapbox::new(lat.clone(), lon.clone()) - .marker( - Marker::new() - .size(3) - .symbol(MarkerSymbol::Circle) - .color(NamedColor::Black) - .opacity(0.5), - ) - .name("TEC Grid"); + /* plot the map grid */ + let grid = ScatterMapbox::new(lat.clone(), lon.clone()) + .marker( + Marker::new() + .size(3) + .symbol(MarkerSymbol::Circle) + .color(NamedColor::Black) + .opacity(0.5), + ) + .name("grid"); + plot_ctx.add_trace(grid); - plot_ctx.add_trace(grid); - - let map = DensityMapbox::new(lat.clone(), lon.clone(), z) - .opacity(0.66) - .zauto(true) - .zoom(3); - //.color_continuous_scale( - // vec![ - // (0, NamedColor::Black), - // (100, NamedColor::White), - // ].into_iter() - // .collect() - //) - //.radius(5); - plot_ctx.add_trace(map); + let map = DensityMapbox::new(lat.clone(), lon.clone(), z) + .opacity(0.66) + .hover_text + .zauto(true) + .zoom(3); + plot_ctx.add_trace(map); + } }