Changeset 23209
- Timestamp:
- Mar 6, 2009, 11:22:53 AM (17 years ago)
- Location:
- branches/eam_branches/eam_branch_20090303/ippScripts/scripts
- Files:
-
- 3 edited
-
detrend_norm_apply.pl (modified) (1 diff)
-
detrend_norm_calc.pl (modified) (2 diffs)
-
detrend_resid_exp.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/eam_branch_20090303/ippScripts/scripts/detrend_norm_apply.pl
r22430 r23209 40 40 'iteration|n=s' => \$iter, # Iteration 41 41 'class_id|i=s' => \$class_id, # Class ID 42 'value|v=s' => \$value, # Value to multiple(for normalisation)42 'value|v=s' => \$value, # Value to apply (for normalisation) 43 43 'input_uri|u=s' => \$input_uri, # Input file 44 44 'camera|c=s' => \$camera, # Camera -
branches/eam_branches/eam_branch_20090303/ippScripts/scripts/detrend_norm_calc.pl
r22430 r23209 95 95 my @files; # The input files 96 96 { 97 my $command = "$dettool -processedimfile"; 98 $command .= " -det_id $det_id"; # Command to run 97 my $command = "$dettool -residimfile"; 98 $command .= " -det_id $det_id"; 99 $command .= " -iteration $iter"; 99 100 $command .= " -included"; # only use the inputs for this detrend run to calculate the norm 100 101 $command .= " -dbname $dbname" if defined $dbname; … … 103 104 print "Running [$command]...\n" if $verbose; 104 105 if (not run(\@command, \$stdin, \$stdout, \$stderr)) { 105 &my_die("Unable to perform dettool - processedimfile on detrend $det_id/$iter: $?",106 &my_die("Unable to perform dettool -residimfile on detrend $det_id/$iter: $?", 106 107 $det_id, $iter, $PS_EXIT_SYS_ERROR); 107 108 } -
branches/eam_branches/eam_branch_20090303/ippScripts/scripts/detrend_resid_exp.pl
r22430 r23209 96 96 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe; 97 97 98 # variables used for I/O 99 my ($command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf); 100 101 # Get list of normalizations by class_id : stored as $norms; save to temp file for ppImage runs below 102 my (%norms, $normsName); 103 { 104 # dettool command to select imfile data for this exp_id 105 $command = "$dettool -normalizedstat"; 106 $command .= " -det_id $det_id"; 107 $command .= " -iteration $iter"; 108 $command .= " -dbname $dbname" if defined $dbname; 109 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 110 run(command => $command, verbose => $verbose); 111 unless ($success) { 112 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 113 warn("Unable to perform dettool -residimfile: $error_code\n"); 114 exit($error_code); 115 } 116 if (@$stdout_buf == 0) { 117 &my_die("No normalizations were found", $det_id, $iter, $PS_EXIT_PROG_ERROR); 118 } 119 120 # Parse the stdout buffer into a metadata 121 my $mdcParser = PS::IPP::Metadata::Config->new; 122 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 123 &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 124 125 # parse the file info in the metadata 126 my $normsMD = parse_md_list($metadata) or 127 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 128 129 130 # write the normalizations to a file as a metadata config file in the form: class_id F32 value 131 # XXX a possible optimization: if there is only one imfile, skip normalization 132 my $normsFile; 133 ($normsFile, $normsName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.norms.XXXX", UNLINK => !$save_temps ); 134 print "saving norms to $normsName\n"; 135 foreach my $norm (@$normsMD) { 136 my $class_id = $norm->{class_id}; 137 my $normalization = $norm->{norm}; 138 139 $norms{$class_id} = $normalization; 140 printf $normsFile "$class_id F32 $normalization\n", 141 } 142 close $normsFile; 143 } 144 98 145 # Get list of imfile files 99 146 my $cmdflags; 100 my ( $files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);147 my (@files); 101 148 { 102 149 # dettool command to select imfile data for this exp_id … … 113 160 exit($error_code); 114 161 } 115 # XXX report an error message if stdout_buf is empty 162 if (@$stdout_buf == 0) { 163 &my_die("No imfiles were found", $det_id, $iter, $PS_EXIT_PROG_ERROR); 164 } 116 165 117 166 # Parse the stdout buffer into a metadata … … 120 169 &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 121 170 171 # since I can't figure out how to do input and output within PERL, I'm writing the (modified) metadata to a temp file 172 my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.stats.XXXX", UNLINK => !$save_temps ); 173 122 174 # parse the file info in the metadata 123 $files = parse_md_list($metadata) or 124 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 125 126 # since I can't figure out how to do input and output within PERL, I'm writing to a temp file 127 my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.stats.XXXX", UNLINK => !$save_temps ); 128 print "saving stats to $statName\n"; 129 foreach my $line (@$stdout_buf) { 130 print $statFile $line; 175 # as we parse the list of files and their stats, apply the normalization to the relevant fields 176 # also, write out the modified metadata set 177 foreach my $mdItem (@$metadata) { 178 if ($mdItem->{class} ne "metadata") { 179 carp "MD element ", $mdItem->{name}, " isn't of type METADATA --- ignored.\n"; 180 next; 181 } 182 my %hash; # Hash element 183 my $mdComponents = $mdItem->{value}; # Components of the metadata 184 185 # determine the class_id for this block: 186 my $class_id; 187 foreach my $data (@$mdComponents) { 188 unless ($data->{name} eq "class_id") { next; } 189 $class_id = $data->{value}; 190 last; 191 } 192 193 # a new metadata block 194 print $statFile "rawResidImfile METADATA\n"; 195 196 # modify and save the data in this block: 197 foreach my $data (@$mdComponents) { 198 my $norm = $norms{$class_id}; 199 200 # fields to modify by the normalization: 201 if ($data->{name} eq "bg") { $data->{value} *= $norm; } 202 if ($data->{name} eq "bg_stdev") { $data->{value} *= $norm; } 203 if ($data->{name} eq "bg_mean_stdev") { $data->{value} *= $norm; } 204 if ($data->{name} eq "bg_skewness") { $data->{value} *= $norm; } 205 if ($data->{name} eq "bg_kurtosis") { $data->{value} *= $norm; } 206 if ($data->{name} eq "bin_stdev") { $data->{value} *= $norm; } 207 208 # write out the metadata, save on the array of hashes 209 print $statFile " $data->{name} $data->{type} $data->{value}\n"; 210 $hash{$data->{name}} = $data->{value}; 211 } 212 print $statFile "END\n"; 213 push @files, \%hash; 131 214 } 132 215 close $statFile; … … 162 245 my ($list1File, $list1Name) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.b1.list.XXXX", UNLINK => !$save_temps ); 163 246 my ($list2File, $list2Name) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.b2.list.XXXX", UNLINK => !$save_temps ); 164 foreach my $file (@ $files) {247 foreach my $file (@files) { 165 248 print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n"); 166 249 print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n"); … … 173 256 unless ($no_op) { 174 257 # Make the jpeg for binning 1 258 # XXX EAM : supply the collection of normalizations as a metadata 175 259 $command = "$ppImage -list $list1Name $outroot"; # Command to run 176 260 $command .= " -recipe PPIMAGE PPIMAGE_J1"; 177 261 $command .= " -recipe JPEG $recipe"; 262 $command .= " -normlist $normsName"; 178 263 $command .= " -dbname $dbname" if defined $dbname; 179 264 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 186 271 187 272 # Make the jpeg for binning 2 273 # XXX EAM : supply the collection of normalizations as a metadata 188 274 $command = "$ppImage -list $list2Name $outroot"; # Command to run 189 275 $command .= " -recipe PPIMAGE PPIMAGE_J2"; 190 276 $command .= " -recipe JPEG $recipe"; 277 $command .= " -normlist $normsName"; 191 278 $command .= " -dbname $dbname" if defined $dbname; 192 279 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 223 310 my @fluxes; 224 311 225 foreach my $file (@ $files) {312 foreach my $file (@files) { 226 313 my $name = $file->{class_id}; 227 314 my $mean = $file->{bg}; # Mean for this imfile
Note:
See TracChangeset
for help on using the changeset viewer.
