-
Notifications
You must be signed in to change notification settings - Fork 0
/
sits_planet_sentinel_harmonize.py
138 lines (115 loc) · 3.75 KB
/
sits_planet_sentinel_harmonize.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# coding: utf-8
# %%
# Raster scatter plot
#
# Compare two raster dataset, plot scatter plot, harmonize data
# Krištof Oštir
# UL FGG
# (c) 2020
# %%
# Imports
import sys
import matplotlib.pyplot as plt
import gdal
# %%
import satimagets as sits
# %%
# Images
# # PlanetScope
# file_1 = "D:/GeoData/PlanetCalibration/PlanetScope/20170720_090825_1032/20170720_090825_1032_3B_AnalyticMS.tif"
# file_1_udm = "D:/GeoData/PlanetCalibration/PlanetScope/20170720_090825_1032/20170720_090825_1032_3B_AnalyticMS_DN_udm.tif"
# file_1_ndvi = "D:/GeoData/PlanetCalibration/PlanetScope/20170720_090825_1032/20170720_090825_1032_3B_AnalyticMS_NDVI.tif"
# # Sentinel-2
# file_2 = "D:/GeoData/PlanetCalibration/Sentinel-2/L1C_T33TVM_A010844_20170720T100027_con/RT_T33TVM_A010844_20170720T100027_stack.tif"
# file_2_ndvi = "D:/GeoData/PlanetCalibration/Sentinel-2/L1C_T33TVM_A010844_20170720T100027_con/RT_T33TVM_A010844_20170720T100027_stack_NDVI.tif"
# Subset
# PlanetScope
file_1 = "D:/GeoData/PlanetCalibration/PlanetScope/20170720_090825_1032/20170720_090825_1032_3B_AnalyticMS_sub.tif"
file_1_udm = "D:/GeoData/PlanetCalibration/PlanetScope/20170720_090825_1032/20170720_090825_1032_3B_AnalyticMS_DN_udm_sub.tif"
file_1_ndvi = "D:/GeoData/PlanetCalibration/PlanetScope/20170720_090825_1032/20170720_090825_1032_3B_AnalyticMS_NDVI_sub.tif"
# Sentinel-2
file_2 = "D:/GeoData/PlanetCalibration/Sentinel-2/L1C_T33TVM_A010844_20170720T100027/T33TVM_A010844_20170720T100027_stack_sub.tif"
file_2_ndvi = "D:/GeoData/PlanetCalibration/Sentinel-2/L1C_T33TVM_A010844_20170720T100027_con/RT_T33TVM_A010844_20170720T100027_stack_NDVI_sub.tif"
# %%
# Open images
try:
file_1_src = gdal.Open(file_1)
except:
print('Could not open:', file_1)
sys.exit(1)
try:
file_1_ndvi_src = gdal.Open(file_1_ndvi)
except:
print('Could not open:', file_1_ndvi)
sys.exit(1)
try:
file_1_udm_src = gdal.Open(file_1_udm)
except:
print('Could not open:', file_1_udm)
sys.exit(1)
try:
file_2_src = gdal.Open(file_2)
except:
print('Could not open:', file_2)
sys.exit(1)
try:
file_2_ndvi_src = gdal.Open(file_2_ndvi)
except:
print('Could not open:', file_2_ndvi)
sys.exit(1)
# %%
# Find overlap
im_bb, im_res, im_srs = sits.image_raster_overlap(file_1_src, file_2_src)
# %%
# Resample images
im_1_ndvi = sits.image_raster_resample(file_1_ndvi_src, im_bb, im_res, im_srs)
im_2_ndvi = sits.image_raster_resample(file_2_ndvi_src, im_bb, im_res, im_srs)
# %%
# Show image
sits.image_show_band(im_1_ndvi)
sits.image_show_band(im_2_ndvi)
# %%
# Resample original images
im_1 = sits.image_raster_resample(file_1_src, im_bb, im_res, im_srs)
# im_1_udm = image_raster_resample(file_1_udm_src, im_bb, im_res, im_srs)
im_2 = sits.image_raster_resample(file_2_src, im_bb, im_res, im_srs)
# %%
sits.image_show(im_1)
sits.image_show(im_2)
sits.image_show_band(im_1, band=1, cmap=plt.cm.RdYlGn)
# %%
# # Mask images
# im_1 = planetscope_mask(im_1, im_1_udm)
# image_show(im_1)
# %%
# Create scatterplot
sits.image_scatterplot(im_1, im_2[[1, 2, 3, 8],:,:], im1_in_name="Planet", im2_in_name="Sentinel")
# %%
sits.image_scatterplot(im_1_ndvi, im_2_ndvi, im1_in_name="Planet", im2_in_name="Sentinel")
# %%
# %%
# Resample original images
im_1_spl = sits.image_raster_resample(file_1_src, im_bb, 100, im_srs)
# im_1_udm = image_raster_resample(file_1_udm_src, im_bb, im_res, im_srs)
im_2_spl = sits.image_raster_resample(file_2_src, im_bb, 100, im_srs)
# %%
b1 = im_1_spl[0]
b2 = im_2_spl[0]
# %%
sits.image_show_band(b1)
sits.image_show_band(b2)
# %%
# from importlib import reload
# %%
# sits = reload(sits)
# %%
sits.image_show(im_1_spl)
sits.image_show(im_2_spl)
# %%
# Find Pearson correlation coefficient
sits.image_correlation(b1, b2)
# %%
m, b, cov = sits.image_linear_regression(b1, b2)
print(m, b)
print(cov)
# %%