Skip to content

Commit

Permalink
Update kwargs for handling http auth
Browse files Browse the repository at this point in the history
  • Loading branch information
wronk committed Nov 11, 2019
1 parent fc02c04 commit b5c865a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion label_maker/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def class_test(value):
image_function = get_image_function(imagery)

for tile in tiles:
image_function(tile, imagery, tiles_dir, imagery_offset)
image_function(tile, imagery, tiles_dir, imagery_offset, kwargs)
3 changes: 2 additions & 1 deletion label_maker/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def preview(dest_folder, number, classes, imagery, ml_type, imagery_offset=False
if n >= number:
break

tile_img = image_function(tile, imagery, class_dir, imagery_offset)
tile_img = image_function(tile, imagery, class_dir, imagery_offset,
kwargs)

if ml_type == 'object-detection':
img = Image.open(tile_img)
Expand Down
11 changes: 6 additions & 5 deletions label_maker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ def class_match(ml_type, label, i):
return np.count_nonzero(label == i)
return None

def download_tile_tms(tile, imagery, folder, *args):
def download_tile_tms(tile, imagery, folder, kwargs):
"""Download a satellite image tile from a tms endpoint"""
o = urlparse(imagery)
_, image_format = op.splitext(o.path)
r = requests.get(url(tile.split('-'), imagery))
r = requests.get(url(tile.split('-'), imagery),
auth=kwargs.get('http_auth'))
tile_img = op.join(folder, '{}{}'.format(tile, image_format))
with open(tile_img, 'wb')as w:
w.write(r.content)
return tile_img

def get_tile_tif(tile, imagery, folder, imagery_offset):
def get_tile_tif(tile, imagery, folder, imagery_offset, kwargs):
"""
Read a GeoTIFF with a window corresponding to a TMS tile
Expand Down Expand Up @@ -87,7 +88,7 @@ def get_tile_tif(tile, imagery, folder, imagery_offset):

return tile_img

def get_tile_wms(tile, imagery, folder, imagery_offset):
def get_tile_wms(tile, imagery, folder, imagery_offset, kwargs):
"""
Read a WMS endpoint with query parameters corresponding to a TMS tile
Expand Down Expand Up @@ -118,7 +119,7 @@ def get_tile_wms(tile, imagery, folder, imagery_offset):

# request the image with the transformed bounding box and save
wms_url = imagery.replace('{bbox}', ','.join([str(b) for b in bbox]))
r = requests.get(wms_url)
r = requests.get(wms_url, auth=kwargs.get('http_auth'))
tile_img = op.join(folder, '{}.{}'.format(tile, image_format))
with open(tile_img, 'wb') as w:
w.write(r.content)
Expand Down

0 comments on commit b5c865a

Please sign in to comment.