Skip to content

Commit

Permalink
Merge pull request #153 from pfuehrlich-pik/master
Browse files Browse the repository at this point in the history
as.SpatRaster sets terra::time
  • Loading branch information
pfuehrlich-pik authored Jul 4, 2023
2 parents ab3ad29 + e20f8dd commit af61b25
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '119151300'
ValidationKey: '119225742'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
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: 'magclass: Data Class and Tools for Handling Spatial-Temporal Data'
version: 6.10.0
date-released: '2023-06-25'
version: 6.10.1
date-released: '2023-07-04'
abstract: Data class for increased interoperability working with spatial-temporal
data together with corresponding functions and methods (conversions, basic calculations
and basic data manipulation). The class distinguishes between spatial, temporal
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: magclass
Title: Data Class and Tools for Handling Spatial-Temporal Data
Version: 6.10.0
Date: 2023-06-25
Version: 6.10.1
Date: 2023-07-04
Authors@R: c(
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre")),
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = "aut"),
Expand Down
3 changes: 3 additions & 0 deletions R/as.SpatRaster.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ as.SpatRaster <- function(x, res = NULL) { # nolint: object_name_linter
target <- terra::rast(ncols = 360 / res, nrows = 180 / res, nlyrs = nyears(x) * ndata(x))
out <- terra::rast(xyz, crs = terra::crs(target))
names(out) <- colnames(m)
if (all(grepl("^y[0-9]+\\.\\.", names(out)))) {
terra::time(out, tstep = "years") <- as.integer(substr(names(out), 2, 5))
}
return(out)
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Data Class and Tools for Handling Spatial-Temporal Data

R package **magclass**, version **6.10.0**
R package **magclass**, version **6.10.1**

[![CRAN status](https://www.r-pkg.org/badges/version/magclass)](https://cran.r-project.org/package=magclass) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158580.svg)](https://doi.org/10.5281/zenodo.1158580) [![R build status](https://github.com/pik-piam/magclass/workflows/check/badge.svg)](https://github.com/pik-piam/magclass/actions) [![codecov](https://codecov.io/gh/pik-piam/magclass/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/magclass) [![r-universe](https://pik-piam.r-universe.dev/badges/magclass)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -56,7 +56,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

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

Dietrich J, Bodirsky B, Bonsch M, Humpenoeder F, Bi S, Karstens K, Leip D (2023). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi: 10.5281/zenodo.1158580 (URL: https://doi.org/10.5281/zenodo.1158580), R package version 6.10.0, <URL: https://github.com/pik-piam/magclass>.
Dietrich J, Bodirsky B, Bonsch M, Humpenoeder F, Bi S, Karstens K, Leip D (2023). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi:10.5281/zenodo.1158580 <https://doi.org/10.5281/zenodo.1158580>, R package version 6.10.1, <https://github.com/pik-piam/magclass>.

A BibTeX entry for LaTeX users is

Expand All @@ -65,7 +65,7 @@ A BibTeX entry for LaTeX users is
title = {magclass: Data Class and Tools for Handling Spatial-Temporal Data},
author = {Jan Philipp Dietrich and Benjamin Leon Bodirsky and Markus Bonsch and Florian Humpenoeder and Stephen Bi and Kristine Karstens and Debbora Leip},
year = {2023},
note = {R package version 6.10.0},
note = {R package version 6.10.1},
doi = {10.5281/zenodo.1158580},
url = {https://github.com/pik-piam/magclass},
}
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test-raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ test_that("terra convertion does not alter data", {
expect_equal(ndata(m), j)
expect_equal(nyears(m), t)
r2 <- as.SpatRaster(m)
expect_equal(r[[names(r)]], terra::extend(r2[[names(r)]], terra::ext(r)))
noTime <- function(a) {
terra::time(a) <- NULL
return(a)
}
# comparing times does not work here, so compare separately
expect_equal(noTime(r), noTime(terra::extend(r2[[names(r)]], terra::ext(r))))
if (t > 1) {
expect_equal(terra::time(r2), rep_len(1900 + 1:t, terra::nlyr(r)))
}
m2 <- as.magpie(r2)
expect_identical(m, m2)
v <- terra::as.polygons(r)
Expand Down

0 comments on commit af61b25

Please sign in to comment.