Coder Social home page Coder Social logo

evolecolgroup / pastclim Goto Github PK

View Code? Open in Web Editor NEW
29.0 1.0 1.0 30.53 MB

An R package providing helper functions to interact with timeseries of worldwide climate reconstructions

Home Page: https://evolecolgroup.github.io/pastclim/

License: Creative Commons Attribution 4.0 International

R 95.92% Shell 4.08%
paleoclimate r

pastclim's Introduction

pastclim

R-CMD-check master R-CMD-check dev codecov CRAN status CRAN downloads

This R library is designed to provide an easy way to extract and manipulate palaeoclimate reconstructions for ecological and anthropological analyses. It is also able to handle time series of future reconstructions.

The functionalities of pastclim are described in Leonardi et al. (2023). Please cite it if you use pastclim in your research.

Install the library

pastclim is on CRAN, and the easiest way to install it is with:

install.packages("pastclim")

The version on CRAN is recommended for every day use. New features and bug fixes appear first on the dev branch on GitHub, before they make their way to CRAN. If you need to have early access to these new features, you can install the development version of pastclim directly from GitHub, using devtools, or more simply get a compiled version from r-universe. Also, note that the dev version of pastclim tracks changes in the dev version of terra, so you will need to upgrade both libraries with:

install.packages('terra', repos='https://rspatial.r-universe.dev')
install.packages("pastclim", repos = c("https://evolecolgroup.r-universe.dev")

Overview of functionality

On its dedicated website, you can find Articles giving you a step-by-step overview of the package, and a cheatsheet. There is also a dev version of the site updated for the dev branch of pastclim (on the top left of the dev website, the version number is in red and in the format x.x.x.9xxx, indicating it is a development version).

pastclim currently includes data from Beyer et al 2020 (a reconstruction of climate based on the HadCM3 model for the last 120k years), Krapp et al 2021 (which covers the last 800k years with a statistical emulator of HadCM3), Barreto et al 2023 (covering the last 5M years using the PALEO-PGEM emulator), PaleoClim (providing a few time steps from different palaeoclimate models downscaled to higher resolution), CHELSA-Trace21K (a transient reconstruction of the last 21k years, downscaled to 1km resolution), the HYDE3.3 database of land use reconstructions for the last 10k years, and the WorldClim and CHELSA data (present, and future projections with a number of models and emission scenarios). More details on each of these datasets can be found here. There are also instructions on how to build and use custom datasets.


When something does not work

If something does not work, check the issues on GitHub to see whether the problem has already been reported. If not, feel free to create an new issue. Please make sure you have updated to the latest version of pastclim on CRAN, as well as updating all other packages on your system, and provide a reproducible example for the developers to investigate the problem.

pastclim's People

Contributors

avpozzi avatar dramanica avatar mikleonardi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

amrcode1

pastclim's Issues

terra interface

In pastclim::time_bp you have

if (x@ptr$timestep!="years"){

That breaks with the development version of terra. The @ptr$ methods are not really safe for use in other packages. Can you use the "official" interface instead? In this case that could be:

if  (timeInfo(x)$step != "years"){

Thanks!

Can't identidy variable names in location_slice

Hi,

First let me congratulate you on creating such a valuable resource. This package is exactly what I have been looking for and I think it is going to be hugely useful for me.

I am just learning the ropes of this package and have hit a roadblock. I think perhaps this might be an probably with a dependency package, or perhaps I have not installed things correctly, but I have run out of things to try and was hoping you could offer some pointers.

I am walking through the vignette code* but when I get the location_slice function, I get errors saying the variables I would like to use aren't available, with some alternatives offered. When I use the alternative names, I get the same message with the expected variable names offered as alternatives.

*I also couldn't compile the vignettes during installation which might stem from the same problem

I used this code, with the following errors:

library(pastclim)

# data installation
# set_data_path(path_to_nc = "~/Documents/projects/pastclim_data/")

df = structure(list(Language = c("Kimaghama ", "Riantana", "Ndom ", "Mombum (Komolom)", "Koneraw ", "Marori"), 
                    longitude = c(138.4520445, 138.4889957, 137.998408, 138.7896383, 138.3278637, 140.5149879), 
                    latitude = c(-7.899618841, -7.526408993, -7.991955007, -8.286129011, -8.327860384, -8.538172179)), 
               row.names = c(NA, 6L), 
               class = "data.frame")
df$time_bp1 = -10000

climate_60kya = location_slice(x = df[, c("longitude", "latitude")],
                               time_bp = df$time_bp1, 
                               bio_variables = c("bio01", "bio12"),
                               dataset = "Example", 
                               nn_interpol = FALSE
                               )
# Error: [rast] BIO1 not found. Choose one of:
# //BIO1, //BIO10, //BIO12, //biome

climate_60kya = location_slice(x = df[, c("longitude", "latitude")],
                               time_bp = df$time_bp1, 
                               bio_variables = c("//BIO1", "//BIO12"),
                               dataset = "Example", 
                               nn_interpol = FALSE)
# Error in check_available_variable(variable, dataset) : 
#  //BIO1, //BIO12 not available for Example; available variables are bio01, bio10, bio12, biome

Stepping through the location_slice function, the error comes from the following line:

climate_brick <- terra::rast(this_file, subds = this_var_nc)
# Error: [rast] BIO01 not found. Choose one of:
# //BIO1, //BIO10, //BIO12, //biome

Remove the subsetting argument allows the function to run, but with a warning:

climate_brick <- terra::rast("~/Documents/projects/pastclim_data//example_climate.nc")
Warning message:
[rast] unknown extent

My conclusion then is there is either something missing from the .nc file or something else is going on. Since I get the same errors for the Beyer2020 dataset, I would guess it is something else. What could I try to figure out what is going wrong?

I am running MacOS Monterey with Apple M1 Chip.

biome value is float when using nn_interpol

Observed behaviour: biome becomes a float when nn_interpol is used on samples for which no climate is available

Example:
floating_biomes.csv

library(pastclim)

# read in data
wolve <- read.csv("./floating_biomes.csv", header = T, sep = ",")

# extract climate data for sample locations
climate_locs <- location_slice(x=wolve[,c("latitude","longitude")], time_bp=0, bio_variables="biome", dataset="Beyer2020")
head(climate_locs)
  latitude longitude time_bp time_bp_slice    biome
1 64.48000 -162.1200       0             0 18.66667
2 64.48000 -162.1200       0             0 18.66667
3 64.48000 -162.1200       0             0 18.66667
4 64.48000 -162.1200       0             0 18.66667
5 59.60000   26.2000       0             0  7.75000
6 70.00499 -144.7539       0             0 22.33333

When nn_interpol is disabled, NA is returned:

climate_locs_no_interpol <- location_slice(x=wolve[,c("latitude","longitude")], time_bp=0, bio_variables="biome", dataset="Beyer2020", nn_interpol = FALSE)
head(climate_locs_no_interpol)
  latitude longitude time_bp time_bp_slice biome
1 64.48000 -162.1200       0             0    NA
2 64.48000 -162.1200       0             0    NA
3 64.48000 -162.1200       0             0    NA
4 64.48000 -162.1200       0             0    NA
5 59.60000   26.2000       0             0    NA
6 70.00499 -144.7539       0             0    NA

Problem appears to be with samples in the sea rather than samples that are under ice although this may be coincidental:
image

# plot map with database points, biome, present day
climate_present <- region_slice( time_bp = 0, bio_variables = c("biome"), dataset = "Beyer2020", ext=c(-180,180,30,85))

# extract ice masks and convert to polygons
ice_mask <- get_ice_mask(0, dataset = "Beyer2020")
ice_mask_vect <- as.polygons(ice_mask)

# extract locations from database
locations_vect <- vect(wolve, geom=c("longitude", "latitude"))

# plot
terra::plot(climate_present$biome, 
fun=function() {
points(locations_vect, pch=21, col="black", bg="red", lwd=0.5, cex=1) 
polys(ice_mask_vect, col="grey", lwd=0.5)})

Error in location_series()

When I tried to run the location_series() command as follows:

location_series(
x = HolDatPlaeoClimDat,
bio_variables = c("bio01", "bio12", "bio05", "bio06","bio16", "bio17"),
dataset = "Krapp2021", time_bp = Holocene, nn_interpol = TRUE
)

and I got the following error:

HoloceneClimAllSpec <- location_series(
+   x = HolDatPlaeoClimDat,
+   bio_variables = c("bio01", "bio12", "bio05", "bio06","bio16", "bio17"),
+   dataset = "Krapp2021", time_bp = Holocene, nn_interpol = TRUE
+ )
Error in `[<-`:
! Assigned data `neighbours_values_mean[bio_variables]` must be compatible with row subscript `i`.
x 1 row must be assigned.
x Assigned data has 6 rows.
i Row updates require a list value. Do you need `list()` or `as.list()`?
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 6 to size 1.
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/tibble_error_assign_incompatible_size>
Error in `[<-`:
! Assigned data `neighbours_values_mean[bio_variables]` must be compatible with row subscript `i`.
x 1 row must be assigned.
x Assigned data has 6 rows.
i Row updates require a list value. Do you need `list()` or `as.list()`?
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 6 to size 1.
---
Backtrace:
     x
  1. +-pastclim::location_series(...)
  2. | \-pastclim::location_slice(...)
  3. |   \-pastclim::location_slice_from_region_series(...)
  4. |     +-base::`[<-`(`*tmp*`, i, bio_variables, value = `<dbl>`)
  5. |     \-tibble:::`[<-.tbl_df`(`*tmp*`, i, bio_variables, value = `<dbl>`)
  6. |       \-tibble:::tbl_subassign(x, i, j, value, i_arg, j_arg, substitute(value))
  7. |         \-tibble:::tbl_subassign_row(xj, i, value, i_arg, value_arg, call)
  8. |           +-base::withCallingHandlers(...)
  9. |           \-tibble:::vectbl_assign(x[[j]], i, recycled_value[[j]])
10. |             \-vctrs::vec_assign(x, i, value)
11. +-vctrs:::stop_recycle_incompatible_size(...)
12. | \-vctrs:::stop_vctrs(...)
13. |   \-rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)
14. |     \-rlang:::signal_abort(cnd, .file)
15. |       \-base::signalCondition(cnd)
16. \-tibble (local) `<fn>`(`<vctrs___>`)
17.   \-tibble:::vectbl_recycle_rhs_rows(value, length(i), i_arg, value_arg, call)

When I tried to run it with only one variable, I got a non-halt error. This is an example of my data:

structure(list(name = c("Struthio camelus", "Struthio camelus", 
"Struthio camelus", "Struthio camelus", "Struthio camelus", "Struthio camelus"
), longitude = c(24.633301, 25.549999, 29.0833, 23.0333, 25.5, 
24.633301), latitude = c(-27.616699, -28.6667, 25.799999, -28.205601, 
23, -27.616699)), row.names = c(NA, 6L), class = "data.frame")

at first I thought it was because I attached the tidyr package before I installed pastclim in my script, and that masked the extract function from terra, since I was getting a separate error associated with extract not working, but even removing tidyr I get this error. Holocene is a vector of the time stamps which fall within the Holocene.

Variable descriptions for each dataset

Hi,

Is there a table available that describes the variables within each dataset? Like with table 1 in the pre-print, but for all variables, and which we could access from within the package? (for plotting titles etc.)

For example: what is mo_npp_[month]?

pastclim not compatible with the latest terra on CRAN 1.6-41

terra has changed the way it reads times from netcdf file. This change impacts a number of the functions in pastclim. We will soon update pastclim, but don't update terra for the moment. Use the commands on the website to downgrade terra if you have an udpated version.

Issue downloading Worldclim

Hi!
I am trying to download worldclim data, and right after it reaches 100% I get this error. Tried running it again and no change.
I'm using the latest .dev version, 2.1.0

 [100%] Downloaded 49869449 bytes...
Error in eval(parse(text = file_details$download_function))(dataset = dataset,  : 
  something went wrong setting up this dataset
 the dataset will need downloading again

Best,
Uri

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.