Coder Social home page Coder Social logo

adamlilith / fasterraster Goto Github PK

View Code? Open in Web Editor NEW
40.0 3.0 5.0 83.19 MB

Faster raster processing in R using GRASS GIS

License: GNU General Public License v3.0

R 100.00%
raster fragmentation-indices fragmentation rasterize topography slope aspect grass-gis grass vectorization

fasterraster's Introduction

fasterRaster

GPLv3 license

Faster raster processing in R using GRASS GIS

fasterRaster is a package designed specifically to handle large-in-memory/large-on-disk spatial rasters and vectors. fasterRaster does this using the stand-alone installer of Open Source Geospatial's GRASS GIS

fasterRaster was created with five design principles:

  • Value added: fasterRaster complements terra and sf, and is highly dependent on them! It is useful for analyzing large-in-memory/large-on-disk rasters and vectors that those packages struggle to handle. For medium- and small-size objects, terra and sf will almost always be faster.
  • Familiarity: If you know how to use terra, you basically know how to use fasterRaster! That's because most of the functions have the same name and almost the same arguments as terra functions.
  • Comparability: To the degree possible, outputs from fasterRaster are the same as those from functions in terra with the same name.
  • Simplicity: GRASS requires users to track things like "locations", "mapsets", and "regions" for which there is no comparable analog in the terra or sf packages. fasterRaster handles these behind the scenes so you don't need to.
  • It's R: The rgrass package provides a powerful conduit through which you can run GRASS modules from R. As such, it provides much more flexibility than fasterRaster. However, to use rgrass, you need to know what GRASS modules you need and be familiar with GRASS syntax. fasterRaster obviates this step but uses rgrass as a backend, allowing you to focus on R syntax and look up help for functions the normal way you do in R. You don't need to know GRASS!

fasterRaster makes heavy use of the rgrass package by Roger Bivand and others, the terra package by Robert Hijmans, the sf package by Edzer Pebesma Roger Bivand, and of course GRASS GIS, so is greatly indebted to all of these creators!

Where we are

As of 2024/08/01, a new version of this package, fasterRaster 8.3, is in alpha release (i.e., near final release). There are known issues and unknown issues. If you encounter one of the latter, please file an issue report.

Special announcement: The new bioclims() function creates the "classic" set of BIOCLIM variables, plus an optional "extended" set. The function works on fasterRaster GRasters and on terra SpatRasters!

Functions

To see a detailed list of functions available in fasterRaster, attach the package and use ?fasterRaster. Note the additional tutorials linked from there!

Getting started

To install fasterRaster, please use:

remotes::install_github('adamlilith/fasterRaster', dependencies = TRUE)

Alternatively, you can install the development version from:

remotes::install_github('adamlilith/fasterRaster@intuitive_fasterRaster', dependencies = TRUE)

To use fasterRaster you must install GRASS version 8+ on your operating system. You will need to use the stand-alone installer, not the Open Source Geospatial (OS Geo) installer.

An example

We'll do a simple operation in which we:

  1. Add a buffer to lines representing rivers, then
  2. Calculate the distance to from each cell to the closest buffer and burn the distance values into a raster; then
  3. Compare the frequency of "geomorphons" (idealized topographical features, like "valley", "slope", "peak", etc.) across the entire region to areas close to rivers.

To do this, we'll be using maps representing the middle of the eastern coast of Madagascar. We will also use the terra and sf packages.

library(terra)
library(sf)
library(fasterRaster)

# Get example elevation raster and rivers vector:
madElev <- fastData('madElev') # SpatRaster with elevation
madRivers <- fastData('madRivers') # sp vector with rivers

# Plot inputs:
plot(madElev)
plot(st_geometry(madRivers), col = "blue", add = TRUE)

Before you use nearly any function in the package, you need to tell fasterRaster where GRASS is installed on your system. The installation folder will vary by operating system and maybe GRASS version, but will look something like this:

grassDir <- "C:/Program Files/GRASS GIS 8.3" # Windows
grassDir <- "/Applications/GRASS-8.2.app/Contents/Resources" # Mac OS
grassDir <- "/usr/local/grass" # Linux

Now, use the faster() function to tell fasterRaster where GRASS is installed:

faster(grassDir = grassDir)

The fast() function is the key function for loading a raster or vector into fasterRaster format. Rasters in this package are called GRasters and vectors GVectors (the "G" stands for GRASS). We will now convert the madElev raster, which is a SpatRaster from the terra package, into a GRaster.

