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

coregisterImages seq.default error #113

Open
John-Polo opened this issue Sep 26, 2024 · 1 comment
Open

coregisterImages seq.default error #113

John-Polo opened this issue Sep 26, 2024 · 1 comment

Comments

@John-Polo
Copy link

I tried to co-register imagery from Planet. When I use coregisterImages(), I get an error.

library(terra)
#> terra 1.7.71
library(RStoolbox)
#> Warning: package 'RStoolbox' was built under R version 4.3.3
#> The legacy packages maptools, rgdal, and rgeos, underpinning this package
#> will retire shortly. Please refer to R-spatial evolution reports on
#> https://r-spatial.org/r/2023/05/15/evolution4.html for details.
#> This package is now running under evolution status 0
#> This is version 1.0.0 of RStoolbox

basedir <- "data/MRS_20222023_8b_harm_psscene_analytic_8b_sr_udm2/PSScene/"

l1 <- list.files(basedir, full.names = T, recursive = T, pattern = "harmonized.*tif$")

r1 <- rast(l1[1])
r1
#> class       : SpatRaster 
#> dimensions  : 22, 12, 8  (nrow, ncol, nlyr)
#> resolution  : 3, 3  (x, y)
#> extent      : 321744, 321780, 3928893, 3928959  (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 84 / UTM zone 17N (EPSG:32617) 
#> source      : 20220807_154955_15_2499_3B_AnalyticMS_SR_8b_harmonized_clip.tif 
#> names       : coastal_blue, blue, green_i, green, yellow,  red, ... 
#> min values  :          405,  474,     679,   757,    906,  770, ... 
#> max values  :          568,  585,     819,   903,   1204, 1132, ...
res(r1)
#> [1] 3 3

r2 <- rast(l1[2])
r2
#> class       : SpatRaster 
#> dimensions  : 22, 12, 8  (nrow, ncol, nlyr)
#> resolution  : 3, 3  (x, y)
#> extent      : 321744, 321780, 3928893, 3928959  (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 84 / UTM zone 17N (EPSG:32617) 
#> source      : 20220807_154957_43_2499_3B_AnalyticMS_SR_8b_harmonized_clip.tif 
#> names       : coastal_blue, blue, green_i, green, yellow,  red, ... 
#> min values  :          385,  454,     681,   766,    899,  740, ... 
#> max values  :          571,  562,     819,   901,   1191, 1111, ...
res(r2)
#> [1] 3 3

coregisterImages(r2, r1, shift = 2, shiftInc = 1, reportStats = T)
#> Error in seq.default(mmin, mmax, by = (mmax - mmin)/nBins): 'from' must be a finite number
#> 
#> Do it all manually
del1 <- seq(0, 2, 1)
del1
#> [1] 0 1 2
del2 <- c(-rev(del1), del1[-1])
del2
#> [1] -2 -1  0  1  2
expand.grid(del2*3, del2*3)
#>    Var1 Var2
#> 1    -6   -6
#> 2    -3   -6
#> 3     0   -6
#> 4     3   -6
#> 5     6   -6
#> 6    -6   -3
#> 7    -3   -3
#> 8     0   -3
#> 9     3   -3
#> 10    6   -3
#> 11   -6    0
#> 12   -3    0
#> 13    0    0
#> 14    3    0
#> 15    6    0
#> 16   -6    3
#> 17   -3    3
#> 18    0    3
#> 19    3    3
#> 20    6    3
#> 21   -6    6
#> 22   -3    6
#> 23    0    6
#> 24    3    6
#> 25    6    6

sessionInfo()
#> R version 4.3.2 (2023-10-31 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> time zone: America/New_York
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.34   fastmap_1.1.1   xfun_0.39       glue_1.7.0     
#>  [5] knitr_1.43      htmltools_0.5.5 rmarkdown_2.22  lifecycle_1.0.4
#>  [9] cli_3.6.2       reprex_2.1.1    withr_3.0.1     compiler_4.3.2 
#> [13] rstudioapi_0.14 tools_4.3.2     evaluate_0.21   yaml_2.3.7     
#> [17] rlang_1.1.3     fs_1.6.2
Created on 2024-09-26 with reprex v2.1.1

There is an unrelated post on StackOverflow about the error. The answer had to do with a custom function that was allowing Inf values, but from what I can see in the code for coregisterImages(), it's not the same situation.

@joaocarr
Copy link

I also get the same error message when coregistering two multiband rasters. I've checked and I don't have any NA, NaN or Inf values.

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