-
Notifications
You must be signed in to change notification settings - Fork 2
/
lakes_cubic_interpolation.py
42 lines (30 loc) · 1.17 KB
/
lakes_cubic_interpolation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import pickle
import numpy as np
import rasterio as rio
from scipy.interpolate import griddata
#Predict lake bathymetry using cubic interpolation and write to file for visual comparison
def main():
best_buffer = '100'
best_buffer_dir = "data/buffer_{}_percent".format(best_buffer)
#Load data
with open(os.path.join(best_buffer_dir, "lakes_dict.pickle"), 'rb') as src:
lakes_dict = pickle.load(src)
#Predict for all lakes
for p in ["train", "valid", "test"]:
for i in lakes_dict[p]:
id = i["id"]
dem = i["lake"]
mask = i["mask"]
xy = np.argwhere(mask == 0)
z = dem[mask == 0]
xy_hat = np.argwhere(mask == 1)
hat = griddata(xy, z, xy_hat, method = "cubic")
mask_copy = mask.copy()
mask_copy[xy_hat[:,0], xy_hat[:,1]] = hat
profile = i["profile"]
pred_path = os.path.join(best_buffer_dir, "lakes_cubic", "lake_{}.tif".format(id))
with rio.open(pred_path, 'w', **profile) as dst:
dst.write(mask_copy, 1)
if __name__ == "__main__":
main()