Changeset 23229 for trunk/ippScripts/scripts/detrend_resid_exp.pl
- Timestamp:
- Mar 8, 2009, 4:50:46 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/detrend_resid_exp.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/eam_branches/eam_branch_20090303 merged eligible
-
Property svn:mergeinfo
set to
-
trunk/ippScripts/scripts/detrend_resid_exp.pl
r23186 r23229 88 88 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe; 89 89 90 # variables used for I/O 91 my ($command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf); 92 93 # Get list of normalizations by class_id : stored as $norms; save to temp file for ppImage runs below 94 my (%norms, $normsName); 95 { 96 # dettool command to select imfile data for this exp_id 97 $command = "$dettool -normalizedstat"; 98 $command .= " -det_id $det_id"; 99 $command .= " -iteration $iter"; 100 $command .= " -dbname $dbname" if defined $dbname; 101 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 102 run(command => $command, verbose => $verbose); 103 unless ($success) { 104 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 105 warn("Unable to perform dettool -residimfile: $error_code\n"); 106 exit($error_code); 107 } 108 if (@$stdout_buf == 0) { 109 &my_die("No normalizations were found", $det_id, $iter, $PS_EXIT_PROG_ERROR); 110 } 111 112 # Parse the stdout buffer into a metadata 113 my $mdcParser = PS::IPP::Metadata::Config->new; 114 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 115 &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 116 117 # parse the file info in the metadata 118 my $normsMD = parse_md_list($metadata) or 119 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 120 121 122 # write the normalizations to a file as a metadata config file in the form: class_id F32 value 123 # XXX a possible optimization: if there is only one imfile, skip normalization 124 my $normsFile; 125 ($normsFile, $normsName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.norms.XXXX", UNLINK => !$save_temps ); 126 print "saving norms to $normsName\n"; 127 foreach my $norm (@$normsMD) { 128 my $class_id = $norm->{class_id}; 129 my $normalization = $norm->{norm}; 130 131 $norms{$class_id} = $normalization; 132 printf $normsFile "$class_id F32 $normalization\n", 133 } 134 close $normsFile; 135 } 136 90 137 # Get list of imfile files 91 138 my $cmdflags; 92 my ( $files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);139 my (@files); 93 140 { 94 141 # dettool command to select imfile data for this exp_id … … 105 152 exit($error_code); 106 153 } 107 # XXX report an error message if stdout_buf is empty 154 if (@$stdout_buf == 0) { 155 &my_die("No imfiles were found", $det_id, $iter, $PS_EXIT_PROG_ERROR); 156 } 108 157 109 158 # Parse the stdout buffer into a metadata … … 112 161 &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 113 162 163 # since I can't figure out how to do input and output within PERL, I'm writing the (modified) metadata to a temp file 164 my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.stats.XXXX", UNLINK => !$save_temps ); 165 114 166 # parse the file info in the metadata 115 $files = parse_md_list($metadata) or 116 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR); 117 118 # since I can't figure out how to do input and output within PERL, I'm writing to a temp file 119 my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.stats.XXXX", UNLINK => !$save_temps ); 120 print "saving stats to $statName\n"; 121 foreach my $line (@$stdout_buf) { 122 print $statFile $line; 167 # as we parse the list of files and their stats, apply the normalization to the relevant fields 168 # also, write out the modified metadata set 169 foreach my $mdItem (@$metadata) { 170 if ($mdItem->{class} ne "metadata") { 171 carp "MD element ", $mdItem->{name}, " isn't of type METADATA --- ignored.\n"; 172 next; 173 } 174 my %hash; # Hash element 175 my $mdComponents = $mdItem->{value}; # Components of the metadata 176 177 # determine the class_id for this block: 178 my $class_id; 179 foreach my $data (@$mdComponents) { 180 unless ($data->{name} eq "class_id") { next; } 181 $class_id = $data->{value}; 182 last; 183 } 184 185 # a new metadata block 186 print $statFile "rawResidImfile METADATA\n"; 187 188 # modify and save the data in this block: 189 foreach my $data (@$mdComponents) { 190 my $norm = $norms{$class_id}; 191 192 # fields to modify by the normalization: 193 if ($data->{name} eq "bg") { $data->{value} *= $norm; } 194 if ($data->{name} eq "bg_stdev") { $data->{value} *= $norm; } 195 if ($data->{name} eq "bg_mean_stdev") { $data->{value} *= $norm; } 196 if ($data->{name} eq "bg_skewness") { $data->{value} *= $norm; } 197 if ($data->{name} eq "bg_kurtosis") { $data->{value} *= $norm; } 198 if ($data->{name} eq "bin_stdev") { $data->{value} *= $norm; } 199 200 # write out the metadata, save on the array of hashes 201 print $statFile " $data->{name} $data->{type} $data->{value}\n"; 202 $hash{$data->{name}} = $data->{value}; 203 } 204 print $statFile "END\n"; 205 push @files, \%hash; 123 206 } 124 207 close $statFile; … … 154 237 my ($list1File, $list1Name) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.b1.list.XXXX", UNLINK => !$save_temps ); 155 238 my ($list2File, $list2Name) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.b2.list.XXXX", UNLINK => !$save_temps ); 156 foreach my $file (@ $files) {239 foreach my $file (@files) { 157 240 print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n"); 158 241 print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n"); … … 165 248 unless ($no_op) { 166 249 # Make the jpeg for binning 1 250 # XXX EAM : supply the collection of normalizations as a metadata 167 251 $command = "$ppImage -list $list1Name $outroot"; # Command to run 168 252 $command .= " -recipe PPIMAGE PPIMAGE_J1"; 169 253 $command .= " -recipe JPEG $recipe"; 254 $command .= " -normlist $normsName"; 170 255 $command .= " -dbname $dbname" if defined $dbname; 171 256 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 178 263 179 264 # Make the jpeg for binning 2 265 # XXX EAM : supply the collection of normalizations as a metadata 180 266 $command = "$ppImage -list $list2Name $outroot"; # Command to run 181 267 $command .= " -recipe PPIMAGE PPIMAGE_J2"; 182 268 $command .= " -recipe JPEG $recipe"; 269 $command .= " -normlist $normsName"; 183 270 $command .= " -dbname $dbname" if defined $dbname; 184 271 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 215 302 my @fluxes; 216 303 217 foreach my $file (@ $files) {304 foreach my $file (@files) { 218 305 my $name = $file->{class_id}; 219 306 my $mean = $file->{bg}; # Mean for this imfile
Note:
See TracChangeset
for help on using the changeset viewer.
