IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9454


Ignore:
Timestamp:
Oct 9, 2006, 10:20:43 PM (20 years ago)
Author:
eugene
Message:

clarified some of the operations,
but added comments to address concerns about the goals.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/detrend_reject_imfile.pl

    r9453 r9454  
    4141use constant RECIPE2 => 'PPIMAGE_J2'; # Recipe to use for ppImage to make JPEGs
    4242
     43#### XXXXX these values must come from the config system, and may depend on filter!!!
    4344# The expected mean, as a function of detrend type
    4445use constant EXPECTED_MEAN => {
     
    4647    'dark' => 0,                # Dark should be zero
    4748    'shutter' => undef,         # Shutter could be anything (depends on exposure level)
    48     'flat' => 0         # Flat could be anything (depends on exposure level)
     49    'flat' => 0                 # Flat could be anything (depends on exposure level)
    4950    };
    5051
    5152# Rejection threshold for the mean, in terms of the standard deviation
    5253# This measures how close it is to what's expected
    53 use constant REJECT_INDIVIDUAL_MEAN => {
     54# XXX it is valid to reject on more than one criterion
     55use constant REJECT_COMPONENT_MEAN => {
    5456    'bias' => 0,                # Should be fairly flat; some CRs
    5557    'dark' => 0,                # Lots of CRs
     
    5961
    6062# Rejection threshold for the standard deviation, in ADUs
    61 # This measures how much variation there is in each component
    62 use constant REJECT_INDIVIDUAL_STDEV => {
     63# This measures how much variation there is in each imfile component
     64use constant REJECT_COMPONENT_STDEV => {
    6365    'bias' => 0,                # Should be fairly flat; some CRs
    6466    'dark' => 0,                # Lots of CRs
     
    7779
    7880# Rejection threshold for the stdev of the sample, in ADUs
    79 # This measures how much variation there is across the components
     81# This measures how much variation there is across the imfile components
    8082use constant REJECT_SAMPLE_STDEV => {
     83    'bias' => 0,                # Should be little variation between chips
     84    'dark' => 0,                # Could be some glow on some chips
     85    'shutter' => undef,         # Can be significant structure
     86    'flat' => 0                 # Could be features on some chips, but all should be about the same
     87    };
     88
     89# Rejection threshold for the stdev of the sample, in ADUs
     90# This measures how much variation there is across the imfile components
     91use constant REJECT_SAMPLE_MEAN_STDEV => {
    8192    'bias' => 0,                # Should be little variation between chips
    8293    'dark' => 0,                # Could be some glow on some chips
     
    151162die "Unknown expected mean for detrend type $det_type\n"
    152163    if not exists EXPECTED_MEAN->{$det_type};
    153 die "Unknown individual mean rejection level for detrend type $det_type\n"
    154     if not exists REJECT_INDIVIDUAL_MEAN->{$det_type};
    155 die "Unknown individual stdev rejection level for detrend type $det_type\n"
    156     if not exists REJECT_INDIVIDUAL_STDEV->{$det_type};
     164die "Unknown component mean rejection level for detrend type $det_type\n"
     165    if not exists REJECT_COMPONENT_MEAN->{$det_type};
     166die "Unknown component stdev rejection level for detrend type $det_type\n"
     167    if not exists REJECT_COMPONENT_STDEV->{$det_type};
    157168die "Unknown sample mean rejection level for detrend type $det_type\n"
    158169    if not exists REJECT_SAMPLE_MEAN->{$det_type};
     
    160171    if not exists REJECT_SAMPLE_STDEV->{$det_type};
    161172
    162 # Reject based on the individual stats
     173# Reject based on the stats of the component imfile
    163174die "Number of means and number of stdevs differ!\n" if scalar @means != scalar @stdevs;
    164175for (my $i = 0; $i < scalar @means; $i++) {
    165176    my $mean = $means[$i];      # Mean for this component
    166177    $mean -= EXPECTED_MEAN->{$det_type} if defined EXPECTED_MEAN->{$det_type};
    167     my $stdev = $stdevs[$i];    # Stdev for this component
    168     my $not_reject;
    169 
    170     if (defined REJECT_INDIVIDUAL_MEAN->{$det_type}
    171         and $stdev > 0 and
    172         $mean / $stdev > REJECT_INDIVIDUAL_MEAN->{$det_type}) {
    173         print "Rejecting exposure based on bad individual mean for component $i: " .
    174             ($mean / $stdev) . " vs " . REJECT_INDIVIDUAL_MEAN->{$det_type} . "\n";
    175         $not_reject = 1;
    176         last;
    177     } elsif (defined REJECT_INDIVIDUAL_STDEV->{$det_type} and
    178              $stdev > REJECT_INDIVIDUAL_STDEV->{$det_type}) {
    179         print "Rejecting exposure based on bad individual stdev for component $i: " .
    180             $stdev . " vs " . REJECT_INDIVIDUAL_STDEV->{$det_type} . "\n";
    181         $not_reject = 1;
    182         last;
     178    my $stdev = sqrt($stdevs[$i]);      # Stdev for this component
     179
     180    ## IT IS VALID to reject on more than one criterion
     181    if (REJECT_COMPONENT_MEAN->{$det_type} && ($stdev > 0) ) {
     182        if ($mean / $stdev > REJECT_COMPONENT_MEAN->{$det_type}) {
     183            print "Rejecting exposure based on bad component mean for component $i: " .
     184                ($mean / $stdev) . " vs " . REJECT_COMPONENT_MEAN->{$det_type} . "\n";
     185            $reject = 1;
     186            last;
     187        }
     188    }
     189    if (REJECT_COMPONENT_STDEV->{$det_type}) {
     190        if ($stdev > REJECT_COMPONENT_STDEV->{$det_type}) {
     191            print "Rejecting exposure based on bad component stdev for component $i: " .
     192                $stdev . " vs " . REJECT_COMPONENT_STDEV->{$det_type} . "\n";
     193            $reject = 1;
     194            last;
     195        }
    183196    }
    184197}
    185198
    186 # Reject based on the sample stats
     199# calculate the imfile ensemble statistics
    187200my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means
    188201$meanStats->add_data(@means);
     
    190203$stdevStats->add_data(@stdevs);
    191204my $mean = $meanStats->mean();  # Mean of the sample of means
    192 my $stdev = $meanStats->standard_deviation(); # Stdev of the sample of means
     205my $meanStdev = $meanStats->standard_deviation(); # Stdev of the sample of means
    193206if (not defined $stdev) {
    194207    $stdev = 0;
    195208}
    196 my $meanStdev = sqrt($stdevStats->mean()); # Root-Mean-Square of the sample of stdevs
    197 my $not_reject;
     209my $stdev = sqrt($stdevStats->mean()); # Root-Mean-Square of the sample of stdevs
    198210print "calculating root-mean-square of the sample stdevs: $meanStdev\n";
    199 if (defined REJECT_SAMPLE_MEAN->{$det_type} and
    200     $stdev != 0 and
    201     $mean / $stdev > REJECT_SAMPLE_MEAN->{$det_type}) {
    202     print "Rejecting exposure based on bad mean: " . ($mean / $stdev) . " vs " .
    203         REJECT_SAMPLE_MEAN->{$det_type} . "\n";
    204     $not_reject = 1;
    205 } elsif (defined REJECT_SAMPLE_STDEV->{$det_type} and
    206          $meanStdev > REJECT_SAMPLE_STDEV->{$det_type}) {
    207     print "Rejecting exposure based on bad mean stdev: " . $meanStdev . " vs " .
    208         REJECT_SAMPLE_STDEV->{$det_type} . "\n";
    209     $not_reject = 1;
     211
     212## Reject based on the imfile ensemble stats
     213# reject if the imfile ensemble
     214if (REJECT_SAMPLE_MEAN->{$det_type} && ($stdev > 0)) {
     215    if ($mean / $stdev > REJECT_SAMPLE_MEAN->{$det_type}) {
     216        print "Rejecting exposure based on bad mean: " . ($mean / $stdev) . " vs " .
     217            REJECT_SAMPLE_MEAN->{$det_type} . "\n";
     218        $reject = 1;
     219    }
     220}
     221if (REJECT_SAMPLE_STDEV->{$det_type}) {
     222    if ($stdev > REJECT_SAMPLE_STDEV->{$det_type}) {
     223        print "Rejecting exposure based on bad mean stdev: " . $stdev . " vs " .
     224            REJECT_SAMPLE_STDEV->{$det_type} . "\n";
     225        $reject = 1;
     226    }
     227}
     228if (REJECT_SAMPLE_MEAN_STDEV->{$det_type}) {
     229    if ($meanStdev > REJECT_SAMPLE_MEAN_STDEV->{$det_type}) {
     230        print "Rejecting exposure based on bad mean stdev: " . $meanStdev . " vs " .
     231            REJECT_SAMPLE_MEAN_STDEV->{$det_type} . "\n";
     232        $reject = 1;
     233    }
    210234}
    211235
     
    229253
    230254__END__
     255
     256####
     257
     258## this function is not well though out.  it loads a collection of
     259## values (background mean and stdev) for a collection of imfile
     260## subcomponents.  it then measures the mean background, the
     261## background stdev (rms of ensemble stdevs), and the background mean
     262## stdev (rms of the means).  it then tries to reject based on the
     263## following criteria:
     264## (background / stdev > limit) for a single component
     265##    ---> this will ACCEPT for a poor images (large stdev)
     266## (stdev > limit)
     267## (mean background / stdev > limit) same problem
     268## (mean stdev > limit)
     269
     270### I would suggest the following:
     271## 1) calculate the ensemble mean and stdev
     272## 2) for each component, is the (back - mean) / mean stdev > limit?
     273##    (ie, is it an outlier?)
     274## 3) is the component stdev > limit? (absolute test)
     275## 4) calculate the background stdev for the ensemble (excluding rejects)
     276## 5) is the mean stdev > limit (poor images)
     277## 6) calculate the ensemble stdev (rms) of remaining (excluding rejects)
     278## 7) is the ensemble stdev > limit
     279
     280## for flats, the value used for stdev should be the fractional stdev
     281## (stdev/mean) and no rejection should be performed on the basis of
     282## the mean value, but could still be done on the mean stdev
     283
     284## the same logical cuts above can be applied to components in an
     285## imfile, imfiles in an exposure, and exposures in a stack
Note: See TracChangeset for help on using the changeset viewer.