我有一个netCDF文件,该文件具有基于气候模型输出的降水,分辨率为1/16度。另外,我有特定的点(纬度/经度),我想从包含该特定纬度/经度的网格单元中提取数据。到目前为止,我已经准备好了可以一次完成一个期望的经/纬度的代码。我该如何处理大约20个独特的经/纬度点(例如,从电子表格中获取),并为每个输出点输出文件(文件名作为每个感兴趣位置的ID#)?
这是我到目前为止所拥有的:
使用特定的LAT / LON读取netCDF数据并将数据写入CSV:
clear all, clc
ncdisp('Extraction_pr.nc');
指定数据目录:
filename=('Extraction_pr.nc');
指定要读取的变量:
pr=ncread(filename,'pr'); %name of netCDF file; 'pr' is the precip variable
time=ncread(filename,'time');
lon=ncread(filename,'lon');
lat=ncread(filename,'lat');
查找经纬度和最接近输入点的位置:
location_lat = knnsearch(lat,32.733);
location_lon = knnsearch(lon,-107.65);
pr1=pr(location_lon,location_lat, 1:end, 1);
pr11=squeeze(pr1);
pr111=pr11';
[years,months,days] = datevec(double(time)+datenum('1900-01-01'));
timeA=datevec(double(time)+datenum('1900-01-01'));
pr2=cat(2,years,months,days, pr11);
dlmwrite('pr_ID_64.csv', pr2) ;
这是我从代码中获得的输出示例:
1950 1 1 5.4268
1950 1 2 4.1988
1950 1 3 0
1950 1 4 0
1950 1 5 0
1950 1 6 0
1950 1 7 0
1950 1 8 0
1950 1 9 0
1950 1 10 0
1950 1 11 0.045451
1950 1 12 1.1241
1950 1 13 0
1950 1 14 0
1950 1 15 0
1950 1 16 0
1950 1 17 0
1950 1 18 0
1950 1 19 3.3355
1950 1 20 0.0078715
1950 1 21 0.31236
1950 1 22 0
1950 1 23 0
1950 1 24 0
1950 1 25 0
1950 1 26 0
1950 1 27 0
1950 1 28 0.025075
1950 1 29 0.60354
1950 1 30 0
1950 1 31 0
1950 2 1 0
1950 2 2 0
1950 2 3 0
1950 2 4 0.12936
1950 2 5 0
1950 2 6 7.4807
1950 2 7 1.0308
1950 2 8 0.14395
1950 2 9 0
1950 2 10 0
1950 2 11 0
1950 2 12 0
1950 2 13 0
1950 2 14 0
1950 2 15 0
1950 2 16 0
1950 2 17 0
1950 2 18 0
1950 2 19 0
1950 2 20 0
1950 2 21 0
1950 2 22 0
1950 2 23 0
1950 2 24 0
1950 2 25 0
1950 2 26 0
1950 2 27 0.68446
1950 2 28 0
1950 3 1 0
1950 3 2 0
1950 3 3 0
1950 3 4 0
1950 3 5 0.086653
1950 3 6 2.9108
1950 3 7 0
1950 3 8 0
1950 3 9 0
1950 3 10 0
1950 3 11 0
1950 3 12 0
1950 3 13 0
1950 3 14 0
1950 3 15 0
1950 3 16 0.06279
1950 3 17 0.043666
1950 3 18 0
1950 3 19 0
1950 3 20 0
1950 3 21 0
1950 3 22 0
1950 3 23 0
1950 3 24 0
1950 3 25 0.6046
1950 3 26 0.46395
1950 3 27 0
1950 3 28 0
1950 3 29 0
1950 3 30 0
1950 3 31 0
1950 4 1 0
1950 4 2 0
1950 4 3 0
1950 4 4 0.89828
1950 4 5 1.1072
1950 4 6 0
1950 4 7 0
1950 4 8 0
1950 4 9 0
1950 4 10 0
1950 4 11 0
1950 4 12 0
1950 4 13 0
1950 4 14 0
1950 4 15 0
1950 4 16 0
1950 4 17 0.87425
1950 4 18 1.7517
1950 4 19 0.96005
1950 4 20 3.729
1950 4 21 0.10016
1950 4 22 0
1950 4 23 0
1950 4 24 0
1950 4 25 0
1950 4 26 0
1950 4 27 0
1950 4 28 0
1950 4 29 0
1950 4 30 0
任何帮助或建议,我们将不胜感激!