Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue 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

ww_multi_scale returns an error for categorical rasters #60

Closed
Nowosad opened this issue Apr 27, 2024 · 3 comments
Closed

ww_multi_scale returns an error for categorical rasters #60

Nowosad opened this issue Apr 27, 2024 · 3 comments

Comments

@Nowosad
Copy link

Nowosad commented Apr 27, 2024

Hi @mikemahoney218 -- I am trying to incorporate waywiser for examples in a paper about spatial patterns comparison. The ww_multi_scale() function works fine for continuous rasters (however, it gives some CRSs warnings), but errors for categorical ones. Is this expected?

library(terra)
library(waywiser)
library(landscapemetrics)
cell_sizes = seq(10, 100, 10) * 1000
l1 = rast(landscape)
l2 = l1
clc_multi_scale = ww_multi_scale(truth = l1, estimate = l2,
                                 metrics = list(yardstick::precision), 
                                 cellsize = cell_sizes)
#> Error in `metric_set()`:
#> ! Failed to compute `<clss_mtr>()`.
#> Caused by error:
#> ! Must select at least one item.
clc_multi_scale
#> Error in eval(expr, envir, enclos): object 'clc_multi_scale' not found
@mikemahoney218
Copy link
Member

Thanks for the report, I can reproduce on my end.

I'm digging into this now, and am going to write notes here as I go. It seems like for some reason we're not passing estimate to the yardstick functions correctly in this case:

Browse[3]> enquo(truth)
<quosure>
expr: ^.truth
env:  0x1634bae58
Browse[3]> enquo(estimate)
<quosure>
expr: ^
env:  empty

@mikemahoney218
Copy link
Member

on a second look, while I can't confirm that's not a problem, I think the bigger issue is that these columns aren't factors when working with classification metrics: tidymodels/yardstick#504

@mikemahoney218
Copy link
Member

Thanks for the report! I think this is mostly fixed in #61. The only other change necessary (and you can see this in the tests added in #61) is that those cellsizes wind up creating a grid with a single cell that includes the entire raster; as precision() requires factors have more than one level, this winds up erroring. Using a smaller grid will work once #61 is merged though.

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