ilyamaclean / microclima

microclima
30 stars 13 forks source link

Error in sp::CRS(SRS_string = prj$wkt) : no arguments in initialization list #19

Closed weavers33 closed 3 years ago

weavers33 commented 3 years ago

Hi there,

I am trying to use the get_dem command as follows; NewDEM<-microclima::get_dem(lat = 35.0408, long = -83.6695, resolution= 30, xdims=10000, ydims=7000)

When I run this, I get the following error

Error in sp::CRS(SRS_string = prj$wkt) : no arguments in initialization list

I uninstalled and reinstalled microclima, NicheMapR, elevatr, and rgdal, but the package unfortunately still doesn't work.

Not sure if it's helpful, but while re-installing Microclima I got a few warnings

clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o In file included from RcppExports.cpp:4: In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp.h:57: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/DataFrame.h:136:18: warning: unused variable 'data' [-Wunused-variable] SEXP data = Parent::get(); ^ 1 warning generated. clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c invls.cpp -o invls.o In file included from invls.cpp:1: In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp.h:57: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/DataFrame.h:136:18: warning: unused variable 'data' [-Wunused-variable] SEXP data = Parent::get(); ^ 1 warning generated. clang++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o microclima.so RcppExports.o invls.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation installing to /Library/Frameworks/R.framework/Versions/3.6/Resources/library/00LOCK-microclima/00new/microclima/libs R data moving datasets to lazyload DB byte-compile and prepare package for lazy loading help Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:12: unknown macro '\item' Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:14: unknown macro '\item' Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:16: unknown macro '\item' Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:18: unexpected section header '\value' Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:29: unexpected section header '\description' Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:32: unexpected section header '\details' Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:41: unexpected section header '\examples' Warning: /private/var/folders/tx/k9ftyf3d0m157rfnxnp_gsgm0000gn/T/RtmpFr32fJ/R.INSTALLf90418858557/microclima/man/humidityconvert.Rd:46: unexpected END_OF_INPUT ' ' installing help indices building package indices installing vignettes testing if installed package can be loaded from temporary location checking absolute paths in shared objects and dynamic libraries testing if installed package can be loaded from final location testing if installed package keeps a record of temporary installation path

ilyamaclean commented 3 years ago

I cannot replicate this error, though I do get an error because the tile you are trying to download is ~2GB, which is too big. Try downloading in tiles and merging. If that returns the same error, could could you let me know which version of rgdal, raster, sf and elevtr you are running.

weavers33 commented 3 years ago

I changed the code to the following, but still received the same error message NewDEM<-microclima::get_dem(lat = 35.0408, long = -83.6695, resolution = 30)

Here are all the package versions currently running microclima 0.1.0 rgdal v 1.5.23 raster v 3.4.5 elevatr v 0.3.4 sf v 0.9.8

Thanks again for all your help, I really appreciate it!

On Wed, Apr 7, 2021 at 4:05 AM Ilya Maclean @.***> wrote:

I cannot replicate this error, though I do get an error because the tile you are trying to download is ~2GB, which is too big. Try downloading in tiles and merging. If that returns the same error, could could you let me know which version of rgdal, raster, sf and elevtr you are running.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ilyamaclean/microclima/issues/19#issuecomment-814741668, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANLH5TKP72HZFJYXCAG2SR3THQN3ZANCNFSM42PV2WZA .

ilyamaclean commented 3 years ago

This is puzzling. I can't replicate the error and have the same versions of of those packages. What version of R are you running?

Does the function look like this:

get_dem <- function(r = NA, lat, long, resolution = 30, zmin = 0, xdims = 200, ydims = 200) { if (resolution < 30) { warning("Higher resolution data only available for some locations. DEM may be derived by interpolation") } if (class(r)[1] != "RasterLayer") { xy <- data.frame(x = long, y = lat) xy <- sf::st_as_sf(xy, coords = c('x', 'y'), crs = 4326)

if (lat >= -80 & lat <= 84)
  xy <- sf::st_transform(xy, 3395)
if (lat > 84)
  xy <- sf::st_transform(xy, 3413)
if (lat < -80)
  xy <- sf::st_transform(xy, 3976)

  e <- extent(c(sf::st_coordinates(xy)[1] - floor(xdims/2) * resolution,
                sf::st_coordinates(xy)[1] + ceiling(xdims/2) * resolution,
                sf::st_coordinates(xy)[2] - floor(ydims/2) * resolution,
                sf::st_coordinates(xy)[2] + ceiling(ydims/2) * resolution))

r <- raster(e)
res(r) <- resolution
crs(r) <- CRS(SRS_string = st_crs(xy)$wkt)

} else { lat <- latlongfromraster(r)$lat long <- latlongfromraster(r)$long res(r) <- resolution } z <- ceiling(log((cos(lat pi/180) 2 pi 6378137) / (256 * resolution), 2)) z <- ifelse(z > 14, 14, z) p <- as(extent(r), 'SpatialPoints') p <- as.data.frame(p) xx <- sp::proj4string(r) r2 <- elevatr::get_elev_raster(p, z = z, src = "aws", prj = xx) r2 <- resample(r2, r) m2 <- getValues(r2, format = "matrix") m2[m2 < zmin] <- zmin m2[is.na(m2)] <- zmin r2 <- if_raster(m2, r2) return(r2) }

