Skip to content

Commit 80332ef

Browse files
author
Shawn P. Serbin
committed
Updated documentation. Created new convolve.spectra() function. Currently only works with AVIRIS data. A work in progress and needs updates to generalize the function for multiple sensors.
1 parent d9725a4 commit 80332ef

20 files changed

+205
-118
lines changed

DESCRIPTION

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,3 @@ License: FreeBSD + file LICENSE
2323
Copyright: Authors
2424
LazyLoad: yes
2525
LazyData: FALSE
26-
Collate:
27-
'import.asd.R'
28-
'read.asd.R'
29-
'spec.utils.R'
30-
'average.spec.R'
31-
'jump.correction.R'
32-
'average.spec.se.R'

FieldSpectra-manual.pdf

321 Bytes
Binary file not shown.

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
export(average.spec.se)
21
export(average.spec)
2+
export(average.spec.se)
33
export(concat.spectra)
4+
export(convolve.spectra)
45
export(extract.metadata)
56
export(import.asd)
67
export(jump.correction)

R/read.asd.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
##'
3131
##'@examples
3232
##' # Set input file
33-
##' file.dir <- system.file("extdata/PM01_TIAM_B_LC_REFL00005.asd",package="FieldSpec")
33+
##' file.dir <- system.file("extdata/PM01_TIAM_B_LC_REFL00005.asd",package="FieldSpectra")
3434
##' spec <- read.asd(file.dir,out.dir='~',start.wave=350,end.wave=2500,step.size=1)
3535
##'
3636
##' # Get info from file header

