Skip to content

Commit a54c7eb

Browse files
Merge pull request #224 from KristinaRiemer/convert_timezones
Add time zone conversion and accompanying notes to all website tutorials
2 parents f6fc4c5 + 523b8d2 commit a54c7eb

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

sensors/01-meteorological-data.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ end of the time period from the stream.
185185

186186
```{r met-datapoints2}
187187
weather_data <- weather_all$properties %>%
188-
mutate(time = ymd_hms(weather_all$end_time))
188+
mutate(time = with_tz(ymd_hms(weather_all$end_time), "America/Phoenix"))
189189
```
190190

191191
## Weather Plots

traits/03-access-r-traits.Rmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ library(traits)
2727
library(ggplot2)
2828
library(ggthemes)
2929
library(dplyr)
30+
library(lubridate)
3031
```
3132

3233
```{r}
@@ -94,18 +95,18 @@ canopy_height <- betydb_query(table = 'search',
9495
limit = 'none')
9596
```
9697

97-
First let's fix the `raw_date` column so that it is represented as a actual date object using `lubridate::ymd_hms`.
98+
First let's fix the `raw_date` column so that it is represented as an actual date object using `lubridate::ymd_hms`. It is also converted to the correct time zone with `with_tz`, another `lubridate` function.
9899

99100
```{r}
100101
canopy_height <- canopy_height %>%
101-
mutate(raw_date = ymd_hms(raw_date))
102+
mutate(trans_date = with_tz(ymd_hms(raw_date), "America/Phoenix"))
102103
```
103104

104105

105106
```{r plot_height}
106107
107108
ggplot(data = canopy_height,
108-
aes(x = raw_date, y = mean)) +
109+
aes(x = trans_date, y = mean)) +
109110
geom_point(size = 0.5, position = position_jitter(width = 0.1)) +
110111
xlab("Date") + ylab("Plant Height") +
111112
guides(color = guide_legend(title = 'Genotype')) +

vignettes/01-get-trait-data-R.Rmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ season_4 <- betydb_query(sitename = "~Season 4",
5959

6060
The return value for the `betydb_query` function is just a `data.frame` so we can work with it like any other `data.frame` in R.
6161

62-
Let's plot a time series of all traits returned. First you might notice that the relevant date columns in the `season_4` data.frame are returned as characters instead of a date format. Before plotting, let's get our `raw_date` column into a proper date format using functions from `dplyr` and `lubridate`.
62+
Let's plot a time series of all traits returned. First you might notice that the relevant date columns in the `season_4` data.frame are returned as characters instead of a date format. Before plotting, let's get our `raw_date` column into a proper date format and time zone using functions from `dplyr` and `lubridate`.
6363

6464

6565
```{r traits-vig-s4-summary-reformat-date, message = FALSE}
6666
season_4 <- season_4 %>%
67-
mutate(raw_date = ymd_hms(raw_date))
67+
mutate(trans_date = with_tz(ymd_hms(raw_date), "America/Phoenix"))
6868
```
6969

7070
### Plot season 4 summary
@@ -73,8 +73,8 @@ Now we can create a plot of all of the trait data collected during season 4, inc
7373

7474
```{r traits-vig-s4-summary-plot-data, fig.height = 15, fig.width = 7}
7575
ggplot(data = season_4) +
76-
geom_point(aes(x = raw_date, y = mean, color = method_name), shape = '.') +
77-
geom_line(aes(x = raw_date, y = mean, group = cultivar, color = method_name)) +
76+
geom_point(aes(x = trans_date, y = mean, color = method_name), shape = '.') +
77+
geom_line(aes(x = trans_date, y = mean, group = cultivar, color = method_name)) +
7878
facet_wrap(~trait, ncol = 4, scales = "free_y") +
7979
xlab("Date") +
8080
ylab("Mean trait value") +
@@ -116,7 +116,7 @@ As before, we need to reformat the raw date column.
116116

117117
```{r traits-vig-fix-date}
118118
canopy_height <- canopy_height %>%
119-
mutate(raw_date = ymd_hms(raw_date))
119+
mutate(trans_date = with_tz(ymd_hms(raw_date), "America/Phoenix"))
120120
```
121121

122122
And we can generate a time series plot of just the canopy height data.
@@ -125,7 +125,7 @@ And we can generate a time series plot of just the canopy height data.
125125
126126
#plot a time series of canopy height
127127
ggplot(data = canopy_height,
128-
aes(x = raw_date, y = mean)) +
128+
aes(x = trans_date, y = mean)) +
129129
geom_point(size = 0.5, position = position_jitter(width = 0.1)) +
130130
xlab("Date") +
131131
ylab("Plant height (cm)") +

vignettes/02-get-weather-data-R.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ weather_all <- fromJSON('https://terraref.ncsa.illinois.edu/clowder/api/geostrea
2626
```
2727

2828
The `geometries` dataframe is then pulled out from these data, which contains the datapoints from this stream.
29-
This is combined with a transformed version of the end of the time period from the stream.
29+
This is combined with a transformed version of the end of the time period in the correct time zone from the stream.
3030

3131
```{r met-datapoints}
3232
weather_data <- weather_all$properties %>%
33-
mutate(time = ymd_hms(weather_all$end_time))
33+
mutate(time = with_tz(ymd_hms(weather_all$end_time), "America/Phoenix"))
3434
```
3535

3636
The temperature data, which is five minute averages for the entire month of January 2017, is used to calculate the growing degree days for each day.

vignettes/04-synthesis-data.Rmd

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ trait_canopy_cover <- betydb_query(table = "search",
3232
date = "~2018",
3333
limit = "none")
3434
trait_canopy_cover_day = trait_canopy_cover %>%
35-
mutate(day = as.Date(raw_date))
35+
mutate(trans_date = with_tz(ymd_hms(raw_date), "America/Phoenix"),
36+
day = as.Date(raw_date))
3637
```
3738

3839
```{r get_weather_data}
3940
weather <- fromJSON('https://terraref.ncsa.illinois.edu/clowder/api/geostreams/datapoints?stream_id=46431&since=2018-01-01&until=2018-12-31', flatten = FALSE)
4041
weather <- weather$properties %>%
41-
mutate(time = ymd_hms(weather$end_time))
42+
mutate(time = with_tz(ymd_hms(weather$end_time), "America/Phoenix"))
4243
daily_values = weather %>%
4344
mutate(day = as.Date(time),
4445
air_temp_converted = air_temperature - 273.15) %>%
@@ -256,7 +257,8 @@ trait_canopy_cover <- betydb_query(table = "search",
256257
limit = "none")
257258
258259
trait_canopy_cover_day <- trait_canopy_cover %>%
259-
mutate(day = as.Date(raw_date))
260+
mutate(trans_date = with_tz(ymd_hms(raw_date), "America/Phoenix"),
261+
day = as.Date(raw_date))
260262
```
261263

262264
We now need to add the height data to the data set to plot.

0 commit comments

Comments
 (0)