Skip to content

Commit

Permalink
mapspam new url
Browse files Browse the repository at this point in the history
  • Loading branch information
Edna Johanna Molina Bacca authored and Edna Johanna Molina Bacca committed Mar 1, 2024
1 parent 0d3545e commit 27c09ed
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '27909580'
ValidationKey: '28091860'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
person("Jan Philipp", "Dietrich", , "[email protected]", role = "aut"),
Expand Down
Empty file modified R/calcClusterBase.R
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion R/calcClusterKMeans.R
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
76 changes: 36 additions & 40 deletions R/downloadMAPSPAM.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

}
4 changes: 2 additions & 2 deletions R/fullCELLULARMAGPIE.R
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 13 additions & 16 deletions R/readMAPSPAM.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#' \dontrun{
#' a <- readSource("MAPSPAM")
#' }

readMAPSPAM <- function(subtype = "harvested") {

type <- subtype
Expand All @@ -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")
}
Expand All @@ -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")
Expand All @@ -81,7 +79,6 @@ readMAPSPAM <- function(subtype = "harvested") {
}

.valuesExtract <- function(rasterAscT) {

# load raster
dataAscT <- rast(rasterAscT)
# aggregate to 0.5 resolution
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/toolApplyRegionNames.R
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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), ]

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Kristine Karstens <karstens@pik-p

To cite package **mrmagpie** in publications use:

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 (URL: https://doi.org/10.5281/zenodo.4319612), R package version 1.41.1, <URL: https://github.com/pik-piam/mrmagpie>.
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 <https://doi.org/10.5281/zenodo.4319612>, R package version 1.42.0, <https://github.com/pik-piam/mrmagpie>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```
Empty file modified inst/extdata/map67420to59199.rds
100755 → 100644
Empty file.

0 comments on commit 27c09ed

Please sign in to comment.