Skip to content

Commit

Permalink
harmonizing wsim lesson 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrinks committed Jan 10, 2024
1 parent bae2f58 commit d47fbd6
Show file tree
Hide file tree
Showing 3 changed files with 736 additions and 224 deletions.
22 changes: 20 additions & 2 deletions docs/wsim-gldas-acquisition.html

Large diffs are not rendered by default.

810 changes: 639 additions & 171 deletions docs/wsim-gldas-vis.html

Large diffs are not rendered by default.

128 changes: 77 additions & 51 deletions wsim-gldas-vis.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "WSIM-GLDAS Dataset Exploration and Visualizations"
author: "Joshua Brinks"
author: "Joshua Brinks & Elaine Fatumi"
date: "December, 6 2023"
---

Expand All @@ -24,65 +24,103 @@ date: "December, 6 2023"

## Setup

```r
library(stars) # raster manipulation
library(sf) # vector manipulation
library(ggplot2) # advanced plotting
library(lubridate) # date/time manipulation
library(exactextractr) # zonal statistics

```

## Load Data

Load in data from previous vignette.

I think the previous vignette should end with a 2000-2014 12-month integration CONUS dataset.
We'll start again with the WSIM-GLDAS 12 month integration anomaly file and quickly subset it to the continental United States.

```{r warning=FALSE}
#| code-fold: true
wsim_gldas <- stars::read_stars("composite_anom_12mo.nc", proxy = FALSE)
keeps<-seq(lubridate::ymd("2000-12-01"),
lubridate::ymd("2014-12-01"),
by = "year")
# filter using that vector
wsim_gldas <- dplyr::filter(wsim_gldas, time %in% keeps)
# you may want to clear your memory if your system is limited
gc()
wsim_deficit <- wsim_gldas['deficit']
# generate a vector of dates for subsetting
usa <- httr::GET("https://www.geoboundaries.org/api/current/gbOpen/USA/ADM1/")
usa <- httr::content(usa)
usa <- sf::st_read(usa$gjDownloadURL)
drops<-
c("Alaska", "Hawaii",
"American Samoa",
"Puerto Rico",
"Commonwealth of the Northern Mariana Islands",
"Guam",
"United States Virgin Islands")
usa<-usa[!(usa$shapeName %in% drops),]
wsim_deficit_usa<-wsim_deficit[usa]
```

```r
Now we'll verify this with `print()` and `plot()`.

```{r}
print(wsim_deficit_usa)
```
The output shows that we've selected a single attribute ('deficit') and 15 time-steps in the 'time' dimension.

```{r warning=FALSE, message=FALSE}
wsim_deficit_usa |>
dplyr::slice(index = 15, along = "time") |>
plot(reset = FALSE, breaks = c(0,-5,-10,-20,-40,-50))
plot(sf::st_geometry(usa),
add = TRUE,
lwd = 3,
fill = NA,
border = 'purple')
```

Verify data structure with `print` or `summary.`

## Exploratory Histogram

Create histogram of raster values for a single time step.

Basic plotting method is OK, but check if it can be done with `ggplot`so we can use a uniform palette across all modules.
Get the values out of the raster and create a histogram.

```r
```{r}
# filter for the first time-step in the file
usa1 <-
wsim_deficit_usa |> dplyr::slice(time, 1)
# extract the values into a data.frame
usa1<-as.data.frame(as.numeric(wsim_deficit_usa$deficit))
# appropriately name the values (it was lost in the example)
names(usa1)<-"Deficit"
```

Extreme values or other items of note might require additional visualization or other data exploration.

## Multi-Panel Time Series

Create a multipanel time series of 12 month integration CONUSA; similar to what we used to identify our case studies. Each panel will represent 1 year.

Load in a CONUSA geojson from geoBoundaries. Copy methods from previous vignette.

```r
Check the values

```{r}
ggplot2::ggplot(usa1, ggplot2::aes(Deficit))+
ggplot2::geom_histogram(na.rm = TRUE)
```
There are some bad outliers, we can just zoom into the majority of values by setting x-axis limits.


Start with the basic plotting commands--create the time series with `slice` or other method used in previous vignette.

```r

```{r}
ggplot2::ggplot(usa1, ggplot2::aes(Deficit))+
ggplot2::geom_histogram(na.rm = TRUE)+
ggplot2::xlim(c(-10,0))
```

The palette will not exist and be difficult to use.
Extreme values or other items of note might require additional visualization or other data exploration.

Try a built in palette for stars (not sure if possible?).
## Multi-Panel Time Series

Introduce the official WSIM palette. This may only be helpful within a `ggplot` function.
Create a multipanel time series of 12 month integration CONUSA; similar to what we used to identify our case studies. Each panel will represent 1 year.**

```r
# numbers are return period values for a composite surplus (blues) and deficit (reds) dataset
leg_colors<-c(
Load in a CONUSA geojson from geoBoundaries. Copy methods from previous vignette.

```{r warning = FALSE}
wsim_deficit_usa |>
plot(reset = FALSE,
col = leg_colors<-c(
'#9B0039',
# -50 to -40
'#D44135',
Expand All @@ -93,25 +131,17 @@ leg_colors<-c(
# -10 to -5
'#FFEDA3',
# -5 to -3
'#FFFFFF',
# -3 to 3
'#CEFFAD',
# 3 to 5
'#00F3B5',
# 5 to 10
'#00CFCE',
# 10 to 20
'#009ADE',
# 20 to 40
'#0045B5')
'#FFFFFF'))
```

Once hot spots are easily identified pick a region of interest to zoom in on using the 1 month integration dataset.

Load in the 1 month integration dataset and subset/index the dataset to the region of interest (copy code from previous vignette). Use `dplyr::slice` or other method to pull out just the 12 months from the year of interest. Code demonstrating these techniques in previous vignette.

```r
```{r}
wsim_gldas_1mo <- stars::read_stars("composite_anom_1mo.nc", proxy = FALSE)
print(wsim_gldas_1mo)
```

Create a multi-panel figure with each panel representing 1 month to identify the most intense months of drought or flooding. Starting with this one maybe use `ggplot` and a nice palette, legend, and panel headings. Will probably have to use some sort of faceting to make individual panels (might not be possible).
Expand All @@ -120,10 +150,6 @@ Create a multi-panel figure with each panel representing 1 month to identify the

```

## Use Case Background

Now that we've keyed in on a particular event, bring in the backup information we've collected to discuss what actually happened.

## Point Location Time Series

Visualize an individual cell with particular extreme or maybe volatile values. Use Google Maps to identify the latitude/longitude of a place of interest. Maybe an urban center or other important location in the region that suffered from the extreme event.
Expand Down

0 comments on commit d47fbd6

Please sign in to comment.