TRMM数据.nc格式IDL批量转换为.tif格式

TRMM介绍

     热带降雨测量卫星(Tropic Rainfall Measurement Mission,TRMM)是美国宇航局(NASA)和日本宇航探索局(JAXA)曾在1997年时联手发射在全球的热带上空的一种遥感卫星,主要是用来观测降水的,其最开始的观测区域是南纬38°北纬38°、西经180°东经180°,在2001年8月时TRMM卫星进行了一次变轨,因此它的观测范围扩展到了南纬50°~北纬50°,它的观测范围显然扩大了。下载的TRMM数据格式为.nc,往往需要转换为.tif格式,这里详细介绍一下IDL批量转为tif格式。

     打开IDL软件,在IDL软件下通过编写代码实现TRMM数据.nc格式批量转换为tif 格式,转换前得先准备好存放文件夹。转换的代码如下所示:

pro batch ;

reftif = read_tiff('E:\2018\GIS Spacial anlayse\GISkeshe\Point\precipitation_Layer1.tif',geotiff=geo);

filelist = file_search('F:\TRMM\trmm\','*.nc');

   for i=0,n_elements(filelist)-1 do begin

   name = strsplit(file_basename(filelist[i]),'_',/Extract);3B43.20120101.7.HDF.nc

   tifname = name[0] + '_' + name[0] 

   data_SMOS = ncdf_readv(filelist[i],varname = 'precipitation')

   index = where(data_SMOS ge 1e+020) & data_SMOS[index]=0

   

   data_AOT = ncdf_readv(filelist[i],varname = 'precipitation')

   index = where(data_AOT ge 1e+020) & data_AOT[index]=0

   

   ;data_SH = ncdf_readv(filelist[i],varname = 'Qair_GDS0_SFC')

   ;index = where(data_SH ge 1e+020) & data_SH[index]=0

   dim = size(data_SMOS)

   data_SMOS2 = fltarr(dim[1],dim[2])

   data_AOT2 = fltarr(dim[1],dim[2])

   data_SMOS3 = fltarr(dim[2],dim[1])

   data_AOT3 = fltarr(dim[2],dim[1])

   ;data_SH2 = fltarr(dim[1],dim[2])

   for m = 0,dim[1]-1 do begin

     for n = 0,dim[2]-1 do begin

        data_SMOS2[m,n] = data_SMOS[m,abs(n-dim[2]+1)]

        data_AOT2[m,n] = data_AOT[m,abs(n-dim[2]+1)]

        ;data_SH2[m,n] = data_SH[m,abs(n-dim[2]+1)]

     endfor

   endfor

   for n = 0,dim[2]-1 do begin

     for m = 0,dim[1]-1 do begin

       data_SMOS3[n,m] = data_SMOS2[m,n]

       data_AOT3[n,m] = data_AOT2[m,n]

       ;data_SH2[m,n] = data_SH[m,abs(n-dim[2]+1)]

     endfor

   endfor

   for n = 0,dim[2]-1 do begin

     for m = 0,dim[1]-1 do begin

       data_SMOS3[n,m] = data_SMOS2[m,dim[2]-1-n]

       data_AOT3[n,m] = data_AOT2[m,dim[2]-1-n]

       ;data_SH2[m,n] = data_SH[m,abs(n-dim[2]+1)]

     endfor

   endfor ;

   write_tiff,'E:\2018\GIS Spacial anlayse\GISkeshe\Point\'+tifname+'.tif',data_AOT3,geotiff=geo,/FLOAT

   endfor 

end;

function ncdf_readv, ncdf_file, varname = varname

if (n_params() ne 1) then $

  message, 'USAGE: result = ncdf_readv(ncdf_file, varname=varname)';

if (keyword_set(varname) eq 0) then begin

    print, 'Keyword VARNAME not supplied, returning array of variable names'

    cdfid = ncdf_open(ncdf_file)

    namearr = ncdf_vardir(cdfid)

    ncdf_close, cdfid

    return, namearr

endif

; Get data

cdfid = ncdf_open(ncdf_file)

;varid = ncdf_varid(cdfid,GRIB_name)

varid = ncdf_varid(cdfid,varname)

ncdf_varget,cdfid,varid,data

; Close netCDF files

ncdf_close, cdfid

return, data

end

你可能感兴趣的:(TRMM数据.nc格式IDL批量转换为.tif格式)