IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 6, 2006, 4:32:51 PM (20 years ago)
Author:
jhoblitt
Message:

change from positional to named CLI options

File:
1 edited

Legend:

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

    r8715 r8763  
    44use strict;
    55
     6use vars qw( $VERSION );
     7$VERSION = '0.01';
     8
    69use IPC::Cmd qw( can_run run );
    710use PS::IPP::Metadata::Config;
    811use PS::IPP::Metadata::List qw( parse_md_list );
    912use Statistics::Descriptive;
    10 use Data::Dumper;
     13
     14use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     15use Pod::Usage qw( pod2usage );
     16
     17my ($det_id, $iter, $det_type);
     18GetOptions(
     19    'det_id|d=s'        => \$det_id,
     20    'iteration=s'       => \$iter,
     21    'det_type|t=s'      => \$det_type,
     22) or pod2usage( 2 );
     23
     24pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     25pod2usage(
     26    -msg => "Required options: --det_id --exp_id --class_id --det_type --input_uri --output_uri",
     27    -exitval => 3,
     28) unless defined $det_id
     29    and defined $iter
     30    and defined $det_type;
     31
     32my $detType = shift @ARGV;      # Detrend type
    1133
    1234# Rejection threshold for the mean, in terms of the standard deviation
     
    3456    };
    3557
    36 # Parse command-line arguments
    37 die "Reject exposures based on the sample of exposures.\n\n" .
    38     "Usage: $0 DET_ID ITER DETREND_TYPE\n\n"
    39     if scalar @ARGV != 3;
    40 my $detId = shift @ARGV;        # Detrend ID
    41 my $iter = shift @ARGV;         # Iteration number
    42 my $detType = shift @ARGV;      # Detrend type
    43 
    4458# Look for programs we need
    4559my $missing_tools;
     
    5165my $exposures;                  # Array of exposures
    5266{
    53     my $command = "$dettool -residexp -det_id $detId -iteration $iter"; # Command to run
     67    my $command = "$dettool -residexp -det_id $det_id -iteration $iter"; # Command to run
    5468    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    5569        run(command => $command, verbose => 1);
     
    8296
    8397# Check the existence of the required rejection levels as a function of detrend type
    84 die "Unknown mean rejection level for detrend type $detType\n"
    85     if not exists REJECT_MEAN->{$detType};
    86 die "Unknown stdev rejection level for detrend type $detType\n"
    87     if not exists REJECT_STDEV->{$detType};
    88 die "Unknown mean stdev rejection level for detrend type $detType\n"
    89     if not exists REJECT_MEAN_STDEV->{$detType};
     98die "Unknown mean rejection level for detrend type $det_type\n"
     99    if not exists REJECT_MEAN->{$det_type};
     100die "Unknown stdev rejection level for detrend type $det_type\n"
     101    if not exists REJECT_STDEV->{$det_type};
     102die "Unknown mean stdev rejection level for detrend type $det_type\n"
     103    if not exists REJECT_MEAN_STDEV->{$det_type};
    90104
    91105# Go through again to do rejection, and update the database for each exposure
     
    93107for (my $i = 0; $i < scalar @means; $i++) {
    94108    my $expId = $expIds[$i];    # Exposure ID
    95     my $command = "$dettool -updateresidexp -det_id $detId -iteration $iter -exp_id $expId"; # Command to run
     109    my $command = "$dettool -updateresidexp -det_id $det_id -iteration $iter -exp_id $expId"; # Command to run
    96110    my $reject = 0;             # Reject this exposure?
    97     if (defined REJECT_MEAN->{$detType} and
     111    if (defined REJECT_MEAN->{$det_type} and
    98112        defined $meanStats->standard_deviation() and
    99113        $meanStats->standard_deviation() > 0 and
    100         ($means[$i] - $meanStats->mean()) / $meanStats->standard_deviation() > REJECT_MEAN->{$detType}) {
     114        ($means[$i] - $meanStats->mean()) / $meanStats->standard_deviation() > REJECT_MEAN->{$det_type}) {
    101115        print "Rejecting $expId based on bad mean: " .
    102116            (($means[$i] - $meanStats->mean()) / $meanStats->standard_deviation()) .
    103             " vs " . REJECT_MEAN->{$detType} . "\n";
     117            " vs " . REJECT_MEAN->{$det_type} . "\n";
    104118        $reject = 1;
    105     } elsif (defined REJECT_STDEV->{$detType} and
     119    } elsif (defined REJECT_STDEV->{$det_type} and
    106120             defined $stdevStats->standard_deviation() and
    107121             $stdevStats->standard_deviation() > 0 and
    108122             ($stdevs[$i] - $stdevStats->mean()) / $stdevStats->standard_deviation() >
    109              REJECT_STDEV->{$detType}) {
     123             REJECT_STDEV->{$det_type}) {
    110124        print "Rejecting $expId based on bad stdev: " .
    111125            (($stdevs[$i] - $stdevStats->mean()) / $stdevStats->standard_deviation()) .
    112             " vs " . REJECT_STDEV->{$detType} . "\n";
     126            " vs " . REJECT_STDEV->{$det_type} . "\n";
    113127        $reject = 1;
    114     } elsif (defined REJECT_MEAN_STDEV->{$detType} and
     128    } elsif (defined REJECT_MEAN_STDEV->{$det_type} and
    115129             defined $meanStdevStats->standard_deviation() and
    116130             $meanStdevStats->standard_deviation() > 0 and
    117131             ($meanStdevs[$i] - $meanStdevStats->mean()) / $meanStdevStats->standard_deviation() >
    118              REJECT_MEAN_STDEV->{$detType}) {
     132             REJECT_MEAN_STDEV->{$det_type}) {
    119133        print "Rejecting $expId based on bad stdev: " .
    120134            (($meanStdevs[$i] - $meanStdevStats->mean()) / $meanStdevStats->standard_deviation()) .
    121             " vs " . REJECT_MEAN_STDEV->{$detType} . "\n";
     135            " vs " . REJECT_MEAN_STDEV->{$det_type} . "\n";
    122136        $reject = 1;
    123137    }
     
    147161# Put the result into the database
    148162{
    149     my $command = "$dettool -adddetrunsummary -det_id $detId -iteration $iter " .
     163    my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter " .
    150164        "-bg " . $meanStats->mean() . " -bg_stdev " . $stdevStats->mean() .
    151165        " -bg_mean_stdev " . $meanStdevStats->mean();
     
    159173# Re-run processing if required
    160174{
    161     my $command = "$dettool -updatedetrun -det_id $detId";
     175    my $command = "$dettool -updatedetrun -det_id $det_id";
    162176    if ($stop) {
    163177        $command .= ' -stop';
Note: See TracChangeset for help on using the changeset viewer.