X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 18 Jun 2015 06:52 AM by  anon
Maximum number of bands in MATH_DOIT
 6 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
18 Jun 2015 06:52 AM
    In MATH_DOIT, is there a limit in the number of bands to include in a mathematical expression? I'm using ENVI 5.0 + IDL 8.2.0. I need to include 155 different bands in the mathematical expression and I get the error "The result is invalid" when I include more than 142 bands: 2.3 + 5.6*B1 + ... + 4.5*B142 + 6.7*B143 + ... Any ideas on what the issue might be?

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    18 Jun 2015 04:29 PM
    Hi Juan, There is a limitation with the number of strings that can be included in the MATH_DOIT for band math. The actual error reads: "Error:"String too long: Execute function." The result may be invalid." which tells you that the error is fromt he string actually being too long. I tested this and the character limit seemed to be about 5600 characters with empty spaces included. You may be able to try and fix this by using strcompress('sample string', /REMOVE_ALL) to see if that will fix your problem. Otherwise, you may need to use the new ENVI API to perform your band math calculations. Here is a small example that you can use which runs the qb_boulder_msi image that comes with the ENVI installation. This also uses the tile iterator to speed things up. Hope this helps! ;Set compile options compile_opt IDL2 e = envi() ; Load an ENVIRaster file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, $ SUBDIRECTORY = ['data']) raster = e.OpenRaster(file) ;Set up output raster same as the input raster except for number of bands newfile = e.GetTemporaryFilename() rasternew = ENVIRaster(URI = newfile, $ NROWS=raster.NROWS, $ NCOLUMNS=raster.NCOLUMNS, $ NBANDS=1, $ SPATIALREF=raster.spatialref, $ DATA_TYPE=4) ;make a tile iterator of first band for input raster because our output will be one band too tiles1 = (ENVIsubsetRaster(raster, BANDS=[0])).CreateTileIterator(MODE='spectral') ;Iterate through tiles FOREACH tile, tiles1 DO BEGIN ;get all spectral data from original raster all_bands = raster.GetData(SUB_RECT=tiles1.CURRENT_SUBRECT) ; declare our bands which is defined by the third index [*,0,band_number-1] ; the * gets all of the elements in the tile, and the 0 is a placeholder ; for the array size of all_bands b1 = all_bands[*,0,0] b2 = all_bands[*,0,1] data = (float(b1) - b2)/(b1 + b2) rasternew.SetTile, data, tiles1 ENDFOREACH rasternew.save view = e.GetView() layer = view.CreateLayer(rasternew)

    Deleted User



    New Member


    Posts:
    New Member


    --
    19 Jun 2015 10:40 AM
    Hi Zach, Thanks a lot for your help. I have removed the empty spaces of the math expression and now it has 2160 characters. Unfortunately it doesn´t work yet, I get the error "An error ocurred in the execution of the given expression. The result is invalid". It doesn´t seem related only to the length of the expression, since the number of characters is much lower than 5600. I´ve checked the math expression several times and I exclude the possibility of a syntax error. I have also tried the new ENVI API to perform the band math calculations, but without success. I´m using ENVI 5.0 + IDL 8.2.0 and some of the functions you suggested, such as "ENVIRaster" and "ENVIsubsetRaster", aren´t available in my version. Currently, I´ve solved the problem by splitting the band math calculation into two steps. Firstly, I´ve calculated some terms of the expression using MATH_DOIT, and then the remaining terms also with MATH_DOIT. Finally, I´ve added both rasters and obtained the expected result. However, this solution isn´t optimal and I´d like to find a more straightforward method.

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    19 Jun 2015 12:12 PM
    Hi Juan, I'm glad to hear that you found a workaround! I would suggest upgrading to the latest and greatest version of IDL + ENVI if you can. There are a lot more features included in the new ENVI API for 5.2 and there will be even more for the next release. The next versions of IDL and ENVI (8.5 and 5.3) will be coming out in a couple of months and they will probably be worth looking into. Would it be possible to include the entire expression for your band math that you are performing? If you would like, I may be able to pass this along and see if anyone else has an idea of what could be wrong with your statement.

    Deleted User



    New Member


    Posts:
    New Member


    --
    22 Jun 2015 02:37 AM
    Hi Zach, I include one of the expressions that I am currently performing: ; Open ENVI e = envi() ; Set directories and file names InPath = 'T:\IN\' OutPath = 'T:\OUT\' IMGFname = 'img.bsq' ; Open image IMG = e.OpenRaster(InPath + IMGFname) IMG_FID = ENVIRasterToFID(IMG) ; Query dimensions of the image envi_file_query, IMG_FID, dims=IMGDims ; Band math IMG_FIDs = [IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID, IMG_FID] IMG_POS = indgen(155, /LONG) IMG_EXP = '-0.1+6.9*B1+6.2*B2+5.4*B3+3.4*B4-3*B5-6.2*B6-8*B7-8.1*B8-7.7*B9-6.5*B10-4.9*B11-2.8*B12+2.8*B13+5*B14+7.2*B15+9*B16+9.3*B17+8.2*B18+6.3*B19+4.4*B20+2.6*B21-2.5*B22-3.4*B23-3.8*B24-3.7*B25-3.9*B26-4.1*B27-4.2*B28-3.9*B29-3.6*B30-3.3*B31-3*B32-2.9*B33-2.8*B34-2.8*B35-2.8*B36-2.9*B37-3.1*B38-3.2*B39-3.3*B40-3.4*B41-3.4*B42-3.4*B43-3.3*B44-3.2*B45-3*B46-2.8*B47-2.6*B48-2.3*B49-2*B50+1.8*B51+3.1*B52+3.4*B53+3.5*B54+1.8*B55-2.5*B56-2.3*B57+1.9*B58+2*B59+2*B60+2.1*B61+2.1*B62+2*B63+2.2*B64+2.5*B65+2.8*B66+3.2*B67+3.6*B68+3.9*B69+4.3*B70+4.5*B71+4.7*B72+4.8*B73+4.8*B74+4.8*B75+4.6*B76+4.3*B77+4*B78+3.8*B79+3.5*B80+3.3*B81+3*B82+2.6*B83+2.2*B84-1.8*B85-2.1*B86-2*B87+1.9*B88+5.4*B89+5*B90+4.5*B91+4*B92+3.5*B93+3.1*B94+2.7*B95+2.3*B96+2*B97-1.8*B98-2.1*B99-2.4*B100-2.8*B101-3.2*B102-3.6*B103-3.9*B104-4.1*B105-4*B106-3.9*B107-3.6*B108-3.4*B109-3.2*B110-2.9*B111-2.5*B112-2.2*B113-2.3*B114-2.9*B115-3.3*B116-3.6*B117-4.1*B118-4.6*B119-5*B120-5.2*B121-6.1*B122-4.8*B123-3.3*B124-2.1*B125+2.3*B126+2.7*B127+3*B128+3.3*B129+3.5*B130+3.7*B131+4*B132+4.2*B133+4*B134+2.9*B135-2.4*B136-4.5*B137-6.8*B138-9.8*B139-12.5*B140-12.7*B141-10.3*B142-7.4*B143-4.4*B144+2.6*B145+5.4*B146+7.2*B147+8.1*B148+8.9*B149+9.1*B150+7.4*B151+5.9*B152+5.1*B153+4.5*B154+3.2*B155' OutFile = OutPath + 'img_out.bsq' envi_doit, 'math_doit', fid=IMG_FIDs, pos=IMG_POS, $ dims=IMGDims, exp=IMG_EXP, out_name=OutFile, $ r_fid=OutFile_FID ; Close ENVI e.Close Thanks again for your help. Juanjo

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    22 Jun 2015 01:39 PM
    Hi Juan, Thanks for including your code. It looks like your expression is reaching the character limit because every spot where you have B1, B2 etc gets replaced with envi_tile_fdata(tile_id[1],i) , envi_tile_fdata(tile_id[2],i) etc. This pushes the string length above the limit, which is about 5600 characters. This is not the behavior in later versions of ENVI and your program works with ENVI 5.2, so I would recommend upgrading if you can. If you upgrade, then you will also have the use of the new ENVI API which has really been coming together over the past few years.

    Deleted User



    New Member


    Posts:
    New Member


    --
    23 Jun 2015 02:10 AM
    Hi Zach, Thanks a lot for your explanation and suggestions. It all makes sense now. Best, Juanjo
    You are not authorized to post a reply.