IDL实现MOD021KM 角度数据重采样中的易错点

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_37970770/article/details/99455537

最近很忙,每天都特别忙碌,也很少有时间去打球了。
想念南京的老铁们,你们还好吗~过得可好,我在北京,想念你们的第53天。
祝愿大家一切都好,北京一切还好,就是北京物价很贵,没有工资补助的我露出了卑微的笑容~

今天和大家分享的是IDL怎么读取MOD021KM MYD021KM中的角度数据,将其重采样到其他的反射率光谱数据的维数大小,即ns = 1354,nl = 2030.重要的是如何避免最容易错的地方,直接po上程序来,如下:
本来我是批处理的,此处简化,po出单景图像的程序,亦可用(中间的其他经纬度代码是我原来读取的时候要用到的,没有用但我就不删除了)。

pro MODIS_angle_resize
  ;***************************启动ENVI批处理模式************************************
  time_begin = systime(1)
  compile_opt idl2
  envi,/restore_base_save_files
  envi_batch_init
  cd,'G:\MODIS_TOA_r_Original\'
  fnames = 'MOD021KM.A2018071.0240.061.2018071132914.hdf'
  out = modis_georef(fnames)
  envi_batch_init
  time_end = systime(1)
  print,'running time :',(time_end-time_begin)/60.0,'mins'
end
;***************************所调用的函数*********************************************
function modis_georef,fn
  ;在函数中也一定要加上编译,否则主过程中的compile不会传到函数中
  compile_opt idl2
  envi,/restore_base_save_files;打开文件
  hd_id = hdf_sd_start(fn)
  ;读取文件数据集数量和属性数量
  hdf_sd_fileinfo,hd_id,nsds,natts
  ;选择打开数据集
  lat_id = hdf_sd_select(hd_id,0)
  long_id = hdf_sd_select(hd_id,1)
  SOZ_id = hdf_sd_select(hd_id,16)
  ;*****************************************读取经纬度数据值*********************************************
  hdf_sd_getdata,lat_id,Lat
  hdf_sd_getdata,long_id,Lon
  hdf_sd_getdata,SOZ_id,SOZ
  SOZ = SOZ*0.01
  ;*****************************************SOZ角度重采样**********************************************
  sz = size(SOZ)
  ns0 = sz[1]
  nl0 = sz[2]
  ;print,angle[58:60,69:71,3]
  envi_enter_data,SOZ,r_fid = SOZ_fid,ns = ns0,nl = nl0,nb= 1,data_type = 4,interleave = 0,offset = 0
  pos = lindgen(1)
  dims = [-1,0,ns0-1,0,nl0-1]
  outname = 'G:\MODIS_TOA_反射率\out1'
  xsize = ns0/1354.0
  ysize = nl0/2030.0
  envi_doit,'resize_doit',fid = SOZ_fid,dims = dims,pos = pos,interp = 1,rfact = [xsize, ysize],out_name =outname ,r_fid = r_fid
  ;关闭数据集
  hdf_sd_endaccess,lat_id
  hdf_sd_endaccess,long_id
  hdf_sd_endaccess,SOZ_id
  hdf_sd_end,hd_id;关闭文件
end

易错点1:
xsize = ns0/1354.0
ysize = nl0/2030.0
重采样的时候设置的xsize和ysize必须是由原来的小size的图像行列数比上最终要得到的重采样后的图像行列号(本程序中是采样到对应的文件中1km反射率波段数据)的大小。或者如果想要扩n倍重采样,则不需要比值,只需要设置:
xsize = 1/n.0
ysize = 1/n.0
一定要.0
易错点2:
dims = [-1,0,ns0-1,0,nl0-1]
envi_doit,‘resize_doit’,fid = SOZ_fid,dims = dims,pos = pos,interp = 1,rfact = [xsize, ysize],out_name =outname ,r_fid = r_fid
在我们本科徐永明老师写的《遥感二次开发语言IDL》书中’resize_doit’这个过程后,对于dims的说明是“重采样后数据的空间范围”,而实际上此处应该是待重采样原始数据的dims,原始待重采样的空间范围。dims数组由一行五列元素组成,其中第一位如果不是用一个已经打开的ROI去重采样的话,就默认用-1,后面四位见下:
DIMS
The “dimensions” keyword is a five-element array of long integers that defines the spatial subset (of a file or array) to use for processing. Nearly every time you specify the keyword FID, you must also specify the spatial subset of the corresponding file (even if the entire file, with no spatial subsetting, is to be processed).

DIMS[0]: A pointer to an open ROI; use only in cases where ROIs define the spatial subset. Otherwise, set to -1L.
DIMS[1]: The starting sample number. The first x pixel is 0.
DIMS[2]: The ending sample number
DIMS[3]: The starting line number. The first y pixel is 0.
DIMS[4]: The ending line number


版权归作者 小白是哪个小白_ 所有,转载、引用请注明链接出处,侵权必纠!

猜你喜欢

转载自blog.csdn.net/qq_37970770/article/details/99455537