diff --git a/.Rhistory b/.Rhistory index 227ae0f..583c313 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,191 +1,3 @@ -alerts = FALSE, -randomvar = TRUE, -smooth = TRUE, -savedir = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/") -devtools::document() -# SD TEST HERE#### -remotes::install_github("SimonDedman/gbm.auto") #only do this if needs updating again! -library(gbm.auto) -RSandVSsamples <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/NarrowedVars_07272023_RSVS.csv") -MatureRSGrid <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/MatureRSGrid.csv") -RSVScropmap <- sf::st_read(dsn = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/Map/CroppedMap/Crop_Map.shp") -setwd("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/") -# but gbm.mapsf not outputting data, whereas gbm.map IS for b&w. Why? -# Abundance_Preds_only.csv col order = lat lon pred. Is this way due to changed order in grids? -# gbm.auto L1787 : gbm.mapsf(predabund = grids[c(gridslat, gridslon, predabund)], -# gbm.mapsf function defaults: -# gbm.mapsf <- function( -# predabund = NULL, # predicted abundance data frame produced by gbm.auto (Abundance_Preds_only.csv), with Latitude, Longitude, and Predicted Abundance columns. -# predabundlon = 2, # Longitude column number. -# predabundlat = 1, # Latitude column number. -# predabundpreds = 3, -# Looks right -predabund <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/Abundance_Preds_only.csv") -gbm.auto::gbm.mapsf(predabund = predabund, -# predabundlon = 2, # Longitude column number. -# predabundlat = 1, # Latitude column number. -# predabundpreds = 3, # Predicted abundance column number. -# myLocation = NULL, # location for extents, format c(xmin, ymin, xmax, ymax). -# trim = TRUE, # remove NA & 0 values and crop to remaining date extents? Default TRUE. -# scale100 = FALSE, # scale Predicted Abundance to 100? Default FALSE. -# gmapsAPI = NULL, # enter your Google maps API here, quoted character string -# mapsource = "google", # Source for ggmap::get_map; uses Stamen as fallback if no Google Maps API present. Options: "google", "stamen", "gbm.basemap". -# googlemap = TRUE, # If pulling basemap from Google maps, this sets expansion factors since -# # Google Maps tiling zoom setup doesn't align to myLocation extents. -# maptype = "satellite", -# darkenproportion = 0, # amount to darken the basemap, 0-1. -mapzoom = 6, # google: 3 (continent) - 21 (building). stamen: 0-18 -shape = RSVScropmap, # If mapsource is "gbm.basemap", enter the full path to gbm.basemaps downloaded map, typically Crop_Map.shp, including the .shp. -# expandfactor = 0, # extents expansion factor for basemap. default was 1.6 -# colourscale = "viridis", # Scale fill colour scheme to use, default "viridis", other option is "gradient". -# colorscale = NULL, # Scale fill colour scheme to use, default NULL, populating this will overwrite colourscale. -# heatcolours = c("white", "yellow", "orange","red", "brown4"), # Vector of colours if gradient selected for colourscale, defaults to heatmap theme. -# colournumber = 8, # Number of colours to spread heatcolours over, if gradient selected for colourscale. Default 8. -studyspecies = "TEST", -# plottitle = paste0("Predicted abundance of ", studyspecies), -# plotsubtitle = "CPUE", # data %>% distinct(ID) %>% nrow() # 13 -# legendtitle = "CPUE", -# plotcaption = paste0("gbm.auto::gbm.map, ", lubridate::today()), -# axisxlabel = "Longitude", -# axisylabel = "Latitude", -legendposition = c(0.05, 0.18), -# fontsize = 12, -# fontfamily = "Times New Roman", -# filesavename = paste0(lubridate::today(), "_", studyspecies, "_", legendtitle, ".png"), -savedir = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/gbmmapsftest" -) -if (TRUE & TRUE) print("yay") -mapsource = "google" -mapzoom = NULL -if (mapsource == "google" & mapzoom == NULL) print("yay") -mapzoom == NULL -is.null(mapzoom) -devtools::document() -# SD TEST HERE#### -remotes::install_github("SimonDedman/gbm.auto") #only do this if needs updating again! -# ctrl shift F10 -library(gbm.auto) -RSandVSsamples <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/NarrowedVars_07272023_RSVS.csv") -MatureRSGrid <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/MatureRSGrid.csv") -RSVScropmap <- sf::st_read(dsn = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/Map/CroppedMap/Crop_Map.shp") -setwd("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/") -# but gbm.mapsf not outputting data, whereas gbm.map IS for b&w. Why? -# Abundance_Preds_only.csv col order = lat lon pred. Is this way due to changed order in grids? -# gbm.auto L1787 : gbm.mapsf(predabund = grids[c(gridslat, gridslon, predabund)], -# gbm.mapsf function defaults: -# gbm.mapsf <- function( -# predabund = NULL, # predicted abundance data frame produced by gbm.auto (Abundance_Preds_only.csv), with Latitude, Longitude, and Predicted Abundance columns. -# predabundlon = 2, # Longitude column number. -# predabundlat = 1, # Latitude column number. -# predabundpreds = 3, -# Looks right -predabund <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/Abundance_Preds_only.csv") -gbm.auto::gbm.mapsf(predabund = predabund, -# predabundlon = 2, # Longitude column number. -# predabundlat = 1, # Latitude column number. -# predabundpreds = 3, # Predicted abundance column number. -# myLocation = NULL, # location for extents, format c(xmin, ymin, xmax, ymax). -# trim = TRUE, # remove NA & 0 values and crop to remaining date extents? Default TRUE. -# scale100 = FALSE, # scale Predicted Abundance to 100? Default FALSE. -# gmapsAPI = NULL, # enter your Google maps API here, quoted character string -# mapsource = "google", # Source for ggmap::get_map; uses Stamen as fallback if no Google Maps API present. Options: "google", "stamen", "gbm.basemap". -# googlemap = TRUE, # If pulling basemap from Google maps, this sets expansion factors since -# # Google Maps tiling zoom setup doesn't align to myLocation extents. -# maptype = "satellite", -# darkenproportion = 0, # amount to darken the basemap, 0-1. -# mapzoom = NULL, # google: 3 (continent) - 21 (building). stamen: 0-18 -shape = RSVScropmap, # If mapsource is "gbm.basemap", enter the full path to gbm.basemaps downloaded map, typically Crop_Map.shp, including the .shp. -# expandfactor = 0, # extents expansion factor for basemap. default was 1.6 -# colourscale = "viridis", # Scale fill colour scheme to use, default "viridis", other option is "gradient". -# colorscale = NULL, # Scale fill colour scheme to use, default NULL, populating this will overwrite colourscale. -# heatcolours = c("white", "yellow", "orange","red", "brown4"), # Vector of colours if gradient selected for colourscale, defaults to heatmap theme. -# colournumber = 8, # Number of colours to spread heatcolours over, if gradient selected for colourscale. Default 8. -studyspecies = "TEST", -# plottitle = paste0("Predicted abundance of ", studyspecies), -# plotsubtitle = "CPUE", # data %>% distinct(ID) %>% nrow() # 13 -# legendtitle = "CPUE", -# plotcaption = paste0("gbm.auto::gbm.map, ", lubridate::today()), -# axisxlabel = "Longitude", -# axisylabel = "Latitude", -legendposition = c(0.05, 0.18), -# fontsize = 12, -# fontfamily = "Times New Roman", -# filesavename = paste0(lubridate::today(), "_", studyspecies, "_", legendtitle, ".png"), -savedir = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/gbmmapsftest" -) -gbm.auto::gbm.mapsf(predabund = predabund, -# predabundlon = 2, # Longitude column number. -# predabundlat = 1, # Latitude column number. -# predabundpreds = 3, # Predicted abundance column number. -# myLocation = NULL, # location for extents, format c(xmin, ymin, xmax, ymax). -trim = TRUE, # remove NA & 0 values and crop to remaining date extents? Default TRUE. -# scale100 = FALSE, # scale Predicted Abundance to 100? Default FALSE. -# gmapsAPI = NULL, # enter your Google maps API here, quoted character string -# mapsource = "google", # Source for ggmap::get_map; uses Stamen as fallback if no Google Maps API present. Options: "google", "stamen", "gbm.basemap". -# googlemap = TRUE, # If pulling basemap from Google maps, this sets expansion factors since -# # Google Maps tiling zoom setup doesn't align to myLocation extents. -# maptype = "satellite", -# darkenproportion = 0, # amount to darken the basemap, 0-1. -# mapzoom = NULL, # google: 3 (continent) - 21 (building). stamen: 0-18 -shape = RSVScropmap, # If mapsource is "gbm.basemap", enter the full path to gbm.basemaps downloaded map, typically Crop_Map.shp, including the .shp. -# expandfactor = 0, # extents expansion factor for basemap. default was 1.6 -# colourscale = "viridis", # Scale fill colour scheme to use, default "viridis", other option is "gradient". -# colorscale = NULL, # Scale fill colour scheme to use, default NULL, populating this will overwrite colourscale. -# heatcolours = c("white", "yellow", "orange","red", "brown4"), # Vector of colours if gradient selected for colourscale, defaults to heatmap theme. -# colournumber = 8, # Number of colours to spread heatcolours over, if gradient selected for colourscale. Default 8. -studyspecies = "TEST", -# plottitle = paste0("Predicted abundance of ", studyspecies), -# plotsubtitle = "CPUE", # data %>% distinct(ID) %>% nrow() # 13 -# legendtitle = "CPUE", -# plotcaption = paste0("gbm.auto::gbm.map, ", lubridate::today()), -# axisxlabel = "Longitude", -# axisylabel = "Latitude", -legendposition = c(0.05, 0.18), -# fontsize = 12, -# fontfamily = "Times New Roman", -# filesavename = paste0(lubridate::today(), "_", studyspecies, "_", legendtitle, ".png"), -savedir = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/gbmmapsftest" -) -gbm.auto::gbm.mapsf(predabund = predabund, -# predabundlon = 2, # Longitude column number. -# predabundlat = 1, # Latitude column number. -# predabundpreds = 3, # Predicted abundance column number. -# myLocation = NULL, # location for extents, format c(xmin, ymin, xmax, ymax). -trim = TRUE, # remove NA & 0 values and crop to remaining date extents? Default TRUE. -trimfivepct = TRUE, -# scale100 = FALSE, # scale Predicted Abundance to 100? Default FALSE. -# gmapsAPI = NULL, # enter your Google maps API here, quoted character string -# mapsource = "google", # Source for ggmap::get_map; uses Stamen as fallback if no Google Maps API present. Options: "google", "stamen", "gbm.basemap". -# googlemap = TRUE, # If pulling basemap from Google maps, this sets expansion factors since -# # Google Maps tiling zoom setup doesn't align to myLocation extents. -# maptype = "satellite", -# darkenproportion = 0, # amount to darken the basemap, 0-1. -# mapzoom = NULL, # google: 3 (continent) - 21 (building). stamen: 0-18 -shape = RSVScropmap, # If mapsource is "gbm.basemap", enter the full path to gbm.basemaps downloaded map, typically Crop_Map.shp, including the .shp. -# expandfactor = 0, # extents expansion factor for basemap. default was 1.6 -# colourscale = "viridis", # Scale fill colour scheme to use, default "viridis", other option is "gradient". -# colorscale = NULL, # Scale fill colour scheme to use, default NULL, populating this will overwrite colourscale. -# heatcolours = c("white", "yellow", "orange","red", "brown4"), # Vector of colours if gradient selected for colourscale, defaults to heatmap theme. -# colournumber = 8, # Number of colours to spread heatcolours over, if gradient selected for colourscale. Default 8. -studyspecies = "TEST", -# plottitle = paste0("Predicted abundance of ", studyspecies), -# plotsubtitle = "CPUE", # data %>% distinct(ID) %>% nrow() # 13 -# legendtitle = "CPUE", -# plotcaption = paste0("gbm.auto::gbm.map, ", lubridate::today()), -# axisxlabel = "Longitude", -# axisylabel = "Latitude", -legendposition = c(0.05, 0.18), -# fontsize = 12, -# fontfamily = "Times New Roman", -# filesavename = paste0(lubridate::today(), "_", studyspecies, "_", legendtitle, ".png"), -savedir = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/gbmmapsftest" -) -devtools::document() -devtools::check() -?rename -data("iris") -tmp <- iris |> dplyr::rename("MYSPECIES" = "Species") -devtools::document() devtools::check() View(iris) tmp <- iris |> dplyr::arrange("Sepal.Length") @@ -510,3 +322,191 @@ devtools::release() devtools::document() devtools::release() devtools::document() +drumline <- readRDS("/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Data/2023-12-18_drumline_reefs_dropoff.rds") +drumline %<>% tidyr::drop_na(CaribbeanReef_CPUE) +library(magrittr) # %<>% +library(dplyr) # %>% matches last filter mutate case_when relocate everything rename across last_col bind_cols group_by tally pull summarise n_distinct left_join arrange select bind_rows # %>% matches last filter mutate case_when relocate everything rename across last_col bind_cols group_by tally pull summarise n_distinct left_join arrange select bind_rows +library(lubridate) # minute yday month is.POSIXt today +library(tidyverse) # "No used functions found" # "No used functions found" +library(tidylog) # filter mutate relocate pivot_wider rename replace_na group_by tally summarise left_join drop_na select pivot_longer # filter mutate relocate pivot_wider rename replace_na group_by tally summarise left_join drop_na select pivot_longer +library(gbm.auto) +source("~/Dropbox/Galway/Analysis/R/My Misc Scripts/lognegs.R") +drumline <- readRDS("/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Data/2023-12-18_drumline_reefs_dropoff.rds") +drumline %<>% tidyr::drop_na(CaribbeanReef_CPUE) +samples = as.data.frame(drumline |> filter(CaribbeanReef_CPUE != 0) |> select(CaribbeanReef_CPUE, all_of(expvars))), +samples = as.data.frame(drumline |> filter(CaribbeanReef_CPUE != 0) |> select(CaribbeanReef_CPUE, all_of(expvars))) +drumline <- readRDS("/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Data/2023-12-18_drumline_reefs_dropoff.rds") +drumline %<>% tidyr::drop_na(CaribbeanReef_CPUE) +expvars = c( +"Habitat", # Site3 Habitat Substrate2 all similar +"Tide", +"Season", +"LunarPhase", +"Depth_m", +"Temperature_C", +"Yearday", +"DtDropOff" +) +samples = as.data.frame(drumline |> filter(CaribbeanReef_CPUE != 0) |> select(CaribbeanReef_CPUE, all_of(expvars))) +expvar = expvars +# expvar = c("Habitat", "Tide", "LunarPhase", "Depth_m", "Temperature_C", "Yearday", "DtDropOffLogNeg"), +# expvar = c("DtDropOffLogNeg"), +resvar = "CaribbeanReef_CPUE" +# expvarnames = NULL, +# resvarname = NULL, +savedir = paste0("../../Projects/2021-10_Drumline_Reefshark/LMplots PairPlots/") +expvarnames = NULL +resvarname = NULL +plotname = NULL +pngtype = c("cairo-png", "quartz", "Xlib") +r2line = TRUE +pointtext = FALSE +pointlabs = resvar +pointcol = "black" +expvar +i <- "Tide" +print(paste0("plotting ", which(expvar %in% i), "/", length(expvar), ": ", i)) +# overwrite xname if expvarnames present +xname <- ifelse(test = is.null(expvarnames), +yes = i, +no = expvarnames[which(expvar %in% i)]) +# overwrite plotname if plotname present +plotname <- ifelse(test = is.null(plotname), +yes = xname, +no = plotname[which(expvar %in% i)]) +# overwrite yname if resvarname present +yname <- ifelse(test = is.null(resvarname), +yes = resvar, +no = resvarname) +# run plot +gbm.auto::lmplot( +x = samples[, i], +y = samples[, resvar], +xname = xname, +yname = yname, +savedir = savedir, +pngtype = c("cairo-png", "quartz", "Xlib"), +# xlab = xname, # x axis label, parsed from xname unless specified +# ylab = yname, # y axis label, parsed from yname unless specified +plotname = plotname, # filename for png, parsed from xname unless specified +r2line = r2line, # plot rsquared trendline, default TRUE +pointtext = pointtext, # label each point? Default false +pointlabs = pointlabs, # point labels, defaults to resvar value +pointcol = pointcol, # points colour +) +savedir +getwd() +# expvarnames = NULL, +# resvarname = NULL, +savedir = "/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Projects/2021-10_Drumline_Reefshark/LMplots PairPlots" +# run plot +gbm.auto::lmplot( +x = samples[, i], +y = samples[, resvar], +xname = xname, +yname = yname, +savedir = savedir, +pngtype = c("cairo-png", "quartz", "Xlib"), +# xlab = xname, # x axis label, parsed from xname unless specified +# ylab = yname, # y axis label, parsed from yname unless specified +plotname = plotname, # filename for png, parsed from xname unless specified +r2line = r2line, # plot rsquared trendline, default TRUE +pointtext = pointtext, # label each point? Default false +pointlabs = pointlabs, # point labels, defaults to resvar value +pointcol = pointcol, # points colour +) +# expvarnames = NULL, +# resvarname = NULL, +savedir = "/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Projects/2021-10_Drumline_Reefshark/LMplots PairPlots/" +# run plot +gbm.auto::lmplot( +x = samples[, i], +y = samples[, resvar], +xname = xname, +yname = yname, +savedir = savedir, +pngtype = c("cairo-png", "quartz", "Xlib"), +# xlab = xname, # x axis label, parsed from xname unless specified +# ylab = yname, # y axis label, parsed from yname unless specified +plotname = plotname, # filename for png, parsed from xname unless specified +r2line = r2line, # plot rsquared trendline, default TRUE +pointtext = pointtext, # label each point? Default false +pointlabs = pointlabs, # point labels, defaults to resvar value +pointcol = pointcol, # points colour +) +plotname +plotname = NULL +expvar +for (i in expvar) { # i <- "Tide" +print(paste0("plotting ", which(expvar %in% i), "/", length(expvar), ": ", i)) +# overwrite xname if expvarnames present +xname <- ifelse(test = is.null(expvarnames), +yes = i, +no = expvarnames[which(expvar %in% i)]) +# overwrite plotname if plotname present +plotnameFun <- ifelse(test = is.null(plotname), +yes = xname, +no = plotname[which(expvar %in% i)]) +# overwrite yname if resvarname present +yname <- ifelse(test = is.null(resvarname), +yes = resvar, +no = resvarname) +# run plot +gbm.auto::lmplot( +x = samples[, i], +y = samples[, resvar], +xname = xname, +yname = yname, +savedir = savedir, +pngtype = c("cairo-png", "quartz", "Xlib"), +# xlab = xname, # x axis label, parsed from xname unless specified +# ylab = yname, # y axis label, parsed from yname unless specified +plotname = plotnameFun, # filename for png, parsed from xname unless specified +r2line = r2line, # plot rsquared trendline, default TRUE +pointtext = pointtext, # label each point? Default false +pointlabs = pointlabs, # point labels, defaults to resvar value +pointcol = pointcol, # points colour +) +rm(list("xname", "plotname")) +} +for (i in expvar) { # i <- "Tide" +print(paste0("plotting ", which(expvar %in% i), "/", length(expvar), ": ", i)) +# overwrite xname if expvarnames present +xname <- ifelse(test = is.null(expvarnames), +yes = i, +no = expvarnames[which(expvar %in% i)]) +# overwrite plotname if plotname present +plotnameFun <- ifelse(test = is.null(plotname), +yes = xname, +no = plotname[which(expvar %in% i)]) +# overwrite yname if resvarname present +yname <- ifelse(test = is.null(resvarname), +yes = resvar, +no = resvarname) +# run plot +gbm.auto::lmplot( +x = samples[, i], +y = samples[, resvar], +xname = xname, +yname = yname, +savedir = savedir, +pngtype = c("cairo-png", "quartz", "Xlib"), +# xlab = xname, # x axis label, parsed from xname unless specified +# ylab = yname, # y axis label, parsed from yname unless specified +plotname = plotnameFun, # filename for png, parsed from xname unless specified +r2line = r2line, # plot rsquared trendline, default TRUE +pointtext = pointtext, # label each point? Default false +pointlabs = pointlabs, # point labels, defaults to resvar value +pointcol = pointcol, # points colour +) +} +samples <- read.csv("~/Downloads/catchdata_2001-2020_USETHISONEforBRT.csv", header=FALSE) +View(samples) +library(gbm.auto) +gbm.auto(samples=samples,expvar=c(10:26),resvar=27,lr=c(0.01,0.001),savedir = "/home/simon/Downloads/") +library(tidyverse) +samples <- read_csv("/home/simon/Downloads/data.csv") +gbm.auto(samples=samples,expvar=c(10:26),resvar=27,lr=c(0.01,0.001),savedir = "/home/simon/Downloads/") +usethis::use_mit_license() +document() +devtools::document() diff --git a/DESCRIPTION b/DESCRIPTION index 2585602..4cc5e1f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gbm.auto Title: Automated Boosted Regression Tree Modelling and Mapping Suite -Version: 2023.12.14 +Version: 2024.02.06 Authors@R: person("Simon", "Dedman", , "simondedman@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9108-972X")) Description: Automates delta log-normal boosted regression tree abundance prediction. Loops through parameters provided (LR (learning rate), TC @@ -41,5 +41,5 @@ Imports: Encoding: UTF-8 Language: en-GB LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) diff --git "a/Gbm.auto_extras/2023-12-21_ML\302\255_Model_\302\255evaluation_TLDR_explainer.docx" "b/Gbm.auto_extras/2023-12-21_ML\302\255_Model_\302\255evaluation_TLDR_explainer.docx" new file mode 100644 index 0000000..9df1734 Binary files /dev/null and "b/Gbm.auto_extras/2023-12-21_ML\302\255_Model_\302\255evaluation_TLDR_explainer.docx" differ diff --git a/Gbm.auto_extras/ML&E Notes.docx b/Gbm.auto_extras/ML&E Notes.docx index 5b40bf7..133573c 100644 Binary files a/Gbm.auto_extras/ML&E Notes.docx and b/Gbm.auto_extras/ML&E Notes.docx differ diff --git a/Gbm.auto_extras/gbm.loop_functionrun.R b/Gbm.auto_extras/gbm.loop_functionrun.R index f48a45d..ee190c1 100644 --- a/Gbm.auto_extras/gbm.loop_functionrun.R +++ b/Gbm.auto_extras/gbm.loop_functionrun.R @@ -33,9 +33,8 @@ mygrids <- gbm.auto::grids # load grids mysamples <- gbm.auto::samples # load samples setwd("/home/simon/Dropbox/Galway/Project Sections/5. Intro & Conclusion/Extra graphics/CofV/") -# library("shapefiles") -# Crop_Map <- read.shapefile("/home/simon/Desktop/gbm temp/CroppedMap/Crop_Map") -library(mapplots) +# Crop_Map <- st_read(dsn = paste0("Crop_Map", ".shp"), layer = savename, quiet = TRUE) +# library(mapplots) data(coast) shape <- coast diff --git a/Gbm.auto_extras/gbmauto.sepbingaus.runscript.R b/Gbm.auto_extras/gbmauto.sepbingaus.runscript.R index de81de0..d21610d 100644 --- a/Gbm.auto_extras/gbmauto.sepbingaus.runscript.R +++ b/Gbm.auto_extras/gbmauto.sepbingaus.runscript.R @@ -1,10 +1,9 @@ library("gbm.auto") mygrids <- gbm.auto::grids # load grids mysamples <- gbm.auto::samples # load samples -setwd("/home/simon/Desktop/gbm temp/sepParamTestbench/") -source('~/Dropbox/Galway/Analysis/R/gbm.auto/R/gbm.utils.R') -library("shapefiles") -Crop_Map <- read.shapefile("/home/simon/Desktop/gbm temp/CroppedMap/Crop_Map") +# setwd("/home/simon/Desktop/gbm temp/sepParamTestbench/") +# source('~/Dropbox/Galway/Analysis/R/gbm.auto/R/gbm.utils.R') +Crop_Map <- st_read(dsn = paste0("Crop_Map", ".shp"), layer = savename, quiet = TRUE) #source('~/Dropbox/Galway/Analysis/R/gbm.auto/Gbm.auto_extras/gbm.auto.binGausSepParams.R') # test1 basic clean run @@ -175,24 +174,23 @@ gbm.auto(samples = mysamples, grids = mygrids, expvar = c(4:9), resvar = 11, # (bf is a list with a vector AND lr OR tc are lists) # if fails. Purple lines not printed in fail runs. # [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Variable interactions done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Binomial predictions done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Gaussian predictions done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Final abundance calculated XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Binomial predictions done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Gaussian predictions done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Final abundance calculated XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Output CSVs written XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Report CSV written XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX RSB CSV written XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Reticulating splines XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour map generated XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Black & white map generated XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour RSB bin map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour RSB Gaus map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour RSB combo map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX B&W RSB bin map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX B&W RSB Gaus map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -[1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX B&W RSB combo map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX RSB CSV written XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Reticulating splines XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour map generated XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Black & white map generated XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour RSB bin map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour RSB Gaus map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Colour RSB combo map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX B&W RSB bin map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX B&W RSB Gaus map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +# [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX B&W RSB combo map done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Grids/maps/everything done XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # > gbm.auto(samples = mysamples, grids = mygrids, expvar = c(4:9), resvar = 11, -# THE FAIL ONES DIDN'T HAVE GRIDS YOU FUCKING FUCK!! JESUS BOY! gbm.auto(samples = mysamples, grids = mygrids, expvar = c(4:9), resvar = 11, tc = list(2,c(2,3)), lr = list(c(0.01, 0.02), 0.005), @@ -230,4 +228,4 @@ gbm.auto(samples = mysamples, grids = mygrids, expvar = c(4:9), resvar = 11, tc = list(2,c(2,3)), lr = list(c(0.01, 0.02), 0.005), bf = 0.5, - mapshape = Crop_Map, simp = F) \ No newline at end of file + mapshape = Crop_Map, simp = F) diff --git a/LICENSE b/LICENSE index 59f0e45..c9636c5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,2 +1,2 @@ -YEAR: 2021 -COPYRIGHT HOLDER: Simon Dedman +YEAR: 2024 +COPYRIGHT HOLDER: gbm.auto authors diff --git a/LICENSE.md b/LICENSE.md index 7a3ed63..0ce7f1c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2021 Simon Dedman +Copyright (c) 2024 gbm.auto authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/R/gbm.basemap.R b/R/gbm.basemap.R index 6f4967a..44f5811 100644 --- a/R/gbm.basemap.R +++ b/R/gbm.basemap.R @@ -34,7 +34,6 @@ #' @importFrom graphics lines par #' @importFrom utils download.file unzip #' @importFrom sf st_crop st_read st_write sf_use_s2 -# #' @importFrom shapefiles read.shapefile #' @author Simon Dedman, \email{simondedman@@gmail.com} #' @examples #' \donttest{ @@ -56,21 +55,14 @@ #' 2. If rgdal install fails in Linux try: #' sudo apt-get install libgdal-dev && sudo apt-get install libproj-dev" #' -#' 3. Error in as.environment(pos):no item called "package:shapefiles" on the -#' search list: strange error occurring despite shapefiles being coded like all -#' other packages. Correct output produced regardless. -#' -#' 4. subscript out of bounds: can't crop world map to your bounds. +#' 3. subscript out of bounds: can't crop world map to your bounds. #' Check lat/lon are the right way around: check gridslat and gridslon point to the correct columns #' for lat and lon in grids, and those columns named (something like) lat and lon, ARE ACTUALLY the #' latitudes and longitudes, and not the wrong way around. #' -#' 5. If your download is timing out use options(timeout = 240). -#' -#' 6. Error in attachNamespace("shapefiles"): namespace is already attached. Use: -#' unloadNamespace("shapefiles") . +#' 4. If your download is timing out use options(timeout = 240). #' -#' 7. Error in if (scope >= 160) res <- "c" : missing value where TRUE/FALSE needed. Check gridslat +#' 5. Error in if (scope >= 160) res <- "c" : missing value where TRUE/FALSE needed. Check gridslat #' and gridslon are indexing the correct columns in grids. #' gbm.basemap <- function( @@ -88,11 +80,6 @@ gbm.basemap <- function( # returnsf = FALSE # obviated by gbm.mapsf ) { # Return object as simple features object? Default FALSE, returns as list format for draw.shape in mapplots, used in gbm.map - attachNamespace("shapefiles") # else Error in as.environment(pos): no item called "package:shapefiles" on the search list - # or Error during wrapup: no item called "package:shapefiles" on the search list - # despite shapefiles being in imports here, in namespace, & in description. Doesn't do this for any other package. - # But if I include this the line can get run twice, giving the error: "namespace(shapefiles) was already taken." - oldwd <- getwd() # record original directory on.exit(setwd(oldwd), add = TRUE) # defensive block, thanks to Gregor Sayer sf::sf_use_s2(FALSE) # 2021 addition of s2 code to sf often causes: Error in s2_geography_from_wkb(x, oriented = oriented, check = check): @@ -159,19 +146,10 @@ gbm.basemap <- function( world <- st_read(dsn = paste0("GSHHS_", res, "_L1.shp"), layer = paste0("GSHHS_", res, "_L1"), quiet = TRUE) # read in worldmap cropshp <- st_crop(world, xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax) # crop to extents - # setwd(savedir) # setwd to savedir else saves CroppedMap folder in res folder setwd("../../") # setwd to savedir else saves CroppedMap folder in res folder dir.create("CroppedMap") # create conservation maps directory setwd("CroppedMap") st_write(cropshp, dsn = paste0(savename, ".shp"), append = FALSE) # append FALSE overwrites existing files - - # if (returnsf) { - # cropshp <- st_read(dsn = paste0(savename, ".shp"), layer = savename, quiet = TRUE) # read in worldmap - # } else { - # cropshp <- shapefiles::read.shapefile(savename) # read it back in with read.shapefile which results in the expected format for draw.shape in mapplots, used in gbm.map # shapefiles:: - # } - - cropshp <- st_read(dsn = paste0(savename, ".shp"), layer = savename, quiet = TRUE) # read in worldmap - + # cropshp <- st_read(dsn = paste0(savename, ".shp"), layer = savename, quiet = TRUE) # read in worldmap print(paste("World map cropped and saved successfully")) return(cropshp)} diff --git a/R/gbm.lmplots.R b/R/gbm.lmplots.R index d7bc36e..d1f6a05 100644 --- a/R/gbm.lmplots.R +++ b/R/gbm.lmplots.R @@ -33,10 +33,11 @@ #' ## Simon Dedman 2018.08.30 & 2023-03-07 ## To Run: -# lmplot(x = samples[,expvar], -# y = samples[,resvar], -# xname = expvar, -# yname = resvar) +# gbm.lmplots(samples = samples[,c(resvar, expvar)], +# expvar = expvar, +# resvar = resvar, +# expvarnames = expvar, +# resvarname = resvar) gbm.lmplots <- function(samples = NULL, # dataframe diff --git a/R/gbm.map.R b/R/gbm.map.R index 901aa1c..41fadfd 100644 --- a/R/gbm.map.R +++ b/R/gbm.map.R @@ -29,7 +29,7 @@ #' @param colournumber Number of colours to spread heatcol over, default:8. #' @param shape Basemap shape to draw, from draw.shape in mapplots. Defaults to #' NULL which calls gbm.basemap to generate it for you. First read in a shp file e.g. myshape <- -#' shapefiles::read.shapefile("Crop_Map") WITHOUT the .shp extension, then use shape = myshape. +#' sf::st_read(dsn = paste0(savename, ".shp"), layer = savename, quiet = TRUE), then use shape = myshape. #' @param landcol Colour for 'null' area of map (for marine plots, this is #' land), from draw.shape in mapplots. Default "grey80" (light grey). #' @param mapback Basemap background colour, defaults to lightblue (ocean for diff --git a/man/gbm.auto-package.Rd b/man/gbm.auto-package.Rd index 2024a05..8482aa5 100644 --- a/man/gbm.auto-package.Rd +++ b/man/gbm.auto-package.Rd @@ -3,7 +3,6 @@ \docType{package} \name{gbm.auto-package} \alias{gbm.auto-package} -\alias{_PACKAGE} \title{gbm.auto: Automated Boosted Regression Tree Modelling and Mapping Suite} \description{ Automates delta log-normal boosted regression tree abundance prediction. Loops through parameters provided (LR (learning rate), TC (tree complexity), BF (bag fraction)), chooses best, simplifies, & generates line, dot & bar plots, & outputs these & predictions & a report, makes predicted abundance maps, and Unrepresentativeness surfaces. Package core built around 'gbm' (gradient boosting machine) functions in 'dismo' (Hijmans, Phillips, Leathwick & Jane Elith, 2020 & ongoing), itself built around 'gbm' (Greenwell, Boehmke, Cunningham & Metcalfe, 2020 & ongoing, originally by Ridgeway). Indebted to Elith/Leathwick/Hastie 2008 'Working Guide' \doi{10.1111/j.1365-2656.2008.01390.x}; workflow follows Appendix S3. See \url{http://www.simondedman.com/} for published guides and papers using this package. diff --git a/man/gbm.basemap.Rd b/man/gbm.basemap.Rd index 4c0848a..54dc270 100644 --- a/man/gbm.basemap.Rd +++ b/man/gbm.basemap.Rd @@ -66,16 +66,11 @@ in the correct directory relative to it. This error means it looked for the folder and couldn't find it. \item If rgdal install fails in Linux try: sudo apt-get install libgdal-dev && sudo apt-get install libproj-dev" -\item Error in as.environment(pos):no item called "package:shapefiles" on the -search list: strange error occurring despite shapefiles being coded like all -other packages. Correct output produced regardless. \item subscript out of bounds: can't crop world map to your bounds. Check lat/lon are the right way around: check gridslat and gridslon point to the correct columns for lat and lon in grids, and those columns named (something like) lat and lon, ARE ACTUALLY the latitudes and longitudes, and not the wrong way around. \item If your download is timing out use options(timeout = 240). -\item Error in attachNamespace("shapefiles"): namespace is already attached. Use: -unloadNamespace("shapefiles") . \item Error in if (scope >= 160) res <- "c" : missing value where TRUE/FALSE needed. Check gridslat and gridslon are indexing the correct columns in grids. } diff --git a/man/gbm.map.Rd b/man/gbm.map.Rd index fa8ee43..b498769 100644 --- a/man/gbm.map.Rd +++ b/man/gbm.map.Rd @@ -62,7 +62,7 @@ legend.grid and draw.grid in mapplots which is c("white", "yellow", "orange" \item{shape}{Basemap shape to draw, from draw.shape in mapplots. Defaults to NULL which calls gbm.basemap to generate it for you. First read in a shp file e.g. myshape <- -shapefiles::read.shapefile("Crop_Map") WITHOUT the .shp extension, then use shape = myshape.} +sf::st_read(dsn = paste0(savename, ".shp"), layer = savename, quiet = TRUE), then use shape = myshape.} \item{landcol}{Colour for 'null' area of map (for marine plots, this is land), from draw.shape in mapplots. Default "grey80" (light grey).}