From 3abc58efd08d601249f7f51d33fa325ba7e3ca98 Mon Sep 17 00:00:00 2001
From: simondreutter <simon.dreutter@awi.de>
Date: Mon, 8 Mar 2021 10:19:16 +0100
Subject: [PATCH] Fixed pole gap issue with gdal warp options

---
 process/4_process_gebco.py | 26 +++++---------------------
 process/config.py          |  3 ++-
 2 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/process/4_process_gebco.py b/process/4_process_gebco.py
index b2696d7..efadd0d 100644
--- a/process/4_process_gebco.py
+++ b/process/4_process_gebco.py
@@ -51,7 +51,7 @@ print('============================================================')
 print('      GENERAL BATHYMETRIC CHART OF THE OCEANS / GEBCO       ')
 
 msg = 'Resampling GEBCO...'
-cmd = f'gdalwarp -s_srs {EPSG_WORLD} -t_srs {EPSG_WORLD} -tr {RESOLUTION_DEG} {RESOLUTION_DEG} -r cubic -of GTiff {GDAL_CREATE_OPTIONS} {GEBCO_IN} {GEBCO_WORLD}'
+cmd = f'gdalwarp -s_srs {EPSG_WORLD} -t_srs {EPSG_WORLD} -tr {RESOLUTION_DEG} {RESOLUTION_DEG} -r cubic -of GTiff {WARP_OPTIONS} {GDAL_CREATE_OPTIONS} {GEBCO_IN} {GEBCO_WORLD}'
 run(msg,cmd)
 
 msg = 'Clipping GEBCO for the Arctic...'
@@ -59,40 +59,24 @@ cmd = f'gdal_translate -projwin -180.0 90.0 180.0 {ARCTIC_EXTENT_LAT} -a_srs {EP
 run(msg,cmd)
 
 msg = 'Reprojecting GEBCO for the Arctic...'
-cmd = f'gdalwarp -s_srs {EPSG_WORLD} -t_srs {EPSG_ARCTIC} -r near -of VRT {GEBCO_ARCTIC_CLIP_VRT} {GEBCO_ARCTIC_FULL_VRT}'
+cmd = f'gdalwarp -s_srs {EPSG_WORLD} -t_srs {EPSG_ARCTIC} -r near -of VRT {WARP_OPTIONS} {GEBCO_ARCTIC_CLIP_VRT} {GEBCO_ARCTIC_FULL_VRT}'
 run(msg,cmd)
 
 msg = 'Resampling Arctic to target resolution...'
-cmd = f'gdalwarp -s_srs {EPSG_ARCTIC} -t_srs {EPSG_ARCTIC} -tr {RESOLUTION_M} {RESOLUTION_M} -r cubic -of GTiff {GDAL_CREATE_OPTIONS} {GEBCO_ARCTIC_FULL_VRT} {TMP_POLAR}'
-#{GEBCO_ARCTIC}
+cmd = f'gdalwarp -s_srs {EPSG_ARCTIC} -t_srs {EPSG_ARCTIC} -tr {RESOLUTION_M} {RESOLUTION_M} -r cubic -of GTiff {WARP_OPTIONS} {GDAL_CREATE_OPTIONS} {GEBCO_ARCTIC_FULL_VRT} {GEBCO_ARCTIC}'
 run(msg,cmd)
 
-# TEMPORARY
-msg = 'Filling North Pole gap...'
-cmd = f'{PYTHON} -m gdal_fillnodata -md {interpolation} -b 1 -of GTiff {TMP_POLAR} {GEBCO_ARCTIC}'
-run(msg,cmd)
-cleanup(TMP_POLAR)
-# /TEMPORARY
-
 msg = 'Clipping GEBCO for the Antarctic...'
 cmd = f'gdal_translate -projwin -180.0 {ANTARCTIC_EXTENT_LAT} 180.0 -90.0 -a_srs {EPSG_WORLD} -of VRT {GEBCO_IN} {GEBCO_ANTARCTIC_CLIP_VRT}'
 run(msg,cmd)
 
 msg = 'Reprojecting GEBCO for the Antarctic...'
-cmd = f'gdalwarp -s_srs {EPSG_WORLD} -t_srs {EPSG_ANTARCTIC} -r near -of VRT {GEBCO_ANTARCTIC_CLIP_VRT} {GEBCO_ANTARCTIC_FULL_VRT}'
+cmd = f'gdalwarp -s_srs {EPSG_WORLD} -t_srs {EPSG_ANTARCTIC} -r near -of VRT {WARP_OPTIONS} {GEBCO_ANTARCTIC_CLIP_VRT} {GEBCO_ANTARCTIC_FULL_VRT}'
 run(msg,cmd)
 
 msg = 'Resampling Antarctic to target resolution...'
-cmd = f'gdalwarp -s_srs {EPSG_ANTARCTIC} -t_srs {EPSG_ANTARCTIC} -tr {RESOLUTION_M} {RESOLUTION_M} -r cubic -of GTiff {GDAL_CREATE_OPTIONS} {GEBCO_ANTARCTIC_FULL_VRT} {TMP_POLAR}'
-#{GEBCO_ANTARCTIC}
-run(msg,cmd)
-
-# TEMPORARY
-msg = 'Filling South Pole gap...'
-cmd = f'{PYTHON} -m gdal_fillnodata -md {interpolation} -b 1 -of GTiff {TMP_POLAR} {GEBCO_ANTARCTIC}'
+cmd = f'gdalwarp -s_srs {EPSG_ANTARCTIC} -t_srs {EPSG_ANTARCTIC} -tr {RESOLUTION_M} {RESOLUTION_M} -r cubic -of GTiff {WARP_OPTIONS} {GDAL_CREATE_OPTIONS} {GEBCO_ANTARCTIC_FULL_VRT} {GEBCO_ANTARCTIC}'
 run(msg,cmd)
-cleanup(TMP_POLAR)
-# /TEMPORARY
 
 cleanup(GEBCO_ARCTIC_CLIP_VRT)
 cleanup(GEBCO_ARCTIC_FULL_VRT)
diff --git a/process/config.py b/process/config.py
index 1d9928e..ce165ef 100644
--- a/process/config.py
+++ b/process/config.py
@@ -201,7 +201,6 @@ GEBCO_ANTARCTIC = os.path.join(PATH_GEBCO,'GEBCO_antarctic.tif')
 GEBCO_ANTARCTIC_HILLSHADE = os.path.join(PATH_GEBCO,'GEBCO_antarctic_hillshade.tif')
 
 # temporary files
-TMP_POLAR = os.path.join(PATH_GEBCO,'tmp_polar.tif') # DEBUGGING
 TMP_RGB = os.path.join(PATH_GEBCO,'tmp_rgb.tif')
 TMP_SHADED = os.path.join(PATH_GEBCO,'tmp_shaded.tif')
 
@@ -264,6 +263,8 @@ GDAL_CREATE_OPTIONS = '-co COMPRESS=NONE -co BIGTIFF=IF_NEEDED'
 GDAL_CREATE_OPTIONS_PY = '--co COMPRESS=NONE --co BIGTIFF=IF_NEEDED'
 #GDAL_CREATE_OPTIONS_PY = '--co COMPRESS=DEFLATE --co PREDICTOR=2 --co ZLEVEL=9 --co BIGTIFF=YES'
 
+# GDAL warp options
+WARP_OPTIONS = '-wo SOURCE_EXTRA=1000 -et 0'
 
 #=============================================================================
 #    RUN FUNCTION
-- 
GitLab