jbferet / biodivMapR

biodivMapR: an R package for α- and β-diversity mapping using remotely-sensed images
https://jbferet.github.io/biodivMapR/index.html
GNU General Public License v3.0
47 stars 13 forks source link

A bug from function "perform_PCA" #2

Closed mixiangcheng closed 4 years ago

mixiangcheng commented 4 years ago

Dr. Féret, Thanks for your package. This is very exciting package so that I can use it to calculate beta diversity for my hyperspectral data. I am using a airborne hyperspectral data with 64 bands. Here is my header file:

ENVI samples = 1342 lines = 13596 bands = 64 header offset = 0 file type = ENVI Standard data type = 2 data ignore value=-Inf interleave = BIL sensor type =Unknown
byte order = 0 wavelength units = Nanometers map info = {projection, 1, 1, xxxx, xxx , 1 , 1 } wavelength = { 398.55, 407.39, 416.27, 425.18, 434.13, 443.10, 452.11, 461.14, 4721, 479.30, 488.43, 497.58, 506.76, 515.96, 525.19, 534.44, 543.72, 553.02, 562.35, 571.70, 581.07, 5946, 599.86, 609.29, 618.74, 628.21, 637.69, 647.19, 656.70, 666.24, 675.78, 685.34, 694.91, 704.50, 714.09, 723.70, 733.32, 742.95, 752.58, 762.23, 771.88, 781.54, 791.21, 800.88, 810.56, 820.24, 829.92, 839.61, 849.30, 858.99, 868.68, 878.38, 888.07, 897.76, 907.45, 917.13, 926.81, 936.49, 946.16, 955.83, 965.49, 975.15, 984.80, 994.44} coordinate system string = {PROJCS["WGS_1984_UTM_Zone_50N",GEOGCS["GCS_WGS_1984",DATUM....} z plot range = { ...... } band names = { ..... }

I encountered an issue when using function "perform_PCA". If I set "Continuum_Removal = T", there is error message from function "future_xapply" in "apply_continuum_removal":


      Format of main raster OK for processing         


     Format of mask raster OK for processing         

[1] "Extract pixels from the images to perform PCA on a subset" Error in Lambda_tmp - Latest.Intercept_tmp : non-conformable arrays

If I set "Continuum_Removal = F", there is error message from function "write_PCA_raster":


      Format of main raster OK for processing         


     Format of mask raster OK for processing         

[1] "Extract pixels from the images to perform PCA on a subset" [1] "perform PCA#1 on the subset image" [1] "perform 2nd filtering: Exclude extreme PCA values" [1] "Perform PCA on image subsets and filter data" [1] "PCA Piece # 1 / 11" [1] "PCA Piece # 2 / 11" [1] "PCA Piece # 3 / 11" [1] "PCA Piece # 4 / 11" [1] "PCA Piece # 5 / 11" [1] "PCA Piece # 6 / 11" [1] "PCA Piece # 7 / 11" [1] "PCA Piece # 8 / 11" [1] "PCA Piece # 9 / 11" [1] "PCA Piece # 10 / 11" [1] "PCA Piece # 11 / 11" [1] "perform PCA#2 on the subset image" [1] "Apply PCA model to the whole image" [1] "PCA Piece # 1 / 11" Error in t(PCA_model$eiV[, 1:Nb_PCs]) %*% t(center_reduce(Image_Chunk, : non-conformable arguments.

Would you give me some suggestions to correct this error? Thanks in advance. Best, Xiangcheng

jbferet commented 4 years ago

Dear Xiangcheng, Thank you for reporting this bug. I can see a few possibilities for the message you are having. It either comes from the original data (and inf values which were not properly masked), or from an exeption unaccounted for in the code... but it should be fixed with a bit more information.

Can you reproduce this bug when using a subset of your image, with reduced size?

if so, would it be possible for you to send the image subset and script reproducing the bug to my personal email (@teledetection.fr)?

the bug occurs early in the code, so a reduced size of 100 x 100 pixels should be sufficient to reproduce the bug.

thank you in advance.

best regards,

jb

jbferet commented 4 years ago

The bug was due to mishandling of spectral bands disturbed by water vapor in case ContinuumRemoval was set to TRUE.

Bug fixed

mixiangcheng commented 4 years ago

Thanks a lot. I can run my code SMOOTHLY.