R/spec.utils.R

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ settings <- function(input.file=NULL){
7575
##'
7676
##' @examples
7777
##' # ASD
78-
##' file <- system.file("extdata/PM01_TIAM_B_LC_REFL00005.asd",package="FieldSpec")
78+
##' file <- system.file("extdata/PM01_TIAM_B_LC_REFL00005.asd",package="FieldSpectra")
7979
##' output <- extract.metadata(file,instrument="ASD")
8080
##'
8181
##' # Spectral Evolution
82-
##' file <- system.file("extdata/cvars_grape_leaf1_lc_rg_01236.sed",package="FieldSpec")
82+
##' file <- system.file("extdata/cvars_grape_leaf1_lc_rg_01236.sed",package="FieldSpectra")
8383
##' output <- extract.metadata(file,instrument="SE")
8484
##'
8585
##' @author Shawn P. Serbin
@@ -962,15 +962,85 @@ smooth.spectra <- function(file.dir=NULL,input.file=NULL,out.dir=NULL,out.filena
962962
#--------------------------------------------------------------------------------------------------#
963963
##'
964964
##' @name convolve.spectra
965-
##' @title Convolve field spectral observations to airborne/satellite spectral bands/channels
965+
##' @title Convolve field spectral observations to airborne/satellite spectral bands/channels.
966966
##'
967-
##' @param
967+
##' @param field.spectra Input field spectra. If a single spectra then the format can be either
968+
##' column or row major with the wavelengths either a column of data or the column headers. If
969+
##' multiple (i.e. a matrix of data) the input should be in row major format with the column headers
970+
##' as wavelength numbers. See examples below.
971+
##' @param start.wave Starting wavelength of field spectra
972+
##' @param end.wave ending wavelength of field spectra
973+
##' @param sensor The sensor (e.g. "AVIRIS", "Landsat 5", "Landsat 7", "MODIS"). Current options
974+
##' are: "AVIRIS" More to come in the future
975+
##' @param year [Optional] E.g. year=2011. If the AVIRIS sensor is selected this allows the user
976+
##' to select a specific spectral calibration based on the year of data aquisition.
977+
##' Defaults to 2011.
978+
##' @param spc [Optional] Option to use custom spectral calibration information. Format:
979+
##' band number, center wavelength, FWHM. NOT YET IMPLEMENTED
980+
##' @param output.dir [Optional] Directory to output the convolved spectral data. If not set
981+
##' the results are only pasesd back to the working environment
982+
##'
983+
##' @return output.spectra Returns a matrix of convolved spectra
984+
##'
985+
##' @export
968986
##'
969987
##' @author Shawn P. Serbin
970988
##'
971-
convolve.spectra <- function(spectra){
989+
convolve.spectra <- function(field.spectra=NULL,start.wave=NULL,end.wave=NULL,sensor=NULL,year=NULL,
990+
spc=NULL){
991+
992+
# Determine sensor type
993+
if (sensor=="AVIRIS"){
994+
if (is.null(year)) {
995+
sensor.file <- system.file("extdata/AVIRIS_2011_SPC_Info.csv",package="FieldSpectra")
996+
sensor.spc <- read.table(sensor.file,header=F, col.names = c('Band_Number','Wavelength','FWHM'),
997+
sep=",")
998+
} else {
999+
print("Not Implemented Yet")
1000+
} # End AVIRIS if/else
1001+
1002+
} else {
1003+
print(paste0(sensor,":"," Not Implemented Yet"))
1004+
} ## End main if/else
1005+
1006+
## Convert field spectra to matrix
1007+
field.spectra <- as.matrix(field.spectra)
1008+
# Temp
1009+
#field.spectra <- field.spectra[1,]
1010+
1011+
##
1012+
wvlArr <- as.array(sensor.spc[,2])
1013+
fwhArr <- as.array(sensor.spc[,3])
1014+
fs_wvArr <- as.array(seq(start.wave,end.wave,1))
1015+
keep <- which(round(wvlArr) %in% fs_wvArr,arr.ind=T)
1016+
wvlArr <- wvlArr[keep]
1017+
fwhArr <- fwhArr[keep]
1018+
convArr <- as.vector(rep(NA,1,length(fwhArr)))
1019+
output.spectra <- array(data=NA,dim=c(dim(field.spectra)[1],length(fwhArr)))
9721020

1021+
## Generic convolve function
1022+
for (i in 1:dim(field.spectra)[1]) {
1023+
for (band in 1:length(wvlArr)) {
1024+
#print(band)
1025+
### Create convolution kernel (from http://en.wikipedia.org/wiki/Gaussian_function)
1026+
convKern <- exp(-(fs_wvArr-wvlArr[band])^2/(2*(fwhArr[band]^2)))
1027+
### Normalize the kernel
1028+
convKern <- convKern/sum(convKern)
1029+
### Generate output band
1030+
convArr[band] <- sum(convKern*field.spectra[i,])
1031+
}
1032+
output.spectra[i,] <- convArr
1033+
} # End main for loop
1034+
output <- list(Wavelengths=wvlArr,Spectra=output.spectra)
1035+
invisible(output) # output convolved spectra
9731036
}
1037+
1038+
# for debugging
1039+
#plot(wvlArr,convArr,type="l")
1040+
#lines(seq(350,2500,1),unlist(field.spectra),type="l")
1041+
1042+
#plot(wvlArr,output.spectra[15,],type="l")
1043+
#lines(seq(350,2500,1),unlist(field.spectra[15,]),type="l")
9741044
#==================================================================================================#
9751045

9761046

inst/extdata/AVIRIS_2011_SPC_Info.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Band_Number,Wavelength,FWHM1,365.93,9.852112,375.594,9.796983,385.263,9.74414,394.935,9.693495,404.613,9.645146,414.295,9.599057,423.981,9.555228,433.671,9.513649,443.366,9.4743310,453.065,9.4372811,462.769,9.4024912,472.477,9.3699613,482.19,9.3396814,491.907,9.3116715,501.628,9.2859216,511.353,9.2624317,521.084,9.241218,530.818,9.2222219,540.557,9.2055120,550.3,9.1910621,560.048,9.1788722,569.8,9.1689423,579.556,9.1612624,589.317,9.1558525,599.082,9.152726,608.852,9.1518127,618.625,9.1531828,628.404,9.156829,638.187,9.1626930,647.974,9.1708431,657.765,9.1812532,667.561,9.1939233,655.792,9.9084734,665.599,9.8487135,675.401,9.7987136,685.198,9.7584837,694.989,9.7280238,704.776,9.7073239,714.557,9.696440,724.333,9.6952341,734.103,9.7038442,743.869,9.7222143,753.629,9.7503544,763.384,9.7882545,773.133,9.8359346,782.878,9.8933647,792.617,9.9605748,802.352,10.037549,812.081,10.124350,821.804,10.220851,831.523,10.327152,841.236,10.443153,850.944,10.568954,860.647,10.704555,870.345,10.849856,880.037,11.004957,889.724,11.169858,899.407,11.344459,909.083,11.528860,918.755,11.72361,928.421,11.92762,938.083,10.781563,947.739,9.761864,957.39,9.7600665,967.035,9.7593266,976.675,9.7595967,986.311,9.7608568,995.941,9.7631169,1005.57,9.7663770,1015.18,9.7706371,1024.8,9.775972,1034.41,9.7821673,1044.01,9.7894274,1053.61,9.7976975,1063.2,9.8069576,1072.79,9.8172277,1082.38,9.8284978,1091.95,9.8407579,1101.53,9.8540280,1111.09,9.8682981,1120.66,9.8835682,1130.21,9.8998383,1139.77,9.9170984,1149.31,9.9353685,1158.85,9.9546386,1168.39,9.9749187,1177.92,9.9961888,1187.45,10.018489,1196.97,10.041790,1206.48,10.06691,1215.99,10.091392,1225.5,10.117593,1235,10.144894,1244.49,10.173195,1253.98,10.202496,1263.46,10.232697,1253.37,10.838398,1263.35,10.832799,1273.32,10.8272100,1283.29,10.8219101,1293.26,10.8167102,1303.23,10.8117103,1313.21,10.8067104,1323.18,10.802105,1333.15,10.7973106,1343.12,10.7928107,1353.09,10.7885108,1363.06,10.7843109,1373.03,10.7802110,1383,10.7762111,1392.97,10.7724112,1402.94,10.7687113,1412.91,10.7652114,1422.88,10.7618115,1432.84,10.7585116,1442.81,10.7554117,1452.78,10.7524118,1462.75,10.7496119,1472.72,10.7469120,1482.69,10.7443121,1492.65,10.7419122,1502.62,10.7396123,1512.59,10.7374124,1522.55,10.7354125,1532.52,10.7335126,1542.48,10.7317127,1552.45,10.7301128,1562.42,10.7287129,1572.38,10.7273130,1582.35,10.7261131,1592.31,10.7251132,1602.28,10.7241133,1612.24,10.7233134,1622.2,10.7227135,1632.17,10.7222136,1642.13,10.7218137,1652.09,10.7216138,1662.06,10.7215139,1672.02,10.7215140,1681.98,10.7217141,1691.94,10.722142,1701.91,10.7225143,1711.87,10.7231144,1721.83,10.7238145,1731.79,10.7247146,1741.75,10.7256147,1751.71,10.7268148,1761.68,10.7281149,1771.64,10.7295150,1781.6,10.731151,1791.56,10.7327152,1801.52,10.7346153,1811.47,10.7365154,1821.43,10.7386155,1831.39,10.7409156,1841.35,10.7432157,1851.31,10.7457158,1861.27,10.7484159,1871.23,10.7512160,1872.38,10.7541161,1866.86,11.1666162,1876.93,11.1579163,1886.98,11.1489164,1897.04,11.1396165,1907.1,11.1299166,1917.15,11.1199167,1927.2,11.1096168,1937.25,11.099169,1947.29,11.0881170,1957.33,11.0769171,1967.38,11.0653172,1977.41,11.0534173,1987.45,11.0413174,1997.48,11.0288175,2007.52,11.0159176,2017.55,11.0028177,2027.57,10.9893178,2037.6,10.9755179,2047.62,10.9615180,2057.64,10.9471181,2067.66,10.9323182,2077.67,10.9173183,2087.69,10.9019184,2097.7,10.8863185,2107.7,10.8703186,2117.71,10.854187,2127.71,10.8373188,2137.72,10.8204189,2147.72,10.8031190,2157.71,10.7856191,2167.71,10.7677192,2177.7,10.7494193,2187.69,10.7309194,2197.68,10.7121195,2207.66,10.6929196,2217.65,10.6734197,2227.63,10.6537198,2237.6,10.6335199,2247.58,10.6131200,2257.55,10.5924201,2267.53,10.5713202,2277.5,10.5499203,2287.46,10.5282204,2297.43,10.5062205,2307.39,10.4839206,2317.35,10.4612207,2327.31,10.4383208,2337.26,10.415209,2347.22,10.3914210,2357.17,10.3675211,2367.11,10.3433212,2377.06,10.3187213,2387,10.2938214,2396.95,10.2687215,2406.89,10.2432216,2416.82,10.2174217,2426.76,10.1912218,2436.69,10.1648219,2446.62,10.138220,2456.55,10.1109221,2466.47,10.0835222,2476.4,10.0558223,2486.32,10.0278224,2496.24,9.99943
1+
1,365.93,9.852112,375.594,9.796983,385.263,9.74414,394.935,9.693495,404.613,9.645146,414.295,9.599057,423.981,9.555228,433.671,9.513649,443.366,9.4743310,453.065,9.4372811,462.769,9.4024912,472.477,9.3699613,482.19,9.3396814,491.907,9.3116715,501.628,9.2859216,511.353,9.2624317,521.084,9.241218,530.818,9.2222219,540.557,9.2055120,550.3,9.1910621,560.048,9.1788722,569.8,9.1689423,579.556,9.1612624,589.317,9.1558525,599.082,9.152726,608.852,9.1518127,618.625,9.1531828,628.404,9.156829,638.187,9.1626930,647.974,9.1708431,657.765,9.1812532,667.561,9.1939233,675.401,9.7987134,685.198,9.7584835,694.989,9.7280236,704.776,9.7073237,714.557,9.696438,724.333,9.6952339,734.103,9.7038440,743.869,9.7222141,753.629,9.7503542,763.384,9.7882543,773.133,9.8359344,782.878,9.8933645,792.617,9.9605746,802.352,10.037547,812.081,10.124348,821.804,10.220849,831.523,10.327150,841.236,10.443151,850.944,10.568952,860.647,10.704553,870.345,10.849854,880.037,11.004955,889.724,11.169856,899.407,11.344457,909.083,11.528858,918.755,11.72359,928.421,11.92760,938.083,10.781561,947.739,9.761862,957.39,9.7600663,967.035,9.7593264,976.675,9.7595965,986.311,9.7608566,995.941,9.7631167,1005.57,9.7663768,1015.18,9.7706369,1024.8,9.775970,1034.41,9.7821671,1044.01,9.7894272,1053.61,9.7976973,1063.2,9.8069574,1072.79,9.8172275,1082.38,9.8284976,1091.95,9.8407577,1101.53,9.8540278,1111.09,9.8682979,1120.66,9.8835680,1130.21,9.8998381,1139.77,9.9170982,1149.31,9.9353683,1158.85,9.9546384,1168.39,9.9749185,1177.92,9.9961886,1187.45,10.018487,1196.97,10.041788,1206.48,10.06689,1215.99,10.091390,1225.5,10.117591,1235,10.144892,1244.49,10.173193,1253.98,10.202494,1263.46,10.232695,1273.32,10.827296,1283.29,10.821997,1293.26,10.816798,1303.23,10.811799,1313.21,10.8067100,1323.18,10.802101,1333.15,10.7973102,1343.12,10.7928103,1353.09,10.7885104,1363.06,10.7843105,1373.03,10.7802106,1383,10.7762107,1392.97,10.7724108,1402.94,10.7687109,1412.91,10.7652110,1422.88,10.7618111,1432.84,10.7585112,1442.81,10.7554113,1452.78,10.7524114,1462.75,10.7496115,1472.72,10.7469116,1482.69,10.7443117,1492.65,10.7419118,1502.62,10.7396119,1512.59,10.7374120,1522.55,10.7354121,1532.52,10.7335122,1542.48,10.7317123,1552.45,10.7301124,1562.42,10.7287125,1572.38,10.7273126,1582.35,10.7261127,1592.31,10.7251128,1602.28,10.7241129,1612.24,10.7233130,1622.2,10.7227131,1632.17,10.7222132,1642.13,10.7218133,1652.09,10.7216134,1662.06,10.7215135,1672.02,10.7215136,1681.98,10.7217137,1691.94,10.722138,1701.91,10.7225139,1711.87,10.7231140,1721.83,10.7238141,1731.79,10.7247142,1741.75,10.7256143,1751.71,10.7268144,1761.68,10.7281145,1771.64,10.7295146,1781.6,10.731147,1791.56,10.7327148,1801.52,10.7346149,1811.47,10.7365150,1821.43,10.7386151,1831.39,10.7409152,1841.35,10.7432153,1851.31,10.7457154,1861.27,10.7484155,1871.23,10.7512156,1876.93,11.1579157,1886.98,11.1489158,1897.04,11.1396159,1907.1,11.1299160,1917.15,11.1199161,1927.2,11.1096162,1937.25,11.099163,1947.29,11.0881164,1957.33,11.0769165,1967.38,11.0653166,1977.41,11.0534167,1987.45,11.0413168,1997.48,11.0288169,2007.52,11.0159170,2017.55,11.0028171,2027.57,10.9893172,2037.6,10.9755173,2047.62,10.9615174,2057.64,10.9471175,2067.66,10.9323176,2077.67,10.9173177,2087.69,10.9019178,2097.7,10.8863179,2107.7,10.8703180,2117.71,10.854181,2127.71,10.8373182,2137.72,10.8204183,2147.72,10.8031184,2157.71,10.7856185,2167.71,10.7677186,2177.7,10.7494187,2187.69,10.7309188,2197.68,10.7121189,2207.66,10.6929190,2217.65,10.6734191,2227.63,10.6537192,2237.6,10.6335193,2247.58,10.6131194,2257.55,10.5924195,2267.53,10.5713196,2277.5,10.5499197,2287.46,10.5282198,2297.43,10.5062199,2307.39,10.4839200,2317.35,10.4612201,2327.31,10.4383202,2337.26,10.415203,2347.22,10.3914204,2357.17,10.3675205,2367.11,10.3433206,2377.06,10.3187207,2387,10.2938208,2396.95,10.2687209,2406.89,10.2432210,2416.82,10.2174211,2426.76,10.1912212,2436.69,10.1648213,2446.62,10.138214,2456.55,10.1109215,2466.47,10.0835216,2476.4,10.0558217,2486.32,10.0278218,2496.24,9.99943

inst/install.dependencies.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
list.of.packages <- c('XML','Hmisc','testthat','signal')
1+
list.of.packages <- c('XML','Hmisc','testthat','signal','Rcpp')
22

33
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
44
if(length(new.packages)) {

man/average.spec.Rd

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
\alias{average.spec}
33
\title{average replicate spectra within a directory of spectra files}
44
\usage{
5-
average.spec(file.dir = NULL, out.dir = NULL,
6-
start.wave = NULL, end.wave = NULL, step.size = NULL,
7-
bias.threshold = NULL, suffix.length = NULL,
8-
output.file.ext = NULL, metadata.file = NULL,
9-
image = FALSE, settings.file = NULL)
5+
average.spec(file.dir = NULL, out.dir = NULL, start.wave = NULL,
6+
end.wave = NULL, step.size = NULL, bias.threshold = NULL,
7+
suffix.length = NULL, output.file.ext = NULL, metadata.file = NULL,
8+
image = FALSE, settings.file = NULL)
109
}
1110
\arguments{
1211
\item{file.dir}{Directory of spectra files to process}
@@ -59,8 +58,8 @@
5958
function call.}
6059
}
6160
\description{
62-
Function to average replicate spectra within a directory
63-
of spectra files
61+
Function to average replicate spectra within a directory of
62+
spectra files
6463
}
6564
\examples{
6665
\dontrun{
@@ -70,6 +69,6 @@ suffix.length=5,output.file.ext=".csv",spec.dataframe = TRUE,)
7069
}
7170
}
7271
\author{
73-
Shawn P. Serbin
72+
Shawn P. Serbin
7473
}
7574

man/average.spec.se.Rd

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
\alias{average.spec.se}
33
\title{average replicate spectra within a directory of spectra files}
44
\usage{
5-
average.spec.se(file.dir = NULL, out.dir = NULL,
6-
spec.type = NULL, spec.file.ext = NULL,
7-
start.wave = NULL, end.wave = NULL, step.size = NULL,
8-
bias.threshold = NULL, suffix.length = NULL,
9-
output.file.ext = NULL, settings.file = NULL)
5+
average.spec.se(file.dir = NULL, out.dir = NULL, spec.type = NULL,
6+
spec.file.ext = NULL, start.wave = NULL, end.wave = NULL,
7+
step.size = NULL, bias.threshold = NULL, suffix.length = NULL,
8+
output.file.ext = NULL, settings.file = NULL)
109
}
1110
\arguments{
1211
\item{file.dir}{directory of spectra files to process}
@@ -52,10 +51,10 @@
5251
function call.}
5352
}
5453
\description{
55-
Function to average replicate spectra within a directory
56-
of spectra files
54+
Function to average replicate spectra within a directory of
55+
spectra files
5756
}
5857
\author{
59-
Shawn P. Serbin
58+
Shawn P. Serbin
6059
}
6160

man/concat.spectra.Rd

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
\title{Concatenate a directory of spectra files into a single .csv file. Works on a single
44
directory or a series of directories}
55
\usage{
6-
concat.spectra(file.dir = NULL, out.dir = NULL,
7-
out.filename = NULL, in.file.ext = ".csv",
8-
out.file.ext = ".csv", transpose = FALSE,
9-
spec.dataframe = FALSE)
6+
concat.spectra(file.dir = NULL, out.dir = NULL, out.filename = NULL,
7+
in.file.ext = ".csv", out.file.ext = ".csv", transpose = FALSE,
8+
spec.dataframe = FALSE)
109
}
1110
\arguments{
1211
\item{file.dir}{directory of spectra files to process.
@@ -35,9 +34,7 @@ directory or a series of directories}
3534
containing the concatenated spectral data. TRUE/FALSE}
3635
}
3736
\description{
38-
Concatenate a directory of spectra files into a single
39-
.csv file. Works on a single directory or a series of
40-
directories
37+
4138
}
4239
\examples{
4340
\dontrun{
@@ -47,6 +44,6 @@ out.file.ext=".csv",transpose=FALSE,spec.dataframe=FALSE)
4744
}
4845
}
4946
\author{
50-
Shawn P. Serbin
47+
Shawn P. Serbin
5148
}
5249

0 commit comments

Comments
 (0)