package Subs::UvotGraspCorr;
##############################################################################
#
# DESCRIPTION: Apply uvotgraspcorr
#
# HISTORY: $Log: UvotGraspCorr.pm,v $
# HISTORY: Revision 1.8 2013/08/14 07:06:29 apsop
# HISTORY: Added the VERSION comment, which lets comN.N/tools/doc
# HISTORY: create the HTML documentation for this file.
# HISTORY:
# HISTORY: Revision 1.7 2013/08/13 19:38:01 apsop
# HISTORY: Handle the case of having ONLY grism data..
# HISTORY:
# HISTORY: Revision 1.6 2013/07/16 07:27:23 apsop
# HISTORY: Rename the resulting grism aspect correction HDU to GRASPCORR,
# HISTORY: so it's different than the non-grism correction's (ASPCORR).
# HISTORY:
# HISTORY: Revision 1.5 2012/01/12 06:52:03 apsop
# HISTORY: Changes going to proc3.15.03
# HISTORY:
#
# VERSION: $Revision: 1.8 $
#
##############################################################################
use Subs::Sub;
use Util::GTIfile;
use Util::SWCatalogue;
use Util::FITSfile;
@ISA = ("Subs::Sub");
use strict;
sub new {
my $proto=shift;
my $self=$proto->SUPER::new();
$self->{DESCRIPTION}="Apply uvotgraspcorr";
return $self;
}
##################
# METHODS:
##################
sub body {
my $self=shift;
my $log =$self->log();
my $filename=$self->filename();
my $jobpar =$self->jobpar();
#########################
# Apply uvotgraspcorr
#########################
$self->apply_uvot_grasp_corr();
} # end of body method
#############################################################################
# Apply uvotgraspcorr
#############################################################################
sub apply_uvot_grasp_corr {
my $self=shift;
my $log =$self->log();
my $filename=$self->filename();
my $jobpar=$self->jobpar();
my $procpar =$self->procpar();
my $corrfile = $filename->get('hk', 'u', 'ac', 0);
if(! $corrfile ){
$log->error(1, "unable to determine UVOT aspect corr file, bailing");
return ;
}
my @infile1=$filename->get('detimage', 'uvot','*', '*');
if(! @infile1 ){
$log->error(1, "no UVOT detimage files to process");
return ;
}
my $infile=join(",",@infile1);
# switch the first catspec for grism processing
my @parspec = split(/,/, $procpar->read('starcatalog'));
my (undef, $dir) = File::Basename::fileparse($parspec[0]);
my $grismspec = "$dir/usnob1.grism";
my $catspec = join(',', $grismspec, $parspec[1]);
my $uvotgraspcorr=Util::HEAdas->new("uvotgraspcorr")->is_script( 1 );
$uvotgraspcorr->params({
infile => $infile,
catspec => $catspec,
starid => 'NONE',
distfile => 'DEFAULT',
chatter => 5,
history => 'yes',
clobber => 'yes',
outfile => "uac.hk",
cleanup => 'yes'#,
});
$uvotgraspcorr->run();
if (-e 'uac.hk' ) {
if (-e $corrfile) {
my $append = Util::HEAdas->new('ftappend');
$append->params({infile => "uac.hk[1][col #EXTNAME='GRASPCORR']",
outfile => $corrfile})
->run();
} else {
# rename the grism aspect corrections and update EXTNAME
if (rename('uac.hk', $corrfile)) {
my $tmp = Util::FITSfile->new($corrfile, 1);
$tmp->keyword('EXTNAME', 'GRASPCORR');
} else {
$log->(1, "unable to rename grism aspect corrections to $corrfile: $!");
}
}
} else {
$log->error(1, "uvotgraspcorr output file uac.hk does not exist");
}
} # end of apply_uvot_grasp_corr