A Preliminary Guide to ISAP Programming

postscript version

1. Introduction

1.1. What ISAP is :

ISAP is the  ISO Spectral Analysis Package for the reduction and scientific analysis of ISO Spectrometer  Pipeline data, and may also be used  for the reduction of generic spectral line data.

1.2 . Purpose of This Manual:

 The purpose of this manual  is to introduce a new developer to the design and operation process of  ISAP.  The manual describes briefly the  functionality, environment, input/ouput,  structure of programming module  start-up procedures and documentation.

1.3. What ISAP does:

The  primary function of ISAP is to simplify the process of data handling. This includes visualizing,
shifting, rebinning, masking, combining scans with weighted means or medians, filtering, and smoothing the  data. Additional analysis includes unit conversions, subsetting, line and continuum fitting, flux measurement, synthetic photometry and modeling of zodiacal light.
 

2. ISAP Environment

The  ISAP software is written in pure IDL and is operational on  Unix  and VMS  systems. All the required  tools were designed and developed using over a time period of 5 years starting with IDL version 3.6 and ending with IDL version 5.1.4. The earlier versions  were command line based where the user  was invoking the procedure calls command in IDL window. The later and final version of ISAP is GUI based where ISAP startup fires a window (known as GUI WIDGET) containing buttons for certain operations. These buttons may be stand alone or the parents of  other children widgets.

2.1. ISAP Directory Tree:

  ISAP

3.  ISAP Input /Output

3.1.  ISAP Data Structures:

ISAP reads all input files into a IDL named structure  known as ISAP AAR. This new AAR contains the following tags.             {WAVE, WAVEU, FLUX, STDEV, TINT, DET, ITK, UTK, RPID,
            SPARE, LINE, SDIR, SCNT, STATUS, FLAG}

The FITS primary and secondary headers are written into the header tag of AAR. In addition,
all HISTORY keywords found in FITS headers are saved in history tag.

The translation of input FITS file parameters into ISAP AAR data tags for each instrument is given as follows:
 For a description of SWS AAR files, please see ISO-SWS Instrument & Data Manual.

SWS : Fits Parameters [SWAAWAVE, SWAAFLUX, SWAASTDV, SWAATINT, SWAADETN, SWAAITK, SWAAUTK, SWAARPID,SWAASPAR , SWAALINE , SWAASDIR, SWAASCNT,  SWAASTAT, SWAAFLAG] are translated into AAR data tags [WAVE, FLUX, STDEV, TINT, DET, ITK , UTK , RPID, SPARE, LINE , SDIR, SCNT, STATUS, FLAG].

For a description of LWS AAR files, please see ISOLWS Data Users Manual.

LWS: Fits Parameters [LSANWAV, LSANWAVU, LSANFLX, LSANFLXU, LSANTINT, LSANDET, LSANITK, LSANUTK, LSANRPID,
LSANFILL, LSANLINE, LSANSDIR, LSANSCNT,  LSANSTAT, LSANFLAG] are translated into AAR data tags
[WAVE, WAVEU, FLUX, STDEV, TINT, DET, ITK, UTK, RPID, SPARE, LINE, SDIR, SCNT, STATUS, FLAG]

PHT: All PHT-S Fits files have data records with each record representing a  single raster point. Each data record also have more than 1 type of flux (source, source + background etc.). Individual AARs are created for each type of flux (user chosen) containing the data tags [WAVE, FLUX, STDEV, FLAG] where WAVE is obtained
from keywords LAMBDnnn, nnn=1, 64 and FLUX and STDEV  is the flux values and their uncertainties.

CAM CVF: CAM CVF Fits files have data records with each record representing a single pixel in CAM array. Each data record also have more than 1 type of flux (source, source + background etc.). Individual AARs are created for each type of flux (user chosen) containing the data tags [WAVE, FLUX, STDEV, FLAG] where WAVE is obtained
from keywords LAMBDnnn, nnn=1, 64 and FLUX and STDEV  is the flux values and their uncertainties.
 

