Skip to content

Commit

Permalink
- add a test for comparing earth_osm with osmium
Browse files Browse the repository at this point in the history
- update test dependencies
  • Loading branch information
mnm-matin committed Mar 13, 2024
1 parent 9144265 commit 2ccbcf2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ flake8
black
isort
pytest-cov
codecov
mypy>=0.9
gitchangelog
mkdocs
pprint
osmium

28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ def read(*paths, **kwargs):
content = open_file.read().strip()
return content

# mirror of dependencies in setup and requirements.txt
install_requires=[
"geopandas",
"pandas",
"tqdm",
"requests",
"protobuf>=4.21.1",
]

extras_require={"test": [
"pytest",
"coverage",
"flake8",
"black",
"isort",
"pytest-cov",
"codecov",
"mypy>=0.9",
"gitchangelog",
"mkdocs",
"pprint",
"osmium",
]
}

assert read("requirements.txt") == "\n".join(install_requires)
assert read("requirements-test.txt") == "\n".join(extras_require["test"])

setup(
name="earth_osm",
Expand Down Expand Up @@ -52,6 +79,7 @@ def read(*paths, **kwargs):
"mypy>=0.9",
"gitchangelog",
"mkdocs",
"osmium",
],
},
classifiers=[
Expand Down
61 changes: 61 additions & 0 deletions tests/test_osmium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import osmium
import pandas as pd
from earth_osm.eo import get_osm_data

class PowerLineHandler(osmium.SimpleHandler):
def __init__(self):
super().__init__()
self.power_lines = []

def way(self, w):
if 'power' in w.tags and w.tags['power'] == 'line':
for node in w.nodes:
location = osmium.osm.Location(node.lon, node.lat)
self.power_lines.append({
'id': w.id,
'version': w.version,
'visible': w.visible,
'timestamp': w.timestamp,
'uid': w.uid,
'user': w.user,
'changeset': w.changeset,
'latitude': location.lat if location else None,
'longitude': location.lon if location else None,
})

def get_dataframe(self):
return pd.DataFrame(self.power_lines)


def test_osmium(shared_data_dir):
region = "nigeria"
primary_name = "power"
feature_name = "line"
mp = True
update = False
data_dir = shared_data_dir

df = get_osm_data(
region,
primary_name,
feature_name,
data_dir=data_dir
)

pbf_fp = os.path.join(shared_data_dir, "pbf", f"{region}-latest.osm.pbf")

omsium_handler = PowerLineHandler()
omsium_handler.apply_file(pbf_fp, locations=True)



df2 = omsium_handler.get_dataframe()

df2.drop_duplicates(subset='id', inplace=True)

assert len(df) == len(df2), f"Lengths are not equal: {len(df)} != {len(df2)}"


if __name__ == "__main__":
test_osmium('earth_data_test')

0 comments on commit 2ccbcf2

Please sign in to comment.