-
Notifications
You must be signed in to change notification settings - Fork 58
/
NormalizeBT.m
96 lines (90 loc) · 3.52 KB
/
NormalizeBT.m
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
function Tempd = NormalizeBT( dim, dem,mask,Temp,ratelaspe_cl,l_pt,h_pt,resl)
%NORMALIZEBT Normalize BT along elevation (DEM) by using a linear model.
%
% Syntax
%
% Tempd = NormalizeBT( dim, dem,mask,Temp,ratelaspe_cl,l_pt,h_pt )
%
% Description
%
% A linear model is used to normalize BT along with DEM (Qiu et al.,
% 2017).
% History:
% 1. Create this function. (1. January, 2017)
% 2. This stratied sampling method sometimes results in no enough
% samples. If the stratied samples are less than 40,000 (not 50,000),
% the stratied sampling method will not be used anymore. (8. March,
% 2018)
% 3. no normalization if no dem data. (20. March, 2018)
%
% Input arguments
%
% dim Dim for data.
% dem Digital Elevation Model (DEM).
% Temp Temperature (BT).
% ratelaspe_cl Clear sky (land) pixels, which are used for this
% normalization.
% l_pt Low level (17.5 percentile).
% h_pt High level (81.5 percentile).
% resl Spatial resolution (Landsat 30 meters; Sentinel-2 20 meters).
%
% Output arguments
%
% Tempd Nomalized Temperature (BT).
%
%
% Author: Shi Qiu (shi.qiu@ttu.edu)
% Date: 8. March, 2018
if isempty (dem)
Tempd = Temp;
else
mask(isnan(dem))=0;% exclude nan dem pixel.
dem_b=double(prctile(dem(mask),0.0001));
temp_cl=Temp(ratelaspe_cl);
% clear ratelaspe_cl;
temp_min=prctile(temp_cl,l_pt*100);
temp_max=prctile(temp_cl,h_pt*100);
clear temp_cl l_pt h_pt;
cls=(Temp>temp_min&Temp<temp_max)&ratelaspe_cl;
clear temp_min temp_max ratelaspe_cl;
% cls=(temp_cl>temp_min&temp_cl<temp_max);
data_bt_c_clear=double(Temp(cls));
data_dem_clear=double(dem(cls));
clear cls;
% stratified random samples select
% total_sample=50000;
total_sample=40000;
ele_strata=300;% meters
samp_distance=450;% meters
dem_t=double(prctile(dem(mask),99.999)); % further exclude non dem pixels.
clear mask temp_max temp_min;
% binScatterPlot(data_dem_clear,data_bt_c_clear)
samples_ids=stratiedSampleHanlder(data_dem_clear,dem_b,dem_t,dim,total_sample,ele_strata,samp_distance,resl);
clear total_sample ele_strata samp_distance dem_t dim resl;
data_dem_clear_tmp=data_dem_clear;
data_bt_c_clear_tmp=data_bt_c_clear;
clear data_dem_clear data_bt_c_clear;
data_dem_clear=data_dem_clear_tmp(samples_ids,:);
data_bt_c_clear=data_bt_c_clear_tmp(samples_ids,:);
clear data_dem_clear_tmp data_bt_c_clear_tmp samples_ids;
%% regress
alpha=0.05;
% [b,bint,r,rint,stats]=regress(data_bt_c_clear,[ones(size(data_dem_clear)),data_dem_clear],alpha);
[b,~,~,~,stats]=regress(data_bt_c_clear,[ones(size(data_dem_clear)),data_dem_clear],alpha);
clear data_bt_c_clear data_dem_clear;
rate_lapse=0.0;
if stats(3)<alpha && double(b(2)) < 0
rate_lapse=double(b(2));% -0.00
end
clear alpha b stats;
Temp=double(Temp);
if rate_lapse==0.0
Tempd=Temp;
else
Tempd=Temp-rate_lapse.*double(dem-dem_b);
clear rate_lapse dem_b;
Tempd(isnan(dem))=Temp(isnan(dem));% back to orignal values for the no dem pixels.
end
clear Temp dem;
end
end