- Timestamp:
- Aug 30, 2013, 4:48:58 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130711/pstamp/scripts
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp_job_run.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130711/pstamp/scripts
- Property svn:mergeinfo changed
/trunk/pstamp/scripts (added) merged: 35827-35828,35892,35900-35903,35911,35932,35937,36010-36011,36017-36018,36048,36059,36061
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130711/pstamp/scripts/pstamp_job_run.pl
r35609 r36071 57 57 my_die("output_base is required", $job_id, $PS_EXIT_PROG_ERROR) if !$outputBase; 58 58 59 $options = 1 if !$options; 60 61 # We don't need to muggle anymore. Ignore those options 62 $options &= ~($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED); 59 # ppstamp requires an input file 60 $options = $PSTAMP_SELECT_IMAGE if !$options; 63 61 64 62 my $ipprc = PS::IPP::Config->new(); # IPP Configuration … … 78 76 my $ppstamp = can_run('ppstamp') or (warn "Can't find ppstamp" and $missing_tools = 1); 79 77 my $pstamp_get_image_job = can_run('pstamp_get_image_job.pl') or (warn "Can't find pstamp_get_image_job.pl" and $missing_tools = 1); 78 my $psgetcalibinfo = can_run('psgetcalibinfo') or (warn "Can't find psgetcalibinfo" and $missing_tools = 1); 80 79 my $dquery_job_run = can_run('dquery_job_run.pl') or (warn "Can't find dquery_job_run.pl" and $missing_tools = 1); 81 my $streaksreplace = can_run('streaksreplace') or (warn "Can't find streaksreplace" and $missing_tools = 1);82 my $magicdstool = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);83 80 my $whichnode = can_run('whichnode') or (warn "can't find whichnode" and $missing_tools = 1); 84 81 … … 96 93 my $argString; 97 94 $argString = $params->{job_args}; 95 96 my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString; 97 98 98 my $stage = $params->{stage}; 99 100 # XXX: should we do any other sanity checking? 101 my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString; 102 103 my $nan_masked = 1; 104 my $muggle = 0; 105 if (!$params->{magicked}) { 106 $nan_masked = 0; 107 } elsif ($params->{magicked} and ($options & ($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED))) { 108 # Attempt to find or create a muggle image 109 $nan_masked = 0; 110 $muggle = 1; 111 } 99 my_die("stage is not defined", $job_id, $PS_EXIT_DATA_ERROR) if !$stage; 100 101 if ($stage eq 'stack_summary') { 102 103 # remove options not supported by stack summary 104 $options &= ~($PSTAMP_SELECT_SOURCES | $PSTAMP_SELECT_BACKMDL | $PSTAMP_SELECT_INVERSE 105 | $PSTAMP_RESTORE_BACKGROUND); 106 107 # stackSummary outputs do not follow the usual IPP conventions for file names. 108 # The parser (actually Job.pm) has deferred handling this until here 109 update_stack_summary_filenames($params); 110 111 } elsif ($stage ne 'stack') { 112 # ignore options only supported by stack and stack_summary 113 $options &= ~($PSTAMP_SELECT_EXP | $PSTAMP_SELECT_NUM); 114 } 115 112 116 113 117 if ($stage eq "raw") { … … 122 126 my @file_list = ($params->{image}); 123 127 124 if ($ nan_masked or ($options & $PSTAMP_SELECT_MASK)) {128 if ($options & $PSTAMP_SELECT_MASK) { 125 129 $mask = $params->{mask}; 126 130 $fileArgs .= " -mask $mask"; … … 162 166 # find our output directory 163 167 my $outdir = dirname($outputBase); 164 my ($tmpImage, $tmpMask, $tmpVariance, $tmproot); 165 166 if ($muggle) { 167 # first see if the original uncensored images are around 168 if (check_for_backups($params, \$fileArgs)) { 169 # We're good to go. fileArgs has been edited to contain the paths for the original uncensored images 170 print "Making stamps from backup images\n"; 171 } elsif (($options & $PSTAMP_REQUIRE_UNCENSORED) and ($stage ne 'chip')) { 172 # user required uncensored but since stage isn't chip we can't rebuild them 173 my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE, 'stop'); 174 } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($params->{state} ne 'full') and ($stage ne 'chip')) { 175 # we can only restore pixels for chip stage images if the data has been updated. 176 # the data will have been updated if the params->{state} the state when the job was queued is not 'full' ( 177 # XXX: we should probably be looking explicitly at the job and checking for a dep_id 178 print "Run state was $params->{state}: will make stamps from destreaked $stage images.\n"; 179 # make stamps from uncensored images 180 $muggle = 0; 168 169 my ($calib_fd, $calibfile); 170 if ($stage eq 'chip' or $stage eq 'warp') { 171 my $cam_id = $params->{cam_id}; 172 if (!$cam_id) { 173 carp "no cam_id found in job params\n"; 174 exit $PS_EXIT_PROG_ERROR; 175 } 176 ($calib_fd, $calibfile) = tempfile ("$outdir/calib.XXXX", UNLINK => !$save_temps); 177 close $calib_fd; 178 179 my $command = "$psgetcalibinfo --cam_id $cam_id --output $calibfile --dbname $params->{imagedb}"; 180 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 181 run(command => $command, verbose => $verbose); 182 183 my $exitStatus; 184 if (WIFEXITED($error_code)) { 185 $exitStatus = WEXITSTATUS($error_code); 181 186 } else { 182 # Try and replace the streaks from the recovery images 183 184 my $temp_dir = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR") or &my_die("Unable to find temporary directory in site configuration", $job_id, $PS_EXIT_CONFIG_ERROR); 185 $tmproot = tempdir("$temp_dir/psjob.$job_id.XXXX", CLEANUP => !$save_temps); 186 my $muggle_command = "$streaksreplace -stage $stage -tmproot $tmproot"; 187 # find the "directory" of the input path_base 188 my $inputdir = dirname($image); 189 my $base = basename($image); 190 $tmpImage = "$tmproot/$base"; 191 192 @file_list = (); 193 194 # XXX: We should get the recovery_path_base from the magicDSFile but that requires a bunch of file rule and 195 # stage work. Import the rule here. 196 my $recImage = "$inputdir/REC_$base"; 197 my $newFileArgs = " -file $tmpImage"; 198 $muggle_command .= " -image $image -recimage $recImage"; 199 push @file_list, $recImage; 200 201 if ($mask) { 202 $base = basename($mask); 203 $tmpMask = "$tmproot/$base"; 204 $newFileArgs .= " -mask $tmpMask"; 205 my $recMask = "$inputdir/REC_$base"; 206 $muggle_command .= " -mask $mask -recmask $recMask"; 207 push @file_list, $recMask; 208 } 209 210 if ($variance) { 211 $base = basename($variance); 212 $tmpVariance = "$tmproot/$base"; 213 $newFileArgs .= " -variance $tmpVariance"; 214 my $recVariance = "$inputdir/REC_$base"; 215 $muggle_command .= " -weight $variance -recweight $recVariance"; 216 push @file_list, $recVariance; 217 } 218 if (check_files(0, @file_list)) { 219 # recovery files exist and are accessible restore the excised pixels 220 221 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 222 run(command => $muggle_command, verbose => $verbose); 223 unless ($success) { 224 my $exitStatus = WEXITSTATUS($error_code); 225 my_die( "streaksreplace failed with error code: $exitStatus", $job_id, $exitStatus); 226 } 227 228 # set the ppstamp file arguments 229 $fileArgs = $newFileArgs; 230 } else { 231 if ($options & $PSTAMP_REQUIRE_UNCENSORED) { 232 my_die( "unable to restore uncensored images", $job_id, $PSTAMP_NOT_AVAILABLE); 233 } 234 # just make stamps from the censored images 235 print "Unable to restore uncensored images, will extract stamps from censored images\n"; 236 # these files won't be used so zap them 237 ($tmpImage, $tmpMask, $tmpVariance, $tmproot) = (undef, undef, undef, undef); 238 } 239 } 240 } 241 242 # MAGIC IS DEAD 243 $nan_masked = 0; 244 245 my $command = "$ppstamp $outputBase $argString $fileArgs"; 246 $command .= " -write_jpeg" if ($options & $PSTAMP_SELECT_JPEG); 247 $command .= " -nocompress" if ($options & $PSTAMP_SELECT_UNCOMPRESSED); 248 $command .= " -stage $stage"; 249 $command .= " -censor_masked" if $nan_masked; 250 $command .= " -dbname $dbname" if $dbname; 251 $command .= " -dbserver $dbserver" if $dbserver; 252 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 253 run(command => $command, verbose => $verbose); 187 print STDERR "psgetcalibinfo failed error_code: $error_code\n"; 188 $exitStatus = $PS_EXIT_SYS_ERROR; 189 } 190 exit $exitStatus if $exitStatus; 191 192 if (-s $calibfile == 0) { 193 print "no calibration information found for $cam_id\n"; 194 $calibfile = undef; 195 } 196 } 197 198 # unless the stage is stack_summary we use ppstamp to make postage stamps (including -wholefile) 199 # otherwise we make copies of the input files to the outputs 200 my $use_ppstamp = ($stage ne 'stack_summary'); 254 201 255 202 my $exitStatus; 256 if (WIFEXITED($error_code)) { 257 $exitStatus = WEXITSTATUS($error_code); 258 } else { 259 print STDERR "ppstamp failed error_code: $error_code\n"; 260 $exitStatus = $PS_EXIT_SYS_ERROR; 203 if ($use_ppstamp) { 204 my $command = "$ppstamp $outputBase $argString $fileArgs"; 205 $command .= " -write_jpeg" if ($options & $PSTAMP_SELECT_JPEG); 206 $command .= " -nocompress" if ($options & $PSTAMP_SELECT_UNCOMPRESSED); 207 $command .= " -stage $stage"; 208 $command .= " -forheader $calibfile" if $calibfile; 209 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 210 run(command => $command, verbose => $verbose); 211 212 if (WIFEXITED($error_code)) { 213 $exitStatus = WEXITSTATUS($error_code); 214 } else { 215 print STDERR "ppstamp failed error_code: $error_code\n"; 216 $exitStatus = $PS_EXIT_SYS_ERROR; 217 } 218 # XXX: if stage is stack deal with EXP and NUM images if selected 219 } else { 220 $exitStatus = justCopyFiles($outputBase, \$options, $params); 261 221 } 262 222 … … 270 230 271 231 # Note: we are assuming the contents of the PSTAMP filerules here. 272 my %extensions = ( $PSTAMP_SELECT_IMAGE => "fits", 273 $PSTAMP_SELECT_MASK => "mk.fits", 274 $PSTAMP_SELECT_VARIANCE => "wt.fits", 275 $PSTAMP_SELECT_SOURCES => "cmf", 276 $PSTAMP_SELECT_JPEG => "jpg"); 277 278 my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES); 232 my %extensions = ( $PSTAMP_SELECT_IMAGE => 'fits', 233 $PSTAMP_SELECT_MASK => 'mk.fits', 234 $PSTAMP_SELECT_VARIANCE => 'wt.fits', 235 $PSTAMP_SELECT_SOURCES => 'cmf', 236 $PSTAMP_SELECT_JPEG => 'jpg', 237 $PSTAMP_SELECT_EXP => 'exp.fits', 238 $PSTAMP_SELECT_NUM => 'num.fits'); 239 240 my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE 241 | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES | $PSTAMP_SELECT_EXP | $PSTAMP_SELECT_NUM); 279 242 280 243 foreach my $key (keys (%extensions)) { … … 523 486 } 524 487 525 sub check_for_backups {526 my $params = shift;527 my $r_fileArgs = shift;528 529 my $command = "$magicdstool -destreakedfile -stage $params->{stage} -stage_id $params->{stage_id} -component $params->{component} -dbname $params->{imagedb}";530 my $results = runToolAndParse($command, $verbose);531 my $dsComponent = $results->[0];532 533 if ($dsComponent and ($dsComponent->{data_state} eq 'full')) {534 535 print "magicDSFile state is full. Backup images should exist\n";536 537 # replace the file names with the backup paths538 # fileArgs has the form: -file imagename [-mask maskname] [-weight weightname]539 my @args = split " ", $$r_fileArgs;540 541 my $newFileArgs;542 while (@args) {543 my $a = shift @args;544 my $f = shift @args;545 my_die( "unexpected fileArg list $$r_fileArgs", $job_id, $PS_EXIT_PROG_ERROR, 'run') if !$a or !$f;546 547 my $backup_image_name = $ipprc->destreaked_filename($f);548 my_die( "failed to extract backup image name from $f", $job_id, $PS_EXIT_PROG_ERROR, 'run') if !$backup_image_name;549 $newFileArgs .= " $a $backup_image_name";550 }551 $$r_fileArgs = $newFileArgs;552 553 return 1;554 }555 556 return 0;557 }558 559 488 my $neb; 560 489 sub storage_object_exists … … 630 559 } 631 560 561 # stack_summary stage does not currently use proper file rules. 562 # The parser defers handlint this to us.. 563 564 sub update_stack_summary_filenames { 565 my $params = shift; 566 567 my $path_base = $params->{path_base}; 568 569 $params->{image} = $path_base . ".image.b1.fits"; 570 $params->{mask} = $path_base . ".mask.b1.fits"; 571 $params->{weight} = $path_base . ".variance.b1.fits"; 572 $params->{jpeg} = $path_base . ".image.0.b1.jpeg"; 573 $params->{exp} = $path_base . ".exp.b1.fits"; 574 $params->{num} = $path_base . ".num.b1.fits"; 575 } 576 577 sub myCopy { 578 my ($dest, $src, $type, $dieOnFail) = @_; 579 580 my $result; 581 my $resolved = $ipprc->file_resolve($src); 582 if ($resolved and $ipprc->file_exists($resolved)) { 583 print "Copying $src to $dest\n" if $verbose;; 584 $result = copy($resolved, $dest); 585 } else { 586 my $msg = "Specified source $type image $src not found."; 587 if ($dieOnFail) { 588 $msg .= "\n"; 589 } else { 590 $msg .= " ignoring\n"; 591 } 592 carp $msg; 593 $result = 0; 594 } 595 596 if (!$result and $dieOnFail) { 597 &my_die("Unable to copy $type image", $job_id, $PS_EXIT_SYS_ERROR, 'run'); 598 } 599 return $result; 600 } 601 602 sub justCopyFiles { 603 my ($outputBase, $r_options, $params) = @_; 604 605 print "Just copying files for $job_id.\n"; 606 607 my $options = $$r_options; 608 if ($options & $PSTAMP_SELECT_IMAGE) { 609 myCopy("$outputBase.fits", $params->{image}, 'image', 1); 610 } 611 if ($options & $PSTAMP_SELECT_MASK) { 612 if (!myCopy("$outputBase.mk.fits", $params->{mask}, 'mask', 0)) { 613 $options &= ~$PSTAMP_SELECT_MASK; 614 } 615 } 616 if ($options & $PSTAMP_SELECT_VARIANCE) { 617 if (!myCopy("$outputBase.wt.fits", $params->{weight}, 'variance', 0)) { 618 $options = ~$PSTAMP_SELECT_VARIANCE; 619 } 620 } 621 if ($options & $PSTAMP_SELECT_JPEG) { 622 if (!myCopy("$outputBase.jpg", $params->{jpeg}, 'jpeg', 0)) { 623 $options &= ~$PSTAMP_SELECT_JPEG; 624 } 625 } 626 if ($options & $PSTAMP_SELECT_EXP) { 627 if (!myCopy("$outputBase.exp.fits", $params->{exp}, 'exp', 0)) { 628 $options &= ~$PSTAMP_SELECT_EXP; 629 } 630 } 631 if ($options & $PSTAMP_SELECT_NUM) { 632 if (!myCopy("$outputBase.num.fits", $params->{num}, 'num', 0)) { 633 $options &= ~$PSTAMP_SELECT_NUM; 634 } 635 } 636 637 $$r_options = $options; 638 639 print "Done with copy.\n"; 640 641 return 0; 642 } 643 632 644 sub my_die 633 645 {
Note:
See TracChangeset
for help on using the changeset viewer.
