From b6c2578e57b6ab6a706d188af04c5203e0a4372f Mon Sep 17 00:00:00 2001
From: simondreutter <simon.dreutter@awi.de>
Date: Wed, 19 May 2021 19:15:39 +0200
Subject: [PATCH] new RUN.py script and some minor code adjustments

---
 INSTRUCTIONS.md                 | 10 ++---
 process/1_process_add.py        |  1 -
 process/2_process_gimp.py       |  1 -
 process/3_process_glims.py      |  1 -
 process/6_burn_vector_layers.py | 29 +++++++--------
 process/7_create_basemaps.py    |  2 +-
 process/RUN.py                  | 66 +++++++++++++++++++++++++++++++++
 process/config.py               |  9 +++--
 process/run.bat                 | 18 ---------
 9 files changed, 89 insertions(+), 48 deletions(-)
 create mode 100644 process/RUN.py
 delete mode 100644 process/run.bat

diff --git a/INSTRUCTIONS.md b/INSTRUCTIONS.md
index a2a056b..ec96c43 100644
--- a/INSTRUCTIONS.md
+++ b/INSTRUCTIONS.md
@@ -43,7 +43,7 @@ The GPKG files `add_coastline_medium_res_polygon_v7.3.gpkg` and `add_rock_outcro
 
 # 2. Adjust scripts
 
-Most of the necessary adjustments are happening in `~/process/config.py`. There are two minor things that need adjustment in other scripts.
+Most of the necessary adjustments are happening in `~/process/config.py`. There is one minor thing that might need adjustment in another script.
 
 ## 2.1 `~/process/config.py`
 
@@ -54,16 +54,12 @@ After downloading the input data you need to make sure the input files in the co
 The default settings for resolution (degree/meter), the z factor for shading and the extent of the polar grids are set here. If you want different settings, adjust the variables in this section. However, read the notes, expecially on resolution.
 
 ##### Operational Parameters
-If your Python 3.x installation has a different executable than OSGeo4W (`python3`), adjust this here.
+Some scripts call the Python executable which is set in `config.py` with `sys.executable`. If you need a specific Python 3.x executable, adjust it here.
 
 ## 2.2 `~/process/1_process_add.py`
 
 Some of the vector processes require the GPKG layer names in their SQL commands. In ADD there is an inconsistency with the layer bames, which is why the layer name varibale for rock outcrops needs to be overwritten at the beginning of the process. In case this gets fixed or other incositencies arise in newer versions, make sure these are taken care of here.
 
-## 2.3 `~/process/run.bat`
-
-Again, if your Python 3.x executable is different to `python3`, adjust this at the beginning of the run script.
-
 # 3. Run
 
-Now run `~/process/run.bat` (or run all python scripts manually in order) and check the results, once finished.
+The process is designed, so that all individual sub steps can be run separately. If you want to run everything at once, simply start`~/process/RUN.py` and check the results, once finished.
diff --git a/process/1_process_add.py b/process/1_process_add.py
index fe109d2..6fe33e8 100644
--- a/process/1_process_add.py
+++ b/process/1_process_add.py
@@ -32,7 +32,6 @@ __status__ = 'Developement'
 #    IMPORT
 #=============================================================================
 
-# import standard libraries
 import os
 
 # import AWI Basemap configuration
diff --git a/process/2_process_gimp.py b/process/2_process_gimp.py
index 8e9d751..5e8a2f2 100644
--- a/process/2_process_gimp.py
+++ b/process/2_process_gimp.py
@@ -30,7 +30,6 @@ __status__ = 'Developement'
 #    IMPORT
 #=============================================================================
 
-# import standard libraries
 import os
 
 # import AWI Basemap configuration
diff --git a/process/3_process_glims.py b/process/3_process_glims.py
index 49ecb45..191207b 100644
--- a/process/3_process_glims.py
+++ b/process/3_process_glims.py
@@ -31,7 +31,6 @@ __status__ = 'Developement'
 #    IMPORT
 #=============================================================================
 
-# import standard libraries
 import os
 
 # import AWI Basemap configuration
diff --git a/process/6_burn_vector_layers.py b/process/6_burn_vector_layers.py
index 6fc3bc5..3b508e6 100644
--- a/process/6_burn_vector_layers.py
+++ b/process/6_burn_vector_layers.py
@@ -31,7 +31,6 @@ __status__ = 'Developement'
 #    IMPORT
 #=============================================================================
 
-# import standard libraries
 import os
 
 # import AWI Basemap configuration
@@ -52,9 +51,9 @@ glims_arctic_name = os.path.splitext(os.path.basename(GLIMS_ARCTIC))[0]
 glims_antarctic_name = os.path.splitext(os.path.basename(GLIMS_ANTARCTIC))[0]
 
 # burn values
-v_rock_outcrops = 3000.0
-v_shelf_ice = 20000.0
-v_ice_sheet = 30000.0
+V_ROCK_OUTCROPS = 3000.0
+V_SHELF_ICE = 20000.0
+V_ICE_SHEET = 30000.0
 
 # heading
 print()
@@ -62,47 +61,47 @@ print('============================================================')
 print('                     BURN VECTOR LAYERS                     ')
 
 msg = 'Burning Antarctic ice shelfs in World raster...'
-cmd = f'gdal_rasterize -l {add_shelf_ice_name} -burn {v_shelf_ice} {ADD_SHELF_ICE} {GEBCO_WORLD}'
+cmd = f'gdal_rasterize -l {add_shelf_ice_name} -burn {V_SHELF_ICE} {ADD_SHELF_ICE} {GEBCO_WORLD}'
 run(msg,cmd)
 
 msg = 'Burning Antarctic ice sheet in World raster...'
-cmd = f'gdal_rasterize -l {add_ice_sheet_name} -burn {v_ice_sheet} {ADD_ICE_SHEET} {GEBCO_WORLD}'
+cmd = f'gdal_rasterize -l {add_ice_sheet_name} -burn {V_ICE_SHEET} {ADD_ICE_SHEET} {GEBCO_WORLD}'
 run(msg,cmd)
 
 msg = 'Burning Antarctic rock outcrops in World raster...'
-cmd = f'gdal_rasterize -l {add_rock_outcrop_name} -burn {v_rock_outcrops} -at {ADD_ROCK_OUTCROP} {GEBCO_WORLD}'
+cmd = f'gdal_rasterize -l {add_rock_outcrop_name} -burn {V_ROCK_OUTCROPS} -at {ADD_ROCK_OUTCROP} {GEBCO_WORLD}'
 run(msg,cmd)
 
 msg = 'Burning Greenland ice sheet in World raster...'
-cmd = f'gdal_rasterize -l {gimp_name} -burn {v_ice_sheet} {GIMP} {GEBCO_WORLD}'
+cmd = f'gdal_rasterize -l {gimp_name} -burn {V_ICE_SHEET} {GIMP} {GEBCO_WORLD}'
 run(msg,cmd)
 
 msg = 'Burning glaciers in World raster...'
-cmd = f'gdal_rasterize -l {glims_world_name} -burn {v_ice_sheet} {GLIMS_WORLD} {GEBCO_WORLD}'
+cmd = f'gdal_rasterize -l {glims_world_name} -burn {V_ICE_SHEET} {GLIMS_WORLD} {GEBCO_WORLD}'
 run(msg,cmd)
 
 msg = 'Burning Greenland ice sheet in Arctic raster...'
-cmd = f'gdal_rasterize -l {gimp_name} -burn {v_ice_sheet} {GIMP} {GEBCO_ARCTIC}'
+cmd = f'gdal_rasterize -l {gimp_name} -burn {V_ICE_SHEET} {GIMP} {GEBCO_ARCTIC}'
 run(msg,cmd)
 
 msg = 'Burning glaciers in Arctic raster...'
-cmd = f'gdal_rasterize -l {glims_arctic_name} -burn {v_ice_sheet} {GLIMS_ARCTIC} {GEBCO_ARCTIC}'
+cmd = f'gdal_rasterize -l {glims_arctic_name} -burn {V_ICE_SHEET} {GLIMS_ARCTIC} {GEBCO_ARCTIC}'
 run(msg,cmd)
 
 msg = 'Burning Antarctic ice shelfs in Antarctic raster...'
-cmd = f'gdal_rasterize -l {add_shelf_ice_name} -burn {v_shelf_ice} {ADD_SHELF_ICE} {GEBCO_ANTARCTIC}'
+cmd = f'gdal_rasterize -l {add_shelf_ice_name} -burn {V_SHELF_ICE} {ADD_SHELF_ICE} {GEBCO_ANTARCTIC}'
 run(msg,cmd)
 
 msg = 'Burning Antarctic ice sheet in Antarctic raster...'
-cmd = f'gdal_rasterize -l {add_ice_sheet_name} -burn {v_ice_sheet} {ADD_ICE_SHEET} {GEBCO_ANTARCTIC}'
+cmd = f'gdal_rasterize -l {add_ice_sheet_name} -burn {V_ICE_SHEET} {ADD_ICE_SHEET} {GEBCO_ANTARCTIC}'
 run(msg,cmd)
 
 msg = 'Burning Antarctic rock outcrops in Antarctic raster...'
-cmd = f'gdal_rasterize -l {add_rock_outcrop_name} -burn {v_rock_outcrops} -at {ADD_ROCK_OUTCROP} {GEBCO_ANTARCTIC}'
+cmd = f'gdal_rasterize -l {add_rock_outcrop_name} -burn {V_ROCK_OUTCROPS} -at {ADD_ROCK_OUTCROP} {GEBCO_ANTARCTIC}'
 run(msg,cmd)
 
 msg = 'Burning glaciers in Antarctic raster...'
-cmd = f'gdal_rasterize -l {glims_antarctic_name} -burn {v_ice_sheet} {GLIMS_ANTARCTIC} {GEBCO_ANTARCTIC}'
+cmd = f'gdal_rasterize -l {glims_antarctic_name} -burn {V_ICE_SHEET} {GLIMS_ANTARCTIC} {GEBCO_ANTARCTIC}'
 run(msg,cmd)
 
 cleanup(ADD_SHELF_ICE)
diff --git a/process/7_create_basemaps.py b/process/7_create_basemaps.py
index 2368094..a1205cc 100644
--- a/process/7_create_basemaps.py
+++ b/process/7_create_basemaps.py
@@ -54,7 +54,7 @@ OVERVIEW_METHOD = 'cubic'
 #=============================================================================
 
 def create_basemap(map_params):
-    name,gebco,hs,cp,epsg,output = map_params
+    name, gebco, hs, cp, epsg, output = map_params
     msg = f'Creating {name} RGB...'
     cmd = f'gdaldem color-relief {gebco} {cp} {TMP_RGB} -of GTiff -b 1 -compute_edges {GDAL_CREATE_OPTIONS}'
     run(msg,cmd)
diff --git a/process/RUN.py b/process/RUN.py
new file mode 100644
index 0000000..2eb531d
--- /dev/null
+++ b/process/RUN.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+"""
+####################################################################
+#                                                                  #
+#                           AWI Basemap                            #
+#                      RUN THE ENTIRE PROCESS                      #
+#                                                                  #
+####################################################################
+
+"""
+
+
+#=============================================================================
+#    SCRIPT INFO
+#=============================================================================
+
+__author__ = 'Simon Dreutter'
+__version__ = '0.1'
+__date__ = '2021-05-19'
+__email__ = 'simon.dreutter@awi.de'
+__status__ = 'Developement'
+
+
+#=============================================================================
+#    IMPORT
+#=============================================================================
+
+import subprocess
+import sys
+
+# import AWI Basemap configuration
+from config import PYTHON
+
+
+#=============================================================================
+#    RUN
+#=============================================================================
+
+cmd = [PYTHON, '1_process_add.py']
+subprocess.call(cmd)
+
+cmd = [PYTHON, '2_process_gimp.py']
+subprocess.call(cmd)
+
+cmd = [PYTHON, '3_process_glims.py']
+subprocess.call(cmd)
+
+cmd = [PYTHON, '4_process_gebco.py']
+subprocess.call(cmd)
+
+cmd = [PYTHON, '5_create_shading_layers.py']
+subprocess.call(cmd)
+
+cmd = [PYTHON, '6_burn_vector_layers.py']
+subprocess.call(cmd)
+
+cmd = [PYTHON, '7_create_basemaps.py']
+subprocess.call(cmd)
+
+#=============================================================================
+
+print()
+print('All done!')
+input('\nPress Enter to exit!\n')
+sys.exit()
diff --git a/process/config.py b/process/config.py
index cbb09ce..e02207a 100644
--- a/process/config.py
+++ b/process/config.py
@@ -39,9 +39,8 @@ __status__ = 'Developement'
 #    IMPORT
 #=============================================================================
 
-# import standard libraries
 import os
-
+import sys
 
 #=============================================================================
 #    INPUT FOLDERS
@@ -124,7 +123,7 @@ RESOLUTION_DEG = 0.008333333333333333
 RESOLUTION_M = 1000.0
 
 # GIMP Resolution
-# half the GEBCO resolution
+# half the grid resolution
 GIMP_RESOLUTION = RESOLUTION_DEG / 2
 
 # Hillshade z factor / vertical exaggeration
@@ -243,7 +242,9 @@ EPSG_ANTARCTIC = 'EPSG:3031' # WGS 84 / Antarctic Polar Stereographic
 # the final results, however, are specified in the last python script.
 
 # Python executable
-PYTHON = 'python3'
+#PYTHON = 'python'
+#PYTHON = 'python3'
+PYTHON = sys.executable
 
 # GDAL creation options
 GDAL_CREATE_OPTIONS = '-co COMPRESS=NONE -co BIGTIFF=IF_NEEDED'
diff --git a/process/run.bat b/process/run.bat
deleted file mode 100644
index 42d0bb7..0000000
--- a/process/run.bat
+++ /dev/null
@@ -1,18 +0,0 @@
-@echo off
-
-rem PYTHON executable
-set PYTHON=python3
-
-%PYTHON% 1_process_add.py
-%PYTHON% 2_process_gimp.py
-%PYTHON% 3_process_glims.py
-%PYTHON% 4_process_gebco.py
-%PYTHON% 5_create_shading_layers.py
-%PYTHON% 6_burn_vector_layers.py
-%PYTHON% 7_create_basemaps.py
-
-echo.
-echo All done!
-echo.
-set /p DONE=Press Enter to exit!
-echo.
\ No newline at end of file
-- 
GitLab