Open JocelyneSze opened 2 years ago
Thanks for this issue @JocelyneSze.
For the error in st_crop.stars()
, does the bounding box you're using also have a crs defined? For example, I can reproduce that error message when running: st_crop(hyde_med, st_bbox(c(xmin = 30, ymin = 35, xmax = 35, ymax = 40)))
, but st_crop(hyde_med, st_bbox(c(xmin = 30, ymin = 35, xmax = 35, ymax = 40), crs = 4326))
runs fine.
I'll have to look into the error with the stars proxy object further.
OK, can confirm this is an issue in the stars
package as stars_proxy
objects do not play nicely with regular stars objects:
> file = system.file("tif/L7_ETMs.tif", package = "stars")
> ras = read_stars(file, proxy = FALSE)
> ras_proxy = read_stars(file, proxy = TRUE)
>
> ras / ras_proxy
Warning: Incompatible methods ("Ops.stars", "Ops.stars_proxy") for "/"
Error in ras/ras_proxy : non-numeric argument to binary operator
The issue here in anthromes
is that hyde_read()
uses read_stars()
under the hood, and the latter function defaults to reading hyde_tropics
as a stars_proxy
object but not inputs_tropics
. The solution you have here of just using st_as_stars()
will work fine, but anthromes
should ultimately do a better job using stars_proxy
objects or warning the user about this behavior.
Hi, thanks for confirming the issue, unfortunately the anthromes_classify
function didn't work with using st_as_stars()
on the stars_proxy
object, I'm not entirely sure why (but I've also found the already-classified data to work with instead, so not pursuing this issue anymore, though others might face the same problem?).
Hi, I'm trying to read in HYDE raw data and inputs and cropping to my area of interest (across the tropics) with
hyde_read
andst_crop
, then classifying the anthromes withanthrome_classify
. However I run into the following error messageError in dat/inputs["land_area"] : non-numeric argument to binary operator In addition: Warning message: In dplyr::mutate(., used = crops + grazing + urban, trees = pot_veg %in% : Incompatible methods ("Ops.stars_proxy", "Ops.stars") for "/"
So I tried to specify the data as a stars object withanthromes_tropics <- anthrome_classify(st_as_stars(hyde_tropics), inputs_tropics)
, however I get a different error message that I'm not sure how to resolveError in st_crop.stars(x = x, y = y, crop = crop, epsilon = epsilon) : for cropping, the CRS of both objects have to be identical
As I have checked usingst_crs
that the CRS of both objects are identical. I'm not quite sure how this can be resolved, if this is an issue withstars
package and how stars proxy objects are dealt with, or if it's possible to read the hyde data as a stars object instead of stars proxy object?If it helps, this is what I did to read the data in