Skip to content

Commit 6f3a154

Browse files
committed
Pass tiles directory as a parameter, don't hardcode
1 parent 9266236 commit 6f3a154

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

label_maker/images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def class_test(value):
6666

6767
# download tiles
6868
tiles = class_tiles + background_tiles
69-
print('Downloading {} tiles to {}'.format(len(tiles), op.join(dest_folder, 'tiles')))
69+
print('Downloading {} tiles to {}'.format(len(tiles), tiles_dir))
7070

7171
# get image acquisition function based on imagery string
7272
image_function = download_tile_tms
7373
if is_tif(imagery):
7474
image_function = get_tile_tif
7575

7676
for tile in tiles:
77-
image_function(tile, imagery, dest_folder, imagery_offset)
77+
image_function(tile, imagery, tiles_dir, imagery_offset)

label_maker/preview.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ def preview(dest_folder, number, classes, imagery, ml_type, imagery_offset=False
5656
# create class directory
5757
class_dir = op.join(dest_folder, 'examples', cl.get('name'))
5858

59-
# the download process downloads into a tiles subdirectory so create that here
60-
class_tile_dir = op.join(class_dir, 'tiles')
61-
62-
if not op.isdir(class_tile_dir):
63-
makedirs(class_tile_dir)
59+
if not op.isdir(class_dir):
60+
makedirs(class_dir)
6461

6562
class_tiles = (t for t in tiles.files
6663
if class_match(ml_type, tiles[t], i + 1))

label_maker/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ def class_match(ml_type, label, i):
2424
return np.count_nonzero(label == i)
2525
return None
2626

27-
def download_tile_tms(tile, imagery, dest_folder, *args):
27+
def download_tile_tms(tile, imagery, folder, *args):
2828
"""Download a satellite image tile from a tms endpoint"""
2929
o = urlparse(imagery)
3030
_, image_format = op.splitext(o.path)
3131
r = requests.get(url(tile.split('-'), imagery))
32-
tile_img = op.join(dest_folder, 'tiles', '{}{}'.format(tile, image_format))
32+
tile_img = op.join(folder, '{}{}'.format(tile, image_format))
3333
open(tile_img, 'wb').write(r.content)
3434
return tile_img
3535

36-
def get_tile_tif(tile, imagery, dest_folder, imagery_offset):
36+
def get_tile_tif(tile, imagery, folder, imagery_offset):
3737
"""
3838
Read a GeoTIFF with a window corresponding to a TMS tile
3939
@@ -80,7 +80,7 @@ def get_tile_tif(tile, imagery, dest_folder, imagery_offset):
8080
src.read(k, window=window, out=data[k - 1], boundless=True)
8181

8282
# save
83-
tile_img = op.join(dest_folder, 'tiles', '{}{}'.format(tile, '.jpg'))
83+
tile_img = op.join(folder, '{}{}'.format(tile, '.jpg'))
8484
img = Image.fromarray(np.moveaxis(data, 0, -1), mode='RGB')
8585
img.save(tile_img)
8686

0 commit comments

Comments
 (0)