Changeset 24687
- Timestamp:
- Jul 6, 2009, 12:56:24 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/magic_destreak.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/magic_destreak.pl
r24553 r24687 29 29 my $magicdstool = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1); 30 30 my $streaksremove = can_run('streaksremove') or (warn "Can't find streaksremove" and $missing_tools = 1); 31 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); 32 # XXX: replace with real name for tool 33 my $censordetections = ""; 34 # my $censordetections = can_run('censordetections') or (warn "Can't find censordetections" and $missing_tools = 1); 31 35 if ($missing_tools) { 32 36 warn("Can't find required tools."); … … 89 93 } elsif ($stage eq "diff") { 90 94 $skycell_id = $component; 91 } els e{95 } elsif ($stage ne "camera") { 92 96 &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 93 97 } … … 159 163 } 160 164 161 # get skycell list if needed 162 my ($sfh, $skycell_list); 163 if ($skycell_args) { 164 my $command = "$magicdstool -magic_ds_id $magic_ds_id -getskycells $skycell_args"; 165 $command .= " -dbname $dbname" if defined $dbname; 166 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 167 run(command => $command, verbose => $verbose); 168 unless ($success) { 169 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 170 &my_die("Unable to perform magicdstool -diffskyfile $skycell_args: $error_code", $magic_ds_id, $component, $error_code); 171 } 172 173 my $getskycells_output = join "", @$stdout_buf; 174 if ($getskycells_output) { 175 my $metadata = $mdcParser->parse($getskycells_output) or 176 &my_die("Unable to parse metadata config doc", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR); 177 178 my $skycells = parse_md_list($metadata) or 179 &my_die("Unable to parse metadata list", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR); 180 181 ($sfh, $skycell_list) = tempfile( "/tmp/skycell_list.XXXX", UNLINK => !$save_temps); 182 183 foreach my $skycell (@$skycells) { 184 my $skycell_uri = $ipprc->filename("PPSUB.OUTPUT", $skycell->{path_base}); 185 print $sfh "$skycell_uri\n"; 186 } 187 close $sfh; 188 } 189 } 190 191 my ($image, $mask, $ch_mask, $weight, $astrom); 192 193 if ($stage eq "raw") { 194 $image = $uri; 195 $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base); 196 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id) if $release ; 197 } elsif ($stage eq "chip") { 198 # we use the mask output from the camera stage for input and replace 199 # the output of the chip stage with that mask as well. 200 $image = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id); 201 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id); 202 $ch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id); 203 $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id); 204 $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base); 205 } elsif ($stage eq "warp") { 206 $image = $ipprc->filename("PSWARP.OUTPUT", $path_base); 207 $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base); 208 $weight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $path_base); 209 } elsif ($stage eq "diff") { 210 my $name = $inverse ? "PPSUB.INVERSE" : "PPSUB.OUTPUT"; # Base name for images 211 $image = $ipprc->filename($name, $path_base); 212 $mask = $ipprc->filename("$name.MASK", $path_base); 213 $weight = $ipprc->filename("$name.VARIANCE", $path_base); 214 } 215 216 { 217 my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image"; 218 219 $command .= " -class_id $class_id" if defined $class_id; 220 $command .= " -recovery $recoveryroot" if defined $recoveryroot; 221 $command .= " -astrom $astrom" if defined $astrom; 222 $command .= " -mask $mask" if defined $mask; 223 $command .= " -chip_mask $ch_mask" if defined $ch_mask; 224 $command .= " -weight $weight" if defined $weight; 225 $command .= " -skycelllist $skycell_list" if defined $skycell_list; 226 $command .= " -replace" if $replace; 227 $command .= " -release" if $release; 228 $command .= " -dbname $dbname" if defined $dbname; 229 unless (defined $no_op) { 165 if ($stage ne "camera") { 166 # get skycell list if needed 167 my ($sfh, $skycell_list); 168 if ($skycell_args) { 169 my $command = "$magicdstool -magic_ds_id $magic_ds_id -getskycells $skycell_args"; 170 $command .= " -dbname $dbname" if defined $dbname; 230 171 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 231 172 run(command => $command, verbose => $verbose); 232 173 unless ($success) { 233 174 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 234 &my_die("Unable to perform streaksremove: $error_code", $magic_ds_id, $component, $error_code); 235 } 236 } else { 237 print "skipping command $command\n"; 175 &my_die("Unable to perform magicdstool -diffskyfile $skycell_args: $error_code", $magic_ds_id, $component, $error_code); 176 } 177 178 my $getskycells_output = join "", @$stdout_buf; 179 if ($getskycells_output) { 180 my $metadata = $mdcParser->parse($getskycells_output) or 181 &my_die("Unable to parse metadata config doc", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR); 182 183 my $skycells = parse_md_list($metadata) or 184 &my_die("Unable to parse metadata list", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR); 185 186 ($sfh, $skycell_list) = tempfile( "/tmp/skycell_list.XXXX", UNLINK => !$save_temps); 187 188 foreach my $skycell (@$skycells) { 189 my $skycell_uri = $ipprc->filename("PPSUB.OUTPUT", $skycell->{path_base}); 190 print $sfh "$skycell_uri\n"; 191 } 192 close $sfh; 193 } 194 } 195 196 my ($image, $mask, $ch_mask, $weight, $astrom); 197 198 if ($stage eq "raw") { 199 $image = $uri; 200 $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base); 201 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id) if $release ; 202 } elsif ($stage eq "chip") { 203 # we use the mask output from the camera stage for input and replace 204 # the output of the chip stage with that mask as well. 205 $image = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id); 206 $ch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id); 207 $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id); 208 $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base); 209 } elsif ($stage eq "warp") { 210 $image = $ipprc->filename("PSWARP.OUTPUT", $path_base); 211 $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base); 212 $weight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $path_base); 213 } elsif ($stage eq "diff") { 214 my $name = $inverse ? "PPSUB.INVERSE" : "PPSUB.OUTPUT"; # Base name for images 215 $image = $ipprc->filename($name, $path_base); 216 $mask = $ipprc->filename("$name.MASK", $path_base); 217 $weight = $ipprc->filename("$name.VARIANCE", $path_base); 218 } 219 220 { 221 my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image"; 222 223 $command .= " -class_id $class_id" if defined $class_id; 224 $command .= " -recovery $recoveryroot" if defined $recoveryroot; 225 $command .= " -astrom $astrom" if defined $astrom; 226 $command .= " -mask $mask" if defined $mask; 227 $command .= " -chip_mask $ch_mask" if defined $ch_mask; 228 $command .= " -weight $weight" if defined $weight; 229 $command .= " -skycelllist $skycell_list" if defined $skycell_list; 230 $command .= " -replace" if $replace; 231 $command .= " -release" if $release; 232 $command .= " -dbname $dbname" if defined $dbname; 233 unless (defined $no_op) { 234 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 235 run(command => $command, verbose => $verbose); 236 unless ($success) { 237 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 238 &my_die("Unable to perform streaksremove: $error_code", $magic_ds_id, $component, $error_code); 239 } 240 } else { 241 print "skipping command $command\n"; 242 } 243 } 244 } else { 245 my $tempOutRoot = "/tmp/destreak"; 246 my ($maskListFile, $maskListName) = tempfile( "$tempOutRoot.mask.list.XXXX", UNLINK => !$save_temps); 247 my $files; 248 { 249 my $cam_id = $stage_id; 250 my $command = "$camtool -pendingimfile -cam_id $cam_id"; # Command to run 251 $command .= " -dbname $dbname" if defined $dbname; 252 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 253 run(command => $command, verbose => $verbose); 254 unless ($success) { 255 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 256 &my_die("Unable to perform camtool: $error_code", $cam_id, $error_code); 257 } 258 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 259 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR); 260 261 # extract the metadata for the files into a hash list 262 $files = parse_md_list($metadata) or 263 &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR); 264 } 265 foreach my $file (@$files) { 266 my $class_id = $file->{class_id}; 267 my $quality = $file->{quality}; 268 if (!$quality) { 269 my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $path_base, $class_id); 270 print $maskListFile "$mask\n"; 271 } 272 } 273 close $maskListFile; 274 275 my $astrom = $ipprc->filename("PSASTRO.OUTPUT", $path_base); 276 { 277 my $output = $tmproot . basename($astrom); 278 my $command = "$censordetections -stage $stage -output $output"; 279 $command .= " -astrom $astrom"; 280 $command .= " -masklist $maskListName"; 281 $command .= " -replace" if $replace; 282 $command .= " -dbname $dbname" if defined $dbname; 283 unless (defined $no_op) { 284 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 285 run(command => $command, verbose => $verbose); 286 unless ($success) { 287 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 288 &my_die("Unable to perform streaksremove: $error_code", $magic_ds_id, $component, $error_code); 289 } 290 } else { 291 print "skipping command $command\n"; 292 } 238 293 } 239 294 }
Note:
See TracChangeset
for help on using the changeset viewer.