elev <- fast(madElev)
elev

You should see some metadata on the GRaster:

class       : GRaster
topology    : 2D 
dimensions  : 1024, 626, NA, 1 (nrow, ncol, ndepth, nlyr)
resolution  : 59.85157, 59.85157, NA (x, y, z)
extent      : 731581.552, 769048.635, 1024437.272, 1085725.279 (xmin, xmax, ymin, ymax)
coord ref.  : Tananarive (Paris) / Laborde Grid 
name(s)     : madElev 
datatype    : integer 
min. value  :       1 
max. value  :     570

Next, we'll do the same for the rivers vector. In this case, the vector is an sf object from the sf package, but we could also use a SpatVector from the terra package.

rivers <- fast(madRivers)
rivers
class       : GVector
geometry    : 2D lines 
dimensions  : 11, 11, 5 (geometries, sub-geometries, columns)
extent      : 731627.1, 762990.132, 1024541.235, 1085580.454 (xmin, xmax, ymin, ymax)
coord ref.  : Tananarive (Paris) / Laborde Grid 
names       :   F_CODE_DES          HYC_DESCRI      NAM   ISO     NAME_0 
type        :        <chr>               <chr>    <chr> <chr>      <chr> 
values      : River/Stream Perennial/Permanent MANANARA   MDG Madagascar 
              River/Stream Perennial/Permanent MANANARA   MDG Madagascar 
              River/Stream Perennial/Permanent      UNK   MDG Madagascar 
             ...and  8  more rows

Now, let's add a 1000-m buffer to the rivers using buffer(). As much as possible, fasterRaster functions have the same names and same arguments as their counterparts in the terra package to help users who are familiar with that package.

Note, though, that the output from fasterRaster is not necessarily guaranteed to be the same as output from the respective functions terra. This is because there are different methods to do the same thing, and the developers of GRASS may have chosen different methods than the developers of other GIS packages.

# width in meters because CRS is projected
river_buffers <- buffer(rivers, width = 1000, dissolve = TRUE)

Now, let's calculate the distances between the buffered areas and all cells on the raster map using distance().

dist_to_rivers_meters <- distance(elev, river_buffers)

Finally, let's plot the output.

plot(dist_to_rivers_meters)
plot(river_buffers, add = TRUE)
plot(rivers, col = "blue", add = TRUE)

And that's how it's done! You can do almost anything in fasterRaster you can do with terra. The examples above do not show the advantage of fasterRaster because the they do not use in large-in-memory/large-on-disk spatial datasets. For very large datasets, fasterRaster can be much faster! For example, for a large raster (many cells), the distance() function in terra can take many days to run and even crash R, whereas in fasterRaster, it could take just a few minutes or hours.

Exporting GRasters and GVectors from a GRASS session

You can convert a GRaster to a SpatRaster raster using rast():

terra_elev <- rast(elev)

To convert a GVector to the terra package's SpatVector, use vect():

terra_rivers <- vect(rivers)

You can use writeRaster() and writeVector() to save fasterRaster rasters and vectors directly to disk. This will always be faster than using rast() or vect() and then saving.

elev_temp_file <- tempfile(fileext = ".tif") # save as GeoTIFF
writeRaster(elev, elev_temp_file)

vect_temp_shp <- tempfile(fileext = ".shp") # save as shapefile
vect_temp_gpkg <- tempfile(fileext = ".gpkg") # save as GeoPackage
writeVector(rivers, vect_temp_shp)
writeVector(rivers, vect_temp_gpkg)

Tips for making fasterRaster faster

  1. Loading rasters and vectors directly from disk using fast(), rather than converting terra or sf objects is faster. Why? Because if the object does not have a file to which the R object points, fast() has to save it to disk first as a GeoTIFF or GeoPackage file, then load it into GRASS.

  2. Similarly, saving GRasters and GVectors directly to disk will always be faster than converting them to SpatRasters or SpatVector using rast() or vect(), then saving them. Why? Because these functions actually save the file to disk then uses the respective function from the respective package to connect to the file.

  3. Every time you switch between using a GRaster or GVector with a different coordinate reference system (CRS), GRASS has to spend a few second changing to that CRS. So, you can save some time by doing as much work as possible with objects in one CRS, then switching to work on objects in another CRS.

  4. By default, fasterRaster use 2 cores and 1024 MB (1 GB) of memory for GRASS modules that allow users to specify these values. You can set these to higher values using faster() and thus potentially speed up some calculations. Functions in newer versions of GRASS have more capacity to use these options, so updating GRASS to the latest version can help, too.

  5. Compared to terra and sf, fasterRaster is not faster with large vector operations, so if have large vectors, do vector processing with those packages first if you can.

  6. To obviate problems with disk space filling up, by default most fasterRaster functions delete intermediate files. However, if you are not creating a lot of very big GRasters or GVectors, you can skip this time-taking step by setting the clean option to FALSE using faster(clean = FALSE).

