Download

package SlewProcess;
use strict;
use English;
use Carp;
use vars qw(@ISA $VERSION $name $author $date $version @instList $numberOfStreams);
@ISA = qw(Module);
use ModuleResources;
use ModuleUtil;

# Declare identity, version, author, date, etc.
$name 	 = __PACKAGE__;
$VERSION = '0.15';
$version = $VERSION;
$author  = 'Duncan Law-Green, Richard Saxton';
$date    = '2010-08-10';

#
# ChangeLog
# =========
#
# version 0.15 - 2010-08-10 DLG
# ------------
# + insert filter/mode check for slew processing
#
# version 0.14 - 2009-06-23 DLG
# ------------
# + changed instList to 'all' to correspond with MakeCIF
#
# version 0.13 - 2009-06-19 DLG
# ------------
# + numberOfStreams set to 1
#
# version 0.12 - 2009-06-19 DLG
# ------------
# + added shared vars to fix module crash
#
# version 0.11 - 2009-06-15 DLG
# ------------
# + continue coding, return success() added 
#
# version 0.1 - 2009-03-18 DLG
# -----------
# + coding started

#
# About Slew Processing
# ---------------------
# SlewProcess calls the SAS wrapper task 'eslewchain'. eslewchain splits an EPIC slew
# into small sections, roughly one degree in length, and generates images and exposure
# maps for each section. It makes use of the tasks atthkgen, attcalc, evselect and 
# eexpmap.

# Processing to proceed as follows:
#
# * Copy slew datafile (SDF) into a clean directory, and point at it with the environment
#   variable SAS_ODF
# 
# * Run ccfbuild and point to the CCF with SAS_CCF
# 
# * Run odfingest
#
# * Run epproc in a working directory
# 
# * Set SAS_ATTITUDE environment variable to 'RAF'
#
# * Run eslewchain in the directory containing the event file produced by epproc

# For guide to issues involved in interpreting slew images, see Saxton et al. 2008, A&A 480, 611

# Declare list of instruments this module is interested in
@instList = qw(all);

# Number of streams
sub numberOfStreams
{
    return 1;
}

# Rules method
sub evaluateRules
{

# Ignore conditions

# Ignore if not doing slew processing
    return ignore()
	if ( ! $ENV{'PCMS_ISSLEW'} );

# Start conditions
    start() 
	if complete( 
		     module => 'MakeCIF'
		     , instrument => 'all'
		     , stream => 1
		     );

}

# Action method
sub performAction
{
    info("Module version number: $version");

# Check for slew dataset here (how??), exit ignore() if not found

    if ( ! $ENV{'PCMS_ISSLEW'} ) {
	info("PCMS_ISSLEW is not set. Ignoring SlewProcess.");
	return ignore();
    }

    info("PCMS_ISSLEW is set. Continuing with SlewProcess.");

# Work out exposure ID for PN, MOS1, MOS2

    my $pn_exp_id = exposureID(instrument => 'epn',
			       stream => 1 );

    my $mos1_exp_id = exposureID(instrument => 'emos1',
				 stream => 1 );

    my $mos2_exp_id = exposureID(instrument => 'emos2',
				 stream => 1 );

# Fetch filter and mode, trip exception if not correct for slew processing

    my $pn_filter = getExposureProperty(instrument => 'epn',
				     exp_id => $pn_exp_id,
				     name => 'filter') || "Inactive" ;
    info("PN Filter: $pn_filter");


    my $mos1_filter = getExposureProperty(instrument => 'emos1',
					  exp_id => $mos1_exp_id,
					  name => 'filter') || "Inactive" ;

    info("MOS1 Filter: $mos1_filter");

    my $mos2_filter = getExposureProperty(instrument => 'emos2',
					  exp_id => $mos2_exp_id,
					  name => 'filter') || "Inactive" ;

    info("MOS2 Filter: $mos2_filter");

    my $pn_mode = getExposureProperty(instrument => 'epn',
				   exp_id => $pn_exp_id,
				   name => 'mode') || "Inactive" ;
    info("PN Mode: $pn_mode");

    my $mos1_mode = getExposureProperty(instrument => 'emos1',
				   exp_id => $mos1_exp_id,
				   name => 'mode') || "Inactive" ;
    info("MOS1 Mode: $mos1_mode");

    my $mos2_mode = getExposureProperty(instrument => 'emos2',
				   exp_id => $mos2_exp_id,
				   name => 'mode') || "Inactive" ;
    info("MOS2 Mode: $mos2_mode");

    if ($pn_filter !~ /^Medium/ && $mos1_filter !~ /^Medium/ && $mos2_filter !~ /^Medium/) {
	info("Incorrect EPIC filter for slew: $pn_filter | $mos1_filter | $mos2_filter, should be Medium.");
	info("Ignoring SlewProcess...");
	return ignore();
    }

    if ($pn_mode !~ /^(PrimeFullWindow|PrimeLargeWindow|PrimeFullWindowExtended)/ && $mos1_mode !~ /^(PrimeFullWindow|PrimeLargeWindow|PrimeFullWindowExtended)/ && $mos2_mode !~ /^(PrimeFullWindow|PrimeLargeWindow|PrimeFullWindowExtended)/) {
	info("Incorrect EPIC mode for slew: $pn_mode | $mos1_mode | $mos2_mode, should be PrimeFullWindow || PrimeLargeWindow || PrimeFullWindowExtended.");
	info("Ignoring SlewProcess...");
	return ignore();
    }

# Run epproc
#
    info("Running epproc on slew sequence");
    doCommand(
	      'epproc'
	      , removetemporaries => 1
	      , removeintermediategtis => 1
	      , removeintermediateeventlists => 1
	      , selectccds => 0
	      )
	or return exception();

# Run eslewchain
# SAS task has no parameters in documentation

    info("Running eslewchain on slew sequence");
    doCommand(
	      'eslewchain'
	      )
	or return exception();

# Return success

    success();
     
}

# need to rename output files by SSC band names
# get translation table?

1;