Skip to content

Commit

Permalink
wsim lesson 1 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrinks committed Jan 10, 2024
1 parent 7527a18 commit bae2f58
Show file tree
Hide file tree
Showing 2 changed files with 510 additions and 160 deletions.
642 changes: 496 additions & 146 deletions docs/wsim-gldas-acquisition.html

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions wsim-gldas-acquisition.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Once you've completed the download and placed the .nc into your working director
# proxy = TRUE will limit memory useage but does
# not always work with certain downstream processing functions
wsim_gldas_anoms <- stars::read_stars("composite_anom_1mo.nc", proxy = FALSE)
wsim_gldas_anoms <- stars::read_stars("composite_anom_12mo.nc", proxy = FALSE)
print(wsim_gldas_anoms)
```
Expand All @@ -41,35 +41,35 @@ This means the total number of individual raster layers in this NetCDF is 4020 (

## Attribute Selection

We can start paring this down by subsetting for just the combined surplus/deficit anomaly (both).
We can start paring this down by subsetting for just deficits (drought).

```{r}
names(wsim_gldas_anoms)
wsim_gldas_anoms <- wsim_gldas_anoms['both']
wsim_gldas_anoms <- wsim_gldas_anoms['deficit']
```
## Time Selection

Specifying a temporal range of interest will free up more space. We'll grab every month for 2000-2014. This can be accomplished by generating a sequence for every month between January 2000 and December 2014, and then passing that vector of dates to `filter`.
Specifying a temporal range of interest will free up more space. We'll grab every year for 2000-2014. This can be accomplished by generating a sequence for every year between December 2000 and December 2014, and then passing that vector of dates to `filter`.


```{r}
# generate a vector of dates for subsetting
keeps<-seq(lubridate::ymd("2000-01-01"),
keeps<-seq(lubridate::ymd("2000-12-01"),
lubridate::ymd("2014-12-01"),
by = "month")
by = "year")
# filter using that vector
wsim_gldas_anoms <- dplyr::filter(wsim_gldas_anoms, time %in% keeps)
print(wsim_gldas_anoms)
```

Now we're down to a single attribute ("both") with 180 time-steps. We can take a look at the first 6 months by passing the object through `slice` and then into `plot`.
Now we're down to a single attribute ("both") with 15 time-steps. We can take a look at the first 6 years by passing the object through `slice` and then into `plot`.

```{r}
```{r warning=FALSE}
wsim_gldas_anoms |>
dplyr::slice(index = 1:6, along = "time") |>
plot(key.pos = 1)
plot(key.pos = 1, breaks = c(0, -5, -10, -20, -30, -50), key.lab = "Deficit")
```

Although we've pared it down to a single attribute with a restricted time period of interest, we can take it a step further and reduce the spatial extent to a country or state of interest.
Expand Down Expand Up @@ -137,13 +137,13 @@ From here we can crop the WSIM GLDAS raster stack by indexing it with the stored
wsim_gldas_anoms_tex <- wsim_gldas_anoms[texas]
```

For a final visual check we'll take the last time-step in the WSIM-GLDAS dataset (180/December, 2014) and plot it with an overlay of the Texas boundary.
For a final visual check we'll take the last time-step in the WSIM-GLDAS dataset (15/December, 2014) and plot it with an overlay of the Texas boundary.


```{r}
```{r warning = FALSE}
wsim_gldas_anoms_tex |>
dplyr::slice(index = 180, along = "time") |>
plot(reset = FALSE)
dplyr::slice(index = 15, along = "time") |>
plot(reset = FALSE, breaks = c(0,-1,-2,-3,-4,-5))
plot(sf::st_geometry(texas),
add = TRUE,
Expand All @@ -155,7 +155,7 @@ plot(sf::st_geometry(texas),
The subsetted dataset may be written to disk, and saved for future modules.

```{r}
stars::write_stars(wsim_gldas_anoms_tex, "wsim_gldas_tex.nc")
stars::write_mdim(wsim_gldas_anoms_tex, "wsim_gldas_tex.nc")
```

The size of the pre-processed dataset is 1.6 MB compared to the original dataset of 1.7 GB. This is much more manageable in cloud environments, workshops, and git platforms.

0 comments on commit bae2f58

Please sign in to comment.