next up previous 80
Next: preprun1
Up: Script source code
Previous: prepflat


prepobjs

Download prepobjs

#!/bin/csh

#+
#  Name:
#     prepobjs

#  Purpose:
#     Script to prepare a set of object frames for use by ECHOMOP.

#  Language:
#     C shell script.

#  Description:
#     This script takes a list of "raw" CCD object frames and performs
#     the basic CCD data processing steps of bias subtraction and trimming
#     on the images.  Bias subtraction removes the zero-point bias
#     introduced by the camera electronics.  Trimming removes the pre-scan
#     and over-scan regions of the CCD image which contain no science data
#     and can confuse the algorithms in echelle data reduction software.
#
#     If required, the CCD frames can be rotated so that the dispersion
#     direction of the echelle orders runs horizontally as required by
#     ECHOMOP.
#
#     The script produces a series of files o_"file" where "file" is the
#     name of the source frame.

#  Usage:
#     This script can simply be invoked from the shell; in this case
#     the script will prompt for a list of the input object images.
#     Alternatively, the list of frames can be supplied on the
#     command line, for example:
#
#        % prepobjs run0800 run0801 run0802 run0856 run0857 run0858
#
#     If wildcarding facilities are available in your shell, you can use
#     them to simplify the command line, for example, the above would
#     become:
#
#        % prepobjs run080[012] run085[678]
#
#     in the C shell.  This wildcarding facility is available when the
#     script prompts for a list of input images.
#
#     In practice, invocation from your shell is unlikely to be a good
#     method of using this script as 8 environment variables defining
#     the region of the image to be kept and the region of the overscan
#     to be used for debiasing are required.  Use of these variables is
#     summarised below.

#  Notes:
#     1. If needed, the input parameters can be input at the command
#        line thus:
#
#           % nohup prepobjs filename [filename...] &
#
#        the "nohup" command will ensure that the script continues
#        to run even when you have logged off the system.  The "&" at
#        the end of the line will run the script in the background.
#
#     2. This script is designed to be used as part of an automated
#        echelle data reduction package.  If you intend to use it
#        for this purpose, you should not change the name of the output
#        frames from o_"file" where "file" is an input frame.  See the
#        comments in the script for changes which can be made if it is
#        to be used stand-alone.
#
#     3. This script will work with FIGARO v5.0-0 or later.
#
#     4. When this script is invoked, 8 environment variables defining
#        the overscan region to be used for debiasing, and the region
#        of the images containing science data must be defined.
#        These environment variables are used:
#
#         $xbimin
#           X-start of overscan region to use for bias subtract.
#         $xbimax
#           X-end of overscan region to use for bias subtract.
#         $ybimin
#           Y-start of overscan region to use for bias subtract.
#         $ybimax
#           Y-end of overscan region to use for bias subtract.
#         $xtrmin
#           X-start of region of image to be retained.
#         $xtrmax
#           X-end of region of image to be retained.
#         $ytrmin
#           Y-start of region of image to be retained.
#         $ytrmax
#           Y-end of region of image to be retained.
#
#     5. A file "biasframe" containing a bias frame prepared by the
#        script "prepbias" should exist in the working directory.
#        You can alter the name of this file, see comments in the
#        script.
#
#     6. The input frames are NOT rotated by this script.  You may
#        have images in which the orders run roughly vertically,
#        in which case you should uncomment the line using FIGARO
#        IROT90 as indicated in the script. Approximately horizontal
#        orders are required by ECHOMOP.
#
#     7. This script is designed to be called by a master reduction
#        script.  See the example scripts "preprun1" and "preprun2"
#        for details.

#  Authors:
#     ACC: Andrew Collier Cameron (St. Andrews)
#     MJC: Martin Clayton (Starlink)
#     {enter_new_authors_here}

#  History:
#     ??-???-???? (ACC):
#       Original Version.
#     06-NOV-1995 (MJC):
#       Minor tidying up for Cookbook Version.
#     {enter_further_changes_here}

