johntruckenbrodt / pyroSAR

framework for large-scale SAR satellite data processing
MIT License
511 stars 112 forks source link

Add option to choose EGM for external DEM in pyroSAR.snap.util.geocode #166

Open peterfriedl opened 3 years ago

peterfriedl commented 3 years ago

With the newest version 0.14, the general support of EGM2008 for geoid correction of DEMs has been added. However, in the function pyroSAR.snap.util.geocode, the EGM that is applyied to an external DEM if externalDEMApplyEGM=True, is hardcoded to EGM96:

if dempar['externalDEMApplyEGM']: get_egm_lookup(geoid='EGM96', software='SNAP')

It would be nice if in a future version an option is added to pyroSAR.snap.util.geocode, in wich the user can choose which EGM will be applied to the external DEM (EGM96 or EGM 2008), just like this is now the case for pyroSAR.auxdata.dem_create.

johntruckenbrodt commented 3 years ago

Hi @peterfriedl. You're right. However, I am not quite sure whether SNAP is able to apply the EGM2008 model. There is no option to select different geoid models in nodes like Terrain-Correction. The function get_egm_lookup only downloads the file (so SNAP does not run into an infinite loop when sitting behind a proxy), to my knowledge there is no such file for EGM2008 yet.

See these links for further details: https://senbox.atlassian.net/browse/SITBX-849 https://forum.step.esa.int/t/terrain-correction-with-copernicus-dem/29025

According to this response, they are just applying EGM96 to the Copernicus DEM auto-download options as well.

Perhaps this option will be added in the next SNAP release, until then there is not much point adding it to snap.geocode.

peterfriedl commented 3 years ago

Hi @johntruckenbrodt, Ok, so e.g. changing

if dempar['externalDEMApplyEGM']:
  get_egm_lookup(geoid='EGM96', software='SNAP')

to

if dempar['externalDEMApplyEGM']:
  get_egm_lookup(geoid='EGM2008', software='PROJ')

has no effect on pyroSAR.snap.util.geocode and still the EGM96 will be applied, right? So what is your recommended way to use an external DEM and apply EGM2008 in pyroSAR? Is it to correct for the geoid outside of pyroSAR and to use the corrected DEM as external DEM with setting externalDEMApplyEGM=False in pyroSAR.snap.util.geocode? Or can the EGM2008 be applied to an external DEM in GeoTIFF-format via pyroSAR.auxdata.dem_create and the resulting output be used as input to pyroSAR.snap.util.geocode (with externalDEMApplyEGM=False)?

johntruckenbrodt commented 3 years ago

The function pyrosar.auxdata.get_egm_lookup only downloads the file, but the actual correction is done by SNAP. Downloading the EGM2008 PROJ file will have no effect, because it cannot be used by SNAP.

Basically there are two ways of applying the correction: either with SNAP or with GDAL/PROJ.

You can use the function pyroSAR.auxdata.dem_create for preparing the external DEM including EGM2008 correction using GDAL. This function also calls get_egm_lookup internally (with software='PROJ') and then calls gdalwarp for the height conversion. GDAL internally uses PROJ for everything related to spatial reference systems (which itself needs dedicated files that are not part of the installation by default).