search for: comparerast

Displaying 10 results from an estimated 10 matches for "comparerast".

Did you mean: compareraster
2024 Aug 15
1
allequal diff
Digging into the code for raster::compareRaster(): library(raster) r <- raster(ncol=3, nrow=3) values(r) <- 1:ncell(r) r2 <- r values(r2) <- c(1:8,10) all.equal(getValues(r), getValues(r2), tolerance = 0) [1] "Mean relative difference: 0.1111111" compareRaster has fancier machinery internally for doing the comparis...
2024 Aug 15
1
allequal diff
...0)) # FALSE, since not exactly [1] FALSE > all.equal(tan(d45), rep(1, 10), tolerance = 0) # to see difference [1] "Mean relative difference: 1.29526e-15" > Unfortunately, I just get "FALSE" not the difference. > r2_resampled <- resample(r2, r1) > compareRaster(r1, r2_resampled) [1] TRUE > # Compare rasters > result <- all.equal(r1, r2_resampled) Warning message: In compareRaster(target, current, ..., values = values, stopiffalse = stopiffalse, : not all objects have the same values > print(result) [1] FALSE > Kind regards...
2024 Aug 16
1
allequal diff
Dear Ben Many thanks. I see that a second challenge are NA values. Is it possible to consider na.rm=TRUE? > r2_resampled <- resample(r2, r1) > compareRaster(r1, r2_resampled) [1] TRUE > > all.equal(getValues(r1), getValues(r2_resampled), tolerance = 0) [1] "'is.NA' value mismatch: 9544032 in current 66532795 in target" Kind regards Sibylle -----Original Message----- From: R-help <r-help-bounces at r-projec...
2024 Aug 18
1
allequal diff
...this may often not elicit a (prompt) response. -- Bert On Sun, Aug 18, 2024 at 11:50?AM Ben Bolker <bbolker at gmail.com> wrote: > > The OP's original problem is that the all.equal method for raster > objects (raster:::all.equal.raster), which is a wrapper around the > compareRaster() function, compares a bunch of different properties of > rasters (extent, resolution, values, etc.) and only returns a single > overall logical (TRUE/FALSE) value. OP wanted to see the magnitude of > the difference (as you could get for more typical all.equal methods by > using toler...
2024 Aug 16
1
allequal diff
...So I need to call > getValues a second time? Not necessarily, but it's one of the options. I was thinking along the lines of: values1 <- getValues(r1) mask1 <- is.na(values1) # Do the same for r2 # Combine the masks all.equal(values1[!combined_mask], values2[!combined_mask]) Unlike compareRaster(), this assumes that the coordinate grid of r1 and r2 is already the same and that only some of the values may differ. > I suppose you mean to first prepare a mask using is.na without > getValues and then in the second step your code? 'raster' documentation says that is.na() wor...
2024 Aug 18
1
allequal diff
?? The OP's original problem is that the all.equal method for raster objects (raster:::all.equal.raster), which is a wrapper around the compareRaster() function, compares a bunch of different properties of rasters (extent, resolution, values, etc.) and only returns a single overall logical (TRUE/FALSE) value. OP wanted to see the magnitude of the difference (as you could get for more typical all.equal methods by using tolerance=0), but in...
2024 Aug 16
1
allequal diff
...So I need to call > getValues a second time? Not necessarily, but it's one of the options. I was thinking along the lines of: values1 <- getValues(r1) mask1 <- is.na(values1) # Do the same for r2 # Combine the masks all.equal(values1[!combined_mask], values2[!combined_mask]) Unlike compareRaster(), this assumes that the coordinate grid of r1 and r2 is already the same and that only some of the values may differ. > I suppose you mean to first prepare a mask using is.na without > getValues and then in the second step your code? 'raster' documentation says that is.na() work...
2024 Aug 18
2
allequal diff
"Is it true that all.equal just compares y values?" The following may be a bit more than you may have wanted, but I hope it is nevertheless useful. The first place you should go to for questions like this is the Help system, not here, i.e. ?all.equal When you do this, you will find that all.equal() is a so-called S3 generic function, which, among other things, means that it works
2024 Aug 16
2
allequal diff
Many thanks Ivan Use is.na() on getValues() outputs, combine the two masks using the | operator to get a mask of values that are missing in either raster, then negate the mask to choose the non-missing values: all.equal(getValues(r1)[!mask], getValues(r2)[!mask]) --> what do you mean by use is.na() in getValues(). So I need to call getValues a second time? I suppose you mean to first
2024 Aug 18
2
allequal diff
Dear Ivan Thanks a lot for this very nice example. Is it true that all.equal just compares y values? Based on this help here I think so and the value I got is the difference for the y-values. https://www.statology.org/all-equal-function-r/ However, here I see x and y testing? https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/all.equal I am actually interested in the x values