IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 12, 2013, 11:03:47 AM (13 years ago)
Author:
bills
Message:

If user specifies RELEASE_NAME or SURVEY use releasetool
to look up images.
When sources are selected extract them from the region of interest
using ppstamp. Use skycal cmf if available.

File:
1 edited

Legend:

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

    r35384 r35398  
    1515our @EXPORT_OK = qw(
    1616                    locate_images
    17                     new_locate_images
     17                    locate_images_for_row
    1818                    resolve_project
    1919                    getCamRunByCamID
     
    7979           ($req_type ne "byskycell");
    8080
    81     if (!$default_data_groups) {
     81    if (!$data_group and !$default_data_groups) {
    8282        $default_data_groups = load_data_groups($verbose);
    8383    }
     
    171171
    172172    my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $stage, $id, $tess_id, $component,
    173         $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     173        $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     174        undef, undef, undef, $verbose);
    174175
    175176    return $results;
    176177}
    177178
    178 sub new_locate_images {
     179sub locate_images_for_row {
    179180    my $ipprc    = shift;
    180181    my $imagedb  = shift;
     
    195196           ($req_type ne "byskycell");
    196197
    197     if (!$default_data_groups) {
    198         $default_data_groups = load_data_groups($verbose);
    199     }
    200 
    201198    my $stage     = $row->{IMG_TYPE};
    202199    my $id        = $row->{ID};
     
    208205    my $mjd_max   = $row->{MJD_MAX};
    209206    my $data_group = $row->{DATA_GROUP};
     207    if (isnull($data_group) and !$default_data_groups) {
     208        $default_data_groups = load_data_groups($verbose);
     209    }
    210210
    211211    my $rownum     = $row->{ROWNUM};
     
    230230        $filter = undef;
    231231    }
    232 
    233 
    234232
    235233    if ($req_type eq "bycoord") {
     
    240238    }
    241239
    242     # for compatability with the lower level functions
     240    # for compatability with the lower level functions that haven't been converted to take a single row
    243241    my $rowList = [$row];
    244242
     
    251249        return $results;
    252250    }
     251
     252    my ($release_name, $survey) = get_release_info($row);
    253253
    254254    if ($req_type eq "bydiff") {
     
    303303
    304304    my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $stage, $id, $tess_id, $component,
    305         0, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     305        0, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     306        undef, $release_name, $survey,
     307        $verbose);
    306308
    307309    return $results;
     
    328330    my $mjd_min = shift;
    329331    my $mjd_max = shift;
     332    my $selectedAstrom = shift;
     333    my $release_name = shift;
     334    my $survey = shift;
    330335    my $verbose  = shift;
    331336
     
    352357    my $magic_arg = $need_magic ? " -destreaked" : "";
    353358
     359    my $row = $rowList->[0];
     360
    354361    # all rows have the same center type
    355     my $skycenter = ! ($rowList->[0]->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
     362    my $skycenter = ! ($row->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
     363
     364    my $use_releasetool = 0;
     365    my $release_args;
     366    if (($req_type eq 'byexp' and $stage ne 'raw') or ($req_type eq 'byskycell' and $stage ne 'diff')) {
     367        unless (isnull($release_name) and isnull($survey)) {
     368            $use_releasetool = 1;
     369            $release_args = " -release_name $release_name" if $release_name;
     370            $release_args .= " -surveyName $survey" if $survey;
     371        }
     372    }
    356373
    357374    my $component_args;
     
    384401        # use chiptool -processsedimfile. Otherwise use chiptool -listrun and then
    385402        # choose the chips containing the center pixel by calling selectComponets() below
    386         if ($component or $use_imfile_id or !$skycenter) {
    387             $command = "$chiptool -processedimfile -pstamp_order -dbname $imagedb";
    388             if ($component and $component ne 'all') {
    389                 $class_id = $component;
    390                 $component_args = " -class_id $class_id";
    391             }
    392         } else {
    393             $command = "$chiptool -listrun -pstamp_order -dbname $imagedb";
     403        if ($use_releasetool) {
     404            $command = "$releasetool -dbname $imagedb -priority_order -listrelexp $release_args";
    394405            $choose_components = 1;
    395         }
    396         $id_opt = $use_imfile_id ? "-chip_imfile_id" : "-chip_id";
     406        } else {
     407            $command = "$chiptool -pstamp_order -dbname $imagedb";
     408            if ($component or $use_imfile_id or !$skycenter) {
     409                $command .= " -processedimfile";
     410                if ($component and $component ne 'all') {
     411                    $class_id = $component;
     412                    $component_args = " -class_id $class_id";
     413                }
     414            } else {
     415                $command .= " -listrun";
     416                $choose_components = 1;
     417            }
     418            $id_opt = $use_imfile_id ? "-chip_imfile_id" : "-chip_id";
     419        }
    397420        # XXX: perhaps we should stop resolving images to this level here and do it at job run time.
    398421        # With the mdc file it has all of the information that it needs.
     
    408431        $want_astrom  = 1;
    409432        $set_class_id = 1;
    410     } elsif ($stage eq "warp") {
    411         if ($component or $use_imfile_id or !$skycenter) {
    412             $command = "$warptool -warped -pstamp_order -dbname $imagedb";
    413             if ($component and $component ne 'all') {
    414                 $skycell_id = $component;
    415                 $component_args = " -skycell_id $skycell_id";
    416             }
    417         } else {
    418             $command = "$warptool -listrun -pstamp_order -dbname $imagedb";
     433    } elsif ($stage eq 'warp') {
     434        if ($use_releasetool) {
     435            $command = "$releasetool -dbname $imagedb -priority_order -listrelexp $release_args";
    419436            $choose_components = 1;
    420         }
    421         $id_opt = $use_imfile_id ? "-warp_skyfile_id" : "-warp_id";
     437        } else {
     438            $command = "$warptool -pstamp_order -dbname $imagedb";
     439            if ($component or $use_imfile_id or !$skycenter) {
     440                $command .= " -warped";
     441                if ($component and $component ne 'all') {
     442                    $skycell_id = $component;
     443                    $component_args = " -skycell_id $skycell_id";
     444                }
     445            } else {
     446                $command = " -listrun";
     447                $choose_components = 1;
     448            }
     449            $id_opt = $use_imfile_id ? "-warp_skyfile_id" : "-warp_id";
     450        }
    422451        $image_name   = "PSWARP.OUTPUT";
    423452        $mask_name    = "PSWARP.OUTPUT.MASK";
     
    427456        $base_name    = "path_base"; # name of the field for the warptool output
    428457    } elsif ($stage eq "diff") {
     458        # XXX: is this path ever used for diff images anymore?
    429459        if ($component or $use_imfile_id or !$skycenter) {
    430460            $command = "$difftool -diffskyfile -pstamp_order -dbname $imagedb";
     
    447477    } elsif ($stage eq "stack") {
    448478        $skycell_id = $component;
    449         $command = "$stacktool -sumskyfile -dbname $imagedb";
    450         # only consider stacks in full state.
    451         $command .= " -state full";
    452         $id_opt = "-stack_id";
     479        if ($use_releasetool) {
     480            $command = "$releasetool -listrelstack -dbname $imagedb $release_args";
     481            $base_name = 'stack_path_base';
     482        } else {
     483            $command = "$stacktool -sumskyfile -dbname $imagedb";
     484            # only consider stacks in full state.
     485            $command .= " -state full";
     486            $id_opt = "-stack_id";
     487            $base_name = 'path_base';
     488        }
    453489        $component_args = " -skycell_id $skycell_id" if $skycell_id and $skycell_id ne  'all';
    454490
     
    464500        # this is wrong but gets the right answer. Need to figure out how to find the
    465501        # rule properly
    466         #$cmf_name    = "PSPHOT.OUTPUT";    # this puts .fpa. in the name
    467502        $cmf_name     = "PSWARP.OUTPUT.SOURCES";
     503        # $cmf_name    = "PSPHOT.OUTPUT";    # this puts .fpa. in the name
    468504        $psf_name    = "PPSTACK.TARGET.PSF";
    469         $base_name   = "path_base";
    470505    } else {
    471         die "Unknown IMG_TYPe supplied: $stage";
     506        die "Unknown IMG_TYPE supplied: $stage";
    472507    }
    473508
     
    512547    if (!isnull($data_group)) {
    513548        $command .= " -data_group $data_group";
    514     } elsif ($req_type eq 'byskycell') {
     549    } elsif (!$use_releasetool and $req_type eq 'byskycell') {
     550        # XXX: Why am I using default data_groups only for byskycell requests?
    515551        $command .= $default_data_groups;
    516552    }
     
    527563        $images = filterRuns($stage, $need_magic, $images, $inverse, $verbose);
    528564    }
     565
    529566    if ($choose_components) {
    530567        # the list of "images" is actually a list of "Runs"
    531568        # match the coords in the rows to the components in the runs
    532569        # returns an actual list of images
    533         $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose);
     570        if ($skycenter) {
     571            $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose);
     572        } else {
     573            $images = selectComponentsByName($ipprc, $imagedb, $req_type, $stage, $component, $rowList, $images, $verbose);
     574        }
    534575    } else {
    535         # put index for each of the rows into all of the the images
     576        # put index for each of the rows into all of the the selected images
    536577        setRowRefs($rowList, $images);
    537578    }
     
    597638            # dquery wants these set
    598639            $out->{magicked} = 0;
    599             $out->{data_state} = $out->{state};
     640            if ($use_releasetool) {
     641                if ($image->{skycal_path_base}) {
     642                    $out->{astrom} = $image->{skycal_path_base} . ".cmf";
     643                }
     644                $out->{data_state} = $out->{state} = $out->{stack_state};
     645            } else {
     646                $out->{data_state} = $out->{state};
     647            }
    600648        }
    601649        $out->{stage_id} = $stage_id;
     
    605653        my $mask_base;
    606654        if ($want_astrom) {
    607             if (! defined $out->{astrom}) {
     655            if ($selectedAstrom) {
     656                $out->{astrom} = $selectedAstrom;
     657                $out->{cam_path_base} = basename($selectedAstrom);
     658            } elsif (! defined $out->{astrom}) {
    608659                if (! find_astrometry($ipprc, $imagedb, $out, $verbose)) {
    609660                    print STDERR "failed to find astrometry for $stage $stage_id\n";
     
    806857    my $mjd_min = shift;
    807858    my $mjd_max = shift;
     859    my $astrom = shift;
    808860    my $verbose    = shift;
    809861
    810     my ($release_name, $survey) = get_release($row);
     862    my ($release_name, $survey) = get_release_info($row);
    811863
    812864    my $rowList = [$row];
     
    825877                my $these_results = lookup($ipprc, $rowList, $imagedb, "byid", $stage, $chip->{id},
    826878                    $tess_id, $chip->{component}, $need_magic,
    827                     $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     879                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     880                    $chip->{astrom}, undef, undef,
     881                    $verbose);
    828882
    829883                next if !$these_results;
     
    845899                my $these_results = lookup($ipprc, $rowList, $imagedb, "byskycell", $stage, undef,
    846900                    $skycell->{tess_id}, $skycell->{component}, $need_magic,
    847                     $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     901                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     902                    undef, $release_name, $survey,
     903                    $verbose);
    848904
    849905                next if !$these_results;
     
    882938    my $using_camtool = 0;
    883939    if ($release_name or $survey) {
    884         my $command = "$releasetool -dbname $imagedb -listrelexp";
    885         if ($survey) {
     940        $command = "$releasetool -dbname $imagedb -listrelexp";
     941        if (!isnull($survey)) {
    886942            $command .= " -survey_name $survey";
    887943        }
    888         if ($release_name) {
     944        if (!isnull($release_name)) {
    889945            $command .= " -release_name $release_name";
    890946        } else {
     
    935991        if ($using_camtool) {
    936992            next if $result->{fault};
    937             updateCamRunCache($result);
    938         }
     993        } else {
     994            $result->{path_base} = $result->{cam_path_base};
     995        }
     996        updateCamRunCache($result);
    939997
    940998        $last_exp_id = $exp_id;
     
    10081066            cam_id    => $result->{cam_id},
    10091067            class_id  => $class_id,
    1010             component => $class_id
     1068            component => $class_id,
     1069            astrom    => $astrom
    10111070        };
    10121071        if ($stage eq "chip") {
     
    14441503}
    14451504
     1505sub selectComponentsByName {
     1506    my $ipprc = shift;
     1507    my $imagedb = shift;
     1508    my $req_type = shift;
     1509    my $stage  = shift;
     1510    my $component  = shift;
     1511    my $rowList = shift;
     1512    my $runList = shift;
     1513    my $verbose = shift;
     1514    my $results = [];
     1515
     1516    $component = "" if $component and lc($component) eq 'all';
     1517
     1518    # all runs match all rows so they can share a common row_index
     1519    # XXX: I'm not sure we ever actually get here with more than one
     1520    # row
     1521    my $numRows = scalar @$rowList;
     1522    my $row_index = [];
     1523    for (my $i=0; $i < $numRows; $i++) {
     1524        push @$row_index, $i;
     1525    }
     1526   
     1527    if (($req_type eq "byid") or ($req_type eq "byexp")) {
     1528        my ($last_tess_id, $tess_dir_abs, $astrom_file) = ("", "", "");
     1529        foreach my $run (@$runList) {
     1530            # now find the images for this run
     1531            #foreach my $c (keys %components) {
     1532            my $command;
     1533            my $stage_id;
     1534            if ($stage eq 'raw') {
     1535                $stage_id = $run->{exp_id};
     1536                $command = "$regtool -processedimfile -exp_id $stage_id";
     1537                $command .= " -class_id $component" if $component;
     1538            } elsif ($stage eq 'chip') {
     1539                $stage_id = $run->{chip_id};
     1540                $command = "$chiptool -processedimfile -chip_id $stage_id";
     1541                $command .= " -class_id $component" if $component;
     1542            } elsif ($stage eq 'warp') {
     1543                $stage_id = $run->{warp_id};
     1544                $command = "$warptool -warped -warp_id $stage_id";
     1545                $command .= " -skycell_id $component" if $component;
     1546            }
     1547            $command .= " -dbname $imagedb";
     1548            my $images = runToolAndParse($command, $verbose);
     1549            if (!defined $images) {
     1550                print "No  $component found for $stage ${stage}_id $stage_id\n";
     1551                next;
     1552            }
     1553            foreach my $image (@$images) {
     1554                $image->{row_index} = $row_index;
     1555                if (($stage eq "raw") or ($stage eq 'chip')) {
     1556                    $image->{cam_id} = $run->{cam_id};
     1557                    $image->{cam_path_base} = $run->{cam_path_base};
     1558                }
     1559                push @$results, $image;
     1560            }
     1561        }
     1562    } else {
     1563        &my_die ("selectComponentsByName not supported for REQ_TYPE: $req_type\n", $PS_EXIT_PROG_ERROR);
     1564    }
     1565    return $results;
     1566}
     1567
    14461568sub filterRuns {
    14471569    my $stage      = shift;
     
    16271749}
    16281750
    1629 sub get_release {
     1751sub get_release_info {
    16301752    my $row = shift;
    16311753
    16321754    my $survey;
    16331755    my $release_name = $row->{IPP_RELEASE};
    1634     if (!isnull($release_name)) {
     1756    if (isnull($release_name)) {
     1757        $release_name = "";
    16351758        # no release check for survey
    16361759        $survey = $row->{SURVEY_NAME};
     1760    } else {
     1761        $survey = "";
    16371762    }
    16381763
Note: See TracChangeset for help on using the changeset viewer.