Skip to content

Commit b8d69da

Browse files
committed
refactor
1 parent f0e79e4 commit b8d69da

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ When API key is reday, you can download DEM data like this:
1616
bbox = 108.444319, 20.161757, 111.318897, 18.05883
1717

1818
terrain = Terrain("Dto0r88DQuaQizoxcQSxxx")
19-
xs, ys, elevation = terrain.fetch(bbox=bbox, progress_bar=True, coord="lonlat", zoom=10)
19+
xs, ys, elevation = terrain.fetch(bbox=bbox, quiet=False, coord="lonlat", zoom=12)
2020
```
2121

2222
If download is not complete because of connection, retry it.

pyterrain/core.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@ def fetch(
7979
self,
8080
bbox: List,
8181
zoom: int = None,
82-
progress_bar=False,
8382
timeout=10,
8483
cache_path="./cache",
8584
keep_cache=True,
8685
coord="xy",
8786
multiproc=4,
87+
quiet=False,
8888
) -> tuple:
89+
if quiet:
90+
progress_bar = False
91+
else:
92+
progress_bar = True
8993

9094
left, upper, right, lower = bbox
9195
if zoom is None:
@@ -149,18 +153,20 @@ def fetch(
149153
if not os.path.exists(tmpfp):
150154
task_args.append([url, tmpfp, timeout])
151155

152-
with Pool(multiproc) as p:
153-
result = list(
154-
tqdm(
155-
p.imap_unordered(single_download, task_args),
156-
total=len(task_args),
157-
desc="downloading",
158-
),
159-
)
160-
try:
161-
assert all(result)
162-
except AssertionError:
163-
raise Exception("Not download completely, please retry")
156+
if task_args:
157+
with Pool(multiproc) as p:
158+
result = list(
159+
tqdm(
160+
p.imap_unordered(single_download, task_args),
161+
total=len(task_args),
162+
desc="downloading",
163+
),
164+
)
165+
166+
try:
167+
assert all(result)
168+
except AssertionError:
169+
raise Exception("Not download completely, please retry")
164170

165171
for (nx, ny), (x, y), url in tqdm(
166172
urls, disable=not progress_bar, desc="mosaicing"
@@ -176,11 +182,12 @@ def fetch(
176182
blue = canvas[..., 2]
177183
elevation = ((red * 256 + green + blue / 256) - 32768).astype(int)[idx]
178184

179-
print(f"bbox: {bbox}")
180-
print(f"zoom: {zoom}")
181-
print(f"mean of elevation: {int(elevation.mean())}")
182-
print(f"max of elevation: {elevation.max()}")
183-
print(f"min of elevation: {elevation.min()}")
185+
if not quiet:
186+
print(f"bbox: {bbox}")
187+
print(f"zoom: {zoom}")
188+
print(f"mean of elevation: {int(elevation.mean())}")
189+
print(f"max of elevation: {elevation.max()}")
190+
print(f"min of elevation: {elevation.min()}")
184191

185192
if not keep_cache:
186193
shutil.rmtree(cache_path)

sample/zelda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
terrain = Terrain("qBD4m7PNT5apV-Xl7PROxA")
1414

15-
xs, ys, elevation = terrain.fetch(bbox=bbox, progress_bar=True, coord="lonlat", zoom=12)
15+
xs, ys, elevation = terrain.fetch(bbox=bbox, quiet=False, coord="lonlat", zoom=12)
1616

1717
land = copy.deepcopy(elevation)
1818
land[land < 0] = -9999

0 commit comments

Comments
 (0)