Skip to content

Commit

Permalink
add mock overpass file
Browse files Browse the repository at this point in the history
  • Loading branch information
mnm-matin committed Oct 6, 2024
1 parent 0329d51 commit f47402d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
4 changes: 3 additions & 1 deletion earth_osm/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
║ Earth-OSM ║
║ "Empowering Open Infrastructure ║
║ Data for the People" ║
║ - @mnm-matin ║
╚═══════════════════════════════════════╝
"""

Expand Down Expand Up @@ -60,6 +59,7 @@ def setup_extract_parser(subparsers):
extract_parser.add_argument('--data_dir', type=str, help='Earth Data Directory')
extract_parser.add_argument('--out_dir', type=str, help='Earth Output Directory')
extract_parser.add_argument('--out_format', nargs="*", type=str, choices=['csv', 'geojson'], default=['csv', 'geojson'], help='Export options')
extract_parser.add_argument('--source', type=str, choices=['geofabrik', 'overpass'], default='geofabrik', help='Data Source')

agg_group = extract_parser.add_mutually_exclusive_group()
agg_group.add_argument('--agg_feature', action='store_true', help='Aggregate Outputs by feature')
Expand Down Expand Up @@ -110,6 +110,7 @@ def handle_extract(args):
f'Output Directory = {out_dir}',
f'Output Format = {" - ".join(args.out_format)}',
f'Aggregate Outputs = {out_aggregate}',
f'Data Source = {args.source}'
]))

save_osm_data(
Expand All @@ -122,6 +123,7 @@ def handle_extract(args):
mp=not args.no_mp,
out_format=set(args.out_format),
out_aggregate=out_aggregate,
data_source=args.source
)

def handle_view(args):
Expand Down
24 changes: 15 additions & 9 deletions earth_osm/eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import warnings
warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)

from earth_osm.overpass import get_overpass_data
from earth_osm.tagdata import get_feature_list
from earth_osm.filter import get_filtered_data
from earth_osm.gfk_data import get_region_tuple, view_regions
Expand All @@ -26,7 +27,7 @@
logger = logging.getLogger("eo.eo")
logger.setLevel(logging.INFO)

def process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=True):
def process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=True, data_source='geofabrik'):
"""
Process Country
Expand All @@ -40,7 +41,11 @@ def process_region(region, primary_name, feature_name, mp, update, data_dir, pro
Returns:
None
"""
primary_dict, feature_dict = get_filtered_data(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar)

if data_source == 'geofabrik':
primary_dict, feature_dict = get_filtered_data(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar)
elif data_source == 'overpass':
primary_dict, feature_dict = get_overpass_data(region, primary_name, feature_name, data_dir, progress_bar=progress_bar)

primary_data = primary_dict['Data']
feature_data = feature_dict['Data']
Expand Down Expand Up @@ -132,12 +137,13 @@ def save_osm_data(
region_list,
primary_name,
feature_list=None,
update=False,
mp=True, # TODO: remove mp arg
data_dir=os.path.join(os.getcwd(), 'earth_data'),
out_dir=os.path.join(os.getcwd(), 'earth_data'),
out_format="csv", # TODO: rename out_format -> format
out_aggregate=True, # TODO: rename out_aggregate -> aggregate
out_dir=os.path.join(os.getcwd(), 'earth_data'),
data_source = 'geofabrik', # 'overpass'
data_dir=os.path.join(os.getcwd(), 'earth_data'),
update=False,
mp=True, # TODO: remove mp arg,
progress_bar=True
):
"""
Expand Down Expand Up @@ -165,7 +171,7 @@ def save_osm_data(
for feature_name in feature_list:
with EarthOSMWriter(region_short_list, primary_name, [feature_name], out_dir, out_format) as writer:
for region in region_tuple_list:
df_feature = process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar)
df_feature = process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar, data_source=data_source)
writer(df_feature)
# output_creation(df_feature, primary_name, [feature_name], region_short_list, data_dir, out_format)

Expand All @@ -174,14 +180,14 @@ def save_osm_data(
for region in region_tuple_list:
with EarthOSMWriter([region.short], primary_name, feature_list, out_dir, out_format) as writer:
for feature_name in feature_list:
df_feature = process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar)
df_feature = process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar, data_source=data_source)
writer(df_feature)

elif out_aggregate is False:
# no aggregation, one file per region per feature
for region in region_tuple_list:
for feature_name in feature_list:
df_feature = process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar)
df_feature = process_region(region, primary_name, feature_name, mp, update, data_dir, progress_bar=progress_bar, data_source=data_source)
with EarthOSMWriter([region.short], primary_name, [feature_name], out_dir, out_format) as writer:
writer(df_feature)

Expand Down
17 changes: 17 additions & 0 deletions earth_osm/overpass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

def get_overpass_data(region, primary_name, feature_name, data_dir, progress_bar):
# returns data of the following form:
# https://github.com/pypsa-meets-earth/earth-osm/issues/54

print('\n'.join(['',
f'-------- Overpass Function------- ',
f'Primary Feature: {primary_name}',
f'Feature Name: {feature_name}',
f'Region Short: {region.short}',
f'Data Directory = {data_dir}',
f'Progress Bar = {progress_bar}'
]))


# return op_dict, op_dict # hacky solution right now to return the same data twice
raise NotImplementedError

0 comments on commit f47402d

Please sign in to comment.