Hello all,
I am writing to request help calculating multiple indices, topo variables, and other transformations (for a large number of files) in one script.
I am working with multiple seven band composites of integer (BSQ) Landsat TM5 surface reflectance and NED elevation data. I need to calculate NDVI, NDWI, and MNDWI on each input file. I also need to calculate some topographic variables including slope, aspect, and hillshade. Finally, if possible, I would like to run a Tasseled Cap and PCA transformation as well.
I recognize that there are functions to call on ENVI for the first set of these calculations:
envi_doit, 'ndvi_doit'
envi_doit, 'topo_doit'
However, here are my concerns:
In regard to the ndvi_doit command, I see that one must designate a position for the band arrays required as input. This is fine, however if I need to calculate multiple indices I will need to be able to designate multiple positions (i.e. NDVI will be pos = [4,3] -1; NDWI will be pos = [2,4] -1; and MNDWI will be pos = [2,5] -1).
For the topo_doit function I will also need to be able to designate one single band from the multi-band image.
Finally, I am unaware currently of a good way to perform Tasseled cap and PCA within IDL so I have not even breached that component as of yet. Any help in this would be wonderful!
So-- The important factor in the whole process is that I will have multiple .dat files in one folder. I will need the program to access this folder, query all .dat files, and perform each of the above tasks on each .dat file. ***I will also need the output files to be separate bands that are named accordingly. For instance I will need an NDVI output labeled with the basename and ndvi, I will need a separate NDWI output labeled as basename and NDWI, and so on.....
Below I have pasted what I have so far. Everything is working up to the point of the second 'for loop' where I am receiving a syntax error on the line: strtrim(string(i+1),2). I have highlighted that point below.
As you will see, I have attempted to set up various positions for the ndvi_doit command, however I currently only have set up for one output name. The latter will have to be adjusted, and I am not sure how. Will I need a new for loop for EVERY variable I wish to calculate? Is there a more efficient way of performing this entire task? I know that some feel 'for loops' to be the worst of all commands, but being very new in IDL programming they seem the easiest for me to currently attempt.
Any suggestions would be greatly appreciated, even if they are to say that I am going about this whole process wrong :)
Thank you!
Allisyn
pro swe_LayerCreation
compile_opt IDL2, hidden
;input path for file_search command to point to
input_path= 'E:\ESPA\'
;here file_search will use the input path indicated above, and read anything with a .dat extension
input_file_list= file_search (input_path + '*.dat')
;this statement creates a string array while maintaining the original base name and removing the .dat extension
rastername= file_basename(input_file_list, '.dat')
;input_file_list is now a string array where each element is the full path to a file
input_fids= lonarr(n_elements(input_file_list))-1
help, input_fids
;envi_open_data_file, ..../LANDSAT_METADATA
for i = 0, n_elements(input_file_list)-1 do begin
envi_open_file, input_file_list[i], r_fid=r_fid
input_fids[i] = r_fid
endfor
;set the necessary variables for the 'doit' command and indicate the positions required for the calculation of multiple indices
envi_file_query, input_fids, dims=dims, nb=nb
posNDVI = [4,3] - 1
posNDWI = [2,4] - 1
posMNDWI = [2,5] - 1
;run a for loop to calculate the indices.
for i = 0, n_elements(input_file_list)-1 do begin
raster_filename = rastername[i] + '_ndvi' + '.ext'
strtrim(string(i+1),2)
;call the envi_doit command for each position designated above
envi_doit, 'ndvi_doit', fid=input_fids[i], dims-dims, $
pos=posNDVI
envi_doit, 'ndvi_doit', fid=input_fids[i], dims-dims, $
pos=posNDWI
envi_doit, 'ndvi_doit', fid=input_fids[i], dims-dims, $
pos=posMNDWI
endfor
print, input_file_list, rastername, input_fids, n_elements (i), posNDVI, posNDWI, posMNDWI
END
|