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 getDEM to use the new dem-stitcher API #342

Merged
merged 2 commits into from
Jun 10, 2022
Merged
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
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ dependencies:
- pytest-timeout
- pip
- pip:
- dem_stitcher
- dem_stitcher==2.1.1
- boto3
- geopandas
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ dependencies:
- xarray
- pip
- pip:
- dem_stitcher
- dem_stitcher==2.1.1
- boto3
- geopandas
2 changes: 1 addition & 1 deletion test/test_dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_isInside(llsimple):
@pytest.mark.long
def test_getDEM(tmp_path):
with pushd(tmp_path):
getDEM([18.5, 18.9, -73.2, -72.8], tmp_path)
getDEM([18.5, 18.9, -73.2, -72.8], os.path.join(tmp_path, 'test.dem'))


def test_isNDArray():
Expand Down
27 changes: 15 additions & 12 deletions tools/RAiDER/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from osgeo import gdal
from pyproj import Proj
from shapely.geometry import shape, Polygon
from dem_stitcher.stitcher import download_dem as download_stitched_dem
from dem_stitcher.stitcher import stitch_dem as download_stitched_dem

import RAiDER.utilFcns

Expand Down Expand Up @@ -156,11 +156,12 @@ def download_dem(
# Otherwise download a new DEM
if do_download:
folder = os.sep.join(os.path.split(outName)[:-1])
fname = os.path.split(outName)[-1]
full_res_dem = getDEM(inExtent, folder)
full_res_dem = os.path.join(folder, 'GLO30.dem')
logger.info('I am downloading a new DEM')
getDEM(inExtent, full_res_dem)
_, _, _, geoProj, trans, noDataVal, _ = readRaster(full_res_dem)
logger.info('DEM download complete')
out = gdal_open(full_res_dem)
logger.info('I am downloading a new DEM')

out = out[::-1]
# Interpolate to the query points
Expand Down Expand Up @@ -262,7 +263,7 @@ def isInside(extent1, extent2):


def getDEM(extent: list,
out_dir: str = os.getcwd(),
dem_path: str,
dem_name: str = 'glo_30',
num_threads: int = 5) -> str:
"""Downloads tiles, merges, and gets ellipsoidal height of DEM. Output
Expand All @@ -286,20 +287,22 @@ def getDEM(extent: list,
Absolute path of the downloaded file. This will be area centered
centered coordinates for agreement with weather model.
"""

if num_threads > 5:
warn('More than 5 threads may be problematic for downloading '
'large tiles')
bounds = [extent[2],
extent[0],
extent[3],
extent[1]]
dem_path = download_stitched_dem(bounds,
dem_name,
out_dir,
dst_area_or_point='Area',
max_workers=num_threads)
return str(dem_path.absolute())
download_stitched_dem(
bounds,
dem_name,
dem_path,
dst_ellipsoidal_height=True, # use the ellipsoidal heights
dst_area_or_point='Area',
max_workers=num_threads,
)


def getArea(extent):
Expand Down