added download/correct functions for GLW4, download/read/correct functions for GLPS; updated readGLW3/4 and correctGLW3#69
Conversation
…ted readGLW3/4 and correctGLW3
There was a problem hiding this comment.
Pull request overview
This PR expands mrland’s madrat source handlers for gridded livestock datasets by adding download/read/correct support for GLW3/GLW4 and GLPS subtypes, plus generated documentation and import updates.
Changes:
- Adds GLW3/GLW4 download metadata and subtype-aware readers for additional species/years.
- Adds GLPS download/read/correct handlers for chicken, pig, and ruminant production-system rasters.
- Updates correction docs/imports and generated Rd files for the new and modified source functions.
Reviewed changes
Copilot reviewed 11 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| R/readGLW4.R | Extends GLW4 reading to 2015/2020 subtype sets and units. |
| R/readGLW3.R | Extends GLW3 reading to all listed species/weighting subtypes. |
| R/readGLPS.R | Adds GLPS raster reader for monogastric and ruminant subtypes. |
| R/downloadGLW4.R | Adds GLW4 download handler and metadata. |
| R/downloadGLW3.R | Adds GLW3 download handler and metadata. |
| R/downloadGLPS.R | Adds GLPS download handler, including ruminant archive extraction. |
| R/correctGLW4.R | Adds GLW4 correction for NA/negative values. |
| R/correctGLW3.R | Updates GLW3 correction documentation. |
| R/correctGLPS.R | Adds GLPS correction behavior by subtype. |
| NAMESPACE | Updates imports for archive/terra and removed old raster/dplyr imports. |
| DESCRIPTION | Adds archive to package imports. |
| man/readGLW4.Rd | Generated documentation for updated GLW4 reader. |
| man/readGLW3.Rd | Generated documentation for updated GLW3 reader. |
| man/readGLPS.Rd | Generated documentation for new GLPS reader. |
| man/downloadGLW4.Rd | Generated documentation for new GLW4 downloader. |
| man/downloadGLW3.Rd | Generated documentation for new GLW3 downloader. |
| man/downloadGLPS.Rd | Generated documentation for new GLPS downloader. |
| man/correctGLW4.Rd | Generated documentation for new GLW4 correction. |
| man/correctGLW3.Rd | Generated documentation for updated GLW3 correction. |
| man/correctGLPS.Rd | Generated documentation for new GLPS correction. |
Files not reviewed (9)
- man/correctGLPS.Rd: Language not supported
- man/correctGLW3.Rd: Language not supported
- man/correctGLW4.Rd: Language not supported
- man/downloadGLPS.Rd: Language not supported
- man/downloadGLW3.Rd: Language not supported
- man/downloadGLW4.Rd: Language not supported
- man/readGLPS.Rd: Language not supported
- man/readGLW3.Rd: Language not supported
- man/readGLW4.Rd: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| x <- as.magpie(x) | ||
| getYears(x) <- "y2010" |
There was a problem hiding this comment.
I also second this analysis.
| gisFile <- list.files(pattern = "\\.(tif|img|asc)$", ignore.case = TRUE)[1] | ||
| if (is.na(gisFile)) stop("No raster file found for Ruminant_2000. Run downloadSource first.") |
There was a problem hiding this comment.
I also see the issue with those lines and the patch suggested by Copilot is fine.
| #' Files are stored under species subdirectories matching the layout expected | ||
| #' by \code{readGLW4}. |
| #' @description Reads Global Livestock Production System (GLPS) data for | ||
| #' reference year 2010. Three animal groups are available: |
- correctGLW3: fix formatting (spacing around <- and braces) - downloadGLW4: remove redundant subdirectory sentence from description - readGLPS: clarify that chicken/pig subtypes are 2010, Ruminant_2000 is ca. 2000; fix @param subtype to remove "for 2010" from description Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
codeZeilen
left a comment
There was a problem hiding this comment.
Thanks for also adding the new and the missing download functions!
| gisFile <- list.files(pattern = "\\.(tif|img|asc)$", ignore.case = TRUE)[1] | ||
| if (is.na(gisFile)) stop("No raster file found for Ruminant_2000. Run downloadSource first.") |
There was a problem hiding this comment.
I also see the issue with those lines and the patch suggested by Copilot is fine.
| x <- as.magpie(x) | ||
| getYears(x) <- "y2010" |
There was a problem hiding this comment.
I also second this analysis.
| Aw_Ho = "Ho/6_Ho_2015_Aw.tif", | ||
| Aw_Dk = "Dk/6_Dk_2015_Aw.tif", | ||
| Aw_Bf = "Bf/6_Bf_2015_Aw.tif")) | ||
| subtypes2015 <- c( |
There was a problem hiding this comment.
I was somewhat scared that this breaks the workflow on the HPC as files were previously organized in sub-folders, but apparently the GLW4 data was never downloaded, so no problem here.
| } | ||
|
|
||
| x <- as.magpie(x) | ||
| x[is.nan(x)] <- NA |
Summary
This PR adds and updates download, read, and correct functions for two gridded livestock data sources.
Gridded Livestock of the World (GLW3 / GLW4)
downloadGLW3anddownloadGLW4with full metadata, including DOI, unit, andbibentryreference.readGLW3to support all 16 subtypes: 8 species × 2 weighting methods. Previously, only one species was handled.readGLW4to support both 2015 data, in heads/pixel, and 2020 data, in heads/km². Previously, only 2015 data was handled.correctGLW4, which replacesNAand negative values with0.correctGLW3with minor improvements.Global Livestock Production Systems (GLPS)
downloadGLPS,readGLPS, andcorrectGLPSfor chicken, pig, and ruminant livestock production system rasters.correctGLPSreplacesNAand negative values with0for continuous subtypes, namely chicken and pig density.Ruminant_2000, which is categorical with class codes 1–15,NAvalues are left unchanged to avoid introducing an invalid class0.Other
archivetoDESCRIPTIONImports, which is required bydownloadGLPSfor 7z extraction.