weavers33 commented 3 years ago

The R version is 3.6.2, which is maybe too old? I pasted the function text, as far as I can tell it's the same as what you pasted above.

function (r = NA, lat, long, resolution = 30, zmin = 0, xdims = 200, ydims = 200) { if (resolution < 30) { warning("Higher resolution data only available for some locations. DEM\n may be derived by interpolation") } if (class(r)[1] != "RasterLayer") { xy <- data.frame(x = long, y = lat) xy <- sf::st_as_sf(xy, coords = c("x", "y"), crs = 4326) if (lat >= -80 & lat <= 84) xy <- sf::st_transform(xy, 3395) if (lat > 84) xy <- sf::st_transform(xy, 3413) if (lat < -80) xy <- sf::st_transform(xy, 3976) e <- extent(c(sf::st_coordinates(xy)[1] - floor(xdims/2) resolution, sf::st_coordinates(xy)[1] + ceiling(xdims/2) resolution, sf::st_coordinates(xy)[2] - floor(ydims/2) resolution, sf::st_coordinates(xy)[2] + ceiling(ydims/2) resolution)) r <- raster(e) res(r) <- resolution crs(r) <- CRS(SRS_string = st_crs(xy)$wkt) } else { lat <- latlongfromraster(r)$lat long <- latlongfromraster(r)$long res(r) <- resolution } z <- ceiling(log((cos(lat pi/180) 2 pi 6378137)/(256 * resolution), 2)) z <- ifelse(z > 14, 14, z) p <- as(extent(r), "SpatialPoints") p <- as.data.frame(p) xx <- sp::proj4string(r) r2 <- elevatr::get_elev_raster(p, z = z, src = "aws", prj = xx) r2 <- resample(r2, r) m2 <- getValues(r2, format = "matrix") m2[m2 < zmin] <- zmin m2[is.na(m2)] <- zmin r2 <- if_raster(m2, r2) return(r2) } <bytecode: 0x7fa2d331b698>

On Wed, Apr 7, 2021 at 9:38 AM Ilya Maclean ***@***.***> wrote: > This is puzzling. I can't replicate the error and have the same versions > of of those packages. What version of R are you running? > > Does the function look like this: > > get_dem <- function(r = NA, lat, long, resolution = 30, zmin = 0, xdims = > 200, ydims = 200) { > if (resolution < 30) { > warning("Higher resolution data only available for some locations. DEM > may be derived by interpolation") > } > if (class(r)[1] != "RasterLayer") { > xy <- data.frame(x = long, y = lat) > xy <- sf::st_as_sf(xy, coords = c('x', 'y'), crs = 4326) > > if (lat >= -80 & lat <= 84) > xy <- sf::st_transform(xy, 3395) > if (lat > 84) > xy <- sf::st_transform(xy, 3413) > if (lat < -80) > xy <- sf::st_transform(xy, 3976) > > e <- extent(c(sf::st_coordinates(xy)[1] - floor(xdims/2) * resolution, > sf::st_coordinates(xy)[1] + ceiling(xdims/2) * resolution, > sf::st_coordinates(xy)[2] - floor(ydims/2) * resolution, > sf::st_coordinates(xy)[2] + ceiling(ydims/2) * resolution)) > > r <- raster(e) > res(r) <- resolution > crs(r) <- CRS(SRS_string = st_crs(xy)$wkt) > > } else { > lat <- latlongfromraster(r)$lat > long <- latlongfromraster(r)$long > res(r) <- resolution > } > z <- ceiling(log((cos(lat * pi/180) * 2 * pi * 6378137) / (256 * > resolution), 2)) > z <- ifelse(z > 14, 14, z) > p <- as(extent(r), 'SpatialPoints') > p <- as.data.frame(p) > xx <- sp::proj4string(r) > r2 <- elevatr::get_elev_raster(p, z = z, src = "aws", prj = xx) > r2 <- resample(r2, r) > m2 <- getValues(r2, format = "matrix") > m2[m2 < zmin] <- zmin > m2[is.na(m2)] <- zmin > r2 <- if_raster(m2, r2) > return(r2) > } > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > , > or unsubscribe > > . >
ilyamaclean commented 3 years ago

