IDL實現MOD021KM 角度數據重採樣中的易錯點

最近很忙,每天都特別忙碌,也很少有時間去打球了。
想念南京的老鐵們,你們還好嗎~過得可好,我在北京,想念你們的第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


版權歸作者 小白是哪個小白_ 所有,轉載、引用請註明鏈接出處,侵權必糾!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章