Changeset 13722 for trunk/ippScripts/scripts/detrend_reject_imfile.pl
- Timestamp:
- Jun 8, 2007, 12:52:10 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_reject_imfile.pl
r13698 r13722 1 1 #!/usr/bin/env perl 2 3 # this program has two jobs: 4 # 1: for the given exp_tag, generate the binned & mosaiced JPEG images 5 # 2: examine the collection of per-imfile statistics and reject. At the moment, 6 # this program (and the database) only allows rejection at the exposure level, 7 # not at the imfile level. 2 8 3 9 use warnings; … … 13 19 $VERSION = '0.01'; 14 20 15 use IPC::Cmd 0.36 qw( can_run run ); 16 use PS::IPP::Metadata::Config; 17 use PS::IPP::Metadata::List qw( parse_md_list ); 18 use Statistics::Descriptive; 19 use File::Temp qw( tempfile ); 20 21 use PS::IPP::Config qw($PS_EXIT_SUCCESS 21 use IPC::Cmd 0.36 qw( can_run run ); # tools to run UNIX programs with control over I/O 22 use PS::IPP::Metadata::Config; # tools to parse the psMetadataConfig files 23 use PS::IPP::Metadata::List qw( parse_md_list ); # ? 24 use Statistics::Descriptive; # tools for calculating basic statistical quantities 25 use File::Temp qw( tempfile ); # tools to construct temp files 26 use PS::IPP::Config qw($PS_EXIT_SUCCESS 22 27 $PS_EXIT_UNKNOWN_ERROR 23 28 $PS_EXIT_SYS_ERROR … … 27 32 $PS_EXIT_TIMEOUT_ERROR 28 33 caturi 29 ); 34 ); # tools to parse the IPP configuration information 30 35 my $ipprc = PS::IPP::Config->new(); # IPP configuration 31 36 32 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 33 use Pod::Usage qw( pod2usage ); 34 37 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); # option parsing 38 use Pod::Usage qw( pod2usage ); 39 40 # parse the command-line options 35 41 my ($det_id, $iter, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $workdir, $no_update, $no_op); 36 42 GetOptions( … … 58 64 and defined $camera; 59 65 66 # load IPP config information for the specified camera 60 67 $ipprc->define_camera($camera); 61 68 … … 91 98 } 92 99 93 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 100 # Parser for psMetadataConfig files (used for output from dettool) 101 my $mdcParser = PS::IPP::Metadata::Config->new; 94 102 95 103 # Get list of imfile files 96 104 my $files; # Array of imfile files 97 105 { 98 my $command = "$dettool -residimfile -det_id $det_id -iteration $iter -exp_tag $exp_tag"; # Command to run 106 # dettool command to select imfile data for this exp_tag 107 my $command = "$dettool -residimfile"; 108 $command .= " -det_id $det_id"; 109 $command .= " -iteration $iter"; 110 $command .= " -exp_tag $exp_tag"; 99 111 $command .= " -dbname $dbname" if defined $dbname; 100 112 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 105 117 exit($error_code); 106 118 } 107 108 119 # XXX report an error message if stdout_buf is empty 109 120 … … 114 125 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR); 115 126 } 116 117 # XXX in debug mode, unlink = 0118 my ($list1File, $list1Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b1.list.XXXX", UNLINK => 1 );119 my ($list2File, $list2Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b2.list.XXXX", UNLINK => 1 );120 my @means; # Array of means121 my @variances; # Array of variances122 my @binVariances; # Array of binned variances123 my @meanStdevs; # Array of mean stdevs124 my @names; # Array of names (class_id)125 foreach my $file (@$files) {126 print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n");127 print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n");128 push @means, $file->{bg};129 push @meanStdevs, $file->{bg_mean_stdev};130 ## calculate the root-mean-square of the bd_stdevs131 push @variances, $file->{bg_stdev}*$file->{bg_stdev};132 push @binVariances, $file->{bin_stdev}*$file->{bin_stdev};133 push @names, $file->{class_id};134 }135 close $list1File;136 close $list2File;137 127 138 128 # Output products … … 146 136 unless ($no_op) { 147 137 # XXX this will fail if the file exists (because of Nebulous rules) 148 $logFile = $ipprc->file_create_open( $logName ); 149 } 138 $logFile = $ipprc->file_create_append( $logName ); 139 } 140 141 #### build the JPEG images #### 142 143 # XXX in debug mode, unlink = 0 144 my ($list1File, $list1Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b1.list.XXXX", UNLINK => 1 ); 145 my ($list2File, $list2Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b2.list.XXXX", UNLINK => 1 ); 146 foreach my $file (@$files) { 147 print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n"); 148 print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n"); 149 } 150 close $list1File; 151 close $list2File; 150 152 151 153 # Recipes to use in processing … … 183 185 } 184 186 185 my $expected = rejection_limit( 'EXPECTED', $det_type, $filter ); # Expected mean 186 # Rejection thresholds 187 #### measure stats and reject if needed #### 188 189 # Rejection thresholds & related data 190 my $expected = rejection_limit( 'EXPECTED', $det_type, $filter ); 187 191 my $reject_imfile_mean = rejection_limit( 'IMFILE.MEAN', $det_type, $filter ); 192 my $reject_imfile_flux = rejection_limit( 'IMFILE.FLUX', $det_type, $filter ); 188 193 my $reject_imfile_stdev = rejection_limit( 'IMFILE.STDEV', $det_type, $filter ); 189 194 my $reject_imfile_meanstdev = rejection_limit( 'IMFILE.MEANSTDEV', $det_type, $filter ); 190 195 my $reject_imfile_sn = rejection_limit( 'IMFILE.SN', $det_type, $filter ); 196 my $reject_imfile_bin_stdev = rejection_limit( 'IMFILE.BIN.STDEV', $det_type, $filter ); 191 197 my $reject_imfile_bin_sn = rejection_limit( 'IMFILE.BIN.SN', $det_type, $filter ); 192 198 my $reject_exp_mean = rejection_limit( 'EXP.MEAN', $det_type, $filter ); 199 my $reject_exp_flux = rejection_limit( 'EXP.FLUX', $det_type, $filter ); 193 200 my $reject_exp_stdev = rejection_limit( 'EXP.STDEV', $det_type, $filter ); 194 201 my $reject_exp_meanstdev = rejection_limit( 'EXP.MEANSTDEV', $det_type, $filter ); 195 202 my $reject_exp_sn = rejection_limit( 'EXP.SN', $det_type, $filter ); 203 my $reject_exp_bin_stdev = rejection_limit( 'EXP.BIN.STDEV', $det_type, $filter ); 196 204 my $reject_exp_bin_sn = rejection_limit( 'EXP.BIN.SN', $det_type, $filter ); 205 206 # storage variables 207 my @means; # Array of means 208 my @fluxes; # Array of means / exptimes 209 my @variances; # Array of variances 210 my @binVariances; # Array of binned variances 211 my @meanStdevs; # Array of mean stdevs 212 my @names; # Array of names (class_id) 213 214 # load the arrays from the imfile output table 215 foreach my $file (@$files) { 216 push @means, $file->{bg}; # mean background counts 217 if ($file->{exp_time} > 0.0) { 218 push @fluxes, $file->{bg} / $file->{exp_time}; # mean background counts / sec 219 } else { 220 push @fluxes, $file->{bg}; 221 } 222 push @meanStdevs, $file->{bg_mean_stdev}; # stdev of the mean counts (for imfile components) 223 push @variances, $file->{bg_stdev}*$file->{bg_stdev}; # total variance from all imfile components 224 push @binVariances, $file->{bin_stdev}*$file->{bin_stdev}; # total variance of binned images over all imfile components 225 push @names, $file->{class_id}; # name of the component 226 } 197 227 198 228 # Reject based on the stats of the imfiles … … 200 230 &my_die("Number of means and number of variances differ!", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless scalar @means == scalar @variances; 201 231 for (my $i = 0; $i < scalar @means; $i++) { 232 my $flux = $fluxes[$i]; # Flux for this imfile 202 233 my $mean = $means[$i]; # Mean for this imfile 203 234 $mean -= $expected; … … 208 239 last if $no_op; 209 240 241 # reject exposure if, for any imfiles, the mean residual counts 242 # deviate from the expected value by more than N sigma, (sigma = 243 # total pixel variance). this test is sensible for images which 244 # should have a predictable nominal residual mean count value (eg, 245 # 0.0 for a bias). in general, use with ADDITIVE components 210 246 if ($reject_imfile_mean > 0) { 211 247 if (abs($mean) > $reject_imfile_mean * $stdev) { … … 215 251 print $logFile "Imfile mean for $name meets requirements: "; 216 252 } 217 print $logFile "$mean vs $reject_imfile_mean \n";253 print $logFile "$mean vs $reject_imfile_mean * $stdev\n"; 218 254 } else { 219 255 print $logFile "No rejection on imfile mean for $name\n"; 220 256 } 257 258 # reject exposure if, for any imfiles, the mean residual flux 259 # deviates from the expected value by more than N sigma, (sigma = 260 # total pixel variance). this test is sensible for images which 261 # should have a predictable nominal residual flux value (eg, 0.0 262 # for a bias). in general, use with ADDITIVE components 263 if ($reject_imfile_flux > 0) { 264 if (abs($flux) > $reject_imfile_flux) { 265 print $logFile "Rejecting exposure based on bad imfile flux for $name: "; 266 $reject = 1; 267 } else { 268 print $logFile "Imfile flux for $name meets requirements: "; 269 } 270 print $logFile "$flux vs $reject_imfile_flux\n"; 271 } else { 272 print $logFile "No rejection on imfile flux for $name\n"; 273 } 274 275 # reject exposure if, for any imfiles, the total pixel variance is 276 # larger than the limit 221 277 if ($reject_imfile_stdev > 0) { 222 278 if ($stdev > $reject_imfile_stdev) { … … 231 287 print $logFile "No rejection on imfile stdev for $name\n"; 232 288 } 289 290 # reject exposure if, for any imfiles, the variance of the imfile 291 # component means is larger than the limit 233 292 if ($reject_imfile_meanstdev > 0) { 234 293 if ($meanStdevs[$i] > $reject_imfile_meanstdev) { … … 242 301 print $logFile "No rejection on imfile mean stdev for $name\n"; 243 302 } 303 304 # reject exposure if, for any imfiles, the signal-to-noise (ie, 305 # the mean counts / total pixel variance) of the imfile component 306 # means are less than the limit. this test is sensible for images 307 # which have finite residual flux such as a flat-field image. 244 308 if ($reject_imfile_sn > 0) { 245 309 if ($mean < $stdev * $reject_imfile_sn) { … … 253 317 print $logFile "No rejection on imfile S/N for $name\n"; 254 318 } 319 320 # reject exposure if, for any imfiles, the signal-to-noise of the 321 # imfile component means, based on the stdev of the binned image 322 # is less than the limit. this test is sensible for images which 323 # have finite residual flux such as a flat-field image. 324 if ($reject_imfile_bin_stdev > 0) { 325 if ($binStdev > $reject_imfile_bin_stdev) { 326 print $logFile "Rejecting exposure based on bad imfile binned stdev for $name: "; 327 $reject = 1; 328 } else { 329 print $logFile "Imfile binned stdev for $name meets requirements: "; 330 } 331 print $logFile "$binStdev vs $reject_imfile_bin_sn\n"; 332 } else { 333 print $logFile "No rejection on imfile binned stdev for $name\n"; 334 } 255 335 if ($reject_imfile_bin_sn > 0) { 256 336 if ($mean < $binStdev * $reject_imfile_bin_sn) { … … 269 349 my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means 270 350 $meanStats->add_data(@means); 351 my $fluxStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means 352 $fluxStats->add_data(@fluxes); 271 353 my $varianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for variances 272 354 $varianceStats->add_data(@variances); … … 275 357 276 358 my $mean = $meanStats->mean(); # Mean of the imfile means 359 my $flux = $fluxStats->mean(); # Mean of the imfile means 277 360 my $meanStdev = $meanStats->standard_deviation(); # Stdev of the imfile means 278 361 if (not defined $meanStdev) { … … 290 373 print $logFile "Exposure mean $mean, stdev $stdev, mean stdev $meanStdev, exp s/n: $exp_sn\n"; 291 374 375 # reject exposure if the ensemble mean residual counts deviate 376 # from the expected value by more than N sigma, (sigma = total 377 # pixel variance). this test is sensible for images which should 378 # have a predictable nominal residual mean count value (eg, 0.0 379 # for a bias). in general, use with ADDITIVE components 292 380 if ($reject_exp_mean > 0) { 293 381 if (abs($mean) > $reject_exp_mean * $stdev) { 294 print $logFile "Rejecting exposure based on bad mean : ";295 $reject = 1; 296 } else { 297 print $logFile "Exposure mean meets requirements: ";298 } 299 print $logFile "mean: $mean, stdev: $stdev (limit is: %$reject_exp_mean\n";382 print $logFile "Rejecting exposure based on bad mean counts: "; 383 $reject = 1; 384 } else { 385 print $logFile "Exposure mean counts meets requirements: "; 386 } 387 print $logFile "mean: $mean, stdev: $stdev (limit is: $reject_exp_mean\n"; 300 388 } else { 301 389 print $logFile "No rejection for exp mean\n"; 302 390 } 303 # reject if the exposure ensemble stdev is deviant 391 392 # reject exposure if, for any imfiles, the mean residual flux 393 # deviates from the expected value by more than N sigma, (sigma = 394 # total pixel variance). this test is sensible for images which 395 # should have a predictable nominal residual flux value (eg, 0.0 396 # for a bias). in general, use with ADDITIVE components 397 if ($reject_exp_flux > 0) { 398 if (abs($flux) > $reject_exp_flux * $stdev) { 399 print $logFile "Rejecting exposure based on bad mean flux: "; 400 $reject = 1; 401 } else { 402 print $logFile "Exposure mean flux meets requirements: "; 403 } 404 print $logFile "flux: $flux, stdev: $stdev (limit is: $reject_exp_flux\n"; 405 } else { 406 print $logFile "No rejection for exp mean\n"; 407 } 408 409 # reject exposure if the total pixel variance is larger than the 410 # limit 304 411 if ($reject_exp_stdev > 0) { 305 412 if ($stdev > $reject_exp_stdev) { … … 313 420 print $logFile "No rejection for exp stdev\n"; 314 421 } 315 # reject if the exposure ensemble mean stdev is deviant 422 423 # reject exposure if the variance of the imfile means is larger 424 # than the limit 316 425 if ($reject_exp_meanstdev > 0) { 317 426 if ($meanStdev > $reject_exp_meanstdev) { … … 325 434 print $logFile "No rejection for exp mean stdev\n"; 326 435 } 436 327 437 # reject if the signal-to-noise is insufficient 328 438 if ($reject_exp_sn > 0) { … … 336 446 } else { 337 447 print $logFile "No rejection for exp S/N\n"; 448 } 449 # reject if the exposure ensemble stdev is deviant 450 if ($reject_exp_bin_stdev > 0) { 451 if ($binStdev > $reject_exp_bin_stdev) { 452 print $logFile "Rejecting exposure based on bad binned stdev: "; 453 $reject = 1; 454 } else { 455 print $logFile "Exposure binned stdev meets requirements: "; 456 } 457 print $logFile "$stdev vs $reject_exp_bin_stdev\n"; 458 } else { 459 print $logFile "No rejection for exp binned stdev\n"; 338 460 } 339 461 # reject if the signal-to-noise is insufficient
Note:
See TracChangeset
for help on using the changeset viewer.
