Reduce the resolution of Spectra
reduce_resolution(x, ...) # S3 method for collection reduce_resolution(x, k, ...)
x | A |
---|---|
... | further arguments passed to or from other methods(not currently used). |
k | an integer expressing the reduction in resolution.
For example |
Reducing resolution of the spectra before computation intensive steps like AI binning can significantly improve their speed, while minimally affecting the output.
You should however be careful with the choice of k and in the caase of subsequent binning make sure to remove the outter limits of the returned results as these will not match the outter limits of the full resolution spectra.
library(tidySpectR) # Speeding up AI binning reduced <- reduce_resolution(fa_nmr, k=2) binned <- bucket_aibin(extract(reduced,0.5, 7.2), 0.5, mask(reduced, -Inf, 8)) breaks <- pull_breaks(binned) # last break does not match spectra limit, leaving it so would create # a bin at the ends of the spectra breaks[1]#> [1] 0.5039788#> [1] 7.203979#> [1] 0.4999788 7.2039788breaks <- breaks[-1] # remove first break breaks <- breaks[-length(breaks)] # remove last break processed <- bucket_from_breaks(extract(fa_nmr, 0.5, 7.2), breaks) # Full resolution bucketted spectra processed#> Spectra collection containing 6 entries. #> Number of bins: 80 #> Limits: 0.4999788 7.203979 #> Labels: conventional organic #> #> Processing: #> Step 1 / 2 : extract #> Step 2 / 2 : cutsom_bucketting