surface-water-network


Namesurface-water-network JSON
Version 0.8 PyPI version JSON
download
home_pageNone
SummarySurface water network
upload_time2024-07-03 02:43:04
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseBSD 3-Clause
keywords modflow flopy groundwater surface water
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Surface water network
[![DOI](https://zenodo.org/badge/187739645.svg)](https://zenodo.org/badge/latestdoi/187739645)
[![Codacy](https://api.codacy.com/project/badge/Grade/420bcd8896c14f18b2077dd987c78849)](https://app.codacy.com/manual/mwtoews/surface-water-network?utm_source=github.com&utm_medium=referral&utm_content=mwtoews/surface-water-network&utm_campaign=Badge_Grade_Dashboard)
[![Codcov](https://codecov.io/gh/mwtoews/surface-water-network/branch/main/graph/badge.svg)](https://codecov.io/gh/mwtoews/surface-water-network)
[![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)

A Python package to create and analyze surface water networks.


## Python packages

Python 3.8+ is required.

### Required

 - `geopandas >=0.9` - process spatial data similar to pandas
 - `packaging` - used to check package versions
 - `pandas >=1.2` - tabular data analysis
 - `pyproj >=2.2` - spatial projection support
 - `rtree` - spatial index support

### Optional

 - `flopy >=3.3.6` - read/write MODFLOW models
 - `netCDF4` - 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

```python
import geopandas
import pandas as pd
import swn
```

Read from Shapefile:
```python
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:
```python
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:
```python
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:
```python
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:
```python
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:
```python

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:
```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "surface-water-network",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Mike Taves <mwtoews@gmail.com>",
    "keywords": "MODFLOW, flopy, groundwater, surface water",
    "author": null,
    "author_email": "Mike Taves <mwtoews@gmail.com>, Brioch Hemmings <briochh@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f2/02/68ae66a6820d59edb26e4c6dc60d79cd00db59990491b1a4898c2cb5d074/surface_water_network-0.8.tar.gz",
    "platform": null,
    "description": "# 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&utm_medium=referral&utm_content=mwtoews/surface-water-network&utm_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.8+ is required.\n\n### Required\n\n - `geopandas >=0.9` - process spatial data similar to pandas\n - `packaging` - used to check package versions\n - `pandas >=1.2` - tabular data analysis\n - `pyproj >=2.2` - spatial projection support\n - `rtree` - spatial index support\n\n### Optional\n\n - `flopy >=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# <SurfaceWaterNetwork: 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 />\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",
    "bugtrack_url": null,
    "license": "BSD 3-Clause",
    "summary": "Surface water network",
    "version": "0.8",
    "project_urls": {
        "Documentation": "https://mwtoews.github.io/surface-water-network/",
        "Source": "https://github.com/mwtoews/surface-water-network"
    },
    "split_keywords": [
        "modflow",
        " flopy",
        " groundwater",
        " surface water"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d56a6b19ee71910c0a3f1bb35c44bdd041b59cc3f2efbedf97476f98dbc1df14",
                "md5": "f7691a4283db1540905f5a79e4a29a2b",
                "sha256": "aa10bf03b8a25fa2c8808ec9b914b538080879bdf7d7bf4b702992f1855e5c28"
            },
            "downloads": -1,
            "filename": "surface_water_network-0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f7691a4283db1540905f5a79e4a29a2b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 101830,
            "upload_time": "2024-07-03T02:43:00",
            "upload_time_iso_8601": "2024-07-03T02:43:00.899155Z",
            "url": "https://files.pythonhosted.org/packages/d5/6a/6b19ee71910c0a3f1bb35c44bdd041b59cc3f2efbedf97476f98dbc1df14/surface_water_network-0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f20268ae66a6820d59edb26e4c6dc60d79cd00db59990491b1a4898c2cb5d074",
                "md5": "f2ff10614102c07e74e1d2f4c8faacbb",
                "sha256": "da2d32efb578d58b11962cf6816ea6e15c756b0d2ddb5076ddd591e30bf6e720"
            },
            "downloads": -1,
            "filename": "surface_water_network-0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "f2ff10614102c07e74e1d2f4c8faacbb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 556509,
            "upload_time": "2024-07-03T02:43:04",
            "upload_time_iso_8601": "2024-07-03T02:43:04.293660Z",
            "url": "https://files.pythonhosted.org/packages/f2/02/68ae66a6820d59edb26e4c6dc60d79cd00db59990491b1a4898c2cb5d074/surface_water_network-0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-03 02:43:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mwtoews",
    "github_project": "surface-water-network",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "surface-water-network"
}
        
Elapsed time: 0.32057s