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_create_resid.pl

    r8715 r8763  
    33use warnings;
    44use strict;
     5
     6use vars qw( $VERSION );
     7$VERSION = '0.01';
    58
    69use IPC::Cmd qw( can_run run );
     
    912use Data::Dumper;
    1013
     14use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     15use Pod::Usage qw( pod2usage );
     16
     17my ($det_id, $iter, $exp_id, $class_id, $det_type, $detrend,
     18        $input_uri, $output_uri);
     19GetOptions(
     20    'det_id|d=s'        => \$det_id,
     21    'iteration=s'       => \$iter,
     22    'exp_id|e=s'        => \$exp_id,
     23    'class_id|i=s'      => \$class_id,
     24    'det_type|t=s'      => \$det_type,
     25    'detrend=s'         => \$detrend,
     26    'input_uri|u=s'     => \$input_uri,
     27    'output_uri|o=s'    => \$output_uri,
     28) or pod2usage( 2 );
     29
     30pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     31pod2usage(
     32    -msg => "Required options: --det_id --iteration --exp_id --class_id --det_type --detrend --input_uri --output_uri",
     33    -exitval => 3,
     34) unless defined $det_id
     35    and defined $iter
     36    and defined $exp_id
     37    and defined $class_id
     38    and defined $det_type
     39    and defined $detrend
     40    and defined $input_uri
     41    and defined $output_uri;
    1142
    1243# Recipes to use, as a function of the detrend type
     
    3465use constant DELETE_STATS => 0; # Delete the statistics file when done?
    3566
    36 # Parse the command-line arguments
    37 if (scalar @ARGV != 8) {
    38     die "Apply a stacked detrend image to an individual detrend.\n\n" .
    39         "Usage: $0 DET_ID ITERATION EXP_ID CLASS_ID DETREND_TYPE DETREND.fits INPUT.fits OUTPUT_ROOT\n\n";
    40 }
    41 my $detId = shift @ARGV;        # Detrend ID
    42 my $iter = shift @ARGV;         # Iteration
    43 my $expId = shift @ARGV;        # Exposure ID
    44 my $classId = shift @ARGV;      # Class ID
    45 my $detType = shift @ARGV;      # Detrend type
    46 my $detrend = shift @ARGV;      # The detrend frame to apply
    47 my $input = shift @ARGV;        # Input FITS file
    48 my $output = shift @ARGV;       # Output root name
    49 
    5067# Look for programs we need
    5168my $missing_tools;
     
    5572
    5673# Recipe to use in processing
    57 my $recipe = RECIPES->{$detType};
    58 die "Unrecognised detrend type: $detType\n" if not defined $recipe;
     74my $recipe = RECIPES->{$det_type};
     75die "Unrecognised detrend type: $det_type\n" if not defined $recipe;
    5976# Detrend to use in processing
    60 my $detFlag = DETRENDS->{$detType};
    61 die "Unrecognised detrend type: $detType\n" if not defined $detFlag;
     77my $detFlag = DETRENDS->{$det_type};
     78die "Unrecognised detrend type: $det_type\n" if not defined $detFlag;
    6279# Prefix to use for filename
    63 my $prefix = PREFIX->{$detType};
    64 die  "Unrecognised detrend type: $detType\n" if not defined $prefix;
     80my $prefix = PREFIX->{$det_type};
     81die  "Unrecognised detrend type: $det_type\n" if not defined $prefix;
    6582
    6683### Output file names --- must match camera configuration!
    67 my $outputRoot = $prefix . '_' . $output;
    68 my $outputName = $outputRoot . '.' . $classId . '.fit';
    69 my $outputStats = $outputRoot . '.' . $classId . '.stats';
    70 my $bin1Name = $outputRoot . '.' . $classId . '.b1.fit';
    71 my $bin2Name =  $outputRoot . '.' . $classId . '.b2.fit';
     84my $outputRoot = $prefix . '_' . $output_uri;
     85my $outputName = $outputRoot . '.' . $class_id . '.fit';
     86my $outputStats = $outputRoot . '.' . $class_id . '.stats';
     87my $bin1Name = $outputRoot . '.' . $class_id . '.b1.fit';
     88my $bin2Name =  $outputRoot . '.' . $class_id . '.b2.fit';
    7289
    7390# Run ppImage
    7491{
    75     my $command = "$ppImage -file $input $outputRoot -recipe PPIMAGE $recipe" .
     92    my $command = "$ppImage -file $input_uri $outputRoot -recipe PPIMAGE $recipe" .
    7693        " -stat $outputStats $detFlag $detrend"; # Command to run ppImage
    7794    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    7895        run(command => $command, verbose => 1);
    79     die "Unable to perform ppImage on $input: $error_code\n" if not $success;
     96    die "Unable to perform ppImage on $input_uri: $error_code\n" if not $success;
    8097    die "Couldn't find expected output file: $outputName\n" if not -f $outputName;
    8198    die "Couldn't find expected output file: $bin1Name\n" if not -f $bin1Name;
     
    99116# Add the processed file to the database
    100117{
    101     my $command = "$dettool -addresidimfile -det_id $detId -iteration $iter -exp_id $expId " .
    102         "-class_id $classId -recip $recipe -uri $outputName -b1_uri $bin1Name " .
     118    my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter -exp_id $exp_id " .
     119        "-class_id $class_id -recip $recipe -uri $outputName -b1_uri $bin1Name " .
    103120        "-b2_uri $bin2Name"; # Command to run dettool
    104121    $command .= " -bg " . $stats->bg_mean();
     
    108125    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    109126        run(command => $command, verbose => 1);
    110     die "Unable to perform dettool -addprocessed for $detId/$expId/$classId: $error_code\n"
     127    die "Unable to perform dettool -addprocessed for $det_id/$exp_id/$class_id: $error_code\n"
    111128        if not $success;
    112129}
    113130
    114 unlink "$output.stats" if DELETE_STATS;
     131unlink "$output_uri.stats" if DELETE_STATS;
    115132
    116133__END__
Note: See TracChangeset for help on using the changeset viewer.