Skip to content

Commit 9b0a3a2

Browse files
committed
update requirements, add blob download
1 parent dbe3b12 commit 9b0a3a2

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

abd_model/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ numpy==1.19.1
55
osmium==3.0.1
66
Pillow==8.3.2
77
psycopg2-binary==2.8.5
8-
rasterio==1.1.5
8+
# rasterio==1.1.5
99
scikit-build==0.11.1
1010
Shapely>=1.7.0
1111
supermercado==0.1.1
1212
toml==0.10.1
13-
torch==1.6.0
14-
torchvision==0.7.0
13+
# torch==1.6.0
14+
# torchvision==0.7.0
1515
tqdm==4.48.2
1616
webcolors==1.11.1

ada_tools/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# This file is autogenerated by pip-compile
2+
azure-storage-blob==12.8.1
23
affine==2.3.0 # via ada_tools (setup.py), rasterio
34
attrs==19.3.0 # via ada_tools (setup.py), fiona, rasterio
45
beautifulsoup4==4.9.1 # via ada_tools (setup.py), bs4

ada_tools/src/ada_tools/check_alternative_buildings.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
import pandas as pd
77
import os
88
from ada_tools.align_raster import align, translate
9+
from azure.storage.blob import BlobServiceClient
910
from tqdm import tqdm
1011
from shapely.geometry import Polygon
1112

13+
14+
def download_blob(container, blobpath, filepath, secret):
15+
blob_service_client = BlobServiceClient.from_connection_string(secret)
16+
blob_client = blob_service_client.get_blob_client(container=container, blob=blobpath)
17+
with open(filepath, "wb") as download_file:
18+
download_file.write(blob_client.download_blob().readall())
19+
20+
1221
def get_extent(raster: str) -> gpd.GeoDataFrame:
1322
"""
1423
get extent of raster, return it as geodataframe
@@ -43,24 +52,28 @@ def get_extent(raster: str) -> gpd.GeoDataFrame:
4352

4453

4554
@click.command()
55+
@click.option('--ext', default='extents.geojson', help='input buildings extents')
4656
@click.option('--builds', default='input', help='input buildings directory')
57+
@click.option('--container', help='blob storage container')
58+
@click.option('--secret', help='blob storage secret')
4759
@click.option('--raster', default='input', help='input raster')
4860
@click.option('--refbuilds', default='buildings.geojson', help='input reference buildings')
4961
@click.option('--dest', default='buildings.geojson', help='output')
50-
def main(builds, raster, refbuilds, dest):
62+
def main(ext, builds, container, secret, raster, refbuilds, dest):
5163
"""
5264
check if builds cover raster, if yes align with refbuilds and save as dest
5365
"""
5466
build_target = gpd.GeoDataFrame()
5567
gdf_raster = get_extent(raster)
5668
xmin, ymin, xmax, ymax = gdf_raster.total_bounds
57-
gdf_builds_extents = gpd.read_file(os.path.join(builds, "extents.geojson"))
69+
gdf_builds_extents = gpd.read_file(ext)
5870
gdf_builds_extents = gdf_builds_extents.rename(columns={'file': 'alternative_buildings_file'})
5971
res_intersection = gpd.overlay(gdf_raster, gdf_builds_extents, how='intersection')
6072
if not res_intersection.empty:
6173
for ix, row in res_intersection.iterrows():
6274
build_file = row["alternative_buildings_file"]
63-
gdf_build = gpd.read_file(os.path.join(builds, build_file))
75+
download_blob(container, os.path.join(builds, build_file), build_file, secret)
76+
gdf_build = gpd.read_file(build_file)
6477
gdf_build_in_raster = gdf_build.cx[xmin:xmax, ymin:ymax]
6578
if not gdf_build_in_raster.empty:
6679
build_target = build_target.append(gdf_build_in_raster, ignore_index=True)

0 commit comments

Comments
 (0)