Skip to content

Commit 67cdd96

Browse files
committed
new_commit
1 parent 29d031b commit 67cdd96

File tree

10 files changed

+375
-301
lines changed

10 files changed

+375
-301
lines changed

code/CURVE.py

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,63 +41,43 @@ def pick(c, r, mask): # (c_number, r_number, an array of 1 amd 0)
4141
def res_iso(res_name, max_wl, point, boundary, res_directory):
4242
# ===================================================== INPUT PARAMETERS
4343
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()
47-
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
53-
54-
bbox = [left, top, right, bottom]
44+
res_dem_file = (res_name + "_DEM_UTM_CLIP.tif")
5545

5646
# 30m nearly equal to 0.00027777778 decimal degree
5747
xp = abs(round((point[0]-boundary[0])/0.00027777778))
5848
yp = abs(round((point[1]-boundary[1])/0.00027777778))
59-
dem_ds = None
6049

6150
# CREATING E-A-S RELATIONSHOP
6251
# isolating the reservoir
63-
dem_bin = gdal_array.LoadFile(res_dem_file)
64-
dem_bin[dem_bin == 32767] = np.nan
65-
#------------------ Visualization <Start>
66-
plt.figure()
67-
plt.imshow(dem_bin, cmap='jet')
68-
plt.colorbar()
69-
52+
dem_bin = gdal_array.LoadFile(res_dem_file).astype(np.float32)
53+
dem_bin[dem_bin == 32767] = np.nan
7054
dem_bin[np.where(dem_bin > max_wl+10)] = 0 #to expand the reservoir extent for accounting uncertainity in max_wl
7155
dem_bin[np.where(dem_bin > 0)] = 1
7256
res_iso = pick(xp, yp, dem_bin)
57+
58+
#------------------ Visualization <Start>
7359
plt.figure()
7460
plt.imshow(res_iso, cmap='jet')
7561
plt.colorbar()
76-
output = gdal_array.SaveArray(res_iso.astype(gdal_array.numpy.float32),
77-
"res_iso.tif", format="GTiff",
78-
prototype = res_dem_file)
79-
output = None
80-
81-
# finding the lowest DEM value in the reservoir extent
82-
res_dem = gdal_array.LoadFile(res_dem_file)
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))
62+
#------------------ Visualization <End>
8663

64+
gdal_array.SaveArray(res_iso.astype(gdal_array.numpy.float32),
65+
"res_iso.tif", format="GTiff",
66+
prototype = res_dem_file)
8767

8868
#============================================================== E-A relationship
8969
def curve(res_name, res_directory):
9070
# caculating reservoir surface area and storage volume coresponding to each water level
9171
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
72+
res_dem_file = (res_name + "_DEM_UTM_CLIP.tif")
73+
res_dem = gdal_array.LoadFile(res_dem_file).astype(np.float32)
74+
res_dem[res_dem == 32767] = np.nan
75+
9576
exp_mask = gdal_array.LoadFile("Expanded_Mask.tif").astype(np.float32)
9677
res_dem[np.where(exp_mask == 0)] = np.nan
97-
output = gdal_array.SaveArray(res_dem.astype(gdal_array.numpy.float32),
78+
gdal_array.SaveArray(res_dem.astype(gdal_array.numpy.float32),
9879
"DEM_Landsat_res_iso.tif",
9980
format="GTiff", prototype = res_dem_file)
100-
output = None
10181
# plt.figure()
10282
# plt.imshow(res_dem, cmap='jet')
10383
# plt.colorbar()
@@ -121,7 +101,7 @@ def curve(res_name, res_directory):
121101
axis=0)
122102

123103
# saving output as a csv file
124-
with open("Curve.csv","w", newline='') as my_csv:
104+
with open('Curve_' + res_name + '.csv',"w", newline='') as my_csv:
125105
csvWriter = csv.writer(my_csv)
126106
csvWriter.writerows(results)
127107

0 commit comments

Comments
 (0)