IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 4, 2006, 6:40:25 PM (20 years ago)
Author:
Paul Price
Message:

Count exposures that change status and use this as the trigger for stopping and master status.

File:
1 edited

Legend:

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

    r9259 r9288  
    7777my @stdevs;                     # Array of stdevs
    7878my @meanStdevs;                 # Array of mean stdevs
     79my @accept;                     # Array of accept flags
     80my @include;                    # Array of include flags
    7981foreach my $exposure (@$exposures) {
    8082    die "Unable to find exposure id.\n" if not defined $exposure->{exp_tag};
     
    8284    die "Unable to find stdev.\n" if not defined $exposure->{bg_stdev};
    8385    die "Unable to find mean stdev.\n" if not defined $exposure->{bg_mean_stdev};
     86    die "Unable to find accept.\n" if not defined $exposure->{accept};
     87    die "Unable to find include.\n" if not defined $exposure->{include};
    8488    push @expTags, $exposure->{exp_tag};
    8589    push @means, $exposure->{bg};
    8690    push @stdevs, $exposure->{bg_stdev};
    8791    push @meanStdevs, $exposure->{bg_mean_stdev};
     92    push @accept, $exposure->{accept};
     93    push @include, $exposure->{include};
    8894}
    8995my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator
     
    103109
    104110# Go through again to do rejection, and update the database for each exposure
    105 unless ($no_update) {
    106     my $numRejected = 0;                # Number of exposures rejected
    107     for (my $i = 0; $i < scalar @means; $i++) {
    108         my $expTag = $expTags[$i];      # Exposure ID
    109         my $command = "$dettool -updateresidexp -det_id $det_id -iteration $iter -exp_tag $expTag"; # Command to run
    110         my $reject = 0;         # Reject this exposure?
    111         if (defined REJECT_MEAN->{$det_type} and
    112             defined $meanStats->standard_deviation() and
    113             $meanStats->standard_deviation() > 0 and
    114             ($means[$i] - $meanStats->mean()) / $meanStats->standard_deviation() > REJECT_MEAN->{$det_type}) {
    115             print "Rejecting $expTag based on bad mean: " .
    116                 (($means[$i] - $meanStats->mean()) / $meanStats->standard_deviation()) .
    117                 " vs " . REJECT_MEAN->{$det_type} . "\n";
    118             $reject = 1;
    119         } elsif (defined REJECT_STDEV->{$det_type} and
    120                  defined $stdevStats->standard_deviation() and
    121                  $stdevStats->standard_deviation() > 0 and
    122                  ($stdevs[$i] - $stdevStats->mean()) / $stdevStats->standard_deviation() >
    123                  REJECT_STDEV->{$det_type}) {
    124             print "Rejecting $expTag based on bad stdev: " .
    125                 (($stdevs[$i] - $stdevStats->mean()) / $stdevStats->standard_deviation()) .
    126                 " vs " . REJECT_STDEV->{$det_type} . "\n";
    127             $reject = 1;
    128         } elsif (defined REJECT_MEAN_STDEV->{$det_type} and
    129                  defined $meanStdevStats->standard_deviation() and
    130                  $meanStdevStats->standard_deviation() > 0 and
    131                  ($meanStdevs[$i] - $meanStdevStats->mean()) / $meanStdevStats->standard_deviation() >
    132                  REJECT_MEAN_STDEV->{$det_type}) {
    133             print "Rejecting $expTag based on bad stdev: " .
    134                 (($meanStdevs[$i] - $meanStdevStats->mean()) / $meanStdevStats->standard_deviation()) .
    135                 " vs " . REJECT_MEAN_STDEV->{$det_type} . "\n";
    136             $reject = 1;
    137         }
    138        
    139         if ($reject) {
    140             $command .= ' -reject';
    141             ### XXX: Need some way to know whether the exposure has already been rejected.
    142             ### rejection flag in $exposures?
    143             $numRejected++;
    144         }
    145        
     111my $numChanges = 0;             # Number of exposures with changed status
     112for (my $i = 0; $i < scalar @means; $i++) {
     113    my $expTag = $expTags[$i];  # Exposure ID
     114    my $command = "$dettool -updateresidexp -det_id $det_id -iteration $iter -exp_tag $expTag"; # Command to run
     115    my $reject = 0;             # Reject this exposure?
     116    if (not $accept[$i]) {
     117        # Rejected this at an earlier stage
     118        print "Rejecting $expTag based on earlier determination.\n";
     119        $reject = 1;
     120    } elsif (defined REJECT_MEAN->{$det_type} and
     121             defined $meanStats->standard_deviation() and
     122             $meanStats->standard_deviation() > 0 and
     123             ($means[$i] - $meanStats->mean()) / $meanStats->standard_deviation() > REJECT_MEAN->{$det_type}) {
     124        print "Rejecting $expTag based on bad mean: " .
     125            (($means[$i] - $meanStats->mean()) / $meanStats->standard_deviation()) .
     126            " vs " . REJECT_MEAN->{$det_type} . "\n";
     127        $reject = 1;
     128    } elsif (defined REJECT_STDEV->{$det_type} and
     129             defined $stdevStats->standard_deviation() and
     130             $stdevStats->standard_deviation() > 0 and
     131             ($stdevs[$i] - $stdevStats->mean()) / $stdevStats->standard_deviation() >
     132             REJECT_STDEV->{$det_type}) {
     133        print "Rejecting $expTag based on bad stdev: " .
     134            (($stdevs[$i] - $stdevStats->mean()) / $stdevStats->standard_deviation()) .
     135            " vs " . REJECT_STDEV->{$det_type} . "\n";
     136        $reject = 1;
     137    } elsif (defined REJECT_MEAN_STDEV->{$det_type} and
     138             defined $meanStdevStats->standard_deviation() and
     139             $meanStdevStats->standard_deviation() > 0 and
     140             ($meanStdevs[$i] - $meanStdevStats->mean()) / $meanStdevStats->standard_deviation() >
     141             REJECT_MEAN_STDEV->{$det_type}) {
     142        print "Rejecting $expTag based on bad stdev: " .
     143            (($meanStdevs[$i] - $meanStdevStats->mean()) / $meanStdevStats->standard_deviation()) .
     144            " vs " . REJECT_MEAN_STDEV->{$det_type} . "\n";
     145        $reject = 1;
     146    }
     147   
     148    if ($reject) {
     149        $command .= ' -reject';
     150    }
     151   
     152    # Check for status changes
     153    if ((not $include[$i] and not $reject) or ($include[$i] and $reject)) {
     154        print "Status of $expTag has changed.\n";
     155        $numChanges++;
     156    }
     157   
     158    unless ($no_update) {
    146159        # Update
    147160        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    149162        die "Unable to perform dettool -updateresidexp: $error_code\n" if not $success;
    150163    }
    151 
    152     # Decide if the current is sufficient to use as a master, and if we can stop iterating
    153     my $master = 1;                     # This is good enough for a master
    154     my $stop = 1;                       # Stop iterating
    155     # XXX: This probably isn't sufficient, but will do for now:
    156     if ($numRejected > 0) {
    157         $master = 0;
    158         $stop = 0;
    159     }
    160 
    161     # Put the result into the database
    162     {
    163         my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter " .
    164             "-bg " . $meanStats->mean() . " -bg_stdev " . $stdevStats->mean() .
    165             " -bg_mean_stdev " . $meanStdevStats->mean();
    166         $command .= " -accept" if $master;
    167        
    168         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    169             run(command => $command, verbose => 1);
    170         die "Unable to perform dettool -adddetrunsummary: $error_code\n" if not $success;
    171     }
    172    
    173     # Re-run processing if required
    174     {
    175         my $command = "$dettool -updatedetrun -det_id $det_id";
    176         if ($stop) {
    177             $command .= ' -stop';
    178         } else {
    179             $command .= ' -again';
    180         }
    181        
    182         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    183             run(command => $command, verbose => 1);
    184         die "Unable to perform dettool -updatedetrun: $error_code\n" if not $success;
    185     }
    186 }
     164}
     165   
     166# Decide if the current is sufficient to use as a master, and if we can stop iterating
     167my $master = 1;                 # This is good enough for a master
     168my $stop = 1;                   # Stop iterating
     169
     170if ($numChanges > 0) {
     171    $master = 0;
     172    $stop = 0;
     173}
     174
     175print "Master: $master\n";
     176print "Stop: $stop\n";
     177
     178# Put the result into the database
     179unless ($no_update) {
     180    my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter " .
     181        "-bg " . $meanStats->mean() . " -bg_stdev " . $stdevStats->mean() .
     182        " -bg_mean_stdev " . $meanStdevStats->mean();
     183    $command .= " -accept" if $master;
     184   
     185    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     186        run(command => $command, verbose => 1);
     187    die "Unable to perform dettool -adddetrunsummary: $error_code\n" if not $success;
     188}
     189
     190# Re-run processing if required
     191unless ($no_update) {
     192    my $command = "$dettool -updatedetrun -det_id $det_id";
     193    if ($stop) {
     194        $command .= ' -stop';
     195    } else {
     196        $command .= ' -again';
     197    }
     198   
     199    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     200        run(command => $command, verbose => 1);
     201    die "Unable to perform dettool -updatedetrun: $error_code\n" if not $success;
     202}
     203
    187204__END__
Note: See TracChangeset for help on using the changeset viewer.