IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 27, 2014, 8:17:01 AM (12 years ago)
Author:
bills
Message:

from ipp-pv3-20140717 tag
Implement making stamps of exptime and exp num images from stacks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_job_run.pl

    r36812 r37318  
    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 (!$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        }
    246326    } else {
    247327        $exitStatus = justCopyFiles($outputBase, \$options, $params);
Note: See TracChangeset for help on using the changeset viewer.