Hi all,
I am new to IDL, so there could be a simple solution to my problem. I am trying to write a simple code that will take single band tiffs as inputs (MODIS bands 1, 2, and 7 for each day in a ~2 week period), stretch each band based on a range of values which are already predetermined (linear stretch using absolute min/max input values), and then stack the bands to create a 721 false color composite for each date.
Right now, I am just testing the code on one date. I am able to successfully perform the stretch on the individual bands. Whenever I call ENVI_LAYER_STACKING_DOIT routine, I get an error regarding the dimension parameter.
At first, I used the same dims array that was successful when applied to the stretch. These values were derived from the EXELIS reference page (
http://www.exelisvis.com/docs/ENVI_LA...):
dims = [-1L, 0, 399, 0 ,399] *My images are 400x400 pixels and I wish to use the entire image
In doing so, I got the following error (in a pop-up ENVI dialog box):
"envi_layer_stacking_doit: An error has occurred during processing
Error: "Attempt to subscript DIMS with I is out of range." The result may be invalid"
So, I changed the DIMS parameter to what you see in my code (written below), just to be sure the dimensions did not change after stretching (which they didn't), but got the same error.
_____________________________________________________________________________________
; now use stretched band outputs from above (rFIDx will be the input identifiers) as ;the inputs for layer stacking:
; set output path:
compOut = outpath + 'composites\' + date + 'comp1.tif'
; set parameters:
; in order: stretched band 7, stretched band 2, stretched band 1 (for false color composite 721)
rFIDarr = [rfid7, rfid2, rfid1]
; position array: first (and only) band of each band file
POSarr = [0, 0, 0]
; get projection info (same for all 3 bands)
proj = ENVI_GET_PROJECTION(FID=rFID1)
; since using the same DIMS=dims array as I did when stretching gives an error for ;stacking, try using explicit dims from output stretched band files (even though all ;input images are 400x400 pixels):
envi_file_query, rfid1, dims=dims1
envi_file_query, rfid2, dims=dims2
envi_file_query, rfid7, dims=dims7
ENVI_DOIT, 'ENVI_LAYER_STACKING_DOIT', DIMS = dims1, FID= rFIDarr, OUT_DT = 1, OUT_NAME= compOut, OUT_PROJ= proj, OUT_PS = [250, 250], POS = POSarr, R_FID= compFID
_____________________________________________________________________________________
Does anyone have any idea why this might be happening? Does it have something to do with the fact that I am now applying it to a process that takes 3 bands as input instead of just one? I have been looking everywhere and can't seem to find a fix. The ENVI API reference docs describe the DIMS keyword the exact same way for both STRETCH_DOIT and LAYER_STACKING_DOIT, so I'm confused as to why the same array will work for one and not the other.
What am I missing? Any input/help/comments would be so greatly appreciated. The entire code is down below.
Thanks in advance.
_______________________________________________________________________________
PRO teststretch
e = ENVI()
inpath= 'C:\Users\mwooten3\Desktop\Projects\Recover\PonyFireTask\VisualizePF\clippedbands_400x400\'
; stretch testing, file path will change when no longer testing
outpath= 'C:\Users\mwooten3\Desktop\Projects\Recover\PonyFireTask\VisualizePF\IDLtest_stretch\'
; set the date to variable for iteration
date = string(230)
date = strtrim(date, 2)
print, date
;set path of input bands:
inBand1 = inpath + 'B1.' + date + 'clip.tif'
inBand2 = inpath + 'B2.' + date + 'clip.tif'
inBand7 = inpath + 'B7.' + date + 'clip.tif'
;set the name of the output bands (output of step 1 --> input of step 2):
stretchBand1 = outpath + 'stretched\B1.' + date + 'stretch1.tif'
stretchBand2 = outpath + 'stretched\B2.' + date + 'stretch1.tif'
stretchBand7 = outpath + 'stretched\B7.' + date + 'stretch1.tif'
; open existing data file (band tiffs for each band) to access file FID for each band
ENVI_OPEN_DATA_FILE, inBand1, R_FID=fid1, /TIFF
ENVI_OPEN_DATA_FILE, inBand2, R_FID=fid2, /TIFF
ENVI_OPEN_DATA_FILE, inBand7, R_FID=fid7, /TIFF
;set spatial dimensions equal to the entire image (400x400 pixels); this is true for each band
dims = [-1L, 0, 399, 0, 399]
; use ENVI's stretch routine to stretch the band (min/max values depend on band being stretched)
; rFIDx will be used as input for next step
; band 1 (blue):
ENVI_DOIT, 'STRETCH_DOIT', DIMS = dims, FID=fid1, I_MAX = 1600, I_MIN = 500, METHOD = 1, OUT_DT = 1, OUT_MAX = 255, OUT_MIN = 0, OUT_NAME = stretchBand1, POS = [0], R_FID= rfid1, RANGE_BY=1
; band 2 (green):
ENVI_DOIT, 'STRETCH_DOIT', DIMS = dims, FID=fid2, I_MAX = 3000, I_MIN = 800, METHOD = 1, OUT_DT = 1, OUT_MAX = 255, OUT_MIN = 0, OUT_NAME = stretchBand2, POS = [0], R_FID= rfid2, RANGE_BY=1
; band 7 (red):
ENVI_DOIT, 'STRETCH_DOIT', DIMS = dims, FID=fid7, I_MAX = 2800, I_MIN = 700, METHOD = 1, OUT_DT = 1, OUT_MAX = 255, OUT_MIN = 0, OUT_NAME = stretchBand7, POS = [0], R_FID= rfid7, RANGE_BY=1
; now use stretched band outputs from above (rFIDx will be the input identifiers) as the inputs for layer stacking:
; set output path:
compOut = outpath + 'composites\' + date + 'comp1.tif'
; set parameters:
; in order: stretched band 7, stretched band 2, stretched band 1 (for false color composite 721)
rFIDarr = [rfid7, rfid2, rfid1]
; position array: first (and only) band of each band file
POSarr = [0, 0, 0]
; get projection info (same for all 3 bands)
proj = ENVI_GET_PROJECTION(FID=rFID1)
;since using the same DIMS=dims array as I did when stretching gives an error for ;stacking, try using explicit dims from output stretched band files (even though all input images are 400x400 pixels):
envi_file_query, rfid1, dims=dims1
envi_file_query, rfid2, dims=dims2
envi_file_query, rfid7, dims=dims7
ENVI_DOIT, 'ENVI_LAYER_STACKING_DOIT', DIMS = dims1, FID= rFIDarr, OUT_DT = 1, OUT_NAME= compOut, OUT_PROJ= proj, OUT_PS = [250, 250], POS = POSarr, R_FID= compFID
RETURN
END