IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 6, 2007, 3:44:38 PM (19 years ago)
Author:
eugene
Message:

rework for consistency with the changes to the database and PS-IPP-Config

File:
1 edited

Legend:

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

    r14009 r14048  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
     18use PS::IPP::Metadata::Stats;
     19
    1820use PS::IPP::Metadata::List qw( parse_md_list );
    1921use Statistics::Descriptive;
     
    8688
    8789# Get list of component files
    88 my $exposures;                  # Array of exposures
     90my ($exposures, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    8991{
    9092    # dettool command to select exp data for this det_run
    91     my $command = "$dettool -residexp";
     93    $command = "$dettool -residexp";
    9294    $command .= " -det_id $det_id";
    9395    $command .= " -iteration $iter";
    9496    $command .= " -dbname $dbname" if defined $dbname;
    95     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     97    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    9698        run(command => $command, verbose => 1);
    9799    unless ($success) {
     
    118120}
    119121
    120 my @expTags;                    # Array of exposure IDs
    121 my @accept;                     # Array of accept flags
    122 my @include;                    # Array of include flags
    123 foreach my $exposure (@$exposures) {
    124     &my_die("Unable to find exposure id.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{exp_tag};
    125     &my_die("Unable to find accept.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{accept};
    126     &my_die("Unable to find include.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{include};
    127 }
    128 
     122# we use the statistics of the ensemble to accept/reject exposurs
    129123my $ensMeanMean       = &STATS_value_for_flag ($REJSTATS, "ensMeanMean");     
    130124my $ensMeanStdev      = &STATS_value_for_flag ($REJSTATS, "ensMeanStdev");     
     
    147141unless ($no_op) {
    148142    $logFile = $ipprc->file_create_append( $logName );
    149     print $logFile "Ensemble mean $meanEnsemble +/- $stdevEnsemble, stdev $meanStdevEnsemble\n\n";
     143    print $logFile "Ensemble mean $ensMeanMean +/- $ensMeanStdevMean, stdev $ensStdevMean\n\n";
    150144}
    151145
     
    153147my $numChanges = 0;             # Number of exposures with changed status
    154148my $numReject = 0;              # Number of exposures rejected
    155 
    156 for (my $i = 0; $i < scalar @$exposures; $i++) {
    157     my $file      = $files[$i];
    158     my $mean      = $file->{bg};        # Mean for this exposure
    159     my $stdev     = $file->{bg_stdev}; # Stdev for this exposure
    160     my $meanStdev = $file->{bg_mean_stdev}; # Stdev of Means for this exposure
    161 
    162     my $expTag  = $exposure->{exp_tag};
    163     my $accept  = $exposure->{accept};
    164     my $include = $exposure->{include};
     149my $firstElement = 1;
     150
     151foreach my $exposure (@$exposures) {
     152    my $mean      = $exposure->{bg};    # Mean for this exposure
     153    my $stdev     = $exposure->{bg_stdev}; # Stdev for this exposure
     154    my $meanStdev = $exposure->{bg_mean_stdev}; # Stdev of Means for this exposure
     155    my $expID     = $exposure->{exp_id};
     156    my $accept    = $exposure->{accept};
     157    my $include   = $exposure->{include};
     158
     159    &my_die("Unable to find exposure id.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $expID;
     160    &my_die("Unable to find accept.\n",      $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $accept;
     161    &my_die("Unable to find include.\n",     $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $include;
    165162
    166163    my $reject = 0;             # Reject this exposure?
    167164
    168     my $command = "$dettool -updateresidexp";
     165    $command = "$dettool -updateresidexp";
    169166    $command .= " -det_id $det_id";
    170167    $command .= " -iteration $iter";
    171     $command .= " -exp_tag $expTag";
     168    $command .= " -exp_id $expID";
    172169    $command .= " -dbname $dbname" if defined $dbname;
    173170   
     
    175172        # Rejected this at an earlier stage
    176173        unless ($no_op) {
    177             print $logFile "Rejecting $expTag based on earlier determination.\n";
     174            print $logFile "Rejecting $expID based on earlier determination.\n";
    178175        }
    179176        $reject = 1;
     
    185182        # Make sure something gets rejected (just once!), just so that
    186183        # we can trace the full range of the workflow
    187         if ($i == 0 and $iter == 0) {
     184        if ($firstElement and $iter == 0) {
    188185            $reject = 1;
    189186        }
     
    194191        my $delta = abs($mean - $ensMeanMean);
    195192        if ($delta > ($reject_mean * $ensMeanStdev)) {
    196             print $logFile "Rejecting $expTag based on ensemble mean value: ";
     193            print $logFile "Rejecting $expID based on ensemble mean value: ";
    197194            $reject = 1;
    198195            #goto UPDATE;
    199196        } else {
    200             print $logFile "$expTag OK against ensemble mean: ";
     197            print $logFile "$expID OK against ensemble mean: ";
    201198        }
    202199        print $logFile "$mean --> $delta vs " . $reject_mean * $ensMeanStdev . "\n";
    203200    } else {
    204         print $logFile "No rejection of $expTag for ensemble mean\n";
     201        print $logFile "No rejection of $expID for ensemble mean\n";
    205202    }
    206203
     
    208205        my $delta = abs($stdev - $ensStdevMean);
    209206        if ($delta > ($reject_stdev * $ensStdevStdev)) {
    210             print $logFile "Rejecting $expTag based on ensemble stdev: ";
     207            print $logFile "Rejecting $expID based on ensemble stdev: ";
    211208            $reject = 1;
    212209            #goto UPDATE;
    213210        } else {
    214             print $logFile "$expTag OK against ensemble stdev: ";
     211            print $logFile "$expID OK against ensemble stdev: ";
    215212        }
    216213        print $logFile "$stdev --> $delta sigma vs " . $reject_stdev * $ensStdevStdev . "\n";
    217214    } else {
    218         print $logFile "No rejection of $expTag for ensemble stdev\n";
     215        print $logFile "No rejection of $expID for ensemble stdev\n";
    219216    }
    220217   
     
    222219        my $delta = abs($meanStdev - $ensMeanStdevMean);
    223220        if ($delta > ($reject_meanstdev * $ensMeanStdevStdev)) {
    224             print $logFile "Rejecting $expTag based on ensemble mean stdev: ";
     221            print $logFile "Rejecting $expID based on ensemble mean stdev: ";
    225222            $reject = 1;
    226223            #goto UPDATE;
    227224        } else {
    228             print $logFile "$expTag OK against ensemble mean stdev: ";
     225            print $logFile "$expID OK against ensemble mean stdev: ";
    229226        }
    230227        print $logFile "$meanStdev --> $delta sigma vs " . $reject_meanstdev * $ensMeanStdevStdev. "\n";
    231228    } else {
    232         print $logFile "No rejection of $expTag for ensemble mean stdev\n";
     229        print $logFile "No rejection of $expID for ensemble mean stdev\n";
    233230    }
    234231
     
    242239    if ((not $include and not $reject) or ($include and $reject)) {
    243240        unless ($no_op) {
    244             print $logFile "Status of $expTag has changed.\n";
     241            print $logFile "Status of $expID has changed.\n";
    245242        }
    246243        $numChanges++;
     
    249246    unless ($no_update) {
    250247        # Update
    251         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     248        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    252249            run(command => $command, verbose => 1);
    253250        unless ($success) {
     
    268265
    269266# Rejecting everything --- stop before something bad happens!
    270 if ($numReject == scalar @means) {
     267if ($numReject == scalar @$exposures) {
    271268    $master = 0;
    272269    $stop = 1;
     
    279276}
    280277
    281 my $command = "$dettool -adddetrunsummary";
     278$command = "$dettool -adddetrunsummary";
    282279$command .= " -det_id $det_id";
    283280$command .= " -iteration $iter";
     
    294291# Put results into the database
    295292unless ($no_update) {
    296     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     293    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    297294        run(command => $command, verbose => 1);
    298295    unless ($success) {
     
    310307    $command .= " -dbname $dbname" if defined $dbname;
    311308
    312     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     309    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    313310        run(command => $command, verbose => 1);
    314311    unless ($success) {
Note: See TracChangeset for help on using the changeset viewer.