I am running a later version of R, which may be the reason I cannot replicate the error, but to help diagnose, would you mind running the code inside the function and letting me know at what point it falls over?

weavers33 commented 3 years ago

Hi there,

I ran through the function a couple of ways to try and find the problem:

1) When trying to just use lat and long- Everything runs fine when resolution is set to 30 until this line

crs(r) <- CRS(SRS_string = st_crs(xy)$wkt)

Which generates the "Error in sp::CRS(SRS_string = prj$wkt) :no arguments in initialization list"

2) When using a DEM I already have- Everything runs fine with resolution set to 30 until this line-

r2 <- elevatr::get_elev_raster(p, z = z, src = "aws", prj = xx)

Which generates the "Error in sp::CRS(SRS_string = prj$wkt) :no arguments in initialization list"

Hopefully this helps, let me know how else I can be useful!

Sam

On Fri, Apr 9, 2021 at 6:08 AM Ilya Maclean @.***> wrote:

I am running a later version of R, which may be the reason I cannot replicate the error, but to help diagnose, would you mind running the code inside the function and letting me know at what point it falls over?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ilyamaclean/microclima/issues/19#issuecomment-816606927, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANLH5TMK256V3N3WOJOVEXTTH3N4FANCNFSM42PV2WZA .

ilyamaclean commented 3 years ago

Apologies - I am really struggling to debug this simply as I can't replicate the error. When running using a supplied lat long up to the point at which the error, does xy have a Projected CRS defined? You should get something like this:

Simple feature collection with 1 feature and 0 fields Geometry type: POINT Dimension: XY Bounding box: xmin: -23472050 ymin: 2603986 xmax: -23472050 ymax: 2603986 Projected CRS: WGS 84 / NSIDC Sea Ice Polar Stereographic South geometry 1 POINT (-23472047 2603986)

dklinges9 commented 3 years ago

HI @weavers33 it appears you'll want to update your R version. I received the same error that you did:

Error in sp::CRS(SRS_string = prj$wkt) : 
  no arguments in initialization list

When I was running get_dem() on R version 3.6.3:

> R.version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          6.3                         
year           2020                        
month          02                          
day            29                          
svn rev        77875                       
language       R                           
version.string R version 3.6.3 (2020-02-29)
nickname       Holding the Windsock 

However, when I used get_dem() with R version 4.0.5 then it works just fine.

@ilyamaclean I think it might be safe to close this issue, with the recommendation that users update to at least R 4.0. However you might want to keep tabs on this, as users of other microclima or NicheMapR functions that use get_dem() may face the same error if they don't have R 4.0.

weavers33 commented 3 years ago

Sorry for the long gap between replies; I updated my R version and no longer get that error, get_dem() is working well now!

On Mon, May 3, 2021 at 12:44 PM Dave Klinges @.***> wrote:

HI @weavers33 https://github.com/weavers33 it appears you'll want to update your R version. I received the same error that you did:

Error in sp::CRS(SRS_string = prj$wkt) : no arguments in initialization list

When I was running get_dem() on R version 3.6.3:

R.version _ platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 3 minor 6.3 year 2020 month 02 day 29 svn rev 77875 language R version.string R version 3.6.3 (2020-02-29) nickname Holding the Windsock

However, when I used get_dem() with R version 4.0.5 then it works just fine.

@ilyamaclean https://github.com/ilyamaclean I think it might be safe to close this issue, with the recommendation that users update to at least R 4.0. However you might want to keep tabs on this, as users of other microclima or NicheMapR functions that use get_dem() may face the same error if they don't have R 4.0.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ilyamaclean/microclima/issues/19#issuecomment-831419986, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANLH5TOE4WAROBRUYUFEIX3TL3OHZANCNFSM42PV2WZA .