YAAAR:

Input to ISAP are the files as described above. However, sometime during processing information is lost on certain data tags. For example when one rebins/merges/averages spectra from individual detectors into one final spectrum, one looses the information on individual detectors. Thus, an ISAP processed AAR , known as YAAAR (Yet Another AAR), can have 4 to 15 data tags. The minimum data tags expected are WAVE, FLUX, STDEV, and FLAG. Also, non-ISO Ascii data are read in as YAAAR.
 

4. ISAP Coding Conventions

 All modules were designed with the following concepts in mind.

4.1. ISAP  Flow:

     All the  top level functions and procedures containing the major functionality  and called by data_handler.pro are identified within parenthesis [] . The lower level routines are identified under 'Dependencies'  in the headers of top level routines.

5. Documentation

         Scripts have been written in Perl (upto version 5.004 )  on Unix system to create automated documentation for ISAP.  They are briefly described as follows.

5.1. Header Extraction:

         The headers of all the routines (* .pro )  in a directory can be extracted using the perl scripts xfile.pl and extract_file.pl  (in ./doc/perl) using the following command.

          setenv PERLLIB  lib
         alias xfile 'perl xfile.pl'
         xfile -v -p  output_directory  input_directory/*.pro
 The output_dirctory will contain the files with .dc1,.dc2 extensions.

5.2 . HTML Conversion:

        Define the environment variable ISAP_DOC pointing to the directory containing header files (*.dc) .
         setenv  ISAP_DOC   output_directory

         Execute Perl script 'make_isap_html_libs' to create html files and index files in the current directory.


AList of Common Routines Written in ISAP:

  ACKNOWLEDGE  - Error handling for GUI mode

  BANDS_TO_DETS - to convert SWS bands to the list of detectors

  CHK_TAG - to check if a given AAR contains a particular tag

   COMBINE  - to combine two AARS data structures

   CUT_AAR  - to obtain  specific data records from an AAR

   CW_DRAW - to create ISAP Plot Windows and their events. This routine defines the actions of mouse buttons which are


    FEEDER - to perform application on unique parts (or whole)  of an AAR

    FIX_SCALAR - to convert a scalar to 1 element array

    GET_HDRKEY - to read a  keyword value in FITS file header

    GET_AOTB_INDEX - to get the AOT number of the instrument  from FITS file header

    GET_UNITS - to obtain wave and flux units from  FITS header

    GUI_FEEDER - to select different parts of an AAR

    GUI_PLOTSTYLE - to set the plot styles (color,symbols etc.) for cw_draw window plots

    IS_STRUCT - to check if input AAR is legal

    KWD_NOTSET - to check the keyword setting  and its legality

    LOCAL_STORE - to store a data set  for later use

    MAKE_PRIME - to make  a data set Prime (current)

    MERGER - to put  masked data back into output AAR (applications driven by FEEDER)

    MERGETWO - to combine two similar data structures,

    PLOT_ALL - for plotting in CW_DRAW windows,

    RESET_DATE - to convert incoming dates in input files to Y2K compliance dates

    SAP_ERROR - Error handling  for command line and GUI modes

    SAP_WFITS - to write an Fits Binary file from an AAR structure

    SET_USERSYM - to set user defined symbols generated with symgen

    SHRINK_ARRAY - to determine the unique values of  a data tag

    SYMGEN - to generate vectors for user defined symbols

    UPDATE_HISTORY - to update the history tag in AAR

    WRITEASC - to write an AAR data  into an Ascii file

    WRITE2HIST - to write a string into 'history'  tag of an AAR

    WRITE_HDRKEY - to write a keyword into "header" tag of an AAR (which is a copy of FITS header)

B. List of Common features Used in ISAP Routines:

1. Error status via  routine argument 'err_stat' which is defined 0 for normal, 1 for error.
2. Messages /Info written in  ISAP message window (at the bottom)  by passing the id of message text widget in  routines argument .
 

C. ISAP  Standard  Header:

;#> Identifier.dcX

; Identifier
; Purpose
; Synopsis
; Arguments            Name                         I/O                       Type                                 Description

                                -----------------------------------------------------
; Returns
; Description
; Comment
 
; Example
; Dependencies    CALLS:

;                                CALLED BY:
; Category
; Filename
; Author
; Version
; History
; Copyright
;#<

D.An ISAP Coding Example:
 Below is given an example to add a new routine to ISAP. The objective is to display a plot of
  wave vs flam (wave*flux) for the prime AAR (data displayed in main ISAP plot window). A new
  button is added to perform this operation. This button can be added at two possible places.

   1. Either in tool kit window  which appears as soon as the data is selected with right mouse button. The routine "make_selection.pro" will be changed for this purpose. The following instruction is added at line # 154.
junk = widget_button(rebbase,value = 'Plot FLAM',uval = {type:'plot_flam'})

This will make a button appear in tool kit window with label "Plot FLAM", and the type of the event is 'plot_flam'. Next, the ISAP event handler will be changed to perform the actual operation. Please note that  the event handler contained in "data_handler8.pro" consists of 2 parts. The first part  consists of the events handling generated  by CW_DRAW select mode (which is the above case). The  following lines are added to this part (at line #1492)

           'plot_flam' : begin
                      handle_value,info.current_data,cdata
                       msg='plot wave vs flam ...'
                       widget_control,info.text_wid,set_value = msg ,/append
                       stat = gui_plot_flam( select_aar, info.pstyle_op1, $        ;selected aar only
                                             title=cdata.name)
                   end
Also note that the function is performed on the selected part of data only.

2. The button can also be placed under "Special Funcs.." which is a menu button on ISAP main Gui.  In this case, the function will be performed on the whole AAR. The following line is added to the data_handler8.pro at line #2852

 plflam   = widget_button(spec_butt,value = 'Plot FLAM',uval = {type:'plot_flam'})

This will make a button  with label 'Plot FLAM'appear under Special Funcs menu. The following lines will be inserted to the second part (line# 1738)  of event handler in data_handler8.pro which handles events depending on the event user value .

       'plot_flam' : begin
                      handle_value,info.current_data,cdata
                       msg='plot wave vs flam ...'
                       widget_control,info.text_wid,set_value = msg ,/append
                       stat = gui_plot_flam( cdata.aar , info.pstyle_op1, $       ;whole aar
                                             title=cdata.name)
                    end

  The functional routine gui_plot_flam.pro used in both above cases by event handler is listed below.

;#> gui_plot_flam.dc2 
;
; Identifier    gui_plot_flam
;
; Purpose       to plot lambda vs flam                       
;
;
; Synopsis      status = gui_plot_flam,aar,     ; the input aar
;                           pstyle,             ; plot styles
;                           title = title,      ; optional title
;                           group = group)      ; group number
;
; Arguments     Name    i/o   type            description
;               ---------------------------------------------------------
;               aar       I    int         aar
;               pstyle    I    int         handle_id to array containing
;                                          plot style info (7 elem array)
;                                          (symbol,color,line specs etc)
;               title     I    string      title of the cw_draw
;               group     I    int         group leader number
;
; Returns       status, 0 for normal, 1 otherwise
; 
; Description
;
; Dependencies  Calls: ACKNOWLEDGE, GET_HDRKEY, KWD_NOTSET, PLOT_ALL,
;                      SAP_ERROR
;               Called By: DATA_HANDLER8
;
; Category      ISAP
;
; Filename      gui_plot_flam.pro
;
; Author        authors's name 
;
; Version       1.0
;
; History
;
;*******************************************************************
;#<

pro gui_plot_flam_event,ev                      ; Event Handler of plot_flam     

widget_control,/hourglass                       ; tell em to wait
widget_control,ev.id, get_uval = uv
type = tag_names(ev,/struct)

if type eq 'CW_DRAW' then return                ;zoom, select, redraw etc

CASE uv.type OF
   'quit'    : widget_control,ev.top,/destroy   ; destroy everything
   else      : print,uv.type
ENDCASE
END

;**************************************************************
FUNCTION gui_plot_flam,aar,pstyle,title = title, $
                   text_wid=text_wid, group=group

IF KWD_NOTSET(title,"title", "str") THEN  $
   title = 'PLOT FLAM'   

IF KWD_NOTSET(text_wid, "text_wid", "int") THEN $
    text_wid = -1           ;do not write info text in isap msg window

;check for flux units in AAR header
;only 'w/cm^2/um' for flux are acceptable
 header = aar.header
 fstat = GET_HDRKEY(header,'TUNIT2',funit, stat=stat)

 IF fstat EQ 1  THEN BEGIN
   SAP_ERROR,'F', $
    'Flux unit definition (TUNIT2) does not exist in AAR header'
   return, 1 

 ENDIF ELSE IF STRPOS(funit, 'w/cm^2/um') LT 0  THEN BEGIN
   funit = STRLOWCASE(funit)
   SAP_ERROR, 'F', $
     "Please change flux units " + funit + " to w/cm^2/um"
   return, 1
 ENDIF

main_base = widget_base(/column)            ;top base for this Gui
cw1 = CW_DRAW(main_base,$                   ;plot window in top base 
                 title = title,$
                 xsize=650,$
                 ysize=400,$
                 max_oplots = 2000,$
                 xmargin = [15,3],$
                 ymargin = [5,2])

junk = widget_button(main_base, $           ;Quit button
        value = 'Quit',uval = {type:'quit'})

;set up the group leader, if desired
;this widget will die when group leader is killed
IF NOT KWD_NOTSET(group, "group","int") THEN BEGIN      ; if group defined,
   IF widget_info(group,/valid_id) eq 1 THEN BEGIN      ; check it & set it up
       widget_control,main_base,group_leader = group
   ENDIF ELSE BEGIN
      ACKNOWLEDGE,text = 'PLOT_FLAM: Invalid Group Leader Id : ' $
                          + strtrim(group)
   ENDELSE
ENDIF

tmp = aar
tmp.data.flux = aar.data.wave*aar.data.flux     ;flam = wave*flux     
ytit = "flam (Watts/cm^2)"                      ;redefine output units

widget_control,main_base,/realize               ; realize it

PLOT_ALL,tmp,$                                  ; plot the converted data
         cw1,$
         pstyle, $
         textwid=text_wid, $
         title = title, $
         ytitle = ytit  

xmanager,'gui_plot_flam',main_base              ; start event handler
                                                ; gui_plot_flam_event
                                                ; the top procedure


RETURN, 0                                       ;normal status
END

E. ISAP Designers and Programmers

ISAP has mainly been developed by members the SWS and LWS Instrument teams and the ISO Data Centers  at the following institutions. A table of developers at each institute also follows.
  • CESR: Centre d'Etude Spatiale des Rayonnements
  • IAS : Institut d'Astrophysique Spatiale, Orsay, France
  • IPAC: Infrared Processing and Analysis Center, Pasadena, CA, USA
  • MPE : Max-Planck-Institut fuer extraterrestrische Physik, Garching, Germany.
  • RAL : Rutherford Appleton Lab,  UK
  • SRON: Space Research Organization Netherlands, Groningen

  •  
     
    ISAPer Institute
    Otto Bauer MPE
    Jim Brauher IPAC
    Mark Buckley RAL
    Andrew Harwood RAL
    Min Hur IPAC
    Iffat Khan IPAC
    Jing Li IPAC
    Steve Lord IPAC
    Dieter Lutz MPE
    Joe Mazzarella IPAC
    Sergio Molinari IPAC
    Pat Morris SRON
    Bob Narron  IPAC
    Karla Seidenschwang MPE
    Sunil Sidher RAL
    Eckhard Sturm MPE
    Bruce Swinyard RAL
    Sarah Unger QMW
    Laurent Verstraete IAS
    Florence Vivares CESR
    Ecki Wieprecht MPE

    Last update:  26-April-2000