r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
588 stars 132 forks source link

[2.2.x] Error in catalog processing #314

Closed spono closed 4 years ago

spono commented 4 years ago

Ciao JR, playing around with 2.2.0/.1 (as a result of #313 ) I'm not able anymore to process a catalog without getting the following: Error: i[1] is 1 which is out of range [1,nrow=0] Might it be related to wrong handling of empty chunks?

Jean-Romain commented 4 years ago

Reproducible example please.

spono commented 4 years ago

(sorry)

ctg = catalog(las.folder)
opt_chunk_size(ctg) <- 500
opt_chunk_buffer(ctg) <- 10

r = grid_canopy(ctg, res=0.5, p2r(0.1))

BTW, in the meantime I rolled back to 2.1.4 and it goes like a charm.

Jean-Romain commented 4 years ago

As I mentioned, first install 2.2.0 from CRAN. lidR has now more than 900 unit tests that all run on on my machine, on travis CI and on different computers flavors on CRAN. Your example is trivial and should work. I'm pretty sure it comes from your installation.

Also notice that catalog is deprecated (not formally yet) and that chunk_buffer is not respected by grid_canopy (see the documentation). But it does not matter actually this won't affect how it works.

spono commented 4 years ago

yup, I still have to catch up with some changes..!

BTW, yes: the task is super-trivial and I tested both with 2.2.0 (from CRAN) and 2.2.1 (github) but I got that error. Tomorrow I can test more and reinstall everything

Jean-Romain commented 4 years ago

Do you have troubleshooting with grid_canopy only or with all other functions?

spono commented 4 years ago

The file is a strip few kms long and 80m wide.

this morning I tested:

r = grid_canopy(ctg, res=0.5, p2r(0.1) )
i[1] is 1 which is out of range [1,nrow=0]

Same results with 2.2.0(CRAN) and 2.2.1 (github). I tried different options within each size range for:

I'm open to suggestions.

Jean-Romain commented 4 years ago

I just ran the following on a fresh install on lidR 2.2.0 on a virtual machine (W7). It worked smoothly

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
ctg = catalog(LASfile)
opt_chunk_size(ctg) <- 150
opt_chunk_buffer(ctg) <- 10
r = grid_canopy(ctg, res=0.5, p2r(0.1))
Jean-Romain commented 4 years ago

No new of you. Did you fix your trouble?

spono commented 4 years ago

No new of you.

(unfortunately) you're right :)

Did you fix your trouble?

No. The example code you posted works fine for me as well, so this makes me think it might be an issue related to the data itself (I'm waiting for permissions before sending it). Nevertheless, it's pretty weird that the same process works smoothly on 2.1.4 [maybe something related to decimals or something wrong in the header? who knows..].

BTW, tomorrow I'll be able to test it on other machines and I'll let you have some news.

Jean-Romain commented 4 years ago

No need to send the cloud for the moment. Save the catalog with saveRDS and share please.

Jean-Romain commented 4 years ago

I cannot reproduce only with the catalog. Without the point cloud I can only fake run the processing without actually computing anything. This is what I did and it worked

ctg = readRDS("/home/jr/Téléchargements/bug_314/ctg_test2_W10_R362_v220cran.rds")
opt_chunk_size(ctg) <- 500
opt_chunk_buffer(ctg) <- 10

plot(ctg, chunk = TRUE)

lidR:::catalog_fakerun(ctg, perror = 0)

If the code above works on your machine, I will need a point cloud and a fully (minimal) reproducible example. If you can reproduce with a single tile it 's better

Jean-Romain commented 4 years ago

You did not told me that it append only in the 3rd chunk. So it was useless to test only with a catalog and without data. Now please make a complete minimal reproducible example that fails. An example in which I don't have to guess anything please...

Edit: and not screen shoot please. One R file that works standalone and one las file (the one from your screenshot)

spono commented 4 years ago

it fails on the first empty chunk it finds: 3rd in the case of chunk_size = 500, 1st chunk in the case of chunk_size = 50. BTW, I send everything asap

Jean-Romain commented 4 years ago

So if I'm able to create an empty chunk I'm able to reproduce in theroy. Let me try first.

Jean-Romain commented 4 years ago

Ok I reproduced easily. The next time please give me all the information the first time that will save us a lot of time. It comes from readLAS that fails at reading empty chunk for a reason I ignore. I will push a fix soon.

chunk <- readRDS("/tmp/RtmpX2pUzz/chunk3.rds")
las <- readLAS(chunk)
#> Error in `[.data.table`(data, 1:.N, `:=`(X = round_any(X, factor), Y = round_any(Y,  : 
#> i[1] is 1 which is out of range [1,nrow=0] 
Jean-Romain commented 4 years ago

Fixed

spono commented 4 years ago

ok, great! first guess was the correct one, then. Sorry to make you lose time and thanks for the patience, as usual.