IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36018


Ignore:
Timestamp:
Aug 23, 2013, 1:31:54 PM (13 years ago)
Author:
bills
Message:

Further progress on stack_summary postage stamp jobs.
Implementation ignores the ROI. The entire images are returned.
If a requested data product is not found (mask, variance, exp, or num images
from older processings) this is ignored

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r36010 r36018  
    774774        }
    775775
     776
    776777        if ($skycells) {
     778            # We have a list of skycells. Find matching projection cells.
     779
     780            #list of projection_cells that we've included
     781            my %projection_cells_found;
    777782            foreach my $skycell (@$skycells) {
    778783                my $tess_id = $skycell->{tess_id};
     
    781786                my $projection_cell = skycell_id_to_projection_cell($skycell_id);
    782787
    783                 print "$tess_id $skycell_id $projection_cell\n";
    784                 my $command = "$stacktool -dbname $imagedb -summary -tess_id $tess_id -projection_cell $projection_cell";
     788                # only need to include a projection cell once
     789                next if $projection_cells_found{$projection_cell};
     790
     791                $projection_cells_found{$projection_cell} = 1;
     792
     793                # print "$tess_id $skycell_id $projection_cell\n";
     794
     795                my $command = "$stacktool -dbname $imagedb -summary -tess_id $tess_id";
     796                $command .= " -projection_cell $projection_cell";
    785797
    786798                $command .= " -filter $filter" if $filter;
     
    791803            }
    792804        }
    793         # XXX: Lookup stackSummaries that match
    794     }
     805    }
     806
    795807    if ($results) {
    796808        foreach my $summary (@$results) {
     
    799811
    800812            # we need to flesh out the hashes returned with values that the parser expects
     813            $summary->{stage} = 'stack_summary';
    801814            $summary->{component} = $projection_cell;
    802815            $summary->{stage_id} = $summary->{sass_id};
    803             # $summary->{image} = "$path_base.$projection_cell.image.b1.fits";
    804             $summary->{image} = "$path_base.$projection_cell";
     816            $summary->{path_base} = "$path_base.$projection_cell";
     817
     818            # The stack_summary stage doesn't follow the usual ipp conventions for file rules
     819            # and path_base. We leave it up to the program that runs the job to handle this.
     820            # However, the parser uses the image parameter to set the job's outputBase (by removing the .fits)
     821            # so we need to set it. Just use the new path_base.
     822            $summary->{image} = $summary->{path_base};
    805823            $summary->{state} = 'full';
    806824            $summary->{data_state} = 'full';
     
    809827            $summary->{row_index} = [];
    810828            push @{$summary->{row_index}}, 0;
    811             # XXX: is there anything else?
     829
     830            # XXX: Are there any other required parameters?
    812831            # TODO: create a function to validate the components returned
    813             # and make sure that any required elements are there
     832            # and make sure that any required elements are there.
    814833        }
    815834    }
     
    19701989}
    19711990
    1972 # not particularly elegant
     1991# Convert from skycell_id to projection_cell
     1992# This code is not particularly elegant but I think that it matches the SQL used
     1993# to create stackAssocations does.
     1994
    19731995sub skycell_id_to_projection_cell {
    19741996    my $skycell_id = shift;
     1997
     1998    # split skycell_id into '.' separated components
    19751999    my @strs = split '\.', $skycell_id;
    19762000
    19772001    my $num = scalar @strs;
     2002
     2003    # projection_cell is 'skycell_id' plus all .num values except the last one
    19782004    my $projection_cell = $strs[0];
    19792005    for (my $i=1; $i < $num - 1; $i++) {
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm

    r35466 r36018  
    2929                    $PSTAMP_SELECT_BACKMDL
    3030                    $PSTAMP_SELECT_JPEG
     31                    $PSTAMP_SELECT_EXP
     32                    $PSTAMP_SELECT_NUM
    3133                    $PSTAMP_SELECT_UNCOMPRESSED
    3234                    $PSTAMP_SELECT_INVERSE
     
    7173our $PSTAMP_SELECT_BACKMDL   = 32;
    7274our $PSTAMP_SELECT_JPEG      = 64;
    73 # unused 128
    74 # unused 256
     75our $PSTAMP_SELECT_EXP       = 128;
     76our $PSTAMP_SELECT_NUM       = 256;
    7577our $PSTAMP_SELECT_UNCOMPRESSED = 512;
    7678our $PSTAMP_SELECT_INVERSE      = 1024;
  • trunk/pstamp/scripts/pstamp_job_run.pl

    r35903 r36018  
    6262$options &=  ~($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED);
    6363
     64
    6465my $ipprc = PS::IPP::Config->new(); # IPP Configuration
    6566if ($redirect_output) {
     
    9596    my $argString;
    9697    $argString = $params->{job_args};
     98   
     99    my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
     100
    97101    my $stage = $params->{stage};
    98 
    99     # XXX: should we do any other sanity checking?
    100     my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
     102    my_die("stage is not defined", $job_id, $PS_EXIT_DATA_ERROR) if !$stage;
     103
     104    if ($stage eq 'stack_summary') {
     105
     106        # remove options not supported by stack summary
     107        $options &= ~($PSTAMP_SELECT_SOURCES | $PSTAMP_SELECT_BACKMDL | $PSTAMP_SELECT_INVERSE
     108            | $PSTAMP_RESTORE_BACKGROUND);
     109
     110        # stackSummary outputs do not follow the usual IPP conventions for file names.
     111        # The parser (actually Job.pm) has deferred handling this until here
     112        update_stack_summary_filenames($params);
     113
     114    } elsif ($stage ne 'stack') {
     115        # ignore options only supported by stack and stack_summary
     116        $options &= ~($PSTAMP_SELECT_EXP | $PSTAMP_SELECT_NUM);
     117    }
     118   
    101119
    102120    if ($stage eq "raw") {
     
    181199    }
    182200
    183     # my ($tmpImage, $tmpMask, $tmpVariance, $tmproot);
    184 
    185     my $command = "$ppstamp $outputBase $argString $fileArgs";
    186     $command .= " -write_jpeg" if ($options & $PSTAMP_SELECT_JPEG);
    187     $command .= " -nocompress" if ($options & $PSTAMP_SELECT_UNCOMPRESSED);
    188     $command .= " -stage $stage";
    189     $command .= " -forheader $calibfile" if $calibfile;
    190     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    191         run(command => $command, verbose => $verbose);
     201    # unless the stage is stack_summary we use ppstamp to make postage stamps (including -wholefile)
     202    # otherwise we make copies of the input files to the outputs
     203    my $use_ppstamp = ($stage ne 'stack_summary');
    192204
    193205    my $exitStatus;
    194     if (WIFEXITED($error_code)) {
    195         $exitStatus = WEXITSTATUS($error_code);
    196     } else {
    197         print STDERR "ppstamp failed error_code: $error_code\n";
    198         $exitStatus = $PS_EXIT_SYS_ERROR;
     206    if ($use_ppstamp) {
     207        my $command = "$ppstamp $outputBase $argString $fileArgs";
     208        $command .= " -write_jpeg" if ($options & $PSTAMP_SELECT_JPEG);
     209        $command .= " -nocompress" if ($options & $PSTAMP_SELECT_UNCOMPRESSED);
     210        $command .= " -stage $stage";
     211        $command .= " -forheader $calibfile" if $calibfile;
     212        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     213            run(command => $command, verbose => $verbose);
     214
     215        if (WIFEXITED($error_code)) {
     216            $exitStatus = WEXITSTATUS($error_code);
     217        } else {
     218            print STDERR "ppstamp failed error_code: $error_code\n";
     219            $exitStatus = $PS_EXIT_SYS_ERROR;
     220        }
     221        # XXX: if stage is stack deal with EXP and NUM images if selected
     222    } else {
     223        $exitStatus = justCopyFiles($outputBase, \$options, $params);
    199224    }
    200225
     
    208233
    209234        # Note: we are assuming the contents of the PSTAMP filerules here.
    210         my %extensions = ( $PSTAMP_SELECT_IMAGE    => "fits",
    211                            $PSTAMP_SELECT_MASK     => "mk.fits",
    212                            $PSTAMP_SELECT_VARIANCE => "wt.fits",
    213                            $PSTAMP_SELECT_SOURCES  => "cmf",
    214                            $PSTAMP_SELECT_JPEG     => "jpg");
    215 
    216         my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES);
     235        my %extensions = ( $PSTAMP_SELECT_IMAGE    => 'fits',
     236                           $PSTAMP_SELECT_MASK     => 'mk.fits',
     237                           $PSTAMP_SELECT_VARIANCE => 'wt.fits',
     238                           $PSTAMP_SELECT_SOURCES  => 'cmf',
     239                           $PSTAMP_SELECT_JPEG     => 'jpg',
     240                           $PSTAMP_SELECT_EXP      => 'exp.fits',
     241                           $PSTAMP_SELECT_NUM      => 'num.fits');
     242
     243        my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE
     244            | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES | $PSTAMP_SELECT_EXP | $PSTAMP_SELECT_NUM);
    217245
    218246        foreach my $key (keys (%extensions)) {
     
    534562}
    535563
     564sub 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->{exp}    = $path_base . ".exp.b1.fits";
     573    $params->{num}    = $path_base . ".num.b1.fits";
     574
     575}
     576
     577sub myCopy {
     578    my ($dest, $src, $type, $dieOnFail) = @_;
     579
     580    my $result;
     581    my $resolved = $ipprc->file_resolve($src);
     582    if ($ipprc->file_exists($resolved)) {
     583        $result = copy($resolved, $dest);
     584    } else {
     585        my $msg = "Specified source $type image $src not found.";
     586        if ($dieOnFail) {
     587            $msg .= "\n";
     588        } else {
     589            $msg .= " ignoring\n";
     590        }
     591        carp $msg;
     592        $result = 0;
     593    }
     594   
     595    if (!$result and $dieOnFail) {
     596        &my_die("Unable to copy $type image", $job_id, $PS_EXIT_SYS_ERROR, 'run');
     597    }
     598    return $result;
     599}
     600
     601sub justCopyFiles {
     602    my ($outputBase, $r_options, $params) = @_;
     603
     604    my $options = $$r_options;
     605    if ($options & $PSTAMP_SELECT_IMAGE) {
     606        myCopy("$outputBase.fits", $params->{image}, 'image', 1);
     607    }
     608    if ($options & $PSTAMP_SELECT_MASK) {
     609        if (!myCopy("$outputBase.mk.fits", $params->{mask}, 'mask', 0)) {
     610            $options &= ~$PSTAMP_SELECT_MASK;
     611        }
     612    }
     613    if ($options & $PSTAMP_SELECT_VARIANCE) {
     614        if (!myCopy("$outputBase.wt.fits", $params->{weight}, 'variance', 0)) {
     615            $options =  ~$PSTAMP_SELECT_VARIANCE;
     616        }
     617    }
     618    if ($options & $PSTAMP_SELECT_EXP) {
     619        if (!myCopy("$outputBase.exp.fits", $params->{exp}, 'exp', 0)) {
     620            $options &= ~$PSTAMP_SELECT_EXP;
     621        }
     622    }
     623    if ($options & $PSTAMP_SELECT_NUM) {
     624        if (!myCopy("$outputBase.num.fits", $params->{num}, 'num', 0)) {
     625            $options &= ~$PSTAMP_SELECT_NUM;
     626        }
     627    }
     628
     629    $$r_options = $options;
     630
     631    return 0;
     632}
     633
    536634sub my_die
    537635{
Note: See TracChangeset for help on using the changeset viewer.