IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13618


Ignore:
Timestamp:
Jun 4, 2007, 2:25:37 PM (19 years ago)
Author:
eugene
Message:

calculate and supply the binned stdev

Location:
trunk/ippScripts/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/detrend_reject_imfile.pl

    r13590 r13618  
    120120my @means;                      # Array of means
    121121my @variances;                  # Array of variances
     122my @binVariances;               # Array of binned variances
    122123my @meanStdevs;                 # Array of mean stdevs
    123124my @names;                      # Array of names (class_id)
     
    129130    ## calculate the root-mean-square of the bd_stdevs
    130131    push @variances, $file->{bg_stdev}*$file->{bg_stdev};
     132    push @binVariances, $file->{bin_stdev}*$file->{bin_stdev};
    131133    push @names, $file->{class_id};
    132134}
     
    180182my $reject_imfile_meanstdev = rejection_limit( 'IMFILE.MEANSTDEV', $det_type, $filter );
    181183my $reject_imfile_sn        = rejection_limit( 'IMFILE.SN',        $det_type, $filter );
     184my $reject_imfile_bin_sn    = rejection_limit( 'IMFILE.BIN.SN',    $det_type, $filter );
    182185my $reject_exp_mean         = rejection_limit( 'EXP.MEAN',         $det_type, $filter );
    183186my $reject_exp_stdev        = rejection_limit( 'EXP.STDEV',        $det_type, $filter );
    184187my $reject_exp_meanstdev    = rejection_limit( 'EXP.MEANSTDEV',    $det_type, $filter );
    185188my $reject_exp_sn           = rejection_limit( 'EXP.SN',           $det_type, $filter );
     189my $reject_exp_bin_sn       = rejection_limit( 'EXP.BIN.SN',       $det_type, $filter );
    186190
    187191my $logName = caturi( $workdir, "$exp_tag.detreject.$det_id.$iter.log" ); # Name for log
     
    199203    $mean -= $expected;
    200204    my $stdev = sqrt($variances[$i]);   # Stdev for this imfile
     205    my $binStdev = sqrt($binVariances[$i]);     # Stdev for this imfile
    201206    my $name = $names[$i];
    202207
     
    247252    } else {
    248253        print $logFile "No rejection on imfile S/N for $name\n";
     254    }
     255    if ($reject_imfile_bin_sn) {
     256        if ($mean < $binStdev * $reject_imfile_bin_sn) {
     257            print $logFile "Rejecting exposure based on bad imfile binned S/N for $name: ";
     258            $reject = 1;
     259        } else {
     260            print $logFile "Imfile binned S/N for $name meets requirements: ";
     261        }
     262        print $logFile "mean: $mean vs binStdev*SNlimit: " . $binStdev * $reject_imfile_bin_sn . "\n";
     263    } else {
     264        print $logFile "No rejection on imfile binned S/N for $name\n";
    249265    }
    250266}
     
    255271my $varianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for variances
    256272$varianceStats->add_data(@variances);
     273my $binVarianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for variances
     274$binVarianceStats->add_data(@binVariances);
    257275
    258276my $mean = $meanStats->mean();  # Mean of the imfile means
     
    263281}
    264282my $stdev = sqrt($varianceStats->mean()); # Root-Mean-Square of the imfile stdevs (root mean of variances)
     283my $binStdev = sqrt($binVarianceStats->mean()); # Root-Mean-Square of the imfile stdevs (root mean of variances)
    265284my $exp_sn = 0.0;
    266285if ($stdev > 0) { $exp_sn = $mean / $stdev; }
     
    318337        print $logFile "No rejection for exp S/N\n";
    319338    }
     339    # reject if the signal-to-noise is insufficient
     340    if ($reject_exp_bin_sn) {
     341        if (abs($mean) < abs($binStdev * $reject_exp_bin_sn)) {
     342            print $logFile "Rejecting exposure based on poor binned S/N: \n";
     343            $reject = 1;
     344        } else {
     345            print $logFile "Exposure binned S/N meets requirements: \n";
     346        }
     347        print $logFile "signal: $mean vs noise: $binStdev (s/n limit is: $reject_exp_bin_sn)\n";
     348    } else {
     349        print $logFile "No rejection for exp binned S/N\n";
     350    }
    320351
    321352    close $logFile;
     
    326357my $bg_stdev = $stdev;
    327358my $bg_mean_stdev = $meanStdev;
     359my $bin_stdev = $binStdev;
    328360
    329361unless ($no_update) {
    330362    my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag";
    331363    $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot ";
    332     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
     364    $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev -bin_stdev $bin_stdev";
    333365    $command .= ' -reject' if $reject;
    334366    $command .= " -dbname $dbname" if defined $dbname;
  • trunk/ippScripts/scripts/detrend_resid.pl

    r13552 r13618  
    105105my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    106106my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
     107my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
    107108if ($missing_tools) {
    108109    warn("Can't find required tools.");
     
    123124my $bin2Name =  $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
    124125my $outputStats = $outputRoot . '.' . $class_id . '.stats';
     126my $outputBinnedStats = $outputRoot . '.' . $class_id . '.bin.stats';
    125127
    126128# Run ppImage
    127129my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
     130my $binnedStats = PS::IPP::Metadata::Stats->new(); # Stats parser
    128131unless ($no_op) {
    129132    my $command = "$ppImage -file $input_uri $outputRoot -recipe PPIMAGE $recipe" .
     
    154157    close $statsFile;
    155158    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    156     my $metadata = $mdcParser->parse(join "", @contents) or
    157         &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    158     $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
     159    my $metadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     160    # $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    159161    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     162
     163    # run ppStats on the binned image
     164    $command = "$ppStats $bin2Name $outputBinnedStats";
     165    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     166        run(command => $command, verbose => 1);
     167
     168    unless ($success) {
     169        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     170        &my_die("Unable to perform ppStats: $error_code", $det_id, $iter, $exp_tag, $class_id, $error_code);
     171    }
     172
     173    &my_die("Couldn't find expected output file: $outputBinnedStats", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBinnedStats);
     174
     175    open $statsFile, $ipprc->file_resolve($outputBinnedStats) or &my_die("Can't open statistics file $outputBinnedStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
     176    @contents = <$statsFile>; # Contents of file
     177    close $statsFile;
     178    my $binnedMetadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     179    # $binnedStats = PS::IPP::Metadata::Stats->new(); # Stats parser
     180    $binnedStats->parse($binnedMetadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    160181}
    161182
     
    164185my $bg_stdev = ($stats->bg_stdev() or 'NAN');
    165186my $bg_mean_stdev = ($stats->bg_mean_stdev() or 'NAN');
     187my $bin_stdev = ($binnedStats->bg_stdev() or 'NAN');
    166188
    167189unless ($no_update) {
    168     my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter -exp_tag $exp_tag " .
    169         "-class_id $class_id -recip $recipe -uri $outputName -path_base $outputRoot"; # Command to run dettool
     190    my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter";
     191    $command .= " -exp_tag $exp_tag -class_id $class_id";
     192    $command .= " -recip $recipe -uri $outputName -path_base $outputRoot";
    170193    $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
     194    $command .= " -bin_stdev $bin_stdev";
    171195    $command .= " -dbname $dbname" if defined $dbname;
    172196
     
    179203    }
    180204}
    181 
    182 
    183205
    184206sub my_die
Note: See TracChangeset for help on using the changeset viewer.