|
| 1 | +--- |
| 2 | +title: "Solar Radiance" |
| 3 | +author: "David LeBauer" |
| 4 | +date: "March 9, 2018" |
| 5 | +output: html_document |
| 6 | +--- |
| 7 | + |
1 | 8 |
|
2 | 9 | # VNIR Radiometer Data |
3 | 10 |
|
| 11 | +An Ocean Optics STS Spectrometer measures downwelling solar spectral radiance every 5s on top of the Gantry. |
| 12 | + |
| 13 | +Lets look at the output from this sensor over the course of the day (and then we will see how to acces the data): |
| 14 | + |
| 15 | +```{r one-downwelling-spectra} |
| 16 | +library(tidyverse) |
| 17 | +library(ggridges) |
| 18 | +load('data/spectra.RData') |
| 19 | +
|
| 20 | +s <- spectra_long %>% |
| 21 | + mutate(hour = hour, |
| 22 | + radiance = radiance - min(radiance)) %>% |
| 23 | + arrange(hour, wavelength) |
| 24 | + # subset for faster exploration: %>% slice(1:(24*64)*16) |
| 25 | +
|
| 26 | +ggplot(data = s, aes(x = wavelength, y = hour, group = hour, |
| 27 | + height = radiance )) + |
| 28 | + geom_density_ridges(stat = 'identity', scale = 6, size = 0.25, alpha = 0.7, color = 'white') + |
| 29 | + theme_ridges(grid = FALSE, center_axis_labels = TRUE) + |
| 30 | + scale_y_continuous(trans = 'reverse') + |
| 31 | + ggtitle("Downwelling Spectral Radiance", |
| 32 | + subtitle = "hourly spectra from April 15, 2017") |
| 33 | +
|
| 34 | +# Fun Challenge: implement wavelength --> color mapping |
| 35 | +#scale_color_gradientn( |
| 36 | +# colors = c('white', 'purple', 'blue', 'cyan', 'green', 'yellow', 'orange', 'red', #'black'), |
| 37 | +# values = c(300, 420, 570, 530, 580, 620, 700, 800)) |
| 38 | +
|
| 39 | +``` |
| 40 | + |
4 | 41 | ## Query from Environmental logger netCDF files |
5 | 42 |
|
6 | | -These are used in the hyperspectral workflow. Let's look at the sky: |
| 43 | +There are 20 observations of 1024 individual wavelengths_per minute_ = `r 20 * 60 * 24 * 1024` data points per day. We convert these data to CF standards and store them in netCDF file formats. |
7 | 44 |
|
8 | | -```{r netcdf-met, eval=FALSE} |
| 45 | +These are used in the hyperspectral workflow. |
| 46 | + |
| 47 | +Let's take a look at one of these files: |
| 48 | + |
| 49 | +```{r netcdf-metadata} |
| 50 | +library(tidyverse) |
9 | 51 | library(ncdf4) |
10 | 52 | library(udunits2) |
11 | 53 | library(lubridate) |
| 54 | +if(!require(tidync)){ |
| 55 | + devtools::install_github('hypertidy/ncmeta') |
| 56 | + devtools::install_github('hypertidy/tidync') |
| 57 | +} |
| 58 | +
|
| 59 | +library(ncmeta) |
| 60 | +library(tidync) |
| 61 | +
|
| 62 | +envlog_file <- "/data/terraref/sites/ua-mac/Level_1/envlog_netcdf/2017-08-21/envlog_netcdf_L1_ua-mac_2017-08-21.nc" |
| 63 | +envlog.nc <- nc_open(envlog_file, readunlim = TRUE) |
12 | 64 |
|
| 65 | +time <- envlog.nc$dim$time$vals |
| 66 | +wvl <- envlog.nc$dim$wvl_lgr$vals |
| 67 | +
|
| 68 | +metadata <- envlog.nc$var %>% bind_cols() |
| 69 | +
|
| 70 | +#flx_dwn <- ncvar_get(envlog.nc, ') |
| 71 | +
|
| 72 | +#if(!require(ncdf4.helpers)) install.packages("ncdf4.helpers") |
| 73 | +#ts <- ncdf4.helpers::nc.get.time.series(envlog.nc) |
| 74 | +s <- tidync::tidync(envlog_file) |
| 75 | + |
| 76 | + |
| 77 | +nc_metadata <- ncmeta::nc_meta(envlog_file) |
| 78 | +
|
| 79 | +nc_metadata$variable %>% |
| 80 | + select(name, longname, units, ndims) %>% |
| 81 | + filter(!grepl('raw', name)) %>% |
| 82 | + knitr::kable() |
| 83 | +``` |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +Now lets query the Downwelling Spectral Irradiance (flx_spc_dwn) from this file: |
| 88 | + |
| 89 | +```{r} |
| 90 | +
|
| 91 | +library(tidync) |
| 92 | +flx_spc_dwn <- ncvar_get(envlog.nc, 'flx_spc_dwn', ) |
| 93 | +time <- ncvar_get(envlog.nc, 'time') |
| 94 | +dim(flx_spc_dwn) |
| 95 | +
|
| 96 | +if(!require(rasterVis)) install.packages("rasterVis") |
| 97 | +
|
| 98 | +library(rasterVis) |
| 99 | +gplot(flx_spc_dwn) + |
| 100 | + geom_tile(aes(fill = value)) |
| 101 | + |
| 102 | +``` |
| 103 | + |
| 104 | + |
| 105 | +```{r} |
| 106 | +time = flx_spc_dwn$ radiance = as.vector(flx_spc_dwn) |
13 | 107 | get_spectra <- function(date, site = 'ua-mac'){ |
14 | 108 | |
15 | 109 | |
@@ -118,6 +212,7 @@ Here we can found the original data written by the sensor. Unlike above, these a |
118 | 212 | ```{r raw-met, cache=TRUE} |
119 | 213 | metfile <- "/data/terraref/sites/ua-mac/raw_data/EnvironmentLogger/2017-05-31/2017-05-31_12-19-38_environmentlogger.json" |
120 | 214 | met <- jsonlite::fromJSON(metfile) |
| 215 | +writeLines(jsonlite::toJSON(met), con = file('foo.json')) |
121 | 216 |
|
122 | 217 | timestamp <- lubridate::ymd_hms(met$environment_sensor_readings$timestamp) |
123 | 218 |
|
|
0 commit comments