@@ -10,10 +10,45 @@ library(ncdf4)
1010library(udunits2)
1111library(lubridate)
1212
13+ get_spectra <- function(date, site = 'ua-mac'){
14+
15+
16+ envlog_file <- file.path("/data/terraref/sites", site, "Level_1/envlog_netcdf", date,
17+ paste0("envlog_netcdf_L1_", site, "_", date, ".nc"))
18+ envlog.nc <- nc_open(envlog_file, readunlim = FALSE)
19+ timepoints <- ud.convert(4*1:5, 'h', '5s')
20+
21+ flx_spc_dwn <- ncvar_get(envlog.nc, 'flx_spc_dwn')[,timepoints]
22+ datetime <- ymd("1970-01-01", tz ="America/Phoenix") +
23+ seconds(ud.convert(ncvar_get(envlog.nc, 'time'), 'day', 's'))
24+ datetime[timepoints]
25+
26+ z <- as.data.frame(flx_spc_dwn)
27+ colnames(z) <- datetime[timepoints]
28+
29+ wvl <- ncvar_get(envlog.nc, 'wvl_lgr')
30+ wvl.idx <- sapply(c(34:81*10),
31+ function(x) which.min(abs(x-wvl)))
32+ zz <- z[wvl.idx,]
33+ rownames(zz) <- round(wvl[wvl.idx])
34+ return(t(zz))
35+ write(zz, file = paste0('tmp/',date, '.csv'))
36+ }
37+
38+
39+ dates <- seq(ymd('2017-04-15'), ymd('2017-11-12'), by = '10 days')
40+ all_spectra <- lapply(as.character(dates), get_spectra)
41+ spectra.df <- lapply(all_spectra, as.data.frame)
42+ zzz <- do.call(rbind, unname(spectra.df))
43+ write.csv(zzz, '~/tmp/spectra.csv')
44+ return(list(spc = spc, wvl = wvl, date = ymd(strftime(datetime, '%Y%m%d')), datetime = datetime))
45+
46+
47+
1348for(date in c('2016-06-21', '2016-09-21', '2016-12-21', '2017-03-21', '2017-05-21')){
1449
15- directory <- file.path("/data/terraref/sites/ua-mac/Level_1/EnvironmentLogger ", date)
16- files <- dir(directory, full.names = TRUE)
50+ directory <- file.path("/data/terraref/sites/ua-mac/Level_1/envlog_netcdf/ ", date)
51+ files <- dir(directory, full.names = TRUE)
1752 spectra_list <- lapply(files, function(x){
1853 metnc <- nc_open(x)
1954 spc <- ncvar_get(metnc, 'flx_spc_dwn')
0 commit comments