[R-sig-Geo] chull function behavior

Lukas Lehnert lukaslehnert at googlemail.com
Thu Dec 13 16:51:44 CET 2012


Dear Carsten,

the function chull finds the hull of a curve, which consists of the upper and 
the lower part of the hull. In your case, you might be only interested in the 
upper part. You can extract this with the following commands:
    c.hull <- chull(y)
    c.hull <- c.hull[(which(c.hull == 1):length(c.hull))]
    c.hull <- sort(c.hull)

The calculation of the hull can be performed by:
    hull[i,] <- approx(x=x[c.hull],y=y[i,c.hull], xout = x,method = "linear", 
ties = "mean")$y

Best regards

Lukas Lehnert

Am Donnerstag, 13. Dezember 2012, 16:38:43 schrieb Carsten Neumann:
> Dear List members,
> 
> sorry for the non specific geo question, but working with image spectra
> led me to the following problem calculating a convex upper hull curve
> using the function "chull {grDevices}".
> 
> Imaging there is a image spectra that you need to normalize using
> continuum removal (deviding spectra by upper hull), then you do not
> expect values greater than 1. Unfortunately the "chull()" functions did
> not identify all points of intersection on a hull curve. At the
> beginning there are also points beneath a hull, see example data (first
> 3 points).
> 
> ############################################################################
> ################################# wavelength<-seq(350,449,1)
> dummy<-c(0.204054, 0.204828, 0.204161, 0.202444, 0.199883, 0.200960,
> 0.203838, 0.205723,
>   0.203404, 0.204835, 0.207257, 0.205682, 0.209670, 0.212622, 0.212032,
> 0.211062,
>   0.212727, 0.215129, 0.216259, 0.217435, 0.218270, 0.219039, 0.220333,
> 0.222520,
>   0.223502, 0.223225, 0.225050, 0.225485, 0.226832, 0.230962, 0.231891,
> 0.231264,
>   0.231170, 0.233540, 0.235799, 0.238165, 0.240494, 0.240793, 0.242218,
> 0.244078,
>   0.244795, 0.246343, 0.247142, 0.247406, 0.249348, 0.250772, 0.251937,
> 0.253166,
>   0.253301, 0.253941, 0.255231, 0.256503, 0.257881, 0.258632, 0.258916,
> 0.260414,
>   0.261584, 0.262598, 0.263891, 0.264702, 0.265681, 0.266892, 0.267861,
> 0.268923,
>   0.270050, 0.271112, 0.271767, 0.273130, 0.274604, 0.275065, 0.276157,
> 0.277331,
>   0.278321, 0.279585, 0.280577, 0.281469, 0.282497, 0.283157, 0.284381,
> 0.285984,
>   0.286866, 0.288173, 0.289387, 0.290084, 0.290770, 0.291659, 0.292730,
> 0.293823,
>   0.294841, 0.295763, 0.296607, 0.297420, 0.298529, 0.299691, 0.300580,
> 0.301300,
>   0.302290, 0.303378, 0.303885, 0.304686)
> 
> id<-sort(chull(wavelength, dummy))
> plot(wavelength,dummy,type="l")
> points(wavelength[id],dummy[id],type="p",col="red")
> ############################################################################
> ################################# Can anybody explain this behavior or give
> some advice on improving functionality?
> 
> Thanks in advance!
> 
> Best
> 
> Carsten



More information about the R-sig-Geo mailing list