Last active
May 3, 2024 20:44
-
-
Save celoyd/1888e517a9a5e397a554681c46cdc3b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import io | |
from pathlib import Path | |
from sys import argv | |
srtm_dir = Path(argv[1]) | |
width = 3601 # pixel width of one of these srtm tiffs | |
starting_lon = -2 | |
ending_lon = 143 | |
def format_lon(lon): | |
# convert -1 -> "W001", 17 -> "E017", etc. | |
ew = "E" if lon >= 0 else "W" | |
lon = abs(lon) | |
return f"{ew}{lon:03}" | |
def make_tiff_path(lon): | |
lon = format_lon(lon) | |
path = Path(srtm_dir / f"N52{lon}.tif") | |
return path | |
def row(lon): | |
path = make_tiff_path(lon) | |
if path.is_file(): | |
row = io.imread(path)[0, :] | |
else: | |
# This will be a list, not a numpy array. | |
# We’ll just `for` through it, so it doesn’t matter. | |
row = [0] * width | |
return row | |
for lon in range(starting_lon, ending_lon + 1): | |
r = row(lon) | |
for e in r: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment