Skip to content

Commit

Permalink
Merge pull request #340 from kaklise/1.0
Browse files Browse the repository at this point in the history
Minor update to the snap function and cleanup
  • Loading branch information
kaklise authored Mar 30, 2023
2 parents 5c3d94c + 2c3dd2e commit 79dd510
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ jobs:
if: matrix.os == 'windows-latest'
run: | # the following skips windows rst doctests that rely on geopandas (gis.rst and model_io.rst) because skipif is not working properly
coverage erase
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*" -m pytest --doctest-modules --doctest-glob="*.rst" wntr
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*" --append -m pytest --doctest-glob="*.rst" --ignore-glob="*model_io.rst" --ignore-glob="*gis.rst" documentation
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*","*/sim/network_isolation/network_isolation.py","*/sim/aml/evaluator.py" -m pytest --doctest-modules --doctest-glob="*.rst" wntr
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*","*/sim/network_isolation/network_isolation.py","*/sim/aml/evaluator.py" --append -m pytest --doctest-glob="*.rst" --ignore-glob="*model_io.rst" --ignore-glob="*gis.rst" documentation
env:
COVERAGE_FILE: .coverage.${{ matrix.python-version }}.${{ matrix.os }}
- name: Run Tests
if: matrix.os != 'windows-latest'
run: |
coverage erase
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*" -m pytest --doctest-modules --doctest-glob="*.rst" wntr
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*" --append -m pytest --doctest-glob="*.rst" documentation
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*","*/sim/network_isolation/network_isolation.py","*/sim/aml/evaluator.py" -m pytest --doctest-modules --doctest-glob="*.rst" wntr
coverage run --context=${{ matrix.os }}.py${{ matrix.python-version }} --source=wntr --omit="*/tests/*","*/sim/network_isolation/network_isolation.py","*/sim/aml/evaluator.py" --append -m pytest --doctest-glob="*.rst" documentation
env:
COVERAGE_FILE: .coverage.${{ matrix.python-version }}.${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/quick_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
python -m pip install -e .
- name: Run tests and coverage (unittests plus doctests)
run: |
coverage run --source=wntr --omit="*/tests/*" -m pytest -m "not time_consuming" --doctest-modules --doctest-glob="*.rst" wntr
coverage run --source=wntr --omit="*/tests/*","*/sim/network_isolation/network_isolation.py","*/sim/aml/evaluator.py" -m pytest -m "not time_consuming" --doctest-modules --doctest-glob="*.rst" wntr
coverage report --fail-under=70
# coverage run --source=wntr --omit="*/tests/*" --append -m pytest --doctest-glob="*.rst" documentation

4 changes: 2 additions & 2 deletions documentation/whatsnew.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Release notes
================

.. _whatsnew_060:
.. _whatsnew_100:

.. include:: whatsnew/v0.6.0.rst
.. include:: whatsnew/v1.0.0.rst

.. _whatsnew_050:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
v0.6.0 (main)
v1.0.0 (March 30, 2023)
---------------------------------------------------
WNTR version 1.0.0 has undergone extensive testing
with a wide range of water distribution system models
and analysis options. The software has also successfully been
used by external research groups and in analysis that uses large-scale
water distribution system models. See
`User community <https://wntr.readthedocs.io/en/latest/users.html>`_
for a list of publications and software that uses WNTR.

* Updated copyright and added EPANET license
`#336 <https://github.com/USEPA/WNTR/pull/336>`_.

* Updated the setup process and documentation
`#335 <https://github.com/USEPA/WNTR/pull/335>`_.

* Bug fix to allow for np.float and np.int in type checking
`#334 <https://github.com/USEPA/WNTR/pull/334>`_.

Expand Down
14 changes: 1 addition & 13 deletions wntr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# shapely and geopandas are optional dependencies of WNTR. If shapely
# version is >= 2.0, the environment variable USE_PYGEOS is set to '0' to
# ensure geopandas uses shapely over pygeos. Future versions of
# geopandas will use shapely by default.
try:
import shapely
if int(shapely.__version__.split('.')[0]) >= 2:
import os
os.environ['USE_PYGEOS'] = '0'
except ModuleNotFoundError:
pass

from wntr import epanet
from wntr import network
from wntr import morph
Expand All @@ -20,7 +8,7 @@
from wntr import gis
from wntr import utils

__version__ = '0.6.0dev'
__version__ = '1.0.0'

__copyright__ = """Copyright 2023 National Technology & Engineering
Solutions of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525
Expand Down
11 changes: 7 additions & 4 deletions wntr/gis/geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def snap(A, B, tolerance):
If B contains Lines or MultiLineString, columns include:
- link: closest Line in B to Point in A
- node: start or end node of Line in B that is closest to the snapped point
- node: start or end node of Line in B that is closest to the snapped point (if B contains columns "start_node_name" and "end_node_name")
- snap_distance: distance between Point A and snapped point
- line_position: normalized distance of snapped point along Line in B from the start node (0.0) and end node (1.0)
- geometry: GeoPandas Point object of the snapped point
Expand Down Expand Up @@ -126,9 +126,12 @@ def snap(A, B, tolerance):
snapped_points = gpd.GeoDataFrame(data=closest ,geometry=snapped_points, crs=crs)
# determine whether the snapped point is closer to the start or end node
snapped_points["line_position"] = closest.geometry.project(snapped_points, normalized=True)
snapped_points.loc[snapped_points["line_position"]<0.5, "node"] = closest["start_node_name"]
snapped_points.loc[snapped_points["line_position"]>=0.5, "node"] = closest["end_node_name"]
snapped_points = snapped_points[["link", "node", "snap_distance", "line_position", "geometry"]]
if ("start_node_name" in closest.columns) and ("end_node_name" in closest.columns):
snapped_points.loc[snapped_points["line_position"]<0.5, "node"] = closest["start_node_name"]
snapped_points.loc[snapped_points["line_position"]>=0.5, "node"] = closest["end_node_name"]
snapped_points = snapped_points[["link", "node", "snap_distance", "line_position", "geometry"]]
else:
snapped_points = snapped_points[["link", "snap_distance", "line_position", "geometry"]]
snapped_points.index.name = None

return snapped_points
Expand Down
7 changes: 5 additions & 2 deletions wntr/tests/test_sim_performance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import unittest
import pytest
from os.path import abspath, dirname, join
import threading
import time
Expand Down Expand Up @@ -245,7 +246,8 @@ def test_Net3_performance_PDA(self):
rel_threshold,
)
)


@pytest.mark.time_consuming
def test_Net6_thread_performance(self):
"""
Test thread-safe performance of simulators
Expand Down Expand Up @@ -303,7 +305,8 @@ def run_wntr(wn, name):
t2.join()
thr_time = time.time()-start_time
self.assertGreaterEqual(seq_time - thr_time, -1, 'WNTR threading took 1s longer than sequential')


@pytest.mark.time_consuming
def test_Net6_mod_performance(self):
head_diff_abs_threshold = 1e-3
demand_diff_abs_threshold = 1e-5
Expand Down

0 comments on commit 79dd510

Please sign in to comment.