f



IDL & ENVI error: WIDGET_CONTROL: Invalid widget identifier: 17

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
0
r.t.wilson (23)
3/27/2009 4:10:33 PM
comp.lang.idl-pvwave 12260 articles. 2 followers. Post Follow

6 Replies
3416 Views

Similar Articles

[PageSpeed] 19

robintw writes:

> 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!

I think the problem you are having is that you are not
invoking ENVI in such a way as to get everything initiated
properly. I would change your "envi" command to this:

   envi, /restore_base_save_files

Let us know if that works.

Cheers,

David
-- 
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
0
news2122 (4023)
3/27/2009 4:32:51 PM
On Mar 27, 4:32=A0pm, David Fanning <n...@dfanning.com> wrote:
>
> I think the problem you are having is that you are not
> invoking ENVI in such a way as to get everything initiated
> properly. I would change your "envi" command to this:
>
> =A0 =A0envi, /restore_base_save_files
>
> Let us know if that works.
>
> Cheers,
>
> David

Thanks for your response David.

I've tried changing the envi command to that, and it still doesn't
seeem to work. I've altered parts of the program now in a way which
means it takes quite a while to run. Therefore, I frequently have to
exit it using the Terminate command within the IDL Workbench. After
I've used that command it always gives the error I mentioned in the
previous post. Presumably this isn't expected behaviour when using the
Terminate command? Any other ideas?

Cheers,

Robin
0
r.t.wilson (23)
3/27/2009 5:19:49 PM
robintw writes:

> I've tried changing the envi command to that, and it still doesn't
> seeem to work. I've altered parts of the program now in a way which
> means it takes quite a while to run. Therefore, I frequently have to
> exit it using the Terminate command within the IDL Workbench. After
> I've used that command it always gives the error I mentioned in the
> previous post. Presumably this isn't expected behaviour when using the
> Terminate command? Any other ideas?

OK, then I think the problem is the Terminate command (which
I didn't even know existed!). I think what happens is that
things immediately get "terminated" in a way that is not
foreseen by the software. So when the software goes to
do something as innocuous as destroy its own top-level
base, for example, with a command like this:

   Widget_Control, state.tlb, /Destroy

That widget is already destroyed, so it throws the
"invalid widget identifier" error you are experiencing.
I think you can probably expect this if you "terminate"
a program in an unexpected way, since programming for
the possibility of this kind of error is really WAY
out of the question. :-)

I think I might try a Cntl-C and see if you can stop
the program that way, followed by a .Reset maybe. I
can't even imagine all the havoc that could ensue with
a "Terminate" command. How come this button doesn't have
a mushroom cloud icon on it?

Cheers,

David
-- 
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
0
news2122 (4023)
3/27/2009 5:30:19 PM
Ahhh! I never knew that I could stop the program running using Ctrl-C
- I knew that was used in other circumstances but I just never thought
to try it in IDL.

That seems to have stopped the problem re-occuring at the moment -
I'll get back to you if I have any more problems.

Thanks a lot for your help (and your book is great too!)

Robin

On Mar 27, 5:30=A0pm, David Fanning <n...@dfanning.com> wrote:
> OK, then I think the problem is the Terminate command (which
> I didn't even know existed!). I think what happens is that
> things immediately get "terminated" in a way that is not
> foreseen by the software. So when the software goes to
> do something as innocuous as destroy its own top-level
> base, for example, with a command like this:
>
> =A0 =A0Widget_Control, state.tlb, /Destroy
>
> That widget is already destroyed, so it throws the
> "invalid widget identifier" error you are experiencing.
> I think you can probably expect this if you "terminate"
> a program in an unexpected way, since programming for
> the possibility of this kind of error is really WAY
> out of the question. :-)
>
> I think I might try a Cntl-C and see if you can stop
> the program that way, followed by a .Reset maybe. I
> can't even imagine all the havoc that could ensue with
> a "Terminate" command. How come this button doesn't have
> a mushroom cloud icon on it?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

0
r.t.wilson (23)
3/27/2009 5:34:33 PM
robintw 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!
> 
> Thanks,
> 
> Robin

Do you use control+F2 at some time before you get the error? I can 
reproduce this problem only by terminating the code....  Envi disapear. 
Next calls to "envi" produce this error. Doing .reset is enough to bring 
back envi and to remove the problem... maybe there is something to 
investigate there... (windows, envi 4.6)

Jean
0
jghasban (475)
3/27/2009 5:51:28 PM
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=3Dfile,dims=3Ddims,pos=3Dpos

