EvolEcolGroup / pastclim

An R package providing helper functions to interact with timeseries of worldwide climate reconstructions
https://evolecolgroup.github.io/pastclim/
Creative Commons Attribution 4.0 International
35 stars 3 forks source link

Can't identidy variable names in location_slice #8

Closed SamPassmore closed 1 year ago

SamPassmore commented 1 year ago

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.

dramanica commented 1 year ago

What version of terra are you using? We have seen this problem before on Macs when terra is not downgraded to version 1.6.3. If you have a more recent version, can you please downgrade it as suggested on the pastclim website and report back? For your information, the problem stems from the fact that recent versions of terra on CRAN have not been compiled with support for netcdf. terra is then unable to properly read variables from any .nc file, not just the ones in pastclim. Those // in front of variable names are the giveaway; there are no such //, it's a problem with gdal installations that lack netcdf support A bit more discussion on this issue from StackOverflow: https://stackoverflow.com/questions/73599324/r-terra-gdal-version-incorrect-cannot-read-nc-gdal-error-4 Let me know if downgrading terra fails to fix the problem, and we can try to dig a bit deeper.

SamPassmore commented 1 year ago

Hello. Thank-you for the quick response. My apologies I did not realize the downgrading related to this error, I thought it was due to the error listed at the end of the readme page.

Downgrading terra did not immediately solve my problem, but uninstalling both terra and pastclim, and re-installing with the aforementioned versions fixed the issue.

dramanica commented 1 year ago

Hi @SamPassmore, no worries, glad it got resolved easily. It is a rather annoying bug, but hopefully it will get fixed on CRAN soon.