You are here: IRS>SmartDoc Web>SmartScripting (08 Sep 2009, VianneyLebouteiller)

SMART Scripting Guide

SMART Scripting - Basic

SMART is designed so that many of its facilities can be used directly without invoking the SMART Project Manager or SMART IDEA Main window.
This is particularly useful for working with large datasets where the same operations must be performed repeatedly for each indivdual observation.

A number of pre-written scripts are provided with SMART. They are described at Provided Scripts?.

To begin scripting type at the system Unix/Linux prompt :

> smart com

This will invoke IDL and SMART without displaying the SMART Project Manager. NOTE : This mode MUST be used for SMART scripts and routines as it sets required environment parameters. It then presents the "IDL>" prompt. Various SMART routines can then be used from the prompt to process data.

For a listing of parameters and keywords used by selected SMART procedures please see Procedure Headers.

If needed the Project Manager can be invoked by typing at the "IDL>" prompt :

To start the IDEA Main Window type at the "IDL>" prompt :

IDL> start_gui

To start the IDEA Main Window with pre-processed data type at the "IDL>" prompt :

IDL> start_gui, aar_in=ptr_aar

where "ptr_aar" is an IDL pointer array of the data, usually in YAAAR format.

SMART Scripting - Commonly Used Routines

NOTE :
More information about SMART data structures can be found at : Data Structures
More information about SMART data conversions can be found at : File Type and Data Structure Conversion |

  1. Convert IPAC tables to YAAAR format and load them into a pointer for input to the IDEA Main Window :

    IDL> sm_ipac_yaaar, aar_dir="directoryname/", ptr_aar

    where "directoryname/" (note trailing "/") is a directory containg IPAC tables.

  2. Read FITS files :

    IDL> sc_read_fits_bcd, bcd_dir="directoryname/", ptr_bcd

    where "directoryname/" (note trailing "/") is a directory containg FITS files.

    NOTE :
    This routine will read all FITS files in directory "directoryname". It assumes that all the files in the directory are FITS bcd files. A pointer array (ptr_bcd) is then produced. Each element in the pointer array is a pointer pointing to a structure. Each element in the structure (BCD, HEADER and FILENAME) is itself a pointer pointing to the FITS data, header or filename. It is fully capable of handling 3-plane data files. |

  3. Preset SMART required keywords in the BCD/DCE FITS header :

    IDL> sm_preset_bcd, ptr_bcd

    NOTE : The same pointer array is used for both input and output.

  4. Set Calibration files and/or parameters within the SMART environment :

    IDL> sm_cal_set, cal_version='15_3'

    This automatically sets the calibration files.

    IDL> sm_cal_select

    This invokes the Calibration Selection window.

  5. Set up Calibration for a particular script within the SMART environment :

    IDL> sm_wavesamp, cal, /restore_cal, /save_cal

    Where "cal" (output parameter) is the Calibration data.

  6. Place "_bcd" FITS headers onto corresponding "_droop" files :

    Pipeline "_bcd" files have been flat field corrected. Pipeline "_droop" have not.
    Sometimes extraction without a predetermined flat field correction is wanted.
    In these cases extract the "_droop" files in SMART and, if wanted, apply seperate flat field correction.

    Attempting to extract "_droop" files with their original (pipeline provided) headers can overload SMART as these headers are significantly longer than "_bcd" ones.
    In this case make a copy file with the "_droop" data and the "_bcd" header.
    CHANGING THE HEADER WILL NOT EFFECT HOW THE DATA IS EXTRACTED

    A very simple IDL function for taking "_droop" files and "_bcd" files and making a new, third set of data files with the "_droop" data and the "_bcd" header : make_composite_file.pro?

    To call it the IDL syntax is : IDL> make_composite_file, in_dir, typename, out_dir

    (All parameters are string type.)

  7. Cleaning up after running scripts :

    The SMART routine sm_cleanup.pro? can be run after running scripts to clean up any outstanding pointers etc.

SMART Scripting - Extraction

There are a wide variety of ways of extracting data with SMART.
SMART scripting has been provided to allow maximum flexibility and indivdual tailoring of data extraction.
In most cases scripted extraction will involve running one or more "top level" IDL functions/procedures which will call the relevant extraction routines.

