Changeset 29764
- Timestamp:
- Nov 12, 2010, 3:11:03 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/tools/czartool/Plotter.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/czartool/Plotter.pm
r29752 r29764 18 18 my $class = shift; 19 19 my $self = { 20 _gpc1Db => shift, 20 21 _czarDb => shift, 21 22 _dateFormat => shift, … … 239 240 my $stage = undef; 240 241 my $pendingMinusFaults = undef; 241 my $maxY = 0;242 my $sum;243 242 foreach $stage (@allStages) { 244 243 245 $self->{_czarDb}->countProcessedPendingAndFaults(244 if (!$self->{_czarDb}->countProcessedPendingAndFaults( 246 245 $label, 247 246 $stage, … … 250 249 \$processed, 251 250 \$pending, 252 \$faults) ;251 \$faults)) {next;} 253 252 254 253 $pendingMinusFaults = $pending - $faults; 255 print GNUDAT "$stage $faults $processed, $pendingMinusFaults\n"; 256 my $sum = $faults + $processed + $pendingMinusFaults; 257 if ($sum > $maxY) {$maxY = $sum;} 254 print GNUDAT "$stage $faults $processed $pendingMinusFaults\n"; 258 255 } 259 256 … … 263 260 use FileHandle; 264 261 GP->autoflush(1); 265 266 if ($maxY == 0) {$maxY = 1;}267 else {$maxY = $maxY*1.1;}268 269 262 270 263 if ($self->{_outputFormat} ne "X11") {print GP "set output \"$outputFile\";";} … … 274 267 "set grid;" . 275 268 "set boxwidth;" . 276 "set yrange [\"0\":\"$maxY\"];" .277 269 "set style data histogram;" . 278 270 "set style histogram rowstacked;" . … … 535 527 close GP; 536 528 } 529 530 ########################################################################### 531 # 532 # Generates 3D plot of magic mask fraction for provided exposure ID 533 # 534 ########################################################################### 535 sub plotMagicMaskFractionForThisExposure { 536 my ($self, $exp_id) = @_; 537 538 # set up file stuff 539 my $prefix = $self->{_outputPath} ? $self->{_outputPath} : "."; # TODO should be function for this 540 my $outputFile = "$prefix/czarplot_single_exp_magic_mask_fraction.png"; 541 my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_single_exp_magic_mask_fraction.XXXXX", DIR => '/tmp', SUFFIX => '.dat'); 542 543 my $fracs; 544 if (!$self->{_gpc1Db}->getMagicMaskFraction($exp_id, \$fracs)) {return 0;} 545 546 open (GNUDAT, ">".$tmpFile->filename); 547 548 print GNUDAT "0 0 0.0\n"; 549 foreach my $row ( @{$fracs} ) { 550 551 if (@{$row}[0] =~ m/XY([0-9])([0-9])/) { 552 print GNUDAT "$1 $2 @{$row}[1]\n"; 553 if($1 == 0 && $2 == 6) {print GNUDAT "0 7 0.0\n";} 554 if($1 == 6 && $2 == 7) {print GNUDAT "7 0 0.0\n";} 555 } 556 } 557 print GNUDAT "7 7 0.0\n"; 558 559 560 close(GNUDAT); 561 562 563 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; 564 use FileHandle; 565 GP->autoflush(1); 566 567 my $datFile = $tmpFile->filename; 568 569 if ($self->{_outputFormat} ne "X11") {print GP "set output \"$outputFile\";";} 570 print GP <<PLOT; 571 572 set term $self->{_outputFormat} 573 set title "Magic mask fraction for exposure $exp_id" 574 set grid 575 set size square 576 set xrange [-0.5:7.5] reverse 577 set yrange [-0.5:7.5] 578 unset key 579 set palette rgb 22,13,10 580 set ylabel "Y" 581 set xlabel "X" 582 set cbrange [0:1] 583 set datafile missing "NaN" 584 plot "$datFile" using 1:2:3 with image 585 PLOT 586 587 close GP; 588 589 return 1; 590 } 591 592 593 ########################################################################### 594 # 595 # Plots mask fraction histogram for exposures taken between these dates 596 # 597 ########################################################################### 598 sub plotMagicMaskFractionHistogram { 599 my ($self, $begin, $end) = @_; 600 601 # set up file stuff 602 my $prefix = $self->{_outputPath} ? $self->{_outputPath} : "."; # TODO should be function for this 603 my $histoOutputFile = "$prefix/czarplot_magic_mask_fraction_h.png"; 604 my $distOutputFile = "$prefix/czarplot_magic_mask_fraction_d.png"; 605 my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_magic_mask_fraction.XXXXX", DIR => '/tmp', SUFFIX => 'dat'); 606 607 my $exp_ids = undef; 608 if (!$self->{_gpc1Db}->getProcessedExposures($begin, $end, \$exp_ids)) {return 0;} 609 610 611 # set up bins 612 my %histogram; 613 my @bins; 614 my $interval = 0.05; 615 my $min = 1.0; 616 my $max = 1.0; 617 for (my $n=0.0; $n<$max; $n += $interval){ 618 619 push(@bins, $n); 620 $histogram{$n} = 0; 621 } 622 623 # get mask for each exposure, and bin 624 my $mask = undef; 625 my $expCount = 0; 626 foreach my $row ( @{$exp_ids} ) { 627 628 $mask = $self->{_gpc1Db}->getAverageMagicMaskFraction(@{$row}[0]); 629 630 if (!$mask) {print "can't get value for @{$row}[0]\n";next;} 631 $expCount++; 632 633 foreach my $bin (@bins) { 634 if ($mask <= ($bin+$interval)) { 635 636 $histogram{$bin}++; 637 last; 638 } 639 } 640 } 641 642 # write data to GNUPLOT data file 643 my $totalExp = @{$exp_ids}; 644 print "* Found mask values for $expCount exposures out of $totalExp\n"; 645 open (GNUDAT, ">".$tmpFile->filename); 646 my $accum = 0; 647 my $maxBin = 0; 648 foreach my $bin (@bins) { 649 650 $accum += $histogram{$bin}; 651 if ($histogram{$bin} > $maxBin) {$maxBin = $histogram{$bin};} 652 print GNUDAT "$bin $histogram{$bin} $accum\n"; 653 } 654 close(GNUDAT); 655 656 # now plot 657 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; 658 use FileHandle; 659 GP->autoflush(1); 660 661 $maxBin = $maxBin * 1.1; 662 $accum = $accum * 1.1; 663 664 if ($self->{_outputFormat} ne "X11") {print GP "set output \"$histoOutputFile\";";} 665 print GP 666 "set term $self->{_outputFormat};" . 667 "set title \"Magic mask fraction for $expCount (of $totalExp) exposures between '$begin' and '$end'\";" . 668 "set grid;" . 669 "set boxwidth;" . 670 "set style data histogram;" . 671 "set yrange [0:$maxBin];" . 672 "set style histogram rowstacked;" . 673 "set style fill solid border -1;" . 674 "set ylabel \"Number of Exposures\";" . 675 "set ylabel \"Magic Mask Fraction\";" . 676 "set boxwidth 0.75;" . 677 "set xtic rotate by -90 scale 0;" . 678 "plot '".$tmpFile->filename."' using 2:xtic(1) notitle lt 1;" . 679 "\n"; 680 681 close GP; 682 683 684 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; 685 use FileHandle; 686 GP->autoflush(1); 687 688 if ($self->{_outputFormat} ne "X11") {print GP "set output \"$distOutputFile\";";} 689 print GP 690 "set term $self->{_outputFormat};" . 691 "set title \"Cumulative distribution of magic streaks per image between '$begin' and '$end'\";" . 692 "set yrange [0:$accum];" . 693 "set key left top;" . 694 "set grid xtics;" . 695 "set xlabel \"Magic Mask Fraction\";" . 696 "set ylabel \"Number of Exposures\";" . 697 "set xtic rotate by -90 scale 0;" . 698 "plot " . 699 "'".$tmpFile->filename."' using 1:3 notitle with lines lt 2 lw 2\n"; 700 701 print GP "\n"; 702 close GP; 703 704 return 1; 705 } 537 706 1;
Note:
See TracChangeset
for help on using the changeset viewer.
