Surface water network
A Python package to create and analyze surface water networks.
https://github.com/mwtoews/surface-water-network
Category: Hydrosphere
Sub Category: Freshwater and Hydrology
Keywords
hydrology modflow python surface-water
Keywords from Contributors
measurements particles pypi mesh energy-system-model packages imaging compresses gan communicator
Last synced: about 12 hours ago
JSON representation
Repository metadata
A Python package to create and analyze surface water networks.
- Host: GitHub
- URL: https://github.com/mwtoews/surface-water-network
- Owner: mwtoews
- License: bsd-3-clause
- Created: 2019-05-21T01:32:38.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-04-07T19:20:24.000Z (19 days ago)
- Last Synced: 2025-04-10T06:04:16.346Z (17 days ago)
- Topics: hydrology, modflow, python, surface-water
- Language: Python
- Homepage: https://mwtoews.github.io/surface-water-network/
- Size: 7.77 MB
- Stars: 29
- Watchers: 6
- Forks: 7
- Open Issues: 10
- Releases: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Citation: CITATION.cff
README.md
Surface water network
A Python package to create and analyze surface water networks.
Python packages
Python 3.9+ is required.
Required
geopandas >=0.9
- process spatial data similar to pandaspackaging
- used to check package versionspandas >=1.2
- tabular data analysispyproj >=2.2
- 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, verify_integrity=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, verify_integrity=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.
Citation (CITATION.cff)
cff-version: 1.2.0 message: "Please cite this software using these metadata." type: software title: "Surface water network" version: "0.8" date-released: "2024-07-03" doi: 10.5281/zenodo.6866082 abstract: "A Python package to create and analyze surface water networks." repository-artifact: https://pypi.org/project/surface-water-network repository-code: https://github.com/mwtoews/surface-water-network license: "BSD-3-Clause" authors: - given-names: "Mike W." family-names: Taves email: [email protected] affiliation: "GNS Science" orcid: "https://orcid.org/0000-0003-3657-7963" - given-names: Brioch family-names: Hemmings email: [email protected] affiliation: "GNS Science" orcid: "https://orcid.org/0000-0001-6311-8450" keywords: - "surface water" - groundwater - MODFLOW - flopy
Owner metadata
- Name: Mike Taves
- Login: mwtoews
- Email:
- Kind: user
- Description: Hydrogeologist, numerical modeller, GIS guru. Last name is also Toews.
- Website: https://mwtoews.github.io/
- Location: Wellington, New Zealand
- Twitter: mwtoews
- Company: GNS Science
- Icon url: https://avatars.githubusercontent.com/u/895458?u=1ee0b55b4f444e663e213b9788ca2315342aae36&v=4
- Repositories: 139
- Last ynced at: 2024-06-11T15:38:02.832Z
- Profile URL: https://github.com/mwtoews
GitHub Events
Total
- Issues event: 1
- Watch event: 1
- Delete event: 5
- Push event: 6
- Pull request review event: 1
- Pull request event: 9
- Create event: 5
Last Year
- Issues event: 1
- Watch event: 1
- Delete event: 5
- Push event: 6
- Pull request review event: 1
- Pull request event: 9
- Create event: 5
Committers metadata
Last synced: 6 days ago
Total Commits: 315
Total Committers: 5
Avg Commits per committer: 63.0
Development Distribution Score (DDS): 0.117
Commits in past year: 18
Committers in past year: 2
Avg Commits per committer in past year: 9.0
Development Distribution Score (DDS) in past year: 0.222
Name | Commits | |
---|---|---|
Mike Taves | m****s@g****m | 278 |
Briochh | b****h@g****m | 23 |
pre-commit-ci[bot] | 6****] | 12 |
Codacy Badger | b****r@c****m | 1 |
Brioch Hemmings | b****s@g****z | 1 |
Committer domains:
- gns.cri.nz: 1
- codacy.com: 1
Issue and Pull Request metadata
Last synced: 1 day ago
Total issues: 23
Total pull requests: 89
Average time to close issues: 11 months
Average time to close pull requests: 5 days
Total issue authors: 4
Total pull request authors: 5
Average comments per issue: 0.78
Average comments per pull request: 0.33
Merged pull request: 80
Bot issues: 0
Bot pull requests: 14
Past year issues: 2
Past year pull requests: 13
Past year average time to close issues: 2 minutes
Past year average time to close pull requests: 6 days
Past year issue authors: 1
Past year pull request authors: 2
Past year average comments per issue: 0.5
Past year average comments per pull request: 0.0
Past year merged pull request: 13
Past year bot issues: 0
Past year bot pull requests: 4
Top Issue Authors
- wkitlasten (12)
- mwtoews (7)
- briochh (3)
- izarikos (1)
Top Pull Request Authors
- mwtoews (63)
- pre-commit-ci[bot] (14)
- wkitlasten (8)
- briochh (3)
- codacy-badger (1)
Top Issue Labels
- task (3)
- enhancement (2)
Top Pull Request Labels
- enhancement (4)
- potentially breaking (1)
Package metadata
- Total packages: 1
-
Total downloads:
- pypi: 243 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 7
- Total maintainers: 1
pypi.org: surface-water-network
Surface water network
- Homepage:
- Documentation: https://mwtoews.github.io/surface-water-network/
- Licenses: BSD 3-Clause
- Latest release: 0.8 (published 10 months ago)
- Last Synced: 2025-04-25T13:30:48.834Z (1 day ago)
- Versions: 7
- Dependent Packages: 0
- Dependent Repositories: 1
- Downloads: 243 Last month
-
Rankings:
- Dependent packages count: 7.31%
- Stargazers count: 12.467%
- Forks count: 13.349%
- Average: 21.564%
- Dependent repos count: 22.088%
- Downloads: 52.605%
- Maintainers (1)
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- peaceiris/actions-gh-pages v3 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- geopandas >=0.9
- packaging *
- pandas >=1.2
- pyproj >=2.2
- rtree *
- shapely *
Score: 10.774257769108473