Skip to content

Commit

Permalink
improve map plotting
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume W. Bres <[email protected]>
  • Loading branch information
gwbres committed Sep 23, 2023
1 parent fc2da81 commit d31b441
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 55 deletions.
12 changes: 10 additions & 2 deletions rinex-cli/src/plot/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Trace>) {
let len = self.plots.len() - 1;
Expand Down
14 changes: 11 additions & 3 deletions rinex-cli/src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down Expand Up @@ -377,7 +385,7 @@ pub fn build_chart_epoch_axis(
let txt: Vec<String> = 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)
Expand Down
100 changes: 50 additions & 50 deletions rinex-cli/src/plot/record/ionex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64> = Vec::new();
let mut lon: Vec<f64> = Vec::new();
let mut z: Vec<f64> = 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<f64> = Vec::new();
let mut lon: Vec<f64> = Vec::new();
let mut z: Vec<f64> = 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);
}
}

0 comments on commit d31b441

Please sign in to comment.