Versioning

fasterRaster versions will look something like 8.3.1.2, or more generally, M1.M2.S1.S2. Here, M1.M2 will mirror the version of GRASS for which fasterRaster was built and tested. For example, fasterRaster version 8.3 will work using GRASS 8.3 (and any earlier versions starting from 8.0). The values in S1.S2 refer to "major" and "minor" versions of fasterRaster. That is, a change in the value of S1 (e.g., from 8.3.1.0 to 8.3.2.0) indicates changes that potentially break older code developed with a prior version of fasterRaster. A change in S2 refers to a bug fix, additional functionality in an existing function, or the addition of an entirely new function.

Note that the M1.M2 and S1.S2 increment independently. For example, if the version changes from 8.3.1.5 to 8.4.1.5, then the new version has been tested on GRASS 8.4, but code developed with version 8.3.1.X of fasterRaster should still work.

NOTE: While fasterRaster is still in beta/alpha release, the version will look something like 8.3.0.7XXX, following Hadley Wickham's guidelines for versioning under development.

Further reading

  • Robert Hijman's terra package and Edzer Pebesma's sf package are good places to start if you are not familiar with doing GIS in R.
  • The GRASS GIS website is authoritative and contains the manual on all the GRASS functions used in this package and more.
  • The Wiki on how to run GRASS in R or R in GRASS is a good place to start if you want to become a power-user of GRASS in R.
  • Roger Bivand's rgrass package allows users to call any GRASS function with all of its functionality, which in some cases is far beyond what is allowed by fasterRaster.

Citation

A publication is forthcoming(!), but as of February 2024, there is not as of yet a package-specific citation for fasterRaster. However, the package was first used in:

Morelli*, T.L., Smith*, A.B., Mancini, A.N., Balko, E. A., Borgenson, C., Dolch,R., Farris, Z., Federman, S., Golden, C.D., Holmes, S., Irwin, M., Jacobs,R.L., Johnson, S., King, T., Lehman, S., Louis, E.E. Jr., Murphy, A.,Randriahaingo, H.N.T., Lucien,Randriannarimanana, H.L.L.,Ratsimbazafy, J.,Razafindratsima, O.H., and Baden, A.L. 2020. The fate of Madagascar’s rainforest habitat. Nature Climate Change 10:89-96. * Equal contribution DOI: https://doi.org/10.1038/s41558-019-0647-x.

Abstract. Madagascar has experienced extensive deforestation and overharvesting, and anthropogenic climate change will compound these pressures. Anticipating these threats to endangered species and their ecosystems requires considering both climate change and habitat loss effects. The genus Varecia (ruffed lemurs), which is composed of two Critically Endangered forest-obligate species, can serve as a status indicator of the biodiversity eastern rainforests of Madagascar. Here, we combined decades of research to show that the suitable habitat for ruffed lemurs could be reduced by 29–59% from deforestation, 14–75% from climate change (representative concentration pathway 8.5) or 38–93% from both by 2070. If current protected areas avoid further deforestation, climate change will still reduce the suitable habitat by 62% (range: 38–83%). If ongoing deforestation continues, the suitable habitat will decline by 81% (range: 66–93%). Maintaining and enhancing the integrity of protected areas, where rates of forest loss are lower, will be essential for ensuring persistence of the diversity of the rapidly diminishing Malagasy rainforests.

~ Adam

fasterraster's People

Contributors

adamlilith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fasterraster's Issues

Old code no longer working

I am trying to make a distance raster with the same river shapefile I have used several times in previous years. I tried using GRASS v. 8.3 and rolled back to 7.8 to see if there was any differece.

This is my code:

set working directory to read in shapefile and country boundary

