Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.2.0 of fdmr #297

Merged
merged 109 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
0480888
Adding code tab for plots
gareth-j Nov 1, 2023
e8f5dd4
Add changelog line
gareth-j Nov 1, 2023
4156fd8
Starting a snow data tutorial, including two datasets in lat/lon and UTM
desireetreichler Nov 3, 2023
f133a55
Added introduction: tutorial purpose, data description, references
desireetreichler Nov 3, 2023
689d501
Tutorial structure up to the point where things don't work with UTM
desireetreichler Nov 3, 2023
237e050
Create Readme.md
Elchin Nov 3, 2023
2b833e0
Commented code up to producing a first mesh attempt in lat/lon
desireetreichler Nov 3, 2023
a4ef9a5
Disabled cells that break the script (eval=false), added html version…
desireetreichler Nov 3, 2023
e4d1390
trial to explain the prior design
mmazzolini Nov 3, 2023
e8af4e9
adding more snow code
Nov 3, 2023
24fd34e
Updated references in snow.Rmd
krisaalstad Nov 3, 2023
90c545a
Added code for simple spatial prediction
desireetreichler Nov 3, 2023
c120235
Merge branch 'snow' of github.com:desireetreichler/fdmr into snow
desireetreichler Nov 3, 2023
79a3f3c
Update reference.Rmd
krisaalstad Nov 3, 2023
aa71090
Merge Kris' changes to the intro of the tutorial.
desireetreichler Nov 3, 2023
2f5973f
Minor tidy up of typos, heading levels etc.
desireetreichler Nov 3, 2023
493b358
new geophysics tutorial draft and MT dataset added
Nov 5, 2023
5e9078c
Deleted outdated file vignettes/Readme.md
desireetreichler Nov 13, 2023
5929dc4
Read-through and fix up to line 133
desireetreichler Nov 13, 2023
bf21b84
Added TO DO part with planned outcome/further development to the tuto…
Nov 17, 2023
3a4f287
Add coordinates to shiny_meshbuilder.R
aabelean Nov 17, 2023
0fd5a40
Add coordinates to shiny_modelbuilder.R map
aabelean Nov 17, 2023
f2e1409
Added coordinates to plot_mapping.R
aabelean Nov 17, 2023
36bb35d
Add coordinates to plot_mesh.R
aabelean Nov 17, 2023
07738cc
Update DESCRIPTION
aabelean Nov 17, 2023
f22ff4a
Update CHANGELOG.md
aabelean Nov 17, 2023
9c927bd
Merge pull request #260 from 4DModeller/Iss227/show_coordinates
mnky9800n Nov 17, 2023
6ac5c37
Update README.md to have contributor guidelines
mnky9800n Nov 17, 2023
254462a
Add missing libraries to DESC
gareth-j Nov 17, 2023
06e1b5e
Small changes to text
gareth-j Nov 17, 2023
f2b2aa1
Merge pull request #257 from 4minakov/newtutorial
gareth-j Nov 17, 2023
104d072
Ran styler over the geophysical tutorial
gareth-j Nov 17, 2023
4ce8894
Added note to changelog
gareth-j Nov 17, 2023
791aff7
Merge pull request #263 from 4DModeller/Iss246/AddMissingLibs
gareth-j Nov 17, 2023
b05fbf7
Merge pull request #261 from 4DModeller/258-we-are-missing-a-contribu…
gareth-j Nov 17, 2023
37e4c9f
Merge branch 'devel' into geophysicsTut
mnky9800n Nov 20, 2023
d1cf20d
Merge pull request #264 from 4DModeller/geophysicsTut
mnky9800n Nov 20, 2023
0500b62
Adding line to changelog
gareth-j Nov 20, 2023
9cb0d56
Ran styler over vignette [skip ci]
gareth-j Nov 20, 2023
bc9eb92
Merge pull request #266 from 4DModeller/Iss253/data_loading
gareth-j Nov 20, 2023
05f09e6
Merge pull request #259 from desireetreichler/snow
gareth-j Nov 20, 2023
db2e1da
Merge branch 'devel' into snowTutorial
gareth-j Nov 20, 2023
a96f236
Remove the html file
gareth-j Nov 20, 2023
b0d3740
added small texts describing each step
mnky9800n Nov 20, 2023
566f5a6
WIP: Testing use of mapview
gareth-j Nov 21, 2023
54a2fd8
Merge pull request #272 from 4DModeller/269-the-geophysics-tutorial-n…
mnky9800n Nov 21, 2023
8990240
WIP: mapview basic working but breaking out of div
gareth-j Nov 22, 2023
d6d9ee1
Looking at reason for div breakout of maps
gareth-j Nov 22, 2023
d004f03
Testing
gareth-j Nov 23, 2023
3bdc2b3
Added functions to util_coords.R
aabelean Nov 28, 2023
d4abfc3
Added support for antimeridian wrapping in plot_mesh.R
aabelean Nov 28, 2023
e5b1825
Added optional support for antimeridian wrapping in plot_mapping.R
aabelean Nov 28, 2023
759a031
Update shiny_meshbuilder.R
aabelean Nov 28, 2023
fa828f8
Update CHANGELOG.md
aabelean Nov 28, 2023
3933ba0
Update util_coords.R
aabelean Nov 28, 2023
cdafc3e
Do not plot duplicate polygons in plot_mapping.R
aabelean Nov 28, 2023
613d926
Fixing shiny_meshbuilder.R error
aabelean Nov 28, 2023
9254c50
Fixed the addMeasure
aabelean Nov 28, 2023
129fab4
Update CHANGELOG.md
aabelean Nov 28, 2023
a76f565
Update NAMESPACE
aabelean Nov 28, 2023
4b12981
Update DESCRIPTION
aabelean Nov 28, 2023
46015b8
Merge pull request #285 from 4DModeller/Iss225/AntimeridianProblem
aabelean Nov 28, 2023
cf815eb
Change the default offset for st_wrap_dateline
aabelean Nov 28, 2023
3960793
Merge pull request #287 from 4DModeller/polar_antimeridian_problem
aabelean Nov 29, 2023
d3a8ab4
Removed the `Comparing the output` section in decision_tree.Rmd
aabelean Dec 4, 2023
8d0bb80
WIP: Adding multiple layers
gareth-j Dec 7, 2023
039a4fd
UTM data and mesh being plotted with mapview
gareth-j Dec 7, 2023
bd1c75e
Fix code output for NULL maxedge etc
gareth-j Dec 7, 2023
94cd220
Add text output to tell user of CRS, correct indentation of code output
gareth-j Dec 7, 2023
d5302fe
Rename col usage
gareth-j Dec 7, 2023
9297687
Convert spatial data to something mapview expects and ensure crs is c…
gareth-j Dec 7, 2023
8c1daa7
Update arguments used
gareth-j Dec 7, 2023
c863f42
Remove section of vignette about mesh checking code we don't have
gareth-j Dec 7, 2023
af5f388
Add line to changelog
gareth-j Dec 7, 2023
d61279c
Merge pull request #288 from 4DModeller/Iss248/UTMMaps
gareth-j Dec 7, 2023
4954c7f
Fix merge conflicts with devel
gareth-j Dec 7, 2023
24ad5b9
Remove snow tutorial work until it can be looked over
gareth-j Dec 7, 2023
43cc562
Add new plot_map_mapview function for simple map plots
gareth-j Dec 7, 2023
d005bac
Add lines to changelog
gareth-j Dec 7, 2023
a07cb92
Ensure mapview is in desc
gareth-j Dec 7, 2023
83d806d
Rename bibtex
gareth-j Dec 7, 2023
0b7f017
Update model_viewer clip
gareth-j Dec 7, 2023
4409a2d
Merge pull request #292 from 4DModeller/Iss195/RenameBibtex
gareth-j Dec 8, 2023
f62dffa
Adding backend argument to tidy mapping function calls
gareth-j Dec 18, 2023
8b8efc7
Update docstring for map plotting fn
gareth-j Dec 18, 2023
e57c713
Add map plot r doc
gareth-j Dec 18, 2023
77050ee
Add numeric inputs instead of sliders for mesh builder
gareth-j Dec 18, 2023
cdaa6cd
WIP: Updating meshbuilder with custom inputs
gareth-j Dec 18, 2023
6e93c17
Added inputs to rows
gareth-j Dec 18, 2023
4db11d9
Update docs
gareth-j Dec 18, 2023
204863c
Add new internal fn docs
gareth-j Dec 18, 2023
fd50b82
Update plot map function calls
gareth-j Dec 19, 2023
6ab9874
Merge pull request #289 from 4DModeller/Iss249/removeSection
gareth-j Dec 19, 2023
4ea070e
Merge pull request #291 from 4DModeller/Isss254/rasterMap
gareth-j Dec 19, 2023
1796e6c
Merging in devel
gareth-j Dec 19, 2023
e83f72b
Merge branch 'devel' into Iss223/ModelViewerPlots
gareth-j Dec 19, 2023
8b3f3a5
Added graph plotting code to code tab
gareth-j Dec 19, 2023
e380bde
Fixes to plot code
gareth-j Dec 19, 2023
c034c46
Merge pull request #237 from 4DModeller/Iss223/ModelViewerPlots
gareth-j Dec 19, 2023
f0c3c17
Merge pull request #290 from 4DModeller/noSnow
gareth-j Dec 19, 2023
56e6d17
Added explainer text for the plots
gareth-j Dec 19, 2023
aa48e83
Add changelog line
gareth-j Dec 19, 2023
fc3330a
Merge pull request #295 from 4DModeller/Iss232/PlotExplainer
gareth-j Dec 19, 2023
4224816
Remove reference to check mesh [skip ci]
gareth-j Dec 19, 2023
3a55737
Merge pull request #296 from 4DModeller/Iss294/CheckMeshNoMore
gareth-j Dec 19, 2023
9aa8031
Release 0.2.0 of fdmr
gareth-j Dec 19, 2023
3ea3fdf
Update changelog with release date
gareth-j Dec 19, 2023
bb958db
remove data loading tut
gareth-j Dec 19, 2023
b79bf89
Add missing function doc files
gareth-j Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ All notable changes to `fdmr` will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/openghg/openghg/compare/0.1.1...HEAD)
## [Unreleased](https://github.com/openghg/openghg/compare/0.2.0...HEAD)

