Skip to main content

A Python package to automate downloading water resource data from SNIRH

Project description

get-snirh

PyPI version Tests Downloads

A Python package to automate the retrieval of water resource data from the Portuguese Environment Agency (SNIRH).

Installation

Install from PyPI:

pip install get-snirh

Or install from source:

git clone https://github.com/rhugman/get-snirh.git
cd get-snirh
pip install .

Usage

Basic Example

from get_snirh import Snirh, Parameters

# Initialize the client for a specific network
# Currently supported: "piezometria" (default), "meteorologica"
snirh = Snirh(network="piezometria")

# 1. Get Stations
# Fetch all stations and filter by basin
# This uses bundled metadata for fast access
stations = snirh.stations.get_stations_with_metadata(basin_filter=['RIBEIRAS DO ALGARVE'])
print(f"Found {len(stations)} stations.")

# 2. Fetch Data
# Fetch Groundwater Level Depth for the year 2023
# Passing the stations DataFrame allows the output to include station names
df = snirh.data.get_timeseries(
    station_codes=stations.head(5), # Limit to first 5 for demo
    parameter=Parameters.GWL_DEPTH,
    start_date='01/01/2023',
    end_date='31/12/2023'
)

print(df.head())

# 3. Save to CSV
df.to_csv('algarve_gwl_2023.csv', index=False)

Testing

To run the standard unit tests (mocked):

pytest

To run the live integration tests (hits SNIRH servers):

RUN_LIVE_TESTS=1 pytest tests/test_live.py

Features & Limitations

  • Supported Networks: Currently fully supports Piezometria (Groundwater) and Meteorologica (Meteorology).
  • Station Database: Station lists are currently limited to a hardcoded local database. Remote access to the live station list is currently unresolved, so the bundled metadata files must be updated manually for now.
  • Data Retrieval: Downloads time-series data for various parameters (Rainfall, Groundwater Level, Temperature, etc.).
  • Robust Parsing: Handles SNIRH's specific CSV formats and encoding (ISO-8859-1).
  • Clean API: Simple, object-oriented interface.

Examples

Check the examples/ folder for more detailed usage scripts and notebooks.

Parameters

Available parameters in get_snirh.Parameters:

  • PRECIPITATION_DAILY
  • PRECIPITATION_MONTHLY
  • GWL_DEPTH
  • AIR_TEMP_AVG_DAILY
  • And more...

Disclaimer & Data Acknowledgment

This software is an unofficial tool and is not affiliated with, endorsed by, or maintained by the Agência Portuguesa do Ambiente (APA) or the Sistema Nacional de Informação de Recursos Hídricos (SNIRH).

All data retrieved by this tool belongs to SNIRH/APA. Users are responsible for adhering to SNIRH's terms of use and data policies. Please ensure you cite the source appropriately when using the data.

This tool is provided "as is", without warranty of any kind. Use it responsibly to avoid overloading the SNIRH servers.

License

GNU GPLv3

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

get_snirh-0.1.1.tar.gz (276.3 kB view details)

Uploaded Source

Built Distribution

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

get_snirh-0.1.1-py3-none-any.whl (274.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: get_snirh-0.1.1.tar.gz
  • Upload date:
  • Size: 276.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for get_snirh-0.1.1.tar.gz
Algorithm Hash digest
SHA256 46aff301d98f2f658cd57b027f0d633c0555f36f086225acdcaf728e3dad57a9
MD5 f23846a46d64a5bf3a1131bc04f8a7c3
BLAKE2b-256 7a1fe9557d87c53cef2e15aec3f82dac629a9277f3932762593550c006c0d6eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: get_snirh-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 274.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for get_snirh-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04da7c0f6ef3e9e3e8fc6a30a1d55aa4797efb14f54d2638cb44c486ff7d34aa
MD5 e7b4fbbaf29dc8ac6faa83802f93e0e1
BLAKE2b-256 798449cd894874104fb42577a674312e85024b7ae62099c09c5a8b8cc878e11d

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