资源描述:
《NetCDF格式转换TIFF-以全球GIMMS3g-NDVI数据为例.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、NetCDF格式转换TIFF-以全球GIMMS3gNDVI数据为例1.全球GIMMS3gNDVI数据格式为.nc4.通过Matlab中的ncdisp即可查看数据内容。2.数据范围为全球尺度,[-9090][-180180]3.每个GIMMS3gNDVI数据中包含十二幅栅格影像,时间尺度为每月两幅。Matlab代码如下%%clear;clc%%settheinputpathforcontaininginputdataInputPath='input';%readthenerCDF4file%initialimagelat[-
2、9090]lon[-180180]filename='*.nc4';OutputPath=(['output']);ifexist(OutputPath,'dir')==0%whenthedirexist,thevalueis7,orthevalueis0mkdir(OutputPath);%buildthenewdirectendIfiles=dir([InputPath,filename]);nIfiles=length(Ifiles);%%addthereferenceinformation%setthemaximu
3、mandminimunlatitudeandlongitudelatlim=[-9090];lonlim=[-180180];%definethegeo-referenceR=georefcells(latlim,lonlim,[36007200],'ColumnsStartFrom','north');fornf=1:nIfilesIfilename=Ifiles(nf).name;Ifiletime=Ifilename(end-6);year=Ifilename(end-12:end-9);year=str2double
4、(year);IData=ncread([InputPath,Ifilename],'ndvi');%each.nc4filecontain12NDVIimagesinhalfyearifstr2double(Ifiletime)==1Imonth=1;elseImonth=7;endfori=1:12ndvidata=IData(:,:,i);ndvidata=ndvidata';%resamplethedatato0.05degreendvi05deg=imresize(ndvidata,[36007200],'near
5、est');ndvi05deg=double(ndvi05deg)/10000;ndvi05deg(ndvi05deg(:,:)<=0)=NaN;ifmod(i,2)==0ndviname=year*10000+Imonth*100+2;ndviname=num2str(ndviname);%savethematfilesave([OutputPath,ndviname,'.mat'],'ndvi05deg','-v7.3');%saveaTIFFimagegeotiffwrite([OutputPath,ndviname]
6、,ndvi05deg,R);%%converttheNDVIfromhalfmonthtomonth%choosethemaxinumasthemonthndvivlaueNDVImax=ndvi05deg;C1=(NDVImax-NDVI1>=0);C2=(NDVI1-NDVImax>0);NDVImon=C1.*NDVImax+C2.*NDVI1;%savethematfilendviMoname=year*100+Imonth;ndviMoname=num2str(ndviMoname);save([OutputPat
7、h,ndviMoname,'.mat'],'NDVImon','-v7.3');%saveaTIFFimagegeotiffwrite([OutputPath,ndviMoname],NDVImon,R);clearC1C2NDVI1NDVImaxNDVImon;Imonth=Imonth+1;elsendviname=year*10000+Imonth*100+1;ndviname=num2str(ndviname);%savethematfilesave([OutputPath,ndviname,'.mat'],'ndv
8、i05deg','-v7.3');%saveaTIFFimagegeotiffwrite([OutputPath,ndviname],ndvi05deg,R);NDVI1=ndvi05deg;endendend