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

Error message while computing spectral indices #6

Closed
mej1d1 opened this issue May 18, 2016 · 14 comments
Closed

Error message while computing spectral indices #6

mej1d1 opened this issue May 18, 2016 · 14 comments

Comments

@mej1d1
Copy link

mej1d1 commented May 18, 2016

I created a raster stack (landsat_data) with 6 layers, each of which represents one band.I also saved the names of the layers in a vector (names_landsat). Now I want to calculate the spectral indices with the following code:

    ind <- landsat_data
    ind <- spectralIndices(ind,blue=as.character(names_landsat[1]),green=as.character(names_landsat[2]),red=as.character(names_landsat[3]),nir=as.character(names_landsat[4]),swir1=as.character(names_landsat[5]),swir2=as.character(names_landsat[6]))

Unfortunately R returns the following error message:

  Error in if ((maxValue(img[[red]])/scaleFactor > 1.5 | minValue(img[[red]])/scaleFactor <  : 
      missing value where TRUE/FALSE needed
    In addition: Warning messages:
    1: In .local(x, ...) : max value not known, use setMinMax
    2: In .local(x, ...) : min value not known, use setMinMax

I have absolutely zero clue what that means as I am pretty new to this package.
I would be very grateful if somebody could give me any kind of help.
Thanks.

@bleutner
Copy link
Owner

bleutner commented May 18, 2016

Looks like this needs more careful heuristics on my side --> I'll refine that in one of the next versions. It should only occur though when EVI or EVI2 are to be calculated and extreme values are unknown.

For now please set the data range beforehand, i.e. run this once after you load the data,

## Reads the raster once to get accurate minimum and maximum values
landsat_data <- setMinMax(landsat_data)

# And then as usual 
indices <- spectralIndices(landsat_data, blue = 1, green=2, red =3 )

@mej1d1
Copy link
Author

mej1d1 commented May 18, 2016

Thanks for your reply ! I did as advised and now I et the following warning message:

Warning message:
In spectralIndices(ind, blue = names_landsat[1], green = names_landsat[2],  :
  EVI/EVI2 parameters L_evi, G, C1 and C2 are defined for reflectance [0,1] but img values are outside of this range.
  If you are using scaled reflectance values please provide the scaleFactor argument.
  If img is in DN or radiance it must be converted to reflectance.
  Skipping EVI calculation.

Also only the following indices are being calculated:

"DVI" "GEMI" "LSWI" "MSAVI" "MSAVI2" "NDVI" "NDWI" "SAVI" "SATVI" "SLAVI" "SR" "TVI" "WDVI"

@bleutner
Copy link
Owner

bleutner commented May 18, 2016

Yes that is what it is supposed to tell you, when your data do not look like reflectance values and yes, it will calculate the remaining indices.

EVI and EVI2 rely on parameters which are defined for reflectance values only (ranging from 0 to 1).
If your data are actually reflectances, but are scaled to a different range, e.g. 0-1000 you can still calculate EVI by supplying the scaling factor, i.e. in this example scaleFactor=1000.

However, if your data are not reflectances, but digital numbers (DN), for example, EVI is not defined and hence will not be calculated.

@mej1d1
Copy link
Author

mej1d1 commented May 18, 2016

oh ok I understand. Did you see my edit ? EVI is not the only one not being computed. Excuse me if my questions may sound stupid, but as I already said, I'm pretty new to all this.

@bleutner
Copy link
Owner

Only EVI and EVI2 should be skipped in this case. Are there any others missing?

@mej1d1
Copy link
Author

mej1d1 commented May 18, 2016

Yes, only 13 indices are being returned. According to the help file for the spectralIndices() function, they should be 22 (if I counted correctly).

You can see the ones that are being returned in my second question in this issue.

@bleutner
Copy link
Owner

Thanks, that was indeed a bug. I've updated the package. The next release is not yet due. To calculate the missing indices for now please install the current Github version.

@mej1d1
Copy link
Author

mej1d1 commented May 18, 2016

Ok, thanks. Where can I find the Github version ?

@bleutner
Copy link
Owner

here ;-)

https://github.com/bleutner/RStoolbox

@mej1d1
Copy link
Author

mej1d1 commented May 18, 2016

Awesome, thanks a lot!

@mej1d1 mej1d1 closed this as completed May 18, 2016
@mej1d1 mej1d1 reopened this May 18, 2016
@mej1d1 mej1d1 closed this as completed May 18, 2016
@mej1d1 mej1d1 reopened this May 18, 2016
@mej1d1
Copy link
Author

mej1d1 commented May 18, 2016

sorry to bother you again, but now (after installing the latest GitHub version) i get 19 indices instead of 20 (total number of indices is 22 according to the help file, so without the two EVI indices a total of 20 indices should be returned, right?).

@bleutner
Copy link
Owner

I guess you did not specify the coefficients swir2coc (completely open canopy) and swir2ccc (completely closed canopy) which are required in order to calculate NDVIC.
Some people simply use min and max values of the SWIR2 band and I could do this automatically, however this can be misleading if for example you have water bodies in your scene. Therefore, these must be specified manually by the user.

I probably should make this more clear in the documentation.

@mej1d1
Copy link
Author

mej1d1 commented May 19, 2016

ok, I understand. Thanks again for helping me out!

@mej1d1 mej1d1 closed this as completed May 19, 2016
@gtalckmin
Copy link

@bleutner :
is there a way I could add a vegetation index to the list of indices, without editing the C++ code within the package ?

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

3 participants