IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 4, 2007, 1:53:22 PM (19 years ago)
Author:
eugene
Message:

extensive changes to use new stats calculation tools; general cleanups

File:
1 edited

Legend:

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

    r13973 r14009  
    1717use PS::IPP::Metadata::Config;
    1818use PS::IPP::Metadata::Stats;
    19 use Data::Dumper;
    2019
    2120use PS::IPP::Config qw($PS_EXIT_SUCCESS
     
    3332use Pod::Usage qw( pod2usage );
    3433
    35 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend,
    36         $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op);
     34my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op);
    3735GetOptions(
    3836    'det_id|d=s'        => \$det_id,
     
    5351
    5452pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    55 pod2usage(
    56     -msg => "Required options: --det_id --iteration --exp_tag --class_id --det_type --camera --input_uri --mode --detrend (not for 'verify' mode)",
    57     -exitval => 3,
    58 ) unless defined $det_id
     53pod2usage( -msg => "Required options: --det_id --iteration --exp_tag --class_id --det_type --camera --input_uri --mode --detrend (not for 'verify' mode)",
     54           -exitval => 3)
     55    unless defined $det_id
    5956    and defined $iter
    6057    and defined $exp_tag
     
    6865$ipprc->define_camera($camera);
    6966
     67# Recipes to use as a function of detrend type and mode
    7068$reduction = 'DETREND' unless defined $reduction;
    7169my $recipe;                     # Name of recipe to use
     
    7876}
    7977$recipe = $ipprc->reduction($reduction, $recipe);
     78
     79# values to extract from output metadata and the stats to calculate
     80my $STATS =
     81   [   
     82       #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
     83       { name => "ROBUST_MEDIAN",      type => "mean",  flag => "-bg" },
     84       { name => "ROBUST_MEDIAN",      type => "stdev", flag => "-bg_mean_stdev" },
     85       { name => "ROBUST_STDEV",       type => "rms",   flag => "-bg_stdev" },
     86       { name => "FRINGE_0",           type => "mean",  flag => "-fringe_0" },
     87       { name => "FRINGE_ERR_0",       type => "rms",   flag => "-fringe_1" },
     88       { name => "FRINGE_0",           type => "stdev", flag => "-fringe_2" },
     89       { name => "FRINGE_RESID_0",     type => "mean",  flag => "-user_1" },
     90       { name => "FRINGE_RESID_ERR_0", type => "rms",   flag => "-user_2" },
     91       { name => "FRINGE_RESID_0",     type => "stdev", flag => "-user_3" },
     92   ];
     93my $BINNED_STATS =
     94   [   
     95       { name => "ROBUST_STDEV",   type => "rms",   flag => "-bin_stdev" },
     96   ];
    8097
    8198# Flags to specify the particular detrend to use
     
    106123
    107124my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detresid.$det_id.$iter", $workdir, $input_uri );
    108 my $outputName = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    109 my $bin1Name =  $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
    110 my $bin2Name =  $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
    111 my $outputStats = $outputRoot . '.' . $class_id . '.stats';
     125
     126my $outputName  = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
     127my $bin1Name    = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
     128my $bin2Name    = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
     129my $outputStats = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id);
    112130
    113131# Run ppImage & ppStats
    114 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    115 my $binnedStats = PS::IPP::Metadata::Stats->new(); # Stats parser
    116132unless ($no_op) {
    117133    my $command = "$ppImage -file $input_uri $outputRoot";
     
    144160    close $statsFile;
    145161
    146     # Parse the statistics on the residual image
     162    # Parse the stats file contents into a metadata
    147163    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    148164    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);
     165
     166    # Parse the statistics on the residual image
     167    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    149168    $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);
    150169
     
    160179    # parse the binned image statistics
    161180    my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     181
     182    my $binnedStats = PS::IPP::Metadata::Stats->new($BINNED_STATS); # Stats parser
    162183    $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);
    163184}
    164185
     186# Command to update the database
     187my $command = "$dettool -addresidimfile";
     188$command .= " -det_id $det_id";
     189$command .= " -iteration $iter";
     190$command .= " -exp_tag $exp_tag";
     191$command .= " -class_id $class_id";
     192$command .= " -recip $recipe";
     193$command .= " -uri $outputName";
     194$command .= " -path_base $outputRoot";
     195$command .= " -dbname $dbname" if defined $dbname;
     196
     197# add in the elements from the selected stats above
     198foreach my $entry (@$STATS @$BINNED_STATS) {
     199    my $value = $entry->{value};
     200    my $flag = $entry->{flag};
     201    $command .= " $flag $value";
     202}
     203
    165204# Add the processed file to the database
    166 # these value must be defined (NAN if not valid), or we raise a programming error
    167 my $bg            = $stats->bg_mean();
    168 my $bg_stdev      = $stats->bg_stdev();
    169 my $bg_mean_stdev = $stats->bg_mean_stdev();
    170 my $bin_stdev     = $binnedStats->bg_stdev();
    171 my $fringe_0      = ${$stats->fringe_mean()}[0];
    172 my $fringe_1      = ${$stats->fringe_err()}[0];
    173 my $fringe_2      = ${$stats->fringe_mean_stdev()}[0];
    174 my $dfringe_0     = ${$stats->dfringe_mean()}[0];
    175 my $dfringe_1     = ${$stats->dfringe_err()}[0];
    176 my $dfringe_2     = ${$stats->dfringe_mean_stdev()}[0];
    177 
    178 print "bg_mean_stdev: " . $bg_mean_stdev . "\n";
    179 print "stats : bg_mean_stdev: " . $stats->bg_mean_stdev() . "\n";
    180 
    181205unless ($no_update) {
    182     my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter";
    183     $command .= " -exp_tag $exp_tag -class_id $class_id";
    184     $command .= " -recip $recipe -uri $outputName -path_base $outputRoot";
    185     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
    186     $command .= " -bin_stdev $bin_stdev";
    187     $command .= " -fringe_0 $fringe_0 -fringe_1 $fringe_1 -fringe_2 $fringe_2";
    188     $command .= " -user_1 $dfringe_0 -user_2 $dfringe_1 -user_3 $dfringe_2";
    189     $command .= " -dbname $dbname" if defined $dbname;
    190 
    191206    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    192207        run(command => $command, verbose => 1);
     
    196211        exit($error_code);
    197212    }
     213} else {
     214    print "skipping command: $command\n";
    198215}
    199216
     
    209226    carp($msg);
    210227    if ($det_id and $iter and $exp_tag and not $no_update) {
    211         my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter -exp_tag $exp_tag -class_id $class_id -code $exit_code";
     228        my $command = "$dettool -addresidimfile";
     229        $command .= " -det_id $det_id";
     230        $command .= " -iteration $iter";
     231        $command .= " -exp_tag $exp_tag";
     232        $command .= " -class_id $class_id";
     233        $command .= " -code $exit_code";
    212234        $command .= " -dbname $dbname" if defined $dbname;
    213235###        system ($command);
Note: See TracChangeset for help on using the changeset viewer.