生活随笔
收集整理的這篇文章主要介紹了
用泰森多边形法求子流域气象数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
用泰森多邊形法求子流域氣象數據 (matlab)
需要先用Arcgis畫泰森多邊形并求出各面積占比(權重),然后用該matlab腳本計算。
%%
clc
;clear
;close
all;%此腳本用于通過泰森多邊形方法求子流域氣象數據,輸入數據和格式包括:
%% 輸入
ThiesenResult
= xlsread
('D:\氣象處理\泰森多邊形法結果.xlsx','Sheet1'); %三列,分別為站點編號、子流域編號、權重
stationDir
= 'D
:\evp\'
; %站點數據所在的目錄(最后有斜杠)
subbasinNum
= 224; % 子流域數目
dataColNum
= 4; % 站點文件中數據所在的列號(在第幾列)
outputFile
= 'Evp_daily.txt';%% 讀取所有氣象文件信息,并建立對應鍵值對
h
=waitbar
(0,'讀取數據中...');
stationDataFiles
= dir([stationDir
'*.txt']);
fileNum
= length
(stationDataFiles
);
for i
=1:fileNumfileName
= stationDataFiles
(i
).name
;thisData
= load
(strcat
(stationDir
,fileName
));thisData
(isnan
(thisData
))=0; %去除NaNallData
{i
} = thisData
;stcdList
{i
} = fileName
(1:5); %% ! ! ! 記得要調整,需要從文件名中截取站點編號
(與excel表對應
) ! ! !
%%indexList
{i
} = i
;waitbar
(i
/fileNum
)
end
map = containers
.Map
(stcdList
,indexList
);
close
(h
);%% 開始計算
[timeStpes
,cols
] = size
(allData
{1});
[interFeatureNums
,cols_Thiesen
] = size
(ThiesenResult
);
result
= zeros
(timeStpes
,subbasinNum
);
h
= waitbar
(0,'正在逐時計算...');
for t
= 1:timeStpes
for n
= 1:interFeatureNumsstcd
= ThiesenResult
(n
,1);subbasinID
= ThiesenResult
(n
,2);ratio
= ThiesenResult
(n
,3); st_Index
= map(num2str
(stcd
));result
(t
,subbasinID
) = result
(t
,subbasinID
) + allData
{st_Index
}(t
,dataColNum
) * ratio
; endwaitbar
(t
/timeStpes
)
end
close
(h
);%% 輸出
h
= waitbar
(0,'正在輸出結果...');
fid
=fopen
(outputFile
,'w');
for t
= 1:timeStpes
for n
= 1:subbasinNumfprintf
(fid
,'%.4f \t',result
(t
,n
));endfprintf
(fid
,'\n');waitbar
(t
/timeStpes
)
end
fclose
(fid
);
close
(h
);
總結
以上是生活随笔為你收集整理的用泰森多边形法求子流域气象数据的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。