From 93d73fc9a5807ea8e860356fc73bd13f83ad0b21 Mon Sep 17 00:00:00 2001
From: sshah <sujen.shah@jpl.nasa.gov>
Date: Thu, 15 Jun 2023 13:49:32 +0000
Subject: [PATCH] Add GDAL wrapper python

---
 gdal_wrapper.py | 25 +++++++++++++++++++++++++
 run.sh          | 10 ++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 gdal_wrapper.py
 create mode 100755 run.sh

diff --git a/gdal_wrapper.py b/gdal_wrapper.py
new file mode 100644
index 0000000..152ab4c
--- /dev/null
+++ b/gdal_wrapper.py
@@ -0,0 +1,25 @@
+import sys
+import argparse 
+import subprocess 
+
+
+def gdal_translate(input_filename, output_filename, reduction_percent):
+    gdal_cmd = ["gdal_translate", "-outsize", f"{reduction_percent}%", f"{reduction_percent}%", 
+               input_filename, output_filename]
+    proc = subprocess.Popen(gdal_cmd, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)
+    out, err = proc.communicate()
+    print(out)
+    return proc.returncode, output_filename
+    
+
+if __name__ == "__main__":
+    parse = argparse.ArgumentParser(description="Runs gdal_translate -outsize to reduce input size by n%")
+    parse.add_argument("--input_file", help="Input file to use", required=True)
+    parse.add_argument("--output_file", help="Output file to write", required=True)
+    parse.add_argument("--outsize", help="Reduction size", required=True)
+    args = parse.parse_args()
+    exit_code, output = gdal_translate(args.input_file, args.output_file, args.outsize)
+    if exit_code != 0:
+        print(f"gdal_translate failed with a non-zero exit code: {exit_code}")
+        exit(exit_code)
+    
\ No newline at end of file
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..3de2df7
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+INPUT_FILENAME=$(ls -d input/*)
+OUTPUT_FILENAME=$1
+REDUCTION_SIZE=$2
+
+# Get path to this run.sh script
+basedir=$( cd "$(dirname "$0")" ; pwd -P )
+
+python ${basedir}/gdal_wrapper.py --input_file ${INPUT_FILENAME} --output_file output/${OUTPUT_FILENAME} --outsize ${REDUCTION_SIZE}
-- 
GitLab