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

Change nodata in rtc dem #464

Merged
merged 21 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
07db724
use envelope of the map-overlay.kml to get the dem files
cirrusasf Jun 17, 2023
f08aeb1
new get_envelope function
cirrusasf Jun 19, 2023
8eb6f07
add get_develope_geometry function and output dem.tif without setting…
cirrusasf Jun 20, 2023
9a4e750
modify get_envelope_geometry function in the dem.py
cirrusasf Jun 20, 2023
c4b4996
modify rtc_sentinel.py
cirrusasf Jun 20, 2023
96fc4ff
modify hyp3_gamma/dem.py
cirrusasf Jun 22, 2023
6bde133
update the CHAGELOG.md
cirrusasf Jun 22, 2023
7eb0c3d
modify the code style
cirrusasf Jun 22, 2023
b12a61f
merge develop to feature branch
cirrusasf Jul 28, 2023
32fc122
modify the dem.py
cirrusasf Jul 28, 2023
28dbe12
refactor the get_envelope_geometry function in the dem.py
cirrusasf Jul 28, 2023
f1662c6
modify the code style
cirrusasf Jul 28, 2023
7770862
add test_get_envelope_geometry function in the test_dem.py
cirrusasf Jul 31, 2023
d5caeb3
do test for get_envelope_geometry with two geometries, one is normal,…
cirrusasf Jul 31, 2023
a4c7718
Refactor `get_envelope_geometry`
jtherrmann Aug 1, 2023
c884d59
Merge pull request #471 from ASFHyP3/jth-change_nodata_in_rtc_dem
jtherrmann Aug 1, 2023
77b92ee
do not use envelope to produce the input dem.tif
cirrusasf Aug 11, 2023
17c22c2
Merge branch 'develop' into change_nodata_in_rtc_dem
cirrusasf Aug 11, 2023
9ccf324
Merge branch 'change_nodata_in_rtc_dem' of github.com:ASFHyP3/hyp3-ga…
cirrusasf Aug 11, 2023
427d4a9
get rid of the method of using larger envelop to deterime the input d…
cirrusasf Aug 11, 2023
bd600b0
remove the test function for larger envelop
cirrusasf Aug 11, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.2.4]

### Changed
- Use the envelope of the map-overlay.kml to determine the input dem.tif
- Remove the NoData setting in the output dem.tif

## [6.2.3]

### Added
Expand Down
23 changes: 23 additions & 0 deletions hyp3_gamma/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ def shift_for_antimeridian(dem_file_paths: List[str], directory: Path) -> List[s
return shifted_file_paths


def get_envelope_geometry(geometry):
# get the envelope of the geometry
geometry_out = ogr.Geometry(ogr.wkbMultiPolygon)
geoms = [g for g in geometry]
boxes = []
for g in geoms:
boxes.append(g.GetEnvelope())

minlat = min([x[2] for x in boxes])
maxlat = max([x[3] for x in boxes])

for item in boxes:
wkt = f'POLYGON (({item[0]} {minlat}, {item[0]} {maxlat}, {item[1]} {maxlat}, {item[1]} {minlat},' \
f' {item[0]} {minlat}))'
poly = ogr.CreateGeometryFromWkt(wkt)
geometry_out.AddGeometry(poly)

return geometry_out


def prepare_dem_geotiff(output_name: str, geometry: ogr.Geometry, pixel_size: float = 30.0):
"""Create a DEM mosaic GeoTIFF covering a given geometry.

Expand All @@ -99,11 +119,14 @@ def prepare_dem_geotiff(output_name: str, geometry: ogr.Geometry, pixel_size: fl
with TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)

geometry = get_envelope_geometry(geometry)
jtherrmann marked this conversation as resolved.
Show resolved Hide resolved

centroid = geometry.Centroid()
dem_file_paths = get_dem_file_paths(geometry.Buffer(0.15))

if geometry.GetGeometryName() == 'MULTIPOLYGON':
centroid = get_centroid_crossing_antimeridian(geometry)

dem_file_paths = shift_for_antimeridian(dem_file_paths, temp_path)

dem_vrt = temp_path / 'dem.vrt'
Expand Down
4 changes: 3 additions & 1 deletion hyp3_gamma/rtc/rtc_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def prepare_dem(safe_dir: str, dem_name: str, bbox: List[float] = None, dem: str
geometry = ogr.CreateGeometryFromWkt(wkt)
else:
geometry = get_geometry_from_kml(f'{safe_dir}/preview/map-overlay.kml')

prepare_dem_geotiff(dem_tif, geometry, pixel_size)
run(f'dem_import {dem_tif} {dem_image} {dem_par} - - $DIFF_HOME/scripts/egm2008-5.dem '
f'$DIFF_HOME/scripts/egm2008-5.dem_par - - - 1')
Expand Down Expand Up @@ -390,7 +391,8 @@ def rtc_sentinel_gamma(safe_dir: str, resolution: float = 30.0, radiometry: str
if include_dem:
with NamedTemporaryFile() as temp_file:
run(f'data2geotiff dem_seg.par dem_seg 2 {temp_file.name}')
gdal.Translate(f'{product_name}/{product_name}_dem.tif', temp_file.name, outputType=gdalconst.GDT_Int16)
gdal.Translate(f'{product_name}/{product_name}_dem.tif', temp_file.name, noData="none",
outputType=gdalconst.GDT_Int16)
if include_inc_map:
run(f'data2geotiff dem_seg.par corrected.inc_map 2 {product_name}/{product_name}_inc_map.tif')
if include_scattering_area:
Expand Down
Loading