predefined SCRIPTS can be found at $SM_HOME/scripts/pro/

  • A SMART provided script used for Full Aperture Extraction.
    This script can either :

    1. Return an output pointer array ("ptr_aar") of extracted data.
    2. Extract the data and start the IDEA Main Window with the extracted data directly loaded.

    To produce an output pointer array of extracted data the IDL syntax is :

    IDL> sc_ext_full, bcd_dir = "directoryname/", ptr_aar=ptr_aar

    This will extract all FITS BCD data files in directory "directoryname/" (note trailing "/") and write them to the IDL pointer array "ptr_aar".

    To extract data and save it to a SMART project do the following :

    1. Loading extracted data to a new project :

      1. At the SMART/IDL prompt type the syntax : IDL> sc_ext_full, bcd_dir = "directoryname/", /start_isap
      2. This will extract all FITS BCD data files in directory "directoryname/" (note trailing "/"), invoke the IDEA window and load the extracted data into it.
      3. On quitting the IDEA window it will open the "Project Manager" and "Dataset Manager" windows, load the extracted data and prompt for a new project name.
        The new project can then be saved on exit.
      4. ALTERNATIVE - Before quitting the IDEA window click on the "2Proj" button.
        This will open the "Project Manager" and "Dataset Manager" windows, load the extracted data and prompt for a new project name. The new project can then be saved on exit.

    2. Adding extracted data to an existing project :

      1. Open an existing SMART project with the Project Manager? window then open the Dataset Manager? window.
        The "Dataset Manager" window must be open, though it does not need any data in it.
      2. At the SMART/IDL prompt type the syntax : IDL> sc_ext_full, bcd_dir = "directoryname/", /start_isap
      3. This will extract all FITS BCD data files in directory "directoryname/" (note trailing "/"), invoke the IDEA window and load the extracted data into it.
      4. On quitting the IDEA window it will save the extracted data to the currently open dataset in the "Dataset Manager" window.
        On exit the existing open project will be updated and saved with the newly extracted data.
      5. ALTERNATIVE - Before quitting the IDEA window click on the "2Proj" button.
        This will save the extracted data to the currently open dataset in the "Dataset Manager" window.
        On exit the existing open project will be updated with the newly extracted data and can then be saved.

    This script can also be run with the "/plotit" option as a quick way to preview the spectra.
    For either "ptr_aar" or "/start_isap" type outputs using the "/plotit" keyword will display a plot of flux (Jy) vs wavelength (microns) for each data file as it is extracted.
    NOTE : When "/plotit" is used "Enter" must be pressed after each plot is displayed for processing to continue.

    The SMART/IDL prompt syntax for the two outputs is :

    IDL> sc_ext_full, bcd_dir = "directoryname/", /plotit, ptr_aar=ptr_aar

    IDL> sc_ext_full, bcd_dir = "directoryname/", /plotit, /start_isap

    This script can be called multiple times without quitting the IDEA Main Window, Dataset Manager?, or Project Manager?.
    The header is at : sc_ext_full.pro?

  • A SMART provided script used for Tapered Column Extraction.
    This script can either :

    1. Return an output pointer array ("ptr_aar") of extracted data.
    2. Extract the data and start the IDEA Main Window with the extracted data directly loaded.

    To produce an output pointer array of extracted data the IDL syntax is :

    IDL> sc_ext_tapered, bcd_dir = "directoryname/", ptr_aar=ptr_aar

    FOR MORE DETAILS ABOUT SCRIPTING, PLEASE CONTACT THE ISC GROUP




    THE FOLLOWING IS OBSOLETE

    1. A very simple IDL function for extracting a single image from a FITS BCD file : extract1.pro?

      To call it the IDL syntax is : IDL> output = extract1("filename", header=header)

      For bulk extractions this function could be included in another IDL routine that passes the relevant files one by one
      and stores the data produced in an easily accessible form (IDL structure, FITS file, text file, etc.) for later processing.
      However SMART scripting provides other, more powerful and efficient, methods for extracting large datasets. (See below.)

    2. An IDL program demonstrating extraction of multiple images in one operation : extract2.pro?

      To call it the IDL syntax is : IDL> extract2, "directoryname/"

      This will extract all FITS BCD data files in directory "directoryname/" (note trailing "/") and write them to ASCII ".txt" files in the calling directory.

    3. An IDL program demonstrating extraction of multiple images in one operation with selectable Tapered Column or Gaussian options : extract3.pro?

      To call it for Tapered Column extraction the IDL syntax is : IDL> extract3, "directoryname/", /column, sigma=3.0

      To call it for Gaussian extraction the IDL syntax is : IDL> extract3, "directoryname/", /gaussian, sigma=3.0

      This will perform a gaussian or tapered column extraction of all FITS BCD data files in directory "directoryname/" (note trailing "/") and write them to ASCII ".txt" files in the calling directory.
      For explanation of Tapered Column and Gaussian extraction see : Spectral Extraction Types?
      In both cases the "sigma" keyword is optional and will default to "sigma=4.0" in this script if a value is not supplied.
      NOTE : The value "sigma=3.0" is shown here for example of syntax only. The relevant value of sigma must be chosen for the particular data being extracted.

    4. SMART Scripting - 3 Plane Data

      1. A SMART provided PERL script for making 3 plane data.

        NOTE :
        To use "sm_make_3plane.pl" you must have PERL installed on your system.
        Once PERL is installed you must add to it the "CFITSIO" file subroutine library, (which allows PERL to handle ".fits" files)
        and the "CFITSIO.pm" interface (which allows PERL to use CFITSIO).
        Information about both CFITSIO and CFITSIO.pm can be found at : CFITSIO - A FITS File Subroutine Library.
        (This is maintained by the NASA Goddard Spaceflight Center.)
        Due to the very large number of possible system configurations, sources for and ways of installing PERL
        the SMART development team cannot advise on how to install PERL, CFITSIO or CFITSIO.pm on any particular system.
        Please see your local system administrator for advice about how best to do this. |

        The syntax at the Unix/Linux prompt is : > ./sm_make_3plane.pl "outfile" "bcd" "data" "unc" "bmask"

        Where :

        outfile O Output file (please suffix "3p.fits")
        bcd I Input "bcd" file (formerly bcd_fp) for header
        data I Input "data" file for data
        unc I Input "uncertantity" file
        bmask I Input "bmask" file

        The resultant file (3p.fits) contains the header and data from the input files in the order :

        header from bcd
        data from data
        header from unc
        data from unc
        header from bmask
        data from bmask

        SMART handles this format automatically. To read it in your own programs you can use at the SMART/IDL prompt : IDL> data = readfits("filename", header, EXTEN_NO = 0,1,2)

        Where the value of EXTEN_NO designates both the header and data returned.

        Alternatively you can use at the SMART/IDL prompt : IDL> rdfits_struct, "filename", data_structure

        This will return an IDL data structure with 6 tags :

        HDR0 STRING Array[234]
        IM0 FLOAT Array[128, 128]
        HDR1 STRING Array[256]
        IM1 FLOAT Array[128, 128]
        HDR2 STRING Array[245]
        IM2 INT Array[128, 128]

        Please note that for both "readfits" and "rdfits_struct" the first two data planes are floating point type and the last (bmask) is integer.
        (See also File Type and Data Structure Conversion?.)

        The latest version of DS9 also allows reading files of this sort :

        1. Invoke DS9 at the prompt.
        2. Click "File", "Open Other", "Open Multi Ext as Data Cube".
        3. Pick the relevant file from the selection box that then appears.
        4. The chosen file will load automatically display the "Data Cube" window, allowing scrolling through each data plane.

        NOTE : Only the most recent version of DS9 has this facility. If it is missing from your version please upgrade.

      2. SMART provided scripts for reading all the FITS files in a given directory and converting them to 3 plane data if necessary :

        1. At the SMART/IDL prompt type : IDL> sc_read_bcd, bcd_dir="directoryname/", ptr_bcd, filetype=filetype, status=status

          where "directoryname/" (note trailing "/") is a directory containg FITS bcd files.
          The header is at : sc_read_fits_bcd.pro?

        2. At the SMART/IDL prompt type : IDL> make_3plane, dirname="/home/me/filesin", pu='1', outdir="/home/me/filesout"

          where :

          dirname Directory containing initial files.
          pu If set first 8 files in input directory will be ignored. (PU etc. files.)
          | outdir |Directory to write output files to (must exist).
          If this keyword is not set then output will be written to input directory. |

  •  
    This site is powered by FoswikiCopyright © 2002-2009 by the Cornell IRS Team.
    Send feedback. We use Foswiki.