Skip to content

Commit e275d37

Browse files
committed
updated sql access and radiometer tutorials
1 parent 723460b commit e275d37

2 files changed

Lines changed: 127 additions & 5 deletions

File tree

sensors/09-vnir-radiometer.Rmd

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,109 @@
1+
---
2+
title: "Solar Radiance"
3+
author: "David LeBauer"
4+
date: "March 9, 2018"
5+
output: html_document
6+
---
7+
18

29
# VNIR Radiometer Data
310

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+
441
## Query from Environmental logger netCDF files
542

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.
744

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)
951
library(ncdf4)
1052
library(udunits2)
1153
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)
1264
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)
13107
get_spectra <- function(date, site = 'ua-mac'){
14108
15109
@@ -118,6 +212,7 @@ Here we can found the original data written by the sensor. Unlike above, these a
118212
```{r raw-met, cache=TRUE}
119213
metfile <- "/data/terraref/sites/ua-mac/raw_data/EnvironmentLogger/2017-05-31/2017-05-31_12-19-38_environmentlogger.json"
120214
met <- jsonlite::fromJSON(metfile)
215+
writeLines(jsonlite::toJSON(met), con = file('foo.json'))
121216
122217
timestamp <- lubridate::ymd_hms(met$environment_sensor_readings$timestamp)
123218

traits/07-betydb-sql-access.Rmd

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,40 @@ date: "`r Sys.Date()`"
55
output: html_document
66
---
77

8-
## On the workbench:
8+
99

1010
will be derived from https://github.com/pi4-uiuc/2017-bootcamp/blob/master/content/post/2017-05-30-databases-and-sql.Rmd#with
1111

12-
## Installing the database locally
12+
# On workbench
13+
14+
On the TERRA REF Workbench, you have access to the database. These connnections will only work if you are on the workbench.
15+
16+
17+
## Using PostgresSQL Studio
18+
19+
20+
Lets connect to the terraref instance of betydb. Until now we have been accessing betydb.org. Now we will access (a copy of) the database behind `terraref.ncsa.illinois.edu/bety`
21+
22+
This connection is only available on the local *ncsa.illinois.edu network, and can be accessed through the NDS Labs workbench.
23+
24+
```
25+
Host: bety.terraref
26+
Port: 5432
27+
User: bety
28+
Password: bety
29+
DB: bety
30+
```
31+
32+
```
33+
Host: bety6.ncsa.illinois.edu
34+
Port: 5432
35+
User: viewer
36+
Password: DelchevskoOro
37+
DB: bety
38+
```
39+
40+
# Installing the database locally
1341

14-
This is truly an easter egg:
1542

1643
You can run the entire database locally, with daily imports:
1744

0 commit comments

Comments
 (0)