R. W. O'CONNELL
November 2003


IDL EXERCISES II:
ARRAYS AND IMAGE DISPLAYS




Before starting these exercises, you should copy to your local
directory all the test data files (*.FITS) from the 
IDL exercises data directory.  



0)  Start IDL.  

    [On most UNIX systems, just type "idl".

       This will start IDL running in the command-line 
       mode using the window from which you called it.  IDL V.5
       also offers a widgit-based interface, the IDL Development
       Environment, which is invoked by the command "idlde".
       This offers convenience features to the experienced user,
       but it is correspondingly more complicated and not
       recommended for learning the basics.] 


    Before starting the exercises, give the IDL command:

                 ON_ERROR,1

       This will return control to the main program level if
       an error occurs in a called routine.
				    

1)  SIMPLE ARRAY FUNCTIONS

    Create a 2-D array, A, with 5 columns and 3 rows using the INDGEN
       function

        Print the array to the screen and verify its structure and
           contents

        Print TRANSPOSE(A).  What are its characteristics?

        Print REVERSE(A).  What are its characteristics?

     Now let B=[0,1,2]

         Predict, then verify, the outcome of the following operations:

              C = A+1

              C = A*0

              C = A^2

              C = A*(A+3)

              C = A/A

              C = EXP(A)

              C = A+B

              C = A*B

              C = A(*,2)*B

              C = A(4,2)*B

              C = A#B

              C = B#A

              C = B##A

    Now replace the element in A(3,1) with the value 100

        Verify the result by printing

        Type the following command and interpret the result:

              PRINT, WHERE(A EQ 100)


2) SIMPLE ARRAY CREATION 

    Create Z, a 301x301 array, using the FINDGEN function.

       What are the maximum and minimum values of Z?

       Using internal subscript notation, print to the terminal:  

           The first 50 elements of the first row of Z

           The first 50 elements of the 99th column of Z

           The last 10 elements of the 100th row of Z

    Use the AstUseLib routine IMLIST to double-check the results of
       the preceding exercise for the last 10 elements of the 100th
       row of Z.  To get information on the IMLIST routine, type
       MAN,'IMLIST.  [Note: you will have to use the optional WIDTH
       keyword to increase the size of the printed display in order to
       read all digits in the Z entries.]

    Write an IDL expression which yields the contents of Z(I,J) as a
       function of I and J. [NOTE: remember the IDL subscripting
       convention for arrays is reversed from FORTRAN's:  in
       IDL A(I,J) yields the value of the I-th column and J-th row.]

       Verify the expression against the actual contents 
       of Z for selected locations.

    Now define B = FLTARR(101,101)+20000.

        What are the maximum and minimum values of B?

        Using internal subscript notation, set the 51st column of B equal
           to 100000.

        Then set the 51st row of B equal to 100000.

    Now insert the array B into the original array Z, with the lower
	left-hand corner of the insert beginning at Z(100,100).

        Confirm the placement of the insert using IMLIST 