setwd("D:/Vietnam ENV Data/Rivers and streams")
list.files()
water <- readOGR(getwd(), "columbia_iscgm_vietnam_2007_watrcrsl")
setwd("D:/Vietnam ENV Data/Shapefiles/Vietnam outline")
list.files()
country <- readOGR(getwd(), "Vietnam")
proj4string(country) <- CRS("EPSG:4326")

make an empty raster that matches the extent of your country

r <- raster(x = extent(country), nrows = 2000, ncols = 2000)
r[] <- 1 # set raster value to standard 1 in all cells

set a latlong projection (this needs to match your shapefiles too)

crs(r) <- "+proj=longlat +datum=WGS84 +no_defs"

install and open fasterRaster

#Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS="true")
#remotes::install_github('adamlilith/fasterRaster', dependencies=TRUE)
library(fasterRaster)

set GRASS directory

grassDir <- 'C:/Program Files/GRASS GIS 7.8'
distToRiver <- fasterVectToRastDistance(rast=r,
vect=water,
metric="geodesic",
grassDir=grassDir,
meters = TRUE,
)

This is the run text and errors:

100%
Check if OGR layer contains polygons...
100%
WARNING: Vector map already exists and will be overwritten
Creating attribute table for layer ...
Importing 2397 features (OGR layer )...
100%

Building topology for vector map vect@PERMANENT...
Registering primitives...
Assertion failed: p->count[0] >= p->minfill && p->count[1] >= p->minfill, file split.c, line 591
WARNING: Unable to open vector map vect@PERMANENT on level 2. Try to
rebuild vector topology with v.build.
ERROR: Unable to open vector map
ERROR: Raster map not found
ERROR: Raster map not found

The warnings are as follows:
Warning messages:
1: Package rgrass7 transitioning to package rgrass for GRASS 7+.
2: Package rgrass7 transitioning to package rgrass for GRASS 7+.
3: Package rgrass7 transitioning to package rgrass for GRASS 7+.
4: Package rgrass7 transitioning to package rgrass for GRASS 7+.
5: Package rgrass7 transitioning to package rgrass for GRASS 7+.
6: Package rgrass7 transitioning to package rgrass for GRASS 7+.
7: Package rgrass7 transitioning to package rgrass for GRASS 7+.
8: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr, ... :
running command 'g.proj.exe -w' had status 884
9: Package rgrass7 transitioning to package rgrass for GRASS 7+.
10: Package rgrass7 transitioning to package rgrass for GRASS 7+.
'writeRAST' is deprecated. Use 'write_RAST' instead.
11: Package rgrass7 transitioning to package rgrass for GRASS 7+.
12: Package rgrass7 transitioning to package rgrass for GRASS 7+.
'writeVECT is deprecated. Use 'write_VECT' instead.
13: OGR support is provided by the sf and terra packages among others
14: OGR support is provided by the sf and terra packages among others
15: OGR support is provided by the sf and terra packages among others
16: Package rgrass7 is transitioning to package rgrass for GRASS GIS 7+.
'readRAST' is deprecated. Use 'read_RAST' instead.
17: Package rgrass7 transitioning to package rgrass for GRASS 7+.
18: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr, ... :
running command 'g.proj.exe -w' had status 884
19: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr, ... :
running command 'r.info.exe -g map=distToVect' had status 1
20: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr, ... :
running command 'r.info.exe -r map=distToVect' had status 1
21: In ifelse(x == "NULL", as.numeric(NA), as.numeric(x)) :
NAs introduced by coercion

Finding the cause of error message in rgrass7::initGRASS on MacOS

Hi Adam,

I solved grassDir on my system (MacOS) it's at '/Applications/GRASS-7.8.app/Contents/Resources'., which may help you. You can add it to the example.

library(fasterRaster)
data(madForest2000)
data(madRivers)
grassDir <- "/Applications/GRASS-7.8.app/Contents/Resources"
distToRiver <- fasterVectToRastDistance(rast=madForest2000, vect=madRivers, grassDir = grassDir)
plot(distToRiver, main='Distance to Rivers (m)')
plot(madRivers, col='blue', add=TRUE)

sessioninfo::platform_info()

setting  value                       
version  R version 4.0.5 (2021-03-31)
os       macOS Big Sur 10.16         
system   x86_64, darwin17.0          
ui       RStudio                     
language (EN)                        
collate  en_US.UTF-8                 
ctype    en_US.UTF-8                 
tz       Asia/Shanghai               
date     2021-06-02          

