福衛七號的大氣觀測資料
下載福衛七號的某一天整天的大氣觀測資料,例如:2024年的第65天(2024/3/5) https://tacc.cwa.gov.tw/data-service/fs7rt_tdpc/level2/wetPf2/2024.065/,下載後的檔案儲存在"C:\fs7data\fs7_2024065"的資料夾中。
使用Octave的程式功能下載大量的檔案需要等待一段時間;如要節省時間,可以運用網路上的免費軟體下載大量的檔案。
% 安裝io函式庫,以便用於大量資料的讀寫
pkg install -forge io
pkg load io
% 目標 URL 應該指向包含檔清單的頁面
url = 'https://tacc.cwa.gov.tw/data-service/fs7rt_tdpc/level2/wetPf2/2024.065/'; % 替換為實際 URL
% 本地目錄,用於保存下載的檔
output_dir = 'C:\fs7data\fs7_2024065'; % 替換為實際的本地目錄
if ~exist(output_dir, 'dir')
mkdir(output_dir);
end
% 下載目錄頁面內容
html = urlread(url);
% 使用規則運算式提取所有檔連結
file_links = regexp(html, 'href="(.*?)"', 'tokens');
file_links = [file_links{:}];
% 迴圈下載每個檔
for i = 1:length(file_links)
file_url = [url file_links{i}];
output_file = fullfile(output_dir,
file_links{i});
try
urlwrite(file_url, output_file);
fprintf('Downloaded: %s\n', output_file);
catch
fprintf('Failed to download: %s\n', file_url);
end
end
fprintf('All files downloaded to %s\n', output_dir);
尋找所有檔案的對流層頂高度,這裡直接設定溫度最低的高度,因為數據只有顯示大約60km以內的高度資料,最低溫仍是在對流層頂;並將數據儲存在c:\fs7data\results.csv檔案裡。
% 安裝和載入 netcdf 套件
pkg load netcdf
% 設置資料夾路徑和結果文件路徑
folder_path = 'C:\fs7data\fs7_2024065';
result_file = 'C:\fs7data\results.csv';
% 找到所有_nc結尾的NetCDF檔案
file_list = dir(fullfile(folder_path, '*_nc'));
% 打開結果文件
fid = fopen(result_file, 'w');
% 寫入CSV文件的標題
fprintf(fid, 'File,Minimum_Temperature,Height,Longitude,Latitude\n');
% 遍歷每個檔案並處理
for i = 1:length(file_list)
file_path = fullfile(folder_path, file_list(i).name);
try
% 開啟 NetCDF 檔案
ncid = netcdf_open(file_path, 'NC_NOWRITE');
% 讀取溫度、高度、經度和緯度資料
temp = netcdf_getVar(ncid, netcdf_inqVarID(ncid, 'Temp'));
height = netcdf_getVar(ncid, netcdf_inqVarID(ncid, 'MSL_alt'));
lon = netcdf_getVar(ncid, netcdf_inqVarID(ncid, 'lon'));
lat = netcdf_getVar(ncid, netcdf_inqVarID(ncid, 'lat'));
% 找到最低溫度的位置
[min_temp, min_temp_index] = min(temp(:));
% 將線性索引轉換為多維索引
[i1, i2, i3] = ind2sub(size(temp), min_temp_index);
% 根據找到的位置,取得對應的高度、經度和緯度
min_height = height(i1, i2, i3);
min_lon = lon(i3);
min_lat = lat(i2);
% 寫入結果文件
fprintf(fid, '%s,%f,%f,%f,%f\n', file_list(i).name, min_temp, min_height, min_lon, min_lat);
% 關閉 NetCDF 檔案
netcdf_close(ncid);
catch
fprintf('Error processing file: %s\n', file_list(i).name);
if exist('ncid', 'var')
netcdf_close(ncid);
end
end
end
% 關閉結果文件
fclose(fid);
將c:\fs7data\results.csv的內容以文字方式顯示出來。
% 讀取 CSV 文件,跳過第一行(標題行)
file_path = 'c:\fs7data\results.csv';
data = csvread(file_path); % 從第一行開始讀取
% data = csvread(file_path, 1, 0); % 從第二行開始讀取
% 顯示 CSV 檔內容
disp('FileName, MinTemp, MinMSLAlt, lon, lat');
more
disp(data);
將c:\fs7data\results.csv的"對流層頂高度"和"經緯度"以3D圖顯示出來。
pkg load io % 載入 IO 包以讀取 CSV 檔
% 讀取 CSV 文件,跳過第一行(標題行)
file_path = 'c:\fs7data\results.csv';
data = csvread(file_path, 1, 0); % 從第二行開始讀取
% 提取經度、緯度和高度資料
lon = data(:, 4); % 假設經度在第四列
lat = data(:, 5); % 假設緯度在第五列
height = data(:, 3); % 假設高度在第三列
% 繪製三維散點圖
figure;
scatter3(lon, lat, height, 'filled');
xlabel('Longitude');
ylabel('Latitude');
zlabel('Height');
title('3D Scatter Plot of Longitude, Latitude, and Height');
% 繪製三維表面圖(插值)
figure;
lon_dense = linspace(min(lon), max(lon), 100);
lat_dense = linspace(min(lat), max(lat), 100);
[lon_grid, lat_grid] = meshgrid(lon_dense, lat_dense);
height_grid = griddata(lon, lat, height, lon_grid, lat_grid);
surf(lon_grid, lat_grid, height_grid);
shading interp; % 平滑渲染
colorbar; % 添加顏色條 (有colorbar的話,3D圖不能旋轉)
xlabel('Longitude');
ylabel('Latitude');
zlabel('Height');
title('3D Surface Plot of Longitude, Latitude, and Height');
將c:\fs7data\results.csv的"對流層頂高度"和"經緯度"以平面圖顯示出來。
pkg load io % 載入 IO 包以讀取 CSV 檔
% 讀取 CSV 文件,跳過第一行(標題行)
file_path = 'c:\fs7data\results.csv';
data = csvread(file_path, 1, 0); % 從第二行開始讀取
% 提取經度、緯度和高度資料
lon = data(:, 4); % 假設經度在第四列
lat = data(:, 5); % 假設緯度在第五列
height = data(:, 3); % 假設高度在第三列
% 繪製二維散點圖,使用高度進行著色
figure;
scatter(lon, lat, 36, height, 'filled'); % 36 是點的大小
xlabel('Longitude');
ylabel('Latitude');
title('Scatter Plot of Longitude, Latitude, and Height');
colorbar; % 添加顏色條
將c:\fs7data\results.csv的"對流層頂高度"和"經緯度"以平面圖顯示出來,並內插填滿所有網格點。
pkg load io % 載入 IO 包以讀取 CSV 檔
% 讀取 CSV 文件,跳過第一行(標題行)
file_path = 'c:\fs7data\results.csv';
data = csvread(file_path, 1, 0); % 從第二行開始讀取
% 提取經度、緯度和高度資料
lon = data(:, 4); % 假設經度在第四列
lat = data(:, 5); % 假設緯度在第五列
height = data(:, 3); % 假設高度在第三列
% 創建更密集的經度和緯度網格
lon_dense = linspace(min(lon), max(lon), 100); % 創建 100 個均勻分佈的經度值
lat_dense = linspace(min(lat), max(lat), 100); % 創建 100 個均勻分佈的緯度值
[lon_grid, lat_grid] = meshgrid(lon_dense, lat_dense); % 創建經緯度的二維網格
% 使用 griddata 進行插值
interpolated_height = griddata(lon, lat, height, lon_grid,
lat_grid);
% 繪製填充後的資料
% 使用 pcolor 函數繪製填充圖,並設置邊界線為不可見
figure;
pcolor(lon_grid, lat_grid, interpolated_height);
shading interp; % 平滑渲染
colorbar; % 添加顏色條
title('Interpolated Height Data');
xlabel('Longitude');
ylabel('Latitude');
將c:\fs7data\results.csv的"對流層頂高度"和"經緯度"以平面圖顯示出來,內插填滿所有網格點,並劃出全球海岸線。
下載簡易的海岸線向量檔,並儲存在c:/fs7data/資料夾中
https://www.naturalearthdata.com/downloads/110m-physical-vectors/
pkg load io % 載入 IO 包以讀取 CSV 檔
pkg load mapping % 載入 Mapping 包以讀取 Shapefile 檔
% 讀取 CSV 文件,跳過第一行(標題行)
file_path = 'c:\\fs7data\\results.csv';
data = csvread(file_path, 1, 0); % 從第二行開始讀取
% 提取經度、緯度和高度資料
lon = data(:, 4); % 假設經度在第四列
lat = data(:, 5); % 假設緯度在第五列
height = data(:, 3); % 假設高度在第三列
% 過濾經緯度在-180到180之間的資料
valid_idx = (lon >= -180 & lon <= 180) & (lat >= -90 & lat <= 90);
lon = lon(valid_idx);
lat = lat(valid_idx);
height = height(valid_idx);
% 創建更密集的經度和緯度網格
lon_dense = linspace(-180, 180, 100); % 創建 100 個均勻分佈的經度值
lat_dense = linspace(-90, 90, 100); % 創建 100 個均勻分佈的緯度值
[lon_grid, lat_grid] = meshgrid(lon_dense, lat_dense); % 創建經緯度的二維網格
% 使用 griddata 進行插值
interpolated_height = griddata(lon, lat, height, lon_grid, lat_grid);
% 繪製填充後的資料
figure;
pcolor(lon_grid, lat_grid, interpolated_height);
shading interp; % 平滑渲染
colorbar; % 添加顏色條
title('對流層高度');
xlabel('Longitude');
ylabel('Latitude');
hold on;
% 讀取 Shapefile 文件
coastline = shaperead('c:\\fs7data\\ne_110m_coastline.shp');
% 繪製海岸線
for k = 1:length(coastline)
plot(coastline(k).X, coastline(k).Y, 'k'); % 使用黑色繪製海岸線
end
hold off;
% 設置 x 軸和 y 軸比例相同
axis equal;
% 設置 x 軸和 y 軸範圍
xlim([-180 180]);
ylim([-90 90]);
將c:\fs7data\results.csv的"對流層頂溫度"和"經緯度"以平面圖顯示出來,內插填滿所有網格點,並劃出全球海岸線。
pkg load io % 載入 IO 包以讀取 CSV 檔
pkg load mapping % 載入 Mapping 包以讀取 Shapefile 檔
% 讀取 CSV 文件,跳過第一行(標題行)
file_path = 'c:\fs7data\results.csv';
data = csvread(file_path, 1, 0); % 從第二行開始讀取
% 提取經度、緯度和溫度資料
lon = data(:, 4); % 假設經度在第四列
lat = data(:, 5); % 假設緯度在第五列
temperature = data(:, 2); % 假設溫度在第二列
% 創建更密集的經度和緯度網格
lon_dense = linspace(min(lon), max(lon), 100); % 創建 100 個均勻分佈的經度值
lat_dense = linspace(min(lat), max(lat), 100); % 創建 100 個均勻分佈的緯度值
[lon_grid, lat_grid] = meshgrid(lon_dense, lat_dense); % 創建經緯度的二維網格
% 使用 griddata 進行插值
interpolated_temperature = griddata(lon, lat, temperature,
lon_grid, lat_grid);
% 繪製填充後的資料
% 使用 pcolor 函數繪製填充圖,並設置邊界線為不可見
figure;
pcolor(lon_grid, lat_grid, interpolated_temperature);
shading interp; % 平滑渲染
colorbar; % 添加顏色條
title('對流層頂溫度');
xlabel('Longitude');
ylabel('Latitude');
hold on;
% 讀取 Shapefile 文件
coastline = shaperead('c:\fs7data\ne_10m_coastline.shp');
% 繪製海岸線
for k = 1:length(coastline)
plot(coastline(k).X,
coastline(k).Y, 'k'); % 使用黑色繪製海岸線
end
hold off;
% 設置 x 軸和 y 軸比例相同
axis equal;
% 設置 x 軸和 y 軸範圍
xlim([-180 180]);
ylim([-90 90]);