Skip to content

Commit e0932e9

Browse files
committed
Add wrapper scripts using the new OSM submodule.
1 parent 740c7c3 commit e0932e9

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

exploratory/osm_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99
import datetime
1010
import os
11-
from openpois.osm_download import (
11+
from openpois.osm.download import (
1212
build_date_range,
1313
collect_element_ids,
1414
download_element_histories,

exploratory/osm_format_tabular.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Exploratory script for reformatting OSM data into a tabular format.
3+
4+
This script:
5+
1. Reads in the OSM versions and changes data from CSV files.
6+
2. Reconfigures POI changesets into 'observations', which are either changes to the
7+
relevant POI tag or confirmation that the tag is unchanged.
8+
3. Saves the observations to a new CSV file.
9+
"""
10+
11+
import pandas as pd
12+
from pathlib import Path
13+
14+
from openpois.osm.format_observations import format_observations
15+
16+
17+
# ----------------------------------------------------------------------------------------
18+
# Configuration constants
19+
# ----------------------------------------------------------------------------------------
20+
21+
DATA_VERSION = "20260129"
22+
SAVE_DIR = Path("~/data/openpois").expanduser() / DATA_VERSION
23+
OSM_KEYS = ["amenity", "shop", "healthcare", "leisure"]
24+
TAG_KEY = "shop"
25+
26+
27+
# ----------------------------------------------------------------------------------------
28+
# Main workflow
29+
# ----------------------------------------------------------------------------------------
30+
31+
if __name__ == "__main__":
32+
# Read files
33+
changes_df = pd.read_csv(SAVE_DIR / "osm_changes.csv")
34+
versions_df = pd.read_csv(SAVE_DIR / "osm_versions.csv")
35+
36+
# Format changes and versions into observations
37+
observations_df = format_observations(
38+
changes_df = changes_df,
39+
versions_df = versions_df,
40+
tag_key = TAG_KEY,
41+
keep_keys = OSM_KEYS,
42+
)
43+
44+
# Save observations
45+
observations_df.to_csv(
46+
SAVE_DIR / f"osm_observations_{TAG_KEY}.csv",
47+
index = False,
48+
)
49+
print(f"Saved {len(observations_df)} observations to {out_fp}")

0 commit comments

Comments
 (0)