From 201ba44807f6337f1f05a3cb741f9aab7af7e2b1 Mon Sep 17 00:00:00 2001
From: Narayana Rao Bhogapurapu <narayanarao.bhogapurapu@gmail.com>
Date: Tue, 12 Nov 2024 10:31:19 -0800
Subject: [PATCH] 0.5.1

---
 algorithm_config.yaml          |  2 +-
 ich.sh                         |  2 ++
 src/ich/InSAR_canopy_height.py |  5 ++---
 src/ich/args_in.py             | 14 ++++++++++----
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/algorithm_config.yaml b/algorithm_config.yaml
index 3afd3cc..9f1bb3b 100644
--- a/algorithm_config.yaml
+++ b/algorithm_config.yaml
@@ -1,6 +1,6 @@
 description: Estimates canopy height from InSAR coherence and LiDAR data
 algo_name: ich
-version: 0.5
+version: 0.5.1
 environment: ubuntu
 repository_url: https://repo.maap-project.org/bnarayanarao/insar_forest_height.git
 docker_url: mas.maap-project.org/root/maap-workspaces/base_images/python:v4.1.0
diff --git a/ich.sh b/ich.sh
index 132fbbf..478dc79 100644
--- a/ich.sh
+++ b/ich.sh
@@ -20,6 +20,8 @@ options=()
 [[ "${2:-}" != "-" ]] && options+=("--upper_limit" "${2}")
 [[ "${3:-}" != "-" ]] && options+=("--window" "${3}")
 [[ "${4:-}" != "-" ]] && options+=("--validation" "${4}")
+[[ "${5:-}" != "-" ]] && options+=("--algorithm" "${5}")
+[[ "${6:-}" != "-" ]] && options+=("--overlap" "${6}")
 
 # Run the Python script with the determined options
 ${ich_py} --correlationFile "${correlationFile}" --cal_ht "${cal_ht}" "${options[@]}"
\ No newline at end of file
diff --git a/src/ich/InSAR_canopy_height.py b/src/ich/InSAR_canopy_height.py
index a700df5..968a706 100644
--- a/src/ich/InSAR_canopy_height.py
+++ b/src/ich/InSAR_canopy_height.py
@@ -37,14 +37,13 @@ parser = argparse.ArgumentParser()
 
 parser.add_argument("-c", "--correlationFile", dest = "corFile", help="correlation file [0,1]")
 parser.add_argument("-l", "--cal_ht", dest = "lidarFile",  help="Calibration height file e.g. LiDAR heights in (m)")
-parser.add_argument("-ll", "--lower_limit",dest ="htl", default = 0 ,help="lower limit of canopy height (m)", type=int)
-parser.add_argument("-ul", "--upper_limit",dest = "htg", default = 40,help="upper limit of canopy height (m)", type=int)
+parser.add_argument("-ll", "--lower_limit",dest ="htl", default = None ,help="lower limit of canopy height (m)", type=int)
+parser.add_argument("-ul", "--upper_limit",dest = "htg", default = None,help="upper limit of canopy height (m)", type=int)
 parser.add_argument("-w", "--window",dest = "window_size", default = 10, help="Size", type=int)
 parser.add_argument("-val", "--validation",dest = "validation", default = 0, help="fraction to split cross validation", type=float)
 parser.add_argument("-al", "--algorithm",dest = "algo", default = 1, help="Algorithm Type", type=int)
 parser.add_argument("-ol", "--overlap",dest = "window_overlap", default = 0, help="window overlap fraction", type=float)
 
-
 args = parser.parse_args()
 
 
diff --git a/src/ich/args_in.py b/src/ich/args_in.py
index 72fb1fd..ced3f94 100644
--- a/src/ich/args_in.py
+++ b/src/ich/args_in.py
@@ -75,6 +75,14 @@ def rvog_inverse(args):
 
 
         lidar_ht[lidar_ht==0] = np.nan
+        if args.htl==None and args.htg==None:
+            """ Calculating the upper limit of the heights to be estimated from the LiDAR data 
+            Ceiling the upper limit to the closest multiple of 5 for the height at 99.9 percentile """
+            args.htl=0
+            pp99 = np.nanpercentile(lidar_ht,99.9)
+            args.htg = int( 5 * np.ceil( pp99 / 5. ))
+
+
         lidar_ht[lidar_ht<args.htl] = np.nan
         lidar_ht[lidar_ht>args.htg] = np.nan
         cor[cor<0.1]=np.nan
@@ -113,7 +121,8 @@ def rvog_inverse(args):
         if not os.path.exists(outDir):
             os.mkdir(outDir)
 
-        _postfix_str = '_w'+str(args.window_size)+'o'+"%02d" %(args.window_overlap*10)+"_"+str(args.htl)+str(args.htg)
+        # _postfix_str = '_w'+str(args.window_size)+'o'+"%02d" %(args.window_overlap*10)+"_"+str(args.htl)+str(args.htg)
+        _postfix_str = f"_w{args.window_size}_{args.htl}_{args.htg}"
 
         outcFile = os.path.join(outDir,os.path.basename(corFile).split('.tif')[0]+_postfix_str+'_c.tif')
         outsFile = os.path.join(outDir,os.path.basename(corFile).split('.tif')[0]+_postfix_str+'_s.tif')
@@ -410,9 +419,6 @@ def rvog_inverse(args):
             s = s*temp_mask
             c = c*temp_mask
 
-
-
-
             # c = np.nanmean([sw,c20,c50])
         else:
             raise ValueError('Invalid algorithm type!')
-- 
GitLab