- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/magic_destreak.pl (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippScripts/scripts/magic_destreak.pl
r25029 r27840 8 8 use Sys::Hostname; 9 9 my $host = hostname(); 10 my $date = `date`; 10 11 print "\n\n"; 11 print "Starting script $0 on $host \n\n";12 print "Starting script $0 on $host at $date\n\n"; 12 13 13 14 use vars qw( $VERSION ); … … 15 16 16 17 use IPC::Cmd 0.36 qw( can_run run ); 17 use File::Temp qw( tempfile );18 use File::Temp qw( tempfile tempdir ); 18 19 use File::Basename qw( basename dirname ); 19 20 use PS::IPP::Metadata::Config; … … 32 33 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); 33 34 my $censorObjects = can_run('censorObjects') or (warn "Can't find censorObjects" and $missing_tools = 1); 35 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 36 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 34 37 if ($missing_tools) { 35 38 warn("Can't find required tools."); … … 38 41 39 42 # Parse the command-line arguments 40 my ($magic_ds_id, $camera, $streaks, $inv_streaks, $ stage, $stage_id, $component, $uri, $path_base, $cam_path_base);43 my ($magic_ds_id, $camera, $streaks, $inv_streaks, $exp_id, $stage, $stage_id, $component, $uri, $path_base, $cam_path_base, $cam_reduction); 41 44 my ($outroot, $recoveryroot); 42 45 my ($replace, $release); … … 48 51 'streaks=s' => \$streaks, # file containing the list of streaks 49 52 'inv_streaks=s' => \$inv_streaks,# file containing the list of streaks from the inverse diff 53 'exp_id=s' => \$exp_id, # exp_id, chip_id, warp_id, or diff_id 50 54 'stage=s' => \$stage, # raw, chip, warp, or diff 51 55 'stage_id=s' => \$stage_id, # exp_id, chip_id, warp_id, or diff_id … … 54 58 'path_base=s' => \$path_base, # path_base of the input 55 59 'cam_path_base=s'=> \$cam_path_base, # path_base from camera stage (for chip and raw) 60 'cam_reduction=s'=> \$cam_reduction, # reduction class from camera stage (for chip and raw) 56 61 'outroot=s' => \$outroot, # "directory" for temporary images (may be nebulous) 57 62 'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels … … 74 79 defined $stage and 75 80 defined $stage_id and 81 defined $exp_id and 76 82 defined $component and 77 83 defined $uri and … … 81 87 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR ); # IPP configuration 82 88 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR ) if $logfile; 89 90 $cam_reduction = 'DEFAULT' if !$cam_reduction or ($cam_reduction eq 'NULL'); 91 92 my $recipe_psastro = $ipprc->reduction($cam_reduction, 'PSASTRO'); # Recipe to use 93 &my_die("Unrecognised PSASTRO recipe", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro; 83 94 84 95 my ($skycell_args, $class_id, $skycell_id); … … 94 105 } elsif ($stage ne "camera") { 95 106 &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 96 } 107 } 97 108 $inv_streaks = undef if defined($inv_streaks) and ($inv_streaks eq "NULL"); 98 109 … … 111 122 if ($stage eq 'camera') { 112 123 my $nebulousServer = metadataLookupStr( $ipprc->{_siteConfig}, 'NEB_SERVER' ); 113 &my_die("cannot find NEB_SERVER in site configuration", 114 $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) 124 &my_die("cannot find NEB_SERVER in site configuration", 125 $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) 115 126 if !$ nebulousServer; 116 127 … … 145 156 } 146 157 } 158 159 my $statsFile = "$outroot/$exp_id.mds.$magic_ds_id.$stage_id.$component.stats"; 147 160 148 161 my $backup_path_base; … … 166 179 if (! -e $recoveryroot ) { 167 180 my $code = system "mkdir -p $recoveryroot"; 168 &my_die("cannot create output directory $ outroot", $magic_ds_id, $component,181 &my_die("cannot create output directory $recoveryroot", $magic_ds_id, $component, 169 182 $code >> 8) if $code; 170 183 } … … 173 186 $recovery_path_base = "$recoveryroot/$basename/"; 174 187 } 188 189 my $temp_dir; 175 190 176 191 if ($stage ne "camera") { … … 195 210 &my_die("Unable to parse metadata list", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR); 196 211 212 $temp_dir = tempdir( CLEANUP => !$save_temps); 197 213 ($sfh, $skycell_list) = tempfile( "/tmp/skycell_list.XXXX", UNLINK => !$save_temps); 198 214 199 215 foreach my $skycell (@$skycells) { 200 my $skycell_uri = $ipprc->filename("PPSUB.OUTPUT", $skycell->{path_base}); 216 my $skycell_uri; 217 if ($skycell->{data_state} eq "full") { 218 $skycell_uri = $ipprc->filename("PPSUB.OUTPUT", $skycell->{path_base}); 219 } else { 220 # diff run must have been cleaned up, need to create this skycell file on the fly 221 my $skycell_id = $skycell->{skycell_id}; 222 $skycell_uri = "$temp_dir/$skycell_id"; 223 $ipprc->skycell_file($skycell->{tess_id}, $skycell_id, $skycell_uri, $verbose) or 224 &my_die("failed to create skycell file for $skycell_id", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR); 225 } 201 226 print $sfh "$skycell_uri\n"; 202 227 } 203 close $sfh ;228 close $sfh 204 229 } 205 230 } … … 216 241 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id) if $release ; 217 242 } elsif ($stage eq "chip") { 243 244 # Check to see if we're using dynamic masks 245 my $dynamicMasks; # Use dynamic masks? 246 { 247 # Get the PSASTRO recipe 248 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -"; 249 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 250 run(command => $command, verbose => $verbose); 251 unless ($success) { 252 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 253 &my_die("Unable to perform ppConfigDump: $error_code", $magic_ds_id, $component, 254 $PS_EXIT_CONFIG_ERROR); 255 } 256 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 257 &my_die("Unable to parse metadata config doc", $magic_ds_id, $component, 258 $PS_EXIT_CONFIG_ERROR); 259 260 $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK'); 261 } 262 218 263 # we use the mask output from the camera stage for input and replace 219 264 # the output of the chip stage with that mask as well. 220 265 $image = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id); 221 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);222 $ch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);223 266 $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id); 224 267 $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base); 225 if (!$ipprc->file_exists($mask)) { 226 carp("camera mask file $mask for $component not found. Continuing using mask from chip stage."); 227 $mask = $ch_mask; 228 $ch_mask = undef; 229 } 268 269 if ($dynamicMasks) { 270 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id); 271 $ch_mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id); 272 } else { 273 $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id); 274 } 275 230 276 # XXX: should we censor the sources as well? For now we're leaving them out of the distribution bundles 231 277 # because they confuse people … … 245 291 246 292 if ($inv_streaks) { 247 # create a temporary file containing the contents of the 293 # create a temporary file containing the contents of the 248 294 # two streaks files 249 295 ($allstreaks_fh, $allstreaks_name) = tempfile ("/tmp/all.streaks.XXXX", … … 260 306 my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image"; 261 307 308 $command .= " -stats $statsFile"; 262 309 $command .= " -class_id $class_id" if defined $class_id; 263 310 $command .= " -recovery $recoveryroot" if defined $recoveryroot; … … 288 335 $sources = $ipprc->filename("PPSUB.INVERSE.SOURCES", $path_base); 289 336 337 # Note: we create a stats file for the inverse procesing but we don't look at the results 338 my $invStatsFile = "$outroot/$exp_id.mds.$magic_ds_id.$stage_id.$component.inv.stats"; 339 290 340 my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image"; 341 $command .= " -stats $invStatsFile"; 291 342 292 343 $command .= " -recovery $recoveryroot" if defined $recoveryroot; … … 335 386 my $quality = $file->{quality}; 336 387 if (!$quality) { 337 my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $path_base, $class_id); 388 my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $path_base, $class_id); 338 389 if (! $ipprc->file_exists($mask)) { 339 390 # camera mask doesn't exist for this chip. Fall back to the chip mask … … 357 408 &my_die("Unable to perform censorObjects: $error_code", $magic_ds_id, $component, $error_code); 358 409 } 359 my $output = $ipprc->filename("CENSOR.OUTPUT", $backup_path_base); 410 my $output = $ipprc->filename("CENSOR.OUTPUT", $backup_path_base); 360 411 &my_die("expected output file $output not found ", $magic_ds_id, $component, $PS_EXIT_DATA_ERROR) 361 412 unless $ipprc->file_exists($output); … … 371 422 } 372 423 373 # if recovery and/or backup files were expected make sure they exist 424 my $statsFlags; 425 if ($stage ne "camera") { 426 file_check($statsFile); 427 { 428 my $resolvedStatsFile = $ipprc->file_resolve($statsFile); 429 my $command = "$ppStatsFromMetadata $resolvedStatsFile - STREAKSREMOVE"; 430 431 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 432 run(command => $command, verbose => $verbose); 433 unless ($success) { 434 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 435 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $magic_ds_id, $component, $error_code); 436 } 437 foreach my $line (@$stdout_buf) { 438 $statsFlags .= " $line"; 439 } 440 chomp $statsFlags; 441 } 442 } 443 444 # XXX: if recovery and/or backup files were expected make sure they exist 374 445 375 446 # Input result into database … … 381 452 $command .= " -backup_path_base $backup_path_base" if $backup_path_base; 382 453 $command .= " -recovery_path_base $recovery_path_base" if $recovery_path_base; 454 $command .= " $statsFlags" if $statsFlags; 383 455 $command .= " -dbname $dbname" if defined $dbname; 384 456 … … 438 510 } 439 511 440 close $fout 512 close $fout 441 513 or my_die("failed to close combined streaks file", $magic_ds_id, 442 514 $component, $PS_EXIT_UNKNOWN_ERROR);
Note:
See TracChangeset
for help on using the changeset viewer.