## [0.2.0] - 2023-12-19

### Fixed

- Added a function to ensure correct polygon display across the dateline - [PR #285](https://github.com/4DModeller/fdmr/pull/285)

### Added

- Added a new tutorial on loading data from different sources - [PR #266](https://github.com/4DModeller/fdmr/pull/266/)
- Added new geophysical processes tutorial thanks to Alexander Minakov (4minakov) - [PR #257](https://github.com/4DModeller/fdmr/pull/257)
- Added mouse pointer coordinates header and standard measurement tool - [PR #260](https://github.com/4DModeller/fdmr/pull/260)
- Added new help explainer to the `Help` tab of the `model_viewer` Shiny app - [PR #295](https://github.com/4DModeller/fdmr/pull/295)

### Changed

- Updated `plot_map` to allow use of both `leaflet` and `mapview` packages - [#291](https://github.com/4DModeller/fdmr/pull/291)
- Moved from using `leaflet` to using (`mapview`)[https://r-spatial.github.io/mapview/index.html] for plotting the mesh and spatial data in the `mesh_builder` Shiny app. This enables use of UTM coordinates - [PR #288](https://github.com/4DModeller/fdmr/pull/288)

## [0.1.1] - 2023-11-01

Expand All @@ -25,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allowed reversal of colour palette and added raster plot legend in map plotter - [PR #229](https://github.com/4DModeller/fdmr/pull/229)
- Added markers option to mesh plotter - [PR #230](https://github.com/4DModeller/fdmr/pull/230)
- Updated the interfaces of the Shiny apps to the use [bslib](https://rstudio.github.io/bslib/index.html) theming - [PR #236](https://github.com/4DModeller/fdmr/pull/236)
- Code tab added to `fdmr::model_viewer` so the user can easily reproduce plots - [PR #237](https://github.com/4DModeller/fdmr/pull/237)

## [0.1.0] - 2023-10-17

Expand Down
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: fdmr
Title: 4D Modeller project
Version: 0.1.1
Version: 0.2.0
Authors@R:
c(person("Gareth", "Jones", , "g.m.jones@bristol.ac.uk", role = c("aut", "cre"),
comment = ""),
Expand Down Expand Up @@ -55,7 +55,12 @@ Imports:
fmesher,
purrr,
shinyjs,
bslib
bslib,
bsicons,
future,
leafem,
sfheaders,
mapview
Suggests:
bookdown,
knitr,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(antimeridian_wrapping)
export(clear_caches)
export(convert_from_lon_360)
export(create_prediction_field)
export(get_tutorial_datapath)
export(latlong_to_utm)
Expand Down
118 changes: 107 additions & 11 deletions R/plot_mapping.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#' Create a simple Leaflet map from data
#' Create a simple map from data using either the leaflet or mapview packages
#'
#' NOTE that the mapview backend is only intended for quick viewing of data,
#' most of the customisation arguments are not available.
#'
#' The leaflet backend will work for most use cases and is recommended.
#' For plotting of maps with UTM coordinates, the mapview backend is recommended.
#'
#' @param polygon_data Polygon data
#' @param raster_data Raster datas
Expand All @@ -12,8 +18,11 @@
#' @param polygon_line_colour Polygon surrounding line colour
#' @param polygon_line_weight Polygon surrounding line weight
#' @param reverse Reverse the colour palette if TRUE
#' @param wrapping Split polygons along the antimeridian (-180/180 boundary) if TRUE
#' @param backend Backend package to use for plotting, either "leaflet" or "mapview"
#'
#' @return leaflet::leaflet or mapview::mapview
#'
#' @return leaflet::leaflet
#' @export
plot_map <- function(polygon_data = NULL,
raster_data = NULL,
Expand All @@ -26,20 +35,84 @@ plot_map <- function(polygon_data = NULL,
polygon_line_colour = "grey",
polygon_line_weight = 1,
polygon_fill_opacity = 0.6,
reverse = FALSE) {
reverse = FALSE,
wrapping = FALSE,
backend = "leaflet") {
if (is.null(polygon_data) && is.null(raster_data)) {
stop("Polygon or raster data must be given.")
}
library(leaflet)

if (backend == "leaflet") {
plot_map_leaflet(
polygon_data = polygon_data,
raster_data = raster_data,
domain = domain,
markers = markers,
palette = palette,
legend_title = legend_title,
add_scale_bar = add_scale_bar,
polygon_fill_colour = polygon_fill_colour,
polygon_line_colour = polygon_line_colour,
polygon_line_weight = polygon_line_weight,
polygon_fill_opacity = polygon_fill_opacity,
reverse = reverse,
wrapping = wrapping
)
} else if (backend == "mapview") {
plot_map_mapview(
polygon_data = polygon_data,
raster_data = raster_data
)
} else {
stop("Invalid backend given, must be either 'leaflet' or 'mapview'.")
}
}


#' Create a simple Leaflet map from data
#'
#' @param polygon_data Polygon data
#' @param raster_data Raster data
#' @param domain Domain data to be passed to leaflet::colorNumeric and leaflet::addLegend
#' @param markers Markers to display on map. A named list with latitude, longitude and label names must be given.
#' @param palette Palette to be used for colours, defaults to viridis
#' @param legend_title Title for legend
#' @param add_scale_bar Add scale bar if TRUE
#' @param polygon_fill_opacity Leaflet polygon fill opacity, float from 0 to 1.0, passed to fillOpacity of leaflet::addPolygons
#' @param polygon_fill_colour Polygon fill colour
#' @param polygon_line_colour Polygon surrounding line colour
#' @param polygon_line_weight Polygon surrounding line weight
#' @param reverse Reverse the colour palette if TRUE
#' @param wrapping Split polygons along the antimeridian (-180/180 boundary) if TRUE
#'
#' @return leaflet::leaflet
#' @keywords internal
plot_map_leaflet <- function(polygon_data = NULL,
raster_data = NULL,
domain = NULL,
markers = NULL,
palette = "viridis",
legend_title = NULL,
add_scale_bar = FALSE,
polygon_fill_colour = "#E4572E",
polygon_line_colour = "grey",
polygon_line_weight = 1,
polygon_fill_opacity = 0.6,
reverse = FALSE,
wrapping = FALSE) {
m <- leaflet::leaflet()
m <- leaflet::addTiles(m)
m <- leaflet::addProviderTiles(m, leaflet::providers$Esri.WorldImagery, group = "Satellite")
m <- leaflet::addProviderTiles(m, leaflet::providers$Openstreetmap, group = "Satellite")
m <- leafem::addMouseCoordinates(m, native.crs = TRUE)

# Store a vector of layers we add to the map,
# used later to create the layers control object
layers <- c()

if (!is.null(polygon_data)) {
if (isTRUE(wrapping)) {
polygon_data <- fdmr::antimeridian_wrapping(polygon_data, crs = "+proj=longlat +datum=WGS84", unique_inst = TRUE, to_sp = FALSE)
}
if (!is.null(domain)) {
colours <- leaflet::colorNumeric(palette = palette, domain = domain, reverse = reverse)
polygon_fill_colour <- ~ colours(domain)
Expand All @@ -63,7 +136,7 @@ plot_map <- function(polygon_data = NULL,
}

if (!is.null(raster_data)) {
colours <- leaflet::colorNumeric(palette = palette, domain = raster::values(raster_data), na.color=rgb(0,0,0,0), reverse = reverse)
colours <- leaflet::colorNumeric(palette = palette, domain = raster::values(raster_data), na.color = rgb(0, 0, 0, 0), reverse = reverse)
m <- leaflet::addRasterImage(m,
x = raster_data,
opacity = 0.75,
Expand All @@ -72,11 +145,11 @@ plot_map <- function(polygon_data = NULL,
colors = colours,
)
m <- leaflet::addLegend(m,
pal = colours,
values = raster::values(raster_data),
opacity = 0.75,
title = legend_title,
na.label = ""
pal = colours,
values = raster::values(raster_data),
opacity = 0.75,
title = legend_title,
na.label = ""
)
layers <- append(layers, "Raster")
}
Expand All @@ -97,5 +170,28 @@ plot_map <- function(polygon_data = NULL,
m <- leaflet::addScaleBar(m, position = "bottomleft")
}

m <- leaflet::addMeasure(m, position = "bottomleft", primaryLengthUnit = "kilometers", primaryAreaUnit = "sqmeters")

return(m)
}


#' A simple map plotter using mapview. This is only intended for very quick viewing of data.
#'
#' @param polygon_data Spatial data to plot
#' @param raster_data Raster data to plot
#'
#' @return mapview::mapview
#' @keywords internal
plot_map_mapview <- function(polygon_data = NULL, raster_data = NULL) {
map_types <- c("OpenStreetMap", "Esri.WorldImagery", "OpenTopoMap")

m <- mapview::mapview(map.types = map_types)
if (!is.null(polygon_data)) {
m <- m + mapview::mapview(polygon_data)
}
if (!is.null(raster_data)) {
m <- m + mapview::mapview(raster_data)
}
return(m)
}
6 changes: 5 additions & 1 deletion R/plot_mesh.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", lati
)
}

spatial_mesh <- fdmr::mesh_to_spatial(mesh = mesh, crs = expected_crs)
spatial_mesh_original <- fdmr::mesh_to_spatial(mesh = mesh, crs = expected_crs)

spatial_mesh <- fdmr::antimeridian_wrapping(spatial_mesh_original, crs = expected_crs, unique_inst = FALSE, to_sp = FALSE)

plot_polygons <- FALSE
plot_points <- FALSE
Expand Down Expand Up @@ -60,6 +62,8 @@ plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", lati
m <- leaflet::leaflet()
m <- leaflet::addTiles(m, group = "OSM")
m <- leaflet::addPolygons(m, data = spatial_mesh, weight = 0.5, fillOpacity = 0.2, fillColor = "#5252ca", group = "Mesh")
m <- leaflet::addMeasure(m, position = "bottomleft", primaryLengthUnit = 'kilometers', primaryAreaUnit = 'sqmeters')
m <- leafem::addMouseCoordinates(m, native.crs = TRUE)

if (plot_polygons) {
m <- leaflet::addPolygons(m, data = spatial_data, fillColor = "#d66363", color = "green", weight = 1, group = "Spatial")
Expand Down
28 changes: 2 additions & 26 deletions R/plot_priors.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#' @param to_plot Type of data to plot, "Range for f" etc
#'
#' @return ggplot2::ggplot
#' @keywords internal
plot_line_comparison <- function(data, to_plot, title) {
ar1_data <- purrr::map(data, function(x) as.data.frame(x$pars[[to_plot]]))
single_df <- dplyr::bind_rows(ar1_data, .id = "Run")
parsed_data <- purrr::map(data, function(x) as.data.frame(x$pars[[to_plot]]))
single_df <- dplyr::bind_rows(parsed_data, .id = "Run")
if (nrow(single_df) == 0) {
return("No pars data.")
}
Expand All @@ -18,32 +17,11 @@ plot_line_comparison <- function(data, to_plot, title) {
ggplot2::theme(text = ggplot2::element_text(size = 16))
}


#' Plot AR(1)
#'
#' @param data Parsed model output
#' @param to_plot Type of data to plot, "Range for f" etc
#'
#' @return ggplot2::ggplot
#' @keywords internal
plot_ar1 <- function(data) {
ar1_data <- purrr::map(data, function(x) as.data.frame(x$pars$`GroupRho for f`))
single_df <- dplyr::bind_rows(ar1_data, .id = "Run")
if (nrow(single_df) == 0) {
return("No pars data.")
}

ggplot2::ggplot(single_df, ggplot2::aes(x = x, y = y, color = Run)) +
ggplot2::geom_line() +
ggplot2::theme(text = ggplot2::element_text(size = 16))
}

#' Create boxplots from priors run data
#'
#' @param data
#'
#' @return graphics::boxplot
#' @keywords internal
plot_priors_boxplot <- function(data) {
# TODO - I'm sure this can be done in a nicer functional way
fitted_mean_post <- purrr::map(data, function(x) x$fitted_mean_post)
Expand All @@ -60,7 +38,6 @@ plot_priors_boxplot <- function(data) {
#' @param measurement_data Measurement data
#'
#' @return ggplot2::ggplot
#' @keywords internal
plot_priors_density <- function(data, measurement_data) {
# Can this be done in a cleaner way? Just create a dataframe from the lists?
fitted_values <- unlist(purrr::map(data, function(x) x$fitted_mean_post))
Expand All @@ -82,7 +59,6 @@ plot_priors_density <- function(data, measurement_data) {
#' @param data
#'
#' @return ggplot2::ggplot
#' @keywords internal
plot_dic <- function(data) {
infocri <- base::cbind.data.frame(
priors = unlist(purrr::map(seq(1, length(data)), function(x) paste("Run", x))),
Expand Down
Loading
Loading