30 abr 2021

Working with Soilspec data (part 2)

 In the previous post we have seen the Reflectance spectra of the "datsoilspc" data set available at the Soilspec R package,  and we have remove the scatter using the SNV algorithm. More treatments are available to remove the scatter like the algorithm "Detrend", that normally it is used in combination with SNV. 

Detrend removes the trending lines that can be linear or quadratic, and are applyed to every spectra individually, so they are applyed to the rows of X matrix.

I use in this case the package "prospectr" like in other posts to convert the raw spectra to a new spectra with the combination of SNV and Detrend, so let´s use the function "detrend":

library(prospectr)
spectra_snvdt<- detrend(spectra, as.numeric(colnames(spectra)))
matplot(as.numeric(colnames(spectra_snvdt)), t(spectra_snvdt),
        type = "l", col = "blue", xlab = "wavelength",
        ylab = "Reflectance")

 

As we know, the band in the NIR region are very overlapped so it is common to apply derivative to see more clearly the bands, and we can start with the first derivative. The derivative are calculated by differences, so resolution of the peaks change depending of the gap and segment we use. We have to find a compromise between a good resolution without to much noise. So try different configuration to find the best option.

spectra_1d<-gapDer(spectra_snvdt,m=1,w=21,s=4)
matplot(as.numeric(colnames(spectra_1d)),t(spectra_1d) ,type="l",
        col = "blue", xlab = "wavelength",
        ylab = "Reflectance")


Now we can apply the second derivative that can be consider the same calculation than the first derivative, but in thi case for the previous spectra:

spectra_2d<-gapDer(spectra_snv,m=2,w=21,s=4)
matplot(as.numeric(colnames(spectra_2d)), t(spectra_2d) ,
        type="l", col = "blue",
        xlab = "wavelength",
        ylab = "Reflectance")


 


This spectra is giving quite a lot information that we will try to discover in coming posts.

No hay comentarios:

Publicar un comentario