Welcome to StreamStats’s documentation!

StreamStats

https://img.shields.io/pypi/v/streamstats.svg https://api.travis-ci.org/earthlab/streamstats.svg?branch=master Documentation Status https://codecov.io/gh/earthlab/streamstats/branch/master/graph/badge.svg https://static.mybinder.org/badge.svg

Python package for interfacing with the USGS StreamStats API.

Features

  • Get the GeoJSON of the watershed containing a spatial point in the U.S.

Credits

This package was created with Cookiecutter.

Installation

Stable release

To install StreamStats, run this command in your terminal:

$ pip install streamstats

This is the preferred method to install StreamStats, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for StreamStats can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/earthlab/streamstats

Or download the tarball:

$ curl  -OL https://codeload.github.com/earthlab/streamstats/legacy.tar.gz/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

Finding the watershed that contains a point

Given a spatial point in the U.S. defined by a lat/lon location and a state, the Watershed class can be used to find the watershed that contains that point using the USGS StreamStats API.

>>> from streamstats import Watershed
>>> Watershed(lat=43.939, lon=-74.524)
Watershed object with HUC8: 04150305, containing lat/lon: (43.939, -74.524)

streamstats

streamstats package

Submodules

streamstats.utils module

Utility functions for streamstats.

streamstats.utils.find_address(lat, lon)[source]

Find the address associated with a lat/lon pair.

Parameters
  • lat (float) – Latitude of point in decimal degrees

  • lon (float) – Longitude of point in decimal degrees

Return type

dictionary containing address data

streamstats.utils.find_state(address)[source]

Find the U.S. state that contains an address

Parameters

address (dict) – An address found by find_address

Return type

string of the state code (e.g., “CO” for Colorado)

streamstats.utils.requests_retry_session(retries=3, backoff=0.3, status_forcelist=(500, 502, 504))[source]

Make a session that backs off automatically.

Parameters
  • retries (int) – Number of times to retry a request

  • backoff (float) – Interval: {backoff} * (2^({number of total retries} - 1))

  • status_forcelist (tuple of ints) – Status codes that prompt a retry

streamstats.watershed module

Functionality for finding watershed information for specific locations.

class streamstats.watershed.Watershed(lat, lon)[source]

Bases: object

Watershed covering a spatial region, with associated information.

The USGS StreamStats API is built around watersheds as organizational units. Watersheds in the 50 U.S. states can be found using lat/lon lookups, along with information about the watershed including its HUC code and a GeoJSON representation of the polygon of a watershed. Basin characteristics can also be extracted from watersheds.

base_url = 'https://streamstats.usgs.gov/streamstatsservices/'
property boundary

Return the full watershed GeoJSON as a dictionary.

:rtype dict containing GeoJSON watershed boundary

property characteristics

List the available watershed characteristics.

Details about these characteristics can be found in the StreamStats docs: https://streamstatsags.cr.usgs.gov/ss_defs/basin_char_defs.aspx

:rtype OrderedDict with characteristic codes and descriptions

get_characteristic(code=None)[source]

Retrieve a specified watershed characteristic

Parameters

code (string) – Watershed characteristic code to extract.

get_characteristic() requires a characteristic code as an argument. Valid codes can be seen as keys in the dictionary returned by the characteristics() method.

:rtype dict containing specified characteristic’s data and metadata

property huc

Find the Hydrologic Unit Code (HUC) of the watershed.

Module contents

Top-level package for StreamStats.

Contributing

We welcome and greatly appreciate contributions to streamstats! Every bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/earthlab/streamstats/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.

  • Any details about your local setup that might be helpful in troubleshooting.

  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

StreamStats could always use more documentation, whether as part of the official StreamStats docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/earthlab/streamstats/issues.

If you are proposing a feature:

  • Explain in detail how it would work.

  • Keep the scope as narrow as possible, to make it easier to implement.

  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up StreamStats for local development.

  1. Fork the streamstats repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/streamstats.git
    
  3. Install your local copy into a new environment.

If you have virtualenvwrapper installed:

$ mkvirtualenv streamstats

If you are a conda user:

$ conda create -n streamstats python=3
$ conda activate streamstats

Then install StreamStats:

$ cd streamstats/
$ pip install -r requirements.txt
$ pip install -r requirements_dev.txt
$ pip install -e .
  1. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  2. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ pytest
    $ tox
    
  3. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  4. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.

  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.

  3. The pull request should work for Python 3.4, 3.5 and 3.6, and for PyPy. Check https://travis-ci.org/earthlab/streamstats/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ py.test tests.test_streamstats

Deploying

A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:

$ bumpversion patch # possible: major / minor / patch
$ git push
$ git push --tags

Travis will then deploy to PyPI if tests pass.

Credits

Development Lead

Contributors

  • Scott Eilerman

  • Leah Wasser

  • Jeremy Diaz

  • Nate Mietkiewicz

History

0.1.3

  • remove get_flow_stats() which is down server side

0.1.0 (2018-10-22)

  • First release on PyPI.

Indices and tables