IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 19, 2010, 6:52:05 PM (16 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/ippScripts/scripts/automate_stacks.pl

    r28794 r28981  
    2525my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    2626my $mkBTpcontrol = can_run('make_burntool_pcontrol.pl') or (warn "Can't find make_burntool_pcontrol.pl" and $missing_tools = 1);
     27my $moondata = can_run('moondata') or (warn "Can't find moondata" and $missing_tools = 1);
    2728
    2829if ($missing_tools) {
     
    4142# Grab options
    4243my ( $date, $camera, $dbname, $logfile, $verbose, $manual);
    43 my ( $help, $isburning, $force_stack_count, $test_mode, $this_target_only, $this_filter_only, $this_mode_only, $check_mode);
     44my ( $help, $isburning, $force_stack_count, $test_mode, $this_target_only, $this_filter_only, $this_mode_only, $check_mode, $burntool_stats);
    4445my ( $check_registration, $define_burntool, $queue_burntool, $check_chips, $queue_chips);
    45 my ( $check_stacks, $queue_stacks, $check_diffs, $queue_diffs, $clean_old);
     46my ( $check_stacks, $queue_stacks, $check_sweetspot, $queue_sweetspot, $check_diffs, $queue_diffs, $clean_old);
    4647my ( $check_detrends, $queue_detrends, $check_dqstats, $queue_dqstats);
    4748
     
    5859    'check'                => \$check_mode,
    5960    'test_mode'            => \$test_mode,
     61    'burntool_stats'       => \$burntool_stats,
    6062    'this_target_only=s'   => \$this_target_only,
    6163    'this_filter_only=s'   => \$this_filter_only,
     
    6870    'check_stacks'         => \$check_stacks,
    6971    'queue_stacks'         => \$queue_stacks,
     72    'check_sweetspot'      => \$check_sweetspot,
     73    'queue_sweetspot'      => \$queue_sweetspot,
    7074    'check_detrends'       => \$check_detrends,
    7175    'queue_detrends'       => \$queue_detrends,
     
    8993           --this_filter_only     Process only a single filter.
    9094           --this_mode_only       Process only a single clean mode.
     95           --burntool_stats       Display Nexp Nimfile Nburntooled Nqueued for check_chips.
    9196        Modes:
    9297           --check_registration   Confirm the data downloaded correctly.
     
    97102           --check_stacks         Confirm that stacks can be built.
    98103           --queue_stacks         Issue stacktool commands to queue stacks.
     104           --check_sweetspot      See if we should queue SweetSpot stacks.
     105           --queue_sweetspot      Issue stacktool commands to queue SweetSpot stacks.
    99106           --check_detrends       Confirm that detrend verify runs can be built.
    100107           --queue_detrends       Issue dettool commands to queue detrend verify runs.
     
    111118          ) unless
    112119    defined $check_registration or defined $define_burntool or defined $queue_burntool or
    113     defined $queue_chips or defined $queue_stacks or $queue_detrends or $queue_dqstats or
    114     defined $check_chips or defined $check_stacks or $check_detrends or $check_dqstats or
     120    defined $queue_chips or defined $queue_stacks or $queue_sweetspot or $queue_detrends or $queue_dqstats or
     121    defined $check_chips or defined $check_stacks or $check_sweetspot or $check_detrends or $check_dqstats or
    115122    defined $test_mode or defined $clean_old or defined $check_mode;
    116123
     
    125132my %stackable_list = ();
    126133my %reduction_class = ();
     134my @unrecoverable_quality = ();
    127135my @detrend_list = ();
    128136my %dettype_list = ();
     
    170178    elsif (${ $entry }{name} eq 'FILTERS') {
    171179        push @filter_list, ${ $entry }{value};
     180    }
     181    elsif (${ $entry }{name} eq 'UNRECOVERABLE_QUALITY') {
     182        push @unrecoverable_quality, ${ $entry }{value};
    172183    }
    173184    elsif (${ $entry }{name} eq 'TARGETS') {
     
    304315    unless (defined($test_mode) || defined($check_mode)) { exit(0); }
    305316}
     317
    306318if (defined($check_dqstats) || defined($test_mode)) {
    307319    $metadata_out{nsState} = 'CHECKDQSTATS';
     
    316328    unless (defined($test_mode)) { exit(0); }
    317329}
     330
    318331if (defined($check_detrends) || defined($test_mode) || defined($check_mode)) {
    319332    $metadata_out{nsState} = 'CHECKDETRENDS';
     
    328341    exit(0);
    329342}
     343
    330344if (defined($define_burntool) || defined($test_mode)) {
    331345    $metadata_out{nsState} = 'QUEUEBURNING';
     
    339353    unless (defined($test_mode)) { exit(0); }
    340354}
     355
    341356if (defined($check_chips) || defined($test_mode) || defined($check_mode)) {
    342357    $metadata_out{nsState} = 'QUEUECHIPS';
     
    354369    exit(0);
    355370}
     371
    356372if (defined($check_stacks) || defined($test_mode) || defined($check_mode)) {
    357373    $metadata_out{nsState} = 'TOWARP';
     
    372388    exit(0);
    373389}
     390
     391if (defined($check_sweetspot) || defined($test_mode) || defined($check_mode)) {
     392    $metadata_out{nsState} = 'CHECKSWEETSPOT';
     393    &execute_sweetspot($date,"pretend");
     394    return_metadata($date);
     395    unless (defined($test_mode) || defined($check_mode)) { exit(0); }
     396}
     397if (defined($queue_sweetspot)) {
     398    $metadata_out{nsState} = 'CHECKSWEETSPOT';
     399    &execute_sweetspot($date);
     400    return_metadata($date);
     401    exit(0);
     402}
     403
    374404if (defined($check_diffs) || defined($queue_diffs)) {
    375405    die("Diffs are currently not implemented.");
    376406}
     407
    377408if (defined($clean_old) || defined($test_mode)) {
    378409    if (defined($test_mode)) {
     
    656687    my $pretend = shift;
    657688    my $exposures = 0;
     689
    658690    foreach my $target (@target_list) {
    659691        my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = pre_chip_queue($date,$target);
     692        if (defined($burntool_stats)) {
     693            print "$Nexposures $Nimfiles $Nburntooled $Nalready\n";
     694        }
     695
    660696        if ($Nexposures == 0) {
    661697            print STDERR "execute_chips: Target $target on $date had no exposures.\n";
     
    861897
    862898#
     899# SweetSpot Stacking
     900################################################################################
     901sub construct_sweetspot_cmd {
     902    my $date = shift;
     903    my $target = 'SweetSpot';
     904    my $filter = 'w.00000';
     905
     906    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     907
     908    # Dateobs begin end?
     909    my ($dateobs_begin,$dateobs_end) = get_lunation_extent($date);
     910    my $select = "-select_dateobs_begin ${dateobs_begin}T00:00:00 -select_dateobs_end ${dateobs_end}T00:00:00";
     911    my $cmd = "$stacktool";
     912    $cmd .= " -simple -dbname $dbname -definebyquery ";
     913    $cmd .= " -set_label SweetSpot.refstack -select_label $label ";
     914    $cmd .= " -set_workdir $workdir -set_dist_group $dist_group ";
     915    $cmd .= " -select_filter $filter -set_data_group $data_group ";
     916    $cmd .= " -select_good_frac_min 0.1 -select_fwhm_major_max 8.0 ";
     917    $cmd .= " -min_num 7 -min_new 4";
     918    $cmd .= " $select ";
     919    if ($debug == 1) {
     920        $cmd .= ' -pretend ';
     921    }
     922    print STDERR "$cmd\n";
     923    return($cmd);
     924}
     925
     926sub get_lunation_extent {
     927    my $date = shift;
     928    my ($year,$month,$day) = split /-/,$date;
     929    my $dateobs_begin;
     930    my $dateobs_end;
     931
     932    my $dt = DateTime->new(year => $year, month => $month, day => $day,
     933                           hour => 0, minute => 0, second => 0, nanosecond => 0,
     934                           time_zone => 'Pacific/Honolulu');
     935    do {
     936        $dt->subtract(days => 1);
     937        my $ymd = $dt->ymd;
     938        my $md_cmd = "moondata $ymd 0 0";
     939        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     940            run ( command => $md_cmd, verbose => $verbose);
     941        unless ($success) {
     942            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     943            &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
     944        }
     945        my @result = split /\s+/,(join "\n", @$stdout_buf);
     946        if (abs($result[6]) <= 0.5) {
     947            $dateobs_end = $ymd;
     948        }
     949    } while (!defined($dateobs_end));
     950   
     951    do {
     952        $dt->subtract(days => 1);
     953        my $ymd = $dt->ymd;
     954        my $md_cmd = "moondata $ymd 0 0";
     955        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     956            run ( command => $md_cmd, verbose => $verbose);
     957        unless ($success) {
     958            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     959            &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
     960        }
     961        my @result = split /\s+/,(join "", @$stdout_buf);
     962        if (abs($result[6]) <= 0.5) {
     963            $dateobs_begin = $ymd;
     964        }
     965    } while (!defined($dateobs_begin));
     966       
     967    return($dateobs_begin,$dateobs_end);
     968}
     969
     970sub pre_sweetspot_queue {
     971    my $date = shift;
     972    my $command = construct_sweetspot_cmd($date) . ' -pretend ';
     973    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     974        run ( command => $command, verbose => $verbose );
     975    unless ($success) {
     976        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     977        &my_die("Unable to perform sweetspot stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     978    }
     979    my @stacks = split /\n/, (join '', @$stdout_buf);
     980    my $Nstacks = $#stacks + 1;
     981       
     982    return(1,$Nstacks);
     983}
     984
     985sub sweetspot_queue {
     986    my $date = shift;
     987    my $command = construct_sweetspot_cmd($date);
     988    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     989        run ( command => $command, verbose => $verbose );
     990    unless ($success) {
     991        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     992        &my_die("Unable to perform sweetspot stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     993    }
     994    my @stacks = split /\n/, (join '', @$stdout_buf);
     995    my $Nstacks = $#stacks + 1;
     996   
     997    return(1,$Nstacks);
     998}
     999
     1000sub execute_sweetspot {   
     1001    my $date = shift;
     1002    my $pretend = shift;
     1003   
     1004    my ($is_lunation_date,$Nstacks) = pre_sweetspot_queue($date);
     1005    if ($Nstacks == 0) {
     1006        print STDERR "execute_sweetspot: No new stacks to make ($Nstacks)\n";
     1007        $metadata_out{nsState} = 'SS_EMPTY';
     1008        return();
     1009    }
     1010    if ($Nstacks < 10) {
     1011        print STDERR "execute_sweetspot: Too few new stacks to make ($Nstacks)\n";
     1012        $metadata_out{nsState} = 'SS_FEW';
     1013        return();
     1014    }
     1015    if ($is_lunation_date == 0) {
     1016        print STDERR "execute_sweetspot: Invalid lunation date. ($date $is_lunation_date)\n";
     1017        $metadata_out{nsState} = 'SS_ERROR';
     1018        return();
     1019    }
     1020    $metadata_out{nsState} = 'SS_QUEUE';
     1021    $metadata_out{nsSweetSpot} = $Nstacks;
     1022    unless(defined($pretend)) {
     1023        $metadata_out{nsState} = 'SS_DONE';
     1024        sweetspot_queue($date);
     1025    }
     1026}
     1027
     1028#
    8631029# Stacking
    8641030################################################################################
     
    9001066    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
    9011067
    902     my $sth = "SELECT skycell_id from stackRun where data_group = '$data_group' AND skycell_id = '$skycell' AND filter = '$filter'";
     1068    my $sth = "SELECT skycell_id from stackRun where data_group = '$data_group' AND skycell_id = '$skycell' AND filter = '$filter' AND tess_id = '$tess_id'";
    9031069    my $data_ref = $db->selectall_arrayref( $sth );
    9041070
     
    9181084
    9191085    my $where = " label = '$label' AND data_group = '$data_group' ";
     1086
     1087    my $where_possibly_faulted = $where . " AND ( " ;
     1088    foreach my $acceptable_quality (@unrecoverable_quality) {
     1089        $where_possibly_faulted .= " quality = $acceptable_quality OR ";
     1090    }
     1091    $where_possibly_faulted .= " 0 )";
     1092
    9201093    my $chip_sth = "SELECT * from chipRun WHERE (state = 'full' OR state = 'new') AND $where ";
     1094    my $cam_sth  = "SELECT * from camRun JOIN camProcessedExp USING(cam_id) WHERE state = 'full' AND $where_possibly_faulted ";
    9211095    my $warp_sth = "SELECT * from warpRun WHERE state = 'full' AND $where ";
    9221096
    9231097    my $chip_ref = $db->selectall_arrayref( $chip_sth );
     1098    my $cam_ref  = $db->selectall_arrayref( $cam_sth );
    9241099    my $warp_ref = $db->selectall_arrayref( $warp_sth );
    9251100
     
    9421117    }
    9431118
    944     return($#input_exposures  + 1, $#{ $chip_ref } + 1, $#{ $warp_ref } + 1, $Nalready);
     1119    return($#input_exposures  + 1, $#{ $chip_ref } + 1, $#{ $cam_ref } + $#{ $warp_ref } + 2, $Nalready);
    9451120}
    9461121
     
    10391214    my $args = $command;
    10401215    if ((exists($clean_alternate{$mode})) && ($clean_alternate{$mode} eq 'A')) {
    1041         $args .= " -dbname $dbname -updaterun -set_state goto_cleaned -full -set_label goto_cleaned -time_stamp_end $cleaning_date ";
     1216        $args .= " -dbname $dbname -updaterun -set_state goto_cleaned -full -set_label goto_cleaned -label $label -time_stamp_end $cleaning_date ";
    10421217    }
    10431218    elsif ((exists($clean_alternate{$mode})) && ($clean_alternate{$mode} eq 'B')) {
     
    10581233
    10591234    foreach my $mode (@mode_list) {
    1060         if ((exists($clean_alternate{$mode})) && ($clean_alternate{$mode} eq 'A')) {
    1061             my ($cleaning_date,$command) = construct_cleantool_args($date,"",$mode);
    1062             if ($cleaning_date eq 'no clean') {
    1063                 next;
    1064             }
    1065             print STDERR "$command\n";
    1066             if (!(defined($pretend) || $debug == 1)) {
    1067 #           print STDERR "BEAR IS DRIVING!?\n";
    1068                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    1069                     run ( command => $command, verbose => $verbose );
    1070                 unless ($success) {
    1071                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    1072                     &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    1073                 }
    1074             }
    1075         }
    1076         else {
     1235#       if ((exists($clean_alternate{$mode})) && ($clean_alternate{$mode} eq 'A')) {
     1236#           my ($cleaning_date,$command) = construct_cleantool_args($date,"",$mode);
     1237#           if ($cleaning_date eq 'no clean') {
     1238#               next;
     1239#           }
     1240#           print STDERR "$command\n";
     1241#           if (!(defined($pretend) || $debug == 1)) {
     1242# #           print STDERR "BEAR IS DRIVING!?\n";
     1243#               my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1244#                   run ( command => $command, verbose => $verbose );
     1245#               unless ($success) {
     1246#                   $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1247#                   &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     1248#               }
     1249#           }
     1250#       }
     1251#       else {
    10771252            foreach my $target (@target_list) {
    10781253                if (exists($noclean_list{$target})) {
     
    10941269                }
    10951270            }
    1096         }
     1271#       }
    10971272    }
    10981273    return(0);
Note: See TracChangeset for help on using the changeset viewer.