Coder Social home page Coder Social logo

nsink's Introduction

nsink

R build status Codecov test coverage Lifecycle: stable DOI DOI

Statement of need

The nsink package is an R implementation of the methods described in Kellogg et. al (2010). Previous implementation of this approach relied on a manual, vector based approach that was time consuming to prepare. This approach uses a hybrid raster-vector approach that takes relatively little time to set up for each new watershed and relies on readily available data. Total run times vary, but range from minutes up to 5 hours depending on options selected. Previous versions took weeks of manual data manipulation. Thus, nsink was developed to satisfy the need for quicker implementation of the NSink method as described in Kellogg et. al (2010).

nsink functionality

As of 2022-03-14 user functions for the nsink package are:

  • nsink_get_huc_id(): A function for searching the name of a USGS Watershed Boundary Dataset Hydrologic Unit (https://www.usgs.gov/core-science-systems/ngp/national-hydrography/watershed-boundary-dataset) and retrieving its 12-digit Hydrologic Unit Code (HUC).
  • nsink_get_data(): Using any acceptable HUC ID (e.g. 2-digit to 12-digit), this function downloads the NHDPlus, SSURGO, NLCD Land Cover, and the NLCD Impervious for that HUC.
  • nsink_prep_data(): nsink needs data in a common coordinate reference system, from mutliple NHDPlus tables, and from different portions of SSURGO. This function completes these data preparation steps and outputs all data, clipped to the HUC boundary.
  • nsink_calc_removal(): Quantifying relative N removal across a landscape is a key aspects of an nsink analysis. The nsink_calc_removal() function takes the object returned from nsink_prep_data() and calculates relative N removal for each landscape sink. See Kellogg et al [-@kellogg2010geospatial] for details on relative N removal estimation for each sink.
  • nsink_generate_flowpath(): This function uses a combination of flow determined by topography, via a flow-direction raster, for the land-based portions of a flow path and of downstream flow along the NHDPlus stream network.
  • nsink_summarize_flowpath(): Summarizing removal along a specified flow path requires relative N removal and a generated flow path. This function uses these and returns a summary of relative N removal along a flow path for each sink.
  • nsink_generate_static_maps(): This function analyzes N removal at the watershed scale by summarizing the results of multiple flow paths. Four static maps are returned: 1)removal efficiency; 2)loading index; 3)transport index; 4)delivery index. Removal efficiency is a rasterized version of the nsink_calc_removal() output. Loading index is N sources based on NLCD categories. Transport index is a heat map with the cumulative relative N removal along flow paths originating from a grid of points, density set by the user, across a watershed, highlighting the gradient of downstream N retention. Delivery index is the result of multiplying the loading index and the transport index, and shows potential N delivery from different sources, taking into account the relative N removal as water moves downstream.
  • nsink_plot(): A function that plots each raster in the list returned from nsink_generate_static_maps().
  • nsink_build(): One of the drivers behind the development of the nsink package was to provide n-sink analysis output that could be used more broadly (e.g. within a GIS). The nsink_build() runs a complete nsink analysis and outputs R objects, shapefiles and/or TIFFs.
  • nsink_load(): Essentially the inverse of the nsink_build() function, this function takes a folder of files, likely created by nsink_build(), and reads them into R.

Installation instructions

At this time we plan on maintaining the nsink package as a GitHub only package and thus it won’t be available directly from CRAN. You may use the install_github() function from the remotes package to install it. The code below will take care of installing remotes and installing nsink from the GitHub repository.

install.packages("remotes")
remotes::install_github("usepa/nsink", dependencies = TRUE, build_vignettes = TRUE)

And then to load up the package:

library(nsink)

Documentation and examples

All functions are documented, with examples, and that documentation may be accessed, in R, via the usual help functions. Additionally, an introduction to the nsink package with a more detailed workflow is documented in a vignette.

# Load up package
library(nsink)

# Access package level help
help(package = "nsink")

# Access the Introduction to nsink vignette
vignette("intro", package = "nsink")

Contributing

If you would like to contribute to the nsink package, please first read the CONTRIBUTING. In short, contributions are happily accepted either via suggestions in the Issues or via pull request.

nsink's People

Contributors

jbousquin avatar jhollist avatar qkellogg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

qkellogg

nsink's Issues

Intermittent Bug on nsink_generate_static_maps

There is an intermittent bug on generating the static maps. Happened ~3 times on my tests. Throws this error:

Error in CPL_geos_op2(op, st_geometry(x), st_geometry(y)) : 
  Evaluation error: IllegalArgumentException: point array must contain 0 or >1 elements.

I think it is due to a starting location for a flowpath that results in a LINESTRING with only one point. Not sure if this occurs becuase the flow direction creates a single point flow path or if the point is directly on an existing flowline. Also not sure if this is occurring in the flowpath generation or in the flowpath summary. Been hard to recreate and find true culprit.

Unsatisfying fix for now is to re-run nsink_generate_static_maps as the bug is rare and unlikely to show itself twice...

nsink_get_data function error, url moved?

Hi:
I get the following error when running the nsink_get_data function:
manhan_download <- nsink_get_data(manhan_huc_id, data_dir = "nsink_manhan_data")
Error in nsink_get_plus_remotepath(rpu[i], "NHDPlusAttributes") :
Neither https://s3.amazonaws.com/edap-nhdplus/NHDPlusV21/Data/NHDPlusNE/NHDPlusV21_NE_01_NHDPlusAttributes_09.7z or https://s3.amazonaws.com/edap-nhdplus/NHDPlusV21/Data/NHDPlusNE/NHDPlus01/NHDPlusV21_NE_01_NHDPlusAttributes_09.7z is a valid URL

I ran the Niantic example in the vignette and received the same error message.

Think the base url in the utils.R code needs to be changed from "https://s3.amazonaws.com/edap-nhdplus/NHDPlusV21/Data/NHDPlus" to "https://edap-ow-data-commons.s3.amazonaws.com/NHDPlusV21/Data/NHDPlus"?

clean up and test examples

  • nsink_build
  • nsink_calc_removal
  • nsink_generate_flowpath
  • nsink_generate_static_maps
  • nsink_get_data
  • nsink_prep_data
  • nsink_summarize_flowpath

Disconnected flowpaths

Part of flowpaths were missing due to the disconnected NHD Plus streams. See example for East River-Frontal Guilford Harbor (huc12 = 011000040203).

image

How to deal with off-network hydrology

Do we have info for off network streams and lakes (e.g. kettle ponds) to calculate removal?

Need to figure out a way to include in flowpath when flowlines are not on network.

Jones River good example of these things happening.

raster vs hybrid method

I don't think I need the two methods anymore as I think I have it hard coded for hybrid everywhere. Look into removing this option...

in both nsink_generate_flowpath and nsink_summarize flowpath. Look for other instances and see if I can standardize to just a single method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.