Skip to content

DOI-USGS/vulnerability-indicators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unequal access to water: how societal factors shape vulnerability to water insecurity

A newer version of the software may be available. See https://code.usgs.gov/wma/vizlab/vulnerability-indicators/-/releases to view all releases.

This repo uses R, Vue, and D3 to build an interactive data visualization website about indicators of vulnerability to water insecurity. In R there is a pipeline that uses the targets library to fetch, process, and visualize data. The rest of the files build the website.

This project:

  1. Pulls, processes, and visualizes data from the USGS Uncertainty Summary of Water Vulnerability in the Western US 2000-2022.

  2. Pull, processes, and visualizes data from the U.S. Census Bureau using the R package [tidycensus](https://walker-data.com/tidycensus/.

  3. Builds a javascript website using data visualization to communicate the motivation for the USGS Social and Economic Drivers project, highlighting how societal factors shape exposure to water-related hazards across the Western U.S.. The website can be accessed here

Running the targets pipeline in R

Clone the repo. In RStudio, run library(targets) and tar_make(). This will require tidycensus, sciencebase, and NASA Earthdata credentialing to run, see instructions below.

tidycensus set up

Adapted from package developers Kyle Walker & Matt Herman, to set up tidycensus run the following in the R Console:

# install.packages("tidycensus")
library(tidycensus)
library(tidyverse)

You will also need to set a Census API key. A key can be obtained from http://api.census.gov/data/key_signup.html.

census_api_key("YOUR API KEY GOES HERE", install = TRUE)
readRenviron("~/.Renviron")

ScienceBase login

To access controlled ScienceBase items, an additional step must be completed to authenticate a ScienceBase session before the targets pipeline is run.

  1. Ensure .gitignore includes a line for ".Renviron" to prevent credentials from being committed the the repository by git.
  2. Run the entire contents of 00_config.R either (1) interactively (i.e., line by line) or (2) by running source("00_config.R").
  3. You will be prompted to enter the token text by R/Rstudio. A browser window should pop-up directing you to https://sciencebase.usgs.gov/manager/ to login.
  4. Once logged in, copy your API token: click the account drop down button (person shaped icon) and click Copy API Token.
  5. Paste the API token into the RStudio popup.

Once the above steps are complete, initialize_and_cache_sb() will cache your username and token into the .Renviron file. From here, the pipeline should be able to use those cached credentials to re-initialize and refresh ScienceBase sessions in different R sessions for up to 10 hours.

NASA Earthdata

Population density data must be manually downloaded from https://sedac.ciesin.columbia.edu/data/set/gpw-v4-population-count-rev11/data-download. You will be prompted to login to a NASA Earthdata account. If you do not have one, you will need to create one. Once logged in, use these selections:

  • Temporal: Single Year
  • FileFormat: GeoTiff
  • Resolution: 30 second
  • File Select: Year 2020

Download the zip in the 1_process/in/ folder.

Building the website locally

Clone the repo. In the directory, run npm install to install the required modules. Once the dependencies have been installed, run npm run dev to run locally from your browser.

To build the website locally you'll need npm v20 and node v8.1 or higher installed. To manage multiple versions of npm, you may try using nvm.

Disclaimer

This software has been approved for release by the U.S. Geological Survey (USGS). Although the software has been subjected to rigorous review, the USGS reserves the right to update the software as needed pursuant to further analysis and review. No warranty, expressed or implied, is made by the USGS or the U.S. Government as to the functionality of the software and related material nor shall the fact of release constitute any such warranty. Furthermore, the software is released on condition that neither the USGS nor the U.S. Government shall be held liable for any damages resulting from its authorized or unauthorized use.

Citation

Azadpour E, Carr AN, Clarke A, Drakes O, Restrepo-Osorio DL, Nell C. 2024. Unequal access to water: How societal factors shape vulnerability to water insecurity. U.S. Geological Survey software release. Reston, VA. https://doi.org/10.5066/P19M9WYT.