diff --git a/.buildlibrary b/.buildlibrary index a6dca41..cbb4d82 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '2399520' +ValidationKey: '2358938' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 38faf84..92394d4 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: 'mrlandcore: One-line description of this awesome package' -version: 1.2.0 -date-released: '2024-09-30' +version: 1.1.8 +date-released: '2024-09-25' abstract: One-paragraph description of this awesome package. authors: - family-names: Beier diff --git a/DESCRIPTION b/DESCRIPTION index 8413c79..e2a973e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrlandcore Title: One-line description of this awesome package -Version: 1.2.0 -Date: 2024-09-30 +Version: 1.1.8 +Date: 2024-09-25 Authors@R: c( person("Felicitas", "Beier", , "beier@pik-potsdam.de", role = c("aut", "cre")), person("Kristine", "Karstens", role = "aut"), diff --git a/R/readLPJmL.R b/R/readLPJmL.R deleted file mode 100644 index a970dbf..0000000 --- a/R/readLPJmL.R +++ /dev/null @@ -1,102 +0,0 @@ -#' @title readLPJmL -#' -#' @description Read in LPJmL outputs -#' -#' @param subtype Switch between different inputs -#' (eg. "LPJmL5.2_Pasture:IPSL_CM6A_LR:ssp126_co2_limN_00:soilc_past_hist") -#' -#' @return List of magpie objects with results on cellular level, weight, unit and description. -#' -#' @author Felicitas Beier, Sebastian Ostberg, Michael Crawford -#' -#' @seealso -#' [readLPJ()] -#' @examples -#' \dontrun{ -#' readSource("LPJmL", convert = FALSE) -#' } - -# nolint start -### This function should be adjusted during the LPJmL - MAgPIE - Hackathon ### -# Testing locations: -# /p/projects/rd3mod/inputdata/sources/LPJmL -# example subtype: lpjml5.9.5.mag1.MRI.ESM2.0.ssp370.crop.sdate - -# Testing data: -# subtype <- "lpjml5.9.5.mag1.MRI.ESM2.0.ssp370.crop.sdate" -# setwd("/p/projects/rd3mod/inputdata/sources/LPJmL/lpjml5.9.5.mag1.MRI.ESM2.0.ssp370.pnv.mrunoff") -# setwd("/p/projects/rd3mod/inputdata/sources/LPJmL/lpjml5.9.5.mag1.MRI.ESM2.0.ssp370.crop.sdate") -# nolint end - -readLPJmL <- function(subtype = "lpjml5.9.5.mag1.MRI.ESM2.0.ssp370.crop.sdate") { - - # filenames for dataset and grid - files <- list.files(path = subtype, pattern = "\\.bin\\.json$", full.names = TRUE) - gridname <- lpjmlkit::find_varfile(subtype, variable = "grid") - dataname <- grep("grid", files, invert = TRUE, value = TRUE) - if (length(dataname) != 1) { - stop("More than one data file is present in the LPJmL source directory.") - } - - # read in LPJmL dataset - x <- lpjmlkit::read_io(dataname) - - # generate a mapping from LPJmL lon-lat to MAgPIE coord - # extract grid information - x$add_grid(gridname, silent = TRUE) - grid <- x$grid$data - - # transform to format of magpie object while maintaining cell order - lon <- gsub("\\.", "p", grid[, "lon"]) - lat <- gsub("\\.", "p", grid[, "lat"]) - coordsLPJmL <- paste(lon, lat, sep = ".") - - # sort mapping according to provided grid to ensure consistency - mapping <- mstools::toolGetMappingCoord2Country(pretty = FALSE, extended = FALSE) - matches <- match(x = coordsLPJmL, table = mapping$coords) - if (any(is.na(matches))) { - stop("Discrepancy between spatial extent of LPJmL coords and MAgPIE coords") - } - mapping <- mapping[matches, ] - - # transform time dimension - x$transform(to = "year_month_day") - if ("month" %in% names(dimnames(x))) { - x <- aperm(x$data, c("cell", "year", "month", "band")) - } else { - x <- x$data - } - x <- drop(x) - - # transform x into a MAgPIE object - x <- magclass::as.magpie(x, spatial = 1) - - meta <- lpjmlkit::read_meta(dataname) - bandNames <- sub("^(rainfed|irrigated)\\s+", "", meta$band_names) - - # MIKE: Move mapping to mrlandcore - lpj2mag <- madrat::toolGetMapping("MAgPIE_LPJmL.csv", type = "sectoral", where = "mappingfolder") - hasCrops <- any(bandNames %in% lpj2mag$LPJmL5) - if (hasCrops) { - - # differentiate between rainfed and irrigated crops in the case of crop data - irrigation <- sub(" .*", "", getNames(x)) # select first word (of, e.g. "rainfed temperature cereals") - crop <- sub("^[^ ]+\\s+", "", getNames(x)) # select everything after first word - x <- magclass::add_dimension(x, dim = 3.1, add = "irrigation", nm = "dummy") - getNames(x, dim = "irrigation") <- irrigation - getNames(x, dim = "band") <- crop - - # transform LPJmL5 to LPJmL-internal names - x <- madrat::toolAggregate(x, rel = lpj2mag, from = "LPJmL5", to = "LPJmL", dim = 3.2, partrel = TRUE) - magclass::getSets(x)["d3.2"] <- "crop" - - } - - # use coordinate mapping to assign MAgPIE coords and iso - x <- magclass::add_dimension(x, dim = 1.1, add = "lon", nm = "dummy") - x <- magclass::add_dimension(x, dim = 1.2, add = "lat", nm = "dummy") - magclass::getItems(x, dim = 1, raw = TRUE) <- paste(mapping$coords, mapping$iso, sep = ".") - magclass::getSets(x)[c("d1.1", "d1.2", "d1.3")] <- c("x", "y", "iso") - - return(x) -} diff --git a/README.md b/README.md index c03500c..f619bdf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # One-line description of this awesome package -R package **mrlandcore**, version **1.2.0** +R package **mrlandcore**, version **1.1.8** [![CRAN status](https://www.r-pkg.org/badges/version/mrlandcore)](https://cran.r-project.org/package=mrlandcore) [![R build status](https://github.com/pik-piam/mrlandcore/workflows/check/badge.svg)](https://github.com/pik-piam/mrlandcore/actions) [![codecov](https://codecov.io/gh/pik-piam/mrlandcore/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrlandcore) [![r-universe](https://pik-piam.r-universe.dev/badges/mrlandcore)](https://pik-piam.r-universe.dev/builds) @@ -38,7 +38,7 @@ In case of questions / problems please contact Felicitas Beier . +Beier F, Karstens K, Alves M, Philipp Dietrich J, Leon Bodirsky B, Hoetten D, Humpenoeder F, Heinke J, v. Jeetze P, Mishra A, Beier F, Wirth S, Chen D, Kreidenweis U (2024). _mrlandcore: One-line description of this awesome package_. R package version 1.1.8, . A BibTeX entry for LaTeX users is @@ -47,7 +47,7 @@ A BibTeX entry for LaTeX users is title = {mrlandcore: One-line description of this awesome package}, author = {Felicitas Beier and Kristine Karstens and Marcos Alves and Jan {Philipp Dietrich} and Benjamin {Leon Bodirsky} and David Hoetten and Florian Humpenoeder and Jens Heinke and Patrick {v. Jeetze} and Abhijeet Mishra and Felcitas Beier and Stephen Wirth and David Chen and Ulrich Kreidenweis}, year = {2024}, - note = {R package version 1.2.0}, + note = {R package version 1.1.8}, url = {https://github.com/pik-piam/mrlandcore}, } ``` diff --git a/man/readLPJmL.Rd b/man/readLPJmL.Rd deleted file mode 100644 index d5c18b2..0000000 --- a/man/readLPJmL.Rd +++ /dev/null @@ -1,29 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readLPJmL.R -\name{readLPJmL} -\alias{readLPJmL} -\title{readLPJmL} -\usage{ -readLPJmL(subtype = "lpjml5.9.5.mag1.MRI.ESM2.0.ssp370.crop.sdate") -} -\arguments{ -\item{subtype}{Switch between different inputs -(eg. "LPJmL5.2_Pasture:IPSL_CM6A_LR:ssp126_co2_limN_00:soilc_past_hist")} -} -\value{ -List of magpie objects with results on cellular level, weight, unit and description. -} -\description{ -Read in LPJmL outputs -} -\examples{ -\dontrun{ -readSource("LPJmL", convert = FALSE) -} -} -\seealso{ -[readLPJ()] -} -\author{ -Felicitas Beier, Sebastian Ostberg, Michael Crawford -}