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;
$name = __PACKAGE__;
$VERSION = '0.17';
$version = $VERSION;
$author = 'Duncan Law-Green, Richard Saxton,Pedro Rodriguez,Jose Vicente Perea';
$date = '2016-08-04';
@instList = qw(all);
sub numberOfStreams
{
return 1;
}
sub evaluateRules
{
return ignore()
if ( ! $ENV{'PCMS_ISSLEW'} );
start()
if complete(
module => 'MakeCIF'
, instrument => 'all'
, stream => 1
);
}
sub performAction
{
info("Module version number: $version");
if ( ! $ENV{'PCMS_ISSLEW'} ) {
info("PCMS_ISSLEW is not set. Ignoring SlewProcess.");
return ignore();
}
info("PCMS_ISSLEW is set. Continuing with SlewProcess.");
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 );
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();
}
info("Running epproc on slew sequence");
doCommand(
'epproc'
, removetemporaries => 1
, removeintermediategtis => 1
, removeintermediateeventlists => 1
, selectccds => 0
)
or return exception();
info("Running eslewchain on slew sequence");
doCommand(
'eslewchain'
, withpng => 'yes'
)
or return exception();
info("Running eslewsearch on slew sequence");
doCommand(
'eslewsearch'
)
or return exception();
my $rootdir = $ModuleResources::Seqdb->{'directories'}{'root'};
info("Sequence root directory: $rootdir");
moveFile(source => "*Badpixels.ds",
destination => 'intermediate/') unless ignored( module => 'SlewProcess', stream => 1 );
my $obsid = $ENV{'SAS_RAND_SEED'};
my ($attfile) = glob("$rootdir/P*OBX000ATTTSR0000.ds");
my $attdest = newFile(class => 'product'
,instrument => 'ob'
,content => 'SLEW ATTITUDE FILE'
,format => 'FITS'
);
moveFile(source => "$attfile"
,destination => "$attdest") unless ignored( module => 'SlewProcess', stream => 1 );
my $sourcename = sprintf("P%010s",$obsid);
doCommand(
'addattribute', set => $attdest
, attributename => 'OBJECT'
, attributetype => 'string'
, stringvalue => "$sourcename"
) unless ignored(module => 'SlewProcess', stream => 1 );
my ($rawfile) = glob("$rootdir/*ImagingEvts.ds");
my $rawdest = newFile(class=>'product'
,instrument => 'epn'
,exp_id => 'S003'
,content => 'SLEW SINGLE RAW EVENT LIST'
,format => 'FITS'
);
moveFile(source => "$rawfile"
,destination => "$rawdest") unless ignored( module => 'SlewProcess', stream => 1 );
my $sourcename = sprintf("P%010s",$obsid);
doCommand(
'addattribute', set => $rawdest
, attributename => 'OBJECT'
, attributetype => 'string'
, stringvalue => "$sourcename"
) unless ignored( module => 'SlewProcess', stream => 1 );
my $filtfile;
my $filtdest;
my $filtstep = 0;
my @filtlist = glob("$rootdir/P*PNS003PIEVLI0*.ds");
foreach $filtfile (@filtlist) {
$filtdest = newFile(class => 'product'
,instrument => 'epn'
,exp_id => 'S003'
,content => 'SLEW STEP FILTERED EVENT LIST'
,format => 'FITS'
,src_num => "$filtstep"
);
moveFile(source => "$filtfile"
,destination => "$filtdest");
my $sourcename = sprintf("P%010s_%03x",$obsid,$filtstep);
doCommand(
'addattribute', set => $filtdest
, attributename => 'OBJECT'
, attributetype => 'string'
, stringvalue => "$sourcename"
);
$filtstep++;
}
my $slewband;
my $stepfile;
my $stepdest;
foreach $slewband ( '6', '7', '8' ) {
$filtstep = 0;
my @steplist = glob("$rootdir/P*PNS003EXPMAP${slewband}*.ds");
foreach $stepfile (@steplist) {
my $stepdest = newFile(class => 'product'
, instrument => 'epn'
, exp_id => 'S003'
, content => 'SLEW STEP EXPOSURE MAP'
, format => 'FITS'
, src_num => "$filtstep"
, band => "$slewband"
);
moveFile(source => "$stepfile"
,destination=> "$stepdest");
my $sourcename = sprintf("P%010s_%03x",$obsid,$filtstep);
doCommand(
'addattribute', set => $stepdest
, attributename => 'OBJECT'
, attributetype => 'string'
, stringvalue => "$sourcename"
);
$filtstep++;
}
}
my $pngfile ;
my $pngdest ;
foreach $slewband ( "6", "7", "8" ) {
$filtstep = 0;
my @steplist = glob("$rootdir/P*PNS003IMAGE_${slewband}*.ds");
foreach $stepfile (@steplist) {
my $pngfile = $stepfile ;
$pngfile =~ s/ds/png/;
my $pngdest = newFile(class => 'product'
, instrument => 'epn'
, exp_id => 'S003'
, content => 'SLEW STEP IMAGE'
, format => 'PNG'
, src_num => "$filtstep"
, band => "$slewband"
);
moveFile(source => "$pngfile"
,destination=> "$pngdest");
my $stepdest = newFile(class => 'product'
, instrument => 'epn'
, exp_id => 'S003'
, content => 'SLEW STEP IMAGE'
, format => 'FITS'
, src_num => "$filtstep"
, band => "$slewband"
);
moveFile(source => "$stepfile"
,destination=> "$stepdest");
my $sourcename = sprintf("P%010s_%03x",$obsid,$filtstep);
doCommand(
'addattribute', set => $stepdest
, attributename => 'OBJECT'
, attributetype => 'string'
, stringvalue => "$sourcename"
);
$filtstep++;
}
}
foreach $slewband ( "6", "7", "8" ) {
my ($stepfile) = glob("$rootdir/P*PNS003OMSRLI${slewband}*.FIT");
my $stepdest = newFile(class => 'product'
, instrument => 'epn'
, exp_id => 'S003'
, content => 'EPIC OBSERVATION ML SOURCE LIST'
, format => 'FITS'
, band => "$slewband"
);
moveFile(source => "$stepfile"
,destination=> "$stepdest");
}
my ($mergedSrcListTemp) = glob("$rootdir/P*PNS003OMSSLI0000.FIT");
my $mergedSrcList = newFile(class => 'product'
, instrument => 'epn'
, exp_id => 'S003'
, content => 'EPIC SUMMARY SOURCE LIST FOR SLEW DATA'
, format => 'FITS'
);
moveFile(source => "$mergedSrcListTemp"
,destination=> "$mergedSrcList");
$filtstep = 0;
my $unffile;
my $unfdest;
my @unflist = glob("$rootdir/P*PNS003UNFDAT8*.ds");
foreach $unffile (@unflist) {
$unfdest = newFile(class => 'product'
,instrument => 'epn'
,exp_id => 'S003'
,content => 'UNFILTERED SLEW STEP IMAGE'
,format => 'FITS'
,src_num => "$filtstep"
,band => '8'
);
moveFile(source => "$unffile"
,destination => "$unfdest");
my $sourcename = sprintf("P%010s_%03x",$obsid,$filtstep);
doCommand(
'addattribute', set => $unfdest
, attributename => 'OBJECT'
, attributetype => 'string'
, stringvalue => "$sourcename"
);
$filtstep++;
}
my @unlinklist = glob("$rootdir/*.ds");
unlink @unlinklist unless ignored( module => 'SlewProcess', stream => 1 );
info("Starting StampKeywords subroutine...");
my ( @name, @type, @value, @comment, @withcomment );
my @list = findFile(
class => 'product'
, 'format' => 'FITS'
);
@list = grep { $_ !~ /CAX000/} @list;
return success() unless @list;
my $obs = getObservationProperties();
my $odsver = getOdsVer();
my $odfver = getOdfVer();
my $info = fileInfo( class => 'product', name => $list[0] );
push @name, 'SEQ_ID';
push @type, 'string';
push @value, $info->{sequence};
push @comment, 'Pipeline sequence';
push @withcomment, 'y';
push @name, 'REVOLUT';
push @type, 'string';
push @value, $obs->{orbit};
push @comment, 'Satellite Revolution Number';
push @withcomment, 'y';
push @name, 'PROCDATE';
push @type, 'string';
push @value, $obs->{procdate};
push @comment, 'Processing date';
push @withcomment, 'y';
push @name, 'PROCREV';
push @type, 'string';
push @value, $obs->{procrevision};
push @comment, 'Processing revision';
push @withcomment, 'y';
push @name, 'PPSVERS';
push @type, 'string';
push @value, $obs->{ppsversion};
push @comment, 'PPS configuration';
push @withcomment, 'y';
push @name, 'SASVERS';
push @type, 'string';
push @value, $obs->{sasversion};
push @comment, 'SAS version';
push @withcomment, 'y';
push @name, 'ODSVER';
push @type, 'string';
push @value, "$odsver";
push @comment, 'ODS version';
push @withcomment, 'y';
push @name, 'ORIGIN';
push @type, 'string';
push @value, 'Leicester/SSC';
push @comment, 'Origin of FITS file';
push @withcomment, 'y';
push @name, 'OBSERVER';
push @type, 'string';
push @value, 'XMM-Newton';
push @comment, 'Observer';
push @withcomment, 'y';
push @name, 'ODFVER';
push @type, 'string';
push @value, sprintf('%03d',$odfver);
push @comment, 'ODF_VERSION';
push @withcomment, 'y';
push @name, 'CONTENT';
push @type, 'string';
push @comment, 'Contents of file';
push @withcomment, 'y';
foreach my $file (@list)
{
next unless fileExists( file => $file );
my $l_info = fileInfo( class => 'product', name => $file );
doCommand(
'addattribute', set => $file
, attributename => [@name]
, attributetype => [@type]
, stringvalue => [ @value, uc( $l_info->{content} ) ]
, attributecomment => [@comment]
)
or return exception();
}
info("StampKeywords subroutine complete!");
success();
}
1;