Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update download of 1" elevation data #272

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
certifi==2023.7.22
chardet==4.0.0
idna==2.10
numpy==1.21.0
Pillow==10.2.0
pyproj==3.1.0
requests==2.31.0
Rtree==0.9.7
Shapely==1.7.1
urllib3==1.26.18
numpy==1.26.4
Pillow
pyproj
requests
Rtree
Shapely
scikit-fmm
94 changes: 30 additions & 64 deletions src/O4_DEM_Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@ def read_elevation_from_file(
"value, assuming -32768.",
)
nodata = -32768
else:
# elevations being stored as float32, we push the nodata to that
# framework too, and then replace no_data values by -32768
else:
# elevations being stored as float32, we push the nodata to that
# framework too, and then replace no_data values by -32768
# anyway for uniformity
nodata = numpy.float32(nodata)
if not info_only:
Expand All @@ -536,8 +536,8 @@ def read_elevation_from_file(
if epsg not in (
4326,
4269,
):
# let's be blind about 4269 which might be sufficiently close to
):
# let's be blind about 4269 which might be sufficiently close to
# 4326 for our purposes
UI.lvprint(
1,
Expand Down Expand Up @@ -592,63 +592,25 @@ def read_elevation_from_file(
##############################################################################
def ensure_elevation(source, lat, lon, verbose=True):
if source == "View":
# Viewfinderpanorama grouping of files and resolutions is a
# Viewfinderpanorama grouping of files and resolutions is a
# bit complicated...
if (lat, lon) in (
(44, 5),
(45, 5),
(46, 5),
(43, 6),
(44, 6),
(45, 6),
(46, 6),
(47, 6),
(43, 7),
(44, 7),
(45, 7),
(46, 7),
(47, 7),
(45, 8),
(46, 8),
(47, 8),
(45, 9),
(46, 9),
(47, 9),
(45, 10),
(46, 10),
(47, 10),
(45, 11),
(46, 11),
(47, 11),
(45, 12),
(46, 12),
(47, 12),
(46, 13),
(47, 13),
(46, 14),
(47, 14),
(46, 15),
(47, 15),
):
resol = 1
url = (
"http://viewfinderpanoramas.org/dem1/"
+ os.path.basename(FNAMES.base_file_name(lat, lon)).lower()
+ ".zip"
)

deferranti_nbr = 31 + lon // 6
if deferranti_nbr < 10:
deferranti_nbr = "0" + str(deferranti_nbr)
else:
deferranti_nbr = 31 + lon // 6
if deferranti_nbr < 10:
deferranti_nbr = "0" + str(deferranti_nbr)
else:
deferranti_nbr = str(deferranti_nbr)
alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
deferranti_letter = (
alphabet[lat // 4] if lat >= 0 else alphabet[(-1 - lat) // 4]
)
if lat < 0:
deferranti_letter = "S" + deferranti_letter
if deferranti_letter + deferranti_nbr in (
deferranti_nbr = str(deferranti_nbr)
alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
deferranti_letter = (
alphabet[lat // 4] if lat >= 0 else alphabet[(-1 - lat) // 4]
)
if lat < 0:
deferranti_letter = "S" + deferranti_letter
if deferranti_letter + deferranti_nbr in (
"L31",
"L32",
"L33",
"K32",
"O31",
"P31",
"N32",
Expand All @@ -673,9 +635,13 @@ def ensure_elevation(source, lat, lon, verbose=True):
"R36",
):
resol = 1
else:
else:
resol = 3
url = (
# 3" DEM elevation data for Iceland
if deferranti_letter+str(deferranti_nbr) in ("Q27","Q28"):
deferranti_letter = "ISL"
deferranti_nbr = ""
url = (
"http://viewfinderpanoramas.org/dem"
+ str(resol)
+ "/"
Expand Down Expand Up @@ -719,7 +685,7 @@ def ensure_elevation(source, lat, lon, verbose=True):
if ("W" in fname) or ("w" in fname):
lon0 *= -1
out_filename = FNAMES.viewfinderpanorama(lat0, lon0)
# we don't wish to overwrite a 1" version by downloading
# we don't wish to overwrite a 1" version by downloading
# the whole archive of a nearby 3" one
if (
not os.path.exists(out_filename)
Expand All @@ -741,7 +707,7 @@ def ensure_elevation(source, lat, lon, verbose=True):
" WARNING : This elevation source has no longer direct downloads !"
)
return 0
# TODO : is there a way to get it back (worth it ?)
# TODO : is there a way to get it back (worth it ?)
url = "https://cloud.sdsc.edu/v1/AUTH_opentopography/Raster/"
if source == "SRTM":
url += "SRTM_GL1/SRTM_GL1_srtm/"
Expand Down