diff --git a/algorithm_config.yaml b/algorithm_config.yaml index 2c2924ed90bb465ae47ed2e27ae6f379b83385ab..2527eb1add4c955393c859058b9f7599223747c6 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.2 +version: 0.5.3 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 @@ -27,3 +27,5 @@ inputs: download: False - name: filter download: False + - name: minshots + download: False diff --git a/ich.sh b/ich.sh index 2a7c5a6c90140697488f0ee5240e1df58cefd4a5..256caedd4e86bf325dcdaa2999b2c07f3dfb864b 100644 --- a/ich.sh +++ b/ich.sh @@ -23,6 +23,7 @@ options=() [[ "${5:-}" != "-" ]] && options+=("--algorithm" "${5}") [[ "${6:-}" != "-" ]] && options+=("--overlap" "${6}") [[ "${7:-}" != "-" ]] && options+=("--filter" "${7}") +[[ "${7:-}" != "-" ]] && options+=("--minshots" "${8}") # 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 aff3a140fb42b0abb676662b129ee8ec96f4aff8..92ea0bfcb88f2da19f31ebc5ba9787351206d143 100644 --- a/src/ich/InSAR_canopy_height.py +++ b/src/ich/InSAR_canopy_height.py @@ -5,22 +5,11 @@ Created on Thu Dec 27 14:40:29 2023 @author: Narayanarao """ +__version__ = "0.5.3" -import argparse,os,sys,warnings,time - -import numpy as np, pandas as pd +import argparse,warnings +import numpy as np from osgeo import gdal -from scipy import interpolate -import matplotlib.pyplot as plt -from matplotlib import cm -from matplotlib.colors import Normalize - -from scipy.stats import linregress -from skimage.util.shape import view_as_blocks -from mpl_toolkits.axes_grid1 import make_axes_locatable -from scipy.interpolate import griddata -from tqdm import tqdm -from scipy.interpolate import interpn gdal.UseExceptions() warnings.filterwarnings('ignore') warnings.filterwarnings('error') @@ -35,6 +24,13 @@ from args_in import rvog_inverse ########################################################################## parser = argparse.ArgumentParser() +parser.add_argument( + "--version", + action="version", + version=f"%(prog)s {__version__}", + help="Show version information" +) + 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 = None ,help="lower limit of canopy height (m)", type=int) @@ -43,7 +39,8 @@ parser.add_argument("-w", "--window",dest = "window_size", default = 10, help="c 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) -parser.add_argument("-f", "--filter",dest = "filt_parm", default = 0, help="filter/smoothen the calibation parameters", type=int) +parser.add_argument("-f", "--filter",dest = "filt_parm", default = 0, help="filter/smoothen the calibration parameters", type=int) +parser.add_argument("-ms", "--minshots",dest = "minshots", default = 3, help="Minimum number of GEDI shots per window", type=int) args = parser.parse_args() diff --git a/src/ich/algo.py b/src/ich/algo.py index 8497b4c6b244dacc1997c14e8f0cf65310ac9f9a..c406e13439a725b7b77729992b944b2db08aaf53 100644 --- a/src/ich/algo.py +++ b/src/ich/algo.py @@ -65,7 +65,7 @@ def arc_sinc_fast(x, c_param): ################################################# def process_st_window(win, temp_cor, temp_lidar, args): - parm = cal_(temp_cor, temp_lidar, args.htl, args.htg) + parm = cal_(temp_cor, temp_lidar, args.htl, args.htg, args.minshots) mask = temp_lidar.copy() mask[~np.isnan(mask)] = 1 @@ -169,7 +169,7 @@ def arc_sinc(x, c_param): # return y return y -def cal_(temp_cor, temp_gedi, htl, htg): +def cal_(temp_cor, temp_gedi, htl, htg,minshots=3): try: # temp_cor = cor.copy() # temp_gedi = gedi.copy() @@ -214,9 +214,12 @@ def cal_(temp_cor, temp_gedi, htl, htg): if tempdf.empty: return [0, 0, 0, 0, 0, 0] elif nn>6: - tempdf_coarse = tempdf[tempdf['N'] > 3].sort_values(by=['rmse'], ascending=True) - tempdf_coarse = tempdf_coarse[tempdf_coarse['inv'] > 0.5] - + if minshots>1: + tempdf_coarse = tempdf[tempdf['N'] >= minshots].sort_values(by=['rmse'], ascending=True) + tempdf_coarse = tempdf_coarse[tempdf_coarse['inv'] > 0.5] + else: + tempdf_coarse = tempdf.sort_values(by=['rmse'], ascending=True) + sCoarse = np.round(tempdf_coarse.iloc[0]['S'], 2) cCoarse = np.round(tempdf_coarse.iloc[0]['C'], 2) @@ -249,7 +252,10 @@ def cal_(temp_cor, temp_gedi, htl, htg): del result tempdf.dropna(subset=['rmse'], inplace=True) # if nn>6: - tempdf = tempdf[tempdf['N'] > 3].sort_values(by=['rmse'], ascending=True) + if minshots>1: + tempdf = tempdf[tempdf['N'] >= minshots].sort_values(by=['rmse'], ascending=True) + else: + tempdf = tempdf.sort_values(by=['rmse'], ascending=True) if tempdf.empty and sCoarse==0: return [0, 0, 0, 0, 0,0] diff --git a/src/ich/args_in.py b/src/ich/args_in.py index 549d4a6f0fd578b010980ae5e114b250134f2147..db7c82659d387b02f64ca8466c18dc82619ceaa5 100644 --- a/src/ich/args_in.py +++ b/src/ich/args_in.py @@ -49,7 +49,7 @@ def rvog_inverse(args): try: t0 = time.time() - print( "-corFile {} -lidarFile {} -htl {} -htg {} -window_size {} -validation {} -algo {} -window_overlap {} -filt_parm {}".format( + print( "-corFile {} -lidarFile {} -htl {} -htg {} -window_size {} -validation {} -algo {} -window_overlap {} -filt_parm {} -minshots {}".format( args.corFile, args.lidarFile, args.htl, @@ -58,7 +58,8 @@ def rvog_inverse(args): args.validation, args.algo, args.window_overlap, - args.filt_parm + args.filt_parm, + args.minshots )) lidar_ht = read_bin(args.lidarFile)