IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37262


Ignore:
Timestamp:
Aug 15, 2014, 3:51:40 PM (12 years ago)
Author:
bills
Message:

Implement creating postage stamps for stack EXP and EXPNUM images
(exposure time and exposure number).
This is done by running ppstamp a second time using the EXP image
as input and EXPNUM as mask. If compression is requested use fpack
to gzip compress them because the EXP image gets mangled by using
the compression usually used for images.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-pv3-20140717/pstamp/scripts/pstamp_job_run.pl

    r36812 r37262  
    9191my $ppBackgroundStack = can_run('ppBackgroundStack') or (warn "Can't find ppBackgroundStack" and $missing_tools = 1);
    9292my $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);
     93my $fpack = can_run('fpack') or (warn "Can't find fpack" and $missing_tools = 1);
     94
    9395
    9496if ($missing_tools) {
     
    146148    my $mask;
    147149    my $variance;
    148 
    149     # We need to background restore HERE
    150     # and change the image file supplied to ppstamp
    151150
    152151    my $fileArgs = " -file $params->{image}";
     
    224223
    225224    # unless the stage is stack_summary we use ppstamp to make postage stamps (including -wholefile)
    226     # otherwise we make copies of the input files to the outputs
     225    # if stage is stack_summary we make copies of the input files to the outputs
    227226    my $use_ppstamp = ($stage ne 'stack_summary');
    228227
     
    243242            $exitStatus = $PS_EXIT_SYS_ERROR;
    244243        }
    245         # 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 ($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            my $pathBase = "$params->{stack_path_base}.unconv";
     251            my $tmpBase = "$outputBase.TMP";
     252            # nocompress because exp image gets corrupted if we do
     253            my $command = "$ppstamp $tmpBase $roiArgs  -nocompress -stage stack";
     254            # XXX: use file rules
     255            # Image is the EXP (exptime) image
     256            $command .= " -file $pathBase.exp.fits";
     257            # treat number image as mask
     258            $command .= " -mask $pathBase.num.fits" if ($options & $PSTAMP_SELECT_NUM);
     259
     260            $command .= " -forheader $calibfile" if $calibfile;
     261
     262            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     263                run(command => $command, verbose => $verbose);
     264
     265            if (WIFEXITED($error_code)) {
     266                $exitStatus = WEXITSTATUS($error_code);
     267            } else {
     268                print STDERR "ppstamp failed error_code: $error_code\n";
     269                $exitStatus = $PS_EXIT_SYS_ERROR;
     270            }
     271
     272            # command to compress fits files to stdout using gzip
     273            my $fpack_gzip = "$fpack -g -S";
     274            $fpack_gzip .= " -D" unless $save_temps;
     275
     276            if (!$exitStatus and ($options & $PSTAMP_SELECT_NUM)) {
     277                # rename the num image if selected since it is not a mask
     278                # Change .exp.mk to .num
     279                my $tmpName = "$tmpBase.mk.fits";
     280                my $numName = "$outputBase.num.fits";
     281                # optionally fpack it while we're here unless user wants uncompressed images
     282                unless ($options & $PSTAMP_SELECT_UNCOMPRESSED) {
     283                    my $command = "$fpack_gzip $tmpName > $numName";
     284                    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     285                        run(command => $command, verbose => $verbose);
     286
     287                    if (WIFEXITED($error_code)) {
     288                        $exitStatus = WEXITSTATUS($error_code);
     289                    } else {
     290                        print STDERR "ppstamp failed error_code: $error_code\n";
     291                        print STDERR "@$stderr_buf\n";
     292                        $exitStatus = $PS_EXIT_SYS_ERROR;
     293                    }
     294                } elsif (!$exitStatus) {
     295                    rename $tmpName, $numName
     296                        or my_die ("failed to rename $tmpName to $numName", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     297                }
     298
     299            }
     300            # fpack the exp image if not -nocompress
     301            unless ($exitStatus or ($options & $PSTAMP_SELECT_UNCOMPRESSED)) {
     302                my $command = "$fpack_gzip $tmpBase.fits > $outputBase.exp.fits";
     303                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     304                    run(command => $command, verbose => $verbose);
     305
     306                if (WIFEXITED($error_code)) {
     307                    $exitStatus = WEXITSTATUS($error_code);
     308                } else {
     309                    print STDERR "ppstamp failed error_code: $error_code\n";
     310                    print STDERR "@$stderr_buf\n";
     311                    $exitStatus = $PS_EXIT_SYS_ERROR;
     312                }
     313            } elsif (!$exitStatus) {
     314                rename "$tmpBase.fits", "$outputBase.exp.fits"
     315                    or my_die ("failed to rename $tmpBase.fits to $outputBase.exp.fits", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     316            }
     317        }
    246318    } else {
    247319        $exitStatus = justCopyFiles($outputBase, \$options, $params);
Note: See TracChangeset for help on using the changeset viewer.