3)  GREYSCALE IMAGE DISPLAYS

    Now open a graphics display window:  type "WINDOW,0" or
      "CHAN,0". 

      [NOTE: To open a new window, use WINDOW,N.  To expose or hide
	an existing window, use WSHOW,N.  To make a given window
        "active"--- i.e. ready for I/O---use WSET,N.  

       The MOUSSE routine CHAN,N combines these three functions and is
         preferred.]

         Troubleshooting:  Move the cursor into the window.  If the
	 other parts of your terminal screen blink out or change
	 color, then your X-windows system is not properly
	 configured.  To ameliorate the problem, try this:

               Exit IDL
               Restart IDL
               As the very first two commands, type:

                    DEVICE,PSEUDO_COLOR=8 
                    WINDOW,0,COL=200

         If this does not remedy the blinking, then other X-windows
	 applications have "reserved" too many display colors.  You may
	 be able to reduce the color hogging using various "Preference"
	 or other settings on your applications (e.g. the Common
	 Desktop Environment).  Try exiting other applications (e.g.
	 Netscape) before starting IDL.  If this doesn't work, you can
	 try reducing the number of IDL color levels requested in the
	 command above.  For further information on color levels in
	 IDL, see the IDL Guide..

         Whether or not color blinking is a problem, verify that your
         terminal is in pseudo-color mode by typing HELP,/DEV

            The response should include the following lines:

                     "Display Depth, Size: 8 bits"
                     "Visual Class: PseudoColor"
                     "Colormap: Shared, N colors", where N 
                         is 256 or smaller.

            If this is not the case, follow the instructions above
            to re-configure your color tables.  

    Load the default color table with the command LOADCT,0

    The system variable !D.N_COLORS contains the maximum number of discrete
        color levels you can display on your screen.  How many are there?

    Now use the MOUSSE routine CTVSCL to display Z in window 0 using
        the following command: 

                  CTVSCL,Z,MIN=0,MAX=100000.  

	Inspect the display.  What values are displayed as full black?
        What as full white?  Is the rest of the display what you expected?

        Try loading Z into the display using several other values of
	MAX.  Does it respond as expected?

    Reload Z with the full [0,100000] range.  Use the AstUseLib routine
        CURVAL,Z to check the values of Z at various locations of interest
        using the cursor on the display window.  (Click the right hand mouse
        button while on the window to exit.)

        Try the AstUseLib routine TVLIST (an interactive version of
	IMLIST) to print out selected areas of the image.  Do the
        "crosshairs" intersect at the image center?
        
    With Z still displayed in window 0, open window 9 to make plots.  
        
        Plot extractions of Z along columns and rows and check that
        they are what you expect from the displayed version.

                   E.g.  PLOT,Z(200,*)  

    Open window 1.  Load TRANSPOSE(Z) with the same scaling as for Z.
        Is it what you expect?

    Now define DIFF = Z - TRANSPOSE(Z).  Load DIFF into window 2,
	scaling from a MIN of -50000. to a MAX of +50000.  

        Examine the result visually, comparing with the other two
	display windows, and with CURVAL or TVLIST.  Be sure you
	understand the result.


4)  IMAGE HARDCOPIES

    The quickest way to generate a hardcopy of an image display 
        on your screen is the use the AstUseLib utility TVLASER.
    
    TVLASER will dump a bitmap copy of any window to a PostScript file
	and print it out.  It makes use of the intrinsic IDL routine
	TVRD to copy a window buffer to an IDL variable.  The basic
	steps in TVLASER are described in the
        IDL Guide Graphics Hardcopies section.  
        
        Make a hardcopy of any of the displays you have made so far
        using TVLASER.

    NOTE: TVLASER can be used to make quick hardcopies of windows
        containing line drawings produced by the PLOT commands.  However, 
        these will NOT have the good resolution typical of the
        SET_PLOT,'PS  process described in Exercises I.  Try comparing
        the results of the two methods.  


5)  FILE INPUT, GREYSCALE IMAGE DISPLAY ADJUSTMENT

    Use the AstUseLib routine FITSDIR to obtain a quick listing of the
       properties of FITS files you copied to your local directory.
       Use FITS_INFO to obtain additional information on the
       file "testpattern.fits".

       [NOTE: your UNIX interface IS CASE SENSITIVE, even though IDL is
       not.  Therefore, you must give file names exactly as they
       appear in your directory.]

    Now use the AstUseLib FITS_READ procedure to read the image file
       "testpattern.fits" into RAM.  Give it the name PATT.

       Use HPRINT to print the image header to your screen.
         Verify that the file contained a 2-D image.  What
         are its dimensions?

    Open Window 0; load color table 0. 

    Now display the image with CTVSCL and MIN,MAX set to [0,240].

    There are N different image values in PATT.  What is N?
       Make a list of the values.  [Hint: use PLOTHIST and WHERE.]

    Can your eye detect N distinct values on the screen?  If not, how
       many?  Try different MIN,MAX pairs to adjust the display.

    Optional: explore the use of the MOUSSE routine CTV.  
       How do CTV and CTVSCL differ?  Try the following exercise:

                 FOR I = 1,20 DO CTV,I*PATT

    Load the image with the original [0,240] scaling.  Now use the
       MOUSSE routine CONTRAST to adjust its appearance.  CONTRAST will
       place the cursor at the center of the image.  By moving the
       cursor up, you increase the contrast (slope) of the color
       tables; by moving the cursor right, you increase the
       Y-intercept of the color tables.  Exit by clicking the righthand
       mouse button.  You can check the effect on the color tables by
       reading them with TVLCT,RR,GG,BB,/GET and then plotting.

    Reload color table 0.  

    Nonlinear transformations of images allow expansion/compression of
       the dynamic range of displays:

       A fractional power law is a quick way to improve discrimination
       for fainter values in an image while holding the brighter
       values.  Define NEW1=PATT^0.3.  Open a new window and
       use CTVSCL to display NEW1 between its minimum and maximum
       values.  Compare it to the linear display.  How does the
       power-law display differ?

       Logarithmic displays have a similar effect.  Try displaying
       NEW2=ALOG10(PATT > 1) between its minimum and maximum
       values.


