Changeset 14009 for trunk/ippScripts/scripts/detrend_norm_apply.pl
- Timestamp:
- Jul 4, 2007, 1:53:22 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/detrend_norm_apply.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_norm_apply.pl
r13989 r14009 11 11 print "Starting script $0 on $host\n\n"; 12 12 13 use vars qw( $VERSION ); 14 $VERSION = '0.01'; 15 16 use IPC::Cmd 0.36 qw( can_run run ); 17 use PS::IPP::Metadata::Config; 13 18 use PS::IPP::Metadata::Stats; 14 use IPC::Cmd 0.36 qw( can_run run );15 use Data::Dumper;16 19 17 20 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 30 33 31 34 # 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 ); 35 my ($det_id, $iter, $class_id, $value, $input_uri, $camera, $det_type, $dbname, $workdir, $no_update, $no_op); 44 36 GetOptions( 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 files54 '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 56 48 ) or pod2usage( 2 ); 57 49 58 50 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 59 51 pod2usage( -msg => "Required options: --det_id --iteration --class_id --value --input_uri --camera --det_type", 60 -exitval => 3, 61 )unless defined $det_id52 -exitval => 3) 53 unless defined $det_id 62 54 and defined $iter 63 55 and defined $class_id 64 56 and defined $value 65 and defined $input 57 and defined $input_uri 66 58 and defined $camera 67 59 and defined $det_type; … … 69 61 $ipprc->define_camera($camera); 70 62 71 72 63 my $RECIPE_PPIMAGE = 'PPIMAGE_N'; # Recipe to use with ppImage 73 64 my $RECIPE_PPSTATS = 'CHIPSTATS'; # Recipe to use with ppStats 65 66 # values to extract from output metadata and the stats to calculate 67 my $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 ]; 74 74 75 75 # Look for programs we need … … 77 77 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1); 78 78 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1); 79 80 79 if ($missing_tools) { 81 80 warn("Can't find required tools."); … … 83 82 } 84 83 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 85 86 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 86 87 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 88 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir, $input_uri ); 89 90 my $output = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id); 91 my $b1name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 92 my $b2name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 93 my $statsName = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id); 92 94 93 95 # Run normalisation 94 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser95 96 unless ($no_op) { 96 my $command = "$ppImage -file $input $outputRoot";97 my $command = "$ppImage -file $input_uri $outputRoot"; 97 98 $command .= " -norm $value -stats $statsName"; 98 99 $command .= " -recipe PPIMAGE $RECIPE_PPIMAGE"; … … 117 118 my @contents = <$statsFile>; # Contents of file 118 119 close $statsFile; 120 121 # parse the statistics MDC file 119 122 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 } 123 133 } 124 134 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 136 my $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; 129 143 144 # add in the elements from the selected stats above 145 foreach 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 130 152 unless ($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 run133 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";134 $command .= " -dbname $dbname" if defined $dbname;135 136 153 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 137 154 run(command => $command, verbose => 1); … … 141 158 exit($error_code); 142 159 } 160 } else { 161 print "skipping command: $command\n"; 143 162 } 144 163 … … 153 172 carp($msg); 154 173 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"; 156 179 $command .= " -dbname $dbname" if defined $dbname; 157 180 ### system ($command);
Note:
See TracChangeset
for help on using the changeset viewer.
