Changeset 14048 for trunk/ippScripts/scripts/detrend_reject_imfile.pl
- Timestamp:
- Jul 6, 2007, 3:44:38 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_reject_imfile.pl
r14009 r14048 22 22 use IPC::Cmd 0.36 qw( can_run run ); # tools to run UNIX programs with control over I/O 23 23 use PS::IPP::Metadata::Config; # tools to parse the psMetadataConfig files 24 use PS::IPP::Metadata::Stats; 25 24 26 use PS::IPP::Metadata::List qw( parse_md_list ); # tools to parse a metadata into a hash list 25 27 use Statistics::Descriptive; # tools for calculating basic statistical quantities … … 41 43 42 44 # parse the command-line options 43 my ($det_id, $iter, $exp_ tag, $det_type, $camera, $filter, $reject, $dbname, $workdir, $no_update, $no_op);45 my ($det_id, $iter, $exp_id, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $workdir, $reduction, $no_update, $no_op); 44 46 GetOptions( 45 47 'det_id|d=s' => \$det_id, 46 48 'iteration=s' => \$iter, 47 'exp_tag|e=s' => \$exp_tag, 49 'exp_id|e=s' => \$exp_id, 50 'exp_tag|=s' => \$exp_tag, 48 51 'det_type|t=s' => \$det_type, 49 52 'camera=s' => \$camera, … … 52 55 'dbname|d=s' => \$dbname, # Database name 53 56 'workdir|w=s' => \$workdir, # Working directory, for output files 57 'reduction|=s' => \$reduction, 54 58 'no-update' => \$no_update, 55 59 'no-op' => \$no_op, … … 57 61 58 62 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 59 pod2usage( -msg => "Required options: --det_id --iteration --exp_ tag --det_type --camera",63 pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --det_type --camera", 60 64 -exitval => 3) 61 65 unless defined $det_id 62 66 and defined $iter 67 and defined $exp_id 63 68 and defined $exp_tag 64 69 and defined $det_type … … 71 76 $reduction = 'DETREND' unless defined $reduction; 72 77 73 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_RESID ' . uc($det_type); # Recipe to use78 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_RESID_' . uc($det_type)); # Recipe to use 74 79 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1; 75 80 76 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_RESID ' . uc($det_type); # Recipe to use81 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_RESID_' . uc($det_type)); # Recipe to use 77 82 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2; 78 83 … … 82 87 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 83 88 my $STATS = 84 [85 # KEYWORD STATISTIC CHIPTOOL FLAG86 { name => "bg", type => "mean", flag => "-bg" },87 { name => "bg_mean_stdev", type => "stdev", flag => "-bg_mean_stdev" },88 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" },89 { name => "bin_stdev", type => "rms", flag => "-bin_stdev" },90 { name => "fringe_0", type => "mean", flag => "-fringe_0" },91 { name => "fringe_1", type => "rms", flag => "-fringe_1" },92 { name => "fringe_0", type => "stdev", flag => "-fringe_2" },93 { name => "user_1", type => "mean", flag => "-user_1" }, # fringe residual94 { name => "user_2", type => "rms", flag => "-user_2" }, # fringe residual95 { name => "user_3", type => "stdev", flag => "-user_1" }, # fringe residual96 ];89 [ 90 # KEYWORD STATISTIC CHIPTOOL FLAG 91 { name => "bg", type => "mean", flag => "-bg" }, 92 { name => "bg_mean_stdev", type => "stdev", flag => "-bg_mean_stdev" }, 93 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 94 { name => "bin_stdev", type => "rms", flag => "-bin_stdev" }, 95 { name => "fringe_0", type => "mean", flag => "-fringe_0" }, 96 { name => "fringe_1", type => "rms", flag => "-fringe_1" }, 97 { name => "fringe_0", type => "stdev", flag => "-fringe_2" }, 98 { name => "user_1", type => "mean", flag => "-user_1" }, # fringe residual 99 { name => "user_2", type => "rms", flag => "-user_2" }, # fringe residual 100 { name => "user_3", type => "stdev", flag => "-user_1" }, # fringe residual 101 ]; 97 102 98 103 # Look for programs we need … … 106 111 107 112 # Get list of imfile files 108 my $files; # Array of imfile files113 my ($files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf); 109 114 { 110 # dettool command to select imfile data for this exp_ tag111 my $command= "$dettool -residimfile";115 # dettool command to select imfile data for this exp_id 116 $command = "$dettool -residimfile"; 112 117 $command .= " -det_id $det_id"; 113 118 $command .= " -iteration $iter"; 114 $command .= " -exp_ tag $exp_tag";119 $command .= " -exp_id $exp_id"; 115 120 $command .= " -dbname $dbname" if defined $dbname; 116 my( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =121 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 117 122 run(command => $command, verbose => 1); 118 123 unless ($success) { … … 126 131 my $mdcParser = PS::IPP::Metadata::Config->new; 127 132 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 128 &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_ tag, $PS_EXIT_PROG_ERROR);133 &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 129 134 130 135 # parse the file info in the metadata 131 136 $files = parse_md_list($metadata) or 132 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_ tag, $PS_EXIT_PROG_ERROR);137 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 133 138 134 139 # Parse the statistics on the residual image 135 140 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 136 $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);141 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 137 142 } 138 143 … … 162 167 # build the JPEG images 163 168 unless ($no_op) { 164 165 169 # Make the jpeg for binning 1 166 { 167 my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run 168 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 169 run(command => $command, verbose => 1); 170 unless ($success) { 171 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 172 &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code); 173 } 174 &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name); 175 } 170 $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run 171 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 172 run(command => $command, verbose => 1); 173 unless ($success) { 174 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 175 &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code); 176 } 177 &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name); 176 178 177 179 # Make the jpeg for binning 2 178 { 179 my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run 180 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 181 run(command => $command, verbose => 1); 182 unless ($success) { 183 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 184 &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code); 185 } 186 &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name); 187 } 180 $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run 181 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 182 run(command => $command, verbose => 1); 183 unless ($success) { 184 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 185 &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code); 186 } 187 &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name); 188 188 } 189 189 … … 207 207 my $reject_exp_bin_sn = rejection_limit( 'EXP.BIN.SN', $det_type, $filter ); 208 208 209 # storage variables210 211 # load the arrays from the imfile output table212 foreach my $file (@$files) {213 if ($file->{exp_time} > 0.0) {214 push @fluxes, $file->{bg} / $file->{exp_time}; # mean background counts / sec215 } else {216 push @fluxes, $file->{bg};217 }218 }219 220 # Reject based on the stats of the imfiles221 # it is VALID to reject on more than one criterion222 &my_die("Number of means and number of variances differ!", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless scalar @means == scalar @variances;223 224 209 # storage array 225 210 my @fluxes; 226 211 227 for (my $i = 0; $i < scalar @$files; $i++) { 228 my $file = $files[$i]; 212 foreach my $file (@$files) { 229 213 my $name = $file->{class_id}; 230 214 my $mean = $file->{bg}; # Mean for this imfile … … 234 218 235 219 # calculate and save the fluxes 236 my $flux = $mean / $file->{exp_time};220 my $flux; 237 221 if ($file->{exp_time} == 0.0) { 238 push @fluxes, $mean; 222 $flux = $mean; 223 } else { 224 $flux = $mean / $file->{exp_time}; 239 225 } 240 226 push @fluxes, $flux; … … 296 282 # component means is larger than the limit 297 283 if ($reject_imfile_meanstdev > 0) { 298 if ($meanStdev s> $reject_imfile_meanstdev) {284 if ($meanStdev > $reject_imfile_meanstdev) { 299 285 print $logFile "Rejecting exposure based on bad imfile mean stdev for $name: "; 300 286 $reject = 1; … … 302 288 print $logFile "Imfile mean stdev for $name meets requirements: "; 303 289 } 304 print $logFile "$meanStdev svs $reject_imfile_meanstdev\n";290 print $logFile "$meanStdev vs $reject_imfile_meanstdev\n"; 305 291 } else { 306 292 print $logFile "No rejection on imfile mean stdev for $name\n"; … … 479 465 } 480 466 481 my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag";467 $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_id $exp_id"; 482 468 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot "; 483 469 $command .= ' -reject' if $reject; … … 492 478 493 479 unless ($no_update) { 494 my( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =480 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 495 481 run(command => $command, verbose => 1); 496 482 unless ($success) { … … 516 502 my $det_id = shift; # Detrend identifier 517 503 my $iter = shift; # Iteration 518 my $exp_ tag= shift; # Exposure tag504 my $exp_id = shift; # Exposure tag 519 505 my $exit_code = shift; # Exit code to add 520 506 521 507 carp($msg); 522 if ($det_id and $iter and $exp_ tagand not $no_update) {508 if ($det_id and $iter and $exp_id and not $no_update) { 523 509 my $command = "$dettool -addresidexp"; 524 510 $command .= " -det_id $det_id"; 525 511 $command .= " -iteration $iter"; 526 $command .= " -exp_ tag $exp_tag";512 $command .= " -exp_id $exp_id"; 527 513 $command .= " -code $exit_code"; 528 514 $command .= " -dbname $dbname" if defined $dbname;
Note:
See TracChangeset
for help on using the changeset viewer.
