Changeset 14009 for trunk/ippScripts/scripts/detrend_resid.pl
- Timestamp:
- Jul 4, 2007, 1:53:22 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/detrend_resid.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_resid.pl
r13973 r14009 17 17 use PS::IPP::Metadata::Config; 18 18 use PS::IPP::Metadata::Stats; 19 use Data::Dumper;20 19 21 20 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 33 32 use Pod::Usage qw( pod2usage ); 34 33 35 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend, 36 $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op); 34 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op); 37 35 GetOptions( 38 36 'det_id|d=s' => \$det_id, … … 53 51 54 52 pod2usage( -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 53 pod2usage( -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 59 56 and defined $iter 60 57 and defined $exp_tag … … 68 65 $ipprc->define_camera($camera); 69 66 67 # Recipes to use as a function of detrend type and mode 70 68 $reduction = 'DETREND' unless defined $reduction; 71 69 my $recipe; # Name of recipe to use … … 78 76 } 79 77 $recipe = $ipprc->reduction($reduction, $recipe); 78 79 # values to extract from output metadata and the stats to calculate 80 my $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 ]; 93 my $BINNED_STATS = 94 [ 95 { name => "ROBUST_STDEV", type => "rms", flag => "-bin_stdev" }, 96 ]; 80 97 81 98 # Flags to specify the particular detrend to use … … 106 123 107 124 my $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 126 my $outputName = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id); 127 my $bin1Name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 128 my $bin2Name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 129 my $outputStats = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id); 112 130 113 131 # Run ppImage & ppStats 114 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser115 my $binnedStats = PS::IPP::Metadata::Stats->new(); # Stats parser116 132 unless ($no_op) { 117 133 my $command = "$ppImage -file $input_uri $outputRoot"; … … 144 160 close $statsFile; 145 161 146 # Parse the stat istics on the residual image162 # Parse the stats file contents into a metadata 147 163 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 148 164 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 149 168 $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); 150 169 … … 160 179 # parse the binned image statistics 161 180 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 162 183 $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); 163 184 } 164 185 186 # Command to update the database 187 my $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 198 foreach my $entry (@$STATS @$BINNED_STATS) { 199 my $value = $entry->{value}; 200 my $flag = $entry->{flag}; 201 $command .= " $flag $value"; 202 } 203 165 204 # Add the processed file to the database 166 # these value must be defined (NAN if not valid), or we raise a programming error167 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 181 205 unless ($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 191 206 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 192 207 run(command => $command, verbose => 1); … … 196 211 exit($error_code); 197 212 } 213 } else { 214 print "skipping command: $command\n"; 198 215 } 199 216 … … 209 226 carp($msg); 210 227 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"; 212 234 $command .= " -dbname $dbname" if defined $dbname; 213 235 ### system ($command);
Note:
See TracChangeset
for help on using the changeset viewer.
