8000 Issue when hyde_read reads data in as stars proxy object? · Issue #2 · nick-gauthier/anthromes · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Issue when hyde_read reads data in as stars proxy object? #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an i 8000 ssue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JocelyneSze opened this issue Dec 1, 2021 · 3 comments
Open

Issue when hyde_read reads data in as stars proxy object? #2

JocelyneSze opened this issue Dec 1, 2021 · 3 comments

Comments

@JocelyneSze
Copy link

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 and st_crop, then classifying the anthromes with anthrome_classify. However I run into the following error message
Error 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 with
anthromes_tropics <- anthrome_classify(st_as_stars(hyde_tropics), inputs_tropics), however I get a different error message that I'm not sure how to resolve
Error 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 using st_crs that the CRS of both objects are identical.
I'm not quite sure how this can be resolved, if this is an issue with stars 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

> hyde <- hyde_read(dir = "../Data/Ellis2021-Anthromes")
> hyde
stars_proxy object with 6 attributes in 6 file(s):
$cropland
[1] "[...]/cropland.tif"

$grazing
[1] "[...]/grazing.tif"

$ir_rice
[1] "[...]/ir_rice.tif"

$popc
[1] "[...]/popc.tif"

$tot_irri
[1] "[...]/tot_irri.tif"

$uopp
[1] "[...]/uopp.tif"

dimension(s):
     from   to  offset      delta refsys point             values x/y
x       1 4320    -180  0.0833333 WGS 84 FALSE               NULL [x]
y       1 2160 89.9999 -0.0833333 WGS 84 FALSE               NULL [y]
time    1   75      NA         NA     NA    NA 10000BC,...,2017AD    

> inputs <- hyde_read(vars="inputs", dir="../Data/Ellis2021-Anthromes")
> inputs
stars object with 2 dimensions and 5 attributes
attribute(s), summary of first 1e+05 cells:
   land_area                                            pot_veg                              regions            iso       
 Min.   : NA     Tropical Evergreen Woodland                :     0   Africa                     :     0   Min.   : NA    
 1st Qu.: NA     Tropical Deciduous Woodland                :     0   Asia                       :     0   1st Qu.: NA    
 Median : NA     Temperate Broadleaf and Evergreen Woodland :     0   Eurasia                    :     0   Median : NA    
 Mean   :NaN     Temperate Needleleaf and Evergreen Woodland:     0   Europe                     :     0   Mean   :NaN    
 3rd Qu.: NA     Temperate Deciduous Woodland               :     0   Latin America and Caribbean:     0   3rd Qu.: NA    
 Max.   : NA     (Other)                                    :     0   (Other)                    :     0   Max.   : NA    
 NA's   :1e+05   NA's                                       :100000   NA's                       :100000   NA's   :1e+05  
   pot_vill     
 Min.   : NA    
 1st Qu.: NA    
 Median : NA    
 Mean   :NaN    
 3rd Qu.: NA    
 Max.   : NA    
 NA's   :1e+05  
dimension(s):
  from   to  offset      delta refsys point values x/y
x    1 4320    -180  0.0833333 WGS 84 FALSE   NULL [x]
y    1 2160 89.9999 -0.0833333 WGS 84 FALSE   NULL [y]
@nick-gauthier
Copy link
Owner

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.

@nick-gauthier
Copy link
Owner
7C81

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.

@JocelyneSze
Copy link
Author

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?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0