-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path00_Image_Application.py
72 lines (36 loc) · 1.53 KB
/
00_Image_Application.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def image_MDN_application(image_NC, image_ref, SAVE_FOLDER, sensor, useRatio):
from MDN import image_estimates, get_tile_data, get_sensor_bands
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from osgeo import gdal
import numpy as np
import pandas as pd
import numpy as np
sensor = sensor
IMAGE_PATH_NC = image_NC
IMAGE_PATH_TIF_REF = image_ref
SAVE_FOLDER = SAVE_FOLDER+'/secchi.tif'
bands, Rrs = get_tile_data(IMAGE_PATH_NC, sensor, allow_neg=False)
kwargs={'product':'secchi-Maciel', 'use_ratio':useRatio}
Secchi_Est, idxs2 = image_estimates(Rrs, sensor=sensor,**kwargs)
print(Secchi_Est, type(Secchi_Est), Secchi_Est.shape, idxs2)
Secchi = Secchi_Est[:,:,slice(None, None, None)]
## Apply and convert to tif
img_prediction = Secchi_Est.reshape((Rrs.shape[0], Rrs.shape[1]))
reference_tif = gdal.Open(IMAGE_PATH_TIF_REF, gdal.GA_ReadOnly)
#Save
gt = reference_tif.GetGeoTransform()
proj = reference_tif.GetProjection()
driver = gdal.GetDriverByName("Gtiff")
driver.Register()
outds = driver.Create(SAVE_FOLDER, xsize = img_prediction.shape[1],
ysize=img_prediction.shape[0], bands=1, eType = gdal.GDT_Float32)
outds.SetGeoTransform(gt)
outds.SetProjection(proj)
outband = outds.GetRasterBand(1)
outband.WriteArray(img_prediction)
outband.SetNoDataValue(np.nan)
outband.FlushCache()
outband = None
outds = None
reference_tif = None