package Subs::NominalPointing; ############################################################################## # # DESCRIPTION: Determine the mean pointing for the observation. # DESCRIPTION: This subroutine first merges all attitude files into a # DESCRIPTION: single file. It then runs the aspect FTOOL to calculate the # DESCRIPTION: mean pointing. It applies an instrument to spacecraft mean # DESCRIPTION: alignment file if there is one. # DESCRIPTION: The result is a set of Euler angles giving the mean spacecraft # DESCRIPTION: orientation, and a set of RA, Dec and Roll giving the mean # DESCRIPTION: instrument pointing as offset by the alignment file. # DESCRIPTION: The subroutine next calculates the galactic coordinates # DESCRIPTION: corresponding to the mean instrument RA, Dec and Roll. # DESCRIPTION: All of this information is logged and stored in the # DESCRIPTION: job.par file. # # HISTORY # HISTORY: $Log: NominalPointing.pm,v $ # HISTORY: Revision 1.2 2006/08/01 20:35:34 apsop # HISTORY: Add in CVS history indicator. # HISTORY: # HISTORY: 2.1 -> 3.0 2002-09-04 # HISTORY: Created this common subroutine from the ASCA-specific Aspecting.pm # HISTORY: module version 2.1. This was done by stipping out the ASCA-specific # HISTORY: "fixing" code and putting in a way to configure the file types. # # HISTORY: 3.0 -> 3.1 2003-08-21 # HISTORY: aspect tool has been moved to HEADAS, so call it from there now. # # VERSION: 3.1 # ############################################################################## use Subs::Sub; @ISA = ("Subs::Sub"); use strict; sub new { my $proto=shift; my $self=$proto->SUPER::new(); $self->{DESCRIPTION}="Determine nominal pointing"; #################################################### # default file types for attitude file and # mean alignment file. These may be overridden # by subclasses. If there is no alignment file, # then you should set the ALIGNMENT_TYPE to "none" #################################################### $self->{ATTITUDE_TYPE}="attitude"; $self->{ALIGNMENT_TYPE}="alignment"; return $self; } ################ # METHODS: ################ ############################################################################# # this body method just calls determine_pointing # subclasses may override this to do other things ############################################################################# sub body { my $self=shift; $self->determine_pointing(); } ############################################################################# # determine the nominal pointing after merging all attitude files ############################################################################# sub determine_pointing { my $self=shift; my $gtis = shift || "none"; my $log =$self->log(); my $filename=$self->filename(); my $procpar =$self->procpar(); my $jobpar =$self->jobpar(); $log->entry("Determining nominal pointing"); my $attitude = $self->{ATTITUDE_TYPE}; my $alignment = $self->{ALIGNMENT_TYPE}; ######################################## # get a list of all the attitude files ######################################## my @attfiles=$filename->any($attitude); unless(@attfiles) { $log->entry("No attitude data available"); return; } ##################################################### # merge the attitude files if there is more than one ##################################################### my $tmp_file="merged_attitude.tmp"; my $merged=Util::FITSlist->new(@attfiles) ->merge($tmp_file); ################################################# # calculate the aspect point ################################################# my $alignfile; if($alignment ne "none") { $alignfile=$filename->fetch_cal($alignment); } else { $alignfile = "none"; } my $aspect=Util::HEAdas->new("aspect") ->params({attfile => $merged, alignfile => $alignfile, gtis => $gtis, nbins => 100, binsize => 0.01}) ->run(); my $euler1=0.0; my $euler2=0.0; my $euler3=0.0; my $ra=0.0; my $dec=0.0; my $roll=0.0; unless($aspect->had_error() ) { ############################################# # read the results from the aspect par file ############################################# $euler1=$aspect->parfile()->read("euler1"); $euler2=$aspect->parfile()->read("euler2"); $euler3=$aspect->parfile()->read("euler3"); if($euler2==180. || $euler2 == 0. && $euler1 =~ /^NaN$/i ) { $euler1=0.; } $ra =$aspect->parfile()->read("ra" ); $dec =$aspect->parfile()->read("dec" ); $roll=$aspect->parfile()->read("roll"); if($dec == 90. || $dec == -90. && $ra =~ /^NaN$/i ) { $ra = 0.; } } ############################################# # convert to galactic coordinates ############################################# my $stools=$procpar->read("stools"); my ($glon, $glat) = split /\s+/, Util::Tool->new($stools,"ecl2gal") ->verbose(0) ->command_line("$ra $dec") ->run() ->stdout(); #################################################### # log the results and write them to the jobpar file #################################################### $log->entry("Nominal spacecraft Euler angles: ". "Phi=$euler1 Theta=$euler2 Psi=$euler3"); $log->entry("Nominal telescope pointing: ". "R.A.=$ra Dec=$dec Roll Angle=$roll"); $log->entry("Galactic Coordinates: ". "Lii=$glon Bii=$glat"); $jobpar->set({euler1 => $euler1, euler2 => $euler2, euler3 => $euler3, ra => $ra, dec => $dec, roll => $roll, glon => $glon, glat => $glat }); unlink $tmp_file; } # end of body method