Changeset 8612
- Timestamp:
- Aug 25, 2006, 3:18:17 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_reject_imfile.pl
r8507 r8612 7 7 use PS::IPP::Metadata::Config; 8 8 use PS::IPP::Metadata::List qw( parse_md_list ); 9 use Statistics::Descriptive; 9 10 use Data::Dumper; 10 11 … … 21 22 # This measures how close it is to what's expected 22 23 use constant REJECT_INDIVIDUAL_MEAN => { 23 'bias' => 0.01, # Should be fairly flat; some CRs24 'dark' => 0.05, # Lots of CRs24 'bias' => 5, # Should be fairly flat; some CRs 25 'dark' => 10, # Lots of CRs 25 26 'flat' => undef # Can't define expected value (depends on exposure level) 26 27 }; … … 29 30 # This measures how much variation there is in each component 30 31 use constant REJECT_INDIVIDUAL_STDEV => { 31 'bias' => 0.1, # Should be fairly flat; some CRs32 'dark' => 0.5, # Lots of CRs33 'flat' => 100 # Stars and galaxies32 'bias' => 10, # Should be fairly flat; some CRs 33 'dark' => 100, # Lots of CRs 34 'flat' => 1000 # Stars and galaxies 34 35 }; 35 36 … … 37 38 # This measures how close it is to what's expected 38 39 use constant REJECT_SAMPLE_MEAN => { 39 'bias' => 0.01, # Should be little variation between chips40 'dark' => 0.05, # Could be some glow on some chips40 'bias' => 10, # Should be little variation between chips 41 'dark' => 100, # Could be some glow on some chips 41 42 'flat' => undef # Can't define expected value (depends on exposure level) 42 43 }; … … 45 46 # This measures how much variation there is across the components 46 47 use constant REJECT_SAMPLE_STDEV => { 47 'bias' => 0.1, # Should be little variation between chips48 'dark' => 0.5, # Could be some glow on some chips49 'flat' => 10 # Could be features on some chips, but all should be about the same48 'bias' => 10, # Should be little variation between chips 49 'dark' => 100, # Could be some glow on some chips 50 'flat' => 500 # Could be features on some chips, but all should be about the same 50 51 }; 51 52 … … 71 72 my $files; # Array of component files 72 73 { 73 my $command = "$dettool -residimfile -det_id $detId -iter $iter -exp_id $expId"; # Command to run74 my $command = "$dettool -residimfile -det_id $detId -iteration $iter -exp_id $expId"; # Command to run 74 75 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 75 76 run(command => $command, verbose => 1); … … 79 80 } 80 81 81 # Generate the file list 82 my $outputName = $detId . '_' . $iter; # Root output name 83 my $statName = $outputName . '.stats'; 84 my $listName = $outputName . '_jpeg.list'; # Name for the input file list 85 open my $listFile, '>' . $listName; 82 # Generate the file list, and get the statistics 83 my $outputName = $detType . '_' . $detId . '_' . $iter; # Root output name 84 my $list1Name = $outputName . '_jpeg1.list'; # Name for the input file list for binning 1 85 my $list2Name = $outputName . '_jpeg2.list'; # Name for the input file list for binning 2 86 my @means; # Array of means 87 my @stdevs; # Array of stdevs 88 open my $list1File, '>' . $list1Name; 89 open my $list2File, '>' . $list2Name; 86 90 foreach my $file (@$files) { 87 print $listFile $file->{uri} . "\n"; 91 print $list1File $file->{b1_uri} . "\n"; 92 print $list2File $file->{b2_uri} . "\n"; 93 push @means, $file->{bg}; 94 push @stdevs, $file->{bg_stdev}; 88 95 } 89 close $listFile; 96 close $list1File; 97 close $list2File; 90 98 91 99 # Output products --- need to synch with the camera configuration! … … 93 101 my $jpeg2Name = $outputName . ".b2.jpeg"; # Binned JPEG #2 94 102 95 # Make the jpeg 103 # Make the jpeg for binning 1 96 104 { 97 my $command = "$ppImage -list $listName $outputName -stat $statName" . 98 "-recipe PPIMAGE " . RECIPE; # Command to run 105 my $command = "$ppImage -list $list1Name $outputName -recipe PPIMAGE " . RECIPE; # Command to run 99 106 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 100 107 run(command => $command, verbose => 1); 101 die "Unable to find expected output file: $jpeg1Name\n" if not -f $jpeg1Name; 102 die "Unable to find expected output file: $jpeg2Name\n" if not -f $jpeg2Name; 103 die "Unable to find expected output file: $statName\n" if not -f $statName; 108 # die "Unable to find expected output file: $jpeg1Name\n" if not -f $jpeg1Name; 104 109 } 105 110 106 # Parse the statistics 107 my $stats; # Statistics from ppImage 111 # Make the jpeg for binning 2 108 112 { 109 open my $statsFile, $statName or die "Can't open statistics file $statName: $!\n"; 110 my @contents = <$statsFile>; # Contents of file 111 close $statsFile; 112 my $metadata = $mdcParser->parse(join "", @contents); # Metadata from the stats 113 $stats = PS::IPP::Metadata::Stats->new(); # Stats parser 114 $stats->parse($metadata) or die "Unable to find all values in statistics output.\n"; 113 my $command = "$ppImage -list $list2Name $outputName -recipe PPIMAGE " . RECIPE; # Command to run 114 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 115 run(command => $command, verbose => 1); 116 # die "Unable to find expected output file: $jpeg2Name\n" if not -f $jpeg2Name; 115 117 } 116 118 … … 128 130 129 131 # Reject based on the individual stats 130 my @means = $stats->bg_data(); # Array of means131 my @stdevs = $stats->bg_stdev_data(); # Array of stdevs132 132 my $reject = 0; # Rejection flag 133 133 die "Number of means and number of stdevs differ!\n" if scalar @means != scalar @stdevs; … … 137 137 my $stdev = $stdevs[$i]; # Stdev for this component 138 138 139 if ((defined REJECT_INDIVIDUAL_MEAN->{$detType} and $mean / $stdev > REJECT_INDIVIDUAL_MEAN->{$detType}) 140 or 141 (defined REJECT_INDIVIDUAL_STDEV->{$detType} and $stdev > REJECT_INDIVIDUAL_STDEV->{$detType})) { 139 if (defined REJECT_INDIVIDUAL_MEAN->{$detType} 140 and $stdev > 0 and 141 $mean / $stdev > REJECT_INDIVIDUAL_MEAN->{$detType}) { 142 print "Rejecting exposure based on bad individual mean for component $i: " . 143 ($mean / $stdev) . " vs " . REJECT_INDIVIDUAL_MEAN->{$detType} . "\n"; 144 $reject = 1; 145 last; 146 } elsif (defined REJECT_INDIVIDUAL_STDEV->{$detType} and 147 $stdev > REJECT_INDIVIDUAL_STDEV->{$detType}) { 148 print "Rejecting exposure based on bad individual stdev for component $i: " . 149 $stdev . " vs " . REJECT_INDIVIDUAL_STDEV->{$detType} . "\n"; 142 150 $reject = 1; 143 151 last; … … 146 154 147 155 # Reject based on the sample stats 148 my $mean = $stats->bg_mean; # Mean of the sample of means 149 my $stdev = $stats->bg_stdev; # Stdev of the sample of means 150 my $meanStdev = $stats->bg_mean_stdev; # Mean of the sample of stdevs 151 152 if ((defined REJECT_SAMPLE_MEAN->{$detType} and $mean / $stdev > REJECT_SAMPLE_MEAN->{$detType}) 153 or 154 (defined REJECT_SAMPLE_STDEV->{$detType} and $meanStdev > REJECT_SAMPLE_STDEV->{$detType})) { 156 my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means 157 $meanStats->add_data(@means); 158 my $stdevStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for stdevs 159 $stdevStats->add_data(@stdevs); 160 my $mean = $meanStats->mean(); # Mean of the sample of means 161 my $stdev = $meanStats->standard_deviation(); # Stdev of the sample of means 162 if (not defined $stdev) { 163 $stdev = 0; 164 } 165 my $meanStdev = $stdevStats->mean(); # Mean of the sample of stdevs 166 if (defined REJECT_SAMPLE_MEAN->{$detType} and 167 $stdev != 0 and 168 $mean / $stdev > REJECT_SAMPLE_MEAN->{$detType}) { 169 print "Rejecting exposure based on bad mean: " . ($mean / $stdev) . " vs " . 170 REJECT_SAMPLE_MEAN->{$detType} . "\n"; 171 $reject = 1; 172 } elsif (defined REJECT_SAMPLE_STDEV->{$detType} and 173 $meanStdev > REJECT_SAMPLE_STDEV->{$detType}) { 174 print "Rejecting exposure based on bad mean stdev: " . $meanStdev . " vs " . 175 REJECT_SAMPLE_STDEV->{$detType} . "\n"; 155 176 $reject = 1; 156 177 } 157 178 158 159 179 # Add the result into the database 160 180 { 161 my $command = " dettool -addresidexp -det_id $detId -iter$iter -exp_id $expId " .181 my $command = "$dettool -addresidexp -det_id $detId -iteration $iter -exp_id $expId " . 162 182 "-recip " . RECIPE() . " -b1_uri $jpeg1Name -b2_uri $jpeg2Name -bg $mean -bg_stdev $stdev " . 163 183 "-bg_mean_stdev $meanStdev"; # Command to run
Note:
See TracChangeset
for help on using the changeset viewer.
