Changeset 18460
- Timestamp:
- Jul 9, 2008, 5:28:06 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/detrend_reject_exp.pl (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_reject_exp.pl
r18445 r18460 30 30 my ($det_id, $iter, $det_type, $camera, $outroot, $filter, $dbname, $verbose, $no_update, $no_op); 31 31 GetOptions( 32 'det_id|d=s' => \$det_id,33 'iteration=s' => \$iter,34 'det_type|t=s' => \$det_type,35 'camera=s' => \$camera,36 'outroot|w=s' => \$outroot, # output file base name37 'filter=s' => \$filter,38 'dbname|d=s' => \$dbname, # Database name39 'verbose' => \$verbose, # Print to stdout40 'no-update' => \$no_update,41 'no-op' => \$no_op,32 'det_id|d=s' => \$det_id, 33 'iteration=s' => \$iter, 34 'det_type|t=s' => \$det_type, 35 'camera=s' => \$camera, 36 'outroot|w=s' => \$outroot, # output file base name 37 'filter=s' => \$filter, 38 'dbname|d=s' => \$dbname, # Database name 39 'verbose' => \$verbose, # Print to stdout 40 'no-update' => \$no_update, 41 'no-op' => \$no_op, 42 42 ) or pod2usage( 2 ); 43 43 44 44 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 45 45 pod2usage( -msg => "Required options: --det_id --iteration --det_type --camera --outroot", 46 -exitval => 3) unless 47 defined $det_id and 48 defined $iter and 49 defined $det_type and 46 -exitval => 3) unless 47 defined $det_id and 48 defined $iter and 49 defined $det_type and 50 50 defined $camera and 51 51 defined $outroot; … … 55 55 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 56 56 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 57 my $STATS = 58 [ 57 my $STATS = 58 [ 59 59 # KEYWORD STATISTIC CHIPTOOL FLAG 60 60 { name => "bg", type => "mean", flag => "-bg", dtype => "float" }, … … 66 66 # these stats are used it the rejections but not passed to the database 67 67 # there is some duplication with the above, but the calculation time is minimal 68 my $REJSTATS = 69 [ 68 my $REJSTATS = 69 [ 70 70 # KEYWORD STATISTIC CHIPTOOL FLAG 71 71 { name => "bg", type => "clipmean", flag => "ensMeanMean", dtype => "float" }, … … 84 84 my $missing_tools; 85 85 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1); 86 if ($missing_tools) { 86 if ($missing_tools) { 87 87 warn("Can't find required tools."); 88 exit($PS_EXIT_CONFIG_ERROR); 88 exit($PS_EXIT_CONFIG_ERROR); 89 89 } 90 90 … … 98 98 $command .= " -dbname $dbname" if defined $dbname; 99 99 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 100 run(command => $command, verbose => $verbose);100 run(command => $command, verbose => $verbose); 101 101 unless ($success) { 102 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);103 &my_die("Unable to perform dettool -residexp: $error_code", $det_id, $iter, $error_code);102 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 103 &my_die("Unable to perform dettool -residexp: $error_code", $det_id, $iter, $error_code); 104 104 } 105 105 106 106 # Parse the stdout buffer into a metadata 107 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files107 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 108 108 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 109 &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR);109 &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR); 110 110 111 111 # parse the file info in the metadata 112 112 $exposures = parse_md_list($metadata) or 113 &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR);113 &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR); 114 114 115 115 # Parse the statistics on the residual image … … 122 122 # each image has a mean mean (average of means over all chips) 123 123 # a standard deviation mean (average of standard deviations over all chips) 124 # and a 124 # and a 125 125 126 126 … … 128 128 # we use the statistics of the ensemble to accept/reject exposurs 129 129 my $ensMeanMean = $rejstats->value_for_flag ("ensMeanMean"); # average of all exposure means (in turn averaged over all chips) 130 my $ensMeanStdev = $rejstats->value_for_flag ("ensMeanStdev"); # standard deviation of all exposure means 130 my $ensMeanStdev = $rejstats->value_for_flag ("ensMeanStdev"); # standard deviation of all exposure means 131 131 my $ensMeanStdevMean = $rejstats->value_for_flag ("ensMeanStdevMean"); # average over all exposures of the stdev of the means for each chip 132 132 my $ensMeanStdevStdev = $rejstats->value_for_flag ("ensMeanStdevStdev"); # standard deviation over all exposures of the stdev of the means for each chip 133 my $ensStdevMean = $rejstats->value_for_flag ("ensStdevMean"); # average over all exposures of the sum of the squares of the stdevs for each chip 134 my $ensStdevStdev = $rejstats->value_for_flag ("ensStdevStdev"); # standard deviation over all exposures of the sum of the squares of the stdevs for each chip 133 my $ensStdevMean = $rejstats->value_for_flag ("ensStdevMean"); # average over all exposures of the sum of the squares of the stdevs for each chip 134 my $ensStdevStdev = $rejstats->value_for_flag ("ensStdevStdev"); # standard deviation over all exposures of the sum of the squares of the stdevs for each chip 135 135 136 136 $ipprc->define_camera($camera); … … 155 155 print $logFile "Ensemble mean $ensMeanMean +/- $ensMeanStdev\n"; 156 156 print $logFile "Ensemble stdev $ensStdevMean +/- $ensStdevStdev\n"; 157 print $logFile "Ensemble mean rms (over imfiles) $ensMeanStdevMean +/- $ensMeanStdevStdev\n\n"; 157 print $logFile "Ensemble mean rms (over imfiles) $ensMeanStdevMean +/- $ensMeanStdevStdev\n\n"; 158 158 } 159 159 160 160 # Go through again to do rejection, and update the database for each exposure 161 my $numChanges = 0; # Number of exposures with changed status162 my $numReject = 0; # Number of exposures rejected161 my $numChanges = 0; # Number of exposures with changed status 162 my $numReject = 0; # Number of exposures rejected 163 163 my $firstElement = 1; 164 164 165 165 foreach my $exposure (@$exposures) { 166 my $mean = $exposure->{bg}; # Mean for this exposure166 my $mean = $exposure->{bg}; # Mean for this exposure 167 167 my $stdev = $exposure->{bg_stdev}; # Stdev for this exposure 168 168 my $meanStdev = $exposure->{bg_mean_stdev}; # Stdev of Means for this exposure … … 175 175 &my_die("Unable to find include.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $include; 176 176 177 my $reject = 0; # Reject this exposure?177 my $reject = 0; # Reject this exposure? 178 178 179 179 $command = "$dettool -updateresidexp"; … … 182 182 $command .= " -exp_id $expID"; 183 183 $command .= " -dbname $dbname" if defined $dbname; 184 184 185 185 if (not $accept) { 186 # Rejected this at an earlier stage187 unless ($no_op) {188 print $logFile "Rejecting $expID based on earlier determination.\n";189 }190 $reject = 1;191 goto UPDATE;186 # Rejected this at an earlier stage 187 unless ($no_op) { 188 print $logFile "Rejecting $expID based on earlier determination.\n"; 189 } 190 $reject = 1; 191 goto UPDATE; 192 192 } 193 193 194 194 # Cop-out if we're not doing any operations 195 195 if ($no_op) { 196 # Make sure something gets rejected (just once!), just so that197 # we can trace the full range of the workflow198 if ($firstElement and $iter == 0) {199 $reject = 1;200 }201 goto UPDATE;202 } 203 196 # Make sure something gets rejected (just once!), just so that 197 # we can trace the full range of the workflow 198 if ($firstElement and $iter == 0) { 199 $reject = 1; 200 } 201 goto UPDATE; 202 } 203 204 204 if ($reject_mean > 0 and $ensMeanStdev > 0) { 205 my $delta = abs($mean - $ensMeanMean);206 if ($delta > ($reject_mean * $ensMeanStdev)) {207 print $logFile "Rejecting $expID based on ensemble mean value: ";208 $reject = 1;209 #goto UPDATE;210 } else {211 print $logFile "$expID OK against ensemble mean: ";212 }213 print $logFile "$mean --> $delta vs " . $reject_mean * $ensMeanStdev . "\n";205 my $delta = abs($mean - $ensMeanMean); 206 if ($delta > ($reject_mean * $ensMeanStdev)) { 207 print $logFile "Rejecting $expID based on ensemble mean value: "; 208 $reject = 1; 209 #goto UPDATE; 210 } else { 211 print $logFile "$expID OK against ensemble mean: "; 212 } 213 print $logFile "$mean --> $delta vs " . $reject_mean * $ensMeanStdev . "\n"; 214 214 } else { 215 print $logFile "No rejection of $expID for ensemble mean\n";215 print $logFile "No rejection of $expID for ensemble mean\n"; 216 216 } 217 217 218 218 if ($reject_stdev > 0 and $ensStdevStdev > 0) { 219 my $delta = abs($stdev - $ensStdevMean);220 if ($delta > ($reject_stdev * $ensStdevStdev)) {221 print $logFile "Rejecting $expID based on ensemble stdev: ";222 $reject = 1;223 #goto UPDATE;224 } else {225 print $logFile "$expID OK against ensemble stdev: ";226 }227 print $logFile "$stdev --> $delta sigma vs " . $reject_stdev * $ensStdevStdev . "\n";219 my $delta = abs($stdev - $ensStdevMean); 220 if ($delta > ($reject_stdev * $ensStdevStdev)) { 221 print $logFile "Rejecting $expID based on ensemble stdev: "; 222 $reject = 1; 223 #goto UPDATE; 224 } else { 225 print $logFile "$expID OK against ensemble stdev: "; 226 } 227 print $logFile "$stdev --> $delta sigma vs " . $reject_stdev * $ensStdevStdev . "\n"; 228 228 } else { 229 print $logFile "No rejection of $expID for ensemble stdev\n";230 } 231 229 print $logFile "No rejection of $expID for ensemble stdev\n"; 230 } 231 232 232 if ($reject_meanstdev > 0 and $ensMeanStdevStdev > 0) { 233 my $delta = abs($meanStdev - $ensMeanStdevMean);234 if ($delta > ($reject_meanstdev * $ensMeanStdevStdev)) {235 print $logFile "Rejecting $expID based on ensemble mean stdev: ";236 $reject = 1;237 #goto UPDATE;238 } else {239 print $logFile "$expID OK against ensemble mean stdev: ";240 }241 print $logFile "$meanStdev --> $delta sigma vs " . $reject_meanstdev * $ensMeanStdevStdev. "\n";233 my $delta = abs($meanStdev - $ensMeanStdevMean); 234 if ($delta > ($reject_meanstdev * $ensMeanStdevStdev)) { 235 print $logFile "Rejecting $expID based on ensemble mean stdev: "; 236 $reject = 1; 237 #goto UPDATE; 238 } else { 239 print $logFile "$expID OK against ensemble mean stdev: "; 240 } 241 print $logFile "$meanStdev --> $delta sigma vs " . $reject_meanstdev * $ensMeanStdevStdev. "\n"; 242 242 } else { 243 print $logFile "No rejection of $expID for ensemble mean stdev\n";243 print $logFile "No rejection of $expID for ensemble mean stdev\n"; 244 244 } 245 245 246 246 UPDATE: 247 247 if ($reject) { 248 $command .= ' -reject';249 $numReject++;250 } 251 248 $command .= ' -reject'; 249 $numReject++; 250 } 251 252 252 # Check for status changes 253 253 if ((not $include and not $reject) or ($include and $reject)) { 254 unless ($no_op) {255 print $logFile "Status of $expID has changed.\n";256 }257 $numChanges++;254 unless ($no_op) { 255 print $logFile "Status of $expID has changed.\n"; 256 } 257 $numChanges++; 258 258 } 259 259 260 260 unless ($no_update) { 261 # Update 262 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =263 run(command => $command, verbose => $verbose);264 unless ($success) {265 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);266 &my_die("Unable to perform dettool -updateresidexp: $error_code", $det_id, $iter, $error_code);267 }261 # Update 262 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 263 run(command => $command, verbose => $verbose); 264 unless ($success) { 265 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 266 &my_die("Unable to perform dettool -updateresidexp: $error_code", $det_id, $iter, $error_code); 267 } 268 268 } 269 269 } 270 270 271 271 # Decide if the current is sufficient to use as a master, and if we can stop iterating 272 my $master = 1; # This is good enough for a master273 my $stop = 1; # Stop iterating272 my $master = 1; # This is good enough for a master 273 my $stop = 1; # Stop iterating 274 274 275 275 if ($numChanges > 0) { … … 282 282 $master = 0; 283 283 $stop = 1; 284 carp "All inputs rejected!\n"; 284 285 } 285 286 … … 290 291 } 291 292 293 # Allow iteration to be turned off 294 my $allow_iter = metadataLookupBool($ipprc->{rejection}, "ITERATION"); # Allow iteration? 295 my $force_master = metadataLookupBool($ipprc->{rejection}, "MASTER"); # Force the stack to be accepted 296 $stop = 1 unless $allow_iter; 297 $master = 1 if $force_master and $stop; 298 292 299 # attempt to prevent endless, pathological iterations 293 300 if ($iter >= $ITER_LIMIT) { … … 295 302 exit($PS_EXIT_PROG_ERROR); 296 303 } 297 298 # Allow iteration to be turned off299 my $allow_iter = metadataLookupBool($ipprc->{rejection}, "ITERATION"); # Allow iteration?300 my $force_master = metadataLookupBool($ipprc->{rejection}, "MASTER"); # Force the stack to be accepted301 $stop = 1 unless $allow_iter;302 $master = 1 if $force_master;303 304 304 305 305 ## add the summary statistics, and request a new iteration if needed … … 310 310 $command .= " -dbname $dbname" if defined $dbname; 311 311 ### XXX WE NEED to make this a recipe-driven option 312 $command .= " -again" unless $stop; 312 $command .= " -again" unless $stop; 313 313 $command .= $stats->cmdflags(); 314 314 … … 316 316 unless ($no_update) { 317 317 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 318 run(command => $command, verbose => $verbose);318 run(command => $command, verbose => $verbose); 319 319 unless ($success) { 320 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);321 warn("Unable to perform dettool -adddetrunsummary: $error_code");322 exit($error_code);320 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 321 warn("Unable to perform dettool -adddetrunsummary: $error_code"); 322 exit($error_code); 323 323 } 324 324 } else { … … 337 337 { 338 338 my $msg = shift; # Warning message on die 339 my $det_id = shift; # Detrend identifier340 my $iter = shift; # Iteration339 my $det_id = shift; # Detrend identifier 340 my $iter = shift; # Iteration 341 341 my $exit_code = shift; # Exit code to add 342 342 343 343 carp($msg); 344 344 if (defined $det_id and defined $iter and not $no_update) { 345 my $command = "$dettool -adddetrunsummary";346 $command .= " -det_id $det_id";347 $command .= " -iteration $iter";348 $command .= " -code $exit_code";349 $command .= " -dbname $dbname" if defined $dbname;345 my $command = "$dettool -adddetrunsummary"; 346 $command .= " -det_id $det_id"; 347 $command .= " -iteration $iter"; 348 $command .= " -code $exit_code"; 349 $command .= " -dbname $dbname" if defined $dbname; 350 350 system ($command); 351 351 } … … 356 356 sub rejection_limit 357 357 { 358 my $name = shift; # Rejection limit to359 my $type = shift; # Type of exposure360 my $filter = shift; # Filter358 my $name = shift; # Rejection limit to 359 my $type = shift; # Type of exposure 360 my $filter = shift; # Filter 361 361 362 362 my $value = $ipprc->rejection( $name, $det_type, $filter ); 363 363 if (not defined $value) { 364 $filter = "(no filter)" unless defined $filter;365 die "Unable to determine $name rejection limit for $det_type with $filter.\n";364 $filter = "(no filter)" unless defined $filter; 365 die "Unable to determine $name rejection limit for $det_type with $filter.\n"; 366 366 } 367 367
Note:
See TracChangeset
for help on using the changeset viewer.
