Skip to content

Commit f3b861c

Browse files
committed
Refactor conditional image download function code
1 parent dacd8f3 commit f3b861c

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

label_maker/images.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88

9-
from label_maker.utils import download_tile_tms, get_tile_tif, is_tif, is_wms, get_tile_wms
9+
from label_maker.utils import get_image_function
1010

1111
def download_images(dest_folder, classes, imagery, ml_type, background_ratio, imagery_offset=False, **kwargs):
1212
"""Download satellite images specified by a URL and a label.npz file
@@ -69,11 +69,7 @@ def class_test(value):
6969
print('Downloading {} tiles to {}'.format(len(tiles), tiles_dir))
7070

7171
# get image acquisition function based on imagery string
72-
image_function = download_tile_tms
73-
if is_tif(imagery):
74-
image_function = get_tile_tif
75-
if is_wms(imagery):
76-
image_function = get_tile_wms
72+
image_function = get_image_function(imagery)
7773

7874
for tile in tiles:
7975
image_function(tile, imagery, tiles_dir, imagery_offset)

label_maker/preview.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
from PIL import Image, ImageDraw
99

10-
from label_maker.utils import class_match, download_tile_tms, get_tile_tif, is_tif, get_tile_wms, is_wms
10+
from label_maker.utils import class_match, get_image_function
1111

1212
def preview(dest_folder, number, classes, imagery, ml_type, imagery_offset=False, **kwargs):
1313
"""Produce imagery examples for specified classes
@@ -48,11 +48,7 @@ def preview(dest_folder, number, classes, imagery, ml_type, imagery_offset=False
4848
print('Writing example images to {}'.format(examples_dir))
4949

5050
# get image acquisition function based on imagery string
51-
image_function = download_tile_tms
52-
if is_tif(imagery):
53-
image_function = get_tile_tif
54-
if is_wms(imagery):
55-
image_function = get_tile_wms
51+
image_function = get_image_function(imagery)
5652

5753
for i, cl in enumerate(classes):
5854
# create class directory

label_maker/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,11 @@ def is_tif(imagery):
122122
def is_wms(imagery):
123123
"""Determine if an imagery path is a WMS endpoint"""
124124
return '{bbox}' in imagery
125+
126+
def get_image_function(imagery):
127+
"""Return the correct image downloading function based on the imagery string"""
128+
if is_tif(imagery):
129+
return get_tile_tif
130+
if is_wms(imagery):
131+
return get_tile_wms
132+
return download_tile_tms

0 commit comments

Comments
 (0)