IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39830


Ignore:
Timestamp:
Nov 29, 2016, 12:34:26 PM (10 years ago)
Author:
watersc1
Message:

Merge from trunk/branch of updated nightly_science code with improved diff queue handling.

Location:
tags/ipp-20141024
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-20141024/ippScripts/scripts/nightly_science.pl

    r38249 r39830  
    4747# Grab options
    4848my ( $date, $datetime, $camera, $dbname, $logfile, $verbose, $manual);
    49 my ( $help, $isburning, $force_stack_count, $force_diff_count, $test_mode, $this_target_only, $this_filter_only, $this_mode_only, $check_mode);
     49my ( $help, $isburning, $force_stack_count, $force_diff_count, $force_registration, $test_mode, $this_target_only, $this_filter_only, $this_mode_only, $check_mode);
    5050my ( $registration_status, $burntool_status, $observing_status, $old_date);
    5151my ( $check_registration, $define_burntool, $queue_burntool, $check_chips, $queue_chips);
     
    6565    'force_stack_count'    => \$force_stack_count,
    6666    'force_diff_count'     => \$force_diff_count,
     67    'force_registration'   => \$force_registration,
    6768    'this_target_only=s'   => \$this_target_only,
    6869    'this_filter_only=s'   => \$this_filter_only,
     
    285286$metadata_out{nsObservingState} = &get_observing_state($date);
    286287$metadata_out{nsRegistrationState} = &get_registration_state($date);
     288if ($force_registration) {
     289    $metadata_out{nsRegistrationState} = 'REGISTERED';
     290}
    287291#
    288292# Mode selection
     
    14351439    if ($metadata_out{nsDiffState} eq 'FINISHED_DIFFS') {
    14361440        foreach my $target (sort (keys %science_config)) {
    1437             if ($science_config{$target}{DIFFABLE} == 1) {
     1441            # CZW: We should only arrive at this point once, so we can construct a diff report and mail it now.
     1442            if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) {
    14381443                foreach my $filter (@filter_list) {
    1439                     multi_date_diff_queue($date,$target,$filter,$pretend);
    1440                 }
    1441             }
    1442             if ((defined($science_config{$target}{OFFNIGHT_DIFFS})) && ($science_config{$target}{OFFNIGHT_DIFFS} == 1)) {
    1443                 foreach my $filter (@filter_list) {
    1444                     offnight_diff_queue($date,$target,$filter,$pretend);
    1445                 }
    1446             }
     1444                    # This one needs to return a state to see if we need to wait on stacking before checking again.
     1445                    $metadata_out{nsDiffState} = desperate_diff_queue($date,$target,$filter,$pretend);
     1446                }
     1447            }
     1448
    14471449            if ((defined($science_config{$target}{SELF_WSDIFFS})) && ($science_config{$target}{SELF_WSDIFFS} == 1)) {
    14481450                foreach my $filter (@filter_list) {
     
    14981500            my $this_comment = ${ $this_warp }[3];
    14991501            my $this_exp_id  = ${ $this_warp }[0];
    1500             $comment_hash{$this_comment} = $this_exp_id;
    1501         }
    1502        
     1502            my $this_quality = ${ $this_warp }[5];
     1503            if ($this_quality != 0) {
     1504                print STDERR "diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality\n";
     1505            }
     1506            else {
     1507                $comment_hash{$this_comment} = $this_exp_id;
     1508            }
     1509        }
     1510        # Exclude any warps that are not stored in the comment_hash.
     1511        my @keep_warps = ();
     1512        foreach my $this_warp (@{ $warps }) {
     1513            my $this_comment = ${ $this_warp }[3];
     1514            my $this_exp_id  = ${ $this_warp }[0];
     1515            if ((exists($comment_hash{$this_comment}))&&
     1516                ($comment_hash{$this_comment} == $this_exp_id)) {
     1517                push @keep_warps, $this_warp;
     1518            }
     1519            else {
     1520                print STDERR "diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n";
     1521            }
     1522        }
     1523        @{ $warps } = @keep_warps;
     1524
     1525        # Exclude the last entry if we do not have an even number of warps.
    15031526        if (($#{ $warps } + 1) % 2 != 0) {
    15041527            print STDERR "diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
     
    15081531            }
    15091532            else {
    1510                 print STDERR ": I should declare an exposure to be qualityy.\n";
    1511                 my @keep_warps = ();
    1512 #               print "@{ $warps }\n";
    1513                 foreach my $this_warp (@{ $warps }) {
    1514                     my $this_comment = ${ $this_warp }[3];
    1515                     my $this_exp_id  = ${ $this_warp }[0];
    1516                     if ($comment_hash{$this_comment} == $this_exp_id) {
    1517                         push @keep_warps, $this_warp;
    1518                     }
    1519                     else {
    1520                         print STDERR "diff_queue: excluding $this_exp_id for $this_object\n";
    1521                     }
    1522                 }
    1523                 @{ $warps } = @keep_warps;
    1524 #               print "@{ $warps }\n";
     1533                my $rejected_warp = pop @{ $warps };
     1534                my $rejected_exp_id = ${ $rejected_warp }[0];
     1535                print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
    15251536            }
    15261537        }
    15271538       
    15281539        while ($#{ $warps } > -1) {
     1540            # The array is sorted in pairs of input/template.
    15291541            my $input_warp = shift @{ $warps };
     1542            my $template_warp = shift @{ $warps };
     1543
    15301544            my $input_exp_id = ${ $input_warp }[0];
    15311545            my $input_comment = ${ $input_warp }[3];
    15321546
    1533            
    1534             my $template_warp = shift @{ $warps };
    1535 
    15361547            my $template_exp_id = ${ $template_warp }[0];
    1537            
     1548            my $template_comment = ${ $template_warp }[3];
     1549
    15381550            my $input_warp_id = ${ $input_warp }[1];
    15391551            my $template_warp_id = ${ $template_warp }[1];
     
    15511563                print STDERR "Diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
    15521564                if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
     1565                    # This should now never be reached.
     1566                    # CZW: Trigger backup plan here?  Or simply set up framework?
    15531567                    print STDERR "  ...but this is due to a camera stage astrometry quality\n";
    15541568                    $Npotential--;
     
    15591573            if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
    15601574                $Nqueued++;
    1561                 print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
     1575                print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    15621576                next;
     1577            }
     1578            else {
     1579                print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    15631580            }
    15641581           
     
    16011618}
    16021619
     1620
     1621sub desperate_diff_queue {
     1622    my $date = shift;
     1623    my $target = shift;
     1624    my $filter = shift;
     1625    my $pretend = shift;
     1626    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     1627
     1628    my $db = init_gpc_db();
     1629
     1630    my $obj_sth = "select DISTINCT rawExp.object from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
     1631    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' ORDER BY rawExp.object";
     1632
     1633    my $object_ref = $db->selectall_arrayref( $obj_sth );
     1634
     1635    my $Npotential = 0;
     1636    my $Nqueued = 0;
     1637   
     1638    foreach my $object_row (@{ $object_ref }) {
     1639        my $this_object = shift @{ $object_row };
     1640       
     1641        my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM ";
     1642        $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
     1643        $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1644        $input_sth .=   " ORDER BY dateobs ";
     1645
     1646        my $warps = $db->selectall_arrayref( $input_sth );
     1647
     1648        # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
     1649        my %comment_hash = ();
     1650        foreach my $this_warp (@{ $warps }) {
     1651            my $this_comment = ${ $this_warp }[3];
     1652            my $this_exp_id  = ${ $this_warp }[0];
     1653            my $this_quality = ${ $this_warp }[5];
     1654            if ($this_quality != 0) {
     1655                print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality\n";
     1656            }
     1657            else {
     1658                $comment_hash{$this_comment} = $this_exp_id;
     1659            }
     1660        }
     1661        # Exclude any warps that are not stored in the comment_hash.
     1662        my @keep_warps = ();
     1663        foreach my $this_warp (@{ $warps }) {
     1664            my $this_comment = ${ $this_warp }[3];
     1665            my $this_exp_id  = ${ $this_warp }[0];
     1666            if ((exists($comment_hash{$this_comment}))&&
     1667                ($comment_hash{$this_comment} == $this_exp_id)) {
     1668                push @keep_warps, $this_warp;
     1669            }
     1670            else {
     1671                print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n";
     1672            }
     1673        }
     1674        # We are attempting to do the missing diffs, so reverse the list of retained warps.
     1675        # Good objects with all visits will be skipped due to the duplicate check.
     1676        # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs.
     1677        @{ $warps } = reverse @keep_warps;
     1678                   
     1679        # Exclude the last entry if we do not have an even number of warps.
     1680        if (($#{ $warps } + 1) % 2 != 0) {
     1681            print STDERR "desp_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
     1682            if ($#{ $warps} + 1 == 1) {
     1683                print STDERR ": I can do no diffs with only one exposure.\n";
     1684                next;
     1685            }
     1686            else {
     1687                my $rejected_warp = pop @{ $warps };
     1688                my $rejected_exp_id = ${ $rejected_warp }[0];
     1689                print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
     1690            }
     1691        }
     1692       
     1693        while ($#{ $warps } > -1) {
     1694            # In this mode, the array is sorted in pairs of template/input, counter to the standard queue.
     1695            my $template_warp = shift @{ $warps };
     1696            my $input_warp = shift @{ $warps };
     1697
     1698            my $input_exp_id = ${ $input_warp }[0];
     1699            my $input_comment = ${ $input_warp }[3];
     1700
     1701            my $template_exp_id = ${ $template_warp }[0];
     1702            my $template_comment = ${ $template_warp }[3];
     1703
     1704            my $input_warp_id = ${ $input_warp }[1];
     1705            my $template_warp_id = ${ $template_warp }[1];
     1706
     1707            my $input_warp_state = ${ $input_warp }[4];
     1708            my $template_warp_state = ${ $template_warp }[4];
     1709
     1710            my $input_warp_camQuality = ${ $input_warp }[5];
     1711            my $template_warp_camQuality = ${ $template_warp }[5];
     1712
     1713            $Npotential++;
     1714
     1715            unless (defined($input_warp_id) && defined($template_warp_id) &&
     1716                    ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     1717                print STDERR "Diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
     1718                if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
     1719                    # This should now never be reached.
     1720                    # CZW: Trigger backup plan here?  Or simply set up framework?
     1721                    print STDERR "  ...but this is due to a camera stage astrometry quality\n";
     1722                    $Npotential--;
     1723                }
     1724                next;
     1725            }
     1726
     1727            if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     1728                $Nqueued++;
     1729                print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     1730                next;
     1731            }
     1732            else {
     1733                print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     1734            }
     1735           
     1736            my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
     1737            $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
     1738            $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     1739            $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures
     1740            $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
     1741            $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     1742#               $cmd .= " -pretend ";
     1743            if (defined($reduction)) {
     1744                $cmd .= " -set_reduction $reduction ";
     1745            }
     1746
     1747            if (defined($pretend)) {
     1748                $cmd .= ' -pretend ';
     1749            }
     1750            if ($debug == 1) {
     1751                $cmd .= ' -pretend ';
     1752                print STDERR "desp_diff_queue: $cmd\n";
     1753                print STDERR " $input_warp_id $template_warp_id\n";
     1754            }
     1755           
     1756            if (($debug == 0)&&(!defined($pretend))) {
     1757                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1758                    run ( command => $cmd, verbose => $verbose );
     1759                unless ($success) {
     1760                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1761                    &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     1762                }
     1763                $Nqueued++;
     1764            }
     1765        }
     1766    }
     1767    $metadata_out{nsDiffPotential} += $Npotential;
     1768    $metadata_out{nsDiffQueued}    += $Nqueued;
     1769#      if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) {
     1770#       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1771#      }       
     1772
     1773}
     1774
     1775
    16031776sub multi_date_diff_queue {
    16041777    my $date = shift;
     
    16261799        my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state FROM ";
    16271800        $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
    1628         $input_sth .=   " WHERE warpRun.label = '$label' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1801        $input_sth .=   " WHERE warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
    16291802        $input_sth .=   " ORDER BY dateobs ";
    16301803
  • tags/ipp-20141024/ippconfig/recipes/nightly_science.config

    r38024 r39830  
    88  MODE           STR WARP
    99  COMMAND        STR warptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -label @LABEL@ -data_group @DATA_GROUP@
    10 #  COMMAND        STR true
    11   RETENTION_TIME U16 2
     10  RETENTION_TIME U16 3
    1211END
    1312CLEAN_MODES METADATA
     
    6968
    7069TARGETS MULTI
     70# TARGETS METADATA
     71#   NAME         STR  LIGO
     72#   DISTRIBUTION STR  LIGO
     73#   TESS         STR  RINGS.V3
     74#   OBSMODE      STR  LIGO
     75#   STACKABLE      BOOL FALSE
     76#   DIFFABLE       BOOL FALSE
     77#   OFFNIGHT_DIFFS BOOL FALSE
     78#   DIST           S16  15
     79#   CHIP           S16  5
     80#   WARP           S16  5
     81#   DIFF           S16  5 
     82# END
    7183TARGETS METADATA
    7284  NAME      STR  M31
     
    8799END
    88100TARGETS METADATA
     101  NAME      STR CFA
     102  DISTRIBUTION STR CFA
     103  TESS      STR MD07.V3
     104  OBSMODE   STR CFA
     105#  OBJECT    STR MD07%
     106  STACKABLE BOOL TRUE
     107  MIN_STACK U16 8
     108  DIFFABLE  BOOL FALSE
     109  OFFNIGHT_DIFFS BOOL FALSE
     110  REDUCTION STR MD_DEFAULT
     111#  DIST S16 30 
     112END
     113TARGETS METADATA
    89114  NAME         STR SNIa
    90115  DISTRIBUTION STR SNIa.test
     
    94119  DIFFABLE    BOOL FALSE
    95120  OFFNIGHT_DIFFS BOOL FALSE
     121#  REDUCTION STR SNIA_DEFAULT
    96122  ## change days till cleanup
    97   DIST      S16 300
    98 #  CHIP           S16  7
    99   WARP      S16 300
    100   DIFF      S16 300
     123  DIST      S16 20
     124  CHIP      S16  2
     125  WARP      S16  2
     126  DIFF      S16  2
     127END
     128TARGETS METADATA
     129  NAME         STR  QUB
     130  DISTRIBUTION STR  NODIST
     131  TESS         STR  RINGS.V3
     132  OBSMODE      STR  QUB
     133  STACKABLE      BOOL FALSE
     134  DIFFABLE       BOOL FALSE
     135  OFFNIGHT_DIFFS BOOL FALSE
     136  REDUCTION STR QUB_DEFAULT
     137  DIST           S16  15
     138  CHIP           S16  5
     139  WARP           S16  300
     140  DIFF           S16  300
    101141END
    102142TARGETS METADATA
     
    280320  STACKABLE   BOOL FALSE
    281321  DIFFABLE    BOOL TRUE
     322  OFFNIGHT_DIFFS BOOL FALSE
     323  REDUCTION STR SWEETSPOT
     324  ADDITIONAL_STACK_LABEL STR ecliptic.rp
     325  DESPERATE_DIFFS BOOL TRUE
     326#  REDUCTION STR SSTF_4SIG
     327END
     328TARGETS METADATA
     329  NAME         STR ESS
     330  DISTRIBUTION STR SweetSpot
     331  TESS         STR RINGS.V3
     332  OBSMODE      STR ESS
     333  STACKABLE   BOOL FALSE
     334  DIFFABLE    BOOL TRUE
     335  OFFNIGHT_DIFFS BOOL FALSE
    282336  REDUCTION STR SWEETSPOT
    283337  ADDITIONAL_STACK_LABEL STR ecliptic.rp
     
    285339END
    286340TARGETS METADATA
    287   NAME         STR ESS
     341  NAME         STR MSS
    288342  DISTRIBUTION STR SweetSpot
    289343  TESS         STR RINGS.V3
    290   OBSMODE      STR ESS
     344  OBSMODE      STR MSS
    291345  STACKABLE   BOOL FALSE
    292346  DIFFABLE    BOOL TRUE
     347  OFFNIGHT_DIFFS BOOL FALSE
    293348  REDUCTION STR SWEETSPOT
    294349  ADDITIONAL_STACK_LABEL STR ecliptic.rp
     
    296351END
    297352TARGETS METADATA
    298   NAME         STR MSS
     353  NAME         STR FSS
    299354  DISTRIBUTION STR SweetSpot
    300355  TESS         STR RINGS.V3
    301   OBSMODE      STR MSS
    302   STACKABLE   BOOL FALSE
    303   DIFFABLE    BOOL TRUE
     356  OBSMODE      STR FSS
     357  STACKABLE   BOOL FALSE
     358  DIFFABLE    BOOL FALSE
     359  OFFNIGHT_DIFFS BOOL FALSE
    304360  REDUCTION STR SWEETSPOT
    305   ADDITIONAL_STACK_LABEL STR ecliptic.rp
    306 #  REDUCTION STR SSTF_4SIG
     361  CHIP      S16 5
     362  WARP      S16 300
     363  DIFF      S16 300
     364END
     365TARGETS  METADATA
     366  NAME          STR NCU
     367  DISTRIBUTION  STR SweetSpot
     368  TESS          STR RINGS.V3
     369  OBSMODE       STR NCU
     370  STACKABLE     BOOL FALSE
     371  DIFFABLE      BOOL FALSE
     372  OFFNIGHT_DIFFS BOOL FALSE
     373  REDUCTION     STR SWEETSPOT
     374  DIST          S16 300
     375  CHIP          S16 300
     376  WARP          S16 300
     377  DIFF          S16 300
    307378END
    308379TARGETS METADATA
     
    332403  STACKABLE   BOOL FALSE
    333404  DIFFABLE    BOOL TRUE
    334   OFFNIGHT_DIFFS BOOL TRUE
    335   CHIP           S16  7
    336   DIFF           S16  7
     405  OFFNIGHT_DIFFS BOOL FALSE
     406  DESPERATE_DIFFS BOOL TRUE
     407#  CHIP          S16  7
     408#  DIFF          S16  7
    337409#  CHIP         S16 10
    338410#  DIFF         S16 12
Note: See TracChangeset for help on using the changeset viewer.