Envi 调用 MODIS Reprojection Tool(MRT)对 MODIS 产品进行批处理拼接、重投影、
裁切
1 熟悉 MRT
MODIS 产品的类型不同,一景 HDF 格式的影像包含的波段也各不相同。MRT 处理时
需要选择处理波段,0 表示不作处理,1 表示处理,首先要确定影像的波段数。
1、拼接
Mrtmosaic.exe 程序用来拼接影像。调用方式为:
mrtmosaic -i "g:\n%1.txt" -s " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 0 0 0 0 " -o "g:\temp.hdf"
命令行帮助如下
Usage: mrtmosaic -i input_filenames_file -t -h -o output_filename
-s spectral_subset "b1 b2 ... bN"
-g filename for the log file
需要指定三个参数:
-I 指定输入文件,可以采取两种方式
1、1.hdf 2.hdf 3.hdf
2、把影像的完整路径保存到 txt 文件中,作为 input 参数。如-I MOD092008001.txt。
-s 指定需要处理的波段,同样可以采用两种方式
1、直接给出,如 –s “0 0 0 0 0 0 0 0 0 0 0 0”,注意英文引号;
2、指定一个 txt 路径,让程序读取;
-o 指定输出路径,一般直接给出
1、直接给出,如 –o g:\tmp.hdf。注意直接存为 HDF 格式,便于后续处理。
2、重投影、裁切
Resample.exe 用来重投影、裁切是 MRT 程序的核心。调用方式为:
命令行帮助如下:
Usage: resample -p parameter_file [options]
Options that override parameter file specifications:
-i input_file_name
-o output_file_name
-r resampling_type [NN BI CC NONE]
-t projection_type [AEA ER GEO HAM IGH ISIN LA LCC MERCAT MOL PS
SIN TM UTM]
-j projection_parameter_list "p1 p2 ... p15"
-s spectral_subset "b1 b2 ... bN"
If using the -s switch, the SDSs should be represented as an
array of 0s and 1s. A '1' specifies to process that SDS;
'0' specifies to skip that SDS. Unspecified SDSs will not be processed.
If the -s switch is not specified, then all SDSs will be processed.
-a spatial_subset_type [INPUT_LAT_LONG INPUT_LINE_SAMPLE
OUTPUT_PROJ_COORDS]
-l spatial_subset "ULlat ULlong LRlat LRlong"
-or- "ULline ULsample LRline LRsample (0-based)"
-or- "ULprojx ULprojy LRprojx LRprojy"
NOTE: line/sample must be specified for the
highest resolution
of all SDSs specified
to be processed in the product.
-u UTM_zone
-x pixel_size
-g filename for the log file
可以只指定 1 个参数:
用 –p 读入 prm 参数文件,进行处理。例如 resample -p
"g:\prrmMOD092008001.prm",prm 文件如下:
INPUT_FILENAME = g:\tmp_%1.hdf 输入文件
SPECTRAL_SUBSET = ( 1 1 1 1) 前面 mrtmosaic 拼接结果有 4 个波段
SPATIAL_SUBSET_TYPE = INPUT_LAT_LONG 经纬度裁切方式
SPATIAL_SUBSET_UL_CORNER = ( 33.0 108.0 ) 左上纬经度
SPATIAL_SUBSET_LR_CORNER = ( 28.0 117.0 ) 右下纬经度
OUTPUT_FILENAME = F:\MRT_out\myd%1.tif 输出路径,不同波段自动区分
RESAMPLING_TYPE = NEAREST_NEIGHBOR 最近邻采样方法
OUTPUT_PROJECTION_TYPE = UTM 输出文件投影方式 utm
OUTPUT_PROJECTION_PARAMETERS = (投影参数
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0 )
DATUM = WGS84 大地水准面
UTM_ZONE = 50 投影分带带号
如果不会设置,可以先在图形界面里设置一次,把设置的结果保存下来。
打开刚刚保存的参数文件
去掉以#号打头的注释,文件显示如下:
INPUT_FILENAME = G:\TmpMosaic.hdf
SPECTRAL_SUBSET = ( 1 1 1 1 1 1 1 1 1 1 1 1 )
SPATIAL_SUBSET_TYPE = INPUT_LAT_LONG
SPATIAL_SUBSET_UL_CORNER = ( 32.0 107.0 )
SPATIAL_SUBSET_LR_CORNER = ( 29.0 116.0 )
OUTPUT_FILENAME = G:\mod092001001.tif
RESAMPLING_TYPE = NEAREST_NEIGHBOR
OUTPUT_PROJECTION_TYPE = UTM
OUTPUT_PROJECTION_PARAMETERS = (
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0 )
DATUM = WGS84
UTM_ZONE = 50
如果研究区的经纬度范围不同,可以修改
SPATIAL_SUBSET_UL_CORNER = ( 32.0 107.0 )
SPATIAL_SUBSET_LR_CORNER = ( 29.0 116.0 )两行
如果需要不同的投影,如经纬度投影,可以修改
OUTPUT_PROJECTION_TYPE = UTM
OUTPUT_PROJECTION_PARAMETERS = (
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0 )
DATUM = WGS84
UTM_ZONE = 50
如果拼接时只选择了 1 个波段,可以修改
SPECTRAL_SUBSET = ( 1 )
当然这句
INPUT_FILENAME = G:\TmpMosaic.hdf 批处理是必须改掉的了
关于像素分辨率,一般留空,也就是默认不改变影像的像素大小。
2 关于 DOS 批处理裁切 MOD 产品
单次处理
Dir g:\mod11*A%1*.hdf /s /b >> g:\n%1.txt
f:\mrt\modis\bin\mrtmosaic -i "g:\n%1.txt" -s " 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 " -o
"g:\temp_%1.hdf"
f:\mrt\modis\bin\resample -p "g:\prm%1.prm"
del g:\prm%1.prm /q /f
del g:\n%1.txt /q /f
del g:\temp_%1.hdf /q /f
批量处理
for /f %%i in (e:\lis.txt) do @单次处理文件名 %%i
如果双击运行,用%%i 号表示变量。在命令行中%i 表示变量。
其中 e:\lis.txt 是年份及天数
2008001
2008009
2008017
2008025
2008033
2008041
2008049
G:\n%1.txt 在运行时为 g:\n2008001.txt,其中包括 2008 年第 1 天的多景 MODIS
产品影像名。
Dir g:\mod11*A%1*.hdf /s /b >> g:\n%1.txt
用来列出 g 盘(数据存储盘)以 mod11 打头的指定日期的的 hdf 格式文件,即 MODIS
影像。
这里要说明一下,MODIS 产品命名的规则
MYD11A2.A2002185.h27v05.005.2007221162948.hdf
从左至右,前 7 位表示产品类型 MYD11 指下午星(MYD)第 11 号产品(land surface
temperature),A2 表示处理级别。A2002185 表示过境时间是 2002 年第 185 天,
h27v05 是 MODIS 产品在全球的轨道行列号,中国一般是 h27v05、h27v06、
h28v05、h28v06,005 表示 HDF5 文件格式,早期 MODIS 采用 HDF4 格式存储,
所以有时也可见到 004 的产品。2007 等一串数字表示影像处理的年月日时分秒,hdf
表示存储格式为 EOS-HDF。
了解了 MODIS 产品命名规则之后,可以用 DOS dir 命令来挑选符合条件的 MODIS
产品路径了。
>> g:\n%1.txt 表示把结果转存为 g:\n%1.txt
%1 表示接收的第一个参数,即 2008001
3Envi 生成时间列表
2008001
2008009
2008017
2008025
这样的列表文件可以用在 Envi 中定义一个 pro 来生成:
pro daylist,startdate,enddate,result_txt_path
;example daylist,2008001,2008013,'example.txt'
;
;
a=(startdate mod 1000) /8 *8+(startdate /1000)*1000+1
b=((enddate mod 1000) /8 +1)*8+(enddate /1000)*1000+1
help,a,b
step=8
openw,lun,result_txt_path,/get_lun
res=a;
for i=a,b,step do begin
printf,lun,string(res,format='(%"%7d")')
res=res+step
endfor
free_lun,lun
print,'done';
close,/all