X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 06 Apr 2010 02:30 PM by  anon
Image stacking problem
 5 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
06 Apr 2010 02:30 PM
    Greetings,   I am trying to create an image stack in chronological order from the command line as the GUI interface seems to want to read my files in  from last to first and not vice-versa.  To add insult to injury I have 232 files to read just for this one stack  so I cannot be bothered with trying to manually reorder them in the GUI.  I decided to write an IDL function to do this, which successfully reads the imagery into ENVI and records FIDs and dims into separate arrays.  When the function calls 'ENVI_LAYER_STACKING_DOIT, it begins reading in each file, then gives me an ENVI error message box stating 'ENVI Error: An error has occurred during processing.  Error: "Attempt to subscript with is out of range." The result may be invalid.' This message then occurs about 10-12 times before failing outright.  It also doesn't seem to process the files in the proper order either.   Any idea what I am doing wrong here?   Thanks, Guy Serbin

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    07 Apr 2010 01:20 PM
    There is no way to tell without seeing the code you have written.  With a subscripting error, I would suspect the FID, DIMS, or POS arrays of the input files.  If these arrays are not set up to handle the separate files correctly, you would get subscripting errors.

    Deleted User



    New Member


    Posts:
    New Member


    --
    13 Apr 2010 11:32 AM
    here it is: pro modisterrandvitimestack, infiledirectory, infilename, startyear, startday, endyear, endday, fileextension, outfiledirectory, suffix ; By Guy Serbin, ASRC Management Services, USDA/FAS Office of Global Analysis, 1400 Independence Ave. SW, Washington, DC 20250. ; This creates a MODIS Terra NDVI image stack.  Data are assumed to be in 8-bit format. ; This currently only works for images of the same spatial extent, dimensions, etc. ; This will only work for TIFF files from Pekko, without any name changes. ; The output file will be in ENVI Standard format with a ".DAT" file extension. ; Variables: ; infiledirectory - path information for where NDVI images reside. ; infilename - name of files without date or file extension information.  Must be the same for all input images. ; startyear - year in which the first image was collected. ; startday - Julian day for the first image collected. ; endyear - year in which the last image was collected. ; endday - Julian day for the last image collected. ; fileextension – file extension, e.g., “img”, “tif”, “dat”, etc. ; outfiledirectory - directory in which NDVI anomaly data are to be saved. ; suffix - this should appear either blank '' or as '.v1' or '.v2' should the MODIS image have '.v1' or '.v2' prior to the tif extension datevec=[1, 17, 33, 49, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 273, 289, 305, 321, 337, 353] ; load in year to be compared to average if startyear gt endyear then begin   print, 'Start year is greater than end year, please correct.  The start year must be less than or equal to the end year.'   return endif if startyear lt 2000 or endyear lt 2000 then begin   print, 'All MODIS Terra NDVI data are available from 2000 and on.  Please correct.'   return endif years=endyear-startyear+1 startdayloctemp=where(datevec eq startday) enddayloctemp=where(datevec eq endday) startdayloc=startdayloctemp[0] enddayloc=enddayloctemp[0] if startdayloc eq -1 or enddayloc eq -1 then begin   if startdayloc eq -1 then print, 'Invalid start date, see http://pekko.geog.umd.edu/usda/test/data.php for actual dates.'   if enddayloc eq -1 then print, 'Invalid end date, see http://pekko.geog.umd.edu/usda/test/data.php for actual dates.'   return endif if years eq 1 then totalfiles = enddayloc-startdayloc+1 else $ totalfiles = 24-startdayloc+enddayloc+(years-2)*23 print, totalfiles dates=findgen(totalfiles) file_ids=intarr(totalfiles) currentyear=startyear currentloc=startdayloc missingfiles=0 ;load files to be stacked dims=intarr(5,totalfiles) for i=0,totalfiles-1 do begin   if (datevec[currentloc]

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    13 Apr 2010 12:16 PM
    One thing I see is that your POS array is created with indgen.  If you are inputting a series of single band files, then the output POS would be a series of 0s, one for each band.  You could create this with lonarr.  Of course, if you have a mix of files with different bands, it becomes more complicated.  For example, if I had 3 input files with 1, 3, 5 bands, I need a POS array that looks like : [0, 0,1,2,0,1,2,3,4].  The other places you can get hung up on are the FID and DIMS arrays.  This is fairly straight-forward if your input is a series of single band files.   Then the FID array is the FID of each input file and the DIMS array contains the DIMS of each input file.  So if you input 3 single band files, you have a FID array of 3 FIDs and a DIMS array of 3 DIMS.  Again, if the number of input bands varies, it becomes more complicated.  For my example above with 3 files of [1,3,5] bands, I need a FID array of: [fid1, fid2, fid2, fid2, fid3, fid3, fid3, fid3, fid3] and the same goes for DIMS - one for each band in each file.

    Deleted User



    New Member


    Posts:
    New Member


    --
    15 Apr 2010 01:11 PM
    Changing indgen to lonarr for the POS array fixed the problem- everything works now.  Thank you!

    Deleted User



    New Member


    Posts:
    New Member


    --
    20 Jun 2011 03:15 AM
    Hello Serbin Could you share with the revised code to run in IDL/ENVI...I am having 12 months EVI data sets for 9 years and I would like to stack using your code. Could advice me the procedure to run the code. Thanks, Giriraj
    You are not authorized to post a reply.