-
Notifications
You must be signed in to change notification settings - Fork 1
Substitute functions from raster package for terra #4
Comments
Just for your information @goergen95 . @Ohm-Np and me are currently working on this. Hope to get it ready soon to test it on big data. @Ohm-Np . Please let us know progress or eventual issues in this threat here... |
@Ohm-Np and @goergen95 : Hi Om, you do not need to consider #6 and #7 for reworking the Terra routines. |
Hi @Jo-Schie,
But I got some error with # calculation of forest loss area
loss_area = LossCalc(inputForestMap = treeCover_yearly,
inputLossMap = lossYear,
studysite = result_latlon,
latlon = TRUE,
polyName = "WDPAID",
ncores = 4,
years = 2000:2020)
What could be the case? |
Hi @Ohm-Np . I was able to identify the error and fix it. Could you do two things for me
library(sf)
library(terra)
remotes::install_github("mapme-initiative/mapme.forest",ref = "terra")
library(mapme.forest)
# ---- test download function and prepare data -----
# read in polygons of interest
aoi = st_read(system.file("extdata", "aoi_polys.gpkg", package = "mapme.forest"))
# download GFW data for the area of interest
# raster_files = downloadfGFW(shape = aoi,
# basename = "pkgTest",
# dataset = "GFC-2018-v1.6",
# outdir = "../../datalake/tempdir/pkg_test",
# keepTmpFiles = T)
raster_files<-rast(paste0("../../datalake/tempdir/pkg_test/",list.files("../../datalake/tempdir/pkg_test/")))
# we need to reproject the aoi object
aoi = st_transform(aoi, crs = st_crs(raster_files))
# crop the rasters to the extent of the aoi
rasters=terra::crop(raster_files, aoi)
# assigning proper names to the layers and simply plot the results
names(rasters) = c("co2_emission_FAKE", "lossyear", "treecover")
plot(rasters)
#----- test prepTC -----
prep_treeCover = prepTC(inputForestMap = rasters$treecover,
thresholdCover = 75,
thresholdClump = 20)
# ----- test Yearly forest mask -----
yearlyForestMask = getTM(inputForestMap = prep_treeCover,
inputLossMap = rasters$lossyear,
years = 2001:2018)
# ---- test Area Calc -----
result_latlon = AreaCalc(yearlyForestMask,
studysite = aoi,
latlon=TRUE,
polyName = "id",
ncores = 1,
years = 2001:2018)
# ----- test LossCalc -----
loss_area = LossCalc(inputForestMap = yearlyForestMask,
inputLossMap = rasters$lossyear,
studysite = result_latlon,
latlon = TRUE,
polyName = "id",
ncores = 1,
years = 2001:2018)
# ----- test CO2Calc ----
# currently not working
# co2_emission = CO2Calc(inputForestMap = yearlyForestMask,
# inputLossMap = rasters$lossyear,
# inputCO2Map = rasters$co2_emission_FAKE,
# studysite = result_latlon,
# polyName = "id",
# ncores = 1,
# years = 2001:2018) |
i just realized on my private pc that the download function did not work properly there. So if you cannot download and open the data you might want to put this on a hold for a while and tell us here. Maybe we need to merge this branch first to main to get the changes that darius made to the download functions... |
Hi, you still have errrors with the download function on your PC? I think there is an is sie relativ to Windows so please let me know if it works fo you? |
Hi Darius. no... I fixed it (see my pushes to this branch from Yesterday). However I am not able to fix an issue in the |
The problem seems to be in the preprocess script in line 64 # create classification matrix to apply thresholdCover value
f = function(x) ifelse(x>=thresholdCover, 1, 0)
inputForestMap = app(inputForestMap, f, cores=ncores) |
I already thought of using maybe the |
Terra
package is the successor ofraster
and is supposedly better to handle large spatial datasets. I suggest that we substitute allraster
functions withterra
functions. This might enable us to also process large data without being reliant onGRASS
and the rather complicated installation of all the dependencies. I created a small test where I benchmark the performances. You can see thatterra
seems to even outperformGRASS
which is quite surprising to me, however I did just compare them for simple zonal statistics.@goergen95 : I will try to do a first draft converting some of the scripts when I find a suitable time-spot in the upcoming days. You might want to confirm, nevertheless, the benchmarks and then eventually help and check if I get stuck.
@Ohm-Np : This is just for your information. You can use the package as is in the meantime.
The text was updated successfully, but these errors were encountered: