Changeset 42229
- Timestamp:
- Jun 30, 2022, 3:42:01 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
-
ippScripts/scripts/camera_exp.pl (modified) (1 diff)
-
ippScripts/scripts/nightly_science.pl (modified) (67 diffs)
-
ippTools/src/pztoolConfig.c (modified) (2 diffs)
-
ippconfig/recipes/psastro.config (modified) (1 diff)
-
ppViz/src/ppCoord/ppCoord.h (modified) (1 diff)
-
ppViz/src/ppCoord/ppCoordArguments.c (modified) (3 diffs)
-
ppViz/src/ppCoord/ppCoordData.c (modified) (2 diffs)
-
ppViz/src/ppCoord/ppCoordLoop.c (modified) (4 diffs)
-
pswarp/src/pswarpMapGrid.c (modified) (4 diffs)
-
pswarp/src/pswarpTransformReadout.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/camera_exp.pl
r42155 r42229 178 178 179 179 # Determine if FWHM is too large to bother continuing. 180 my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX. ALLOWED.FWHM');180 my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.PROCESS.FWHM'); 181 181 if ($maxFWHM) { 182 182 my $expFWHM; -
trunk/ippScripts/scripts/nightly_science.pl
r42155 r42229 142 142 my %unique_filter_hash = (); 143 143 144 #set up the camera config 145 my $ipprcam = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up camera", $PS_EXIT_CONFIG_ERROR ); # IPP camera configuration 146 144 147 # Grab the configuration data. 145 148 my $conf_cmd = "$ppConfigDump -camera $camera -dump-recipe NIGHTLY_SCIENCE -"; … … 155 158 foreach my $entry (@{ $metadata }) { 156 159 if (@{ $entry }{name} eq 'CLEAN_MODES') { 157 my @mode_data = @{ ${ $entry }{value} };158 my $this_mode = '';159 foreach my $mentry (@mode_data) {160 if (${ $mentry }{name} eq 'MODE') {161 $this_mode = ${ $mentry }{value};162 }163 elsif (${ $mentry }{name} eq 'COMMAND') {164 $clean_config{$this_mode}{COMMAND} = ${ $mentry }{value};165 }166 elsif (${ $mentry }{name} eq 'RETENTION_TIME') {167 $clean_config{$this_mode}{RETENTION_TIME} = ${ $mentry }{value};168 }169 }160 my @mode_data = @{ ${ $entry }{value} }; 161 my $this_mode = ''; 162 foreach my $mentry (@mode_data) { 163 if (${ $mentry }{name} eq 'MODE') { 164 $this_mode = ${ $mentry }{value}; 165 } 166 elsif (${ $mentry }{name} eq 'COMMAND') { 167 $clean_config{$this_mode}{COMMAND} = ${ $mentry }{value}; 168 } 169 elsif (${ $mentry }{name} eq 'RETENTION_TIME') { 170 $clean_config{$this_mode}{RETENTION_TIME} = ${ $mentry }{value}; 171 } 172 } 170 173 } 171 174 elsif (${ $entry }{name} eq 'FILTERS') { 172 $unique_filter_hash{ ${ $entry }{value} } = 1;175 $unique_filter_hash{ ${ $entry }{value} } = 1; 173 176 # push @filter_list, ${ $entry }{value}; 174 177 } … … 177 180 } 178 181 elsif (${ $entry }{name} eq 'MACRO_DEFINITIONS') { 179 my @macro_data = @{ ${ $entry }{value} };180 my $this_mode = '';181 foreach my $mentry (@macro_data) {182 if (${ $mentry }{name} eq 'PROC_MODE') {183 $this_mode = ${ $mentry }{value};184 }185 elsif (${ $mentry }{name} eq 'MACRO') {186 $macro_config{$this_mode} = ${ $mentry }{value};187 }188 }182 my @macro_data = @{ ${ $entry }{value} }; 183 my $this_mode = ''; 184 foreach my $mentry (@macro_data) { 185 if (${ $mentry }{name} eq 'PROC_MODE') { 186 $this_mode = ${ $mentry }{value}; 187 } 188 elsif (${ $mentry }{name} eq 'MACRO') { 189 $macro_config{$this_mode} = ${ $mentry }{value}; 190 } 191 } 189 192 } 190 193 elsif (${ $entry }{name} eq 'TARGETS') { … … 194 197 if (${ $tentry }{name} eq 'NAME') { 195 198 $this_target = ${ $tentry }{value}; 196 $science_config{$this_target}{DISTRIBUTION} = $this_target; # Set the default dist_group197 } 198 else {199 $science_config{$this_target}{ ${ $tentry }{name} } = ${ $tentry }{value};200 }199 $science_config{$this_target}{DISTRIBUTION} = $this_target; # Set the default dist_group 200 } 201 else { 202 $science_config{$this_target}{ ${ $tentry }{name} } = ${ $tentry }{value}; 203 } 201 204 } 202 205 } 203 206 elsif (${ $entry }{name} eq 'DETRENDS') { 204 my @detrend_data = @{ ${ $entry }{value} };205 my $this_detrend = '';206 foreach my $dentry (@detrend_data) {207 if (${ $dentry }{name} eq 'NAME') {208 $this_detrend = ${ $dentry }{value};209 }210 else {211 $detrend_config{$this_detrend}{ ${ $dentry }{name} } = ${ $dentry }{value};212 }213 }214 } 207 my @detrend_data = @{ ${ $entry }{value} }; 208 my $this_detrend = ''; 209 foreach my $dentry (@detrend_data) { 210 if (${ $dentry }{name} eq 'NAME') { 211 $this_detrend = ${ $dentry }{value}; 212 } 213 else { 214 $detrend_config{$this_detrend}{ ${ $dentry }{name} } = ${ $dentry }{value}; 215 } 216 } 217 } 215 218 elsif (${ $entry }{name} eq 'END_OF_NIGHT') { 216 my @eon_data = @{ ${ $entry }{value} };217 my $this_eon = '';218 foreach my $tentry (@eon_data) {219 if (${ $tentry }{name} eq 'NAME') {220 $this_eon = ${ $tentry }{value};221 }222 else {223 $eon_config{$this_eon}{ ${ $tentry }{name} } = ${ $tentry }{value};224 }225 }219 my @eon_data = @{ ${ $entry }{value} }; 220 my $this_eon = ''; 221 foreach my $tentry (@eon_data) { 222 if (${ $tentry }{name} eq 'NAME') { 223 $this_eon = ${ $tentry }{value}; 224 } 225 else { 226 $eon_config{$this_eon}{ ${ $tentry }{name} } = ${ $tentry }{value}; 227 } 228 } 226 229 } 227 230 } … … 231 234 my $time; 232 235 if ($date =~ / /) { 233 ($date,$time) = split / /, $date;236 ($date,$time) = split / /, $date; 234 237 } 235 238 elsif ($date =~ /T/) { 236 ($date,$time) = split /T/, $date;239 ($date,$time) = split /T/, $date; 237 240 } 238 241 my ($year,$month,$day) = split /-/, $date; 239 242 if (defined($time)) { 240 my ($hour,$min,$sec) = split /\:/, $time; #/;241 $datetime = DateTime->new( year => $year,242 month => $month,243 day => $day,244 hour => $hour,245 min => $min,246 second => $sec,247 time_zone => 'UTC');243 my ($hour,$min,$sec) = split /\:/, $time; #/; 244 $datetime = DateTime->new( year => $year, 245 month => $month, 246 day => $day, 247 hour => $hour, 248 min => $min, 249 second => $sec, 250 time_zone => 'UTC'); 248 251 } 249 252 else { 250 $datetime = DateTime->now(time_zone => 'UTC');251 $datetime->set_year($year);252 $datetime->set_day($day);253 $datetime->set_month($month);254 } 255 } 253 $datetime = DateTime->now(time_zone => 'UTC'); 254 $datetime->set_year($year); 255 $datetime->set_day($day); 256 $datetime->set_month($month); 257 } 258 } 256 259 else { 257 260 $datetime = DateTime->now(time_zone => 'UTC'); # time_zone => 'Pacific/Honolulu'); … … 263 266 foreach my $t (keys %science_config) { 264 267 if ($t ne $this_target_only) { 265 undef($science_config{$t});268 undef($science_config{$t}); 266 269 } 267 270 } … … 282 285 foreach my $t (keys %clean_config) { 283 286 if ($t ne $this_mode_only) { 284 undef($clean_config{$t});287 undef($clean_config{$t}); 285 288 } 286 289 } … … 295 298 296 299 if (defined($desdiffdt) == 0) { 297 $desdiffdt = 1.5;300 $desdiffdt = 1.5; 298 301 } 299 302 300 303 #Build in a safety for desdiffdt 301 304 if ((defined($desdiffdt) == 1) && ($desdiffdt <= 0.5)) { 302 $desdiffdt = 0.5;305 $desdiffdt = 0.5; 303 306 } 304 307 … … 312 315 my $v; 313 316 foreach $z (sort (keys %science_config)) { 314 foreach $v (keys %{ $science_config{$z} }) {315 print "SCIENCE: $z $v $science_config{$z}{$v}\n";316 }317 foreach $v (keys %{ $science_config{$z} }) { 318 print "SCIENCE: $z $v $science_config{$z}{$v}\n"; 319 } 317 320 } 318 321 foreach $z (sort (keys %detrend_config)) { 319 foreach $v (keys %{ $detrend_config{$z} }) {320 print "DETREND: $z $v $detrend_config{$z}{$v}\n";321 }322 foreach $v (keys %{ $detrend_config{$z} }) { 323 print "DETREND: $z $v $detrend_config{$z}{$v}\n"; 324 } 322 325 } 323 326 foreach $z (keys (%clean_config)) { 324 foreach $v (keys %{ $clean_config{$z} }) {325 print "CLEAN: $z $v $clean_config{$z}{$v}\n";326 }327 foreach $v (keys %{ $clean_config{$z} }) { 328 print "CLEAN: $z $v $clean_config{$z}{$v}\n"; 329 } 327 330 } 328 331 foreach $z (@filter_list) { 329 print "FILTER: $z\n";332 print "FILTER: $z\n"; 330 333 } 331 334 foreach $z (keys (%macro_config)) { 332 print "MACROS: $z $macro_config{$z}\n";335 print "MACROS: $z $macro_config{$z}\n"; 333 336 } 334 337 } … … 397 400 &execute_stacks($date,$metadata_out{nsObservingState}); 398 401 if ($metadata_out{nsStackState} eq 'QUEUESTACKING') { 399 $metadata_out{nsStackState} = 'STACKING_POSSIBLE_ERROR';402 $metadata_out{nsStackState} = 'STACKING_POSSIBLE_ERROR'; 400 403 } 401 404 return_metadata($date); … … 416 419 &execute_diffs($date,$metadata_out{nsObservingState}); 417 420 if ($metadata_out{nsDiffState} eq 'QUEUESTACKING') { 418 $metadata_out{nsDiffState} = 'STACKING_POSSIBLE_ERROR';421 $metadata_out{nsDiffState} = 'STACKING_POSSIBLE_ERROR'; 419 422 } 420 423 return_metadata($date); … … 481 484 my ($exp_name,$registered,$dateobs,$imfiles,$summit_fault, 482 485 $download_state,$download_count,$new_state,$exp_id,$exp_type) = @{ $row_ref }; 483 $Nsummit_imfiles += $imfiles;484 $Ndownload_imfiles += $download_count;486 $Nsummit_imfiles += $imfiles; 487 $Ndownload_imfiles += $download_count; 485 488 $Nsummit_exps++; 486 489 if ($summit_fault) { 487 print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault";490 print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault"; 488 491 if (($exp_type ne 'OBJECT')||($exp_name =~ /^c.*/)) { 489 492 print STDERR " (but I don't care).\n"; … … 526 529 } 527 530 elsif ($Ndownload_imfiles != $Nsummit_imfiles) { 528 print STDERR "Not done downloading from the summit for $date (Summit: $Nsummit_imfiles, Downloaded: $Ndownload_imfiles)\n";529 $metadata_out{nsRegState} = 'NEW';531 print STDERR "Not done downloading from the summit for $date (Summit: $Nsummit_imfiles, Downloaded: $Ndownload_imfiles)\n"; 532 $metadata_out{nsRegState} = 'NEW'; 530 533 } 531 534 else { … … 615 618 } 616 619 if (defined($reduction)) { 617 $cmd .= " -set_reduction $reduction ";620 $cmd .= " -set_reduction $reduction "; 618 621 } 619 622 $cmd .= " $select "; … … 674 677 675 678 foreach my $target (sort (keys %science_config)) { 676 my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = check_chip_status($date,$target);677 print "BTSTATS: $date $target $Nexposures $Nimfiles $Nburntooled $Nalready\n";679 my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = check_chip_status($date,$target); 680 print "BTSTATS: $date $target $Nexposures $Nimfiles $Nburntooled $Nalready\n"; 678 681 } 679 682 } … … 695 698 $cmd .= " -set_label dqstats.nightlyscience "; 696 699 if ($debug == 1) { 697 $cmd .= ' -pretend ';700 $cmd .= ' -pretend '; 698 701 } 699 702 print STDERR "$cmd\n"; … … 703 706 sub pre_dqstats_queue { 704 707 my $date = shift; 705 708 706 709 my $command = construct_dqstats_cmd($date) . ' -pretend '; 707 710 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 711 714 &my_die("Unable to perform dqstatstool: $error_code",1,1,,$date, $PS_EXIT_SYS_ERROR); 712 715 } 713 716 714 717 my @input_exposures = split /\n/, (join '', @$stdout_buf); 715 718 … … 735 738 my ($Nexposures,$Nchips,$Ncams) = pre_dqstats_queue($date); 736 739 if ($Nexposures == 0) { 737 print STDERR "execute_dqstats: No exposures on date $date.\n";740 print STDERR "execute_dqstats: No exposures on date $date.\n"; 738 741 } 739 742 elsif ($Ncams != $Nchips) { 740 print STDERR "execute_dqstats: Not done processing data through camera stage.\n";743 print STDERR "execute_dqstats: Not done processing data through camera stage.\n"; 741 744 } 742 745 else { 743 unless(defined($pretend)) {744 dqstats_queue($date);745 }746 if (defined($pretend)) {747 add_to_macro_list('check_dqstats',1,$date);748 }749 else {750 add_to_macro_list('queue_dqstats',1,$date);751 }746 unless(defined($pretend)) { 747 dqstats_queue($date); 748 } 749 if (defined($pretend)) { 750 add_to_macro_list('check_dqstats',1,$date); 751 } 752 else { 753 add_to_macro_list('queue_dqstats',1,$date); 754 } 752 755 } 753 756 } … … 761 764 762 765 my ($label,$workdir,$filter,$exp_type,$det_type,$ref_det_id,$ref_iter,$maxN) = get_dettool_parameters($date,$target); 763 766 764 767 my $select = "-select_dateobs_begin ${date}T00:00:00 -select_dateobs_end ${date}T23:59:59 "; 765 768 my $use_limits = " -use_begin ${date}T00:00:00 -use_end ${date}T23:59:59 "; … … 778 781 $cmd .= " $use_limits "; 779 782 if ($maxN > 0) { 780 $cmd .= " -random_subset -random_limit $maxN ";783 $cmd .= " -random_subset -random_limit $maxN "; 781 784 } 782 785 if ($debug == 1) { 783 $cmd .= ' -pretend ';786 $cmd .= ' -pretend '; 784 787 } 785 788 print STDERR "$cmd\n"; 786 789 return($cmd); 787 } 790 } 788 791 789 792 sub verify_uniqueness_detverify { … … 792 795 793 796 my ($label,$workdir,$filter,$exp_type,$det_type,$ref_det_id,$ref_iter,$maxN) = get_dettool_parameters($date,$target); 794 797 795 798 my $db = init_gpc_db(); 796 799 my $sth = "SELECT * FROM detRun WHERE workdir = '$workdir' AND ref_det_id = $ref_det_id AND ref_iter = $ref_iter"; … … 803 806 my $date = shift; 804 807 my $target = shift; 805 808 806 809 my $command = construct_dettool_cmd($date,$target) . ' -pretend '; 807 810 my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 808 run ( command => $command, verbose => $verbose);811 run ( command => $command, verbose => $verbose); 809 812 unless ($success) { 810 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);811 &my_die("Unable to perform dettool: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);812 } 813 813 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 814 &my_die("Unable to perform dettool: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR); 815 } 816 814 817 my @input_exposures = split /\n/, (join '', @$stdout_buf); 815 818 return($#input_exposures + 1); … … 819 822 my $date = shift; 820 823 my $target = shift; 821 824 822 825 my $command = construct_dettool_cmd($date,$target); 823 826 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 824 run ( command => $command, verbose => $verbose);827 run ( command => $command, verbose => $verbose); 825 828 unless ($success) { 826 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);827 &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);829 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 830 &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 828 831 } 829 832 $metadata_out{nsDetState} = 'DETREND_QUEUED'; … … 836 839 my $exposures = 0; 837 840 foreach my $target (sort (keys %detrend_config)) { 838 my ($Nexposures) = pre_detrend_queue($date,$target);839 if ($Nexposures == 0) {840 print STDERR "execute_detrends: Target $target on $date had no exposures.\n";841 next;842 }843 $exposures++;844 unless(defined($pretend)) {845 detrend_queue($date,$target);846 }847 if (defined($pretend)) {848 add_to_macro_list('check_detrends',1,$date,$target,"dettool");849 }850 else {851 add_to_macro_list('queue_detrends',1,$date,$target,"dettool");852 }841 my ($Nexposures) = pre_detrend_queue($date,$target); 842 if ($Nexposures == 0) { 843 print STDERR "execute_detrends: Target $target on $date had no exposures.\n"; 844 next; 845 } 846 $exposures++; 847 unless(defined($pretend)) { 848 detrend_queue($date,$target); 849 } 850 if (defined($pretend)) { 851 add_to_macro_list('check_detrends',1,$date,$target,"dettool"); 852 } 853 else { 854 add_to_macro_list('queue_detrends',1,$date,$target,"dettool"); 855 } 853 856 } 854 857 if ($exposures == 0) { 855 $metadata_out{nsDetState} = 'DETREND_DROP';858 $metadata_out{nsDetState} = 'DETREND_DROP'; 856 859 } 857 860 if (($metadata_out{nsDetState} eq 'CHECKDETRENDS') && ($exposures > 0)) { 858 $metadata_out{nsDetState} eq 'QUEUEDETRENDS';861 $metadata_out{nsDetState} eq 'QUEUEDETRENDS'; 859 862 } 860 863 } … … 882 885 # $cmd .= " $select "; 883 886 # if ($debug == 1) { 884 # $cmd .= ' -pretend ';887 # $cmd .= ' -pretend '; 885 888 # } 886 889 # print STDERR "$cmd\n"; … … 895 898 896 899 my $dt = DateTime->new(year => $year, month => $month, day => $day, 897 hour => 0, minute => 0, second => 0, nanosecond => 0,898 time_zone => 'Pacific/Honolulu');900 hour => 0, minute => 0, second => 0, nanosecond => 0, 901 time_zone => 'Pacific/Honolulu'); 899 902 do { 900 $dt->add(days => 1);901 my $ymd = $dt->ymd;902 my $md_cmd = "moondata $ymd 0 0";903 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =904 run ( command => $md_cmd, verbose => $verbose);905 unless ($success) {906 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);907 &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);908 }909 my @result = split /\s+/,(join "\n", @$stdout_buf);910 if (abs($result[6]) <= 0.6) {911 $dateobs_end = $ymd;912 }903 $dt->add(days => 1); 904 my $ymd = $dt->ymd; 905 my $md_cmd = "moondata $ymd 0 0"; 906 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 907 run ( command => $md_cmd, verbose => $verbose); 908 unless ($success) { 909 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 910 &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR); 911 } 912 my @result = split /\s+/,(join "\n", @$stdout_buf); 913 if (abs($result[6]) <= 0.6) { 914 $dateobs_end = $ymd; 915 } 913 916 } while (!defined($dateobs_end)); 914 917 915 918 do { 916 $dt->subtract(days => 1);917 my $ymd = $dt->ymd;918 my $md_cmd = "moondata $ymd 0 0";919 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =920 run ( command => $md_cmd, verbose => $verbose);921 unless ($success) {922 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);923 &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);924 }925 my @result = split /\s+/,(join "", @$stdout_buf);926 if (abs($result[6]) <= 0.6) {927 $dateobs_begin = $ymd;928 }919 $dt->subtract(days => 1); 920 my $ymd = $dt->ymd; 921 my $md_cmd = "moondata $ymd 0 0"; 922 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 923 run ( command => $md_cmd, verbose => $verbose); 924 unless ($success) { 925 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 926 &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR); 927 } 928 my @result = split /\s+/,(join "", @$stdout_buf); 929 if (abs($result[6]) <= 0.6) { 930 $dateobs_begin = $ymd; 931 } 929 932 } while (!defined($dateobs_begin)); 930 933 931 934 return($dateobs_begin,$dateobs_end); 932 935 } 933 936 934 # sub pre_sweetspot_queue { 937 # sub pre_sweetspot_queue { 935 938 # my $date = shift; 936 939 # my $command = construct_sweetspot_cmd($date) . ' -pretend '; 937 940 # my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 938 # run ( command => $command, verbose => $verbose );941 # run ( command => $command, verbose => $verbose ); 939 942 # unless ($success) { 940 943 # $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); … … 943 946 # my @stacks = split /\n/, (join '', @$stdout_buf); 944 947 # my $Nstacks = $#stacks + 1; 945 948 946 949 # return(1,$Nstacks); 947 950 # } … … 951 954 # my $command = construct_sweetspot_cmd($date); 952 955 # my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 953 # run ( command => $command, verbose => $verbose );956 # run ( command => $command, verbose => $verbose ); 954 957 # unless ($success) { 955 958 # $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); … … 958 961 # my @stacks = split /\n/, (join '', @$stdout_buf); 959 962 # my $Nstacks = $#stacks + 1; 960 963 961 964 # return(1,$Nstacks); 962 965 # } 963 966 964 # sub execute_sweetspot { 967 # sub execute_sweetspot { 965 968 # my $date = shift; 966 969 # my $pretend = shift; 967 970 968 971 # my ($is_lunation_date,$Nstacks) = pre_sweetspot_queue($date); 969 972 # if ($Nstacks == 0) { 970 # print STDERR "execute_sweetspot: No new stacks to make ($Nstacks)\n";971 # $metadata_out{nsSSState} = 'SS_EMPTY';972 # return();973 # print STDERR "execute_sweetspot: No new stacks to make ($Nstacks)\n"; 974 # $metadata_out{nsSSState} = 'SS_EMPTY'; 975 # return(); 973 976 # } 974 977 # if ($Nstacks < 10) { 975 # print STDERR "execute_sweetspot: Too few new stacks to make ($Nstacks)\n";976 # $metadata_out{nsSSState} = 'SS_FEW';977 # return();978 # print STDERR "execute_sweetspot: Too few new stacks to make ($Nstacks)\n"; 979 # $metadata_out{nsSSState} = 'SS_FEW'; 980 # return(); 978 981 # } 979 982 # if ($is_lunation_date == 0) { 980 # print STDERR "execute_sweetspot: Invalid lunation date. ($date $is_lunation_date)\n";981 # $metadata_out{nsSSState} = 'SS_ERROR';982 # return();983 # print STDERR "execute_sweetspot: Invalid lunation date. ($date $is_lunation_date)\n"; 984 # $metadata_out{nsSSState} = 'SS_ERROR'; 985 # return(); 983 986 # } 984 987 # $metadata_out{nsSSState} = 'SS_QUEUE'; 985 988 # $metadata_out{nsSweetSpot} = $Nstacks; 986 989 # unless(defined($pretend)) { 987 # $metadata_out{nsSSState} = 'SS_DONE';988 # sweetspot_queue($date);990 # $metadata_out{nsSSState} = 'SS_DONE'; 991 # sweetspot_queue($date); 989 992 # } 990 993 # if (defined($pretend)) { 991 # add_to_macro_list('check_sweetspot',1,$date);994 # add_to_macro_list('check_sweetspot',1,$date); 992 995 # } 993 996 # else { 994 # add_to_macro_list('queue_sweetspot',1,$date);997 # add_to_macro_list('queue_sweetspot',1,$date); 995 998 # } 996 999 # } … … 1020 1023 $cmd .= " -select_good_frac_min 0.05"; 1021 1024 if (defined($reduction)) { 1022 $cmd .= " -set_reduction $reduction ";1025 $cmd .= " -set_reduction $reduction "; 1023 1026 } 1024 1027 else { 1025 $cmd .= " -set_reduction NIGHTLY_STACK ";1028 $cmd .= " -set_reduction NIGHTLY_STACK "; 1026 1029 } 1027 1030 if (defined($science_config{$target}{ADDITIONAL_STACK_LABEL})) { 1028 # Grab list of skycells1029 my $skycell_select = '';1030 {1031 my %skycells = ();1032 my $warpcmd = "$warptool -warped -label $label -data_group $data_group -dbname $dbname";1033 my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =1034 run(command => $warpcmd, verbose => $verbose);1035 unless($success) {1036 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);1037 &my_die("Unabel to perform warptool -warped to determine skycell_ids: $error_code",$target);1038 }1039 my $runs = $mdcParser->parse_list(join "", @$stdout_buf) or1040 &my_die("Unabel to parse warptool -warped to determine skycell_ids: $error_code",$target);1041 if ($#{ $runs } != -1) {1042 for my $warp (@$runs) {1043 $skycells{$warp->{skycell_id}} = 1;1044 }1045 foreach my $skycell (sort (keys (%skycells))) {1046 $skycell_select .= " -select_skycell_id $skycell ";1047 }1048 $cmd .= " -select_label $science_config{$target}{ADDITIONAL_STACK_LABEL} $skycell_select ";1049 }1050 }1031 # Grab list of skycells 1032 my $skycell_select = ''; 1033 { 1034 my %skycells = (); 1035 my $warpcmd = "$warptool -warped -label $label -data_group $data_group -dbname $dbname"; 1036 my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = 1037 run(command => $warpcmd, verbose => $verbose); 1038 unless($success) { 1039 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1040 &my_die("Unabel to perform warptool -warped to determine skycell_ids: $error_code",$target); 1041 } 1042 my $runs = $mdcParser->parse_list(join "", @$stdout_buf) or 1043 &my_die("Unabel to parse warptool -warped to determine skycell_ids: $error_code",$target); 1044 if ($#{ $runs } != -1) { 1045 for my $warp (@$runs) { 1046 $skycells{$warp->{skycell_id}} = 1; 1047 } 1048 foreach my $skycell (sort (keys (%skycells))) { 1049 $skycell_select .= " -select_skycell_id $skycell "; 1050 } 1051 $cmd .= " -select_label $science_config{$target}{ADDITIONAL_STACK_LABEL} $skycell_select "; 1052 } 1053 } 1051 1054 } 1052 1055 $cmd .= " $select "; … … 1090 1093 my $where_possibly_faulted = $where . " AND ( " ; 1091 1094 foreach my $acceptable_quality (@unrecoverable_quality) { 1092 $where_possibly_faulted .= " quality = $acceptable_quality OR ";1095 $where_possibly_faulted .= " quality = $acceptable_quality OR "; 1093 1096 } 1094 1097 $where_possibly_faulted .= " 0 )"; … … 1119 1122 $Nalready += $trash[0]; 1120 1123 } 1121 1124 1122 1125 my $minimum_required_warp; 1123 1126 if ($observing_state eq 'OBSERVING') { 1124 $minimum_required_warp = $science_config{$target}{MIN_STACK};1127 $minimum_required_warp = $science_config{$target}{MIN_STACK}; 1125 1128 } 1126 1129 unless (defined($minimum_required_warp)) { 1127 $minimum_required_warp = 0;1130 $minimum_required_warp = 0; 1128 1131 } 1129 1132 … … 1143 1146 &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 1144 1147 } 1145 1146 1148 1149 1147 1150 return(0); 1148 1151 } … … 1158 1161 my $is_registering; 1159 1162 if ($metadata_out{nsRegistrationState} eq 'REGISTERED') { 1160 $is_registering = 0;1163 $is_registering = 0; 1161 1164 } 1162 1165 else { 1163 $is_registering = 1;1166 $is_registering = 1; 1164 1167 } 1165 1168 1166 1169 foreach my $target (sort (keys %science_config)) { 1167 if ($science_config{$target}{STACKABLE} == 1) {1168 foreach my $filter (@filter_list) {1170 if ($science_config{$target}{STACKABLE} == 1) { 1171 foreach my $filter (@filter_list) { 1169 1172 my ($Nexposures,$NprocChips,$NprocWarps,$NrequiredWarps,$Nalready) = pre_stack_queue($date,$observing_state,$target,$filter); 1170 1173 if ((!defined($force_stack_count))&&($NprocChips != $NprocWarps)) { # This makes me sad. :( 1171 if ($debug == 1) {1172 print STDERR "execute_stacks: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n";1173 }1174 $is_processing = 1;1174 if ($debug == 1) { 1175 print STDERR "execute_stacks: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n"; 1176 } 1177 $is_processing = 1; 1175 1178 $metadata_out{nsStackState} = 'FORCETOWARP'; 1176 1179 next; 1177 1180 } 1178 1181 if ($Nexposures == 0) { 1179 if ($debug == 1) {1180 print STDERR "execute_stacks: Target $target in filter $filter on $date has no exposures.\n";1181 }1182 if ($debug == 1) { 1183 print STDERR "execute_stacks: Target $target in filter $filter on $date has no exposures.\n"; 1184 } 1182 1185 next; 1183 1186 } 1184 if ($NprocWarps < $NrequiredWarps) {1185 if ($debug == 1) {1186 print STDERR "execute_stacks: Target $target in filter $filter on $date has too few warps to begin stacking. ($NprocWarps $NrequiredWarps)\n";1187 }1188 next;1189 }1190 $Npotential++;1187 if ($NprocWarps < $NrequiredWarps) { 1188 if ($debug == 1) { 1189 print STDERR "execute_stacks: Target $target in filter $filter on $date has too few warps to begin stacking. ($NprocWarps $NrequiredWarps)\n"; 1190 } 1191 next; 1192 } 1193 $Npotential++; 1191 1194 if ($Nalready != 0) { 1192 $Nqueued++;1193 if ($debug == 1) {1194 print STDERR "execute_stacks: Not queueing $target in filter $filter on $date due to already existing stacks.\n";1195 }1196 unless ($metadata_out{nsStackState} eq 'FORCETOWARP') {1197 $metadata_out{nsStackState} = 'STACKING';1198 }1195 $Nqueued++; 1196 if ($debug == 1) { 1197 print STDERR "execute_stacks: Not queueing $target in filter $filter on $date due to already existing stacks.\n"; 1198 } 1199 unless ($metadata_out{nsStackState} eq 'FORCETOWARP') { 1200 $metadata_out{nsStackState} = 'STACKING'; 1201 } 1199 1202 next; 1200 1203 } … … 1203 1206 } 1204 1207 unless(defined($pretend)) { 1205 if ($debug == 1) {1206 print STDERR "execute_stacks: Target $target in filter $filter on $date has exposures and will be queued.\n";1207 }1208 if ($debug == 1) { 1209 print STDERR "execute_stacks: Target $target in filter $filter on $date has exposures and will be queued.\n"; 1210 } 1208 1211 stack_queue($date,$target,$filter); 1209 $Nqueued ++;1210 } 1211 if (defined($pretend)) {1212 add_to_macro_list('check_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter);1213 }1214 else {1215 add_to_macro_list('queue_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter);1216 }1217 } 1218 }1219 else {1220 if ($debug == 1) {1221 print STDERR "execute_stacks: Target $target is not auto-stackable.\n";1222 }1212 $Nqueued ++; 1213 } 1214 if (defined($pretend)) { 1215 add_to_macro_list('check_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter); 1216 } 1217 else { 1218 add_to_macro_list('queue_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter); 1219 } 1220 } 1221 } 1222 else { 1223 if ($debug == 1) { 1224 print STDERR "execute_stacks: Target $target is not auto-stackable.\n"; 1225 } 1223 1226 } 1224 1227 } … … 1226 1229 $metadata_out{nsStackQueued} = $Nqueued; 1227 1230 if (($Npotential == $Nqueued)&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')&&($is_processing == 0)&&($is_registering == 0)) { 1228 $metadata_out{nsStackState} = 'FINISHED_STACKS';1229 } 1231 $metadata_out{nsStackState} = 'FINISHED_STACKS'; 1232 } 1230 1233 } 1231 1234 … … 1246 1249 $stack_done_sth .= " AND ((state = 'full') OR (state = 'new' && fault != 0)) "; 1247 1250 if ($debug == 1) { 1248 print STDERR "post_stack_queue: database queries:\n";1249 print STDERR "$stack_full_sth\n";1250 print STDERR "$stack_done_sth\n";1251 print STDERR "post_stack_queue: database queries:\n"; 1252 print STDERR "$stack_full_sth\n"; 1253 print STDERR "$stack_done_sth\n"; 1251 1254 } 1252 1255 my $stack_full_ref = $db->selectall_arrayref( $stack_full_sth ); … … 1259 1262 my $date = shift; 1260 1263 my $pretend = shift; 1261 1264 1262 1265 foreach my $target (sort (keys %science_config)) { 1263 1266 if ($science_config{$target}{STACKABLE} == 1) { 1264 my ($Nstacks, $Nattempted) = post_stack_queue($date,$target);1265 if ($debug == 1) {1266 print STDERR "confirm_stacks: Target $target on $date has $Nattempted attempts on $Nstacks.\n";1267 }1268 if ($Nstacks != $Nattempted) {1269 if ($debug == 1) {1270 print STDERR "confirm_stacks: Target $target on $date is not done stacking. $Nstacks $Nattempted\n";1271 }1272 if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') {1273 $metadata_out{nsStackState} = 'STACKING';1274 }1275 next;1276 }1277 if ($Nstacks == 0) {1278 if ($debug == 1) {1279 print STDERR "confirm_stacks: Target $target on $date has no stacks. Skipping.\n";1280 }1281 next;1282 }1283 if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') {1284 if (defined($pretend)) {1285 add_to_macro_list('check_confirm_stacks',$science_config{$target}{STACKABLE},$date,$target);1286 }1287 else {1288 add_to_macro_list('confirm_stacks',$science_config{$target}{STACKABLE},$date,$target);1289 }1290 }1291 }1292 } 1293 } 1267 my ($Nstacks, $Nattempted) = post_stack_queue($date,$target); 1268 if ($debug == 1) { 1269 print STDERR "confirm_stacks: Target $target on $date has $Nattempted attempts on $Nstacks.\n"; 1270 } 1271 if ($Nstacks != $Nattempted) { 1272 if ($debug == 1) { 1273 print STDERR "confirm_stacks: Target $target on $date is not done stacking. $Nstacks $Nattempted\n"; 1274 } 1275 if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') { 1276 $metadata_out{nsStackState} = 'STACKING'; 1277 } 1278 next; 1279 } 1280 if ($Nstacks == 0) { 1281 if ($debug == 1) { 1282 print STDERR "confirm_stacks: Target $target on $date has no stacks. Skipping.\n"; 1283 } 1284 next; 1285 } 1286 if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') { 1287 if (defined($pretend)) { 1288 add_to_macro_list('check_confirm_stacks',$science_config{$target}{STACKABLE},$date,$target); 1289 } 1290 else { 1291 add_to_macro_list('confirm_stacks',$science_config{$target}{STACKABLE},$date,$target); 1292 } 1293 } 1294 } 1295 } 1296 } 1294 1297 1295 1298 # … … 1308 1311 1309 1312 my $count = 0; 1310 1313 1311 1314 my $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where data_group = '$data_group' AND warp1 = $warp_id_1 AND warp2 = $warp_id_2"; 1312 1315 my $data_ref = $db->selectall_arrayref( $sth ); … … 1331 1334 1332 1335 my $count = 0; 1333 1336 1334 1337 my $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where (label = '$label' OR label = 'goto_cleaned') AND warp1 = $warp_id_1 AND warp2 = $warp_id_2"; 1335 1338 my $data_ref = $db->selectall_arrayref( $sth ); … … 1349 1352 my $filter = shift; 1350 1353 my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target); 1351 1354 1352 1355 my $db = init_gpc_db(); 1353 1356 … … 1358 1361 my $where_possibly_faulted = $where . " AND ( " ; 1359 1362 foreach my $acceptable_quality (@unrecoverable_quality) { 1360 $where_possibly_faulted .= " quality = $acceptable_quality OR ";1363 $where_possibly_faulted .= " quality = $acceptable_quality OR "; 1361 1364 } 1362 1365 $where_possibly_faulted .= " 0 )"; … … 1383 1386 my $is_registering; 1384 1387 if ($metadata_out{nsRegistrationState} eq 'REGISTERED') { 1385 $is_registering = 0;1388 $is_registering = 0; 1386 1389 } 1387 1390 else { 1388 $is_registering = 1;1391 $is_registering = 1; 1389 1392 } 1390 1393 1391 1394 foreach my $target (sort (keys %science_config)) { 1392 if ($science_config{$target}{DIFFABLE} == 1) { 1393 foreach my $filter (@filter_list) { 1394 $Npotential ++; 1395 my ($NprocChips,$NprocWarps) = pre_diff_queue($date,$observing_state,$target,$filter); 1396 if ((!defined($force_diff_count))&&($NprocChips != $NprocWarps)) { 1397 if ($debug == 1) { 1398 print STDERR "execute_diffs: Target $target in filter $filter on $date is not fully processed. ($NprocChips $NprocWarps)\n"; 1399 } 1400 $is_processing = 1; 1401 } 1395 if ($science_config{$target}{DIFFABLE} == 1) { 1396 1397 my $config_reduction = "DEFAULT"; 1398 if($science_config{$target}{REDUCTION}) {$config_reduction=$science_config{$target}{REDUCTION};} 1399 print STDERR "execute_diffs: Trying target $target on $date $camera $science_config{$target}{REDUCTION} $config_reduction\n"; 1400 1401 my $recipe_psastro = $ipprcam->reduction($config_reduction, 'PSASTRO'); # Recipe to use 1402 &my_die("Unrecognised PSASTRO recipe", $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro; 1403 1404 my $recipeData; 1405 { 1406 # Get the PSASTRO recipe 1407 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -"; 1408 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1409 run(command => $command); 1410 unless ($success) { 1411 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1412 &my_die("Unable to perform ppConfigDump: $error_code", $PS_EXIT_CONFIG_ERROR); 1413 } 1414 $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 1415 &my_die("Unable to parse metadata config doc", $PS_EXIT_CONFIG_ERROR); 1416 } 1417 1418 my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.ALLOWED.FWHM'); 1419 print STDERR "execute_diffs: Max FWHM= $maxFWHM for $target\n"; 1420 1421 foreach my $filter (@filter_list) { 1422 $Npotential ++; 1423 my ($NprocChips,$NprocWarps) = pre_diff_queue($date,$observing_state,$target,$filter); 1424 if ((!defined($force_diff_count))&&($NprocChips != $NprocWarps)) { 1425 if ($debug == 1) { 1426 print STDERR "execute_diffs: Target $target in filter $filter on $date is not fully processed. ($NprocChips $NprocWarps)\n"; 1427 } 1428 $is_processing = 1; 1429 } 1402 1430 if ($NprocChips == 0) { 1403 $Nnoexp ++;1404 if ($debug == 1) {1405 print STDERR "execute_diffs: Target $target in filter $filter on $date has no exposures.\n";1406 }1431 $Nnoexp ++; 1432 if ($debug == 1) { 1433 print STDERR "execute_diffs: Target $target in filter $filter on $date has no exposures.\n"; 1434 } 1407 1435 next; 1408 1436 } … … 1410 1438 $metadata_out{nsDiffState} = 'QUEUEDIFFS'; 1411 1439 } 1412 if ($debug == 1) {1413 print STDERR "execute_diffs: Target $target in filter $filter on $date has exposures and will be queued.\n";1414 }1415 diff_queue($date,$target,$filter,$pretend);1416 1417 #Queue up desperate diffs if the conditions are right for them 1418 if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) {1419 desperate_diff_singles($date,$target,$filter,$pretend);1420 }1421 1422 if (defined($pretend)) {1423 add_to_macro_list('check_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter);1424 }1425 else {1426 add_to_macro_list('queue_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter);1427 }1428 } 1429 }1430 else {1431 if ($debug == 1) {1432 print STDERR "execute_diffs: Target $target is not auto-diffable.\n";1433 }1440 if ($debug == 1) { 1441 print STDERR "execute_diffs: Target $target in filter $filter on $date has exposures and will be queued.\n"; 1442 } 1443 diff_queue($date,$target,$filter,$maxFWHM,$pretend); 1444 1445 #Queue up desperate diffs if the conditions are right for them 1446 if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) { 1447 desperate_diff_singles($date,$target,$filter,$maxFWHM,$pretend); 1448 } 1449 1450 if (defined($pretend)) { 1451 add_to_macro_list('check_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter); 1452 } 1453 else { 1454 add_to_macro_list('queue_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter); 1455 } 1456 } 1457 } 1458 else { 1459 if ($debug == 1) { 1460 print STDERR "execute_diffs: Target $target is not auto-diffable.\n"; 1461 } 1434 1462 } 1435 1463 } 1436 1464 if ($debug == 1) { 1437 print "$metadata_out{nsObservingState} $metadata_out{nsDiffPotential} $metadata_out{nsDiffQueued} $is_processing $is_registering\n";1465 print "$metadata_out{nsObservingState} $metadata_out{nsDiffPotential} $metadata_out{nsDiffQueued} $is_processing $is_registering\n"; 1438 1466 } 1439 1467 1440 1468 if ($metadata_out{nsObservingState} eq 'END_OF_NIGHT') { 1441 if ($is_processing == 1) {1442 $metadata_out{nsDiffState} = 'DIFFING';1443 }1444 elsif ($is_registering == 0) {1445 if ($Npotential == $Nnoexp) {1446 $metadata_out{nsDiffState} = 'FINISHED_DIFFS';1447 }1448 elsif ($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued}) {1449 $metadata_out{nsDiffState} = 'FINISHED_DIFFS';1450 }1451 }1452 else {1453 $metadata_out{nsDiffState} = 'DIFFING';1454 }1469 if ($is_processing == 1) { 1470 $metadata_out{nsDiffState} = 'DIFFING'; 1471 } 1472 elsif ($is_registering == 0) { 1473 if ($Npotential == $Nnoexp) { 1474 $metadata_out{nsDiffState} = 'FINISHED_DIFFS'; 1475 } 1476 elsif ($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued}) { 1477 $metadata_out{nsDiffState} = 'FINISHED_DIFFS'; 1478 } 1479 } 1480 else { 1481 $metadata_out{nsDiffState} = 'DIFFING'; 1482 } 1455 1483 } 1456 1484 else { 1457 $metadata_out{nsDiffState} = 'DIFFING';1485 $metadata_out{nsDiffState} = 'DIFFING'; 1458 1486 } 1459 1487 if ($metadata_out{nsDiffState} eq 'FINISHED_DIFFS') { 1460 foreach my $target (sort (keys %science_config)) { 1461 # CZW: We should only arrive at this point once, so we can construct a diff report and mail it now. 1462 if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) { 1463 foreach my $filter (@filter_list) { 1464 desperate_diff_queue($date,$target,$filter,$pretend); 1465 } 1466 } 1467 1468 if ((defined($science_config{$target}{SELF_WSDIFFS})) && ($science_config{$target}{SELF_WSDIFFS} == 1)) { 1469 foreach my $filter (@filter_list) { 1470 # This one needs to return a state to see if we need to wait on stacking before checking again. 1471 $metadata_out{nsDiffState} = self_WS_diff_queue($date,$target,$filter,$pretend); 1472 } 1473 } 1474 } 1488 foreach my $target (sort (keys %science_config)) { 1489 1490 my $config_reduction = "DEFAULT"; 1491 if($science_config{$target}{REDUCTION}) {$config_reduction=$science_config{$target}{REDUCTION};} 1492 print STDERR "execute_diffs: Trying target $target on $date $camera $science_config{$target}{REDUCTION} $config_reduction\n"; 1493 1494 my $recipe_psastro = $ipprcam->reduction($config_reduction, 'PSASTRO'); # Recipe to use 1495 &my_die("Unrecognised PSASTRO recipe", $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro; 1496 1497 my $recipeData; 1498 { 1499 # Get the PSASTRO recipe 1500 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -"; 1501 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1502 run(command => $command); 1503 unless ($success) { 1504 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1505 &my_die("Unable to perform ppConfigDump: $error_code", $PS_EXIT_CONFIG_ERROR); 1506 } 1507 $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 1508 &my_die("Unable to parse metadata config doc", $PS_EXIT_CONFIG_ERROR); 1509 } 1510 1511 my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.ALLOWED.FWHM'); 1512 1513 # CZW: We should only arrive at this point once, so we can construct a diff report and mail it now. 1514 if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) { 1515 foreach my $filter (@filter_list) { 1516 desperate_diff_queue($date,$target,$filter,$maxFWHM,$pretend); 1517 } 1518 } 1519 1520 if ((defined($science_config{$target}{SELF_WSDIFFS})) && ($science_config{$target}{SELF_WSDIFFS} == 1)) { 1521 foreach my $filter (@filter_list) { 1522 # This one needs to return a state to see if we need to wait on stacking before checking again. 1523 $metadata_out{nsDiffState} = self_WS_diff_queue($date,$target,$filter,$pretend); 1524 } 1525 } 1526 } 1475 1527 } 1476 1528 1477 1529 # if (($Npotential == $Nnoexp)&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')&&($is_processing == 0)) { 1478 # $metadata_out{nsDiffState} = 'FINISHED_DIFFS';1479 # } 1530 # $metadata_out{nsDiffState} = 'FINISHED_DIFFS'; 1531 # } 1480 1532 1481 1533 # if ($is_processing == 1) { 1482 # $metadata_out{nsDiffState} = 'DIFFING';1534 # $metadata_out{nsDiffState} = 'DIFFING'; 1483 1535 # } 1484 1536 } … … 1488 1540 my $target = shift; 1489 1541 my $filter = shift; 1542 my $maxFWHM = shift; 1490 1543 my $pretend = shift; 1491 1544 my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target); … … 1500 1553 my $Npotential = 0; 1501 1554 my $Nqueued = 0; 1502 1555 1503 1556 foreach my $object_row (@{ $object_ref }) { 1504 my $this_object = shift @{ $object_row }; 1505 my $this_chunk = shift @{ $object_row }; 1506 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM "; 1507 $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) "; 1508 $input_sth .= " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 1509 $input_sth .= " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs "; 1510 1511 my $warps = $db->selectall_arrayref( $input_sth ); 1512 1513 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra. 1514 my %comment_hash = (); 1515 foreach my $this_warp (@{ $warps }) { 1516 my $this_comment = ${ $this_warp }[3]; 1517 my $this_exp_id = ${ $this_warp }[0]; 1518 my $this_quality = ${ $this_warp }[5]; 1519 my $this_state = ${ $this_warp }[4]; 1520 if (($this_quality != 0) || ($this_state eq 'drop') ) { 1521 print STDERR "diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n"; 1522 } 1523 else { 1524 $comment_hash{$this_comment} = $this_exp_id; 1525 } 1526 } 1527 # Exclude any warps that are not stored in the comment_hash. 1528 my @keep_warps = (); 1529 foreach my $this_warp (@{ $warps }) { 1530 my $this_comment = ${ $this_warp }[3]; 1531 my $this_exp_id = ${ $this_warp }[0]; 1532 if ((exists($comment_hash{$this_comment}))&& 1533 ($comment_hash{$this_comment} == $this_exp_id)) { 1534 push @keep_warps, $this_warp; 1535 } 1536 else { 1537 print STDERR "diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n"; 1538 } 1539 } 1540 @{ $warps } = @keep_warps; 1541 1542 # Exclude the last entry if we do not have an even number of warps. 1543 if (($#{ $warps } + 1) % 2 != 0) { 1544 print STDERR "diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } "; 1545 if ($#{ $warps} + 1 == 1) { 1546 print STDERR ": I can do no diffs with only one exposure.\n"; 1547 next; 1548 } 1549 else { 1550 my $rejected_warp = pop @{ $warps }; 1551 my $rejected_exp_id = ${ $rejected_warp }[0]; 1552 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 1553 } 1554 } 1555 1556 while ($#{ $warps } > -1) { 1557 # The array is sorted in pairs of input/template. 1558 my $input_warp = shift @{ $warps }; 1559 my $template_warp = shift @{ $warps }; 1560 1561 my $input_exp_id = ${ $input_warp }[0]; 1562 my $input_comment = ${ $input_warp }[3]; 1563 1564 my $template_exp_id = ${ $template_warp }[0]; 1565 my $template_comment = ${ $template_warp }[3]; 1566 1567 my $input_warp_id = ${ $input_warp }[1]; 1568 my $template_warp_id = ${ $template_warp }[1]; 1569 1570 my $input_warp_state = ${ $input_warp }[4]; 1571 my $template_warp_state = ${ $template_warp }[4]; 1572 1573 my $input_warp_camQuality = ${ $input_warp }[5]; 1574 my $template_warp_camQuality = ${ $template_warp }[5]; 1575 1576 $Npotential++; 1577 1578 unless (defined($input_warp_id) && defined($template_warp_id) && 1579 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 1580 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"; 1581 if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 1582 # This should now never be reached. 1583 # CZW: Trigger backup plan here? Or simply set up framework? 1584 print STDERR " ...but this is due to a camera stage astrometry quality\n"; 1585 $Npotential--; 1586 } 1587 next; 1588 } 1589 1590 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 1591 $Nqueued++; 1592 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"; 1593 next; 1594 } 1595 else { 1596 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"; 1597 } 1598 1599 my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 1600 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 1601 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 1602 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group "; 1603 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 1604 # $cmd .= " -pretend "; 1605 if (defined($reduction)) { 1606 $cmd .= " -set_reduction $reduction "; 1607 } 1608 1609 if (defined($pretend)) { 1610 $cmd .= ' -pretend '; 1611 } 1612 if ($debug == 1) { 1613 $cmd .= ' -pretend '; 1614 print STDERR "diff_queue: $cmd\n"; 1615 print STDERR " $input_warp_id $template_warp_id\n"; 1616 } 1617 1618 if (($debug == 0)&&(!defined($pretend))) { 1619 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1620 run ( command => $cmd, verbose => $verbose ); 1621 unless ($success) { 1622 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1623 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 1624 } 1625 $Nqueued++; 1626 } 1627 } 1557 my $this_object = shift @{ $object_row }; 1558 my $this_chunk = shift @{ $object_row }; 1559 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM "; 1560 $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) "; 1561 $input_sth .= " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 1562 $input_sth .= " AND camProcessedExp.fwhm_major <= $maxFWHM "; 1563 $input_sth .= " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs "; 1564 1565 my $warps = $db->selectall_arrayref( $input_sth ); 1566 1567 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra. 1568 my %comment_hash = (); 1569 foreach my $this_warp (@{ $warps }) { 1570 my $this_comment = ${ $this_warp }[3]; 1571 my $this_exp_id = ${ $this_warp }[0]; 1572 my $this_quality = ${ $this_warp }[5]; 1573 my $this_state = ${ $this_warp }[4]; 1574 if (($this_quality != 0) || ($this_state eq 'drop') ) { 1575 print STDERR "diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n"; 1576 } 1577 else { 1578 $comment_hash{$this_comment} = $this_exp_id; 1579 } 1580 } 1581 # Exclude any warps that are not stored in the comment_hash. 1582 my @keep_warps = (); 1583 foreach my $this_warp (@{ $warps }) { 1584 my $this_comment = ${ $this_warp }[3]; 1585 my $this_exp_id = ${ $this_warp }[0]; 1586 if ((exists($comment_hash{$this_comment}))&& 1587 ($comment_hash{$this_comment} == $this_exp_id)) { 1588 push @keep_warps, $this_warp; 1589 } 1590 else { 1591 print STDERR "diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n"; 1592 } 1593 } 1594 @{ $warps } = @keep_warps; 1595 1596 # Exclude the last entry if we do not have an even number of warps. 1597 if (($#{ $warps } + 1) % 2 != 0) { 1598 print STDERR "diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } "; 1599 if ($#{ $warps} + 1 == 1) { 1600 print STDERR ": I can do no diffs with only one exposure.\n"; 1601 next; 1602 } 1603 else { 1604 my $rejected_warp = pop @{ $warps }; 1605 my $rejected_exp_id = ${ $rejected_warp }[0]; 1606 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 1607 } 1608 } 1609 1610 while ($#{ $warps } > -1) { 1611 # The array is sorted in pairs of input/template. 1612 my $input_warp = shift @{ $warps }; 1613 my $template_warp = shift @{ $warps }; 1614 1615 my $input_exp_id = ${ $input_warp }[0]; 1616 my $input_comment = ${ $input_warp }[3]; 1617 1618 my $template_exp_id = ${ $template_warp }[0]; 1619 my $template_comment = ${ $template_warp }[3]; 1620 1621 my $input_warp_id = ${ $input_warp }[1]; 1622 my $template_warp_id = ${ $template_warp }[1]; 1623 1624 my $input_warp_state = ${ $input_warp }[4]; 1625 my $template_warp_state = ${ $template_warp }[4]; 1626 1627 my $input_warp_camQuality = ${ $input_warp }[5]; 1628 my $template_warp_camQuality = ${ $template_warp }[5]; 1629 1630 $Npotential++; 1631 1632 unless (defined($input_warp_id) && defined($template_warp_id) && 1633 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 1634 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"; 1635 if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 1636 # This should now never be reached. 1637 # CZW: Trigger backup plan here? Or simply set up framework? 1638 print STDERR " ...but this is due to a camera stage astrometry quality\n"; 1639 $Npotential--; 1640 } 1641 next; 1642 } 1643 1644 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 1645 $Nqueued++; 1646 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"; 1647 next; 1648 } 1649 else { 1650 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"; 1651 } 1652 1653 my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 1654 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 1655 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 1656 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group "; 1657 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 1658 # $cmd .= " -pretend "; 1659 if (defined($reduction)) { 1660 $cmd .= " -set_reduction $reduction "; 1661 } 1662 1663 if (defined($pretend)) { 1664 $cmd .= ' -pretend '; 1665 } 1666 if ($debug == 1) { 1667 $cmd .= ' -pretend '; 1668 print STDERR "diff_queue: $cmd\n"; 1669 print STDERR " $input_warp_id $template_warp_id\n"; 1670 } 1671 1672 if (($debug == 0)&&(!defined($pretend))) { 1673 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1674 run ( command => $cmd, verbose => $verbose ); 1675 unless ($success) { 1676 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1677 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 1678 } 1679 $Nqueued++; 1680 } 1681 } 1628 1682 } 1629 1683 $metadata_out{nsDiffPotential} += $Npotential; 1630 1684 $metadata_out{nsDiffQueued} += $Nqueued; 1631 1685 # if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) { 1632 # $metadata_out{nsDiffState} = 'FINISHED_DIFFS';1633 # } 1686 # $metadata_out{nsDiffState} = 'FINISHED_DIFFS'; 1687 # } 1634 1688 1635 1689 } … … 1639 1693 my $target = shift; 1640 1694 my $filter = shift; 1695 my $maxFWHM = shift; 1641 1696 my $pretend = shift; 1642 1697 my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target); … … 1655 1710 my $Nqueued = 0; 1656 1711 1657 #Before considering making diffs, we should check if there are no issues with summit download and/or registration. 1712 #Before considering making diffs, we should check if there are no issues with summit download and/or registration. 1658 1713 #summitExp has limited information, so see if the number of exps in rawExp and summitExp match up before most recent dateobs of chunk 1659 1714 #be careful here, since dateobs is not quite completely the same in both tables. Therefore, allow numbers to be off by 1 … … 1673 1728 $rawdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/; 1674 1729 my $date1=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC"); 1675 1730 1676 1731 $summitdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/; 1677 1732 my $date2=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC"); … … 1686 1741 if (($summittimediff > 10.)||($noff >10)) { 1687 1742 if ($debug == 1) { 1688 print STDERR "desp_diff_singles: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n";1689 } 1690 } 1691 else { 1743 print STDERR "desp_diff_singles: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n"; 1744 } 1745 } 1746 else { 1692 1747 foreach my $object_row (@{ $object_ref }) { 1693 my $this_object = shift @{ $object_row }; 1694 my $this_chunk = shift @{ $object_row }; 1695 1696 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality,substr(comment, 1, position(' ' in comment)) FROM "; 1697 $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) "; 1698 $input_sth .= " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 1699 $input_sth .= " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs "; 1700 1701 my $warps = $db->selectall_arrayref( $input_sth ); 1702 1703 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra. 1704 my %comment_hash = (); 1705 foreach my $this_warp (@{ $warps }) { 1706 my $this_comment = ${ $this_warp }[3]; 1707 my $this_exp_id = ${ $this_warp }[0]; 1708 my $this_quality = ${ $this_warp }[5]; 1709 my $this_state = ${ $this_warp }[4]; 1710 if (($this_quality != 0) || ($this_state eq 'drop') ) { 1711 print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n"; 1712 } 1713 else { 1714 $comment_hash{$this_comment} = $this_exp_id; 1715 } 1716 } 1717 # Exclude any warps that are not stored in the comment_hash. 1718 my @keep_warps = (); 1719 foreach my $this_warp (@{ $warps }) { 1720 my $this_comment = ${ $this_warp }[3]; 1721 my $this_exp_id = ${ $this_warp }[0]; 1722 if ((exists($comment_hash{$this_comment}))&& 1723 ($comment_hash{$this_comment} == $this_exp_id)) { 1724 push @keep_warps, $this_warp; 1748 my $this_object = shift @{ $object_row }; 1749 my $this_chunk = shift @{ $object_row }; 1750 1751 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality,substr(comment, 1, position(' ' in comment)),camProcessedExp.fwhm_major FROM "; 1752 $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) "; 1753 $input_sth .= " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 1754 $input_sth .= " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs "; 1755 1756 my $warps = $db->selectall_arrayref( $input_sth ); 1757 my $warpsBQ = $db->selectall_arrayref( $input_sth );; 1758 1759 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra. 1760 my %comment_hash = (); 1761 my %comment_hash_good = (); 1762 foreach my $this_warp (@{ $warps }) { 1763 my $this_comment = ${ $this_warp }[3]; 1764 my $this_exp_id = ${ $this_warp }[0]; 1765 my $this_quality = ${ $this_warp }[5]; 1766 my $this_state = ${ $this_warp }[4]; 1767 my $this_fwhm = ${ $this_warp }[7]; 1768 if (($this_quality != 0) || ($this_state eq 'drop') || ($this_fwhm > $maxFWHM)) { 1769 print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state or FWHM $this_fwhm\n"; 1770 } 1771 else { 1772 $comment_hash_good{$this_comment} = $this_exp_id; 1773 } 1774 1775 #also save the entries which are ok, but not best quality 1776 if (($this_quality == 0) && ($this_state ne 'drop') ) { 1777 $comment_hash{$this_comment} = $this_exp_id; 1778 } 1779 } 1780 1781 # Exclude any warps that are not stored in the comment_hash_good. 1782 my @keep_warps = (); 1783 foreach my $this_warp (@{ $warps }) { 1784 my $this_comment = ${ $this_warp }[3]; 1785 my $this_exp_id = ${ $this_warp }[0]; 1786 if ((exists($comment_hash_good{$this_comment}))&& 1787 ($comment_hash_good{$this_comment} == $this_exp_id)) { 1788 push @keep_warps, $this_warp; 1725 1789 $this_date = ${ $this_warp }[2]; 1726 1790 $chunk_name = ${ $this_warp }[6]; 1727 } 1728 else { 1729 print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to being rejected $this_comment\n"; 1730 } 1731 } 1732 @{ $warps } = @keep_warps; 1733 1791 } 1792 else { 1793 print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to being rejected $this_comment\n"; 1794 } 1795 } 1796 @{ $warps } = @keep_warps; 1797 my $nwarps = ($#{ $warps } + 1); 1798 1734 1799 #find the time of the most recent exposure in that chunk 1735 my $input_chunk = "select max(dateobs) FROM rawExp WHERE substr(comment, 1, position(' ' in comment)) = '$chunk_name' AND filter = '$filter' ";1736 my $chunk = $db->selectall_arrayref( $input_chunk );1737 foreach my $this_chunk (@{ $chunk }) {1738 $this_date = ${ $this_chunk }[0];1800 my $input_chunk = "select max(dateobs) FROM rawExp WHERE substr(comment, 1, position(' ' in comment)) = '$chunk_name' AND filter = '$filter' "; 1801 my $chunk = $db->selectall_arrayref( $input_chunk ); 1802 foreach my $this_chunk (@{ $chunk }) { 1803 $this_date = ${ $this_chunk }[0]; 1739 1804 } 1740 1805 1741 1806 #compute and store some stats for potential on-the-fly desperate diffs 1742 my $nwarps = ($#{ $warps } + 1);1743 1807 my $timediff = 0; 1744 1808 my $now=DateTime->now; … … 1752 1816 } 1753 1817 } 1754 1755 #Consider the special case of on-the-fly desperate diffs 1756 #The conditions are: uneven nr of warps greater than 3, and the most recent observations is more than $desdiffdt hours old 1757 if (($nwarps % 2 != 0) && ($nwarps >= 3) && ($timediff < $desdiffdt)) { 1758 print STDERR "desp_diff_singles: There are potential desperate diffs to be done, but the time criterium is not met.\n"; 1759 next; 1760 } 1761 if (($nwarps % 2 == 0) || ($nwarps == 1) || ($timediff < $desdiffdt)) { 1762 next; 1763 } 1764 1765 # We are attempting to do the missing diffs, so reverse the list of retained warps. 1766 # Good objects with all visits will be skipped due to the duplicate check. 1767 # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs. 1768 @{ $warps } = reverse @keep_warps; 1769 1770 # Exclude the last entry if we do not have an even number of warps. 1771 if (($#{ $warps } + 1) % 2 != 0) { 1772 print STDERR "desp_diff_singles: Number of input warps to make diffs is not even for target $target and object $this_object!"; 1773 my $rejected_warp = pop @{ $warps }; 1774 my $rejected_exp_id = ${ $rejected_warp }[0]; 1775 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 1776 } 1777 1778 while ($#{ $warps } > -1) { 1779 # The array is sorted in pairs of input/template. 1780 my $template_warp = shift @{ $warps }; 1781 my $input_warp = shift @{ $warps }; 1782 1783 my $input_exp_id = ${ $input_warp }[0]; 1784 my $input_comment = ${ $input_warp }[3]; 1785 1786 my $template_exp_id = ${ $template_warp }[0]; 1787 my $template_comment = ${ $template_warp }[3]; 1788 1789 my $input_warp_id = ${ $input_warp }[1]; 1790 my $template_warp_id = ${ $template_warp }[1]; 1791 1792 my $input_warp_state = ${ $input_warp }[4]; 1793 my $template_warp_state = ${ $template_warp }[4]; 1794 1795 my $input_warp_camQuality = ${ $input_warp }[5]; 1796 my $template_warp_camQuality = ${ $template_warp }[5]; 1797 1798 $Npotential++; 1799 1800 unless (defined($input_warp_id) && defined($template_warp_id) && 1801 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 1802 print STDERR "Desp 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"; 1803 if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 1804 # This should now never be reached. 1805 # CZW: Trigger backup plan here? Or simply set up framework? 1806 print STDERR " ...but this is due to a camera stage astrometry quality\n"; 1807 $Npotential--; 1808 } 1809 next; 1810 } 1811 1812 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 1813 $Nqueued++; 1814 print STDERR "Desp 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"; 1815 next; 1816 } 1817 else { 1818 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"; 1819 } 1820 1821 my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 1822 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 1823 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 1824 $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures 1825 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group "; 1826 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 1827 if (defined($reduction)) { 1828 $cmd .= " -set_reduction $reduction "; 1829 } 1830 1831 if (defined($pretend)) { 1832 $cmd .= ' -pretend '; 1833 } 1834 if ($debug == 1) { 1835 $cmd .= ' -pretend '; 1836 print STDERR "desp_diff_singles: $cmd\n"; 1837 print STDERR " $input_warp_id $template_warp_id\n"; 1838 } 1839 1840 if (($debug == 0)&&(!defined($pretend))) { 1841 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1842 run ( command => $cmd, verbose => $verbose ); 1843 unless ($success) { 1844 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1845 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 1846 } 1847 $Nqueued++; 1848 } 1849 } 1818 1819 ################################ 1820 #We reach a junction here, where having more than 3 (but uneven) warps will result in desperate diffs 1821 #Conversely, less than 3 good quality warps might result in dirty diffs 1822 ################################ 1823 if($nwarps >= 3) { 1824 #Consider the special case of on-the-fly desperate diffs 1825 #The conditions are: uneven nr of warps greater than 3, and the most recent observations is more than $desdiffdt hours old 1826 if (($nwarps % 2 != 0) && ($nwarps >= 3) && ($timediff < $desdiffdt)) { 1827 print STDERR "desp_diff_singles: There are potential desperate diffs to be done, but the time criterium is not met.\n"; 1828 next; 1829 } 1830 if (($nwarps % 2 == 0) || ($nwarps == 1) || ($timediff < $desdiffdt)) { 1831 next; 1832 } 1833 1834 # We are attempting to do the missing diffs, so reverse the list of retained warps. 1835 # Good objects with all visits will be skipped due to the duplicate check. 1836 # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs. 1837 @{ $warps } = reverse @keep_warps; 1838 1839 # Exclude the last entry if we do not have an even number of warps. 1840 if (($#{ $warps } + 1) % 2 != 0) { 1841 print STDERR "desp_diff_singles: Number of input warps to make diffs is not even for target $target and object $this_object!"; 1842 my $rejected_warp = pop @{ $warps }; 1843 my $rejected_exp_id = ${ $rejected_warp }[0]; 1844 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 1845 } 1846 1847 while ($#{ $warps } > -1) { 1848 # The array is sorted in pairs of input/template. 1849 my $template_warp = shift @{ $warps }; 1850 my $input_warp = shift @{ $warps }; 1851 1852 my $input_exp_id = ${ $input_warp }[0]; 1853 my $input_comment = ${ $input_warp }[3]; 1854 1855 my $template_exp_id = ${ $template_warp }[0]; 1856 my $template_comment = ${ $template_warp }[3]; 1857 1858 my $input_warp_id = ${ $input_warp }[1]; 1859 my $template_warp_id = ${ $template_warp }[1]; 1860 1861 my $input_warp_state = ${ $input_warp }[4]; 1862 my $template_warp_state = ${ $template_warp }[4]; 1863 1864 my $input_warp_camQuality = ${ $input_warp }[5]; 1865 my $template_warp_camQuality = ${ $template_warp }[5]; 1866 1867 $Npotential++; 1868 1869 unless (defined($input_warp_id) && defined($template_warp_id) && 1870 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 1871 print STDERR "Desp 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"; 1872 if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 1873 # This should now never be reached. 1874 # CZW: Trigger backup plan here? Or simply set up framework? 1875 print STDERR " ...but this is due to a camera stage astrometry quality\n"; 1876 $Npotential--; 1877 } 1878 next; 1879 } 1880 1881 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 1882 $Nqueued++; 1883 print STDERR "Desp 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"; 1884 next; 1885 } 1886 else { 1887 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"; 1888 } 1889 1890 my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 1891 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 1892 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 1893 $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures 1894 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group "; 1895 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 1896 if (defined($reduction)) { 1897 $cmd .= " -set_reduction $reduction "; 1898 } 1899 1900 if (defined($pretend)) { 1901 $cmd .= ' -pretend '; 1902 } 1903 if ($debug == 1) { 1904 $cmd .= ' -pretend '; 1905 print STDERR "desp_diff_singles: $cmd\n"; 1906 print STDERR " $input_warp_id $template_warp_id\n"; 1907 } 1908 1909 if (($debug == 0)&&(!defined($pretend))) { 1910 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1911 run ( command => $cmd, verbose => $verbose ); 1912 unless ($success) { 1913 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 1914 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 1915 } 1916 $Nqueued++; 1917 } 1918 } 1919 1920 } else { 1921 print STDERR "desp_diff_singles: There is a possibility for dirty diffs to be made\n"; 1922 #Consider the case of on-the-fly dirty desperate diffs 1923 #The conditions are: uneven nr of bad quality warps greater than 3, and the most recent observations is more than $desdiffdt hours old 1924 1925 # # Exclude any warps that are not stored in the more general comment_hash. 1926 # my @keep_warps = (); 1927 # foreach my $this_warp (@{ $warpsBQ }) { 1928 # my $this_comment = ${ $this_warp }[3]; 1929 # my $this_exp_id = ${ $this_warp }[0]; 1930 # if ((exists($comment_hash{$this_comment}))&& 1931 # ($comment_hash{$this_comment} == $this_exp_id)) { 1932 # push @keep_warps, $this_warp; 1933 # $this_date = ${ $this_warp }[2]; 1934 # $chunk_name = ${ $this_warp }[6]; 1935 # } 1936 # else { 1937 # print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to being rejected $this_comment\n"; 1938 # } 1939 # } 1940 # @{ $warpsBQ } = @keep_warps; 1941 # 1942 # if ($nwarps >= 2) { 1943 # #one regular diff has already been made. So, need only one more. Strip a good entry from the array 1944 # my $nrem = 0; 1945 # my @keep_warps = (); 1946 # foreach my $this_warp (@{ $warpsBQ }) { 1947 # my $this_comment = ${ $this_warp }[3]; 1948 # my $this_exp_id = ${ $this_warp }[0]; 1949 # my $this_fwhm = ${ $this_warp }[7]; 1950 # if (($nrem <1) && ($this_fwhm <= $maxFWHM)) { 1951 # $nrem++; 1952 # print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object from dirty desp diffs $this_comment\n"; 1953 # } else { 1954 # push @keep_warps, $this_warp; 1955 # } 1956 # } 1957 # @{ $warpsBQ } = @keep_warps; 1958 # } 1959 # 1960 # # We are attempting to do the missing diffs, so reverse the list of retained warps. 1961 # # Good objects with all visits will be skipped due to the duplicate check. 1962 # # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs. 1963 # @{ $warpsBQ } = reverse @{ $warpsBQ }; 1964 # 1965 # # Exclude the last entry if we do not have an even number of warps. 1966 # if (($#{ $warpsBQ } + 1) % 2 != 0) { 1967 # print STDERR "desp_diff_singles: Number of input warps to make dirty diffs is not even for target $target and object $this_object!"; 1968 # my $rejected_warp = pop @{ $warpsBQ }; 1969 # my $rejected_exp_id = ${ $rejected_warp }[0]; 1970 # print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 1971 # } 1972 # my $nwarpsBQ = ($#{$warpsBQ} + 1); 1973 # 1974 # 1975 # if (($nwarpsBQ >= 2) && ($timediff < $desdiffdt)) { 1976 # print STDERR "desp_diff_singles: There are potential dirty desperate diffs to be done, but the time criterium is not met.\n"; 1977 # next; 1978 # } 1979 # if (($nwarpsBQ <= 1) || ($timediff < $desdiffdt)) { 1980 # next; 1981 # } 1982 # 1983 # while ($#{ $warpsBQ } > -1) { 1984 # # The array is sorted in pairs of input/template. 1985 # my $template_warp = shift @{ $warpsBQ }; 1986 # my $input_warp = shift @{ $warpsBQ }; 1987 # 1988 # my $input_exp_id = ${ $input_warp }[0]; 1989 # my $input_comment = ${ $input_warp }[3]; 1990 # 1991 # my $template_exp_id = ${ $template_warp }[0]; 1992 # my $template_comment = ${ $template_warp }[3]; 1993 # 1994 # my $input_warp_id = ${ $input_warp }[1]; 1995 # my $template_warp_id = ${ $template_warp }[1]; 1996 # 1997 # my $input_warp_state = ${ $input_warp }[4]; 1998 # my $template_warp_state = ${ $template_warp }[4]; 1999 # 2000 # my $input_warp_camQuality = ${ $input_warp }[5]; 2001 # my $template_warp_camQuality = ${ $template_warp }[5]; 2002 # 2003 # $Npotential++; 2004 # 2005 # unless (defined($input_warp_id) && defined($template_warp_id) && 2006 # ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 2007 # print STDERR "Desp 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"; 2008 # if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 2009 # # This should now never be reached. 2010 # # CZW: Trigger backup plan here? Or simply set up framework? 2011 # print STDERR " ...but this is due to a camera stage astrometry quality\n"; 2012 # $Npotential--; 2013 # } 2014 # next; 2015 # } 2016 # 2017 # if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 2018 # $Nqueued++; 2019 # print STDERR "Desp 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"; 2020 # next; 2021 # } 2022 # else { 2023 # print STDERR "Preparing to dirty diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n"; 2024 # } 2025 # 2026 # my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 2027 # $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 2028 # $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 2029 # $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures 2030 # $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group "; 2031 # $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 2032 # if (defined($reduction)) { 2033 # $cmd .= " -set_reduction $reduction "; 2034 # } 2035 # 2036 # if (defined($pretend)) { 2037 # $cmd .= ' -pretend '; 2038 # } 2039 # if ($debug == 1) { 2040 # $cmd .= ' -pretend '; 2041 # print STDERR "desp_diff_singles: $cmd\n"; 2042 # print STDERR " $input_warp_id $template_warp_id\n"; 2043 # } 2044 # 2045 # if (($debug == 0)&&(!defined($pretend))) { 2046 # my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2047 # run ( command => $cmd, verbose => $verbose ); 2048 # unless ($success) { 2049 # $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2050 # &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2051 # } 2052 # $Nqueued++; 2053 # } 2054 # } 2055 2056 2057 2058 } 1850 2059 } 1851 2060 } … … 1858 2067 my $target = shift; 1859 2068 my $filter = shift; 2069 my $maxFWHM = shift; 1860 2070 my $pretend = shift; 1861 2071 my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target); … … 1872 2082 my $Nqueued = 0; 1873 2083 1874 #Before considering making diffs, we should check if there are no issues with summit download and/or registration. 2084 #Before considering making diffs, we should check if there are no issues with summit download and/or registration. 1875 2085 #summitExp has limited information, so see if the number of exps in rawExp and summitExp match up before most recent dateobs of chunk 1876 2086 #be careful here, since dateobs is not quite completely the same in both tables. Therefore, allow numbers to be off by 1 … … 1890 2100 $rawdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/; 1891 2101 my $date1=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC"); 1892 2102 1893 2103 $summitdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/; 1894 2104 my $date2=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC"); … … 1903 2113 if (($summittimediff > 10.)||($noff >10)) { 1904 2114 if ($debug == 1) { 1905 print STDERR "desp_diff_queue: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n";2115 print STDERR "desp_diff_queue: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n"; 1906 2116 } 1907 2117 } 1908 2118 else { 1909 2119 foreach my $object_row (@{ $object_ref }) { 1910 my $this_object = shift @{ $object_row }; 1911 my $this_chunk = shift @{ $object_row }; 1912 1913 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM "; 1914 $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) "; 1915 $input_sth .= " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 1916 $input_sth .= " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs "; 1917 1918 my $warps = $db->selectall_arrayref( $input_sth ); 1919 1920 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra. 1921 my %comment_hash = (); 1922 foreach my $this_warp (@{ $warps }) { 1923 my $this_comment = ${ $this_warp }[3]; 1924 my $this_exp_id = ${ $this_warp }[0]; 1925 my $this_quality = ${ $this_warp }[5]; 1926 my $this_state = ${ $this_warp }[4]; 1927 if (($this_quality != 0) || ($this_state eq 'drop') ) { 1928 print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n"; 1929 } 1930 else { 1931 $comment_hash{$this_comment} = $this_exp_id; 1932 } 1933 } 1934 # Exclude any warps that are not stored in the comment_hash. 1935 my @keep_warps = (); 1936 foreach my $this_warp (@{ $warps }) { 1937 my $this_comment = ${ $this_warp }[3]; 1938 my $this_exp_id = ${ $this_warp }[0]; 1939 if ((exists($comment_hash{$this_comment}))&& 1940 ($comment_hash{$this_comment} == $this_exp_id)) { 1941 push @keep_warps, $this_warp; 1942 } 1943 else { 1944 print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n"; 1945 } 1946 } 1947 # We are attempting to do the missing diffs, so reverse the list of retained warps. 1948 # Good objects with all visits will be skipped due to the duplicate check. 1949 # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs. 1950 @{ $warps } = reverse @keep_warps; 1951 1952 # Exclude the last entry if we do not have an even number of warps. 1953 if (($#{ $warps } + 1) % 2 != 0) { 1954 print STDERR "desp_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } "; 1955 if ($#{ $warps} + 1 == 1) { 1956 print STDERR ": I can do no diffs with only one exposure.\n"; 1957 next; 1958 } 1959 else { 1960 my $rejected_warp = pop @{ $warps }; 1961 my $rejected_exp_id = ${ $rejected_warp }[0]; 1962 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 1963 } 1964 } 1965 1966 while ($#{ $warps } > -1) { 1967 # In this mode, the array is sorted in pairs of template/input, counter to the standard queue. 1968 my $template_warp = shift @{ $warps }; 1969 my $input_warp = shift @{ $warps }; 1970 1971 my $input_exp_id = ${ $input_warp }[0]; 1972 my $input_comment = ${ $input_warp }[3]; 1973 1974 my $template_exp_id = ${ $template_warp }[0]; 1975 my $template_comment = ${ $template_warp }[3]; 1976 1977 my $input_warp_id = ${ $input_warp }[1]; 1978 my $template_warp_id = ${ $template_warp }[1]; 1979 1980 my $input_warp_state = ${ $input_warp }[4]; 1981 my $template_warp_state = ${ $template_warp }[4]; 1982 1983 my $input_warp_camQuality = ${ $input_warp }[5]; 1984 my $template_warp_camQuality = ${ $template_warp }[5]; 1985 1986 $Npotential++; 1987 1988 unless (defined($input_warp_id) && defined($template_warp_id) && 1989 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 1990 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"; 1991 if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 1992 # This should now never be reached. 1993 # CZW: Trigger backup plan here? Or simply set up framework? 1994 print STDERR " ...but this is due to a camera stage astrometry quality\n"; 1995 $Npotential--; 1996 } 1997 next; 1998 } 1999 2000 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 2001 $Nqueued++; 2002 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"; 2003 next; 2004 } 2005 else { 2006 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"; 2007 } 2120 my $this_object = shift @{ $object_row }; 2121 my $this_chunk = shift @{ $object_row }; 2122 2123 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality,camProcessedExp.fwhm_major FROM "; 2124 $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) "; 2125 $input_sth .= " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 2126 $input_sth .= " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs "; 2127 2128 my $warps = $db->selectall_arrayref( $input_sth ); 2129 my $warpsBQ = $db->selectall_arrayref( $input_sth );; 2130 2131 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra. 2132 my %comment_hash = (); 2133 my %comment_hash_good = (); 2134 foreach my $this_warp (@{ $warps }) { 2135 my $this_comment = ${ $this_warp }[3]; 2136 my $this_exp_id = ${ $this_warp }[0]; 2137 my $this_quality = ${ $this_warp }[5]; 2138 my $this_state = ${ $this_warp }[4]; 2139 my $this_fwhm = ${ $this_warp }[7]; 2140 if (($this_quality != 0) || ($this_state eq 'drop') || ($this_fwhm > $maxFWHM)) { 2141 print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state or FWHM $this_fwhm\n"; 2142 } 2143 else { 2144 $comment_hash_good{$this_comment} = $this_exp_id; 2145 } 2146 2147 #also save the entries which are ok, but not best quality 2148 if (($this_quality == 0) && ($this_state ne 'drop') ) { 2149 $comment_hash{$this_comment} = $this_exp_id; 2150 } 2151 } 2152 2153 # Exclude any warps that are not stored in the comment_hash_good. 2154 my @keep_warps = (); 2155 foreach my $this_warp (@{ $warps }) { 2156 my $this_comment = ${ $this_warp }[3]; 2157 my $this_exp_id = ${ $this_warp }[0]; 2158 if ((exists($comment_hash_good{$this_comment}))&& 2159 ($comment_hash_good{$this_comment} == $this_exp_id)) { 2160 push @keep_warps, $this_warp; 2161 my $this_date = ${ $this_warp }[2]; 2162 my $chunk_name = ${ $this_warp }[6]; 2163 } 2164 else { 2165 print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to being rejected $this_comment\n"; 2166 } 2167 } 2168 @{ $warps } = @keep_warps; 2169 my $nwarps = ($#{ $warps } + 1); 2170 2171 ################################ 2172 #We reach a junction here, where having more than 3 (but uneven) warps will result in desperate diffs 2173 #Conversely, less than 3 warps might result in dirty diffs 2174 ################################ 2175 if($nwarps >= 3) { 2176 # We are attempting to do the missing diffs, so reverse the list of retained warps. 2177 # Good objects with all visits will be skipped due to the duplicate check. 2178 # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs. 2179 @{ $warps } = reverse @keep_warps; 2180 2181 # Exclude the last entry if we do not have an even number of warps. 2182 if (($#{ $warps } + 1) % 2 != 0) { 2183 print STDERR "desp_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } "; 2184 if ($#{ $warps} + 1 == 1) { 2185 print STDERR ": I can do no diffs with only one exposure.\n"; 2186 next; 2187 } 2188 else { 2189 my $rejected_warp = pop @{ $warps }; 2190 my $rejected_exp_id = ${ $rejected_warp }[0]; 2191 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 2192 } 2193 } 2194 2195 while ($#{ $warps } > -1) { 2196 # The array is sorted in pairs of input/template. 2197 my $template_warp = shift @{ $warps }; 2198 my $input_warp = shift @{ $warps }; 2199 2200 my $input_exp_id = ${ $input_warp }[0]; 2201 my $input_comment = ${ $input_warp }[3]; 2202 2203 my $template_exp_id = ${ $template_warp }[0]; 2204 my $template_comment = ${ $template_warp }[3]; 2205 2206 my $input_warp_id = ${ $input_warp }[1]; 2207 my $template_warp_id = ${ $template_warp }[1]; 2208 2209 my $input_warp_state = ${ $input_warp }[4]; 2210 my $template_warp_state = ${ $template_warp }[4]; 2211 2212 my $input_warp_camQuality = ${ $input_warp }[5]; 2213 my $template_warp_camQuality = ${ $template_warp }[5]; 2214 2215 $Npotential++; 2216 2217 unless (defined($input_warp_id) && defined($template_warp_id) && 2218 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 2219 print STDERR "Desp 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"; 2220 if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 2221 # This should now never be reached. 2222 # CZW: Trigger backup plan here? Or simply set up framework? 2223 print STDERR " ...but this is due to a camera stage astrometry quality\n"; 2224 $Npotential--; 2225 } 2226 next; 2227 } 2228 2229 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 2230 $Nqueued++; 2231 print STDERR "Desp 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"; 2232 next; 2233 } 2234 else { 2235 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"; 2236 } 2237 2238 my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 2239 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 2240 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 2241 $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures 2242 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group "; 2243 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 2244 if (defined($reduction)) { 2245 $cmd .= " -set_reduction $reduction "; 2246 } 2247 2248 if (defined($pretend)) { 2249 $cmd .= ' -pretend '; 2250 } 2251 if ($debug == 1) { 2252 $cmd .= ' -pretend '; 2253 print STDERR "desp_diff_queue: $cmd\n"; 2254 print STDERR " $input_warp_id $template_warp_id\n"; 2255 } 2256 2257 if (($debug == 0)&&(!defined($pretend))) { 2258 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2259 run ( command => $cmd, verbose => $verbose ); 2260 unless ($success) { 2261 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2262 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2263 } 2264 $Nqueued++; 2265 } 2266 } 2267 2268 } else { 2269 print STDERR "desp_diff_queue: There is a possibility for dirty diffs to be made\n"; 2270 #Consider the case of on-the-fly dirty desperate diffs 2271 #The conditions are: uneven nr of bad quality warps greater than 3, and the most recent observations is more than $desdiffdt hours old 2272 2273 # # Exclude any warps that are not stored in the more general comment_hash. 2274 # my @keep_warps = (); 2275 # foreach my $this_warp (@{ $warpsBQ }) { 2276 # my $this_comment = ${ $this_warp }[3]; 2277 # my $this_exp_id = ${ $this_warp }[0]; 2278 # if ((exists($comment_hash{$this_comment}))&& 2279 # ($comment_hash{$this_comment} == $this_exp_id)) { 2280 # push @keep_warps, $this_warp; 2281 # my $this_date = ${ $this_warp }[2]; 2282 # my $chunk_name = ${ $this_warp }[6]; 2283 # } 2284 # else { 2285 # print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to being rejected $this_comment\n"; 2286 # } 2287 # } 2288 # @{ $warpsBQ } = @keep_warps; 2289 # 2290 # if ($nwarps >= 2) { 2291 # #one regular diff has already been made. So, need only one more. Strip a good entry from the array 2292 # my $nrem = 0; 2293 # my @keep_warps = (); 2294 # foreach my $this_warp (@{ $warpsBQ }) { 2295 # my $this_comment = ${ $this_warp }[3]; 2296 # my $this_exp_id = ${ $this_warp }[0]; 2297 # my $this_fwhm = ${ $this_warp }[7]; 2298 # if (($nrem <1) && ($this_fwhm <= $maxFWHM)) { 2299 # $nrem++; 2300 # print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object from dirty desp diffs $this_comment\n"; 2301 # } else { 2302 # push @keep_warps, $this_warp; 2303 # } 2304 # } 2305 # @{ $warpsBQ } = @keep_warps; 2306 # } 2307 # 2308 # # We are attempting to do the missing diffs, so reverse the list of retained warps. 2309 # # Good objects with all visits will be skipped due to the duplicate check. 2310 # # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs. 2311 # @{ $warpsBQ } = reverse @{ $warpsBQ }; 2312 # 2313 # # Exclude the last entry if we do not have an even number of warps. 2314 # if (($#{ $warpsBQ } + 1) % 2 != 0) { 2315 # print STDERR "desp_diff_queue: Number of input warps to make dirty diffs is not even for target $target and object $this_object!"; 2316 # my $rejected_warp = pop @{ $warpsBQ }; 2317 # my $rejected_exp_id = ${ $rejected_warp }[0]; 2318 # print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n"; 2319 # } 2320 # my $nwarpsBQ = ($#{$warpsBQ} + 1); 2321 # 2322 # 2323 # while ($#{ $warpsBQ } > -1) { 2324 # # The array is sorted in pairs of input/template. 2325 # my $template_warp = shift @{ $warpsBQ }; 2326 # my $input_warp = shift @{ $warpsBQ }; 2327 # 2328 # my $input_exp_id = ${ $input_warp }[0]; 2329 # my $input_comment = ${ $input_warp }[3]; 2330 # 2331 # my $template_exp_id = ${ $template_warp }[0]; 2332 # my $template_comment = ${ $template_warp }[3]; 2333 # 2334 # my $input_warp_id = ${ $input_warp }[1]; 2335 # my $template_warp_id = ${ $template_warp }[1]; 2336 # 2337 # my $input_warp_state = ${ $input_warp }[4]; 2338 # my $template_warp_state = ${ $template_warp }[4]; 2339 # 2340 # my $input_warp_camQuality = ${ $input_warp }[5]; 2341 # my $template_warp_camQuality = ${ $template_warp }[5]; 2342 # 2343 # $Npotential++; 2344 # 2345 # unless (defined($input_warp_id) && defined($template_warp_id) && 2346 # ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 2347 # print STDERR "Desp 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"; 2348 # if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) { 2349 # # This should now never be reached. 2350 # # CZW: Trigger backup plan here? Or simply set up framework? 2351 # print STDERR " ...but this is due to a camera stage astrometry quality\n"; 2352 # $Npotential--; 2353 # } 2354 # next; 2355 # } 2356 # 2357 # if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 2358 # $Nqueued++; 2359 # print STDERR "Desp 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"; 2360 # next; 2361 # } 2362 # else { 2363 # print STDERR "Preparing to dirty diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n"; 2364 # } 2365 # 2366 # my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 2367 # $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 2368 # $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 2369 # $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures 2370 # $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group "; 2371 # $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 2372 # if (defined($reduction)) { 2373 # $cmd .= " -set_reduction $reduction "; 2374 # } 2375 # 2376 # if (defined($pretend)) { 2377 # $cmd .= ' -pretend '; 2378 # } 2379 # if ($debug == 1) { 2380 # $cmd .= ' -pretend '; 2381 # print STDERR "desp_diff_queue: $cmd\n"; 2382 # print STDERR " $input_warp_id $template_warp_id\n"; 2383 # } 2384 # 2385 # if (($debug == 0)&&(!defined($pretend))) { 2386 # my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2387 # run ( command => $cmd, verbose => $verbose ); 2388 # unless ($success) { 2389 # $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2390 # &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2391 # } 2392 # $Nqueued++; 2393 # } 2394 # } 2008 2395 2009 my $cmd = "$difftool -dbname $dbname -definewarpwarp ";2010 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 ";2011 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.2012 $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures2013 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $data_group ";2014 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";2015 # $cmd .= " -pretend ";2016 if (defined($reduction)) {2017 $cmd .= " -set_reduction $reduction ";2018 }2019 2020 if (defined($pretend)) {2021 $cmd .= ' -pretend ';2022 }2023 if ($debug == 1) {2024 $cmd .= ' -pretend ';2025 print STDERR "desp_diff_queue: $cmd\n";2026 print STDERR " $input_warp_id $template_warp_id\n";2027 }2028 2396 2029 if (($debug == 0)&&(!defined($pretend))) { 2030 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2031 run ( command => $cmd, verbose => $verbose ); 2032 unless ($success) { 2033 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2034 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2035 } 2036 $Nqueued++; 2037 } 2038 } 2397 2398 } 2039 2399 } 2040 2400 } 2041 2401 $metadata_out{nsDiffPotential} += $Npotential; 2042 2402 $metadata_out{nsDiffQueued} += $Nqueued; 2043 # if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) {2044 # $metadata_out{nsDiffState} = 'FINISHED_DIFFS';2045 # }2046 2047 2403 } 2048 2404 … … 2064 2420 my $Npotential = 0; 2065 2421 my $Nqueued = 0; 2066 2422 2067 2423 foreach my $object_row (@{ $object_ref }) { 2068 my $this_object = shift @{ $object_row };2069 # my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";2070 # $input_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";2071 # $input_sth .= " ORDER BY dateobs ";2072 2073 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state FROM ";2074 $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) ";2075 $input_sth .= " WHERE warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";2076 $input_sth .= " ORDER BY dateobs ";2077 2078 my $warps = $db->selectall_arrayref( $input_sth );2079 2080 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.2081 my %comment_hash = ();2082 foreach my $this_warp (@{ $warps }) {2083 my $this_comment = ${ $this_warp }[3];2084 my $this_exp_id = ${ $this_warp }[0];2085 $comment_hash{$this_comment} = $this_exp_id;2086 }2087 2088 if (($#{ $warps } + 1) % 2 != 0) {2089 print STDERR "md_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";2090 if ($#{ $warps} + 1 == 1) {2091 print STDERR ": I can do no diffs with only one exposure.\n";2092 next;2093 }2094 else {2095 print STDERR ": I should declare an exposure to be faulty.\n";2096 my @keep_warps = ();2097 # print "@{ $warps }\n";2098 foreach my $this_warp (@{ $warps }) {2099 my $this_comment = ${ $this_warp }[3];2100 my $this_exp_id = ${ $this_warp }[0];2101 if ($comment_hash{$this_comment} == $this_exp_id) {2102 push @keep_warps, $this_warp;2103 }2104 else {2105 print STDERR "md_diff_queue: excluding $this_exp_id for $this_object\n";2106 }2107 }2108 @{ $warps } = @keep_warps;2109 # print "@{ $warps }\n";2110 }2111 }2112 2113 while ($#{ $warps } > -1) {2114 my $input_warp = shift @{ $warps };2115 my $input_exp_id = ${ $input_warp }[0];2116 my $input_comment = ${ $input_warp }[3];2117 2118 2119 my $template_warp = shift @{ $warps };2120 2121 my $template_exp_id = ${ $template_warp }[0];2122 2123 my $input_warp_id = ${ $input_warp }[1];2124 my $template_warp_id = ${ $template_warp }[1];2125 2126 my $input_warp_state = ${ $input_warp }[4];2127 my $template_warp_state = ${ $template_warp }[4];2128 2129 unless(defined($template_warp)&& defined($template_exp_id)) {2130 print STDERR "md_diff received an undef! $input_exp_id $input_comment $this_object T: $template_warp V: @$template_warp\n";2131 next;2132 }2133 $Npotential++;2134 2135 unless (defined($input_warp_id) && defined($template_warp_id) &&2136 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {2137 print STDERR "md_Diff for this $date $target $input_exp_id ($input_warp_id $input_warp_state) $template_exp_id ($template_warp_id $template_warp_state) not fully processed\n";2138 next;2139 }2140 2141 if (multi_date_verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {2142 $Nqueued++;2143 print STDERR "md_Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";2144 next;2145 }2146 2147 my $new_data_group = "${data_group}.multi";2148 my $cmd = "$difftool -dbname $dbname -definewarpwarp ";2149 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 ";2150 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.2151 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $new_data_group ";2152 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";2153 if (defined($reduction)) {2154 $cmd .= " -set_reduction $reduction ";2155 }2156 2157 # $cmd .= " -pretend ";2158 if (defined($pretend)) {2159 $cmd .= ' -pretend ';2160 }2161 if ($debug == 1) {2162 $cmd .= ' -pretend ';2163 print STDERR "md_Diffs would like to queue for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";2164 print STDERR "md_diff_queue: $cmd\n";2165 print STDERR " $input_warp_id $template_warp_id\n";2166 }2167 2168 if (($debug == 0)&&(!defined($pretend))) {2169 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =2170 run ( command => $cmd, verbose => $verbose );2171 unless ($success) {2172 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);2173 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);2174 }2175 $Nqueued++;2176 }2177 }2424 my $this_object = shift @{ $object_row }; 2425 # my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) "; 2426 # $input_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 2427 # $input_sth .= " ORDER BY dateobs "; 2428 2429 my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state FROM "; 2430 $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) "; 2431 $input_sth .= " WHERE warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' "; 2432 $input_sth .= " ORDER BY dateobs "; 2433 2434 my $warps = $db->selectall_arrayref( $input_sth ); 2435 2436 # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra. 2437 my %comment_hash = (); 2438 foreach my $this_warp (@{ $warps }) { 2439 my $this_comment = ${ $this_warp }[3]; 2440 my $this_exp_id = ${ $this_warp }[0]; 2441 $comment_hash{$this_comment} = $this_exp_id; 2442 } 2443 2444 if (($#{ $warps } + 1) % 2 != 0) { 2445 print STDERR "md_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } "; 2446 if ($#{ $warps} + 1 == 1) { 2447 print STDERR ": I can do no diffs with only one exposure.\n"; 2448 next; 2449 } 2450 else { 2451 print STDERR ": I should declare an exposure to be faulty.\n"; 2452 my @keep_warps = (); 2453 # print "@{ $warps }\n"; 2454 foreach my $this_warp (@{ $warps }) { 2455 my $this_comment = ${ $this_warp }[3]; 2456 my $this_exp_id = ${ $this_warp }[0]; 2457 if ($comment_hash{$this_comment} == $this_exp_id) { 2458 push @keep_warps, $this_warp; 2459 } 2460 else { 2461 print STDERR "md_diff_queue: excluding $this_exp_id for $this_object\n"; 2462 } 2463 } 2464 @{ $warps } = @keep_warps; 2465 # print "@{ $warps }\n"; 2466 } 2467 } 2468 2469 while ($#{ $warps } > -1) { 2470 my $input_warp = shift @{ $warps }; 2471 my $input_exp_id = ${ $input_warp }[0]; 2472 my $input_comment = ${ $input_warp }[3]; 2473 2474 2475 my $template_warp = shift @{ $warps }; 2476 2477 my $template_exp_id = ${ $template_warp }[0]; 2478 2479 my $input_warp_id = ${ $input_warp }[1]; 2480 my $template_warp_id = ${ $template_warp }[1]; 2481 2482 my $input_warp_state = ${ $input_warp }[4]; 2483 my $template_warp_state = ${ $template_warp }[4]; 2484 2485 unless(defined($template_warp)&& defined($template_exp_id)) { 2486 print STDERR "md_diff received an undef! $input_exp_id $input_comment $this_object T: $template_warp V: @$template_warp\n"; 2487 next; 2488 } 2489 $Npotential++; 2490 2491 unless (defined($input_warp_id) && defined($template_warp_id) && 2492 ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) { 2493 print STDERR "md_Diff for this $date $target $input_exp_id ($input_warp_id $input_warp_state) $template_exp_id ($template_warp_id $template_warp_state) not fully processed\n"; 2494 next; 2495 } 2496 2497 if (multi_date_verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) { 2498 $Nqueued++; 2499 print STDERR "md_Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n"; 2500 next; 2501 } 2502 2503 my $new_data_group = "${data_group}.multi"; 2504 my $cmd = "$difftool -dbname $dbname -definewarpwarp "; 2505 $cmd .= "-input_label $label -template_label $label -good_frac 0.1 "; 2506 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting. 2507 $cmd .= "-set_workdir $workdir -set_dist_group $dist_group -set_data_group $new_data_group "; 2508 $cmd .= " -simple -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id "; 2509 if (defined($reduction)) { 2510 $cmd .= " -set_reduction $reduction "; 2511 } 2512 2513 # $cmd .= " -pretend "; 2514 if (defined($pretend)) { 2515 $cmd .= ' -pretend '; 2516 } 2517 if ($debug == 1) { 2518 $cmd .= ' -pretend '; 2519 print STDERR "md_Diffs would like to queue for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n"; 2520 print STDERR "md_diff_queue: $cmd\n"; 2521 print STDERR " $input_warp_id $template_warp_id\n"; 2522 } 2523 2524 if (($debug == 0)&&(!defined($pretend))) { 2525 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2526 run ( command => $cmd, verbose => $verbose ); 2527 unless ($success) { 2528 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2529 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2530 } 2531 $Nqueued++; 2532 } 2533 } 2178 2534 } 2179 2535 $metadata_out{nsDiffPotential} += $Npotential; 2180 2536 $metadata_out{nsDiffQueued} += $Nqueued; 2181 2537 # if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) { 2182 # $metadata_out{nsDiffState} = 'FINISHED_DIFFS';2183 # } 2538 # $metadata_out{nsDiffState} = 'FINISHED_DIFFS'; 2539 # } 2184 2540 2185 2541 } … … 2200 2556 2201 2557 2202 # Get a list of exposures that could be diffed 2558 # Get a list of exposures that could be diffed 2203 2559 my $new_data_group = "${data_group}.offnight"; 2204 2560 my $new_dist_group = "${dist_group}.offnight"; … … 2210 2566 $check_cmd .= " -dateobs_begin ${lunation_start}T00:00:00 -dateobs_end ${lunation_end}T23:59:59 -distance 1.5 "; 2211 2567 if (defined($reduction)) { 2212 $check_cmd .= " -set_reduction $reduction ";2568 $check_cmd .= " -set_reduction $reduction "; 2213 2569 } 2214 2570 2215 2571 my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2216 run ( command => $check_cmd, verbose => $verbose );2572 run ( command => $check_cmd, verbose => $verbose ); 2217 2573 unless ($success) { 2218 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);2219 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);2220 } 2221 2574 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2575 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2576 } 2577 2222 2578 # Parse results 2223 2579 my $diffs = $mdcParser->parse_list(join "", @$stdout_buf) or 2224 &my_die("Unable to parse metadata from difftool -definewarpwarp", 0, 0, $date, $PS_EXIT_PROG_ERROR);2580 &my_die("Unable to parse metadata from difftool -definewarpwarp", 0, 0, $date, $PS_EXIT_PROG_ERROR); 2225 2581 foreach my $diff (@$diffs) { 2226 unless (multi_date_verify_uniqueness_diff($diff->{input_warp_id},$diff->{template_warp_id},$date,$target)) {2227 # If we don't already have a diff with these inputs, make a diff with these inputs.2228 my $cmd = "$difftool -dbname $dbname -definewarpwarp -good_frac 0.1 ";2229 $cmd .= "-input_label $label -template_label $label ";2230 $cmd .= "-warp_id $diff->{input_warp_id} -template_warp_id $diff->{template_warp_id} ";2231 $cmd .= "-set_workdir $workdir -set_dist_group $new_dist_group -set_data_group $new_data_group ";2232 $cmd .= " -mintimediff 40000 ";2233 $cmd .= " -simple -rerun -set_label $label -filter $filter ";2234 $cmd .= " -dateobs_begin ${lunation_start}T00:00:00 -dateobs_end ${lunation_end}T23:59:59 -distance 1.5 ";2235 if (defined($reduction)) {2236 $cmd .= " -set_reduction $reduction ";2237 }2238 2239 if (defined($pretend)) {2240 $cmd .= ' -pretend ';2241 }2242 print STDERR "ON_diffs wants to run this command: $cmd\n";2243 2244 if (($debug == 0)&&(!defined($pretend))) {2245 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =2246 run ( command => $cmd, verbose => $verbose );2247 unless ($success) {2248 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);2249 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);2250 }2251 }2252 }2582 unless (multi_date_verify_uniqueness_diff($diff->{input_warp_id},$diff->{template_warp_id},$date,$target)) { 2583 # If we don't already have a diff with these inputs, make a diff with these inputs. 2584 my $cmd = "$difftool -dbname $dbname -definewarpwarp -good_frac 0.1 "; 2585 $cmd .= "-input_label $label -template_label $label "; 2586 $cmd .= "-warp_id $diff->{input_warp_id} -template_warp_id $diff->{template_warp_id} "; 2587 $cmd .= "-set_workdir $workdir -set_dist_group $new_dist_group -set_data_group $new_data_group "; 2588 $cmd .= " -mintimediff 40000 "; 2589 $cmd .= " -simple -rerun -set_label $label -filter $filter "; 2590 $cmd .= " -dateobs_begin ${lunation_start}T00:00:00 -dateobs_end ${lunation_end}T23:59:59 -distance 1.5 "; 2591 if (defined($reduction)) { 2592 $cmd .= " -set_reduction $reduction "; 2593 } 2594 2595 if (defined($pretend)) { 2596 $cmd .= ' -pretend '; 2597 } 2598 print STDERR "ON_diffs wants to run this command: $cmd\n"; 2599 2600 if (($debug == 0)&&(!defined($pretend))) { 2601 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2602 run ( command => $cmd, verbose => $verbose ); 2603 unless ($success) { 2604 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2605 &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2606 } 2607 } 2608 } 2253 2609 } 2254 2610 } … … 2264 2620 my ($stacks_to_finish,$stacks_total) = check_stack_count($label); 2265 2621 if (($stacks_to_finish == 0)&&($stacks_total != 0)) { 2266 my $cmd = "$difftool -dbname $dbname -definewarpstack ";2267 $cmd .= " -good_frac 0.2 ";2268 $cmd .= " -warp_label $label -stack_label $label -set_label $label ";2269 $cmd .= " -set_workdir $workdir -available -set_reduction WARPSTACK -set_dist_group $dist_group ";2270 $cmd .= " -rerun ";2271 } 2272 } 2622 my $cmd = "$difftool -dbname $dbname -definewarpstack "; 2623 $cmd .= " -good_frac 0.2 "; 2624 $cmd .= " -warp_label $label -stack_label $label -set_label $label "; 2625 $cmd .= " -set_workdir $workdir -available -set_reduction WARPSTACK -set_dist_group $dist_group "; 2626 $cmd .= " -rerun "; 2627 } 2628 } 2273 2629 2274 2630 sub check_stack_count { … … 2301 2657 my $retention_time; 2302 2658 if (exists($science_config{$target}{$mode})) { 2303 $retention_time = $science_config{$target}{$mode};2659 $retention_time = $science_config{$target}{$mode}; 2304 2660 } 2305 2661 else { 2306 $retention_time = $clean_config{$mode}{RETENTION_TIME};2662 $retention_time = $clean_config{$mode}{RETENTION_TIME}; 2307 2663 } 2308 2664 if ($retention_time <= 0) { 2309 return("no clean","true");2665 return("no clean","true"); 2310 2666 } 2311 2667 2312 2668 my ($year,$month,$day) = split /-/,$date; 2313 2669 my $dt = DateTime->new(year => $year, month => $month, day => $day, 2314 hour => 0, minute => 0, second => 0, nanosecond => 0,2315 time_zone => 'Pacific/Honolulu');2316 2670 hour => 0, minute => 0, second => 0, nanosecond => 0, 2671 time_zone => 'Pacific/Honolulu'); 2672 2317 2673 $dt->subtract(days => $retention_time); 2318 2674 my $cleaning_date = $dt->ymd; 2319 2675 2320 2676 my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($cleaning_date,$target); 2321 2677 2322 2678 $command =~ s/\@DBNAME\@/$dbname/; 2323 2679 $command =~ s/\@LABEL\@/$label/; … … 2330 2686 $command =~ s/\@REDUCTION\@/$reduction/; 2331 2687 $command =~ s/\@CURRENT_DATE\@/$cleaning_date/; 2332 2688 2333 2689 if ($debug == 1) { 2334 2690 $command .= ' -pretend '; … … 2342 2698 2343 2699 foreach my $mode (sort (keys %clean_config)) { 2344 foreach my $target (sort (keys %science_config)) {2345 if (exists($science_config{$target}{NOCLEAN})) {2346 next;2347 }2348 my ($cleaning_date,$command) = construct_cleantool_args($date,$target,$mode);2349 2350 if ($cleaning_date eq 'no clean') {2351 next;2352 } 2353 print STDERR "$command\n";2354 if (!(defined($pretend) || $debug == 1)) {2700 foreach my $target (sort (keys %science_config)) { 2701 if (exists($science_config{$target}{NOCLEAN})) { 2702 next; 2703 } 2704 my ($cleaning_date,$command) = construct_cleantool_args($date,$target,$mode); 2705 2706 if ($cleaning_date eq 'no clean') { 2707 next; 2708 } 2709 print STDERR "$command\n"; 2710 if (!(defined($pretend) || $debug == 1)) { 2355 2711 # print STDERR "BEAR IS DRIVING!?\n"; 2356 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =2357 run ( command => $command, verbose => $verbose );2358 unless ($success) {2359 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);2360 &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);2361 }2362 add_to_macro_list('clean_old',1,$date,$target,$mode);2363 }2364 if ($mode eq 'DIFF') {2365 my $WS_command = $command;2366 $WS_command =~ s/$target/${target}.WS/;2367 print STDERR "$WS_command\n";2368 if (!(defined($pretend) || $debug == 1)) {2369 2370 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =2371 run ( command => $WS_command, verbose => $verbose );2372 unless ($success) {2373 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);2374 &my_die("Unable to perform cleantool ($WS_command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);2375 }2376 }2377 }2378 2379 }2712 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2713 run ( command => $command, verbose => $verbose ); 2714 unless ($success) { 2715 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2716 &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2717 } 2718 add_to_macro_list('clean_old',1,$date,$target,$mode); 2719 } 2720 if ($mode eq 'DIFF') { 2721 my $WS_command = $command; 2722 $WS_command =~ s/$target/${target}.WS/; 2723 print STDERR "$WS_command\n"; 2724 if (!(defined($pretend) || $debug == 1)) { 2725 2726 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2727 run ( command => $WS_command, verbose => $verbose ); 2728 unless ($success) { 2729 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2730 &my_die("Unable to perform cleantool ($WS_command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2731 } 2732 } 2733 } 2734 2735 } 2380 2736 } 2381 2737 return(0); … … 2389 2745 my $date = shift; 2390 2746 my $eon_dt = DateTime->new( year => $datetime->year, 2391 month => $datetime->month,2392 day => $datetime->day,2393 hour => 17, # 7,2394 minute => 30,2395 second => 0,2396 time_zone => 'UTC');2397 2747 month => $datetime->month, 2748 day => $datetime->day, 2749 hour => 17, # 7, 2750 minute => 30, 2751 second => 0, 2752 time_zone => 'UTC'); 2753 2398 2754 foreach my $eon (keys %eon_config) { 2399 my $command = "$regtool -processedexp -simple ";2400 $command .= " -dbname $dbname ";2401 $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";2402 $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT});2403 $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE});2404 $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE});2405 $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT});2406 2407 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =2408 run ( command => $command, verbose => $verbose );2409 unless ($success) {2410 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);2411 &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);2412 }2413 my @eon_exposures = split /\n/, (join '', @$stdout_buf);2414 if ($#eon_exposures >= 0) {2415 return("END_OF_NIGHT");2416 }2417 } 2755 my $command = "$regtool -processedexp -simple "; 2756 $command .= " -dbname $dbname "; 2757 $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 "; 2758 $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT}); 2759 $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE}); 2760 $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE}); 2761 $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT}); 2762 2763 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2764 run ( command => $command, verbose => $verbose ); 2765 unless ($success) { 2766 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2767 &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2768 } 2769 my @eon_exposures = split /\n/, (join '', @$stdout_buf); 2770 if ($#eon_exposures >= 0) { 2771 return("END_OF_NIGHT"); 2772 } 2773 } 2418 2774 if ($force_registration) { 2419 return("END_OF_NIGHT");2775 return("END_OF_NIGHT"); 2420 2776 } 2421 2777 # print "$now $eon_dt " . DateTime->compare($now,$eon_dt) . "\n"; 2422 2778 if (DateTime->compare($now,$eon_dt) < 1) { 2423 return("OBSERVING");2779 return("OBSERVING"); 2424 2780 } 2425 2781 else { 2426 return("END_OF_NIGHT");2782 return("END_OF_NIGHT"); 2427 2783 } 2428 2784 } … … 2433 2789 2434 2790 foreach my $eon (keys %eon_config) { 2435 my $command = "$regtool -processedexp -simple ";2436 $command .= " -dbname $dbname ";2437 $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";2438 $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT});2439 $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE});2440 $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE});2441 $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT});2442 2443 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =2444 run ( command => $command, verbose => $verbose );2445 unless ($success) {2446 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);2447 &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);2448 }2449 my @eon_exposures = split /\n/, (join '', @$stdout_buf);2450 if ($#eon_exposures >= 0) {2451 return("REGISTERED");2452 }2453 } 2791 my $command = "$regtool -processedexp -simple "; 2792 $command .= " -dbname $dbname "; 2793 $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 "; 2794 $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT}); 2795 $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE}); 2796 $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE}); 2797 $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT}); 2798 2799 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 2800 run ( command => $command, verbose => $verbose ); 2801 unless ($success) { 2802 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 2803 &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR); 2804 } 2805 my @eon_exposures = split /\n/, (join '', @$stdout_buf); 2806 if ($#eon_exposures >= 0) { 2807 return("REGISTERED"); 2808 } 2809 } 2454 2810 return("NOT_REGISTERED"); 2455 2811 } 2456 2812 2457 2813 2458 2814 2459 2815 sub get_tool_parameters { … … 2489 2845 my $internal_filter; 2490 2846 if (defined($det_filter)) { 2491 $internal_filter = $det_filter; $internal_filter =~ s/\..*//;2492 $internal_filter = '.' . $internal_filter;2847 $internal_filter = $det_filter; $internal_filter =~ s/\..*//; 2848 $internal_filter = '.' . $internal_filter; 2493 2849 } 2494 2850 else { 2495 $internal_filter = '';2851 $internal_filter = ''; 2496 2852 } 2497 2853 unless (defined($maxN)) { 2498 $maxN = 0;2854 $maxN = 0; 2499 2855 } 2500 2856 my $lc_type = lc($exp_type); … … 2512 2868 2513 2869 if ((defined($macro_config{$proc_mode}))&&($do_or_do_not)) { 2514 unless (defined($metadata_out{N_MACROS})) {2515 $metadata_out{N_MACROS} = 0;2516 }2517 my $N = $metadata_out{N_MACROS};2518 $metadata_out{"ns${N}Macro"} = $macro_config{$proc_mode};2519 if ($debug == 1) {2520 print STDERR "WORKING ON A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n";2521 }2522 if (defined($date)&&(defined($target))) {2523 2524 my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction)2525 = get_tool_parameters($date,$target);2526 $metadata_out{"ns${N}Macro"} =~ s/\@LABEL\@/$label/;2527 $metadata_out{"ns${N}Macro"} =~ s/\@WORKDIR\@/$workdir/;2528 $metadata_out{"ns${N}Macro"} =~ s/\@OBSMODE\@/$obs_mode/;2529 $metadata_out{"ns${N}Macro"} =~ s/\@OBJECT\@/$object/;2530 $metadata_out{"ns${N}Macro"} =~ s/\@COMMENT\@/$comment/;2531 $metadata_out{"ns${N}Macro"} =~ s/\@TESS_ID\@/$tess_id/;2532 $metadata_out{"ns${N}Macro"} =~ s/\@DIST_GROUP\@/$dist_group/;2533 $metadata_out{"ns${N}Macro"} =~ s/\@DATA_GROUP\@/$data_group/;2534 $metadata_out{"ns${N}Macro"} =~ s/\@REDUCTION\@/$reduction/;2535 }2536 if (defined($mode)) {2537 $metadata_out{"ns${N}Macro"} =~ s/\@EXTRA\@/$mode/;2538 }2539 if (defined($date)) {2540 $metadata_out{"ns${N}Macro"} =~ s/\@DATE\@/$date/;2541 }2542 if ($debug == 1) {2543 print STDERR "DONE WITH A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n";2544 }2545 $metadata_out{N_MACROS} ++;2870 unless (defined($metadata_out{N_MACROS})) { 2871 $metadata_out{N_MACROS} = 0; 2872 } 2873 my $N = $metadata_out{N_MACROS}; 2874 $metadata_out{"ns${N}Macro"} = $macro_config{$proc_mode}; 2875 if ($debug == 1) { 2876 print STDERR "WORKING ON A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n"; 2877 } 2878 if (defined($date)&&(defined($target))) { 2879 2880 my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) 2881 = get_tool_parameters($date,$target); 2882 $metadata_out{"ns${N}Macro"} =~ s/\@LABEL\@/$label/; 2883 $metadata_out{"ns${N}Macro"} =~ s/\@WORKDIR\@/$workdir/; 2884 $metadata_out{"ns${N}Macro"} =~ s/\@OBSMODE\@/$obs_mode/; 2885 $metadata_out{"ns${N}Macro"} =~ s/\@OBJECT\@/$object/; 2886 $metadata_out{"ns${N}Macro"} =~ s/\@COMMENT\@/$comment/; 2887 $metadata_out{"ns${N}Macro"} =~ s/\@TESS_ID\@/$tess_id/; 2888 $metadata_out{"ns${N}Macro"} =~ s/\@DIST_GROUP\@/$dist_group/; 2889 $metadata_out{"ns${N}Macro"} =~ s/\@DATA_GROUP\@/$data_group/; 2890 $metadata_out{"ns${N}Macro"} =~ s/\@REDUCTION\@/$reduction/; 2891 } 2892 if (defined($mode)) { 2893 $metadata_out{"ns${N}Macro"} =~ s/\@EXTRA\@/$mode/; 2894 } 2895 if (defined($date)) { 2896 $metadata_out{"ns${N}Macro"} =~ s/\@DATE\@/$date/; 2897 } 2898 if ($debug == 1) { 2899 print STDERR "DONE WITH A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n"; 2900 } 2901 $metadata_out{N_MACROS} ++; 2546 2902 } 2547 2903 } -
trunk/ippTools/src/pztoolConfig.c
r42154 r42229 171 171 psMetadataAddStr(updatepzexpArgs, PS_LIST_TAIL, "-set_state", 0, "define new state (required)", NULL); 172 172 173 # if (0) 173 174 // -updatesummitexp 174 175 psMetadata *updatesummitexpArgs = psMetadataAlloc(); … … 178 179 psMetadataAddStr(updatesummitexpArgs, PS_LIST_TAIL, "-telescope", 0, "search by telescope (required)", NULL); 179 180 psMetadataAddS32(updatesummitexpArgs, PS_LIST_TAIL, "-set_fault", 0, "define new fault (required)", 0); 181 # endif 180 182 181 183 // -updatenewexp -
trunk/ippconfig/recipes/psastro.config
r42109 r42229 244 244 # maximum allowed fwhm_major (moved from */camera.config) 245 245 PSASTRO.MAX.ALLOWED.FWHM F32 0 246 PSASTRO.MAX.PROCESS.FWHM F32 30 246 247 247 248 #PSASTRO.CATDIR STR PS1.REF.20140713 -
trunk/ppViz/src/ppCoord/ppCoord.h
r42154 r42229 14 14 psString rawName; // Filename with raw image (or NULL) 15 15 psString pixelsName; // Filename with pixel coordinates 16 psString fpaName; // Filename with FPA coordinates17 16 psString chipName; // Name of chip of interest 18 17 psString radecName; // Filename with sky coordinates -
trunk/ppViz/src/ppCoord/ppCoordArguments.c
r42154 r42229 49 49 psMetadataAddStr(arguments, PS_LIST_TAIL, "-raw", 0, "Filename with raw data", NULL); 50 50 psMetadataAddStr(arguments, PS_LIST_TAIL, "-pixels", 0, "Filename with pixel coordinates", NULL); 51 psMetadataAddStr(arguments, PS_LIST_TAIL, "-fpa", 0, "Filename with FPA coordinates", NULL);52 51 psMetadataAddStr(arguments, PS_LIST_TAIL, "-chip", 0, "Chip for pixel coordinates", NULL); 53 52 psMetadataAddStr(arguments, PS_LIST_TAIL, "-radec", 0, "Filename with RA,Dec (default decimal degrees)", NULL); … … 67 66 data->rawName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-raw")); 68 67 data->pixelsName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-pixels")); 69 data->fpaName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-fpa"));70 68 data->chipName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-chip")); 71 69 data->radecName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-radec")); … … 98 96 } 99 97 100 if (!data->pixelsName && !data->radecName && !data-> fpaName && !data->streaksName && !data->clustersName) {101 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Neither -pixels nor -radec nor -fpaprovided.");98 if (!data->pixelsName && !data->radecName && !data->streaksName && !data->clustersName) { 99 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Neither -pixels nor -radec provided."); 102 100 return false; 103 101 } -
trunk/ppViz/src/ppCoord/ppCoordData.c
r42154 r42229 16 16 psFree(data->rawName); 17 17 psFree(data->pixelsName); 18 psFree(data->fpaName);19 18 psFree(data->chipName); 20 19 psFree(data->radecName); … … 38 37 data->rawName = NULL; 39 38 data->pixelsName = NULL; 40 data->fpaName = NULL;41 39 data->chipName = NULL; 42 40 data->radecName = NULL; -
trunk/ppViz/src/ppCoord/ppCoordLoop.c
r42154 r42229 79 79 NULL; // File with raw image 80 80 81 psArray *pixels = NULL, *radec = NULL, * fpas = NULL, *streaks = NULL, *clusters = NULL; // Array of coordinate vectors82 psArray *radecOut = NULL, *fpaOut = NULL,*streaksOut = NULL, *clustersOut = NULL; // Output for sky coordinates81 psArray *pixels = NULL, *radec = NULL, *streaks = NULL, *clusters = NULL; // Array of coordinate vectors 82 psArray *radecOut = NULL, *streaksOut = NULL, *clustersOut = NULL; // Output for sky coordinates 83 83 if (data->pixelsName) { 84 84 pixels = psVectorsReadFromFile(data->pixelsName, "%f %f"); … … 107 107 psVectorInit(radecOut->data[1], NAN); 108 108 psVectorInit(radecOut->data[2], NAN); 109 }110 111 if (data->fpaName) {112 fpas = psVectorsReadFromFile(data->fpaName, "%f %f");113 if (!fpas || fpas->n != 2) {114 psError(psErrorCodeLast(), false, "Unable to read FPA coordinates");115 return false;116 }117 psVector *fpa_x = fpas->data[0]; // FPA x coordinates118 long num = fpa_x->n; // Number of coordinates119 fpaOut = psArrayAlloc(6);120 fpaOut->data[0] = psArrayAlloc(num);121 fpaOut->data[1] = psVectorAlloc(num, PS_TYPE_F32);122 fpaOut->data[2] = psVectorAlloc(num, PS_TYPE_F32);123 fpaOut->data[3] = psArrayAlloc(num);124 fpaOut->data[4] = psVectorAlloc(num, PS_TYPE_F32);125 fpaOut->data[5] = psVectorAlloc(num, PS_TYPE_F32);126 psVectorInit(fpaOut->data[1], NAN);127 psVectorInit(fpaOut->data[2], NAN);128 psVectorInit(fpaOut->data[4], NAN);129 psVectorInit(fpaOut->data[5], NAN);130 109 } 131 110 … … 415 394 yTP->data.F32[i] = src.tp.y; 416 395 } 417 }418 419 if (fpas) {420 psVector *fpa_x = fpas->data[0], *fpa_y = fpas->data[1]; // FPA coordinates421 long num = fpa_x->n; // Number of coordinates422 423 int numCols = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS1"); // Number of columns424 int numRows = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS2"); // Number of rows425 if (numCols <= 0 || numRows <= 0) {426 psError(psErrorCodeLast(), false, "Unable to read size of chip.");427 return false;428 }429 430 psArray *chipPix = fpaOut->data[0]; // Chip for pixels431 psVector *xPix = fpaOut->data[1]; // x coordinate for pixels432 psVector *yPix = fpaOut->data[2]; // y coordinate for pixels433 psArray *cellPix = fpaOut->data[3]; // Cell for pixels434 psVector *xCell = fpaOut->data[4]; // x coordinate for cell435 psVector *yCell = fpaOut->data[5]; // y coordinate for cell436 437 psPlane *pix = psPlaneAlloc(); // Pixel coordinates on chip438 psPlane *fp = psPlaneAlloc(); // Focal plane coordinates439 440 for (long i = 0; i < num; i++) {441 float x, y; // Pixel coordinates442 fp->x = fpa_x->data.F32[i];443 fp->y = fpa_y->data.F32[i];444 445 psPlaneTransformApply(pix, chip->fromFPA, fp);446 psTrace("ppCoord",2,"fpa2pix tr1: %f %f\n",pix->x,pix->y);447 448 x = pix->x;449 y = pix->y;450 451 if ((x < 0 || x > numCols || y < 0 || y > numRows)) {452 // Not on this chip453 continue;454 }455 456 chipPix->data[i] = psStringCopy(chipName);457 xPix->data.F32[i] = x;458 yPix->data.F32[i] = y;459 460 if (rawChip) {461 psString cellName = NULL; // Name of cell462 coordChip2Cell(&cellName, &x, &y, x, y, cellNames, cellBounds,463 cellX0, cellY0, cellParityX, cellParityY, cellBinX, cellBinY);464 cellPix->data[i] = cellName;465 xCell->data.F32[i] = x;466 yCell->data.F32[i] = y;467 }468 469 }470 psFree(pix);471 psFree(fp);472 396 } 473 397 … … 632 556 } 633 557 634 if (fpaOut) {635 psArray *chipPix = fpaOut->data[0]; // Chip for pixels636 psVector *xPix = fpaOut->data[1]; // x coordinate for pixels637 psVector *yPix = fpaOut->data[2]; // y coordinate for pixels638 psArray *cellPix = fpaOut->data[3]; // Cell for pixels639 psVector *xCell = fpaOut->data[4]; // x coordinate for pixels640 psVector *yCell = fpaOut->data[5]; // y coordinate for pixels641 psVector *fpa_x = fpas->data[0]; // FPA x coordinate642 psVector *fpa_y = fpas->data[1]; // FPA y coordinate643 644 for (long i = 0; i < chipPix->n; i++) {645 const char *chipName = chipPix->data[i]; // Name of chip646 const char *cellName = cellPix->data[i]; // Name of cell, or NULL647 if (!data->all && (!isfinite(xPix->data.F32[i]) || !isfinite(yPix->data.F32[i]) ||648 !chipName || (rawFile && !cellName))) {649 continue;650 }651 if (!rawFile && data->ds9) {652 // Region file is only appropriate if we're not mapping all the way back to cell coordinates653 fprintf(data->ds9, "image;circle(%f,%f,%f) # color=%s\n",654 xPix->data.F32[i], yPix->data.F32[i], data->ds9radius, data->ds9color);655 } else if (rawFile) {656 fprintf(stdout, "%.3f %.3f --> %.3f %.3f %s %.3f %.3f %s\n",657 fpa_x->data.F32[i], fpa_y->data.F32[i], xPix->data.F32[i], yPix->data.F32[i],658 chipName ? chipName : "UNKNOWN",659 xCell->data.F32[i], yCell->data.F32[i],660 cellName ? cellName : "UNKNOWN");661 } else {662 fprintf(stdout, "%.3f %.3f --> %.3f %.3f %s\n",663 fpa_x->data.F32[i], fpa_y->data.F32[i], xPix->data.F32[i], yPix->data.F32[i],664 chipName ? chipName : "UNKNOWN");665 }666 }667 }668 669 558 if (streaksOut) { 670 559 psArray *chipPix1 = streaksOut->data[0]; // Chip for point 1 -
trunk/pswarp/src/pswarpMapGrid.c
r42154 r42229 38 38 int nYpts = (int)(Ny / nYpix) + 1; 39 39 40 psLogMsg("pswarp", 3, "in grid sampling\n");41 40 // create the grid of maps 42 41 pswarpMapGrid *grid = pswarpMapGridAlloc (nXpts, nYpts); … … 50 49 } 51 50 52 //if (0) {51 if (0) { 53 52 // test the transformation sky<->chip for chip in smf: 54 53 if (fout == NULL) { fout = fopen ("map.grid.txt", "w"); } … … 89 88 fprintf (fout, "%f %f < %f %f < %f %f \n", TP1->x, TP1->y, FP1->x, FP1->y, CH1->x, CH1->y); 90 89 91 psLogMsg("pswarp", 3, "testing grid sampling\n");92 psLogMsg("pswarp", 3, "%f %f > %f %f > %f %f > %f %f | ", CH0->x, CH0->y, FP0->x, FP0->y, TP0->x, TP0->y, sky->r*180/M_PI, sky->d*180/M_PI);93 psLogMsg("pswarp", 3, "%f %f < %f %f < %f %f \n", TP1->x, TP1->y, FP1->x, FP1->y, CH1->x, CH1->y);94 95 90 } 96 91 } … … 106 101 107 102 psFree (sky); 108 //}103 } 109 104 110 105 grid->nXpix = nXpix; -
trunk/pswarp/src/pswarpTransformReadout.c
r42154 r42229 104 104 // pswarpMapGridFromImage builds a set of locally-linear maps which convert the 105 105 // output coordinates to input coordinates 106 psLogMsg("pswarp", 3, "going into MapGrid \n");107 106 pswarpMapGrid *grid = pswarpMapGridFromImage(input, output, nGridX, nGridY); 108 107
Note:
See TracChangeset
for help on using the changeset viewer.
