Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
19e8a5a
add calving tutorial notebook
icetianli Nov 3, 2023
357b47a
Merge pull request #297 from 4DModeller/devel
gareth-j Dec 19, 2023
8ef2b83
add data
icetianli Mar 12, 2024
e7e9b1b
Update pkgdown.yaml
mnky9800n Mar 20, 2024
2f2814f
Merge pull request #309 from 4DModeller/mnky9800n-patch-1
mnky9800n Mar 20, 2024
3571c5d
Merge branch '4DModeller:main' into main
icetianli Mar 20, 2024
facecba
remove figures
icetianli Mar 20, 2024
ab0aa9f
Merge branch 'main' of github.com:icetianli/fdmr into main
icetianli Mar 20, 2024
08b8f18
Revert runner to latest
gareth-j Mar 20, 2024
3005063
change notebook header
icetianli Mar 20, 2024
3f93749
change notebook header
icetianli Mar 20, 2024
d9f578e
Update DESCRIPTION
aabelean Mar 21, 2024
8a3c96c
Update plot_mapping.R
aabelean Mar 21, 2024
85808ba
Update CHANGELOG.md
aabelean Mar 21, 2024
6afa86c
Merge pull request #310 from 4DModeller/306-hydro-tutorial-doesnt-plo…
mnky9800n Mar 21, 2024
6f0076f
Added a check if output only contains random fields
aabelean Mar 30, 2024
378c8d5
Finn added this to inlabru test workflow (https://github.com/inlabru-…
aabelean Mar 30, 2024
4711201
Revert addition of package installation
aabelean Mar 30, 2024
1280863
Modify standard check
aabelean Mar 30, 2024
09d0695
Updated CHANGELOG.md
aabelean Mar 30, 2024
d1e00e6
Update CHANGELOG.md
aabelean Mar 30, 2024
27322e0
Merge pull request #317 from 4DModeller/Iss315/fix_model_viewer
mnky9800n May 15, 2024
42539a3
Merge pull request #256 from icetianli/main
mnky9800n May 23, 2024
d1b026f
Update references.bib
aabelean Jun 28, 2024
87aa348
Adding the reference formatting file
aabelean Jun 29, 2024
f0fdf19
Add the OHC tutorial
aabelean Jun 29, 2024
e5a7e70
Update CHANGELOG.md
aabelean Jun 29, 2024
3e19124
Update _pkgdown.yml
aabelean Jun 29, 2024
cec8c9f
Update CHANGELOG.md
aabelean Jun 29, 2024
11e5d34
Update references.bib
aabelean Jun 29, 2024
df7e974
Disable map plots for ohc_tutorial.Rmd
aabelean Jun 29, 2024
c6d8c0b
Include warnings in ohc_tutorial.Rmd
aabelean Jun 29, 2024
b7db45f
Update ohc_tutorial.Rmd
aabelean Jun 29, 2024
398852b
Merge pull request #318 from 4DModeller/tutorialOHC
mnky9800n Jul 11, 2024
57732d4
Update pkgdown.yaml
aabelean Jul 11, 2024
acfa344
paper files for JOSS paper
mnky9800n Jul 12, 2024
cde47c1
added workflows
mnky9800n Jul 12, 2024
56c45b4
changed workflow
mnky9800n Jul 12, 2024
c333374
maybe / will work
mnky9800n Jul 15, 2024
55891b7
added branch
mnky9800n Jul 15, 2024
cce83d3
maybe workflow works
mnky9800n Jul 15, 2024
3937606
no fdmr
mnky9800n Jul 15, 2024
a6c8d00
updated errors in draft
mnky9800n Jul 15, 2024
0934eed
fixed error in bib file
mnky9800n Jul 15, 2024
f2f3735
fixed more errors in bibfile
mnky9800n Jul 15, 2024
5d74191
fixed reference
mnky9800n Jul 15, 2024
30c5571
Addition of new reference (Lindgren et al., 2024 arXiv)
richardwestaway Jul 24, 2024
7090416
Addition of new reference (Lindgren et al., 2024 arXiv)
richardwestaway Jul 24, 2024
6c0b0e4
Merge pull request #321 from rwestaway/JOSS
mnky9800n Jul 26, 2024
35f148a
Revert "Addition of new reference (Lindgren et al., 2024 arXiv)"
mnky9800n Jul 26, 2024
bfcee9e
Merge pull request #322 from 4DModeller/revert-321-JOSS
mnky9800n Jul 26, 2024
73e75e1
Added the (default) option to save to the session's temporary directory
aabelean Sep 21, 2024
a7223ee
Improved the option so that the user can pass a character. Also added…
aabelean Sep 21, 2024
4f32550
Corrected an error
aabelean Sep 21, 2024
9eb5cfe
Update CHANGELOG.md
aabelean Sep 21, 2024
d8c02a0
Forgot to update the documentation
aabelean Sep 21, 2024
0ce34ce
Added a line to call for tutorial data retrieval - I guess testing ha…
aabelean Sep 21, 2024
655405c
Changed the description to match the function
aabelean Sep 22, 2024
acc4f86
Updated documentation
aabelean Sep 22, 2024
68e7d32
Improved desciptions of model_parse
aabelean Sep 22, 2024
a04066d
Improved the documentation for shiny_meshbuilder
aabelean Sep 22, 2024
6bbf6b0
Updated model builder documentation
aabelean Sep 22, 2024
48d90cb
Updated model viewer documentation
aabelean Sep 22, 2024
80a87c1
Updated plot_mesh documentation
aabelean Sep 22, 2024
3611546
Simplified so that we use the functions we already have
aabelean Sep 22, 2024
be58c52
Improved meshing documentation
aabelean Sep 22, 2024
7d6fead
Updated plot_priors documentation
aabelean Sep 22, 2024
ac8d677
Updated meshing_checks documentation
aabelean Sep 22, 2024
b9a6b5c
Fixed an error is the description
aabelean Sep 22, 2024
e672be9
Added more information to the docs
aabelean Sep 22, 2024
e951927
Updated plot_graph
aabelean Sep 23, 2024
efa4144
Another small update to plot_graph
aabelean Sep 23, 2024
4a1c279
Updated doc
aabelean Sep 23, 2024
b6ee2bd
Update CHANGELOG.md
aabelean Sep 23, 2024
63bf514
Merge pull request #330 from 4DModeller/326-joss-review-homedir
mnky9800n Sep 24, 2024
1c1397b
Merge pull request #331 from 4DModeller/327-joss-review-model_viewer_…
mnky9800n Sep 24, 2024
eb830d4
Merge pull request #332 from 4DModeller/328-joss-review-documentation
mnky9800n Sep 24, 2024
e5ff9e1
added install INLA to the quickstart
mnky9800n Oct 12, 2024
3b65174
Correction to install INLA
aabelean Oct 17, 2024
5750f21
Merge pull request #334 from 4DModeller/325-notebooks-depend-on-inla-…
aabelean Oct 17, 2024
2b45c95
Update README.md
aabelean Nov 16, 2024
f157fb4
Merge pull request #340 from 4DModeller/337-timeout-error-when-downlo…
aabelean Nov 19, 2024
595a86b
Removing the non-numeric or non-logical variables from the model feat…
aabelean Dec 18, 2024
c5f64d3
Updated the docs. Passing a "data.frame" to measurement_data in "mode…
aabelean Dec 18, 2024
fb21bec
Removing the non-numeric or non-logical variables from the model feat…
aabelean Dec 18, 2024
c8af62d
Revert "Removing the non-numeric or non-logical variables from the mo…
aabelean Dec 18, 2024
c22ce63
Revert "Updated the docs. Passing a "data.frame" to measurement_data …
aabelean Dec 18, 2024
7ee39ea
Update CHANGELOG.md
aabelean Dec 18, 2024
24d1a62
Changed the default parameters
aabelean Dec 18, 2024
f6b8442
Corrected the error in text
aabelean Dec 18, 2024
2eab457
Merge pull request #342 from 4DModeller/338-shiny-app-in-mesh-buildin…
mnky9800n Jan 4, 2025
0a9cf67
Merge pull request #341 from 4DModeller/339-model-builder-tutorial
mnky9800n Jan 4, 2025
8ef82b9
Merge branch 'JOSS' into joss-devel
mnky9800n Jan 21, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Removed non-numeric/non-logical variable features from `shiny_modelbuilder` - [PR #341](https://github.com/4DModeller/fdmr/pull/341)
- Updated documentation for all functions to reflect better the inputs and outputs - [PR #332](https://github.com/4DModeller/fdmr/pull/332)
- Fixed an error in `model_viewer` description - [PR #331](https://github.com/4DModeller/fdmr/pull/331)
- Added to `retrieve_tutorial_data` an option to save tutorial data at a user-specified location or in a temporary directory as default - [PR #330](https://github.com/4DModeller/fdmr/pull/330)
- Fixed `model_viewer` app to work with random effect models - [PR #317](https://github.com/4DModeller/fdmr/pull/317)
- Updated `plot_map_leaflet` to feature the same selection of basemap tiles as `mapview` and fix features not appearing - [PR #310](https://github.com/4DModeller/fdmr/pull/310)

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BugReports: https://github.com/4DModeller/fdmr/issues
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Additional_repositories: https://inla.r-inla-download.org/R/testing
Imports:
colorspace,
Expand Down
6 changes: 3 additions & 3 deletions R/meshing.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This function taken from https://groups.google.com/g/r-inla-discussion-group/c/z1n1exlZrKM/m/8vYNr2D8BwAJ
#' Convert an INLA mesh to a SpatialPolygonsDataFrame
#'
#' @param mesh Mesh
#' @param crs Coordinate Reference System as proj4string
#' @param mesh Mesh object from INLA or fmesher (only R2 manifolds are valid)
#' @param crs Coordinate Reference System as proj4string, does not support geocentric coordinates
#'
#' @return SpatialPolygonsDataFrame
#' @return SpatialPolygonsDataFrame with mesh triangles
#' @export
mesh_to_spatial <- function(mesh, crs) {
if (!is.character(crs)) {
Expand Down
4 changes: 2 additions & 2 deletions R/meshing_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#' 2. A greater number of mesh triangles than observations
#' 3. Isolated triangles in mesh
#'
#' @param mesh INLA mesh
#' @param observations Observations data to be used woith model
#' @param mesh INLA/fmesher mesh
#' @param observations Observations data to be used with model (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
#'
#' @return list: Named list containing errors
#' @export
Expand Down
24 changes: 12 additions & 12 deletions R/model_parse.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Parses inlabru::bru model output to create a list of model parameters
#'
#' @param model_output Output from running inlabru::bru
#' @param measurement_data Measurement data
#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
#'
#' @return list
#' @return Creates a list of model outputs for the first timestep, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC
#' @keywords internal
parse_model_output_bru <- function(model_output, measurement_data) {
fitted_mean_post <- model_output$summary.fitted.values$mean[seq_len(nrow(measurement_data))]
Expand Down Expand Up @@ -33,11 +33,11 @@ parse_model_output_bru <- function(model_output, measurement_data) {

#' Parse model output to create a list of model parameters
#'
#' @param model_output Data returned by model
#' @param measurement_data Measurement data
#' @param model_type Type of model, we currently support inlabru
#' @param model_output Output returned by model (currently only from running inlabru::bru)
#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
#' @param model_type Type of model, we currently only support inlabru
#'
#' @return list
#' @return Creates a list of model outputs, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC
#' @export
parse_model_output <- function(model_output, measurement_data, model_type = "inlabru") {
if (model_type == "inlabru") {
Expand All @@ -48,13 +48,13 @@ parse_model_output <- function(model_output, measurement_data, model_type = "inl

#' Create a prediction field from the parsed model output and the mesh
#'
#' @param mesh INLA mesh
#' @param plot_type Type of plot to create, "predicted_mean_fields" etc
#' @param data_dist Type of data, "poisson" etc
#' @param var_a Data for variable a, required for "predicted_mean_fields" and "random_effect_fields"
#' @param var_b Data for variable b, required for "predicted_mean_fields"
#' @param mesh INLA/fmesher mesh
#' @param plot_type Type of plot to create, "predicted_mean_fields" or "random_mean_fields"
#' @param data_dist Type of data, "poisson" or "gaussian"
#' @param var_a Data for variable a (numeric), required for "predicted_mean_fields" and "random_effect_fields"; normally, random effect field from "summary.random$f"
#' @param var_b Data for variable b (numeric), required for "predicted_mean_fields"; normally, fixed effect from "summary.fixed"
#'
#' @return data.frame
#' @return data.frame with mesh node latlong coordinates (x, y) and the selected field values at the mesh nodes (z)
#' @export
create_prediction_field <- function(mesh,
plot_type = "predicted_mean_fields",
Expand Down
28 changes: 14 additions & 14 deletions R/plot_graph.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Plot a bar chart using ggplot2
#'
#' @param data Data to plot
#' @param x x-axis data
#' @param data Data to plot (all data types recognised by ggplot2::geom_bar() like data.frame)
#' @param x x-axis data, must be a Date object
#' @param y y-axis data
#' @param breaks Break points
#' @param breaks Break points, must be a sequence of dates
#' @param x_label x-axis label
#' @param y_label y-axis label
#' @param fill Fill colour
Expand Down Expand Up @@ -47,10 +47,10 @@ plot_barchart <- function(data, x, y, breaks, x_label, y_label, fill = "pink", c

#' Plot a boxplot using ggplot2
#'
#' @param data Data to plot
#' @param x x-axis data
#' @param data Data to plot (all data types recognised by ggplot2::geom_boxplot() like data.frame)
#' @param x x-axis data, must be a Date object
#' @param y y-axis data
#' @param breaks Break points
#' @param breaks Break points, must be a sequence of dates
#' @param x_label x-axis label
#' @param y_label y-axis label
#'
Expand Down Expand Up @@ -82,19 +82,19 @@ plot_boxplot <- function(data, x, y, breaks, x_label, y_label) {

#' Plot timeseries data
#'
#' @param data Data to plot
#' @param x Name of column to plot on x-axis, should be datetime, will be converted to Dates using as.Date
#' @param data Data to plot (data.frame with x-axis column a character convertible to Date)
#' @param x Name of column to plot on x-axis
#' @param y Name of column to plot on y-axis
#' @param breaks Date break points
#' @param breaks Date break points, must be a sequence of dates
#' @param x_label x-axis label
#' @param y_label y-axis label
#' @param title Figure title
#' @param line_width Line width
#' @param line_colour Line colour
#' @param horizontal_y y-intercept for horizontal line
#' @param vertical_x x-intercept for vertical line
#' @param x_lim Limits for x-axis continous scale, vector passed to scale_x_continuous
#' @param y_lim Limits for y-axis continuous scale, vector passed to scale_y_continous
#' @param x_lim Limits for x-axis continuous scale, vector passed to scale_x_continuous
#' @param y_lim Limits for y-axis continuous scale, vector passed to scale_y_continuous
#'
#' @return ggplot
#' @export
Expand Down Expand Up @@ -172,12 +172,12 @@ plot_timeseries <- function(data,

#' Create a line plot with a confidence interval.
#'
#' @param data Data to plot
#' @param x x-axis data
#' @param data Data to plot (all data types recognised by ggplot2::geom_line() like data.frame)
#' @param x x-axis data, must be a Date object
#' @param y1 y1 line data - solid
#' @param y2 y2 line data - dashed
#' @param y3 y3 line data - dashed
#' @param breaks Breaks vector
#' @param breaks Breaks vector, must be a sequence of dates
#' @param x_label x-axis label
#' @param y_label y-axis label
#' @param y1_colour Colour for y1
Expand Down
16 changes: 8 additions & 8 deletions R/plot_mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#' 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
#' @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 polygon_data Polygon data (SpatialPolygon or SpatialPolygonDataFrame)
#' @param raster_data Raster data (RasterLayer or SpatialRaster)
#' @param domain Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend
#' @param markers Markers to display on map. A named list or data.frame 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
Expand Down Expand Up @@ -71,10 +71,10 @@ plot_map <- function(polygon_data = NULL,

#' 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 polygon_data Polygon data (SpatialPolygon or SpatialPolygonDataFrame)
#' @param raster_data Raster data (RasterLayer or SpatialRaster)
#' @param domain Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend
#' @param markers Markers to display on map. A named list or data.frame 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
Expand Down
8 changes: 4 additions & 4 deletions R/plot_mesh.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Plot a mesh on a Leaflet map
#'
#' @param mesh Mesh data
#' @param mesh Mesh object from INLA or fmesher
#' @param spatial_data Spatial data, either a SpatialPolygonsDataFrame, SpatialPointsDataFrame or an object
#' that can be converted to a data.frame with longitude and latitude columns
#' @param longitude_column Longitude column in spatial_data
#' @param latitude_column Latitude column in spatial_data name
#' @param longitude_column Longitude column name in spatial_data
#' @param latitude_column Latitude column name in spatial_data
#' @param markers Markers to display on top of mesh. A named list with latitude, longitude and label names must be given.
#' Expects longitude name to be longitude, latitude name to be latitude, label name to be label.
#'
#' @return leaflet::leaflet
#' @return leaflet::leaflet with mesh and markers
#' @export
plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", latitude_column = "LAT", markers = NULL) {
expected_crs <- "+proj=longlat +datum=WGS84"
Expand Down
21 changes: 11 additions & 10 deletions R/plot_priors.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#' Plot line comparison for stdev etc
#'
#' @param data Parsed model output
#' @param data List of parsed model outputs from "parse_model_output" (a list of lists)
#' @param to_plot Type of data to plot, "Range for f" etc
#' @param title Title of the plot, defaults to the value of "to_plot"
#'
#' @return ggplot2::ggplot
plot_line_comparison <- function(data, to_plot, title) {
#' @return ggplot2::ggplot of the selected hyperparameter posterior distribution
plot_line_comparison <- function(data, to_plot, title = to_plot) {
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) {
Expand All @@ -19,9 +20,9 @@ plot_line_comparison <- function(data, to_plot, title) {

#' Create boxplots from priors run data
#'
#' @param data
#' @param data A list of parsed model output from "parse_model_output" (a list of lists)
#'
#' @return graphics::boxplot
#' @return graphics::boxplot of fitted values
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 @@ -34,10 +35,10 @@ plot_priors_boxplot <- function(data) {
#' Plot density function
#'
#'
#' @param data Parsed model outputs
#' @param measurement_data Measurement data
#' @param data List of parsed model outputs from "parse_model_output" (a list of lists)
#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
#'
#' @return ggplot2::ggplot
#' @return ggplot2::ggplot of measurement density by value
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 @@ -56,9 +57,9 @@ plot_priors_density <- function(data, measurement_data) {

#' Plot Deviance Information Criterion (DIC) values
#'
#' @param data
#' @param data List of parsed model outputs from "parse_model_output" (a list of lists)
#'
#' @return ggplot2::ggplot
#' @return ggplot2::ggplot with DIC values shown as points
plot_dic <- function(data) {
infocri <- base::cbind.data.frame(
priors = unlist(purrr::map(seq(1, length(data)), function(x) paste("Run", x))),
Expand Down
16 changes: 8 additions & 8 deletions R/shiny_meshbuilder.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Mesh building shiny app
#'
#' @param spatial_data Spatial data
#' @param spatial_data Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame)
#' @param obs_data Measurement data
#' @param crs CRS as a proj4string
#' @param offset Specifies the size of the inner and outer extensions around data locations, passed to fmesher::fm_mesh_2d_inla
Expand All @@ -11,7 +11,7 @@
#'
#' @importFrom magrittr %>%
#'
#' @return shiny::app
#' @return shiny::app with meshbuilder functionality
#' @keywords internal
meshbuilder_shiny <- function(
spatial_data,
Expand Down Expand Up @@ -55,10 +55,10 @@ meshbuilder_shiny <- function(
stop("Cannot read latitude and longitude data from spatial data. Please ensure given names are correct.")
}

default_max_edge_min <- 0.01
default_max_edge_max <- 0.3
default_max_edge_min <- 0.9
default_max_edge_max <- 1.8
default_offset_min <- 0.02
default_offset_max <- 0.2
default_offset_max <- 2
default_cutoff <- 0.02
# TODO - these defaults need changing?
if (!is.null(max_edge)) {
Expand Down Expand Up @@ -234,7 +234,7 @@ meshbuilder_shiny <- function(
spatial_data
}
})

output$map <- leaflet::renderLeaflet({
map_tiles <- c("OpenStreetMap", "Esri.WorldImagery", "OpenTopoMap")
m <- mapview::mapview(mesh_spatial(), layer.name = "Mesh", col.regions = "#548C2F", map.types = map_tiles) + mapview::mapview(spatial(), layer.name = "Spatial")
Expand Down Expand Up @@ -270,7 +270,7 @@ meshbuilder_shiny <- function(

#' Mesh building shiny app. Creates and visualises a mesh from some spatial data.
#'
#' @param spatial_data Spatial data
#' @param spatial_data Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame)
#' @param obs_data Measurement data
#' @param crs CRS as a proj4string
#' @param offset Specifies the size of the inner and outer extensions around data locations, passed to fmesher::fm_mesh_2d_inla
Expand All @@ -279,7 +279,7 @@ meshbuilder_shiny <- function(
#' @param y_coord Name of the latitude column in the spatial data
#' @param x_coord Name of the longitude column in the spatial data
#'
#' @return shiny::app
#' @return shiny::app with meshbuilder functionality
#' @export
mesh_builder <- function(spatial_data, obs_data = NULL, crs = NULL, max_edge = NULL, offset = NULL, cutoff = NULL, y_coord = "LAT", x_coord = "LONG") {
shiny::runApp(meshbuilder_shiny(
Expand Down
24 changes: 12 additions & 12 deletions R/shiny_modelbuilder.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#' Interactively set and see the result of different priors
#'
#' @param spatial_data Spatial data
#' @param measurement_data Measurement data
#' @param time_variable Time variable in measurement_data
#' @param mesh INLA mesh
#' @param spatial_data Spatial data (must be SpatialPoints or SpatialPointsDataFrame)
#' @param measurement_data Measurement data (SpatialPointsDataFrame, SpatialPolygonsDataFrame with a named time column and at least 1 named feature column with measurements)
#' @param time_variable Time variable name in measurement_data
#' @param mesh INLA/fmesher mesh
#' @param data_distribution Data distribution, Poisson or Gaussian
#' @param log_folder Folder to write out logs
#' @param log_folder Folder to write out logs (character)
#'
#' @importFrom INLA f
#'
#' @return shiny::app
#' @return shiny::app with model builder functionality
#' @keywords internal
model_builder_shiny <- function(spatial_data,
measurement_data,
Expand Down Expand Up @@ -65,7 +65,7 @@ model_builder_shiny <- function(spatial_data,
citation_control_group <- "Prior explanation text modified from https://www.paulamoraga.com/book-geospatial/sec-geostatisticaldataexamplest.html"

initial_equation_val <- "formula <- model_var ~ 0 + Intercept(1)"
features <- names(measurement_data)
features <- names(measurement_data@data[base::sapply(measurement_data@data, is.numeric) | base::sapply(measurement_data@data, is.logical)])
if (is.null(features)) {
stop("We require the columns of measurement_data to have the names of the features to use in the model.")
}
Expand Down Expand Up @@ -697,12 +697,12 @@ model_builder_shiny <- function(spatial_data,
#' Interactively set and see the result of different priors
#'
#' @param spatial_data Spatial data
#' @param measurement_data Measurement data
#' @param time_variable Time variable in measurement_data
#' @param mesh INLA mesh
#' @param log_folder Folder to write logs to
#' @param measurement_data Measurement data (SpatialPointsDataFrame, SpatialPolygonsDataFrame with a named time column and at least 1 named feature column with measurements)
#' @param time_variable Time variable name in measurement_data
#' @param mesh INLA/fmesher mesh
#' @param log_folder Folder to write logs to (character)
#'
#' @return shiny::app
#' @return shiny::app with model builder functionality
#' @export
model_builder <- function(spatial_data, measurement_data, time_variable, mesh, data_distribution = "Poisson", log_folder = NULL) {
shiny::runApp(model_builder_shiny(spatial_data = spatial_data, measurement_data = measurement_data, time_variable = time_variable, mesh = mesh, data_distribution = data_distribution, log_folder = log_folder))
Expand Down
Loading