package Subs::XRTReport; ############################################################################## # # DESCRIPTION: This creates an HTML report of XRT exposures. It is largely # DESCRIPTION: a translation of the FITS head/tail HK files. # # HISTORY: # HISTORY: $Log: XRTReport.pm,v $ # HISTORY: Revision 1.11 2005/03/09 16:44:49 apsop # HISTORY: Fix bug in test for INDEF value. # HISTORY: # HISTORY: Revision 1.10 2005/03/07 22:43:56 apsop # HISTORY: Changes to deal with UNDEF values in the input fits files. # HISTORY: # HISTORY: Revision 1.9 2004/10/12 16:24:02 apsop # HISTORY: Calculate unfiltered exposures using summed GTIs # HISTORY: # HISTORY: Revision 1.8 2004/09/05 19:06:21 apsop # HISTORY: Make sure that exposure param values always get initialize to zero. # HISTORY: # HISTORY: Revision 1.7 2004/09/01 14:34:57 apsop # HISTORY: Split up accumulation of lr and pu exposure times. # HISTORY: # HISTORY: Revision 1.6 2004/08/13 14:27:06 apsop # HISTORY: Update Report modules to record exposure information in job.par file. # HISTORY: # HISTORY: Revision 1.5 2004/05/06 20:02:34 dah # HISTORY: Add version number back into the header comments. # HISTORY: # HISTORY: Revision 1.4 2004/04/16 20:21:18 dah # HISTORY: Begin using embedded history records # HISTORY: # # VERSION: 0.0 # # ############################################################################## use Subs::Sub; use Subs::HTMLPage; @ISA = ("Subs::HTMLPage"); use strict; sub new { my $proto=shift; my $file=$proto->filename()->get("report", "xrt"); my $self=$proto->SUPER::new($file, "XRT Exposure Report"); $self->{DESCRIPTION}="Making XRT HTML Exposure Report"; return $self; } ################## # METHODS: ################## ############################################################################## # ############################################################################## sub mode_name { my $self = shift; my $num = shift; if( $num == 1) { return "Null"; } elsif($num == 2) { return "Short Image"; } elsif($num == 3) { return "Long Image"; } elsif($num == 4) { return "Piled Up Photodiode"; } elsif($num == 5) { return "Low Rate Photodiode"; } elsif($num == 6) { return "Windowed Timing"; } elsif($num == 7) { return "PhotonCounting"; } elsif($num == 8) { return "Raw Data"; } elsif($num == 9) { return "Bias Map"; } elsif($num == 10) { return "Stop"; } else { return "Unknown $num"; } } ############################################################################## # ############################################################################## sub data_key { my $self = shift; my $key = join "|", (@_); $key =~ s/ //g; return $key; } ############################################################################## # ############################################################################## sub body { my $self=shift; my $log =$self->log(); my $filename=$self->filename(); my $procpar =$self->procpar(); my $jobpar =$self->jobpar(); my $gtisum=Util::Stool->new("compute_exposure") ->verbose(0); ####################################### # get the exposure report file ####################################### my ($image_expo, $lr_expo, $pu_expo, $pc_expo, $wt_expo) = (0, 0, 0, 0, 0); my ($pu_evt_expo, $lr_evt_expo, $pc_evt_expo, $wt_evt_expo) = (0, 0, 0, 0); my $head_name = $filename->get("hk", "x", "hd", "*"); if ( ! -f $head_name ) { $log->entry("No XRT exposure header FITS file $head_name"); }else{ ######################################## # read the FITS file ######################################## my $head = Util::FITSfile->new($head_name,1); if ( $head->nhdus() <= 1 ){ $log->entry("XRT exposure header FITS file $head_name has no extensions"); } my @start = $head->cols( "TIME")->table(); my @stop = $head->cols("ENDTIME")->table(); my @mode = $head->cols("XRTMode")->table(); ######################### # write the HTML table ######################### $self->begin_table("Start Time", "duration", "Mode"); my $nrows = $head->nrows(); for(my $i=0; $i<$nrows; $i++) { my $old_data = $self->data_key($mode[$i]); my $start = $start[$i]; while($i<$nrows && $self->data_key($mode[$i]) eq $old_data) { $i++; } $i--; my $duration = $stop[$i]; if( $duration eq 'INDEF' || $start eq 'INDEF' ){ $duration = 0; }else{ $duration -= $start; } $self->table_row( $start eq 'INDEF' ? $start : sprintf("%.14g", $start), sprintf("%.1f s", $duration ), $self->mode_name($mode[$i]) ); } $self->end_table(); foreach my $file ($filename->get("unfiltered", "xrt", "*", "*")) { my $mode = ($filename->parse($file, 'unfiltered'))[1]; my $expo += $gtisum->command_line($file."\[GTI\]") ->run() ->stdout(); $pu_expo += $expo if $mode=~/^pu/; $lr_expo += $expo if $mode=~/^lr/; $pc_expo += $expo if $mode=~/^pc/; $wt_expo += $expo if $mode=~/^wt/; } foreach my $file ($filename->get("event", "xrt", "*", "*")) { my $mode = ($filename->parse($file, 'event'))[1]; my $expo += $gtisum->command_line($file."\[GTI\]") ->run() ->stdout(); $pu_evt_expo += $expo if $mode=~/^pu/; $lr_evt_expo += $expo if $mode=~/^lr/; $pc_evt_expo += $expo if $mode=~/^pc/; $wt_evt_expo += $expo if $mode=~/^wt/; } } $jobpar->set({xrt_image => sprintf('%.03f', $image_expo), xrt_unf_piledup => sprintf('%.03f', $pu_expo), xrt_unf_lowrate => sprintf('%.03f', $lr_expo), xrt_unf_windowed => sprintf('%.03f', $wt_expo), xrt_unf_photon => sprintf('%.03f', $pc_expo), xrt_evt_piledup => sprintf('%.03f', $pu_evt_expo), xrt_evt_lowrate => sprintf('%.03f', $lr_evt_expo), xrt_evt_windowed => sprintf('%.03f', $wt_evt_expo), xrt_evt_photon => sprintf('%.03f', $pc_evt_expo) }); } # end of body method