IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25143


Ignore:
Timestamp:
Aug 20, 2009, 11:12:36 AM (17 years ago)
Author:
watersc1
Message:
 
Location:
branches/czw_branch/cleanup/pstamp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup/pstamp/scripts/pstamp_finish.pl

    r25051 r25143  
    88use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    99use Pod::Usage qw( pod2usage );
     10use Carp;
    1011
    1112use Time::Local;
     
    4748
    4849my $ipprc = PS::IPP::Config->new(); # IPP Configuration
    49 
    5050if ($redirect_output) {
    5151    my $logDest = "$out_dir/psfinish.$req_id.log";
     
    9494        if (!mkdir $out_dir) {
    9595            print STDERR "cannot create output directory $out_dir";
    96             stop_request($req_id, $PS_EXIT_UNKNOWN_ERROR);
     96            stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
    9797        }
    9898
     
    102102        # request
    103103        print STDERR "output directory $out_dir exists but is not a directory";
    104         stop_request($req_id, $PS_EXIT_UNKNOWN_ERROR);
     104        stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
    105105    }
    106106
    107107    if (! -e $req_file ) {
    108108        print STDERR "request file $req_file is missing\n";
    109         stop_request($req_id, $PS_EXIT_CONFIG_ERROR);
     109        stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
    110110    }
    111111
     
    117117        # point
    118118        print STDERR "failed to read request_file $req_file" ;
    119         stop_request($req_id, $PS_EXIT_CONFIG_ERROR);
     119        stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
    120120    }
    121121
     
    154154                print STDERR "Request $req_id produced no jobs.\n"
    155155            }
    156             # No Jobs.
    157             # XXXX Ouch. We need results for each rownum (each request specification) in the request file
    158             # including those that produced no jobs.
    159             # for now add an entry for rownum 1 and a phony error code.
    160             # we've included parse_error.txt to the fileset if it exists
    161             #
    162             my $rownum = 0;
    163             my $fault = 42; # get a real error code
    164             print $tdf "$rownum|$fault|0|0|";
    165             print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n";
     156            # This should not happen. A fake job should be queued
     157            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    166158        } else {
    167159            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
     
    182174        my $exp_id = $job->{exp_id};
    183175
     176        if ($fault eq $PSTAMP_DUP_REQUEST) {
     177            # this request had a duplicate request name. We can't put the results
     178            # on the data store since the product name is already used
     179            # maybe we could be more clever about this and choose a fileset name
     180            stop_request_and_exit($req_id, $fault);
     181        }
     182
    184183        my ($row, $req_info, $project) = get_request_info($rows, $rownum);
    185184
     
    188187        if (!$image_db) {
    189188            carp("failed to find imagedb for project: $project");
    190             stop_request($req_id, $PS_EXIT_CONFIG_ERROR);
     189            if (!$fault) {
     190                stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
     191            }
    191192        }
    192193
     
    227228                print $tdf "$exp_info|";
    228229                print $tdf "$req_info|";
     230                print $tdf "\n";
    229231            }
    230232        } else {
     
    277279}
    278280
    279 sub stop_request {
     281sub stop_request_and_exit {
    280282    my $req_id = shift;
    281283    my $fault  = shift;
     
    299301    my $row = $rows->{$rownum};
    300302
     303    # these may be set to null during processing
     304    my $component = $row->{COMPONENT};
     305    $component = "null" if !$component;
     306    my $tess_id = $row->{TESS_ID};
     307    $tess_id = "null" if !$tess_id;
     308
    301309    # This is ugly, error prone and hard to change.
    302310    # Create a results file module and provide a list of the names (we have the data in the columns)
    303311    my $rowinfo = "$row->{PROJECT}|$row->{JOB_TYPE}|$row->{REQ_TYPE}|$row->{IMG_TYPE}|";
    304     $rowinfo   .= "$row->{ID}|$row->{TESS_ID}|$row->{COMPONENT}|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";
     312    $rowinfo   .= "$row->{ID}|$tess_id|$component|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";
    305313    $rowinfo   .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|";
    306314    $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}";
     
    313321    my $exp_id = shift;
    314322
    315     if (!$exp_id) {
     323    if (!$exp_id or !$image_db) {
    316324        # no exposure id just return zeros
    317325        # XXX: we could put a value in for filter, but we don't have a good place to find it
  • branches/czw_branch/cleanup/pstamp/scripts/pstamp_job_run.pl

    r25051 r25143  
    208208        $command .= " -job_id $job_id";
    209209        $command .= " -fault $exit_code";
     210        # XXX: fix pstamptool to not require -state when -fault with nonzero value is provided
     211        $command .= " -state run";
    210212        $command .= " -dbname $dbname" if defined $dbname;
    211213        $command .= " -dbserver $dbserver" if defined $dbserver;
  • branches/czw_branch/cleanup/pstamp/scripts/pstamp_listjobs.pl

    r24951 r25143  
    1212my $verbose;
    1313my $dbname;
    14 my $dserver;
     14my $dbserver;
    1515
    1616GetOptions(
  • branches/czw_branch/cleanup/pstamp/scripts/pstampparse.pl

    r25051 r25143  
    1414use PS::IPP::PStamp::Job qw( :standard );
    1515use File::Temp qw(tempfile);
     16use Carp;
    1617
    1718my $verbose;
     
    9192# make sure the file contains what we are expecting
    9293
    93 die "$request_file_name is not a PS1_PS_REQEST" if $extname ne "PS1_PS_REQUEST";
    94 die "REQ_NAME not found in $request_file_name"  if (!$req_name);
    95 die "wrong EXTVER $extver found in $request_file_name" if ($extver ne "1");
     94# we shouldn't get here if this is the case so just die. No need to notify the client
     95my_die("$request_file_name is not a PS1_PS_REQEST", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST";
     96my_die("REQ_NAME not found in $request_file_name", $PS_EXIT_PROG_ERROR)  if (!$req_name);
     97my_die("wrong EXTVER $extver found in $request_file_name", $PS_EXIT_PROG_ERROR) if ($extver ne "1");
     98
     99# check for duplicate request name
     100if (!$no_update) {
     101    my $command = "$pstamptool -listreq  -name $req_name";
     102    $command .= " -dbname $dbname" if $dbname;
     103    $command .= " -dbserver $dbserver" if $dbserver;
     104    # no verbose so that error message about request not found doesn't appear in parse_error.txt
     105    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     106        run(command => $command, verbose => 0);
     107    my $exitStatus = $error_code >> 8;
     108    if ($success) {
     109        # -listreq succeeded duplicate request name
     110        insertFakeJobForRow(undef, 0, $PSTAMP_DUP_REQUEST);
     111        exit 0;
     112    } elsif ($exitStatus ne $PS_EXIT_DATA_ERROR) {
     113        # wrong error code something else is wrong
     114        my_die("$command failed", $exitStatus);
     115    }
     116}
    96117
    97118if ($req_id and !$no_update) {
     119    # update the database with the request name. This will be used as the
     120    # the output data store's product name
    98121    my $command = "$pstamptool -updatereq -req_id $req_id  -name $req_name";
    99122    $command .= " -outProduct $product";
     
    103126        run(command => $command, verbose => $verbose);
    104127    unless ($success) {
    105         die "$command failed";
     128        my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
    106129    }
    107130}
     
    120143    }
    121144    my $table =  $mdcParser->parse(join "", @$stdout_buf) or
    122         die("Unable to parse metdata config doc");
     145        my_die("Unable to parse metdata config doc", $PS_EXIT_UNKNOWN_ERROR);
    123146
    124147    $rows = parse_md_list($table);
     
    143166    # parameters that select the images of interest
    144167    my $project  = $row->{PROJECT};
     168
     169    # note: resolve_project avoids running pstamptool every time by remembering the
     170    # last project resolved
     171    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
     172    if (!$proj_hash) {
     173        print STDERR "project $project not found\n"  if $verbose;
     174        insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PRODUCT);
     175        $num_jobs++;
     176        next;
     177    }
    145178    my $req_type = $row->{REQ_TYPE};
    146179    $stage = $row->{IMG_TYPE};
     
    153186
    154187    my $option_mask= $row->{OPTION_MASK};
    155 
    156     die "valid region of interest is required to make postage stamps"
    157         if (($job_type eq "stamp") and ! validROI($row));
     188    my $inverse = ($option_mask & $PSTAMP_SELECT_INVERSE) ? 1 : 0;
     189    $row->{inverse} = $inverse;
    158190
    159191    my $skycenter = $row->{skycenter} = ! ($row->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
    160     $component = "" if (defined($component) and ($component eq "null" or $component eq "all"));
     192
     193    my $search_component = (!defined($component) or ($component eq "null")) ? "" : $component;
    161194   
    162     die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri");
    163 
    164 
    165     # note: resolve_project avoids running pstamptool every time by remembering the
    166     # last project resolved
    167     my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
    168     die "project $project not found\n" unless $proj_hash;
     195    if (!$skycenter and !$search_component) {
     196        print STDERR "COMPONENT must be specified for pixel coordinate ROI\n" if $verbose;
     197        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     198        $num_jobs++;
     199        next;
     200    }
     201
     202    $search_component = "" if $search_component eq "all";
     203
     204    if (($job_type eq "stamp") and ! validROI($row)) {
     205        print STDERR "invalid ROI for row $rownum\n" if $verbose;
     206        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     207        $num_jobs++;
     208        next;
     209    }
     210
     211   
     212    # $mode list_uri is a debugging mode (it may used by the http interface)
     213    # if this happens just croak
     214    my_die("job_type is list_uri but mode is $mode", $PS_EXIT_PROG_ERROR) if ($job_type eq "list_uri") and ($mode ne "list_uri");
     215
    169216
    170217    my $image_db   = $proj_hash->{dbname};
     
    173220
    174221    # collect rows with the same images of interest in a list so that they
    175     # can be processed optimially
     222    # can be looked up together
    176223    if (@rowList) {
    177224        my $firstRow = $rowList[0];
    178         # XXX: the collecting might work with !$skycenter but I need to think about it
    179         if ($skycenter and same_images_of_interest($row, $firstRow)) {
     225        # note order of these parameters matters
     226        if (same_images_of_interest($firstRow, $row)) {
     227
     228            # add this row to the list and move on
    180229            push @rowList, $row;
    181             # On to the next row
     230
    182231            next;
     232
    183233        } else {
    184             # queue the jobs for this set of rows
     234            # this row has different selectors
     235            # queue the jobs for the ones we've collected
    185236            $num_jobs += queueJobs($mode, \@rowList, $imageList);
    186237            @rowList = ();
     
    188239    }
    189240
     241    # look up images for the current row
    190242    if ($req_type eq "bycoord") {
    191         die "center must be specified in sky coordintes for bycoord" if ( ! $skycenter);
    192         die "lookup bycoord is not yet implemented";
     243        if (!$skycenter) {
     244            print STDERR "center must be specified in sky coordintes for bycoord" if $verbose;
     245            insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     246            $num_jobs++;
     247            next;
     248        }
     249        print STDERR "lookup bycoord is not yet implemented" if $verbose;
     250        insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
     251        $num_jobs++;
     252        next;
    193253    } else {
    194 
    195         # Call PS::IPP::PStamp::Job's locate_images routine to get the parameters for this
    196         # request specification. An array reference is returned
     254        # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
     255        # request specification. An array reference is returned.
    197256        my ($x, $y);
    198         $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $component, $skycenter,
    199                 $x, $y, $mjd_min, $mjd_max, $filter, $verbose);
    200     }
    201 
    202     if (!$imageList or !@$imageList) {
    203         print STDERR "no matching images found for row $rownum\n";
    204         next;
    205     }
    206     $row->{need_magic} = $need_magic;
    207     push @rowList, $row;
     257
     258        $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $search_component,
     259                $inverse, $skycenter, $x, $y, $mjd_min, $mjd_max, $filter, $verbose);
     260
     261        if (!$imageList or !@$imageList) {
     262            print STDERR "no matching images found for row $rownum\n" if $verbose;
     263            # note in this case queueJobs inserts the fake job for these rows
     264        }
     265        $row->{need_magic} = $need_magic;
     266        push @rowList, $row;
     267    }
    208268}
    209269
     
    212272}
    213273
    214 if ($mode eq "queue_jobs") {
    215     if ($num_jobs) {
    216         exit 0;
    217     } else {
    218         # no jobs queued return error to get the request stopped
    219         # TODO: need to define meaningful error codes
    220         exit $PS_EXIT_UNKNOWN_ERROR;
    221     }
    222 } else {
    223     exit 0;
    224 }
     274if (($mode eq "queue_jobs") and ($num_jobs eq 0)) {
     275    print STDERR "no jobs created for $req_name\n" if $verbose;
     276    insertFakeJobForRow(undef, 0, $PSTAMP_UNKNOWN_ERROR);
     277}
     278
     279# PAU
     280
     281exit 0;
    225282
    226283
     
    232289    my $have_skycells = shift;
    233290    my $need_magic = shift;
     291    my $num_jobs = 0;
     292
     293    my $rownum = $row->{ROWNUM};
     294
     295    my $components = $row->{components};
     296
     297    my $roi_string;
     298
     299    # note values were insured to be numbers in validROI()
     300    my $x = $row->{CENTER_X};
     301    my $y = $row->{CENTER_Y};
     302    my $w = $row->{WIDTH};
     303    my $h = $row->{HEIGHT};
     304    my $coord_mask = $row->{COORD_MASK};
     305    if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) {
     306        if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) {
     307            $roi_string = "-pixcenter $x $y";
     308        } else {
     309            $roi_string = "-skycenter $x $y";
     310        }
     311        if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) {
     312            $roi_string .= " -pixrange $w $h";
     313        } else {
     314            $roi_string .= " -arcrange $w $h";
     315        }
     316    }
    234317
    235318    # loop over images
     
    244327
    245328        # skip this component if it is not in the list for this row
    246         next if !$row->{components}->{$component};
    247 
    248         my $rownum = $row->{ROWNUM};
    249 
    250         my $roi_string;
    251 
    252         # note values were insured to be numbers in validROI()
    253         my $x = $row->{CENTER_X};
    254         my $y = $row->{CENTER_Y};
    255         my $w = $row->{WIDTH};
    256         my $h = $row->{HEIGHT};
    257         my $coord_mask = $row->{COORD_MASK};
    258         if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) {
    259             if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) {
    260                 $roi_string = "-pixcenter $x $y";
    261             } else {
    262                 $roi_string = "-skycenter $x $y";
    263             }
    264             if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) {
    265                 $roi_string .= " -pixrange $w $h";
    266             } else {
    267                 $roi_string .= " -arcrange $w $h";
    268             }
    269         }
     329        next if ! $components->{$component};
     330
     331        $job_num++;
    270332
    271333        my $imagefile = $image->{image};
    272334        if (($stage ne "stack") and ($need_magic and !$image->{magicked})) {
    273             # XXX: should we add a faulted job so the client can know what happened?
     335            # XXX: should we add a faulted job so the client can know what happened if no images come back?
    274336            print STDERR "skippping non-magicked image $imagefile\n" if $verbose;
     337
     338            # for now assume yes.
     339
     340            insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_DESTREAKED);
     341
    275342            next;
    276343        }
     
    282349        }
    283350
    284         $job_num++;
    285 
    286351        # add astrometry file for raw and chip images if one is available
    287352        if (($stage eq "chip") || ($stage eq "raw")) {
     
    302367
    303368        # copy the argument list to a file
    304         open ARGSLIST, ">$argslist" or die "failed to open $argslist";
     369        open ARGSLIST, ">$argslist" or my_die("failed to open $argslist", $PS_EXIT_UNKNOWN_ERROR);
    305370        print ARGSLIST "$args\n";
    306         close ARGSLIST or die "failed to close $argslist";
    307 
    308         # XXX: TODO: here is where we need to check whether or not the source inputs still exist
    309         # and if not, queue an update job and set the job state appropriately.
     371        close ARGSLIST or my_die("failed to close $argslist", $PS_EXIT_UNKNOWN_ERROR);
    310372
    311373        my $newState = "run";
     374        my $fault = 0;
     375
     376        if (($stage ne 'stack') and ($stage ne 'raw')) {
     377            if (($image->{state} eq 'goto_purged') or ($image->{data_state} eq 'purged')) {
     378                $newState = 'stop';
     379                $fault = $PSTAMP_GONE;
     380            } elsif (($image->{data_state} ne 'full') or ($image->{state} ne 'full' )) {
     381                # XXX here is where we need to queue an update job
     382                # for now just say that the image is not available
     383                $newState = 'stop';
     384                $fault = $PSTAMP_NOT_AVAILABLE;
     385            }
     386        }
    312387
    313388        $num_jobs++;
    314389        my $command = "$pstamptool -addjob  -req_id $req_id -job_type $row->{JOB_TYPE}"
    315390                        . " -outputBase $output_base -rownum $rownum -state $newState";
     391        $command .= " -fault $fault" if $fault;
    316392        $command .= " -exp_id $exp_id" if $exp_id;
    317393        $command .= " -dbname $dbname" if $dbname;
     
    331407                # should we keep going for other uris? If so how do we report that some
    332408                # of the work that the request wanted isn't going to get done
    333                 die "failed to queue job for request $req_id";
     409                my_die("failed to queue job for request $req_id", $PS_EXIT_UNKNOWN_ERROR);
    334410            }
    335411        } else {
     
    337413        }
    338414    }
     415    if ( $num_jobs == 0 ) {
     416        print STDERR "no jobs for row $rownum\n" if $verbose;
     417        insertFakeJobForRow($row, 1, $PSTAMP_NO_OVERLAP);
     418        $num_jobs = 1;
     419    }
    339420    return $num_jobs;
    340421}
    341422
     423# queue jobs for a collection of request specifications that have the same Images of Interest
    342424sub queueJobs
    343425{
     
    358440        }
    359441    } elsif ($job_type eq "get_image") {
    360         die "get_image jobs not implemented yet";
     442        print STDERR "get_image jobs not implemented yet" if $verbose;
     443        foreach my $row (@$rowList) {
     444            insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
     445            $num_jobs++;
     446        }
    361447    } else {
    362         my $thisRun;
    363 
    364         my ($pointsList, $pointsListName) = tempfile ("/tmp/pointsList.XXXX", UNLINK => !$save_temps);
    365         foreach my $row (@$rowList) {
    366             print $pointsList "$row->{ROWNUM} $row->{CENTER_X} $row->{CENTER_Y}\n";
    367             $row->{components} = {};
    368         }
    369         close $pointsList;
     448        if (!$imageList or (scalar @$imageList eq 0)) {
     449            # we didn't find any images for this set of rows. Insert a fake job to carry
     450            # the status back to the requestor
     451            foreach my $row (@$rowList) {
     452                insertFakeJobForRow($row, 1, $PSTAMP_NO_IMAGE_MATCH);
     453                $num_jobs++;
     454            }
     455            return $num_jobs;
     456        }
    370457
    371458        my $have_skycells;
     
    376463        }
    377464       
     465        my $thisRun;
     466
     467        my ($pointsList, $pointsListName) = tempfile ("/tmp/pointsList.XXXX", UNLINK => !$save_temps);
     468        my $npoints = 0;
     469        foreach my $row (@$rowList) {
     470            $row->{components} = {};
     471            if ($row->{skycenter}) {
     472                print $pointsList "$row->{ROWNUM} $row->{CENTER_X} $row->{CENTER_Y}\n";
     473                $npoints++;
     474            } else {
     475                # this row's center is in pixel coordinates add all images to the component list for this row
     476                foreach my $i (@$imageList) {
     477                    my $component = $have_skycells ? $i->{skycell_id} : $i->{class_id};
     478                    my_die( "image found with no value for component", $PS_EXIT_UNKNOWN_ERROR) if !$component;
     479                    $row->{components}->{$component} = 1;
     480                }
     481            }
     482        }
     483        close $pointsList;
     484
    378485        my $tess_dir_abs;
    379486        my $last_tess_id = "";
    380487        while ($thisRun = getOneRun($stage, $imageList)) {
    381             {
     488            if ($npoints) {
     489                # we collected a set of sky coordintates above filter the images so that only
     490                # those tat contain the centers are processed
    382491                my $command = "$dvoImagesAtCoords $pointsListName";
    383492                if ($have_skycells) {
     
    391500                } else {
    392501                    my $astrom = $thisRun->[0]->{astrom};
    393                     die "no astrometry file found" if !$astrom;
     502                    my_die( "no astrometry file found", $PS_EXIT_UNKNOWN_ERROR) if !$astrom;
    394503                    my $astrom_resolved = $ipprc->file_resolve($astrom);
    395504                    $command .= " -astrom $astrom_resolved";
     
    400509                    print STDERR @$stderr_buf;
    401510                    my $rc = $error_code >> 8;
    402                     die "dvoImagesAtCoords failed: $rc";
     511                    my_die( "dvoImagesAtCoords failed: $rc", $PS_EXIT_UNKNOWN_ERROR);
    403512                }
    404513                # now we have a list of row numbers and components
     
    422531    }
    423532    return $num_jobs;
     533}
     534sub insertFakeJobForRow
     535{
     536    my $row = shift;
     537    my $job_num = shift;
     538    my $fault = shift;
     539
     540    my ($job_type, $rownum);
     541    if ($row) {
     542        $job_type = $row->{JOB_TYPE};
     543        $rownum = $row->{ROWNUM};
     544    } else {
     545        $job_type = "none";
     546        $rownum = 0;
     547    }
     548
     549    my $command = "$pstamptool -addjob  -req_id $req_id -job_type $job_type"
     550                        . " -rownum $rownum -state stop -fault $fault";
     551    $command .= " -dbname $dbname" if $dbname;
     552    $command .= " -dbserver $dbserver" if $dbserver;
     553
     554    if ($mode eq "list_job") {
     555        # this is a debugging mode, just print the pstamptool that would have run
     556        # this is sort of like the mode -noupdate that some other tools support
     557        print "$command\n";
     558    } elsif (!$no_update) {
     559        # mode eq "queue_job"
     560        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     561            run(command => $command, verbose => $verbose);
     562        unless ($success) {
     563            print STDERR @$stderr_buf;
     564            # XXX TODO: now what? Should we mark the error state for the request?
     565            # should we keep going for other uris? If so how do we report that some
     566            # of the work that the request wanted isn't going to get done
     567            my_die("failed to queue job for request $req_id", $PS_EXIT_UNKNOWN_ERROR);
     568        }
     569    } else {
     570        print "skipping command: $command\n";
     571    }
    424572}
    425573
     
    440588        return $image->{diff_id};
    441589    } else {
    442         die "unenexpected stage: $stage found";
     590        my_die("unenexpected stage: $stage found", $PS_EXIT_PROG_ERROR);
    443591    }
    444592}
     
    476624    return 0 if ($r1->{IMG_TYPE} ne $r2->{IMG_TYPE});
    477625    return 0 if ($r1->{ID} ne $r2->{ID});
     626    return 0 if ($r1->{inverse} ne $r2->{inverse});
    478627
    479628    if (defined($r1->{COMPONENT})) {
    480629        return 0 if !defined $r2->{COMPONENT} or ($r1->{COMPONENT} ne $r2->{COMPONENT});
    481630    } elsif (defined($r2->{COMPONENT})) {
     631        # if first row has no component all of the images will be retrieved, so
     632        # the fact that this row has a component is ok. Fall through to return 1
     633        # XXX Nope that doesn't work (yet)
    482634        return 0;
    483635    }
     
    514666    return undef;
    515667}
     668
     669sub my_die
     670{
     671    my $msg = shift;
     672    my $fault = shift;
     673
     674    carp $msg;
     675
     676    # we don't fault the request here pstamp_parser_run.pl handles that if necessary
     677
     678    return $fault;
     679}
  • branches/czw_branch/cleanup/pstamp/src/ppstampMakeStamp.c

    r21403 r25143  
    1717
    1818static void skyToChip(pmAstromObj *pt, pmFPA *fpa, pmChip *chip);
     19static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance);
    1920
    2021// convert the input chip's transforms to the output
     
    325326            break;
    326327        }
     328        if (readout->variance) {
     329            outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
     330            if (!outReadout->variance) {
     331                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
     332                status = false;
     333                break;
     334            }
     335        }
    327336        if (readout->mask) {
    328337            outReadout->mask = extractStamp(readout->mask, extractRegion,  0);
     
    332341                break;
    333342            }
    334         }
    335         if (readout->variance) {
    336             outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
    337             if (!outReadout->variance) {
    338                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
    339                 status = false;
    340                 break;
     343
     344            if (!setMaskedToNAN(config, outReadout->image, outReadout->mask, outReadout->variance)) {
     345                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");
     346                 status = false;
     347                 break;
    341348            }
    342349        }
     
    668675
    669676
     677static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance)
     678{
     679    bool status;
     680    psMetadata *masks = psMetadataLookupMetadata(&status, config->recipes, "MASKS");
     681    if (!status) {
     682        psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n");
     683        return false;
     684    }
     685    // we set anything masked to NAN except if CONV.POOR is the only bit set
     686    // First check the old value
     687    psU32 convPoor = psMetadataLookupU32(&status, masks, "POOR.WARP");
     688    if (!status) {
     689        convPoor = psMetadataLookupU32(&status, masks, "CONV.POOR");
     690        if (!status) {
     691            psError(PM_ERR_CONFIG, false, "failed to lookup mask value for CONV.POOR in recipes\n");
     692            return false;
     693        }
     694    }
     695    psU32 maskMask = ~convPoor;
     696
     697    double exciseValue;
     698    if (image->type.type == PS_TYPE_U16) {
     699        exciseValue = 0xffff;
     700    } else if (image->type.type == PS_TYPE_F32) {
     701        exciseValue = NAN;
     702    } else {
     703         psError(PS_ERR_PROGRAMMING, true, "unexpected image type: %d\n", image->type.type);
     704        return false;
     705    }
     706    long numExcised = 0;
     707    for (int y=0; y<image->numRows; y++) {
     708        for (int x=0; x<image->numCols; x++) {
     709            psU16 maskVal = psImageGet(mask, x, y);
     710            if (maskVal & maskMask) {
     711                numExcised++;
     712                psImageSet(image, x, y, exciseValue);
     713                if (variance) {
     714                    psImageSet(variance, x, y, exciseValue);
     715                }
     716            }
     717        }
     718    }
     719    fprintf(stderr, "excised %ld masked pixels\n", numExcised);
     720
     721    return true;
     722}
Note: See TracChangeset for help on using the changeset viewer.