-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstream_window.py
More file actions
71 lines (57 loc) · 1.87 KB
/
Copy pathstream_window.py
File metadata and controls
71 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Stream a windowed read from a remote COG — no download required.
Demonstrates reading a small spatial window from a cloud-hosted tile
without downloading the full file.
Usage:
python stream_window.py
"""
import abovepy
def main():
# Search for a single DEM tile
print("Searching for DEM tiles...")
result = abovepy.search(
bbox=(-84.85, 38.18, -84.82, 38.21),
product="dem_phase3",
)
print(f"Found {result.count} tiles")
if result.empty:
print("No tiles found.")
return
# Stream a windowed read — only fetches the bytes within the bbox
url = result.tiles.iloc[0].asset_url
print(f"\nStreaming from: {url}")
print("Reading window bbox=(-84.85, 38.18, -84.82, 38.21)...")
data, profile = abovepy.read(
url,
bbox=(-84.85, 38.18, -84.82, 38.21),
)
print(f"\nArray shape: {data.shape}")
print(f"Data type: {data.dtype}")
print(f"CRS: {profile['crs']}")
print(f"Resolution: {profile['transform'][0]:.2f} x {-profile['transform'][4]:.2f}")
print(f"Value range: {data.min():.1f} - {data.max():.1f}")
# Plot if matplotlib is available
try:
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 6))
plt.imshow(data.squeeze(), cmap="terrain")
plt.colorbar(label="Elevation (ft)")
plt.title("Streamed DEM Window")
plt.axis("off")
plt.tight_layout()
plt.show()
except ImportError:
print("\nInstall matplotlib for visualization: pip install abovepy[viz]")
if __name__ == "__main__":
main()
# Expected output:
# Searching for DEM tiles...
# Found 2 tiles
#
# Streaming from: https://kyfromabove.s3.us-west-2...cog.tif
# Reading window bbox=(-84.85, 38.18, -84.82, 38.21)...
#
# Array shape: (1, 362, 300)
# Data type: float32
# CRS: EPSG:3089
# Resolution: 2.00 x 2.00
# Value range: 501.3 - 812.7