- Timestamp:
- May 18, 2010, 5:06:01 PM (16 years ago)
- Location:
- branches/czw_branch/20100427
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20100427
- Property svn:mergeinfo changed
-
branches/czw_branch/20100427/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
r27784 r28017 17 17 resolve_project 18 18 getCamRunByCamID 19 parse_md_fast 19 20 ); 20 21 our %EXPORT_TAGS = (standard => [@EXPORT_OK]); … … 27 28 use PS::IPP::Config qw( :standard ); 28 29 use Carp; 29 use DateTime;30 30 use File::Temp qw(tempfile); 31 31 use File::Basename; 32 32 use POSIX; 33 use Time::HiRes qw(gettimeofday); 33 34 34 35 my $dvo_verbose = 0; … … 169 170 170 171 # The subroutine lookup handles byexp, byid, and byskycell lookups including lookups that are 171 # triggered by a bydiff request 172 173 sub lookup 174 { 172 # triggered by a bydiff or bycoord request 173 174 sub lookup { 175 175 my $ipprc = shift; 176 176 my $rowList = shift; … … 206 206 my $class_id; 207 207 my $skycell_id; 208 209 if (isnull($component)) { 210 $component = undef; 211 } 208 my $default_error = $PSTAMP_NO_IMAGE_MATCH; 212 209 213 210 # note $magic_arg may be cleared below depending on $req_type … … 220 217 my $choose_components = 0; 221 218 if ($stage eq "raw") { 222 $class_id = $component;223 219 $command = "$regtool -processedimfile -dbname $imagedb"; 224 220 # XXX: for now restrict lookups to type object … … 226 222 $command .= " -exp_type object"; 227 223 $id_opt = $use_imfile_id ? "-raw_imfile_id" : "-exp_id"; 228 $component_args = " -class_id $class_id" if $component; 224 225 if ($component and $component ne 'all') { 226 $class_id = $component; 227 $component_args = " -class_id $class_id"; 228 } 229 229 $want_astrom = 1; 230 230 $set_class_id = 1; 231 231 } elsif ($stage eq "chip") { 232 $class_id = $component;233 232 # if the request is such that it will yield a single image per "run" or the 234 233 # center is specified in pixel coordinates 235 234 # use chiptool -processsedimfile. Otherwise use chiptool -listrun and then 236 235 # choose the chips containing the center pixel by calling selectComponets() below 237 if ($c lass_idor $use_imfile_id or !$skycenter) {236 if ($component or $use_imfile_id or !$skycenter) { 238 237 $command = "$chiptool -processedimfile -dbname $imagedb"; 239 $component_args = " -class_id $class_id" if $class_id; 238 if ($component and $component ne 'all') { 239 $class_id = $component; 240 $component_args = " -class_id $class_id"; 241 } 240 242 } else { 241 243 $command = "$chiptool -listrun -pstamp_order -dbname $imagedb"; … … 246 248 # With the mdc file it has all of the information that it needs. 247 249 $image_name = "PPIMAGE.CHIP"; 248 $mask_name = "PPIMAGE.CHIP.MASK"; 250 # $mask_name = "PPIMAGE.CHIP.MASK"; 251 # XXX: really need to handle this properly! 252 $mask_name = "PSASTRO.OUTPUT.MASK"; 249 253 $weight_name = "PPIMAGE.CHIP.VARIANCE"; 250 254 $cmf_name = "PSPHOT.OUTPUT"; … … 255 259 $set_class_id = 1; 256 260 } elsif ($stage eq "warp") { 257 $skycell_id = $component; 258 if ($skycell_id or $use_imfile_id or !$skycenter) { 261 if ($component or $use_imfile_id or !$skycenter) { 259 262 $command = "$warptool -warped -dbname $imagedb"; 260 $component_args = " -skycell_id $skycell_id" if $skycell_id; 263 if ($component and $component ne 'all') { 264 $skycell_id = $component; 265 $component_args = " -skycell_id $skycell_id"; 266 } 261 267 } else { 262 268 $command = "$warptool -listrun -pstamp_order -dbname $imagedb"; … … 271 277 $base_name = "path_base"; # name of the field for the warptool output 272 278 } elsif ($stage eq "diff") { 273 $skycell_id = $component; 274 if ($skycell_id or $use_imfile_id or !$skycenter) { 279 if ($component or $use_imfile_id or !$skycenter) { 275 280 $command = "$difftool -diffskyfile -dbname $imagedb"; 276 $component_args = " -skycell_id $skycell_id" if $skycell_id; 281 if ($component and $component ne 'all') { 282 $skycell_id = $component; 283 $component_args = " -skycell_id $skycell_id"; 284 } 277 285 } else { 278 286 $command = "$difftool -listrun -pstamp_order -dbname $imagedb"; … … 284 292 $weight_name = "PPSUB.OUTPUT.VARIANCE"; 285 293 $cmf_name = "PPSUB.OUTPUT.SOURCES"; 286 $psf_name = "PSPHOT.PSF.SKY.SAVE";294 $psf_name = "PSPHOT.PSF.SKY.SAVE"; 287 295 $base_name = "path_base"; 288 296 } elsif ($stage eq "stack") { … … 361 369 $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose); 362 370 } else { 363 # put each of the rows into all of the the images371 # put index for each of the rows into all of the the images 364 372 setRowRefs($rowList, $images); 365 373 } … … 390 398 $ipprc->define_camera($camera); 391 399 } 400 # ok it's a keeper 392 401 my $out = $image; 393 402 394 403 # if uri is nil this will get overridded below 395 404 # (we do this here for raw stage) 396 $out->{image} = $ image->{uri};405 $out->{image} = $out->{uri}; 397 406 398 407 if ($set_class_id) { 399 $class_id = $ image->{class_id};408 $class_id = $out->{class_id}; 400 409 $out->{component} = $class_id; 401 410 } else { 402 $out->{component} = $ image->{skycell_id};411 $out->{component} = $out->{skycell_id}; 403 412 } 404 413 my $stage_id; 405 414 if ($stage eq "raw") { 406 $stage_id = $ image->{exp_id};415 $stage_id = $out->{exp_id}; 407 416 } elsif ($stage eq "chip") { 408 $stage_id = $ image->{chip_id};417 $stage_id = $out->{chip_id}; 409 418 } elsif ($stage eq "warp") { 410 $stage_id = $ image->{warp_id};419 $stage_id = $out->{warp_id}; 411 420 } elsif ($stage eq "diff") { 412 $stage_id = $ image->{diff_id};413 if ($inverse && $ image->{bothways}) {421 $stage_id = $out->{diff_id}; 422 if ($inverse && $out->{bothways}) { 414 423 $image_name = "PPSUB.INVERSE"; 415 424 $mask_name = "PPSUB.INVERSE.MASK"; … … 418 427 } 419 428 } elsif ($stage eq "stack") { 420 $stage_id = $ image->{stack_id};429 $stage_id = $out->{stack_id}; 421 430 } 422 431 $out->{stage_id} = $stage_id; … … 424 433 $out->{imagedb} = $imagedb; 425 434 435 my $mask_base; 436 if ($want_astrom) { 437 if (! defined $out->{astrom}) { 438 if (! find_astrometry($ipprc, $imagedb, $out, $verbose)) { 439 print STDERR "failed to find astrometry for $stage $stage_id\n"; 440 next; 441 } 442 } 443 # XXX: do this right by looking at the recipe 444 $mask_base = $out->{cam_path_base}; 445 } else { 446 $mask_base = $base; 447 } 448 426 449 if ($base) { 427 450 $out->{image} = $ipprc->filename($image_name, $base, $class_id) if $image_name; 428 $out->{mask} = $ipprc->filename($mask_name, $ base, $class_id) if $mask_name;451 $out->{mask} = $ipprc->filename($mask_name, $mask_base, $class_id) if $mask_name; 429 452 $out->{weight} = $ipprc->filename($weight_name, $base, $class_id) if $weight_name; 430 $out->{cmf} = $ipprc->filename($cmf_name, $base, $class_id) if $cmf_name; 431 $out->{psf} = $ipprc->filename($psf_name, $base, $class_id) if $psf_name; 432 $out->{backmdl}= $ipprc->filename($backmdl_name, $base, $class_id) if $backmdl_name; 433 } 434 if ($want_astrom and ! defined $out->{astrom}) { 435 $out->{astrom} = find_astrometry($ipprc, $imagedb, $image, $verbose); 453 $out->{cmf} = $ipprc->filename($cmf_name, $base, $class_id) if $cmf_name; 454 $out->{psf} = $ipprc->filename($psf_name, $base, $class_id) if $psf_name; 455 $out->{backmdl}= $ipprc->filename($backmdl_name,$base, $class_id) if $backmdl_name; 436 456 } 437 457 … … 455 475 my $inverse = $option_mask & $PSTAMP_SELECT_INVERSE; 456 476 457 my $command = "$difftool -d iffskyfile -dbname $imagedb";477 my $command = "$difftool -dbname $imagedb"; 458 478 479 my $listrun = 0; 459 480 if ($byid) { 460 $command .= " -diff_id $id"; 481 if ($skycell_id) { 482 $command .= " -diffskyfile -diff_id $id -skycell_id $skycell_id"; 483 } else { 484 $command .= " -listrun -diff_id $id"; 485 $listrun = 1; 486 } 461 487 } else { 462 $command .= " -diff_skyfile_id $id"; 463 } 464 $command .= " -skycell_id $skycell_id" if $skycell_id; 465 466 my $images = runToolAndParse($command, $verbose); 467 468 my $n = @$images; 469 if (!$byid && ($n > 1)) { 488 $command .= " -diffskyfile -diff_skyfile_id $id"; 489 } 490 491 my $output = runToolAndParse($command, $verbose); 492 493 my $n = $output ? scalar @$output : 0; 494 if (!$listrun && ($n > 1)) { 470 495 die ("difftool returned an unexpected number of diffskyfiles: $n"); 471 496 } elsif ($n == 0) { 472 497 return undef; 498 } 499 500 my $images; 501 if ($listrun) { 502 $images = selectComponents($ipprc, $imagedb, 'byid', 'diff', $rowList, $output, $verbose); 503 } else { 504 $images = $output; 473 505 } 474 506 … … 501 533 if (($img_type ne "diff") and ($img_type ne "stack")) { 502 534 print STDERR "lookup_diff: cannot lookup IMG_TYPE $img_type bydiff from a stack stack diff run\n"; 503 next; 535 setErrorCodes($rowList, $PSTAMP_INVALID_REQUEST); 536 # all images will be the same so we can stop 537 last; 504 538 } 505 539 # stack-stack diff … … 569 603 } else { 570 604 # XXX this will only happen if the minuend is not a warp. See hack above 571 print STDERR "WARNING: cannot resolve camera so cannot get resolvefile rules\n";605 print STDERR "WARNING: cannot resolve camera so cannot find file rules\n"; 572 606 next; 573 607 } … … 691 725 next if !$astrom_resolved; 692 726 693 my $start_dvo = DateTime->now->mjd;727 my $start_dvo = gettimeofday(); 694 728 my $command = "$dvoImagesAtCoords -astrom $astrom_resolved $ra $dec"; 695 729 # run the tool and parse the output 696 730 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 697 731 run(command => $command, verbose => $dvo_verbose); 698 my $dtime_dvo = (DateTime->now->mjd - $start_dvo)* 86400.;732 my $dtime_dvo = gettimeofday() - $start_dvo; 699 733 # print "Time to run dvoImagesAtCoords: $dtime_dvo\n"; 700 734 unless ($success) { … … 720 754 my $n = scalar @lines; 721 755 if ($n != 1) { 722 print STDERR "unexpected number of lines returned by dvoImagesAtCoords: $n\n";723 724 756 # XXX: There is a bug in dvo where each component is listed twice 725 757 # When that gets fixed remove the conditional and just die 726 die "unexpected number lines returned by dvoImagesAtCoords: $n" 727 if ($n != 2) or ($lines[0] ne $lines[1]); 758 if ($n ne 2 or $lines[0] ne $lines[1]) { 759 print STDERR "unexpected number of lines returned by dvoImagesAtCoords: $n\n"; 760 print STDERR "OUTPUT:\n$output\n"; 761 # actually this seems to happen sometimes. Probably due to a problem with 762 # astrometry. Just skip this camRun 763 print STDERR "skipping: $astrom\n"; 764 next; 765 } 728 766 } 729 767 … … 741 779 chip_id => $camRun->{chip_id}, 742 780 cam_id => $camRun->{cam_id}, 743 astrom => $astrom_resolved, 781 astrom => $astrom_resolved, # XXX: is astrom used? 744 782 class_id => $class_id, 745 783 component => $class_id … … 821 859 # cache of results of ppConfigDump 822 860 my %astromSources; 823 my $last_exp_id = 0;824 my $lastAstromFile;825 861 826 862 # find the astrometry file for a given exposure 827 863 # return undef if no completed camRun exists 864 # XXX Right now this probably only works cameras where the astrometry is done at the camera stage 865 # What other possibilities are there for ASTROM.SOURCE besides PSASTRO.OUTPUT? 866 828 867 sub find_astrometry { 829 868 my $ipprc = shift; … … 835 874 836 875 my $exp_id = $image->{exp_id}; 837 if (($exp_id eq $last_exp_id) and $lastAstromFile) {838 # running camtool 60 times is really expensive when the answer is the same every time839 return $lastAstromFile;840 }841 $last_exp_id = 0;842 $lastAstromFile = undef;843 876 844 877 my $camRun = getCamRunByExpID($exp_id); … … 850 883 unless ($success) { 851 884 print STDERR @$stderr_buf; 852 return undef;885 return 0; 853 886 } 854 887 … … 858 891 if (!$output) { 859 892 print STDERR "no output returned from $command\n" if $verbose; 860 return undef;893 return 0; 861 894 } 862 895 my $camruns = parse_md_fast($mdcParser, $output); 863 896 if (!$camruns) { 864 return undef;897 return 0; 865 898 } 866 899 867 900 # If there are multiple cam runs for this exposure, take the last completed one with good quality 868 901 # on the assumption that it has the best astrometry. 869 foreach $camRun (@$camruns) { 870 last if (($camRun->{state} eq 'full') and ($camRun->{quality} eq 0) and ($camRun->{fault} eq 0)); 902 foreach my $cr (@$camruns) { 903 if (($cr->{state} eq 'full') and ($cr->{quality} eq 0) and ($cr->{fault} eq 0)) { 904 $camRun = $cr; 905 last; 906 } 871 907 } 872 908 # XXX: this looks like a bug at least if ASTROM.SOURCE eq PSASTRO.OUTPUT 873 909 if (!$camRun) { 874 910 # no cam runs for this exposure id therefore best astrometry is whatever is in the header 875 return undef;911 return 0; 876 912 } 877 913 updateCamRunCache($camRun); … … 902 938 # XXX: Is this code correct if ASTROM.SOURCE ne "PSASTRO.OUTPUT" 903 939 my $astromFile = $ipprc->filename($astromSource, $camRoot); 904 if ($astromFile) { 905 $lastAstromFile = $astromFile; 906 $last_exp_id = $exp_id; 907 } 908 909 return $astromFile; 940 if (!$astromFile) { 941 print STDERR "failed to find astrometry file from $astromSource $camRoot\n"; 942 return 0; 943 } 944 945 $image->{astrom} = $astromFile; 946 $image->{cam_path_base} = $camRoot; 947 948 return 1; 910 949 } 911 950 … … 973 1012 } 974 1013 975 if ($ project_name eq $last_project) {1014 if ($last_project and ($project_name eq ($last_project->{name}))) { 976 1015 return $last_project; 977 1016 } … … 1049 1088 print $pointsList "$npoints $row->{CENTER_X} $row->{CENTER_Y}\n"; 1050 1089 $npoints++; 1090 # this gets overwitten if an overlapping image is found 1091 $row->{error_code} = $PSTAMP_NO_OVERLAP; 1051 1092 } 1052 1093 close $pointsList; … … 1093 1134 } 1094 1135 push @$ref, $ptnum; 1136 my $row = $rowList->[$ptnum]; 1137 # this row found a match 1138 $row->{error_code} = 0; 1095 1139 } 1096 1140 if ($verbose) { … … 1124 1168 my $images = runToolAndParse($command, $verbose); 1125 1169 if (!defined $images) { 1126 # XXX: need to get the set error_code to $PSTAMP_NO_OVERLAP1127 1170 print "No components containing coordinates found for ${stage}_id $stage_id\n"; 1128 1171 foreach my $row (@$rowList) { 1172 # XXX: This doesn't seem like the correct error code? 1129 1173 $row->{error_code} = $PSTAMP_NO_OVERLAP; 1130 1174 } … … 1221 1265 1222 1266 print "Running $command\n" if !$verbose; 1223 my $start_tool = DateTime->now->mjd;1267 my $start_tool = gettimeofday(); 1224 1268 # run the command and parse the output 1225 1269 … … 1232 1276 } 1233 1277 1234 my $now = DateTime->now->mjd;1235 my $dtime_tool = (DateTime->now->mjd - $start_tool) * 86400.;1278 my $now = gettimeofday(); 1279 my $dtime_tool = $now - $start_tool; 1236 1280 print "Time to run $program: $dtime_tool\n"; 1237 1281 … … 1241 1285 } 1242 1286 1243 my $start_parse = DateTime->now->mjd;1287 my $start_parse = gettimeofday(); 1244 1288 1245 1289 my $mdcParser = PS::IPP::Metadata::Config->new; … … 1247 1291 or die ("Unable to parse metadata config doc"); 1248 1292 1249 my $dtime_parse = (DateTime->now->mjd - $start_parse) * 86400.;1293 my $dtime_parse = gettimeofday() - $start_parse; 1250 1294 print "Time to parse results from $program: $dtime_parse\n"; 1251 1295 … … 1287 1331 } 1288 1332 } 1333 # set error_code for an array of rows to a given value 1334 sub setErrorCodes { 1335 my $rowList = shift; 1336 my $code = shift; 1337 foreach my $row (@$rowList) { 1338 $row->{error_code} = $code; 1339 } 1340 } 1289 1341 1290 1342 sub my_die
Note:
See TracChangeset
for help on using the changeset viewer.
