Skip to main content

A lightweight Python toolkit for downloading, processing, and filtering USGS NWIS daily water data

Project description

pyNWIS

pyNWIS

PyPI Python License

A lightweight Python toolkit for downloading, processing, and filtering
USGS National Water Information System (NWIS) daily water data.


✨ Features

Feature Description
📡 Daily Value Fetching Download daily values from the USGS NWIS API with automatic retries and rate-limit handling
📦 Batch Downloads Fetch data for hundreds of sites at once with progress bars
🧹 Tidy DataFrames Convert raw JSON responses into clean Pandas DataFrames
🔍 Parameter Search Built-in catalog of 30+ common USGS parameter codes with keyword search
🎯 Smart Filtering Keep only sites with sufficient data for your required variables

🚀 Installation

pip install pynwis

Or install from source:

git clone https://github.com/Bluerrror/NWIS-Data-Downloader.git
cd NWIS-Data-Downloader
pip install -e .

Requirements: Python ≥ 3.8  |  requests  |  pandas  |  tqdm


📖 Quick Start

1. Fetch discharge data for a single site

from pynwis import fetch_usgs_daily, usgs_json_to_df

json_data = fetch_usgs_daily(
    sites=["01491000"],
    parameter_codes=["00060"],       # Discharge (ft³/s)
    start="2024-01-01",
    end="2024-12-31",
)

df = usgs_json_to_df(json_data)
print(df.head())
#   site_no       time  00060
# 0  01491000 2024-01-01  222.0
# 1  01491000 2024-01-02  201.0
# 2  01491000 2024-01-03  187.0

2. Search the parameter catalog

from pynwis import get_usgs_parameters, search_parameters

params = get_usgs_parameters()
print(params.head())
#   parm_cd     group                               parameter_nm parameter_unit
# 0   00010  Physical  Temperature, water, degrees Celsius          deg C
# 1   00020  Physical  Temperature, air, degrees Celsius            deg C

# Find sediment-related parameters
results = search_parameters(params, "sediment")
print(results[["parm_cd", "parameter_nm"]])
#   parm_cd                                      parameter_nm
# 0   80154       Suspended sediment concentration, mg/L
# 1   80155  Suspended sediment discharge, short tons per day
# 2   80225  Bedload sediment discharge, short tons per day

3. Batch download with filtering

from pynwis import fetch_batch_usgs_data

sites = ["01491000", "01646500", "09522500"]

df = fetch_batch_usgs_data(
    sites=sites,
    parameter_codes=["00060", "80154"],   # Discharge + Suspended sediment
    start="2000-01-01",
    required_params=["80154"],            # Only keep sites that have sediment data
    min_records=100,
)

print(df.shape)
print(df.describe())

📋 Common Parameter Codes

Code Name Description Units
00010 Temperature Water temperature °C
00060 Discharge Streamflow discharge ft³/s
00065 Gage Height Gage height ft
00045 Precipitation Precipitation depth in
00400 pH pH value std units
00300 Dissolved O₂ Dissolved oxygen mg/L
00630 NO₃ + NO₂ Nitrate plus nitrite mg/L as N
80154 SSC Suspended sediment concentration mg/L
80155 SS Discharge Suspended sediment discharge tons/day

Tip: Call get_usgs_parameters() for the full built-in catalog, or use search_parameters() to find codes by keyword.


📚 API Reference

Core Functions

Function Description
fetch_usgs_daily(sites, parameter_codes, ...) Fetch raw NWIS daily-values JSON for one or more sites
usgs_json_to_df(json_data) Convert NWIS JSON response into a tidy DataFrame
fetch_batch_usgs_data(sites, parameter_codes, ...) Batch fetch with progress bars, retries, and filtering

Parameter Utilities

Function Description
get_usgs_parameters() Return the built-in catalog of common parameter codes
search_parameters(params_df, query, ...) Search parameters by keyword

🤝 Contributing

  1. Fork the repo
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m "Add amazing feature"
  4. Push: git push origin feature/amazing-feature
  5. Open a Pull Request

📄 License

MIT License — see LICENSE for details.


🙏 Acknowledgments

Built on the USGS Water Services API.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynwis-0.1.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynwis-0.1.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pynwis-0.1.1.tar.gz.

File metadata

  • Download URL: pynwis-0.1.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pynwis-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1f90ce7147818faa56b0df8fdc2d42b0c34c01152e2d99c8cea57f692c620b99
MD5 671ef84999b78d7bd7408c521ce7a646
BLAKE2b-256 d2c8d475ba9b7be2234fdd7cd8b7755f7f2e6b5e70fca30796f25195c7ab38f2

See more details on using hashes here.

File details

Details for the file pynwis-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pynwis-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pynwis-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e9cde0cc91fd1320bb290cdd2fa56630f73d6888aef3c497be8b067cd07a91d
MD5 42f347a67a3ccc52a36067ca40de372f
BLAKE2b-256 d28658d0f40669fe7da47ece29688ca9bfba483296ad2c1eba055af69322e24b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page