SAY " "
SAY "Demonstration of IMAGER: Single Channel case"
SAY " "
@ gag_demo:demo-setup
say " "
SAY "-----------------------------------------------------------"
SAY " The first step: Reading UV data, UV_MAP and CLEAN"
SAY " "
DO "read uv gag_demo:demo-single-imager.uvt"  "Read the UV data"
!
! Pipeline imaging.
!
DO "uv_map"   "Compute DIRTY image and BEAM"
DO "clean"    "Compute CLEAN image"
DO "show clean"  "Show the CLEAN image"
!
DO "Set Angle sec"      " Commute SHOW into relative offset labeling mode"
DO "let do_nice = yes"  " nice SHOW: add the Clean beam"
DO "let size = 20"      " Size in arcsec of the field displayed in SHOW"
DO "show clean"         " CLEAN image display"
!
! Show parameters used: 1) for mapping, 2) for cleaning, 3) plotting. 
! Everything is at default values (lot's of 0).
!
DO "uv_map ?"    "Check UV_MAP input parameters"
DO "clean ?"     "Check CLEAN input parameters"
DO "show ?"      "Check SHOW input parameters"
!
! Let's do imaging step by step.
SAY "-----------------------------------------------------------"
SAY " "
SAY "Now, we will explore various aspects of the UV data"
SAY 
!
! UV table inspection
!
DO "uv_stat header" "List the UV buffer header"
DO "show coverage"  "Show the UV coverage"
DO "show uv"        "Show the UV data"
DO "let xtype weight"  "Change the type of data to be displayed"
DO "show uv ?"      "List the input parameters of SHOW UV"
DO "show uv "       "xtype "'xtype'" vs ytype "'ytype'
DO "uv_stat weight"  "List the impact of the MAP_ROBUST parameter on beam size" 
!
! Imaging
SAY "-----------------------------------------------------------"
SAY " "
SAY "Now evaluating the impact of UV_MAP parameters"
say " "
!
DO "uv_map ?" "Check the UV_MAP input parameters"
DO "uv_map"   "Compute Dirty and Beam images"  
DO "show beam"  "Show dirty beam"
DO "set angle_unit absolute"  "Back to Absolute labeling"
DO "show dirty" "Show dirty image"
!
! Simple clean deconvolution
SAY "-----------------------------------------------------------"
SAY " "
SAY "Now evaluating the impact CLEAN parameters"
SAY " "
!
DO "clean ?" "CLEAN input parameters"
DO "clean"   "Compute the CLEAN image from DIRTY and BEAM"
DO "show residual" "Look at the RESIDUAL image"
DO "show clean"    "Look at the CLEAN image" 
DO "view cct"      "Show the flux convergence"
!
! Computes difference between final image and residuals to see the clean 
! components alone.
SAY "-----------------------------------------------------------"
say " "
SAY "Now, we shall look at the difference between the Clean image and "
say "  the Residual image to see the Clean components convolved with "
say "  the Clean beam."
SAY " "
!
DO "defin image diff * real /like clean /global" "Define a temporay image"
DO "let diff% clean%" "Initialize its header from the CLEAN image"
DO "let diff clean-residual"  "Get the pure CLEAN components..."
DO "show diff" "Look at this difference..."
delet /var diff
!
SAY "-----------------------------------------------------------"
say " "
SAY "Now, we shall look at the noise and significance of the image."
SAY " "
!
! Empirical noise definition
DO "view noise" "Look at the Noise of the CLEAN (last shown) image"
!
! Use noise information for contour plotting
DO "let spacing 2.5 sigma" "2.5 sigma level spacing"      
DO "let do_bit no" "No bitmap display"
DO "show clean"  "The contour map with this spacing"
!
! Let's see tapering effect: smoothing => decrease resolution and 
! increase of brightness sentivity (but decrease of point source sensitivity).
!
SAY "-----------------------------------------------------------"
SAY " "
SAY "Now we shall see the effect of tapering."
SAY " Tapering is smoothing: it decreases resolution, but improves the"
SAY  " brightness sensitivity (but degrades the point source sensitivity)"
SAY " "
DO "uv_stat taper" "Explore the impact of Tapers"
DO "let map_uvtaper 170 170 0" "Select the most appropriate one"
DO "uv_map ?" "Check UV_MAP input parameters"
DO "uv_map"   "Now compute the Dirty and Beam images"
DO "let do_bit yes"    "Back to bitmap display"
DO "show beam"         "Look at the dirty beam"
DO "let spacing 0"     "Back to automatic contour levels"
DO "show dirty"        "Look at Dirty image"        
DO "clean"             " Clean it"
DO "show clean"        " and look at the Clean image"
!
SAY "-----------------------------------------------------------"
SAY " "
SAY "Let us see weighting effect: increase of resolution and noise."
SAY " "
DO "let map_uvtaper 0 0 0" "Reset the Taper, otherwise it is also used"
DO "uv_stat weight"  "See how the beam size and noise changes"
DO "let map_uvcell 7.5"   " Select a UV cellsize - Default is half-dish" 
DO "let map_robust .5"    " Select the robustness value"
DO "uv_map ?"
DO "uv_map" "Compute Dirty and Beam images"
DO "show beam"  "As of now, you know what it means..."
DO "show dirty"
DO "clean"
DO "show clean"
!
! Use of a support
!
SAY "-----------------------------------------------------------"
SAY " Using MASK "
SAY " "
@ tutorial-pause
DO "MASK INIT" "Initialize a Mask"
for i 1 to 2
  SAY " "
  SAY "Now we are going to define a mask interactively "
  say "     - That should be intuitive (type H if not...)"
  SAY " "
  DO "MASK" "Define the Mask"
  if i.eq.1 then
    SAY " "
    SAY "     --- So far, the Mask is defined, but not yet used ---"
    SAY " "
    DO "MASK USE" "Tell Clean to use this Mask"
  endif
  DO "clean"
  DO "show residual"
  DO "show clean" 
  if i.eq.1 then
    SAY "We try again with a different Mask, to see the effects"
    SAY "Just remove the previous one before, for example"
  endif
next
!
SAY "Done --- Exiting "
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
