Skip to content

Commit

Permalink
shapefiles package refs removed post RGDAL purge, wasn't being used a…
Browse files Browse the repository at this point in the history
…nyway
  • Loading branch information
SimonDedman committed Feb 6, 2024
1 parent 7b51497 commit 0d6f51c
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 253 deletions.
376 changes: 188 additions & 188 deletions .Rhistory

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", 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
Expand Down Expand Up @@ -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)
Binary file not shown.
Binary file modified Gbm.auto_extras/ML&E Notes.docx
Binary file not shown.
5 changes: 2 additions & 3 deletions Gbm.auto_extras/gbm.loop_functionrun.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 17 additions & 19 deletions Gbm.auto_extras/gbmauto.sepbingaus.runscript.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
mapshape = Crop_Map, simp = F)
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2021
COPYRIGHT HOLDER: Simon Dedman
YEAR: 2024
COPYRIGHT HOLDER: gbm.auto authors
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 4 additions & 26 deletions R/gbm.basemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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(
Expand All @@ -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):
Expand Down Expand Up @@ -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)}
9 changes: 5 additions & 4 deletions R/gbm.lmplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/gbm.map.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion man/gbm.auto-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions man/gbm.basemap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gbm.map.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d6f51c

Please sign in to comment.