fasterFragmentation returns more values than input

Hi,

first of all thanks for creating the fasterFragmentation function, it is very handy and runs extremely fast!
When checking the output, however, I discovered that the rasters had significantly more "filled" values (non-NA/non-zero) than my input raster (with the madForest2000 example data it was original: 842'726; output$class: 1'131'486).
I suspect this is due to the windows being used, so that values are returned for the whole window instead of just the window center.
This leads to the undesirable result, that cells that had not been forest before are suddenly shown as "edge" or similar and also area statistics do not add up anymore when compared to the original raster.

As a quick hack I just masked the fragmentation output with the input raster, however I'm not sure, if all cells have correct classes now since I cut away the "edges".

Best,
Lukas

Using a matrix as weights in fasterFocal

Hi Adam,
I find your package really impressive. It is the fastest I guess.
However, I try to use the function fasterFocal with a specific matrix created with the base function "matrix" and it doesn't work.
The matrix used is created as follows:
m5 <- matrix(c(1,NA,1,NA,1,NA,1,1,1,NA,1,1,NA,1,1,NA,1,1,1,NA,1,NA,1,NA,1), nrow=5, ncol=5)
And I just try to do the following, with a very big raster 'r' object:
ff1 <- fasterFocal (r, w=m5, fun=max)

I think this could be because the class of a matrix is "matrix" "array" and hence the condition class(w) == "matrix" is not met.
I have not found any way of producing a matrix with its actual class being only "matrix".
Could you consider checking this possible bug?
Thanks a lot,

MPilar

R Version 4.3.2 Issues

Hi, I'm trying to install fasterRaster using the given code:
remotes::install_github('adamlilith/fasterRaster', dependencies=TRUE)
But I'm running into issues due to my R version (4.3.2). Initally I got this error:
Downloading GitHub repo adamlilith/fasterRaster@HEAD Error in utils::download.file(url, path, method = method, quiet = quiet, : download from 'https://api.github.com/repos/adamlilith/fasterRaster/tarball/HEAD' failed
Then I removed the dependencies argument, got a little further, and then got this error message:
`Installing package into ‘C:/Users/katie/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)
ERROR: dependencies 'rgrass7', 'rgdal' are not available for package 'fasterRaster'

  • removing 'C:/Users/katie/AppData/Local/R/win-library/4.3/fasterRaster'
    Warning messages:
    1: packages ‘rgdal’, ‘rgrass7’ are not available for this version of R

Versions of these packages for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
2: In i.p(...) :
installation of package ‘C:/Users/katie/AppData/Local/Temp/Rtmp8cZqtS/file30f477e11e79/fasterRaster_0.7.2.tar.gz’ had non-zero exit status`

I know rgdal is being phased out, and rgrass7 appears to have been replaced by rgrass. Are there any plans to update fasterRaster to work with newer versions/packages?

Difficulty Installing fasterRaster

Hi Adam,

I just updated my R version to 4.3.3 due to issues with another package (the terra::extract function has been throwing weird errors for me for weeks now). It looked like I had resolved that, but in the process of trying to reinstall the fasterRaster package, I've been getting errors:

When installing normally:
` remotes::install_github('adamlilith/fasterRaster', dependencies = TRUE)
Downloading GitHub repo adamlilith/fasterRaster@HEAD
Skipping 1 packages ahead of CRAN: terra
── R CMD build ───────────────────────────────────────────────────────────────────────────────────
✔ checking for file 'C:\Users\katie\AppData\Local\Temp\RtmpCaAsKe\remotes65f441094753\adamlilith-fasterRaster-fb3d235/DESCRIPTION' ...
─ preparing 'fasterRaster': (2.3s)
✔ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts (451ms)
─ checking for empty or unneeded directories
─ building 'fasterRaster_8.3.0.7003.tar.gz'

Installing package into ‘C:/Users/katie/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)

  • installing source package 'fasterRaster' ...
    ** using staged installation
    ** R
    ** data
    *** moving datasets to lazyload DB
    ** inst
    ** byte-compile and prepare package for lazy loading
    Creating a generic function for '%in%' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for '%notin%' in package 'fasterRaster'
    Creating a generic function for 'barplot' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'cor' in package 'fasterRaster'
    Creating a new generic function for 'cov' in package 'fasterRaster'
    Creating a generic function for 'droplevels' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'grid' in package 'fasterRaster'
    Creating a generic function for 'hist' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'intersect' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'kernel' in package 'fasterRaster'
    Creating a generic function for 'match' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'merge' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'nlevels' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'pairs' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'plot' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'predict' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'quantile' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'scale' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'show' from 'methods' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'update' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'union' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'xor' in package 'fasterRaster'
    Creating a generic function for 'sd' from package 'stats' in package 'fasterRaster'
    Creating a generic function for 'var' from package 'stats' in package 'fasterRaster'
    Error : in method for 'activeCat<-' with signature 'x="GRaster",value="numeric"': arguments ('value') after '...' in the generic must appear in the method, in the same place at the end of the argument list
    Error: unable to load R code in package 'fasterRaster'
    Execution halted
    ERROR: lazy loading failed for package 'fasterRaster'
  • removing 'C:/Users/katie/AppData/Local/R/win-library/4.3/fasterRaster'
    Warning message:
    In i.p(...) :
    installation of package ‘C:/Users/katie/AppData/Local/Temp/RtmpCaAsKe/file65f47e3354d1/fasterRaster_8.3.0.7003.tar.gz’ had non-zero exit status`

When installing the development version:
`remotes::install_github('adamlilith/fasterRaster@intuitive_fasterRaster', dependencies = TRUE)
Downloading GitHub repo adamlilith/fasterRaster@intuitive_fasterRaster
Skipping 1 packages ahead of CRAN: terra
── R CMD build ───────────────────────────────────────────────────────────────────────────────────
✔ checking for file 'C:\Users\katie\AppData\Local\Temp\RtmpCaAsKe\remotes65f42cd552eb\adamlilith-fasterRaster-9eb0c98/DESCRIPTION' ...
─ preparing 'fasterRaster': (2s)
✔ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts (441ms)
─ checking for empty or unneeded directories
─ building 'fasterRaster_8.3.0.7004.tar.gz'

Installing package into ‘C:/Users/katie/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)

  • installing source package 'fasterRaster' ...
    ** using staged installation
    ** R
    ** data
    *** moving datasets to lazyload DB
    ** inst
    ** byte-compile and prepare package for lazy loading
    Creating a generic function for '%in%' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for '%notin%' in package 'fasterRaster'
    Creating a generic function for 'barplot' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'cor' in package 'fasterRaster'
    Creating a new generic function for 'cov' in package 'fasterRaster'
    Creating a generic function for 'droplevels' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'grid' in package 'fasterRaster'
    Creating a generic function for 'hist' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'intersect' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'kernel' in package 'fasterRaster'
    Creating a generic function for 'match' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'merge' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'nlevels' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'pairs' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'plot' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'predict' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'quantile' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'scale' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'show' from 'methods' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'update' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a generic function for 'union' from 'terra' in package 'fasterRaster'
    (from the saved implicit definition)
    Creating a new generic function for 'xor' in package 'fasterRaster'
    Creating a generic function for 'sd' from package 'stats' in package 'fasterRaster'
    Creating a generic function for 'var' from package 'stats' in package 'fasterRaster'
    Error : in method for 'activeCat<-' with signature 'x="GRaster",value="numeric"': arguments ('value') after '...' in the generic must appear in the method, in the same place at the end of the argument list
    Error: unable to load R code in package 'fasterRaster'
    Execution halted
    ERROR: lazy loading failed for package 'fasterRaster'
  • removing 'C:/Users/katie/AppData/Local/R/win-library/4.3/fasterRaster'
    Warning message:
    In i.p(...) :
    installation of package ‘C:/Users/katie/AppData/Local/Temp/RtmpCaAsKe/file65f468d87d73/fasterRaster_8.3.0.7004.tar.gz’ had non-zero exit status`

Can't install enmSdm because grpregOverlap is gone

Hi Adam,

I can't install enmSdm or fasterRaster, because I get this error: ERROR: dependency 'grpregOverlap' is not available for package 'enmSdm' because grpregOverlap has been removed from CRAN.

Is there a workaround?

Thanks!
Jen

`addTable()<-`

"Error in addTable(bg_sites_species) : could not find function "addTable""

Unable to install fasterRaster package using R.4.3.3 on PC

Hi,

I tried installing fasterRaster on a PC with R4.3.3 using the following code:

remotes::install_github('adamlilith/fasterRaster@intuitive_fasterRaster', dependencies = TRUE)

I then received error below. Do you have any suggestions on how to resolve?

Error : in method for 'activeCat<-' with signature 'x="GRaster",value="numeric"': arguments ('value') after '...' in the generic must appear in the method, in the same place at the end of the argument list
Error: unable to load R code in package 'fasterRaster'
Execution halted
ERROR: lazy loading failed for package 'fasterRaster'

Warning messages:
1: In untar2(tarfile, files, list, exdir, restore_times) :
skipping pax global extended headers
2: In untar2(tarfile, files, list, exdir, restore_times) :
skipping pax global extended headers
3: In i.p(...) :
installation of package ‘C:/Users/name/AppData/Local/Temp/Rtmpk1ykmO/file16f04aff378e/fasterRaster_8.3.0.7005.tar.gz’ had non-zero exit status

fasterDistance and foreach

Hi Adam,
Amazing package you've developed here.
I'm having some issues when performing the fasterDistance function in a foreach loop.
It works well when i run the code outside of a loop, but getting issue when trying to parallelize the computation.
Is this normal ? I was wondering whether it was might not be possible to call GRASS from multiple cores.

Error in fasterHorizon when grassToR = TRUE

Hi Adam,

The output name in GRASS is incorrectly generated within fasterHorizon when grassToR = TRUE based on the vector of directions.

degs <- c(ifelse(direction < 100, '0', ''), ifelse(direction < 10, '0', ''), direction)
thisOut <- rgrass7::readRAST(paste0(outGrassName, '_', degs))

For example, when direction = 0, the name provided to rgrass7::readRAST() is c(“horizonHeight_0”, “horizonHeight_0”, “horizonHeight_0”) instead of “horizonHeight_000”.

This issue is fixed by adding the argument collapse = “”:

degs <- paste0(c(ifelse(direction < 100, "0", ""), ifelse(direction < 10, "0", ""), direction), collapse = "")

Writing this also made me realize that an error would occur if non-integer values are provided for direction (e.g. 90.5). This could be avoided by using floor() as GRASS appears to round down to the closest full degree when naming the output. One possible solution:

degs <- sprintf("%03d", floor(direction))

Best,
Forest

fasterTerrain is not working with default code

Hello,
I am running fasterTerrain function with pre-default code.

library(fasterRaster)
grassDir <- 'C:/Program Files/GRASS GIS 7.8'

data(madElev)
topo <- fasterTerrain(rast=madElev, 
                      slope=TRUE, 
                      aspect=TRUE,
                      grassDir=grassDir) 

i get the following error:

Error in fasterConvertDegree(outGrassNameAspect, grassDir = grassDir, :
object 'grassToR' not found

I am not sure what is casuing the problem, as i did not modify anything
aa

Error message in rgrass7::initGRASS

Hi Adam,

First of all, I want to thank you for this really helpful package. I had an error while I was trying to use the function "fasterVectToRastDistance". Here the error message :

Error in rgrass7::initGRASS(gisBase = grassDir, home = tempDir, location = location, :
/Users/ilhem/grassdata does not contain bin, the directory with GRASS programs

Is it possible to resolve this error?
Thank you in advance
Ilhem

Support sf as the input for the parameter vect?

Hi Adam, this is a great package to make the work related to rasterize and distance much faster in R. Thanks a lot. I realized now it only support sp spatial features (I am sorry if I am wrong about this). It would be helpful if the package could support the new sf simple features so we don't have to switch back and forth.

Control of parallel computation using fasterFragmentation()

Hi Adam,

It's super nice to have fasterRaster for work involving large raster files! Projection and similar calculations always take so much time using the raster package, even when using beginCluster(), so thank you very much for this great tool!

I saw some unexpected behaviour when doing parallel computing with fasterFragmentation() using specific arguments for cores and forceMulti.

Typically, the program starts normally (using a single core for 1-2 minutes). Then, the parallel processing kicks in and typically runs at nearly 100% total CPU usage (but runs many (>20) individual processes, each with low %CPU) until the computer needs to "cool down" again for 1-2 minutes, and kicks back into parallel processing. On my best computer, the computation ran through after 5 hours but this behaviour caused an R session interruption on my laptop (4 cores, 16 GB RAM).

  • Isn't this unexpected given that cores = 3 and forceMulti = FALSE?
  • Is there an issue in fasterRaster, or is the issue in the evoked snow or parallel packages?
  • Any advice on which parameter combination to use for such a large raster?

Here are two .png screenshots of my activity manager (CPU consumption) during the function execution.

I can send you the raster to try and reproduce the behaviour, I've seen a similar behaviour on Mac, Windows and Linux OS.

Thanks again and best wishes,
Simon

##############################

Here is the code:

> cores
[1] 3
> forceMulti
[1] FALSE
> frag <- fasterFragmentation(rast = input, size = 5, pad = TRUE, padValue = NA, calcDensity = TRUE, calcConnect = TRUE, 
                              calcClass = TRUE, na.rm = TRUE, undet = "perforated", cores = cores, forceMulti = forceMulti)
  

This is how the input raster looks like (it has NA, 0, 1 values):

> input
class      : RasterLayer 
dimensions : 50884, 26746, 1360943464  (nrow, ncol, ncell)
resolution : 30, 30  (x, y)
extent     : 298440, 1100820, 7155900, 8682420  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=38 +south +datum=WGS84 +units=m +no_defs 
source     : /.../forest.tif 
names      : forest 
values     : 0, 1  (min, max)

Here is my computer info:

  • macOS Catalina (10.15.7)
  • 1 processor (4 GHz Quad-Core Intel Core i7)
  • 4 processor cores
  • 32 GB RAM

Here is my session info:

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fasterRaster_0.6.0 rgrass7_0.2-3      XML_3.99-0.5       raster_3.4-5       sp_1.4-4           link2GI_0.4-5     

loaded via a namespace (and not attached):
 [1] xfun_0.19          tidyselect_1.1.0   remotes_2.2.0      purrr_0.3.4        sf_0.9-6           lattice_0.20-41   
 [7] vctrs_0.3.6        generics_0.1.0     testthat_3.0.1     htmltools_0.5.0    usethis_2.0.0      base64enc_0.1-3   
[13] rlang_0.4.10       pkgbuild_1.2.0     e1071_1.7-4        pillar_1.4.7       glue_1.4.2         withr_2.3.0       
[19] DBI_1.1.0          sessioninfo_1.1.1  lifecycle_0.2.0    stringr_1.4.0      devtools_2.3.2     htmlwidgets_1.5.3 
[25] codetools_0.2-18   memoise_1.1.0      knitr_1.30         callr_3.5.1        ps_1.5.0           crosstalk_1.1.0.1 
[31] class_7.3-17       fansi_0.4.1        leafem_0.1.3       Rcpp_1.0.5         KernSmooth_2.23-18 classInt_0.4-3    
[37] desc_1.2.0         pkgload_1.1.0      leaflet_2.0.3      fs_1.5.0           png_0.1-7          digest_0.6.27     
[43] stringi_1.5.3      processx_3.4.5     dplyr_1.0.2        grid_4.0.2         rprojroot_2.0.2    rgdal_1.5-18      
[49] cli_2.2.0          tools_4.0.2        magrittr_2.0.1     tibble_3.0.4       crayon_1.3.4       pkgconfig_2.0.3   
[55] ellipsis_0.3.1     xml2_1.3.2         prettyunits_1.1.1  assertthat_0.2.1   roxygen2_7.1.1     rstudioapi_0.13   
[61] R6_2.5.0           units_0.6-7        compiler_4.0.2 

Adding compatibility with terra

Hi,
This is not really an issue, more like a wish. First, thank you for this great package! It’s been a real lifesaver for me. Although the new terra package is great and a bit faster than raster in some calculations, it still cannot produce, for example, a global distance-to-coast raster with the resolution of 10min in my relatively powerful laptop. However, for fasterRastDistance it takes only few seconds to produce such raster.

So, I really hope that you will continue maintaining the wonderful fasterRaster package and, because terra is gradually overtaking raster, hopefully also add compatibility with terra (and GRASS 8). It’s obvious that terra has not yet solved problems that fasterRaster is able to solve.

Best wishes,
Miikka

Handling of rasterBrick or RasterStacks?

I was hoping to use your package to handle raterbrick or rasterStacks.

Is there anyway this could be implemented?

Tried using a rasterBrick on the function fasterRasterProject as input and the output was a single rasterlayer.

Looking at the code, it seems that the output is a raster so this would obviously have to be changed, however the input into grass seems to go as a spatialgridDataframe, do you happen to know if those can handle bricks?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.