package OMImageAnalyse;
use strict;
use English;
use Carp;
use Regexp::Common qw(boolean);
use vars
qw(@ISA $VERSION $name $author $date $version @instList $numberOfStreams);
@ISA = qw(Module);
use ModuleResources;
use Astro::FITS::CFITSIO qw(TRUE FALSE);
use ModuleUtil;
use Data::Dumper;
$name = __PACKAGE__;
$VERSION = '3.24';
$version = $VERSION;
$author = 'Duncan Law-Green,Dean Hinshaw,Duncan John Fyfe,Ian Stewart,Eduardo Ojero,Ed Chapin,Pedro Rodriguez,Jose Vicente Perea';
$date = '2016-02-18';
@instList = qw(om);
sub Instlist
{
return 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
)
and complete (
module => 'USNOExtract'
, instrument => 'all'
, stream => 1
);
}
use vars qw( %Filters );
my %Filters = (
'BLOCKED' => '9'
, 'V' => 'V'
, 'U' => 'U'
, 'B' => 'B'
, 'WHITE' => 'W'
, 'GRISM2' => 'G'
, 'GRISM1' => 'H'
, 'UVW1' => 'L'
, 'UVW2' => 'S'
, 'UVM2' => 'M'
);
sub getfiltershortname
{
my ($c,$f) = (@_);
$f = uc($f);
return exists( $Filters{$f} )
? $Filters{$f}
: exception( Exception->('BADOMFILTER','Unrecognized filter :',$f) );
;
}
sub performAction
{
info("Module version number: $version");
my $exp_id = exposureID(
instrument => thisInstrument
,stream => thisStream
);
my %products = (
USER => {
IMG => { CLASS => 'product', CONTENT => 'OM OSW IMAGE' }
, SKYIMG => { CLASS => 'product', CONTENT => 'OM OSW SKY IMAGE' }
, SRC => { CLASS => 'product', CONTENT => 'OM OSW SOURCE LIST' }
}
, RUDI5_LR => {
IMG => { CLASS => 'product', CONTENT => 'OM OSW IMAGE' }
, SKYIMG => { CLASS => 'product', CONTENT => 'OM OSW SKY IMAGE' }
, SRC => { CLASS => 'product', CONTENT => 'OM OSW SOURCE LIST' }
}
, RUDI5_HR => {
IMG => { CLASS => 'product', CONTENT => 'OM OSW IMAGE' }
, SKYIMG => { CLASS => 'product', CONTENT => 'OM OSW SKY IMAGE' }
, SRC => { CLASS => 'product', CONTENT => 'OM OSW SOURCE LIST' }
}
, FFENG2 => {
IMG => { CLASS => 'product', CONTENT => 'OM FULL-FRAME IMAGE' }
, SKYIMG => { CLASS => 'product' , CONTENT => 'OM FULL-FRAME SKY IMAGE' }
, SRC => { CLASS => 'product', CONTENT => 'OM OSW SOURCE LIST' }
}
, PFENG2 => {
IMG => { CLASS => 'product', CONTENT => 'OM FULL-FRAME IMAGE' }
, SKYIMG => { CLASS => 'product' , CONTENT => 'OM FULL-FRAME SKY IMAGE' }
, SRC => { CLASS => 'product', CONTENT => 'OM OSW SOURCE LIST' }
}
, ENG4 => {
IMG => { CLASS => 'product', CONTENT => 'OM FULL-FRAME IMAGE' }
, SKYIMG => { CLASS => 'product' , CONTENT => 'OM FULL-FRAME SKY IMAGE' }
, SRC => { CLASS => 'product', CONTENT => 'OM OSW SOURCE LIST' }
}
);
my %inputimage = (
RUDI5_LR => {
CLASS => 'odf'
, CONTENT => 'Imaging mode image'
, LIST => []
}
, RUDI5_HR => {
CLASS => 'odf'
, CONTENT => 'Imaging mode image'
, LIST => []
}
, PFENG2 => {
CLASS => 'intermediate'
, CONTENT => 'Engineering Mode 2 Combined Image'
, LIST => []
}
, FFENG2 => {
CLASS => 'odf'
, CONTENT => 'Engineering mode image'
, LIST => []
}
, ENG4 => {
CLASS => 'odf'
, CONTENT => 'Engineering mode image'
, LIST => []
}
, USER => {
CLASS => 'odf'
, CONTENT => 'Imaging mode image'
, LIST => []
}
);
my $count = 0;
info("Looking for Engineering Mode Files...");
my @englist = findFile(
class => 'odf'
, instrument => thisInstrument
, exp_id => $exp_id
, content => 'Engineering mode image'
);
$count = scalar(@englist) || "None";
info("Found $count Engineering mode Windows.");
my %keywords;
$inputimage{ENG4}{LIST} = [ grep ( /E4I/, @englist ) ];
foreach my $e4i ( @{$inputimage{ENG4}{LIST}} )
{
$keywords{$e4i} = { &get_keywords($e4i,'OME4I1') };
}
$count = scalar(@{$inputimage{ENG4}{LIST}}) || 'No';
info("Found $count Full Frame Engineering 4 Windows.");
push @{$inputimage{FFENG2}{LIST}} , ( grep ( /E2I/, @englist ));
foreach my $e2i ( @{ $inputimage{FFENG2}{LIST} } )
{
$keywords{$e2i} = { &get_keywords($e2i,'OME2I1') };
}
$count = scalar(@{$inputimage{FFENG2}{LIST}}) || 'no';
info("Found $count Full Frame Engineering 2 Windows.");
info("Looking for Image Mode Files...");
my @imiList = findFile(
class => 'odf'
, instrument => thisInstrument
, exp_id => $exp_id
, content => 'Imaging mode image'
);
$count = scalar(@imiList) || "no";
info("Found $count Image mode images.");
foreach my $imi (@imiList)
{
$keywords{$imi} = { &get_keywords($imi,'OMIMI1') };
&image_format( $imi , $keywords{$imi} );
my $mode = $keywords{$imi}{MODE};
info("Identified mode: $mode");
push( @{ $inputimage{$mode}{LIST} }, $imi );
}
my $combine = 0;
my $imggap;
if ( @{ $inputimage{PFENG2}{LIST} } > 2 )
{
my @pfeng2list = @{ $inputimage{PFENG2}{LIST} };
$inputimage{PFENG2}{LIST} = [];
info("Might have Partial-Frame Engineering Mode 2 images.");
info("Trying to generate a combined image.");
my $en2comb = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, content => 'Engineering Mode 2 Combined Image'
);
$combine = doCommand(
'omcomb', imagesets => [ @pfeng2list ]
, outset => $en2comb
);
if ($combine)
{
info("Successfully created a combined image.");
$keywords{$en2comb} = { &get_keywords($en2comb , 'OMIMI1') };
$imggap = readFITSKeyword(
class => 'odf'
, file => $en2comb
, extension => 'OMIMI1'
, keyword => 'IMGGAP'
);
if ($imggap)
{
if (( $keywords{$en2comb}{FILTER} eq '200' || $keywords{$en2comb}{FILTER} eq '1000' )
&& ($imggap eq '2' || $imggap eq '3')
){
info( "Inner segment of combined image missing with GRISM filter." );
info( "Will process as individual USER mode images." );
$combine = 0;
push @{ $inputimage{USER}{LIST} } , @pfeng2list;
}
else
{
info( "Outer segment of combined image missing with GRISM filter." );
info( "Will continue to process as an ENG2 image." );
}
}
else
{
info( "Processing as Engineering mode 2" );
push ( @{ $inputimage{PFENG2}{LIST} } , $en2comb );
}
}
}
else
{
info(
"Failed to make a suitable combined image. Will process components as USER mode."
);
push( @{ $inputimage{USER}{LIST} } , @{ $inputimage{PFENG2}{LIST} });
$inputimage{PFENG2}{LIST} = [];
}
my %p;
$p{windowFile} = findFile(
class => 'odf'
, instrument => thisInstrument
, exp_id => $exp_id
, content => 'Priority window data'
, required => 'true'
);
$p{phkFile} = findFile(
class => 'odf'
, instrument => thisInstrument
, content => 'Periodic housekeeping'
, required => 'true'
);
$p{nphkFile} = findFile(
class => 'odf'
, instrument => thisInstrument
, content => 'Non-periodic housekeeping'
, required => 'true'
);
$p{prepThFile} = findFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, content => 'omprep tracking history'
);
$p{flatGenFile} = findFile(
class => 'intermediate'
, instrument => thisInstrument
, content => 'OM Flatfield'
);
my @skyimagedetails = ();
my @sourcedetails = ();
foreach my $mode ( 'USER', 'RUDI5_LR', 'RUDI5_HR', 'PFENG2' , 'FFENG2' , 'ENG4' )
{
info("Processing $mode Images.");
my @imList = @{ $inputimage{$mode}{LIST} };
$count = scalar(@imList);
info("$count images to process.");
next unless ($count);
foreach my $imFile (@imList)
{
Msg->mark( __PACKAGE__ , INPUTIMAGE => \%inputimage, MODE => $mode );
my $imInfo = fileInfo(
class => $inputimage{$mode}{CLASS}
, name => $imFile
);
my $osw = $imInfo->{'osw'};
$osw = $imInfo->{'osw_id'}
unless ( defined($osw) )
;
$osw = 9
unless ( defined($osw) )
;
info("Processing $exp_id:$osw:$imFile");
$p{rawImFile} = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'Raw Image'
);
my $result;
if ($keywords{$imFile}{FILTER} eq '200' || $keywords{$imFile}{FILTER} eq '1000')
{
$result = &process_grism_image(exp_id => $exp_id
,osw => $osw
,imFile => $imFile
,mode => $mode
,keywords => $keywords{$imFile}
,skyimageoutput => $products{$mode}{SKYIMG}
,srcoutput => $products{$mode}{SRC}
,imgoutput => $products{$mode}{IMG}
,%p
);
}
else
{
$result = &process_image(exp_id => $exp_id
,osw => $osw
,imFile => $imFile
,mode => $mode
,keywords => $keywords{$imFile}
,skyimageoutput => $products{$mode}{SKYIMG}
,srcoutput => $products{$mode}{SRC}
,imgoutput => $products{$mode}{IMG}
,%p
);
}
if ($result)
{
my @tmpsrcdetails = $result->{srcdetails};
my $di = 0;
my @flatsrcdetails = ();
for ($di = 0; $di <= $#tmpsrcdetails; $di++) {
push (@flatsrcdetails, $tmpsrcdetails[$di][0]);
}
my @tmpskyimgdetails = $result->{skyimgdetails};
my $di = 0;
my @flatskyimgdetails = ();
for ($di = 0; $di <= $#tmpskyimgdetails; $di++) {
push (@flatskyimgdetails, $tmpskyimgdetails[$di][0]);
}
push @skyimagedetails, @flatskyimgdetails;
push @sourcedetails, @flatsrcdetails;
}
}
}
info("All images processed");
info("Writing accounting information");
my $debugsourcedetails = Dumper(\@sourcedetails);
info("DEBUG: sourcedetails array: $debugsourcedetails");
my $debugskyimagedetails = Dumper(\@skyimagedetails);
info("DEBUG: skyimagedetails array: $debugskyimagedetails");
if (@sourcedetails)
{
my $sourcedetailsfile = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, format => "ASCII"
, content => "OM SRC IMAGE DETAILS"
);
writeASCIIFile(
name => $sourcedetailsfile
, text => \@sourcedetails
);
}
if (@skyimagedetails)
{
my $skyimagedetailsfile = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, format => "ASCII"
, content => "OM SKY IMAGE DETAILS"
);
writeASCIIFile(
name => $skyimagedetailsfile
, text => \@skyimagedetails
);
}
return success();
}
sub process_image
{
my ( %h ) = (@_);
my ($exp_id , $osw , $imFile , $rawImFile , $nphkFile , $phkFile , $windowFile , $prepThFile , $flatGenFile , $skyimageoutput , $srcoutput , $imgoutput , $mode , $keywords );
($exp_id , $osw , $imFile , $rawImFile , $nphkFile , $phkFile , $windowFile , $prepThFile , $flatGenFile , $skyimageoutput , $srcoutput , $imgoutput , $mode , $keywords )
= @h{qw( exp_id osw imFile rawImFile nphkFile phkFile windowFile prepThFile flatGenFile skyimageoutput srcoutput imgoutput mode keywords)}
;
my $rtn = { srcdetails => [] , skyimgdetails => []};
doCommand(
'omprep', set => $imFile
, nphset => $nphkFile
, pehset => $phkFile
, wdxset => $windowFile
, outset => $rawImFile
, modeset => 0
)
or return exception();
info("Retrieving FILTER value");
my $filter = readFITSKeyword(
class => 'intermediate'
, file => "$rawImFile"
, extension => 'PRIMARY'
, keyword => 'FILTER'
);
$filter = __PACKAGE__->getfiltershortname($filter);
info("FILTER = $filter");
info("Retrieving EXPOSURE value");
my $duration = readFITSKeyword(
class => 'intermediate'
, file => "$rawImFile"
, extension => 'PRIMARY'
, keyword => 'EXPOSURE'
);
info("EXPOSURE = $duration");
if ( ( $mode eq 'RUDI5_LR' )
&& !( ( $keywords->{WINDOWDX} == 976 )
&& ( $keywords->{WINDOWDY} == 960 )
)){
$duration *= -1;
}
$osw = ( $mode =~ /ENG[24]/ ) ? $filter : $osw;
doCommand(
'omcosflag', set => $rawImFile
, thxset => $prepThFile
)
or return exception();
my $flatOut = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OSW Flat Field'
);
my $flattedIm = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OSW Flat Fielded Image'
);
doCommand(
'omflatfield', set => $rawImFile
, thxset => $prepThFile
, inorbitflatset => $flatGenFile
, tsflatset => $flatOut
, outset => $flattedIm
)
or return exception();
my $finalImage = newFile(
class => $imgoutput->{CLASS}
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => $imgoutput->{CONTENT}
);
my $mod8Im = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OSW MODULO 8 IMAGE'
);
doCommand(
'ommodmap', set => $flattedIm
, mod8product => 'Y'
, mod8set => $mod8Im
, outset => $finalImage
, nsig => 6
, nbox => 16
)
or return exception();
doCommand('omqualitymap', set => $finalImage
, srclistset => ''
, outset => $finalImage
, mode => 'setqualityimage'
)
or return exception();
my $sourceListFile = newFile(
class => $srcoutput->{CLASS}
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => $srcoutput->{CONTENT}
);
my $RegionFile=newFile(class => 'product'
,instrument => thisInstrument
,exp_id => $exp_id
,osw_id => $osw
,content => 'OM OSW REGION FILE'
,format => 'ASCII'
);
doCommand(
'omdetect', set => $finalImage
, nsigma => 2.0
, minsignificance => 3
, detectextended => 'Y'
, regionfile => $RegionFile
, outset => $sourceListFile
)
or return exception();
doCommand('omqualitymap', set => $finalImage
, srclistset => $sourceListFile
, outset => $finalImage
, mode => 'setqualityimage'
)
or return exception();
push( @{$rtn->{srcdetails}}
, "$sourceListFile\|$mode\|$filter\n"
);
doCommand( 'ommag', set => $sourceListFile )
or return exception();
my $usnoList = findFile(
class => 'product'
, instrument => 'all'
, content => 'Reference catalogue'
, format => 'FITS'
);
info("No USNO extract to work from. Unable to continue.") and ignore() unless defined ($usnoList);
my $skyImage = newFile(
class => $skyimageoutput->{CLASS}
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => $skyimageoutput->{CONTENT}
);
doCommand(
'omatt', set => $finalImage
, sourcelistset => $sourceListFile
, ppsoswset => $skyImage
, usecat => 'Y'
, catfile => $usnoList
) or return exception();
push( @{$rtn->{skyimgdetails}}
, "$skyImage\|$mode\|$filter\|$duration\|$exp_id\n"
);
my $imgStat = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, format => "ASCII"
, content => "OSW $osw sky image statistics"
);
unless ( &ModuleUtil::isImageEmpty( $skyImage , $imgStat ) )
{
my $gifFile = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => $skyimageoutput->{CONTENT}
, format => 'GIF'
);
my $pngFile = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => $skyimageoutput->{CONTENT}
, format => 'PNG'
);
doCommand(
'implot', set => $skyImage
, device => "$pngFile/PNG"
, withsrclisttab => 'no'
) or return exception();
}
return $rtn;
}
sub process_grism_image
{
my ( %h ) = (@_);
my ($exp_id , $osw , $imFile , $rawImFile , $nphkFile , $phkFile , $windowFile , $prepThFile , $skyimageoutput , $srcoutput , $imgoutput , $mode , $keywords );
($exp_id , $osw , $imFile , $rawImFile , $nphkFile , $phkFile , $windowFile , $prepThFile , $skyimageoutput , $srcoutput , $imgoutput , $mode , $keywords )
= @h{qw( exp_id osw imFile rawImFile nphkFile phkFile windowFile prepThFile skyimageoutput srcoutput imgoutput mode keywords)}
;
my $rtn = { srcdetails => [] , skyimgdetails => []};
doCommand(
'omprep', set => $imFile
, nphset => $nphkFile
, pehset => $phkFile
, wdxset => $windowFile
, outset => $rawImFile
, modeset => 4
)
or return exception();
info("Retrieving FILTER value");
my $filter = readFITSKeyword(
class => 'intermediate'
, file => $rawImFile
, extension => 'PRIMARY'
, keyword => 'FILTER'
);
$filter = __PACKAGE__->getfiltershortname($filter);
info("FILTER = $filter");
$filter = uc($filter);
info("FILTER = $filter");
info("Retrieving EXPOSURE value");
my $duration = readFITSKeyword(
class => 'intermediate'
, file => $rawImFile
, extension => 'PRIMARY'
, keyword => 'EXPOSURE'
);
info("EXPOSURE = $duration");
my $mod8Im = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OSW Modulo 8 Image'
);
my $mod8CorrectedIm = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OSW Mod-8-corrected Image'
);
doCommand(
'ommodmap'
, set => $rawImFile
, mod8product => 'yes'
, mod8set => $mod8Im
, outset => $mod8CorrectedIm
, nsig => 3
, nbox => 16
)
or return exception();
my $finalImage = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM GRISM-ALIGNED IMAGE'
);
doCommand(
'omgprep'
, set => $mod8CorrectedIm
, outset => $finalImage
)
or return exception();
if (0)
{
my $imgStat = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, format => "ASCII"
, content => "Aligned image statistics"
);
if ( !ModuleUtil::isImageEmpty( $finalImage , $imgStat ) )
{
ppd( "000023" );
my $gifFile = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM GRISM-ALIGNED IMAGE'
, format => 'GIF'
);
my $pngFile = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM GRISM-ALIGNED IMAGE'
, format => 'PNG'
);
doCommand(
'implot', set => $finalImage
, device => "$pngFile/PNG"
, withsrclisttab => 'no'
) or warn('implot failed to create an OM GRISM-ALIGNED IMAGE PNG');
}
else
{
ppd( "000024" );
}
}
my $omgwin = readFITSKeyword(
file => $finalImage
, extension => "PRIMARY"
, keyword => "OMGWIN"
);
if ($omgwin =~ /$RE{boolean}{true}/s)
{
ppd( "000021" );
my $omdetectRegionFile = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM GRISM DS9 REGIONS'
, format => "ASCII"
);
my $sourceListFile = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM OSW GRISM SOURCE LIST'
);
doCommand(
'omdetect'
, set => $finalImage
, nsigma => 2.0
, regionfile => $omdetectRegionFile
, outset => $sourceListFile
)
or return exception();
push( @{$rtn->{sourcedetails}}
, "$sourceListFile\|$mode\|$filter\n" );
my $omgrismRegionFile = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM GRISM DS9 SPECTRUM REGIONS'
, format => "ASCII"
);
my $listOfGrismSpectra = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM GRISM SPECTRA LIST'
);
my $omgrismSpectrum = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, content => 'OM GRISM SOURCE SPECTRUM'
);
doCommand(
'omgrism'
, set => $finalImage
, sourcelistset => $sourceListFile
, outset => $omgrismSpectrum
, bkgoffsetleft => 6.0
, bkgwidthleft => -6.0
, bkgoffsetright => 6.0
, bkgwidthright => -6.0
, spectrumhalfwidth => -6.0
, spectrumsmoothlength => 0
, extractionmode => 0
, extractfieldspectra => 'no'
, regionfile => $omdetectRegionFile
, spectraregionfile => $omgrismRegionFile
, outspectralistset => $listOfGrismSpectra
)
or return exception();
if(fileExists(
file => $omgrismSpectrum
) && hasFITSExtension(
file => $omgrismSpectrum
,extension => 'RATE001')
)
{
setExposureProperty( instrument => thisInstrument , exp_id => $exp_id , name => 'ssp' , value => 0+TRUE );
my $tempPlotFile = newFile(
class => 'intermediate'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, format => 'PS'
, content => "OM grism source spectrum"
);
doCommand(
'omgrismplot'
, set => $omgrismSpectrum
, scalebkgplot => 'no'
, binsize => 1
, plotflux => 2
, plotfile => $tempPlotFile
)
or return exception();
my $grismSpectrumPlot = newFile(
class => 'product'
, instrument => thisInstrument
, exp_id => $exp_id
, osw_id => $osw
, 'format' => 'PDF'
, content => "OM GRISM SOURCE SPECTRUM"
);
PStoPDF(
source => $tempPlotFile
, destination => $grismSpectrumPlot
)
or return exception();
}
}
else
{
ppd( "000022" );
}
return $rtn;
}
use vars qw(%Windowdefinition $Tolerance $Window1 $Window2 $Window1min $Window1max $Window2min $Window2max );
%Windowdefinition = (
'976x960' => { '2x2' => 'USER' }
, '480x1792' => { '2x2' => 'USER' }
, '1792x480' => { '2x2' => 'USER' }
, '224x224' => { '1x1' => 'RUDI5_HR' }
, '2048x2048' => { '1x1' => 'FFENG2' }
, '512x2048' => { '1x1' => 'PFENG2' }
, '256x1024' => { '1x1' => 'FUNNY' }
);
$Tolerance = 50;
($Window1 , $Window2) = (1792 , 480);
($Window1min , $Window1max) = ( $Window1 - $Tolerance , $Window1 + $Tolerance);
($Window2min , $Window2max) = ( $Window2 - $Tolerance , $Window2 + $Tolerance);
sub image_format
{
my ( $image, $kw ) = @_;
info("Analysing $image for image identification");
my $windowsize = $kw->{WINDOWDX}.'x'.$kw->{WINDOWDY};
my $naxissize = $kw->{NAXIS1}.'x'.$kw->{NAXIS2};
my $windowbin = $kw->{BINAX1}.'x'.$kw->{BINAX2};
my $mode = (exists $Windowdefinition{$windowsize}{$windowbin}) ? $Windowdefinition{$windowsize}{$windowbin} : 'USER';
if ( ( $mode eq 'USER' ) && ( $kw->{EXP_ID} =~ /4\d\d$/ ) )
{
my $tolerance = 50;
my ( $val1, $val2 ) = ( 1792, 480 );
my ( $dim2, $dim1 ) = sort {$a <=> $b} ($kw->{WINDOWDX} , $kw->{WINDOWDY});
$mode = 'USER'
if ( ( ($dim1 == $Window1) && ($dim2 == $Window2) )
|| ( ( $dim1 > $Window1min ) && ( $dim1 < $Window1max )
&& ( $dim2 > $Window2min ) && ( $dim2 < $Window2max ) )
);
}
if ( $mode eq 'FUNNY' )
{
info("Peculiar case: Could be ENG2 or USER mode. Testing...");
if ( ( $windowsize eq $naxissize ) && ( $kw->{BINBPE} eq 'F' ) )
{
info( "WINDOWDX/Y = NAXIS1/2 and BINBPE = F indicates an PFENG2 component image");
$mode = 'PFENG2';
}
else
{
$mode = 'USER';
}
}
$kw->{MODE} = $mode;
}
sub get_keywords
{
my ($file,$extn) = (shift,shift);
my %keywords = (
EXP_ID => ''
, WINDOWDX => 0
, WINDOWDY => 0
, BINAX1 => 0
, BINAX2 => 0
, BINBPE => 0
, FILTER => 0
, NAXIS1 => 0
, NAXIS2 => 0
);
foreach my $k ( keys(%keywords) )
{
$keywords{$k} = readFITSKeyword(
class => 'odf'
, file => $file
, extension => $extn
, keyword => "$k"
);
}
return %keywords;
}
1;