Skip to content

Commit

Permalink
live download + unzip
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellmanware committed Jan 21, 2025
1 parent 636a41c commit 2494bb4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ _bookdown_files/
_main_files
.DS_Store
docs/
dataset/epa/daily_88101_2021.csv
dataset/narr/air.2m_2021.nc
19 changes: 3 additions & 16 deletions chapters/01-02-spatial-point-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ unzip(

After inspecting the file size, unzip `epa_data.zip`.

```{r, eval = FALSE}
```{r, eval = TRUE}
unzip(
"./dataset/epa/epa_data.zip",
exdir = "./dataset/epa/"
Expand All @@ -80,32 +80,19 @@ Inspecting the file with `utils::unzip(list = TRUE)` returned the size of the fi
Multiple chunks of code in this tutorial will contain `./dataset/`, a fixed directory path to run the tutorial code. To run the code on your machine, substitute `./dataset/` with the file path where you would like to store the tutorial data.
:::

```{r, eval = FALSE}
```{r}
list.files("./dataset/epa")
```
```{r, echo = FALSE, include = FALSE}
cat("[1] \"daily_88101_2021.csv\" \"epa_data.zip\"")
```

## Data Preparation

### Import

Now that the contents of the zip file have been saved on your machine and the data file of interest has been identified, import the data with `sf::st_read()`.

```{r, eval = FALSE}
```{r}
pm <- sf::st_read("./dataset/epa/daily_88101_2021.csv")
```
```{r, echo = FALSE, include = FALSE}
pm <- readRDS("./dataset/epa/daily_sf.rds")
```
```{r, echo = FALSE, include = FALSE}
cat("Reading layer `daily_88101_2021' from data source
`/Users/manwareme/Documents/bookdown/niehs/PCOR_bookdown_tools/dataset/epa/daily_88101_2021.csv'
using driver `CSV'
Warning message:
no simple feature geometries present: returning a data.frame or tbl_df ")
```

The previous chunk of code returned a `Warning:` message. This warning informs the user that the imported data does not have native spatial features, so the data was imported as a `data.frame`.

Expand Down
14 changes: 3 additions & 11 deletions chapters/01-04-spatial-raster-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The `utils::download.file()` function downloads the file according to the define
Multiple chunks of code in this tutorial will contain `./dataset/`, a fixed directory path to run the tutorial code. To run the code on your machine, substitute `./dataset/` with the file path where you would like to store the tutorial data.
:::

```{r, eval = FALSE}
```{r, eval = TRUE}
# specify the URL where data is stored based on year variable of interest
url_narr <- paste0(
"https://downloads.psl.noaa.gov//Datasets/NARR/Dailies/monolevel/air.2m.",
Expand All @@ -72,11 +72,7 @@ download.file(
Identify the desired data file with `utils::list.files()`

```{r, eval = FALSE}
list.files("./dataset/narr/")
```

```{r, echo = FALSE, include = FALSE}
cat("[1] \"air_2m.2021.nc\"")
list.files("./dataset/narr")
```

The file downloaded from NOAA's NARR data set is an `.nc`, or netCDF, file. NetCDF files are common for raster data, and do not need to be unzipped.
Expand All @@ -87,14 +83,10 @@ The file downloaded from NOAA's NARR data set is an `.nc`, or netCDF, file. NetC

Now that the data file of interest has been downloaded and identified, import the data with `terra::rast()`.

```{r, eval = FALSE}
```{r}
narr <- terra::rast("./dataset/narr/air.2m_2021.nc")
```

```{r, echo = FALSE, include = FALSE}
narr <- readRDS("./dataset/narr/air.2m_2021.rds")
```

### Inspect Structure

Inspect the structure of `narr` to see its class, dimensions, variables, and layer names.
Expand Down
Binary file removed dataset/epa/daily_sf.rds
Binary file not shown.
Binary file removed dataset/narr/air.2m_2021.rds
Binary file not shown.

0 comments on commit 2494bb4

Please sign in to comment.