- Timestamp:
- Sep 19, 2014, 4:05:27 PM (12 years ago)
- Location:
- branches/eam_branches/ps2-tc3-20130727
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp/scripts/pstamp_job_run.pl (modified) (6 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ps2-tc3-20130727
- Property svn:mergeinfo changed
-
branches/eam_branches/ps2-tc3-20130727/pstamp/scripts/pstamp_job_run.pl
- Property svn:mergeinfo set to
r36680 r37403 29 29 my ($job_id, $redirect_output, $outputBase, $rownum, $jobType, $options); 30 30 my ($verbose, $dbname, $dbserver, $no_update, $save_temps); 31 my $very_verbose = 0; # for debugging 31 32 32 33 GetOptions( … … 67 68 } 68 69 70 if ($verbose && $save_temps) { 71 # we're probably debugging turn up the verbosity 72 $very_verbose = 1; 73 } 74 69 75 if (!$dbserver) { 70 76 $dbserver = metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER'); 71 77 } 72 78 79 my $temproot = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR"); 80 $temproot = "/tmp" if !defined $temproot; 81 73 82 my $missing_tools; 74 83 75 84 my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools = 1); 76 my $ppstamp = can_run('ppstamp') or (warn "Can't find ppstamp" and $missing_tools = 1);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);85 my $ppstamp = can_run('ppstamp') or (warn "Can't find ppstamp" and $missing_tools = 1); 86 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); 87 my $psgetcalibinfo = can_run('psgetcalibinfo') or (warn "Can't find psgetcalibinfo" and $missing_tools = 1); 79 88 my $dquery_job_run = can_run('dquery_job_run.pl') or (warn "Can't find dquery_job_run.pl" and $missing_tools = 1); 80 89 my $whichnode = can_run('whichnode') or (warn "can't find whichnode" and $missing_tools = 1); 90 my $ppBackground = can_run('ppBackground') or (warn "Can't find ppBackground" and $missing_tools = 1); 91 my $ppBackgroundStack = can_run('ppBackgroundStack') or (warn "Can't find ppBackgroundStack" and $missing_tools = 1); 92 my $stack_bkg_mk_mdc = can_run('stack_bkg_mk_mdc.pl') or (warn "Can't find stack_bkg_mk_mdc.pl" and $missing_tools = 1); 93 my $fpack = can_run('fpack') or (warn "Can't find fpack" and $missing_tools = 1); 94 81 95 82 96 if ($missing_tools) { … … 120 134 } 121 135 136 if ($options & $PSTAMP_RESTORE_BACKGROUND) { 137 # this subroutine creates a background restored version of the image or fails. 138 # upon success params->{image} is replaced with the new (temporary) version 139 my $error_code = create_background_restored_images($params); 140 if ($error_code) { 141 # if error code is one of the permanant ones set state of job to stop 142 my_die("failed to create background restored images", $job_id, $error_code, 143 $error_code >= $PSTAMP_FIRST_ERROR_CODE ? 'stop' : undef); 144 } 145 } 146 122 147 my $image = $params->{image}; 123 148 my $mask; 124 149 my $variance; 150 125 151 my $fileArgs = " -file $params->{image}"; 126 152 my @file_list = ($params->{image}); … … 197 223 198 224 # unless the stage is stack_summary we use ppstamp to make postage stamps (including -wholefile) 199 # otherwisewe make copies of the input files to the outputs225 # if stage is stack_summary we make copies of the input files to the outputs 200 226 my $use_ppstamp = ($stage ne 'stack_summary'); 201 227 … … 216 242 $exitStatus = $PS_EXIT_SYS_ERROR; 217 243 } 218 # XXX: if stage is stack deal with EXP and NUM images if selected 244 245 # if stage is stack deal with EXP and NUM images if selected by running ppstamp again 246 if (!$exitStatus and $stage eq 'stack' and ($options & ($PSTAMP_SELECT_EXP | $PSTAMP_SELECT_NUM))) { 247 # XXX Here I am assuming that nothing relevant gets added to $argString 248 # Need to check 249 my $roiArgs = $params->{job_args}; 250 251 # XXX: define expnum and exptime input images in the params file so that we don't have to 252 # make assumptions about the file rules here 253 my $pathBase = $params->{stack_path_base}; 254 $pathBase = $params->{path_base} unless defined $pathBase; 255 unless (defined $pathBase) { 256 my_die("stack path base undefined found when creating exp or expnum image", $job_id, $PS_EXIT_PROG_ERROR); 257 } 258 $pathBase .= ".unconv"; 259 my $tmpBase = "$outputBase.TMP"; 260 # nocompress because exp image gets corrupted if we do 261 my $command = "$ppstamp $tmpBase $roiArgs -nocompress -stage stack"; 262 # XXX: use file rules 263 # Image is the EXP (exptime) image 264 $command .= " -file $pathBase.exp.fits"; 265 # treat number image as mask 266 $command .= " -mask $pathBase.num.fits" if ($options & $PSTAMP_SELECT_NUM); 267 268 $command .= " -forheader $calibfile" if $calibfile; 269 270 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 271 run(command => $command, verbose => $verbose); 272 273 if (WIFEXITED($error_code)) { 274 $exitStatus = WEXITSTATUS($error_code); 275 } else { 276 print STDERR "ppstamp failed error_code: $error_code\n"; 277 $exitStatus = $PS_EXIT_SYS_ERROR; 278 } 279 280 # command to compress fits files to stdout using gzip 281 my $fpack_gzip = "$fpack -g -S"; 282 $fpack_gzip .= " -D" unless $save_temps; 283 284 if (!$exitStatus and ($options & $PSTAMP_SELECT_NUM)) { 285 # rename the num image if selected since it is not a mask 286 # Change .exp.mk to .num 287 my $tmpName = "$tmpBase.mk.fits"; 288 my $numName = "$outputBase.num.fits"; 289 # optionally fpack it while we're here unless user wants uncompressed images 290 unless ($options & $PSTAMP_SELECT_UNCOMPRESSED) { 291 my $command = "$fpack_gzip $tmpName > $numName"; 292 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 293 run(command => $command, verbose => $verbose); 294 295 if (WIFEXITED($error_code)) { 296 $exitStatus = WEXITSTATUS($error_code); 297 } else { 298 print STDERR "ppstamp failed error_code: $error_code\n"; 299 print STDERR "@$stderr_buf\n"; 300 $exitStatus = $PS_EXIT_SYS_ERROR; 301 } 302 } elsif (!$exitStatus) { 303 rename $tmpName, $numName 304 or my_die ("failed to rename $tmpName to $numName", $job_id, $PS_EXIT_UNKNOWN_ERROR); 305 } 306 307 } 308 # fpack the exp image if not -nocompress 309 unless ($exitStatus or ($options & $PSTAMP_SELECT_UNCOMPRESSED)) { 310 my $command = "$fpack_gzip $tmpBase.fits > $outputBase.exp.fits"; 311 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 312 run(command => $command, verbose => $verbose); 313 314 if (WIFEXITED($error_code)) { 315 $exitStatus = WEXITSTATUS($error_code); 316 } else { 317 print STDERR "ppstamp failed error_code: $error_code\n"; 318 print STDERR "@$stderr_buf\n"; 319 $exitStatus = $PS_EXIT_SYS_ERROR; 320 } 321 } elsif (!$exitStatus) { 322 rename "$tmpBase.fits", "$outputBase.exp.fits" 323 or my_die ("failed to rename $tmpBase.fits to $outputBase.exp.fits", $job_id, $PS_EXIT_UNKNOWN_ERROR); 324 } 325 } 219 326 } else { 220 327 $exitStatus = justCopyFiles($outputBase, \$options, $params); … … 665 772 } 666 773 774 # use ppBackground or ppBackgroundStack to produce background restored images 775 sub create_background_restored_images { 776 my $params = shift; 777 my $stage = $params->{stage}; 778 779 if ($stage ne 'stack' and $stage ne 'chip') { 780 # this function is only supported for chip and stack stage 781 # perhaps the parser should catch this ... 782 print STDERR "background restoration not currently supported for stage $params->{stage}\n"; 783 return $PSTAMP_BG_RESTORE_NOT_AVAILABLE; 784 } 785 786 my $tempdir = tempdir("$temproot/pstamp.$job_id.XXXX", CLEANUP => !$save_temps); 787 my $imagedb = $params->{imagedb}; 788 my $camera = $params->{camera}; 789 790 # reinstantiate IPP Configuration using the now known camera so that we get the applicable file rules 791 $ipprc = PS::IPP::Config->new($camera); 792 793 my $input_image = $params->{image}; 794 my $input_mask = $params->{mask}; 795 my $input_variance = $params->{weight}; 796 797 if ($stage eq 'stack') { 798 my $stack_id = $params->{stack_id}; 799 my $mdcfile = "$tempdir/stk.$stack_id.bkg_input.mdc"; 800 { 801 my $command = "$stack_bkg_mk_mdc --stack_id $stack_id --camera $camera --dbname $imagedb > $mdcfile"; 802 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 803 run(command => $command, verbose => $verbose); 804 unless ($success) { 805 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 806 &my_die("Unable to perform stack_bg_mk_mdc.pl: $error_code", $job_id, $PS_EXIT_CONFIG_ERROR, 'run'); 807 } 808 } 809 810 my $outroot = "$tempdir/stk.$stack_id"; 811 812 # XXX: get otapath from a config file or detrend system 813 my $otapath = "neb:///detrends/background_OTA_models.20140527/test_solutions"; 814 { 815 my $command = "$ppBackgroundStack $outroot -input $mdcfile -image $input_image" 816 . " -OTApath $otapath" ; 817 $command .= " -mask $input_mask" if $input_mask; 818 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 819 run(command => $command, verbose => $very_verbose); 820 unless ($success) { 821 # we turned off verbosity because ppBackgroundStack emits too much output 822 # XXX: perhaps use a log file and save it with the job data 823 print STDERR join "", @$stderr_buf; 824 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 825 &my_die("Unable to perform ppBackgroundStack: $error_code", $job_id, $PS_EXIT_CONFIG_ERROR, 'run'); 826 } 827 } 828 # it's all good change the image to be passed to ppstamp 829 $params->{image} = $ipprc->filename('PPBACKGROUND.STACK.OUTPUT', $outroot) or 830 &my_die("Unable to resolve ppBackgroundStack output file name", $job_id, $PS_EXIT_UNKNOWN_ERROR, 'run'); 831 832 } elsif ($stage eq 'chip') { 833 my $input_mdl = $params->{backmdl}; 834 my $chip_id = $params->{chip_id}; 835 my $class_id = $params->{class_id}; 836 my $outroot = "$tempdir/bgrestored.ch.$chip_id"; 837 { 838 my $command = "$ppBackground $outroot -background $input_mdl -image $input_image"; 839 # XXX: I think ppBackground might always require mask and variance images 840 $command .= " -mask $input_mask"; 841 $command .= " -variance $input_variance"; 842 843 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 844 run(command => $command, verbose => $verbose); 845 unless ($success) { 846 print STDERR join "", @$stderr_buf; 847 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 848 &my_die("Unable to perform ppBackground: $error_code", $job_id, $PS_EXIT_CONFIG_ERROR, 'run'); 849 } 850 } 851 $params->{image} = $ipprc->filename('PPBACKGROUND.OUTPUT', $outroot, $class_id) or 852 &my_die("Unable to resolve ppBackgroundStack output image name", $job_id, $PS_EXIT_CONFIG_ERROR, 'run'); 853 $params->{mask} = $ipprc->filename('PPBACKGROUND.OUTPUT.MASK', $outroot, $class_id) or 854 &my_die("Unable to resolve ppBackgroundStack output mask name", $job_id, $PS_EXIT_CONFIG_ERROR, 'run'); 855 $params->{weight} = $ipprc->filename('PPBACKGROUND.OUTPUT.VARIANCE', $outroot, $class_id) or 856 &my_die("Unable to resolve ppBackgroundStack output variance name", $job_id, $PS_EXIT_CONFIG_ERROR, 'run'); 857 858 } else { 859 # can't get here 860 &my_die( "background restoration not currently supported for stage $params->{stage}\n", 861 $job_id, $PS_EXIT_PROG_ERROR, 'stop'); ; 862 } 863 864 return 0; 865 } 866 667 867 sub my_die 668 868 {
Note:
See TracChangeset
for help on using the changeset viewer.
