IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30955


Ignore:
Timestamp:
Mar 17, 2011, 4:28:59 PM (15 years ago)
Author:
rhenders
Message:

can now create rate histograms or line plots

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czartool/Plotter.pm

    r30918 r30955  
    146146#
    147147###########################################################################
    148 sub createRateTimeSeries {
    149     my ($self, $label, $selectedStage, $beginTime, $endTime, $interval) = @_;
     148sub createRatePlot {
     149    my ($self, $label, $selectedStage, $beginTime, $endTime, $interval, $histogram, $timeSeries) = @_;
    150150
    151151    # stages
     
    164164    my $stage = undef;
    165165    my $gnuplotFile = undef;
    166     my $outputFile = createImageFileName($self, $label, $selectedStage, "r", 0);
     166    my $minX = 999999999;     
     167    my $maxX = -9999999999;
     168    my $timeDiff = 0;
     169
     170    foreach $stage (@{$stages}) {
     171
     172        if ($self->{_czarDb}->createProcessingRateData(
     173                    $stage,
     174                    $label,
     175                    $beginTime,
     176                    $endTime,
     177                    $interval,
     178                    \$gnuplotFile,
     179                    \$minX, \$maxX, \$timeDiff)) {
     180
     181            $gnuplotFiles{$stage} = $gnuplotFile;
     182            #print "$minX, $maxX, $timeDiff\n";
     183        }
     184    }
     185
     186    if ($histogram) {
     187
     188        my $outputFile = createImageFileName($self, $label, $selectedStage, "rh", 0);
     189        $self->plotRateStackedHistogram(\%gnuplotFiles, $outputFile, $label, $selectedStage, $beginTime, $endTime, $interval);
     190    }
     191    if ($timeSeries) {
     192
     193        my $outputFile = createImageFileName($self, $label, $selectedStage, "rt", 0);
     194        $self->plotTimeSeries(\%gnuplotFiles, $outputFile, $label, $beginTime, $endTime, $maxX, $minX, $timeDiff, "", "Exposures processed per $interval");
     195    }
     196
     197    # now delete temp dat files
     198    foreach my $stage (keys %gnuplotFiles) {unlink($gnuplotFiles{$stage});}
     199
     200    return 1;
     201}
     202
     203###########################################################################
     204#
     205# Plots a stacked histogram of rate data for one or more stages
     206#
     207###########################################################################
     208sub plotRateStackedHistogram {
     209    my ($self, $gnuplotFiles, $outputFile, $label, $selectedStage, $beginTime, $endTime, $interval) = @_;
     210
    167211    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
    168212    use FileHandle;
     
    173217    print GP
    174218        "set term $self->{_outputFormat};" .
    175         "set title \"'$label', '$selectedStage'\\nFrom '$beginTime' to '$endTime' HST\";" .
     219        "set title \"'$label' for '$selectedStage'\\nFrom '$beginTime' to '$endTime' HST\";" .
    176220        "set boxwidth;" .
    177221        "set xtic rotate by -90 scale 0;" .
     
    184228
    185229    my $first = 1;
    186     foreach $stage (@{$stages}) {
    187 
    188         if ($self->{_czarDb}->createProcessingRateData(
    189                     $stage,
    190                     $label,
    191                     $beginTime,
    192                     $endTime,
    193                     $interval,
    194                     \$gnuplotFile)) {
    195 
    196             $gnuplotFiles{$stage} = $gnuplotFile;
    197 
    198             if (!$first) { print GP ","; }
    199             print GP "'$gnuplotFile' using 2:xtic(1) title \"$stage\" ";
    200             $first = 0;
    201         }
     230    foreach my $stage (@allStages) {
     231
     232
     233        if(!$gnuplotFiles->{$stage}) {next;}
     234
     235        if (!$first) { print GP ","; }
     236        print GP "'" . $gnuplotFiles->{$stage}. "' using 4:xtic(1) title \"$stage\" ";
     237        $first = 0;
    202238    }
    203239
    204240    print GP ";\n";
    205241    close GP;
    206 
    207     # now delete temp dat files
    208     foreach my $stage (keys %gnuplotFiles) {unlink($gnuplotFiles{$stage});}
    209242
    210243    return 1;
     
    265298
    266299    my $outputFile = createImageFileName($self, $label, $selectedStage, "t", $isLog);
     300    my $yTitle;
     301    if ($isLog) {$yTitle = "Log(Exposures)";}
     302    elsif ($deriv) {$yTitle = "dExposures/dTime(secs)";}
     303    else {$yTitle = "Exposures";}
    267304    $self->plotTimeSeries(
    268305            \%gnuplotFiles,
     
    274311            $minX,
    275312            $timeDiff,
    276             $isLog,
    277             $deriv);
     313            "",
     314            $yTitle);
    278315}                                                   
    279316
     
    365402###########################################################################
    366403#
    367 # Figures out suitable spacing for time tics on time-series pliots
     404# Figures out suitable spacing for time tics on time-series plots
    368405#
    369406###########################################################################
     
    427464###########################################################################
    428465sub plotTimeSeries {
    429     my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $timeDiff, $isLog, $isDeriv) = @_;
     466    my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $timeDiff, $title, $yTitle) = @_;
    430467
    431468    my $timeFormat = undef;
    432469    my $divX = undef;
    433     my $yTitle = undef;
    434     if ($isLog) {$yTitle = "Log( Exposures )";}
    435     elsif ($isDeriv) {$yTitle = "dExposures/dTime(secs)";}
    436     else {$yTitle = "Exposures";}
     470    #my $yTitle = undef;
     471    #if ($isLog) {$yTitle = "Log( Exposures )";}
     472    #elsif ($isDeriv) {$yTitle = "dExposures/dTime(secs)";}
     473    #else {$yTitle = "Exposures";}
    437474
    438475    $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat);
     
    441478
    442479    # sort out plot title
    443     my $title = "";
    444     if ($isDeriv) {$title .= "First derivatives of "}
     480    #my $title = "";
     481    #if ($isDeriv) {$title .= "First derivatives of "}
    445482    if ($numOfPlots == 1) {foreach my $stage (keys %$gnuplotFiles) {$title .= "'".$stage."'";}}
    446483    else {$title .= "'all stages'"}
     
    462499        "set xtics \"$minX\", $divX, \"$maxX\";" .
    463500        "set grid xtics;" .
     501        "set grid ytics;" .
    464502        "set xlabel \"Time\";" .
    465503        "set ylabel \"$yTitle\";" .
Note: See TracChangeset for help on using the changeset viewer.