Skip to content

Commit

Permalink
full fua testing for simplify_network() (#41)
Browse files Browse the repository at this point in the history
* curate full FUA testing data

* add full fua simplify_network() tests

* bump 4/5 tolerance to 0.2 – test_simplify_network_full_fua()

* try uploading osberved artifacts

* try uploading osberved artifacts [2]

* try uploading osberved artifacts [3]

* try uploading osberved artifacts [4]

* try uploading osberved artifacts [5]

* try uploading osberved artifacts [6]

* try uploading osberved artifacts [7]

* try uploading osberved artifacts [8]

* try uploading osberved artifacts [9]

* try uploading osberved artifacts [10]

* upload osberved artifacts

* try uploading osberved artifacts [11]

* try uploading osberved artifacts [12]

* known simplified from ci_artifacts-ubuntu-latest-py312_sgeop-latest

* run equality tests only on Ubuntu + latest/dev CI envs

* codecov

---------

Co-authored-by: Martin Fleischmann <[email protected]>
  • Loading branch information
jGaboardi and martinfleis authored Oct 16, 2024
1 parent 92579a9 commit 5c033a4
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 12 deletions.
36 changes: 27 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@
name: ${{ matrix.os }}, ${{ matrix.environment-file }}
runs-on: ${{ matrix.os }}
timeout-minutes: 30
continue-on-error: true
strategy:
matrix:
os: [ubuntu-latest]
environment-file: [
ci/py311_sgeop-oldest.yaml,
ci/py311_sgeop-latest.yaml,
ci/py312_sgeop-latest.yaml,
ci/py312_sgeop-dev.yaml,
py311_sgeop-oldest,
py311_sgeop-latest,
py312_sgeop-latest,
py312_sgeop-dev,
]
include:
- environment-file: ci/py312_sgeop-latest.yaml
- environment-file: py312_sgeop-latest
os: macos-13 # Intel
- environment-file: ci/py312_sgeop-latest.yaml
- environment-file: py312_sgeop-latest
os: macos-14 # Apple Silicon
- environment-file: ci/py312_sgeop-latest.yaml
- environment-file: py312_sgeop-latest
os: windows-latest
fail-fast: false

Expand All @@ -51,7 +52,7 @@
- name: setup micromamba
uses: mamba-org/setup-micromamba@v2
with:
environment-file: ${{ matrix.environment-file }}
environment-file: ci/${{ matrix.environment-file }}.yaml
micromamba-version: "latest"

- name: install package
Expand All @@ -71,7 +72,24 @@
--cov core \
--cov-append \
--cov-report term-missing \
--cov-report xml .
--cov-report xml . \
--env_type ${{ matrix.environment-file }}
- name: zip artifacts - Ubuntu & macOS
run: zip ci_artifacts.zip ci_artifacts -r
if: matrix.os != 'windows-latest' && (success() || failure())

- name: zip artifacts - Windows
shell: powershell
run: Compress-Archive -Path ci_artifacts -Destination ci_artifacts.zip
if: matrix.os == 'windows-latest' && (success() || failure())

- name: archive observed simplified networks
uses: actions/upload-artifact@v4
with:
name: ci_artifacts-${{ matrix.os }}-${{ matrix.environment-file }}
path: ci_artifacts.zip
if: success() || failure()

- name: codecov
uses: codecov/codecov-action@v4
25 changes: 25 additions & 0 deletions data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# FUA testing data

## Contents

* This `README.md`
* `generate_simplified.py` – see [sgeop#7](https://github.com/uscuni/sgeop/issues/7)
* Data
* There is a directory for each FUA listed below that contains 2 files:
* `original.parquet`: The original input street network derived from [OSM](https://www.openstreetmap.org/about) via [OSMNX](https://osmnx.readthedocs.io/en/stable/).
* `simplified.parquet`: The simplified street network following our algorithm with *default parameters*.

## FUA Information

| FUA | City | Shortand |
| --- | --- | --- |
| 1133 | Aleppo, Syria, Middle East / Asia | `aleppo_1133` |
| 869 | Auckland, New Zealand, Oceania / Asia | `auckland_869` |
| 809 | Douala, Cameroon, Africa | `douala_809` |
| 1656 | Liège, Belgium, Europe | `liege_1656` |
| 4617 | Bucaramanga, Colombia, S. America | `bucaramanga_4617` |
| 4881 | Salt Lake City, Utah, USA, N. America | `slc_4881` |

---------------------------------------

Copyright (c) 2024-, sgeop Developers
Binary file added data/aleppo_1133/original.parquet
Binary file not shown.
Binary file added data/aleppo_1133/simplified.parquet
Binary file not shown.
Binary file added data/auckland_869/original.parquet
Binary file not shown.
Binary file added data/auckland_869/simplified.parquet
Binary file not shown.
Binary file added data/bucaramanga_4617/original.parquet
Binary file not shown.
Binary file added data/bucaramanga_4617/simplified.parquet
Binary file not shown.
Binary file added data/douala_809/original.parquet
Binary file not shown.
Binary file added data/douala_809/simplified.parquet
Binary file not shown.
83 changes: 83 additions & 0 deletions data/generate_simplified.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import logging
import pathlib
import time

import geopandas

import sgeop

start_time = time.time()

logging.basicConfig(
filename="simplified_generation.log",
filemode="a",
format="%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s",
datefmt="%H:%M:%S",
level=logging.NOTSET,
)
logger = logging.getLogger(__name__)

logging.info("")
logging.info("")
logging.info(" |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|")
logging.info(" | Generating Simplified Street Networks |")
logging.info(" |_______________________________________|")
logging.info("")
logging.info("")
logging.info("")

fua_city = {
1133: "aleppo",
869: "auckland",
4617: "bucaramanga",
809: "douala",
1656: "liege",
4881: "slc",
}

# dict of cityname: fua ID
city_fua = {c: f for f, c in fua_city.items()}

for city, fua in city_fua.items():

t1 = time.time()
aoi = f"{city}_{fua}"

logging.info("")
logging.info("")
logging.info("")
logging.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>>")
logging.info("")
logging.info("")
logging.info(f" ** {aoi} **")
logging.info("")
logging.info("")

# input data
original = geopandas.read_parquet(pathlib.Path(aoi, "original.parquet"))

# output data
simplified = sgeop.simplify_network(original)
simplified.to_parquet(pathlib.Path(aoi, "simplified.parquet"))

t2 = round((time.time() - t1) / 60.0, 2)

logging.info("")
logging.info("")
logging.info(f"\t{aoi} runtime: {t2} minutes")
logging.info("")
logging.info("")
logging.info("")
logging.info("<<<< ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
logging.info("")

endtime_time = round((time.time() - start_time) / 60.0, 2)

logging.info("")
logging.info("")
logging.info(f"Total runtime: {endtime_time} minutes")
logging.info(
"========================================================================="
)
logging.info("")
logging.info("")
Binary file added data/liege_1656/original.parquet
Binary file not shown.
Binary file added data/liege_1656/simplified.parquet
Binary file not shown.
Binary file added data/slc_4881/original.parquet
Binary file not shown.
Binary file added data/slc_4881/simplified.parquet
Binary file not shown.
21 changes: 21 additions & 0 deletions sgeop/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import platform

import geopandas.testing
import numpy
import pandas
Expand Down Expand Up @@ -59,8 +61,27 @@ def geom_test(
).all()


def pytest_addoption(parser):
"""Add custom command line arguments."""

# flag for determining CI environment
parser.addoption(
"--env_type",
action="store",
default="latest",
help="Testing environment type label",
type=str,
)


def pytest_configure(config): # noqa: ARG001
"""PyTest session attributes, methods, etc."""

valid_env_types = ["oldest", "latest", "dev"]
pytest.env_type = config.getoption("env_type").split("-")[-1]
assert pytest.env_type in valid_env_types

pytest.ubuntu = "ubuntu" in platform.version().lower()

pytest.polygonize = polygonize
pytest.geom_test = geom_test
49 changes: 46 additions & 3 deletions sgeop/tests/test_simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,58 @@
import sgeop

test_data = pathlib.Path("sgeop", "tests", "data")
full_fua_data = pathlib.Path("data")

ac = "apalachicola"
ci_artifacts = pathlib.Path("ci_artifacts")


def test_simplify():
def test_simplify_network_small():
ac = "apalachicola"
known = geopandas.read_parquet(test_data / f"{ac}_simplified.parquet")
known_length = 69477.0

observed = sgeop.simplify_network(
geopandas.read_parquet(test_data / f"{ac}_original.parquet")
)
observed_length = observed.geometry.length.sum()

pytest.geom_test(known, observed)
# storing GH artifacts
artifact_dir = ci_artifacts / ac
artifact_dir.mkdir(parents=True, exist_ok=True)
observed.to_parquet(artifact_dir / "simplified.parquet")

assert pytest.approx(observed_length, rel=0.00001) == known_length

assert observed.shape == known.shape
assert_series_equal(known._status, observed._status)
pytest.geom_test(known, observed)


@pytest.mark.parametrize(
"aoi,tol,known_length",
[
("aleppo_1133", 2e-1, 4_361_625),
("auckland_869", 2e-1, 1_268_048),
("bucaramanga_4617", 2e-1, 1_681_011),
("douala_809", 1e-1, 2_961_364),
("liege_1656", 2e-1, 2_350_782),
("slc_4881", 2e-1, 1_762_456),
],
)
def test_simplify_network_full_fua(aoi, tol, known_length):
known = geopandas.read_parquet(full_fua_data / aoi / "simplified.parquet")
observed = sgeop.simplify_network(
geopandas.read_parquet(full_fua_data / aoi / "original.parquet")
)
observed_length = observed.geometry.length.sum()

# storing GH artifacts
artifact_dir = ci_artifacts / aoi
artifact_dir.mkdir(parents=True, exist_ok=True)
observed.to_parquet(artifact_dir / "simplified.parquet")

assert pytest.approx(observed_length, rel=0.0001) == known_length

if pytest.ubuntu and pytest.env_type != "oldest":
assert_series_equal(known._status, observed._status)
pytest.geom_test(known, observed, tolerance=tol)

0 comments on commit 5c033a4

Please sign in to comment.