Re: IDL & ENVI error: WIDGET_CONTROL: Invalid widget identifier: 17 [message #65875] |
Sat, 28 March 2009 07:08  |
devin.white
Messages: 50 Registered: March 2007
|
Member |
|
|
Off the top of my head, you have two options for avoiding this issue:
1) Only run your program from within an active ENVI+IDL session (don't
call ENVI inside of your program)
2) Start up and shut down ENVI *in batch mode* from within your
program
The modified version of your program (below) does #2. BE SURE THAT
YOU CHANGE YOUR ENVI PREFERENCES SO THAT IDL DOES NOT SHUT DOWN WHEN
YOU EXIT ENVI. The envi_batch_exit routine shuts down ENVI and will
shut down IDL as well unless you specifically change your preferences.
PRO GetImage
;envi
; Use the ENVI dialog box to select a file
;ENVI_SELECT, fid=file,dims=dims,pos=pos
in_file = dialog_pickfile(title='Select File')
if in_file eq '' then return
envi, /restore_base_save_files
envi_batch_init, /no_status_window
envi_open_file, in_file, r_fid=file
envi_file_query, file, dims=dims, nb=nb
pos = lindgen(nb)
; TODO: Get this to loop through bands
; Get the data for the first band of the file (ignores pos from
earlier)
WholeBand = ENVI_GET_DATA(fid=file, dims=dims, pos=0)
;Set Distance to be considered
Distance = 3
; Therefore the area to go each side is (d-1)/2
DistanceEachSide = (Distance - 1)/2
; Calculate the dimensions of WholeBand
SizeInfo = SIZE(WholeBand, /DIMENSIONS)
NumRows = SizeInfo[0]
NumCols = SizeInfo[1]
FOR Rows = 3, NumRows DO BEGIN
FOR Cols = 3, NumCols DO BEGIN
; Make sure RowBottom doesn't go below 0
RowBottom = Rows - DistanceEachSide
IF RowBottom LT 0 THEN RowBottom = 0
; Make sure RowTop doesn't go above NumRows
RowTop = Rows + DistanceEachSide
IF RowTop GE NumRows THEN RowTop = NumRows - 1
ColBottom = Cols - DistanceEachSide
IF ColBottom LT 0 THEN ColBottom = 0
ColTop = Cols + DistanceEachSide
IF ColTop GE NumCols THEN ColTop = (NumCols - 1)
print, RowTop
print, ColTop
AOI = WholeBand[RowBottom:RowTop, ColBottom:ColTop]
;print, AOI
;print, "---"
ENDFOR
ENDFOR
; --- Calculate variable values for the WholeBand
; Get the global mean
GlobMean = MEAN(WholeBand)
; Get the global variance
GlobVariance = VARIANCE(WholeBand)
; Get the number of values in the whole image
SizeInfo = SIZE(WholeBand, /DIMENSIONS)
GlobNumber = SizeInfo[0] * SizeInfo[1]
; --- Calculate variable values for the AOI
; Get the Sum of the values in the AOI
AOISum = TOTAL(aoi)
; Get number of values in AOI
SizeInfo = SIZE(aoi, /DIMENSIONS)
AOINumber = SizeInfo[0] * SizeInfo[1]
; --- Start Calculating Getis Statistic
; Calculate the top of the fraction
TopFraction = AOISum - (AOINumber * GlobMean)
; Calculate the square root
SquareRootAnswer = (AOINumber * (GlobNumber - AOINumber))/(GlobNumber
- 1)
; Calculate bottom of fraction
BottomFraction = GlobVariance * SquareRootAnswer
; Calculate Getis Statistic
Getis = TopFraction / BottomFraction
print, Getis
envi_batch_exit, /no_confirm
END
On Mar 27, 12:10 pm, robintw <r.t.wil...@rmplc.co.uk> wrote:
> Hi,
>
> I'm very much an IDL newbie, but I have experience in other
> programming languages. I'm trying to use IDL with ENVI to do some
> image processing.
>
> My code is below, and is relatively simple - just calculating some
> statistics for the image. However, every so often when I run it I get
> the error "WIDGET_CONTROL: Invalid widget identifier: 17.". If I close
> the IDL/ENVI Workbench and reload it then the error goes away and I
> can run it fine again a few times, until the error starts coming up
> again.
>
> I'm not doing anything with widgets explicitly (although I think the
> ENVI_SELECT_FILE function uses widgets) so I can't think what I'm
> doing. I use the "envi" command at the beginning to load the envi
> environment, is there a command I need to run at the end to close the
> envi environment and release all the files and widgets etc. If so,
> what is this command - I can't seem to find it anywhere!
>
> My code is below:
>
> PRO GetImage
> envi
> ; Use the ENVI dialog box to select a file
> ENVI_SELECT, fid=file,dims=dims,pos=pos
>
> ; TODO: Get this to loop through bands
> ; Get the data for the first band of the file (ignores pos from
> earlier)
> WholeBand = ENVI_GET_DATA(fid=file, dims=dims, pos=0)
>
> ;Set Distance to be considered
> Distance = 3
>
> ; Therefore the area to go each side is (d-1)/2
> DistanceEachSide = (Distance - 1)/2
>
> ; Calculate the dimensions of WholeBand
> SizeInfo = SIZE(WholeBand, /DIMENSIONS)
> NumRows = SizeInfo[0]
> NumCols = SizeInfo[1]
>
> FOR Rows = 3, NumRows DO BEGIN
> FOR Cols = 3, NumCols DO BEGIN
> ; Make sure RowBottom doesn't go below 0
> RowBottom = Rows - DistanceEachSide
> IF RowBottom LT 0 THEN RowBottom = 0
>
> ; Make sure RowTop doesn't go above NumRows
> RowTop = Rows + DistanceEachSide
> IF RowTop GE NumRows THEN RowTop = NumRows - 1
>
> ColBottom = Cols - DistanceEachSide
> IF ColBottom LT 0 THEN ColBottom = 0
>
> ColTop = Cols + DistanceEachSide
> IF ColTop GE NumCols THEN ColTop = (NumCols - 1)
>
> print, RowTop
> print, ColTop
>
> AOI = WholeBand[RowBottom:RowTop, ColBottom:ColTop]
> ;print, AOI
> ;print, "---"
> ENDFOR
> ENDFOR
>
> ; --- Calculate variable values for the WholeBand
>
> ; Get the global mean
> GlobMean = MEAN(WholeBand)
>
> ; Get the global variance
> GlobVariance = VARIANCE(WholeBand)
>
> ; Get the number of values in the whole image
> SizeInfo = SIZE(WholeBand, /DIMENSIONS)
> GlobNumber = SizeInfo[0] * SizeInfo[1]
>
> ; --- Calculate variable values for the AOI
>
> ; Get the Sum of the values in the AOI
> AOISum = TOTAL(aoi)
>
> ; Get number of values in AOI
> SizeInfo = SIZE(aoi, /DIMENSIONS)
> AOINumber = SizeInfo[0] * SizeInfo[1]
>
> ; --- Start Calculating Getis Statistic
>
> ; Calculate the top of the fraction
> TopFraction = AOISum - (AOINumber * GlobMean)
>
> ; Calculate the square root
> SquareRootAnswer = (AOINumber * (GlobNumber - AOINumber))/(GlobNumber
> - 1)
>
> ; Calculate bottom of fraction
> BottomFraction = GlobVariance * SquareRootAnswer
>
> ; Calculate Getis Statistic
> Getis = TopFraction / BottomFraction
>
> print, Getis
>
> END
>
> Thanks,
>
> Robin
|
|
|