#-

#  Do Starlink login and set up for Starlink applications used.
#  You can comment out these lines if you already have these set up AND
#  you invoke the script by "source"ing it, for example:
#
#     % source prepobjs run080[012] run085[678]
#
      source /star/etc/cshrc;
      source /star/etc/login;
      alias echo 'echo >/dev/null';
      figaro;
      unalias echo;

#  Force standard UNIX commands to "normal" behaviour.
#  This is to remove any special alias for the remove command.
      set rm_old = `alias rm`;
      unalias rm;

#  This line should only be modified if you wish to run several jobs
#  simultaneously, or you keep your Starlink parameter files in a
#  non-default directory.  If you don't understand this then leave the
#  line as it is!
      set ADAMDIR = $HOME/adam;

#  Get the list of input object frames, either from the command line
#  or by prompting.
      if ( "$#argv" == 0 ) then
         echo '';
         echo -n '? Object Frame(s) > ';
         set Files = ( `echo $< ` );

      else
         set Files = ( $* );
      endif

#  Display information confirming the selected bias-level calculation
#  region.
      echo " Bias statistics will be calculated over X-range "\
 "$xbimin to $xbimax ";
      echo "                                and over Y-range "\
 "$ybimin to $ybimax ";

#  Display information confirming the selected region of the image to be
#  retained; i.e., the CCD area containing the science data.
      echo " Frames will be trimmed over X-range $xtrmin to $xtrmax ";
      echo "                    and over Y-range $ytrmin to $ytrmax ";

#  Set script-internal variables to describe the trimming region.
      @ Xmin = $xtrmin;
      @ Xmax = $xtrmax;
      @ Ymin = $ytrmin;
      @ Ymax = $ytrmax;

      @ Xsize = $Xmax - $Xmin + 1;
      @ Ysize = $Ymax - $Ymin + 1;

#  Set the name of the input median bias frame.
#  You can change this line if you are using the script on its own.
      set Biasframe = 'biasframe';

#  Set loop parameters and go through the input file list,
#  checking whether the files exist, and processing them into "o_" files.
      @ found = 0;
      foreach File ( $Files )
         if ( -e $File ) then

#        Subtract the bias frame from the input image.
            isub $File:r $Biasframe junk1;

#        Use FIGARO ISTAT to determine the median level in the
#        selected overscan region.
            istat junk1 $ybimin $ybimax $xbimin $xbimax median;

#        Use FIGARO ICSUB to subtract the overscan level from the image.
#        This accesses the parameters written by the previous (ISTAT)
#        command and uses the median value found in the overscan region.
            icsub junk1 @$ADAMDIR/istat.STAT_MEDIAN junk2;

#        Set the name of the trimmed, debiassed image.
            set NewFile = o_$File:r;

#        Trim off the unwanted parts of the frame, leaving only the
#        region containing the science data.
#        Rotate the frame by 90 degrees to give horizontal orders.
#        If your orders already run with the dispersion direction
#        in a roughly horizontal direction then comment out the next
#        two code lines and replace them with the line below.
#            isubset junk2 $Ymin $Ymax $Xmin $Xmax $NewFile;
            isubset junk2 $Ymin $Ymax $Xmin $Xmax junk3;
            irot90 junk3 $NewFile;

#        Increment the count of flat-field frames found.
            @ found++;

#        Delete intermediate files.
            rm junk*;

         else
            echo "! Could not find $File.";
         endif
      end

#  Display informational message.
      echo "! $found object frames subtracted by master-bias, trimmed and rotated.";

#  Reset any user command aliases.
      alias rm $rm_old;

#  End-of-file.


next up previous 80
Next: preprun1
Up: Script source code
Previous: prepflat

Echelle Data Reduction Cookbook
Starlink Cookbook 3
Martin Clayton
10 July 2003
E-mail:ussc@star.rl.ac.uk

Copyright © 2000, 2003 Council for the Central Laboratory of the Research Councils