|
| 1 | + |
| 2 | +# VNIR Radiometer Data |
| 3 | + |
| 4 | +## Query from Environmental logger netCDF files |
| 5 | + |
| 6 | +These are used in the hyperspectral workflow. Let's look at the sky: |
| 7 | + |
| 8 | +```{r netcdf-met, eval=FALSE} |
| 9 | +library(ncdf4) |
| 10 | +library(udunits2) |
| 11 | +library(lubridate) |
| 12 | +
|
| 13 | +for(date in c('2016-06-21', '2016-09-21', '2016-12-21', '2017-03-21', '2017-05-21')){ |
| 14 | + |
| 15 | + directory <- file.path("/data/terraref/sites/ua-mac/Level_1/EnvironmentLogger", date) |
| 16 | + files <- dir(directory, full.names = TRUE) |
| 17 | + spectra_list <- lapply(files, function(x){ |
| 18 | + metnc <- nc_open(x) |
| 19 | + spc <- ncvar_get(metnc, 'flx_spc_dwn') |
| 20 | + datetime <- ymd("1970-01-01") + |
| 21 | + seconds(ud.convert(ncvar_get(metnc, 'time'), 'day', 's')) |
| 22 | + wvl <- ncvar_get(metnc, 'wvl_lgr') |
| 23 | + time <- hour(datetime) + |
| 24 | + minute(datetime)/60 + |
| 25 | + second(datetime)/3600 |
| 26 | + return(list(spc = spc, wvl = wvl, date = ymd(strftime(datetime, '%Y%m%d')), datetime = datetime)) |
| 27 | + |
| 28 | + }) |
| 29 | + |
| 30 | + spectra_df <- do.call('cbind',(lapply(spectra_list, '[[', 'spc') )) |
| 31 | + dim(spectra_df) |
| 32 | + |
| 33 | + time <- do.call('c',lapply(spectra_list,'[[','datetime')) |
| 34 | + wavelengths <- spectra_list[[1]]$wvl |
| 35 | + save(spectra_df, time, wavelengths, file = file.path('data', paste0("spectra",date,".Rdata"))) |
| 36 | + idx <- 1+0:700*24 |
| 37 | + i <- 1:length(hr)[!is.na(hr)] |
| 38 | + library(lubridate) |
| 39 | + hr <- hour(time) + minute(time)/60 + second(time)/3600 |
| 40 | + png(filename = paste0('data/spectra',date,'.png')) |
| 41 | + image(x = wavelengths, y = as.numeric(hr[idx]), spectra_df[,idx], |
| 42 | + ylab = 'hour of day', |
| 43 | + xlab = 'wavelength (nm)', |
| 44 | + col = cm.colors(n=100),zlim = c(-1,2.1), |
| 45 | + main = paste0('diurnal solar spectral radiation\n',date)) |
| 46 | + dev.off() |
| 47 | + |
| 48 | +} |
| 49 | +library(lubridate) |
| 50 | +library(data.table) |
| 51 | +library(udunits2) |
| 52 | +
|
| 53 | +time <- ncvar_get(metnc, 'time') |
| 54 | +
|
| 55 | +wavelengths <- ncvar_get(metnc, 'wvl_lgr') |
| 56 | +
|
| 57 | +f_down_spectrum <- ncvar_get(metnc, 'flx_spc_dwn') |
| 58 | +
|
| 59 | +library(ggplot2) |
| 60 | +
|
| 61 | +ggplot() + |
| 62 | + geom_point(aes(wavelengths, f_down_spectrum[,1])) + |
| 63 | + geom_line(aes(wavelengths, f_down_spectrum[,1])) |
| 64 | +
|
| 65 | +f_down_means <- rowMeans(f_down_spectrum) |
| 66 | +
|
| 67 | +ggplot() + |
| 68 | + geom_point(aes(wavelengths, f_down_means)) + |
| 69 | + geom_line(aes(wavelengths, f_down_means)) |
| 70 | +
|
| 71 | +print(metnc) |
| 72 | +
|
| 73 | +``` |
| 74 | + |
| 75 | +### Your turn: |
| 76 | + |
| 77 | +Can you see the effect of the August 21, 2017 solar eclipse on the diurnal spectral radiance? |
0 commit comments