Subs::Images (version 0.0)


package Subs::Images;
##############################################################################
#
# DESCRIPTION: Extract transform and plot images
#
# HISTORY: 
# HISTORY: $Log: Images.pm,v $
# HISTORY: Revision 1.10  2005/02/08 14:33:54  apsop
# HISTORY: Just format clean up.
# HISTORY:
# HISTORY: Revision 1.9  2004/08/27 18:39:02  apsop
# HISTORY: Use swiftxform for image transformations.
# HISTORY:
# HISTORY: Revision 1.8  2004/05/06 20:02:34  dah
# HISTORY: Add version number back into the header comments.
# HISTORY:
# HISTORY: Revision 1.7  2004/04/28 13:49:15  dah
# HISTORY: Fix attitude file instrument type.
# HISTORY:
# HISTORY: Revision 1.6  2004/04/16 20:21:18  dah
# HISTORY: Begin using embedded history records
# HISTORY:
#
# VERSION: 0.0
#
#
##############################################################################


use Subs::Sub;
use Util::Xanadu;

@ISA = ("Subs::Sub");
use strict;

sub new {
    my $proto=shift;
    my $self=$proto->SUPER::new();

    $self->{DESCRIPTION}="Extracting, merging and plotting images";

    return $self;
}

##################
# METHODS:
##################

sub body {
    my $self=shift;

    #####################################
    # extract images from the event data
    #####################################
    $self->extract_images();
    $self->image_raw_to_det();
    $self->image_raw_to_sky();
    $self->plot_images();


} # end of body method

###############################################################################
# convert raw coordinate images to sky coordinates
###############################################################################
sub image_raw_to_sky {
    my $self=shift;
    my $inst=shift;

    my $log     =$self->log();
    my $filename=$self->filename();
    my $procpar =$self->procpar();
    my $jobpar  =$self->jobpar();

    $log->entry("Converting raw coordinate images to sky coordinates for $inst");

    ######################################################
    # make sure there is an attitude file
    ######################################################
    my $attitude = $filename->get('attitude', 's');
    unless(-f $attitude) {
        $log->entry("No attitude data available - can't make sky images");
        return;
    }

    ####################################
    # parameters needed for sky coords
    ####################################
    my $swiftxform = Util::HEAdas->new("swiftxform")
          ->is_script(1);

    my $teldef = $filename->fetch_cal('teldef', $inst);
    $swiftxform->params({
			 teldeffile => $teldef,
			 to => 'SKY',
			 attfile => $attitude,
			 ra => $jobpar->read('ra'),
			 dec => $jobpar->read('dec'),
			 aberration => 'no',
			 seed => $procpar->read('seed'),
			 chatter => 4
			});

    ######################
    # loop over files
    ######################
    foreach my $rawFile ($filename->get('corrimage', $inst, '*', '*') ) {

      #########################################
      # determine the SKY coordinate filename
      #########################################
      my $skyFile = $filename->corresponding("corrimage", "skyimage", $rawFile);
      unlink $skyFile;
      $log->entry("converting $rawFile to $skyFile");

	  $swiftxform->params({
             infile   => $rawFile,
             outfile  => $skyFile,
             })
          ->run;

    } # end of loop over files

} # end of image_raw_to_sky method