{"id":13948518,"url":"https://github.com/mwtoews/surface-water-network","last_synced_at":"2025-08-22T07:41:02.961Z","repository":{"id":37987829,"uuid":"187739645","full_name":"mwtoews/surface-water-network","owner":"mwtoews","description":"A Python package to create and analyze surface water networks.","archived":false,"fork":false,"pushed_at":"2025-07-07T17:08:34.000Z","size":8269,"stargazers_count":29,"open_issues_count":13,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-08-13T02:22:22.392Z","etag":null,"topics":["hydrology","modflow","python","surface-water"],"latest_commit_sha":null,"homepage":"https://mwtoews.github.io/surface-water-network/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mwtoews.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-05-21T01:32:38.000Z","updated_at":"2025-05-12T00:26:59.000Z","dependencies_parsed_at":"2023-09-30T11:31:04.541Z","dependency_job_id":"904ec108-eb24-4d17-8df1-37b0bfdc521e","html_url":"https://github.com/mwtoews/surface-water-network","commit_stats":{"total_commits":310,"total_committers":5,"mean_commits":62.0,"dds":"0.11290322580645162","last_synced_commit":"9665610873de7098044712f5b3a56f7ad494d6eb"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/mwtoews/surface-water-network","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwtoews%2Fsurface-water-network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwtoews%2Fsurface-water-network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwtoews%2Fsurface-water-network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwtoews%2Fsurface-water-network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwtoews","download_url":"https://codeload.github.com/mwtoews/surface-water-network/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwtoews%2Fsurface-water-network/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270515699,"owners_count":24598440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hydrology","modflow","python","surface-water"],"created_at":"2024-08-08T05:01:24.257Z","updated_at":"2025-08-22T07:41:02.939Z","avatar_url":"https://github.com/mwtoews.png","language":"Python","funding_links":[],"categories":["Hydrosphere"],"sub_categories":["Freshwater and Hydrology"],"readme":"# Surface water network\n[![DOI](https://zenodo.org/badge/187739645.svg)](https://zenodo.org/badge/latestdoi/187739645)\n[![Codacy](https://api.codacy.com/project/badge/Grade/420bcd8896c14f18b2077dd987c78849)](https://app.codacy.com/manual/mwtoews/surface-water-network?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=mwtoews/surface-water-network\u0026utm_campaign=Badge_Grade_Dashboard)\n[![Codcov](https://codecov.io/gh/mwtoews/surface-water-network/branch/main/graph/badge.svg)](https://codecov.io/gh/mwtoews/surface-water-network)\n[![CI](https://github.com/mwtoews/surface-water-network/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mwtoews/surface-water-network/actions/workflows/tests.yml)\n\nA Python package to create and analyze surface water networks.\n\n\n## Python packages\n\nPython 3.10+ is required.\n\n### Required\n\n - `geopandas` - process spatial data similar to pandas\n - `packaging` - used to check package versions\n - `pandas` - tabular data analysis\n - `pyproj` - spatial projection support\n - `rtree` - spatial index support\n\n### Optional\n\n - `flopy \u003e=3.3.6` - read/write MODFLOW models\n - `netCDF4` - used to read TopNet files\n\n## Testing\n\nRun `pytest -v` or `python3 -m pytest -v`\n\nFor faster multi-core `pytest -v -n 2` (with `pytest-xdist`)\n\nTo run doctests `pytest -v swn --doctest-modules`\n\n## Examples\n\n```python\nimport geopandas\nimport pandas as pd\nimport swn\n```\n\nRead from Shapefile:\n```python\nshp_srs = \"tests/data/DN2_Coastal_strahler1z_stream_vf.shp\"\nlines = geopandas.read_file(shp_srs)\nlines.set_index(\"nzsegment\", inplace=True, verify_integrity=True)  # optional\n```\n\nOr, read from PostGIS:\n```python\nfrom sqlalchemy import create_engine, engine\n\ncon_url = engine.url.URL(drivername=\"postgresql\", database=\"scigen\")\ncon = create_engine(con_url)\nsql = \"SELECT * FROM wrc.rec2_riverlines_coastal\"\nlines = geopandas.read_postgis(sql, con)\nlines.set_index(\"nzsegment\", inplace=True, verify_integrity=True)  # optional\n```\n\nInitialise and create network:\n```python\nn = swn.SurfaceWaterNetwork.from_lines(lines.geometry)\nprint(n)\n# \u003cSurfaceWaterNetwork: with Z coordinates\n#   304 segments: [3046409, 3046455, ..., 3050338, 3050418]\n#   154 headwater: [3046409, 3046542, ..., 3050338, 3050418]\n#   3 outlets: [3046700, 3046737, 3046736]\n#   no diversions /\u003e\n```\n\nPlot the network, write a Shapefile, write and read a SurfaceWaterNetwork file:\n```python\nn.plot()\n\nswn.file.gdf_to_shapefile(n.segments, \"segments.shp\")\n\nn.to_pickle(\"network.pkl\")\nn = swn.SurfaceWaterNetwork.from_pickle(\"network.pkl\")\n```\n\nRemove segments that meet a condition (stream order), or that are\nupstream/downstream from certain locations:\n```python\nn.remove(\n    n.segments.stream_order == 1,\n    segnums=n.gather_segnums(upstream=3047927))\n```\n\nRead flow data from a TopNet netCDF file, convert from m3/s to m3/day:\n```python\n\nnc_path = \"tests/data/streamq_20170115_20170128_topnet_03046727_strahler1.nc\"\nflow = swn.file.topnet2ts(nc_path, \"mod_flow\", 86400)\n# remove time and truncate to closest day\nflow.index = flow.index.floor(\"d\")\n\n# 7-day mean\nflow7d = flow.resample(\"7D\").mean()\n\n# full mean\nflow_m = pd.DataFrame(flow.mean(0)).T\n```\n\nProcess a MODFLOW/flopy model:\n```python\nimport flopy\n\nm = flopy.modflow.Modflow.load(\"h.nam\", model_ws=\"tests/data\", check=False)\nnm = swn.SwnModflow.from_swn_flopy(n, m)\nnm.default_segment_data()\nnm.set_segment_data_inflow(flow_m)\nnm.plot()\nnm.to_pickle(\"sfr_network.pkl\")\nnm = swn.SwnModflow.from_pickle(\"sfr_network.pkl\", n, m)\nnm.set_sfr_obj()\nm.sfr.write_file(\"file.sfr\")\nnm.grid_cells.to_file(\"grid_cells.shp\")\nnm.reaches.to_file(\"reaches.shp\")\n```\n\n## Citation\n\nToews, 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwtoews%2Fsurface-water-network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwtoews%2Fsurface-water-network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwtoews%2Fsurface-water-network/lists"}