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/detrend_norm_apply.pl

    r13989 r14009  
    1111print "Starting script $0 on $host\n\n";
    1212
     13use vars qw( $VERSION );
     14$VERSION = '0.01';
     15
     16use IPC::Cmd 0.36 qw( can_run run );
     17use PS::IPP::Metadata::Config;
    1318use PS::IPP::Metadata::Stats;
    14 use IPC::Cmd 0.36 qw( can_run run );
    15 use Data::Dumper;
    1619
    1720use PS::IPP::Config qw($PS_EXIT_SUCCESS
     
    3033
    3134# Parse the command-line
    32 my ($det_id,                     # Detrend ID
    33     $iter,                      # Iteration
    34     $class_id,                  # Class ID
    35     $value,                     # Value to multiple (for normalisation)
    36     $input,                     # Input file
    37     $camera,                    # Camera
    38     $det_type,                  # Detrend type
    39     $dbname,                    # Database name
    40     $workdir,                   # Working directory, for output files
    41     $no_update,                 # Don't update the database
    42     $no_op,                     # Don't do any operations
    43     );
     35my ($det_id, $iter, $class_id, $value, $input_uri, $camera, $det_type, $dbname, $workdir, $no_update, $no_op);
    4436GetOptions(
    45     'det_id|d=s'        => \$det_id,
    46     'iteration|n=s'     => \$iter,
    47     'class_id|i=s'      => \$class_id,
    48     'value|v=s'         => \$value,
    49     'input_uri|u=s'     => \$input,
    50     'camera|c=s'        => \$camera,
    51     'det_type|t=s'      => \$det_type,
    52     'dbname|d=s'        => \$dbname,
    53     'workdir|w=s'       => \$workdir, # Working directory, for output files
    54     'no-update'         => \$no_update,
    55     'no-op'             => \$no_op,
     37    'det_id|d=s'        => \$det_id,     # Detrend ID                           
     38    'iteration|n=s'     => \$iter,       # Iteration                           
     39    'class_id|i=s'      => \$class_id,   # Class ID                             
     40    'value|v=s'         => \$value,      # Value to multiple (for normalisation)       
     41    'input_uri|u=s'     => \$input_uri,  # Input file                           
     42    'camera|c=s'        => \$camera,     # Camera                               
     43    'det_type|t=s'      => \$det_type,   # Detrend type                         
     44    'dbname|d=s'        => \$dbname,     # Database name                               
     45    'workdir|w=s'       => \$workdir,    # Working directory, for output files 
     46    'no-update'         => \$no_update,  # Don't update the database           
     47    'no-op'             => \$no_op,      # Don't do any operations               
    5648    ) or pod2usage( 2 );
    5749   
    5850pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5951pod2usage( -msg => "Required options: --det_id --iteration --class_id --value --input_uri --camera --det_type",
    60     -exitval => 3,
    61     ) unless defined $det_id
     52           -exitval => 3)
     53    unless defined $det_id
    6254    and defined $iter
    6355    and defined $class_id
    6456    and defined $value
    65     and defined $input
     57    and defined $input_uri
    6658    and defined $camera
    6759    and defined $det_type;
     
    6961$ipprc->define_camera($camera);
    7062
    71 
    7263my $RECIPE_PPIMAGE = 'PPIMAGE_N'; # Recipe to use with ppImage
    7364my $RECIPE_PPSTATS = 'CHIPSTATS'; # Recipe to use with ppStats
     65
     66# values to extract from output metadata and the stats to calculate
     67my $STATS =
     68   [   
     69       #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
     70       { name => "ROBUST_MEDIAN",  type => "mean",  flag => "-bg" },
     71       { name => "ROBUST_MEDIAN",  type => "stdev", flag => "-bg_mean_stdev" },
     72       { name => "ROBUST_STDEV",   type => "rms",   flag => "-bg_stdev" },
     73   ];
    7474
    7575# Look for programs we need
     
    7777my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    7878my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    79 
    8079if ($missing_tools) {
    8180    warn("Can't find required tools.");
     
    8382}
    8483
     84&my_die("Couldn't find input file: $input_uri\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
     85
    8586$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
    8687
    87 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir, $input );
    88 my $output = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    89 my $b1name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
    90 my $b2name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
    91 my $statsName = $outputRoot . '.' . $class_id . '.stats'; # Statistics file
     88my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir, $input_uri );
     89
     90my $output    = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
     91my $b1name    = $ipprc->filename("PPIMAGE.BIN1",   $outputRoot, $class_id);
     92my $b2name    = $ipprc->filename("PPIMAGE.BIN2",   $outputRoot, $class_id);
     93my $statsName = $ipprc->filename("PPIMAGE.STATS",  $outputRoot, $class_id);
    9294
    9395# Run normalisation
    94 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    9596unless ($no_op) {
    96     my $command = "$ppImage -file $input $outputRoot";
     97    my $command = "$ppImage -file $input_uri $outputRoot";
    9798    $command .= " -norm $value -stats $statsName";
    9899    $command .= " -recipe PPIMAGE $RECIPE_PPIMAGE";
     
    117118    my @contents = <$statsFile>; # Contents of file
    118119    close $statsFile;
     120
     121    # parse the statistics MDC file
    119122    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    120     my $metadata = $mdcParser->parse(join "", @contents)
    121         or &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    122     $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     123    my $metadata = $mdcParser->parse(join "", @contents);
     124    unless ($metadata) {
     125        &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     126    }
     127
     128    # extract the stats from the metadata
     129    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
     130    unless ($stats->parse($metadata)) {
     131        &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     132    }
    123133}
    124134
    125 # Update the database
    126 my $bg            = $stats->bg_mean();
    127 my $bg_stdev      = $stats->bg_stdev();
    128 my $bg_mean_stdev = $stats->bg_mean_stdev();
     135# Command to update the database
     136my $command = "$dettool -addnormalizedimfile";
     137$command .= " -det_id $det_id";
     138$command .= " -iteration $iter";
     139$command .= " -class_id $class_id";
     140$command .= " -uri $output";
     141$command .= " -path_base $outputRoot";
     142$command .= " -dbname $dbname" if defined $dbname;
    129143
     144# add in the elements from the selected stats above
     145foreach my $entry (@$STATS) {
     146    my $value = $entry->{value};
     147    my $flag = $entry->{flag};
     148    $command .= " $flag $value";
     149}
     150
     151# Add the processed file to the database
    130152unless ($no_update) {
    131     my $command = "$dettool -addnormalizedimfile -det_id $det_id -iteration $iter -class_id $class_id ".
    132         "-uri $output -path_base $outputRoot"; # Command to run
    133     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
    134     $command .= " -dbname $dbname" if defined $dbname;
    135 
    136153    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    137154        run(command => $command, verbose => 1);
     
    141158        exit($error_code);
    142159    }
     160} else {
     161    print "skipping command: $command\n";
    143162}
    144163
     
    153172    carp($msg);
    154173    if ($det_id and $iter and $class_id and not $no_update) {
    155         my $command = "$dettool -addnormalizedimfile -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code";
     174        my $command = "$dettool -addnormalizedimfile";
     175        $command .= " -det_id $det_id";
     176        $command .= " -iteration $iter";
     177        $command .= " -class_id $class_id";
     178        $command .= " -code $exit_code";
    156179        $command .= " -dbname $dbname" if defined $dbname;
    157180###        system ($command);
Note: See TracChangeset for help on using the changeset viewer.