6)  IMAGE STRUCTURE, ZOOMS, HISTOGRAMS, COLOR DISPLAYS

    Now read in the file "noisytestpattern.fits".  This is the same
       test array as before except that it has had Poisson (photon)
       noise added corresponding to the mean photon count values at
       each of the N levels.  [Where the photon count was zero, we
       have substituted the noise for a count of 1.]
    
    Display this image in window 1 with the same [0,240] scaling.
       How obvious is the photon noise in the display?

       Try plotting (in a third window) cuts across the two images:
          e.g.:  PLOT,PATT(*,150) & OPLOT,NOISY(*,150)

       Use the ZOOM routine to enlarge the display of the noisy image.
	  The default zoom factor is 4.  Change to a factor of 10 for
	  a better look at pixel structure.  Try using the CONTINUOUS
	  keyword.

       Optional:  As an alternative to ZOOM, you could REBIN the image
	  (or parts of it) to larger values and redisplay.  Use the
	  keyword /SAMPLE to preserve the pixel structure. 

    Extract a 60x60 subarray from the part of NOISY which has a mean
       value of 112 (refer to the original PATT).  Histogram the pixel
       values.  Measure (by eye) the FWHM of the histogram.  Is it
       consistent with Poisson noise?  

    Arrange your display so you can see both windows 0 and 1.
       Make window 0 active and call the MOUSSE routine
       REFSCL,/OVER.  This will place a small visual display of
       your color table at the bottom of window 0.

    Now experiment with loading any or all of the 40 built-in IDL color
       tables using the LOADCT,N routine.  Explore how the different
       tables emphasize different brightness levels in the images and
       affect the contrast of the noise fluctuations.
    

7)  CONTOUR PLOTS

    Read in the file "gaussimage.fits".  This contains the image of
      a 2-D circular Gaussian.

    Using any of the tools you have tried so far:

       Find the [X,Y] location of the maximum of the image and
         its value.

       Determine the full-width-half-maximum of the image (accuracy
         of a few pixels OK).

    Open a plotting window.  Use the SQUARE routine (from MOUSSE) to make
       the axes of the next plot equal.

    Now make a contour plot of the image using the CONTOUR built-in routine.
       Select about 10 levels spanning the range of image values for the
       contours.  Make a hardcopy (note: you will need to use the SQUARE
       routine again after you give the SET_PLOT,'PS command). 

    Display the image, perhaps with power-law scaling, so that you
       preserve most of its dynamic range.  Load IDL color table 31.
       This will yield a contoured image by virtue of the color table
       entries.  

       Use the MOUSSE routine CROLL to "roll" the table for a nice
       "Hashbury 1969" effect.  




END OF IDL EXERCISES PART II Part III continues analysis of 2-D arrays. IDL Tutorial Home Page

Copyright © 2000-2003 Robert W. O'Connell. All rights reserved.
Last modified by RWO, 11/02/03