in_file =3D dialog_pickfile(title=3D'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=3Dfile
envi_file_query, file, dims=3Ddims, nb=3Dnb
pos =3D lindgen(nb)

; TODO: Get this to loop through bands
; Get the data for the first band of the file (ignores pos from
earlier)
WholeBand =3D ENVI_GET_DATA(fid=3Dfile, dims=3Ddims, pos=3D0)


;Set Distance to be considered
Distance =3D 3


; Therefore the area to go each side is (d-1)/2
DistanceEachSide =3D (Distance - 1)/2


; Calculate the dimensions of WholeBand
SizeInfo =3D SIZE(WholeBand, /DIMENSIONS)
NumRows =3D SizeInfo[0]
NumCols =3D SizeInfo[1]


FOR Rows =3D 3, NumRows DO BEGIN
  FOR Cols =3D 3, NumCols DO BEGIN
    ; Make sure RowBottom doesn't go below 0
    RowBottom =3D Rows - DistanceEachSide
    IF RowBottom LT 0 THEN RowBottom =3D 0


    ; Make sure RowTop doesn't go above NumRows
    RowTop =3D Rows + DistanceEachSide
    IF RowTop GE NumRows THEN RowTop =3D NumRows - 1


    ColBottom =3D Cols - DistanceEachSide
    IF ColBottom LT 0 THEN ColBottom =3D 0


    ColTop =3D Cols + DistanceEachSide
    IF ColTop GE NumCols THEN ColTop =3D (NumCols - 1)


    print, RowTop
    print, ColTop


    AOI =3D WholeBand[RowBottom:RowTop, ColBottom:ColTop]
    ;print, AOI
    ;print, "---"
  ENDFOR
ENDFOR


; --- Calculate variable values for the WholeBand


; Get the global mean
GlobMean =3D MEAN(WholeBand)


; Get the global variance
GlobVariance =3D VARIANCE(WholeBand)


; Get the number of values in the whole image
SizeInfo =3D SIZE(WholeBand, /DIMENSIONS)
GlobNumber =3D SizeInfo[0] * SizeInfo[1]


; --- Calculate variable values for the AOI


; Get the Sum of the values in the AOI
AOISum =3D TOTAL(aoi)


; Get number of values in AOI
SizeInfo =3D SIZE(aoi, /DIMENSIONS)
AOINumber =3D SizeInfo[0] * SizeInfo[1]


; --- Start Calculating Getis Statistic


; Calculate the top of the fraction
TopFraction =3D AOISum - (AOINumber * GlobMean)


; Calculate the square root
SquareRootAnswer =3D (AOINumber * (GlobNumber - AOINumber))/(GlobNumber
- 1)


; Calculate bottom of fraction
BottomFraction =3D GlobVariance * SquareRootAnswer


; Calculate Getis Statistic
Getis =3D TopFraction / BottomFraction


print, Getis


envi_batch_exit, /no_confirm


END



On Mar 27, 12:10=A0pm, 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=3Dfile,dims=3Ddims,pos=3Dpos
>
> ; TODO: Get this to loop through bands
> ; Get the data for the first band of the file (ignores pos from
> earlier)
> WholeBand =3D ENVI_GET_DATA(fid=3Dfile, dims=3Ddims, pos=3D0)
>
> ;Set Distance to be considered
> Distance =3D 3
>
> ; Therefore the area to go each side is (d-1)/2
> DistanceEachSide =3D (Distance - 1)/2
>
> ; Calculate the dimensions of WholeBand
> SizeInfo =3D SIZE(WholeBand, /DIMENSIONS)
> NumRows =3D SizeInfo[0]
> NumCols =3D SizeInfo[1]
>
> FOR Rows =3D 3, NumRows DO BEGIN
> =A0 FOR Cols =3D 3, NumCols DO BEGIN
> =A0 =A0 ; Make sure RowBottom doesn't go below 0
> =A0 =A0 RowBottom =3D Rows - DistanceEachSide
> =A0 =A0 IF RowBottom LT 0 THEN RowBottom =3D 0
>
> =A0 =A0 ; Make sure RowTop doesn't go above NumRows
> =A0 =A0 RowTop =3D Rows + DistanceEachSide
> =A0 =A0 IF RowTop GE NumRows THEN RowTop =3D NumRows - 1
>
> =A0 =A0 ColBottom =3D Cols - DistanceEachSide
> =A0 =A0 IF ColBottom LT 0 THEN ColBottom =3D 0
>
> =A0 =A0 ColTop =3D Cols + DistanceEachSide
> =A0 =A0 IF ColTop GE NumCols THEN ColTop =3D (NumCols - 1)
>
> =A0 =A0 print, RowTop
> =A0 =A0 print, ColTop
>
> =A0 =A0 AOI =3D WholeBand[RowBottom:RowTop, ColBottom:ColTop]
> =A0 =A0 ;print, AOI
> =A0 =A0 ;print, "---"
> =A0 ENDFOR
> ENDFOR
>
> ; --- Calculate variable values for the WholeBand
>
> ; Get the global mean
> GlobMean =3D MEAN(WholeBand)
>
> ; Get the global variance
> GlobVariance =3D VARIANCE(WholeBand)
>
> ; Get the number of values in the whole image
> SizeInfo =3D SIZE(WholeBand, /DIMENSIONS)
> GlobNumber =3D SizeInfo[0] * SizeInfo[1]
>
> ; --- Calculate variable values for the AOI
>
> ; Get the Sum of the values in the AOI
> AOISum =3D TOTAL(aoi)
>
> ; Get number of values in AOI
> SizeInfo =3D SIZE(aoi, /DIMENSIONS)
> AOINumber =3D SizeInfo[0] * SizeInfo[1]
>
> ; --- Start Calculating Getis Statistic
>
> ; Calculate the top of the fraction
> TopFraction =3D AOISum - (AOINumber * GlobMean)
>
> ; Calculate the square root
> SquareRootAnswer =3D (AOINumber * (GlobNumber - AOINumber))/(GlobNumber
> - 1)
>
> ; Calculate bottom of fraction
> BottomFraction =3D GlobVariance * SquareRootAnswer
>
> ; Calculate Getis Statistic
> Getis =3D TopFraction / BottomFraction
>
> print, Getis
>
> END
>
> Thanks,
>
> Robin

0
3/28/2009 2:08:08 PM
Reply:

Web resources about - IDL & ENVI error: WIDGET_CONTROL: Invalid widget identifier: 17 - comp.lang.idl-pvwave

Resources last updated: 2/21/2016 11:42:07 PM