diff --git a/.buildlibrary b/.buildlibrary index b3de9db2..c4976323 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '27909580' +ValidationKey: '28091860' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 14a32cdc..ca78e6cd 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'mrmagpie: madrat based MAgPIE Input Data Library' -version: 1.41.1 -date-released: '2024-02-27' +version: 1.42.0 +date-released: '2024-03-01' abstract: Provides functions for MAgPIE country and cellular input data generation. authors: - family-names: Karstens diff --git a/DESCRIPTION b/DESCRIPTION index 37db448c..6f48651b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrmagpie Title: madrat based MAgPIE Input Data Library -Version: 1.41.1 -Date: 2024-02-27 +Version: 1.42.0 +Date: 2024-03-01 Authors@R: c( person("Kristine", "Karstens", , "karstens@pik-potsdam.de", role = c("aut", "cre")), person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = "aut"), diff --git a/R/calcClusterBase.R b/R/calcClusterBase.R old mode 100755 new mode 100644 diff --git a/R/calcClusterKMeans.R b/R/calcClusterKMeans.R old mode 100755 new mode 100644 index 4d12eab3..9962fa01 --- a/R/calcClusterKMeans.R +++ b/R/calcClusterKMeans.R @@ -28,7 +28,7 @@ calcClusterKMeans <- function(regionscode, ncluster, weight = NULL, cpr = NULL, lpjml = c(natveg = "LPJmL4", crop = "LPJmL5"), clusterdata = "yield_airrig") { # read in clustering base data cdata <- toolApplyRegionNames(cdata = calcOutput("ClusterBase", aggregate = FALSE, - lpjml = lpjml, clusterdata = clusterdata), + lpjml = lpjml, clusterdata = clusterdata), regionscode = regionscode) if (is.null(cpr)) { diff --git a/R/downloadMAPSPAM.R b/R/downloadMAPSPAM.R index 6f46baab..a363720a 100644 --- a/R/downloadMAPSPAM.R +++ b/R/downloadMAPSPAM.R @@ -14,45 +14,41 @@ downloadMAPSPAM <- function() { # more information at: https://www.mapspam.info/data/ # https://www.mapspam.info/publications/ - links <- c( - Harv2000 = "https://s3.amazonaws.com/mapspam/2000/v3.0.7/geotiff/spam2000v3.0.7_global_harvested-area.geotiff.zip", #nolint - Phy2000 = "https://s3.amazonaws.com/mapspam/2000/v3.0.7/geotiff/spam2000v3.0.7_global_physical-area.geotiff.zip", #nolint - Harv2005 = "https://s3.amazonaws.com/mapspam/2005/v3.2/geotiff/spam2005v3r2_global_harv_area.geotiff.zip", #nolint - Phy2005 = "https://s3.amazonaws.com/mapspam/2005/v3.2/geotiff/spam2005v3r2_global_phys_area.geotiff.zip", #nolint - Harv2010 = "https://s3.amazonaws.com/mapspam/2010/v2.0/geotiff/spam2010v2r0_global_harv_area.geotiff.zip", #nolint - Phy2010 = "https://s3.amazonaws.com/mapspam/2010/v2.0/geotiff/spam2010v2r0_global_phys_area.geotiff.zip" #nolint - ) - - names <- c(Harv2000 = "spam2000v3r7_global_HA_geotiff", - Phy2000 = "spam2000v3r7_global_PA_geotiff", - Harv2005 = "spam2005v3r2_global_HA_geotiff", - Phy2005 = "spam2005v3r2_global_PA_geotiff", - Harv2010 = "spam2010v2r0_global_HA_geotiff", - Phy2010 = "spam2010v2r0_global_PA_geotiff" - ) - - ### unzip files - - lapply(seq_len(length(links)), FUN = function(x) { - download.file(links[x], destfile = paste0(names[x], ".zip"), mode = "wb") - }) - - zipfiles <- list.files(pattern = ".zip$") - - lapply(seq_len(length(links)), FUN = function(x) { - unzip(zipfiles[x], exdir = names[x]) - }) - - lapply(zipfiles, unlink) - - return(list(url = "https://www.mapspam.info/data/", - doi = NULL, - title = "MapSPAM Global Data", - author = "IFPRI", - version = "2000=v3.0.7, 2005=v3.2, 2010=v2.0", - release_date = "2000=Jan 22, 2020, 2005=Dec 5, 2017, 2010=Jul 15, 2020", - description = "Grid data of physical and harvested croparea", - license = "CC BY 4.0", - reference = NULL)) + links <- c( + Harv2000 = "https://dvn-cloud.s3.amazonaws.com/10.7910/DVN/A50I2T/16fcdb67eea-f921ce3db735?response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27spam2000v3.0.7_global_harvested-area.geotiff.zip&response-content-type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240301T100405Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=AKIAIEJ3NV7UYCSRJC7A%2F20240301%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=ba5c37dc3979e3b735c0439c60f821e7c74b406647e3d348c763fe112d06a138", # nolint + Phy2000 = "https://dvn-cloud.s3.amazonaws.com/10.7910/DVN/A50I2T/16fcdb6a393-48a3ec461f3e?response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27spam2000v3.0.7_global_physical-area.geotiff.zip&response-content-type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240301T095814Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=AKIAIEJ3NV7UYCSRJC7A%2F20240301%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=2b2c0176d16691e9637161a10fcc16d1915c07199cc57128e0f3e2e25be6478e", # nolint + Harv2005 = "https://dvn-cloud.s3.amazonaws.com/10.7910/DVN/DHXBJX/16028059857-53c4854c49cc?response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27spam2005v3r2_global_harv_area.geotiff.zip&response-content-type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240301T100508Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=AKIAIEJ3NV7UYCSRJC7A%2F20240301%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=de525e5e07e42b184ca5d62cf70b420357367787c674e2c51e011ef0d7ae432c", # nolint + Phy2005 = "https://dvn-cloud.s3.amazonaws.com/10.7910/DVN/DHXBJX/160280628d5-764f80d27a41?response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27spam2005v3r2_global_phys_area.geotiff.zip&response-content-type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240301T100453Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=AKIAIEJ3NV7UYCSRJC7A%2F20240301%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=5fa97d903ed5fe6e7543924e4f8ada761813ecfaae7a2333eb4affacd61b1a76", # nolint + Harv2010 = "https://dvn-cloud.s3.amazonaws.com/10.7910/DVN/PRFF8V/1735567cda7-3ad213a31087?response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27spam2010v2r0_global_harv_area.geotiff.zip&response-content-type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240301T100549Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=AKIAIEJ3NV7UYCSRJC7A%2F20240301%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=84402b34cbf080487477ffb61fb58b0086fc26c9d823c7dd6ed8003e50d71541", # nolint + Phy2010 = "https://dvn-cloud.s3.amazonaws.com/10.7910/DVN/PRFF8V/17355681721-503806f0e24a?response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27spam2010v2r0_global_phys_area.geotiff.zip&response-content-type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240301T100601Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=AKIAIEJ3NV7UYCSRJC7A%2F20240301%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=ff08690dfc132351037be9153c87469f0035b33c9da8f839ab89f6bdc6510d1b" # nolint + ) + + names <- c(Harv2000 = "spam2000v3r7_global_harv_area.geotiff", Phy2000 = "spam2000v3r7_global_phys_area.geotiff", + Harv2005 = "spam2005v3r2_global_harv_area.geotiff", Phy2005 = "spam2005v3r2_global_phys_area.geotiff", + Harv2010 = "spam2010v2r0_global_harv_area.geotiff", Phy2010 = "spam2010v2r0_global_phys_area.geotiff") + + ### unzip files + + lapply(seq_len(length(links)), FUN = function(x) { + download.file(links[x], destfile = paste0(names[x], ".zip"), mode = "wb") + }) + + zipfiles <- list.files(pattern = ".zip$") + + lapply(seq_len(length(links)), FUN = function(x) { + unzip(zipfiles[x], exdir = names[x]) + }) + + lapply(zipfiles, unlink) + + return(list(url = "https://www.mapspam.info/data/", + doi = NULL, + title = "MapSPAM Global Data", + author = "IFPRI", + version = "2000=v3.0.7, 2005=v3.2, 2010=v2.0", + release_date = "2000=Jan 22, 2020, 2005=Dec 5, 2017, 2010=Jul 15, 2020", + description = "Grid data of physical and harvested croparea", + license = "CC BY 4.0", + reference = NULL)) } diff --git a/R/fullCELLULARMAGPIE.R b/R/fullCELLULARMAGPIE.R old mode 100755 new mode 100644 index 286f8970..eb2482c8 --- a/R/fullCELLULARMAGPIE.R +++ b/R/fullCELLULARMAGPIE.R @@ -223,10 +223,10 @@ fullCELLULARMAGPIE <- function(rev = numeric_version("0.1"), dev = "", cellular = TRUE, cells = cells, irrigation = TRUE, round = roundArea, aggregate = "cluster", file = paste0("f30_croparea_w_initialisation_", ctype, ".mz")) ## For cellular comparison - calcOutput("MAPSPAM", subtype = "physical", cellular = TRUE, aggregate = FALSE, + calcOutput("MAPSPAM", subtype = "physical", aggregate = FALSE, file = paste0("MAPSPAM_croparea_0.5.mz")) calcOutput("Croparea", sectoral = "kcr", physical = TRUE, - cellular = TRUE, cells = cells, irrigation = TRUE, round = roundArea, + cells = cells, irrigation = TRUE, round = roundArea, aggregate = FALSE, file = paste0("LUH2_croparea_0.5.mz")) calcOutput("AvlCropland", marginal_land = "magpie", cell_upper_bound = 0.9, diff --git a/R/readMAPSPAM.R b/R/readMAPSPAM.R index bb111f9d..f1711566 100644 --- a/R/readMAPSPAM.R +++ b/R/readMAPSPAM.R @@ -13,7 +13,6 @@ #' \dontrun{ #' a <- readSource("MAPSPAM") #' } - readMAPSPAM <- function(subtype = "harvested") { type <- subtype @@ -37,9 +36,9 @@ readMAPSPAM <- function(subtype = "harvested") { cropsSpam <- spam2Magpie[, "SPAM"] if (type == "harvested") { - ty <- "HA" + ty <- "harv_area" } else if (type == "physical") { - ty <- "PA" + ty <- "phys_area" } else { stop("Not a valid type") } @@ -52,26 +51,25 @@ readMAPSPAM <- function(subtype = "harvested") { for (i in seq_len(length(cropsSpam))) { if (year == 2000) { - # Reads raster data from SPAM - tyArea <- if (ty == "HA") "harvested-area" else if (ty == "PA") "physical-area" - rasterAscT <- paste0("spam2000v3r7_global_", ty, "_geotiff/spam2000v3r7_", tyArea, "_", cropsSpam[i], ".tif") - rasterAscI <- paste0("spam2000v3r7_global_", ty, "_geotiff/spam2000v3r7_", tyArea, "_", cropsSpam[i], "_I.tif") + tyArea <- if (ty == "harv_area") "H" else if (ty == "phys_area") "P" + rasterAscT <- paste0("spam2000v3r7_global_", ty, "_geotiff/spam2000v3r107_global_", tyArea, "_", + cropsSpam[i], "_A.tif") + rasterAscI <- paste0("spam2000v3r7_global_", ty, "_geotiff/spam2000v3r107_global_", tyArea, "_", + cropsSpam[i], "_I.tif") } else if (year == 2005) { - # Reads raster data from SPAM - tyArea <- if (ty == "HA") "H" else if (ty == "PA") "A" - tyArea1 <- if (ty == "HA") "harv_area" else if (ty == "PA") "phys_area" + tyArea <- if (ty == "harv_area") "H" else if (ty == "phys_area") "A" - rasterAscT <- paste0("spam2005v3r2_global_", ty, "_geotiff/geotiff_global_", tyArea1, "/SPAM2005V3r2_global_", + rasterAscT <- paste0("spam2005v3r2_global_", ty, "_geotiff/geotiff_global_", ty, "/SPAM2005V3r2_global_", tyArea, "_TA_", cropsSpam[i], "_A.tif") - rasterAscI <- paste0("spam2005v3r2_global_", ty, "_geotiff/geotiff_global_", tyArea1, "/SPAM2005V3r2_global_", + rasterAscI <- paste0("spam2005v3r2_global_", ty, "_geotiff/geotiff_global_", ty, "/SPAM2005V3r2_global_", tyArea, "_TI_", cropsSpam[i], "_I.tif") } else if (year == 2010) { - tyArea <- if (ty == "HA") "H" else if (ty == "PA") "A" + tyArea <- if (ty == "harv_area") "H" else if (ty == "phys_area") "A" rasterAscT <- paste0("spam2010v2r0_global_", ty, "_geotiff/spam2010V2r0_global_", tyArea, "_", cropsSpam[i], "_A.tif") @@ -81,7 +79,6 @@ readMAPSPAM <- function(subtype = "harvested") { } .valuesExtract <- function(rasterAscT) { - # load raster dataAscT <- rast(rasterAscT) # aggregate to 0.5 resolution @@ -144,8 +141,8 @@ readMAPSPAM <- function(subtype = "harvested") { setNames(magObjSPAMR, paste0(getNames(magObjSPAMR), ".rainfed"))) out[, intersect(getYears(out), getYears(magObjSPAM)), - intersect(getNames(out), getNames(magObjSPAM))] <- magObjSPAM[, intersect(getYears(out), getYears(magObjSPAM)), - intersect(getNames(out), getNames(magObjSPAM))] + intersect(getNames(out), getNames(magObjSPAM))] <- magObjSPAM[, intersect(getYears(out), getYears(magObjSPAM)), + intersect(getNames(out), getNames(magObjSPAM))] } return(out) diff --git a/R/toolApplyRegionNames.R b/R/toolApplyRegionNames.R old mode 100755 new mode 100644 index 55f1f63c..e6e94369 --- a/R/toolApplyRegionNames.R +++ b/R/toolApplyRegionNames.R @@ -35,7 +35,7 @@ toolApplyRegionNames <- function(cdata, regionscode) { isocountries <- getItems(cdata, dim = 1.3, full = TRUE) isoMap <- data.frame(CountryCode = isocountries) map <- base::merge(isoMap, map, by = "CountryCode", - all.x = TRUE, sort = FALSE, no.dups = TRUE) + all.x = TRUE, sort = FALSE, no.dups = TRUE) # correct cell order map <- map[match(isocountries, map$CountryCode), ] diff --git a/README.md b/README.md index b698c471..78cc31b8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # madrat based MAgPIE Input Data Library -R package **mrmagpie**, version **1.41.1** +R package **mrmagpie**, version **1.42.0** [![CRAN status](https://www.r-pkg.org/badges/version/mrmagpie)](https://cran.r-project.org/package=mrmagpie) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4319612.svg)](https://doi.org/10.5281/zenodo.4319612) [![R build status](https://github.com/pik-piam/mrmagpie/workflows/check/badge.svg)](https://github.com/pik-piam/mrmagpie/actions) [![codecov](https://codecov.io/gh/pik-piam/mrmagpie/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrmagpie) [![r-universe](https://pik-piam.r-universe.dev/badges/mrmagpie)](https://pik-piam.r-universe.dev/builds) @@ -39,7 +39,7 @@ In case of questions / problems please contact Kristine Karstens . +Karstens K, Dietrich J, Chen D, Windisch M, Alves M, Beier F, Köberle A, v. Jeetze P, Mishra A, Humpenoeder F, Sauer P (2024). _mrmagpie: madrat based MAgPIE Input Data Library_. doi:10.5281/zenodo.4319612 , R package version 1.42.0, . A BibTeX entry for LaTeX users is @@ -48,8 +48,8 @@ A BibTeX entry for LaTeX users is title = {mrmagpie: madrat based MAgPIE Input Data Library}, author = {Kristine Karstens and Jan Philipp Dietrich and David Chen and Michael Windisch and Marcos Alves and Felicitas Beier and Alexandre Köberle and Patrick {v. Jeetze} and Abhijeet Mishra and Florian Humpenoeder and Pascal Sauer}, year = {2024}, - note = {R package version 1.41.1}, - doi = {10.5281/zenodo.4319612}, + note = {R package version 1.42.0}, url = {https://github.com/pik-piam/mrmagpie}, + doi = {10.5281/zenodo.4319612}, } ``` diff --git a/inst/extdata/map67420to59199.rds b/inst/extdata/map67420to59199.rds old mode 100755 new mode 100644