Surface water network
A Python package to create and analyze surface water networks.
Python packages
Python 3.10+ is required.
Required
geopandas- process spatial data similar to pandaspackaging- used to check package versionspandas- tabular data analysispyproj- spatial projection supportrtree- spatial index support
Optional
flopy >=3.3.6- read/write MODFLOW modelsnetCDF4- used to read TopNet files
Testing
Run pytest -v or python3 -m pytest -v
For faster multi-core pytest -v -n 2 (with pytest-xdist)
To run doctests pytest -v swn --doctest-modules
Examples
import geopandas
import pandas as pd
import swn
Read from Shapefile:
shp_srs = "tests/data/DN2_Coastal_strahler1z_stream_vf.shp"
lines = geopandas.read_file(shp_srs)
lines.set_index("nzsegment", inplace=True) # optional
Or, read from PostGIS:
from sqlalchemy import create_engine, engine
con_url = engine.url.URL(drivername="postgresql", database="scigen")
con = create_engine(con_url)
sql = "SELECT * FROM wrc.rec2_riverlines_coastal"
lines = geopandas.read_postgis(sql, con)
lines.set_index("nzsegment", inplace=True) # optional
Initialise and create network:
n = swn.SurfaceWaterNetwork.from_lines(lines.geometry)
print(n)
# <SurfaceWaterNetwork: with Z coordinates
# 304 segments: [3046409, 3046455, ..., 3050338, 3050418]
# 154 headwater: [3046409, 3046542, ..., 3050338, 3050418]
# 3 outlets: [3046700, 3046737, 3046736]
# no diversions />
Plot the network, write a Shapefile, write and read a SurfaceWaterNetwork file:
n.plot()
swn.file.gdf_to_shapefile(n.segments, "segments.shp")
n.to_pickle("network.pkl")
n = swn.SurfaceWaterNetwork.from_pickle("network.pkl")
Remove segments that meet a condition (stream order), or that are upstream/downstream from certain locations:
n.remove(
n.segments.stream_order == 1,
segnums=n.gather_segnums(upstream=3047927))
Read flow data from a TopNet netCDF file, convert from m3/s to m3/day:
nc_path = "tests/data/streamq_20170115_20170128_topnet_03046727_strahler1.nc"
flow = swn.file.topnet2ts(nc_path, "mod_flow", 86400)
# remove time and truncate to closest day
flow.index = flow.index.floor("d")
# 7-day mean
flow7d = flow.resample("7D").mean()
# full mean
flow_m = pd.DataFrame(flow.mean(0)).T
Process a MODFLOW/flopy model:
import flopy
m = flopy.modflow.Modflow.load("h.nam", model_ws="tests/data", check=False)
nm = swn.SwnModflow.from_swn_flopy(n, m)
nm.default_segment_data()
nm.set_segment_data_inflow(flow_m)
nm.plot()
nm.to_pickle("sfr_network.pkl")
nm = swn.SwnModflow.from_pickle("sfr_network.pkl", n, m)
nm.set_sfr_obj()
m.sfr.write_file("file.sfr")
nm.grid_cells.to_file("grid_cells.shp")
nm.reaches.to_file("reaches.shp")
Citation
Toews, M. W.; Hemmings, B. 2019. A surface water network method for generalising streams and rapid groundwater model development. In: New Zealand Hydrological Society Conference, Rotorua, 3-6 December, 2019. p. 166-169.
Metadata
Release files for surface-water-network 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| surface_water_network-1.0.tar.gz | 547.3 kB | Without provenance | Details for surface_water_network-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| surface_water_network-1.0-py3-none-any.whl | Python 3 | none | any | Details for surface_water_network-1.0-py3-none-any.whl |
Total release size: 649.5 kB
Release files / surface_water_network-1.0.tar.gz
| Download URL | surface_water_network-1.0.tar.gz |
|---|---|
| Size | 547.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de6f0811e71e08b58a5acebc845718a85a6e6005b05844924ac796336573ebbd
|
|
BLAKE2b-256 checksum How to use checksums |
848bd96004b1084429115b443c080959383fdf59c83a7319ce1f9d75daf72168
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / surface_water_network-1.0-py3-none-any.whl
| Download URL | surface_water_network-1.0-py3-none-any.whl |
|---|---|
| Size | 102.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28fe5415c719c19001feea1e5e489f5ba6ab10ab635ac88327c8463d7fae931f
|
|
BLAKE2b-256 checksum How to use checksums |
58fedba1da0e2e3bb69ee050e00255deb59addd596c895dfb32220405be913f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for surface-water-network 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.