X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 25 Nov 2008 01:17 AM by  anon
how to calculate NDVI for tons of MODIS images using IDL
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
25 Nov 2008 01:17 AM
    Hi guys, I've been quite familiar with ENVI, were using it at school. I have recently discovered IDL and using some of the procedures I found on the net, i find it really good and useful. I know how to compute NDVI, EVI and LSWI using ENVI's band math but it would be really time consuming if im gonna compute the vegetation indices one by one for all images using band math. I am still in the process of learning IDL and without a background in programming i find it really hard to write a procedure for calculating ndvi, evi, lswi for tons of images. DO you have any suggestions on how i can do this in IDL? Any help I cant get from you guys will be greatly appreciated. Thank you very much in advance. :) Sincerely, Onyang

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    25 Nov 2008 09:35 AM
    If you still have access to ENVI, you can use the batch routine 'NDVI_DOIT' to calculate NDVI for several images.  For other indices, you would need to use MATH_DOIT.  You need to set up a loop to work through each file. There is an example of both the NDVI and MATH DOIT routines in the ENVI Help.  To process multiple files, you need to loop through each input set of files.  The basics include searching a folder for files to process, then feed each file into the routine.  For example: pro ndvi_batch  compile_opt idl2  ;set up path to input and output files  input_path = 'c:\myInputData\'  ;change to output directory where I want the processed files to be placed  cd, 'C:\myProcessedData\'     ; search for data files in the specified directory     files = FILE_SEARCH(input_path + '*.dat', count=count)     IF (count EQ 0) THEN BEGIN   PrintF, 'No files were found to process'  ENDIF   for i=0, count-1 do begin         envi_open_file, files[i], r_fid=fid         if (fid eq -1) then begin             envi_batch_exit             return         endif  envi_file_query, fid, dims=dims, ns=ns, nl=nl, fname=filename  ;set pos array for calculating NDVI    pos  = [4,3] - 1    ;set the output file names by stripping out the base name and appending 'ndvi.img'    out_name = file_basename(filename, '.dat') + '_ndvi.img'  ;call the doit    envi_doit, 'ndvi_doit', $      fid=fid, pos=pos, dims=dims, $      /check, o_min=0, o_max=255, $      out_name=out_name, r_fid=r_fid  endfor end BAND_MATH is a little more complicated when setting up the FID and POS but the idea is the same.

    Deleted User



    New Member


    Posts:
    New Member


    --
    25 Nov 2008 05:21 PM
    Thank you so much mminari! Your help is deeply appreciated. You made my life easier today. God bless you.

    Deleted User



    New Member


    Posts:
    New Member


    --
    03 Feb 2010 08:46 PM
    hi,   i applying this code to modis data (mod13a2)  but when im trying to run it, the error message appear   % Type conversion error: Unable to convert given STRING to Long. % Detected at: NDVI_BATCH         16 C:\mod13a2_ndvi\mod13a2_ndvi\ndvi_batch.pro % PRINTF: File is not open for output. Unit: 0, File: % Execution halted at: NDVI_BATCH         16   C:\mod13a2_ndvi\mod13a2_ndvi\ndvi_batch.pro %                      $MAIN$          how i can overcome this error?   i really need your help. thank you very much.
    You are not authorized to post a reply.