Changeset 30574
- Timestamp:
- Feb 11, 2011, 2:11:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-20101215/ippScripts/scripts/warp_skycell.pl
- Property svn:mergeinfo set to
r27754 r30574 71 71 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR ); # IPP configuration 72 72 73 my $logDest = $ipprc->filename("LOG.EXP", $outroot, $skycell_id) or my_die( "Unable to get log filename", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR ); 74 $logDest .= ".update" if ($run_state eq 'update'); 73 my ($logDest, $traceDest); 74 if ($run_state eq 'new') { 75 $logDest = prepare_output("LOG.EXP", $outroot, $skycell_id, 0); 76 $traceDest = prepare_output("TRACE.EXP", $outroot, $skycell_id, 1); 77 } elsif ($run_state eq 'update') { 78 $logDest = prepare_output("LOG.EXP.UPDATE", $outroot, $skycell_id, 0); 79 $traceDest = prepare_output("TRACE.EXP.UPDATE", $outroot, $skycell_id, 1); 80 } else { 81 &my_die( "invalid run_state: $run_state", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR ); 82 } 83 84 my $neb; 85 my $scheme = file_scheme($outroot); 86 if ($scheme and $scheme eq 'neb') { 87 $neb = $ipprc->nebulous(); 88 } 75 89 76 90 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR ) if $redirect; … … 117 131 unless ($success) { 118 132 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 119 &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $ error_code);133 &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $skycell_id, $tess_dir, $error_code); 120 134 } 121 135 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 122 &my_die("Unable to parse metadata config doc", $warp_id, $ PS_EXIT_PROG_ERROR);136 &my_die("Unable to parse metadata config doc", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR); 123 137 $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE'); 124 138 } … … 141 155 142 156 143 my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id ); 144 my $outputMask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outroot, $skycell_id); 145 my $outputWeight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $outroot, $skycell_id); 146 my $outputSources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $outroot, $skycell_id); 147 my $outputPSF = $ipprc->filename("PSPHOT.PSF.SKY.SAVE", $outroot); 148 my $outputBin1 = $ipprc->filename("PSWARP.BIN1", $outroot, $skycell_id ); 149 my $outputBin2 = $ipprc->filename("PSWARP.BIN2", $outroot, $skycell_id ); 150 my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot, $skycell_id ); 151 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot, $skycell_id); 152 my $configuration = $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id); 153 154 if ($run_state eq 'update') { 155 $traceDest .= ".update"; 156 $outputStats .= ".update"; 157 } 158 159 my $skyFile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id ); 157 my $outputImage = prepare_output ("PSWARP.OUTPUT", $outroot, $skycell_id, 1); 158 my $outputMask = prepare_output ("PSWARP.OUTPUT.MASK", $outroot, $skycell_id, 1); 159 my $outputWeight = prepare_output ("PSWARP.OUTPUT.VARIANCE", $outroot, $skycell_id, 1); 160 my $outputSources = prepare_output ("PSWARP.OUTPUT.SOURCES", $outroot, $skycell_id, 1); 161 my $outputPSF = prepare_output ("PSPHOT.PSF.SKY.SAVE", $outroot, 1); 162 my $outputBin1 = prepare_output ("PSWARP.BIN1", $outroot, $skycell_id, 1); 163 my $outputBin2 = prepare_output ("PSWARP.BIN2", $outroot, $skycell_id, 1); 164 my $outputStats = prepare_output ("SKYCELL.STATS", $outroot, $skycell_id, 1); 165 my $configuration; 166 167 my $dump_config = 1; 168 if ($run_state eq 'new') { 169 $configuration = prepare_output ("PSWARP.CONFIG", $outroot, $skycell_id, 1); 170 } else { 171 $configuration = $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id) or 172 &my_die("Missing entry from camera config PSWARP.CONFIG", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR); 173 if ($ipprc->file_exists($configuration)) { 174 $dump_config = 0; 175 } else { 176 print STDERR "WARNING: Config dump file $configuration is missing. Using current recipes and file rules.\n"; 177 178 # XXX: should we create a new config dump file? 179 # I vote yes but only if we can distingusing between temporarily unavailable and GONE. 180 my $gone = 0; 181 if (storage_object_exists($configuration, \$gone)) { 182 if ($gone) { 183 $configuration = prepare_output('PSWARP.CONFIG', $outroot, $skycell_id, 1); 184 # if we dump the config we need to insure that the config dump represents 185 # the full processing 186 } else { 187 # file is temporarily not available. Don't dump config. 188 $dump_config = 0; 189 } 190 } 191 } 192 } 193 194 195 my $skyFile = prepare_output ("SKYCELL.TEMPLATE", $outroot, $skycell_id, 1); 160 196 $ipprc->skycell_file( $tess_dir, $skycell_id, $skyFile, $verbose ) or &my_die("Unable to generate template skycell", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR); 161 197 ## XXX this seems to have insufficient error checking: dvoImageExtract can fail to write and still return a valid exit status … … 171 207 foreach my $imfile (@$imfiles) { 172 208 my $image = $imfile->{uri}; # Image name 173 my $weight = $ipprc->filename ("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id}); # Mask name209 my $weight = $ipprc->filename ("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id}); # Mask name 174 210 175 211 my $mask; # Mask name 176 212 if ($dynamicMasks) { 177 $mask = $ipprc->filename ("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});213 $mask = $ipprc->filename ("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id}); 178 214 } else { 179 $mask = $ipprc->filename ("PPIMAGE.CHIP.MASK", $imfile->{chip_path_base}, $imfile->{class_id});215 $mask = $ipprc->filename ("PPIMAGE.CHIP.MASK", $imfile->{chip_path_base}, $imfile->{class_id}); 180 216 } 181 217 … … 186 222 # Astrometry file: astrometry is done at the camera stage, and always results in a MEF file 187 223 # XXX allow an option to use the image header astrometry? 188 my $astrom = $ipprc->filename ($astromSource, $imfile->{cam_path_base});224 my $astrom = $ipprc->filename ($astromSource, $imfile->{cam_path_base}); 189 225 190 226 &my_die("Couldn't find input file: $astrom", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless defined $astrom and $ipprc->file_exists($astrom); … … 245 281 $do_stats = 1; 246 282 } else { 247 #$command .= " -ipprc $configuration"; 248 my $resolved = $ipprc->file_resolve($configuration); 249 $command .= " -ipprc $resolved"; 283 $command .= " -ipprc $configuration"; 250 284 } 251 285 if ($do_stats) { … … 263 297 if ($do_stats) { 264 298 # Check first for the stats file 299 check_output($outputStats, 0); 265 300 my $outputStatsReal = $ipprc->file_resolve($outputStats); 266 &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);301 # &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal); 267 302 &my_die("Stats file has zero size: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless -s $outputStatsReal; 268 303 269 # measure chipstats304 # measure skycell stats 270 305 $command = "$ppStatsFromMetadata $outputStatsReal - WARP_SKYCELL"; 271 306 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 283 318 284 319 if (!$quality) { 285 &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage); 286 &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 287 &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight); 288 &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 289 &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) if metadataLookupBool($recipe, 'PSF') and not $ipprc->file_exists($outputPSF); 290 if ($run_state eq 'new') { 291 &my_die("Couldn't find expected output file: $configuration", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($configuration); 320 # &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage); 321 # &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 322 # &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight); 323 # &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 324 # &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) if metadataLookupBool($recipe, 'PSF') and not $ipprc->file_exists($outputPSF); 325 326 check_output($outputImage, 0); 327 check_output($outputMask, 0); 328 check_output($outputWeight, 0); 329 check_output($outputSources, 1); 330 check_output($outputPSF, 1) if metadataLookupBool($recipe, 'PSF') ; 331 if ($dump_config) { 332 check_output($configuration, 1); 333 # &my_die("Couldn't find expected output file: $configuration", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($configuration); 292 334 } 293 335 } … … 335 377 } 336 378 } 379 380 exit 0; 381 382 # Prepare to write to an output file 383 # Lookup the filename in the rules. 384 # Make sure that if file exists and is a nebulous file that there is only one instance 385 # Deal with files that have been lost. 386 sub prepare_output 387 { 388 my $filerule = shift; 389 my $outroot = shift; 390 my $skycell_id = shift; 391 my $delete = shift; 392 $delete = 0 if !defined $delete; 393 394 my $error; 395 my $output = $ipprc->prepare_output($filerule, $outroot, $skycell_id, $delete, \$error) 396 or &my_die("failed to prepare output file for: $filerule", $warp_id, $skycell_id, $tess_dir, $error); 397 return $output; 398 } 399 400 sub check_output 401 { 402 my $file = shift; 403 my $replicate = shift; 404 405 if (!defined $file) { 406 return; 407 } 408 409 &my_die("Couldn't find expected output file: $file", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file); 410 411 if ($replicate and $neb) { 412 $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR); 413 } 414 } 415 416 # subroutine to check the status of a nebulous file. Used to distinguish between a storage object that 417 # does not exist and one that all of the instances have been lost. 418 # XXXX This should be implemented properly in Nebulous 419 # For now uses Bill's script 'whichnode' which queries the nebulous database directly 420 421 my $whichnode; 422 sub storage_object_exists 423 { 424 return 0 if !$neb; 425 426 my $file = shift; 427 my $ref_all_gone = shift; 428 429 my $exists = $neb->storage_object_exists($file); 430 if (!$exists) { 431 return 0; 432 } 433 434 if (!$whichnode) { 435 $whichnode = can_run('whichnode') or 436 &my_die("Can't find whichnode", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR); 437 } 438 439 my $command = "$whichnode $file"; 440 441 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 442 run(command => $command, verbose => $verbose); 443 unless ($success) { 444 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 445 &my_die("Unable to perform whichnode: $error_code", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR); 446 } 447 448 my @lines = split "\n", (join "", @$stdout_buf); 449 450 if (scalar @lines == 0) { 451 # no output the file is really and truely gone 452 # XXX: this is now caught above 453 print STDERR "storage object for $file does not exist\n"; 454 return 0; 455 } 456 457 my $numGone = 0; 458 my $numNotGone = 0; 459 foreach my $line (@lines) { 460 chomp $line; 461 462 # output lines are either 463 # "volume available" 464 # or 465 # "volume not available" 466 467 my ($volume, $answer, undef) = split " ", $line; 468 # our hack is if the volume has an X in the name it's gone 469 if ($volume =~ /X/) { 470 print STDERR "$file is on $volume which is gone\n"; 471 $numGone++; 472 } elsif ($answer eq 'available') { 473 $numNotGone++; 474 } elsif ($answer eq 'not') { 475 print STDERR "$file is on $volume which is not available\n"; 476 $numNotGone++; 477 } else { 478 print STDERR "unexpected output from whichnode: $line\n"; 479 } 480 } 481 # if there are any instances that are not on a gone volume set all_gone to 0 482 if ($numNotGone == 0 and $numGone > 0) { 483 $$ref_all_gone = 1; 484 } else { 485 $$ref_all_gone = 0; 486 } 487 488 # storage object exists so return true 489 return 1; 490 } 491 337 492 338 493 sub my_die
Note:
See TracChangeset
for help on using the changeset viewer.
