NetCDF格式转换TIFF-以全球GIMMS3g-NDVI数据为例

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

NetCDF格式转换TIFF-以全球GIMMS3g NDVI数据为例
1.全球GIMMS3g NDVI数据格式为.nc4. 通过Matlab中的ncdisp即可查看数据内容。

2.数据范围为全球尺度,[-90 90] [-180 180]
3.每个GIMMS3g NDVI数据中包含十二幅栅格影像,时间尺度为每月两幅。

Matlab 代码如下
%%
clear;clc
%% set the input path for containing inputdata
InputPath = 'input\';
% read the nerCDF4 file
% initial image lat [-90 90] lon[-180 180]
filename = '*.nc4';
OutputPath=(['output\']);
if exist(OutputPath,'dir')==0 %when the dir exist, the value is 7,or the value is 0 mkdir(OutputPath); %build the new direct
end
Ifiles = dir([InputPath,filename]);
nIfiles = length(Ifiles);
%% add the reference information
% set the maximum and minimun latitude and longitude
latlim = [-90 90];
lonlim = [-180 180];
% define the geo-reference
R = georefcells(latlim,lonlim,[3600 7200],'ColumnsStartFrom','north');
for nf =1:nIfiles
Ifilename = Ifiles(nf).name;
Ifiletime = Ifilename(end-6);
year = Ifilename(end-12:end-9);
year = str2double(year);
IData = ncread([InputPath,Ifilename],'ndvi');
% each .nc4 file contain 12 NDVI images in half year
if str2double(Ifiletime) ==1
Imonth = 1;
else
Imonth = 7;
end
for i =1:12
ndvidata = IData(:,:,i);
ndvidata = ndvidata';
% resample the data to 0.05 degree
ndvi05deg=imresize(ndvidata,[3600 7200],'nearest');
ndvi05deg= double(ndvi05deg)/10000;
ndvi05deg(ndvi05deg(:,:)<= 0)=NaN;
if mod(i,2) == 0
ndviname = year*10000+Imonth*100+2;
ndviname = num2str(ndviname);
% save the mat file
save([OutputPath,ndviname,'.mat'],'ndvi05deg','-v7.3');
% save a TIFF image
geotiffwrite([OutputPath,ndviname],ndvi05deg,R);
%% convert the NDVI from half month to month
% choose the maxinum as the month ndvi vlaue
NDVImax=ndvi05deg;
C1=(NDVImax-NDVI1>=0);
C2=(NDVI1-NDVImax>0);
NDVImon=C1.*NDVImax+C2.*NDVI1;
% save the mat file
ndviMoname = year*100+Imonth;
ndviMoname = num2str(ndviMoname);
save([OutputPath,ndviMoname,'.mat'],'NDVImon','-v7.3');
% save a TIFF image
geotiffwrite([OutputPath,ndviMoname],NDVImon,R);
clear C1C2NDVI1NDVImax NDVImon;
Imonth = Imonth+1;
else
ndviname = year*10000+Imonth*100+1;
ndviname = num2str(ndviname);
% save the mat file
save([OutputPath,ndviname,'.mat'],'ndvi05deg','-v7.3');
% save a TIFF image
geotiffwrite([OutputPath,ndviname],ndvi05deg,R);
NDVI1=ndvi05deg;
end
end
end。

相关文档
最新文档