@@ -38,61 +38,79 @@ def pick(c, r, mask): # (c_number, r_number, an array of 1 amd 0)
3838 fill .add (south )
3939 return picked
4040
41- def curve (res_name , max_wl , point , boundary , dem_file_path ):
41+ def res_iso (res_name , max_wl , point , boundary , res_directory ):
4242 # ===================================================== INPUT PARAMETERS
43- bc = boundary
44- pc = point
45- coords = bc + pc
46- utm_coords = np .array ([utm .from_latlon (coords [i + 1 ], coords [i ]) for i in range (0 , len (coords ), 2 )])
47- # Bounding box of the reservoir [ulx, uly, lrx, lry]
48- bbox = np .array ([utm_coords [0 ,0 ], utm_coords [0 ,1 ], utm_coords [1 ,0 ], utm_coords [1 ,1 ]], dtype = np .float32 )
49- res_point = np .array ([utm_coords [2 ,0 ], utm_coords [2 ,1 ]], dtype = np .float32 )
50- # 30m equivalent distance in degree
51- #dist30m= 0.01745329252
52- xp = round (abs (res_point [0 ]- bbox [0 ])/ 30 )
53- yp = round (abs (res_point [1 ]- bbox [1 ])/ 30 )
54- # Maximum reservoir water level
55- curve_ext = max_wl + 10 # to expand the curve
43+ os .chdir (res_directory + "/Outputs" )
44+ res_dem_file = (res_name + "DEM_UTM_CLIP.tif" )
45+ dem_ds = gdal .Open (res_dem_file )
46+ geotransform = dem_ds .GetGeoTransform ()
5647
57- # CREATING E-A-S RELATIONSHOP
58- # clipping DEM by the bounding box
59- print ("Clipping DEM by the bounding box ..." )
60- dem = gdal .Open (dem_file_path )
48+ # Calculate the bounding box coordinates
49+ left = geotransform [0 ]
50+ top = geotransform [3 ]
51+ right = left + geotransform [1 ] * dem_ds .RasterXSize
52+ bottom = top + geotransform [5 ] * dem_ds .RasterYSize
6153
62- # Changing path to the desired reservoir
63- os .chdir (os .getcwd () + "/Outputs" )
64- res_dem_file = res_name + "DEM.tif"
65- dem = gdal .Translate (res_dem_file , dem , projWin = bbox ) #bbox=bc
66- dem = None
54+ bbox = [left , top , right , bottom ]
6755
56+ # 30m nearly equal to 0.00027777778 decimal degree
57+ xp = abs (round ((point [0 ]- boundary [0 ])/ 0.00027777778 ))
58+ yp = abs (round ((point [1 ]- boundary [1 ])/ 0.00027777778 ))
59+ dem_ds = None
60+
61+ # CREATING E-A-S RELATIONSHOP
6862 # isolating the reservoir
6963 dem_bin = gdal_array .LoadFile (res_dem_file )
64+ dem_bin [dem_bin == 32767 ] = np .nan
7065 #------------------ Visualization <Start>
7166 plt .figure ()
7267 plt .imshow (dem_bin , cmap = 'jet' )
7368 plt .colorbar ()
74- dem_bin [np .where (dem_bin > curve_ext )] = 0
69+
70+ dem_bin [np .where (dem_bin > max_wl + 10 )] = 0 #to expand the reservoir extent for accounting uncertainity in max_wl
7571 dem_bin [np .where (dem_bin > 0 )] = 1
7672 res_iso = pick (xp , yp , dem_bin )
73+ plt .figure ()
74+ plt .imshow (res_iso , cmap = 'jet' )
75+ plt .colorbar ()
7776 output = gdal_array .SaveArray (res_iso .astype (gdal_array .numpy .float32 ),
7877 "res_iso.tif" , format = "GTiff" ,
7978 prototype = res_dem_file )
8079 output = None
8180
8281 # finding the lowest DEM value in the reservoir extent
8382 res_dem = gdal_array .LoadFile (res_dem_file )
84- res_dem [np .where (res_iso == 0 )] = 9999
85- min_dem = np .nanmin (res_dem )
83+ res_dem [res_dem == 32767 ] = np .nan
84+ res_dem [np .where (res_iso == 0 )] = 9999 # 9999 is any arbitrary unrealistice value
85+ min_dem = int (np .nanmin (res_dem ))
8686
87- # caculating reservoir surface area and storage volume
88- # coresponding to each water level
87+
88+ #============================================================== E-A relationship
89+ def curve (res_name , res_directory ):
90+ # caculating reservoir surface area and storage volume coresponding to each water level
91+ os .chdir (res_directory + "/Outputs" )
92+ res_dem_file = (res_name + "DEM_UTM_CLIP.tif" )
93+ res_dem = gdal_array .LoadFile (res_dem_file )
94+ res_dem [res_dem == 32767 ] = np .nan
95+ exp_mask = gdal_array .LoadFile ("Expanded_Mask.tif" ).astype (np .float32 )
96+ res_dem [np .where (exp_mask == 0 )] = np .nan
97+ output = gdal_array .SaveArray (res_dem .astype (gdal_array .numpy .float32 ),
98+ "DEM_Landsat_res_iso.tif" ,
99+ format = "GTiff" , prototype = res_dem_file )
100+ output = None
101+ # plt.figure()
102+ # plt.imshow(res_dem, cmap='jet')
103+ # plt.colorbar()
104+ min_dem = int (np .nanmin (res_dem ))
105+ curve_ext = int (np .nanmax (res_dem )) + 10 # to expand the curve
106+ res_dem_updated = ("DEM_Landsat_res_iso.tif" )
107+
89108 results = [["Level (m)" , "Area (skm)" , "Storage (mcm)" ]]
90109 pre_area = 0
91110 tot_stor = 0
92111 for i in range (min_dem , curve_ext ):
93112 level = i
94- water_px = gdal_array .LoadFile (res_dem_file )
95- water_px [np .where (res_iso == 0 )] = 9999
113+ water_px = gdal_array .LoadFile (res_dem_updated )
96114 water_px [np .where (res_dem > i )] = 0
97115 water_px [np .where (water_px > 0 )] = 1
98116 area = np .nansum (water_px )* 9 / 10000
@@ -107,8 +125,7 @@ def curve(res_name, max_wl, point, boundary, dem_file_path):
107125 csvWriter = csv .writer (my_csv )
108126 csvWriter .writerows (results )
109127
110- # ==================== Plot the DEM-based Level-Storage curve
111-
128+ # ==================== Plot the DEM-based Level-Storage curve
112129 data = results [1 :, :]
113130 data = np .array (data , dtype = np .float32 )
114131 # Extract column 2 and 3 from the array
@@ -124,6 +141,8 @@ def curve(res_name, max_wl, point, boundary, dem_file_path):
124141 plt .savefig (res_name + '_storageVSelevation.png' , dpi = 600 , bbox_inches = 'tight' )
125142
126143 return min_dem
144+
145+
127146
128147
129148
0 commit comments