IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 4, 2007, 1:53:22 PM (19 years ago)
Author:
eugene
Message:

extensive changes to use new stats calculation tools; general cleanups

File:
1 edited

Legend:

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

    r13989 r14009  
    11#!/usr/bin/env perl
    22
     3use Carp;
    34use warnings;
    45use strict;
    5 use Carp;
    66
    77## report the program and machine
     
    1111print "Starting script $0 on $host\n\n";
    1212
     13use vars qw( $VERSION );
     14$VERSION = '0.01';
     15
    1316use IPC::Cmd 0.36 qw( can_run run );
    1417use PS::IPP::Metadata::Config;
    1518use PS::IPP::Metadata::Stats;
    16 use Data::Dumper;
     19
    1720use PS::IPP::Config qw($PS_EXIT_SUCCESS
    1821                       $PS_EXIT_UNKNOWN_ERROR
     
    3033
    3134# Parse the command-line arguments
    32 my ($exp_id,                    # Exposure identifier
    33     $chip_id,                   # Chiptool identifier
    34     $class_id,                  # Class identifier
    35     $input,                     # Input FITS file
    36     $camera,                    # Camera
    37     $dbname,                    # Database name
    38     $workdir,                   # Working directory, for output files
    39     $reduction,                 # Reduction class
    40     $no_update,                 # Don't update the database?
    41     $no_op,                     # Don't do any operations?
    42     );
     35my ($exp_id, $chip_id, $class_id, $input_uri, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
    4336GetOptions(
    44            'exp_id=s'      => \$exp_id,
    45            'chip_id=s'     => \$chip_id,
    46            'class_id=s'    => \$class_id,
    47            'uri|u=s'       => \$input,
    48            'camera|c=s'    => \$camera,
    49            'dbname|d=s'    => \$dbname, # Database name
    50            'workdir|w=s'   => \$workdir,
    51            'reduction=s'   => \$reduction,
    52            'no-update'     => \$no_update,
    53            'no-op'         => \$no_op,
     37           'exp_id=s'      => \$exp_id,    # Exposure identifier                       
     38           'chip_id=s'     => \$chip_id,   # Chiptool identifier                       
     39           'class_id=s'    => \$class_id,  # Class identifier                 
     40           'input_uri|u=s' => \$input_uri, # Input FITS file                   
     41           'camera|c=s'    => \$camera,    # Camera                           
     42           'dbname|d=s'    => \$dbname,    # Database name
     43           'workdir|w=s'   => \$workdir,   # Working directory, for output files 
     44           'reduction=s'   => \$reduction, # Reduction class                   
     45           'no-update'     => \$no_update, # Don't update the database?       
     46           'no-op'         => \$no_op,     # Don't do any operations?             
    5447           ) or pod2usage( 2 );
    5548
    5649pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    57 pod2usage(
    58     -msg => "Required options: --exp_id --chip_id --class_id --uri --camera",
    59     -exitval => 3,
    60 ) unless defined $exp_id
     50pod2usage( -msg => "Required options: --exp_id --chip_id --class_id --uri --camera",
     51           -exitval => 3)
     52    unless defined $exp_id
    6153    and defined $chip_id
    6254    and defined $class_id
    63     and defined $input
     55    and defined $input_uri
    6456    and defined $camera;
    6557
    6658$ipprc->define_camera($camera);
     59
     60# Recipes to use based on reduction class
    6761$reduction = 'DEFAULT' unless defined $reduction;
    6862my $recipe = $ipprc->reduction($reduction, 'CHIP'); # Recipe to use
     63
     64# values to extract from output metadata and the stats to calculate
     65my $STATS =
     66   [   
     67       #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
     68       { name => "ROBUST_MEDIAN",  type => "mean",  flag => "-bg" },
     69       { name => "ROBUST_MEDIAN",  type => "stdev", flag => "-bg_mean_stdev" },
     70       { name => "ROBUST_STDEV",   type => "rms",   flag => "-bg_stdev" },
     71       { name => "FRINGE_0",       type => "rms",   flag => "-fringe_0" },
     72       { name => "FRINGE_RESID_0", type => "rms",   flag => "-fringe_1" },
     73       { name => "FRINGE_ERR_0",   type => "rms",   flag => "-fringe_2" },
     74       { name => "OVER_VAL",       type => "mean",  flag => "-bias" },
     75       { name => "FWHM",           type => "mean",  flag => "-fwhm" },
     76       { name => "APMIFIT",        type => "mean",  flag => "-ap_resid" },
     77       { name => "DAPMIFIT",       type => "rms",   flag => "-ap_resid_stdev" },
     78       { name => "CERROR",         type => "rms",   flag => "-sigma_ra" },
     79       { name => "CERROR",         type => "rms",   flag => "-sigma_dec" },
     80       { name => "NSTARS",         type => "sum",   flag => "-n_stars" },
     81       { name => "NASTRO",         type => "sum",   flag => "-n_astrom" },
     82   ];
    6983
    7084# Look for programs we need
     
    7690    exit($PS_EXIT_CONFIG_ERROR);
    7791}
    78 $ppImage .= " -dbname $dbname" if defined $dbname;
    79 
    80 &my_die("Couldn't find input file: $input\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
     92
     93&my_die("Couldn't find input file: $input_uri\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
    8194
    8295$workdir = caturi( $workdir, $exp_id ) if defined $workdir;
    8396
    84 my $outputRoot = $ipprc->file_prepare( "$exp_id.chp$chip_id", $workdir, $input );
    85 my $outputImage = $ipprc->filename("PPIMAGE.CHIP", $outputRoot, $class_id);
    86 my $outputMask = $ipprc->filename("PPIMAGE.CHIP.MASK", $outputRoot, $class_id);
    87 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
    88 my $outputBin2 = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
    89 my $outputStats = $outputRoot  . '.' . $class_id . '.stats';
    90 
    91 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
     97my $outputRoot  = $ipprc->file_prepare( "$exp_id.chp$chip_id", $workdir, $input_uri );
     98
     99my $outputImage = $ipprc->filename("PPIMAGE.CHIP",      $outputRoot, $class_id);
     100my $outputMask  = $ipprc->filename("PPIMAGE.CHIP.MASK", $outputRoot, $class_id);
     101my $outputBin1  = $ipprc->filename("PPIMAGE.BIN1",      $outputRoot, $class_id);
     102my $outputBin2  = $ipprc->filename("PPIMAGE.BIN2",      $outputRoot, $class_id);
     103my $outputStats = $ipprc->filename("PPIMAGE.STATS",     $outputRoot, $class_id);
     104
     105# Run ppImage
    92106unless ($no_op) {
    93     # Run ppImage
    94     print "outputImage: $outputImage\n";
    95     print "outputBin1: $outputBin1\n";
    96     print "outputStats: $outputStats\n";
    97 
    98     my $command = "$ppImage -file $input $outputRoot";
     107    my $command = "$ppImage -file $input_uri $outputRoot";
    99108    $command .= " -recipe PPIMAGE $recipe";
    100109    $command .= " -recipe PPSTATS CHIPSTATS";
    101     $command .= " -stats $outputStats"; # Command to run ppImage
     110    $command .= " -stats $outputStats";
     111    $command .= " -dbname $dbname" if defined $dbname;
    102112
    103113    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    119129    my @contents = <$statsFile>; # Contents of file
    120130    close $statsFile;
    121     my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    122     my $metadata = $mdcParser->parse(join "", @contents) or
     131
     132    # parse the statistics MDC file
     133    my $mdcParser = PS::IPP::Metadata::Config->new();   # Parser for metadata config files
     134    my $metadata = $mdcParser->parse(join "", @contents);
     135    unless ($metadata) {
    123136        &my_die("Unable to parse metadata config doc", $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
    124     $stats->parse($metadata) or
     137    }
     138
     139    # extract the stats from the metadata
     140    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
     141    unless ($stats->parse($metadata)) {
    125142        &my_die("Unable to find all values in statistics output.\n", $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
     143    }
     144}
     145
     146# command to update database
     147my $command = "$chiptool -addprocessedimfile";
     148$command .= " -chip_id $chip_id";
     149$command .= " -class_id $class_id";
     150$command .= " -uri $outputImage";
     151$command .= " -path_base $outputRoot";
     152$command .= " -dbname $dbname" if defined $dbname;
     153
     154# add in the elements from the selected stats above
     155foreach my $entry (@$STATS) {
     156    my $value = $entry->{value};
     157    my $flag = $entry->{flag};
     158    $command .= " $flag $value";
    126159}
    127160
    128161# Add the processed file to the database
    129 my $bg            = $stats->bg_mean();
    130 my $bg_stdev      = $stats->bg_stdev();
    131 my $bg_mean_stdev = $stats->bg_mean_stdev();
    132 my $fringe_0      = ${$stats->fringe_mean()}[0];
    133 my $fringe_1      = ${$stats->fringe_err()}[0];
    134 my $fringe_2      = ${$stats->fringe_mean_stdev()}[0];
    135 my $dfringe_0     = ${$stats->dfringe_mean()}[0];
    136 my $dfringe_1     = ${$stats->dfringe_err()}[0];
    137 my $dfringe_2     = ${$stats->dfringe_mean_stdev()}[0];
    138 
    139162unless ($no_update) {
    140     # Command to run chiptool
    141     my $command = "$chiptool -addprocessedimfile";
    142     $command .= " -chip_id $chip_id";
    143     $command .= " -class_id $class_id";
    144     $command .= " -uri $outputImage";
    145     $command .= " -path_base $outputRoot";
    146     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
    147     $command .= " -fringe_0 $fringe_0 -fringe_1 $fringe_1 -fringe_2 $fringe_2";
    148     $command .= " -user_1 $dfringe_0 -user_2 $dfringe_1 -user_3 $dfringe_2";
    149     # XXX add sigma_ra, etc here
    150     $command .= " -dbname $dbname" if defined $dbname;
    151 
    152163    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    153164        run(command => $command, verbose => 1);
     
    157168        exit($error_code);
    158169    }
    159 }
    160 
     170} else {
     171    print "skipping command: $command\n";
     172}
    161173
    162174sub my_die
Note: See TracChangeset for help on using the changeset viewer.