package OMFastAnalyse;
use strict;
use English;
use Carp;
use vars
qw(@ISA $VERSION $name $author $date $version @instList $numberOfStreams);
@ISA = qw(Module);
use ModuleResources;
use Astro::FITS::CFITSIO qw(TRUE FALSE);
$name = __PACKAGE__;
$VERSION = '1.29';
$version = $VERSION;
$author="Duncan John Fyfe,Ian Stewart,Duncan Law-Green, Jose V Perea, Laura Tomas";
$date="2015-06-23";
@instList=qw(om);
sub numberOfStreams {
return numberOfExposures();
}
sub evaluateRules {
return ignore() if ignored(module => 'OMgetFlat'
,instrument => thisInstrument
,stream => 1
);
return ignore()
if ignored(module => 'OMExpAnalyse'
,instrument => thisInstrument
,stream => thisStream
);
start()
if complete(module => 'OMExpAnalyse'
,instrument => thisInstrument
,stream => thisStream
);
}
sub performAction {
info("Module version number: $version");
my (@extraopts);
my $exp_id=exposureID(instrument => thisInstrument
,stream => thisStream
);
my @FAEList=findFile(class => 'odf'
,instrument => thisInstrument
,exp_id => $exp_id
,content => 'Fast mode events'
,required => 'false'
);
if (scalar(@FAEList)) {
my $tmp = scalar(@FAEList) ;
info("$tmp Fast Mode Windows to process");
}
else {
info("No Fast Mode Windows to process");
return success();
}
my $windowFile=findFile(class => 'odf'
,instrument => thisInstrument
,exp_id => $exp_id
,content => 'Priority window data'
,required => 'true'
);
my $phkFile=findFile(class => 'odf'
,instrument => thisInstrument
,content => 'Periodic housekeeping'
,required => 'true'
);
my $nphkFile=findFile(class => 'odf'
,instrument => thisInstrument
,content => 'Non-periodic housekeeping'
,required => 'true'
);
my $prepThFile=findFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,content => 'omprep tracking history'
);
my $flatGenFile=findFile(class => 'intermediate'
,instrument => thisInstrument,
,content => 'OM Flatfield'
);
foreach my $FAEFile (@FAEList) {
my $imInfo;
$imInfo=fileInfo(class => 'odf'
,name => $FAEFile
);
my $osw = $$imInfo{'osw'};
$osw = $$imInfo{'osw_id'} unless (defined($osw));
$osw = 9 unless (defined($osw));
info("Processing OSW $osw");
my $rawImFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'Fast Mode Raw Image'
);
my $EvListFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'PPS Event List File'
);
info("Start omprep");
doCommand('omprep'
,set => $FAEFile
,nphset => $nphkFile
,pehset => $phkFile
,wdxset => $windowFile
,outset => $EvListFile
,modeset => '1'
) or return exception();
info("Start evselect(1)");
doCommand('evselect'
,table => $EvListFile
,xcolumn => 'RAWX'
,ycolumn => 'RAWY'
,withimageset => 'true'
,imageset => $rawImFile
) or return exception();
info("Start omfastshift");
doCommand('omfastshift'
,nphset => $nphkFile
,thxset => $prepThFile
,set => $EvListFile
) or return exception();
my $FastImgFile=newFile(class => 'product'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'OM FAST MODE OSW IMAGE'
);
my $oswFlatFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'OM OSW Flat Field'
);
info("Start omfastflat");
doCommand('omfastflat'
,slewflatset => $flatGenFile
,oswflatset => $oswFlatFile
,fastimgset => $FastImgFile
,set => $EvListFile
) or return exception();
my $RegionFile=newFile(class => 'product'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'OM OSW FAST REGION FILE'
,format => 'ASCII'
);
my $sourceListFile=newFile(class => 'product'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'OM OSW FAST SOURCE LIST'
);
info("Start omdetect");
doCommand('omdetect'
,set => $FastImgFile
,nsigma => 3
,regionfile => $RegionFile
,outset => $sourceListFile
) or return exception();
my $skyImage=newFile(class => 'product'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'OM FAST MODE OSW SKY IMAGE'
);
info("Start omatt");
doCommand('omatt'
,set => $FastImgFile
,sourcelistset => $sourceListFile
,ppsoswset => $skyImage
,usecat => 'F'
) or return exception();
if (fileExists( file => $skyImage))
{
info("Sky image found ");
my $pngskyImage = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM FAST MODE OSW SKY IMAGE'
, format => 'PNG'
);
if (fileExists( file => $sourceListFile))
{
doCommand(
'implot', set => $skyImage
, device => "$pngskyImage/PNG"
, withsrclisttab => 'yes'
, srclisttab => $sourceListFile.':SRCLIST'
, zscaletype=>'sqrt'
, colourmap=>'7'
) or return exception();
info("implot has created PNG with src list");
}
else
{
doCommand(
'implot', set => $skyImage
, device => "$pngskyImage/PNG"
, withsrclisttab => 'no'
, zscaletype=>'sqrt'
, colourmap=>'7'
) or return exception();
info("implot has created PNG wothout src list");
}
}
else
{
info("Sky image not found");
}
my @RegionFile= readASCIIfile($RegionFile);
my $regionSourceCount = scalar(@RegionFile);
my $sourceListCount = numberFITSRows(file => $sourceListFile, extension => 'SRCLIST');
info("Per-Source Processing");
info("Number of sources from region file $RegionFile: $regionSourceCount");
info("Sources in sourcelist $sourceListFile : $sourceListCount");
if (!$regionSourceCount || !$sourceListCount) {
info("One of the source counts is zero. No source level products will be produced.");
return success();
}
for(my $source = 1;$source < ($regionSourceCount+1);$source++) {
info("Source Number : $source");
setExposureProperty( instrument => thisInstrument , exp_id => $exp_id , name => 'ssp' , value => 0+TRUE );
my $bkgRegionFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,src_num => $source
,content => "OM Background Region File"
);
my $bkgRatesFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,src_num => $source
,content => "OM Background Rates File"
);
my $srcRegionFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,src_num => $source
,content => "OM Source Region File"
);
my $srcRatesFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,src_num => $source
,content => "OM Source Rates File"
);
info("Start omregion");
doCommand('omregion'
,set => $sourceListFile
,srcnumber => "$source"
,nfwhm => '3'
,bkginner => '1.2'
,bkgouter => '2.5'
,bkgfile => $bkgRegionFile
,srcfile => $srcRegionFile
,srcradius => -6
) or return exception();
info("Start evselect (2)");
doCommand('evselect'
,table => $EvListFile
,expression=> "((WIN_FLAG .eq. 0) .and. (region($srcRegionFile, CORR_X, CORR_Y)))"
,maketimecolumn => 'true'
,withrateset => 'T'
,timebinsize => '10'
,rateset => $srcRatesFile
) or return exception();
info("Start evselect (3)");
doCommand('evselect'
,table => $EvListFile
,expression=> "((WIN_FLAG .eq. 0) .and. (region($bkgRegionFile, CORR_X, CORR_Y)))"
,maketimecolumn => 'true'
,withrateset => 'T'
,timebinsize => '10'
,rateset => $bkgRatesFile
) or return exception();
my $lightCurveFile=newFile(class => 'product'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,src_num => $source
,content => "OM OSW SOURCE TIMESERIES"
);
info("Start omlcbuild");
my @IMIList=findFile(class => 'odf'
,instrument => thisInstrument
,exp_id => $exp_id
,content => 'Imaging mode image'
,required => 'false'
);
my $bkgFromImage = 'no';
my $bkgImageFile = '';
foreach my $IMIFile ( sort @IMIList ){
if (fileExists(file => $IMIFile)){
info("Imaging mode image for determining background $exp_id:$IMIFile");
$bkgImageFile = $IMIFile;
$bkgFromImage = 'yes';
last;
}
}
if ( $bkgFromImage =~ /no/){
info("No Imaging mode image (IMI) found for this Fast exposure: $FAEFile");
}
doCommand('omlcbuild'
,srcregionset => $srcRegionFile
,bkgregionset => $bkgRegionFile
,srcrateset => $srcRatesFile
,bkgrateset => $bkgRatesFile
,sourcelistset => $sourceListFile
,wdxset => $windowFile
,outset => $lightCurveFile
,bkgfromimage => $bkgFromImage
,imageset => $bkgImageFile
) or return exception();
info("DEBUG ++ omlcbuild complete, generated TIMESR file: $lightCurveFile");
if (-e $lightCurveFile) {
info("DEBUG ++ TIMESR file $lightCurveFile exists!");
} else {
info("DEBUG ++ WARNING: TIMESR file $lightCurveFile not found!");
}
my $lcPlotFile=newFile(class => 'intermediate'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,src_num => $source
,format => 'PS'
,content => "OM OSW SOURCE TIMESERIES"
);
info("Start lcplot");
doCommand('lcplot'
,set => $lightCurveFile
,binsize => '1'
,plotdevice=>'/VPS'
,plotfile => $lcPlotFile
,tests => 'chi'
) or return exception();
my $pdfLCplot=newFile(class => 'product'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,src_num => $source
,'format' => 'PDF'
,content => "OM OSW SOURCE TIMESERIES"
) or return exception();
info("Start PStoPDF");
PStoPDF(source => $lcPlotFile
,destination => $pdfLCplot
) or return exception();
}
}
return success();
}
1;