Changeset 27140
- Timestamp:
- Mar 2, 2010, 12:19:43 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm (modified) (10 diffs)
-
pstamp/scripts/pstampparse.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
r27091 r27140 19 19 our %EXPORT_TAGS = (standard => [@EXPORT_OK]); 20 20 21 22 use PS::IPP::PStamp::RequestFile qw( :standard ); 21 23 22 24 use IPC::Cmd 0.36 qw( can_run run ); … … 43 45 my $mjd_max = shift; 44 46 my $filter = shift; 45 my $data_group = shift;47 my $data_group = shift; 46 48 my $verbose = shift; 47 49 48 50 49 51 # we die in response to bad data in request files 52 # The wrapper script is responsible for updating the database 50 53 die "Unknown req_type: $req_type" 51 54 if ($req_type ne "byid") and … … 65 68 if (isnull($tess_id)) { 66 69 $tess_id = undef; 70 } 71 if (isnull($data_group)) { 72 $data_group = undef; 73 } 74 if (isnull($filter)) { 75 $filter = undef; 76 } 77 78 if ($req_type eq "bycoord") { 79 my $results = lookup_bycoord($ipprc, $image_db, $img_type, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose); 80 return $results; 67 81 } 68 82 … … 113 127 return undef; 114 128 } 115 116 } elsif ($req_type eq "bycoord") {117 118 if ($img_type eq "stack") {119 print STDERR "Error bycoord lookup not implemented for stage stack yet\n";120 return undef;121 }122 129 } elsif ($req_type eq "byskycell") { 123 130 if (($img_type eq "raw") or ($img_type eq "chip")) { … … 131 138 } 132 139 133 my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose); 140 my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $tess_id, $component, $need_magic, 141 $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose); 134 142 135 143 return $results; … … 146 154 my $component= shift; 147 155 my $need_magic = shift; 148 my $x = shift;149 my $y = shift;150 156 my $dateobs_begin = shift; 151 157 my $dateobs_end = shift; … … 267 273 die "tess_id and component are required for byskycell" if !$tess_id or ! $skycell_id; 268 274 $command .= " -tess_id $tess_id -skycell_id $skycell_id"; 269 } elsif ($req_type eq "bycoord") {270 $command .= " -radius 3.0 -ra $x -decl $y";271 if ($img_type ne "raw") {272 $command .= " -tess_id $tess_id" if $tess_id;273 $command .= " -skycell_id $skycell_id" if $skycell_id;274 }275 275 } else { 276 276 die "Unknown req_type supplied: $req_type"; … … 515 515 516 516 sub lookup_bycoord { 517 my $ipprc = shift; 518 my $image_db = shift; 519 my $x = shift; 520 my $y = shift; 517 my $ipprc = shift; 518 my $image_db = shift; 519 my $img_type = shift; 520 my $tess_id = shift; 521 my $component = shift; 522 my $need_magic = shift; 523 my $ra = shift; 524 my $dec = shift; 521 525 my $dateobs_begin = shift; 522 my $dateobs_end = shift; 523 my $filter = shift; 524 my $verbose = shift; 526 my $dateobs_end = shift; 527 my $filter = shift; 528 my $data_group = shift; 529 my $verbose = shift; 525 530 526 531 my $missing_tools; 527 532 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1); 533 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); 534 my $dvoImagesAtCoords = can_run('dvoImagesAtCoords') or (warn "Can't find dvoImagesAtCoords" and $missing_tools = 1); 535 my $whichimage = can_run('whichimage') or (warn "Can't find whichimage" and $missing_tools = 1); 528 536 if ($missing_tools) { 529 537 warn("Can't find required tools."); … … 531 539 } 532 540 533 # XXX TODO: 534 # Full lookups by coordinate require looking at the DVO database. However, 535 # dateobs and filter which is all that MOPS has asked for. 536 537 my $args; 538 if (!isnull($dateobs_begin)) { 539 $args .= " -dateobs_begin $dateobs_begin"; 540 } 541 if (!isnull($dateobs_end)) { 542 $args .= " -dateobs_end $dateobs_end"; 543 } 544 if (!isnull($filter)) { 545 $args .= " -filter $filter"; 546 } 547 548 if (!$args) { 549 # avoid returning every exposure in the DB 550 print STDERR "no query arguments provided for bycoord\n"; 551 return undef; 552 } 553 554 # XXX TODO: This query doesn't work Something appears to be out of 555 # sync about the times I'm passing and what regtool and or the DB expect 556 # the query I used in the C version of locateimages used 557 # WHERE dateobs >= FROM_UNIXTIME(%ld) AND dateobs <= FROM_UNIXTIME(%ld + exp_time) 558 559 my $command = "$regtool -processedexp -dbname $image_db $args"; 560 561 # run the tool and parse the output 562 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 563 run(command => $command, verbose => $verbose); 564 unless ($success) { 565 # not sure if we should die here 566 print STDERR @$stderr_buf; 567 return undef; 568 } 569 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 570 571 my $output = join "", @$stdout_buf; 572 if (!$output) { 573 print STDERR "no output returned from $command\n" if $verbose; 574 return undef; 575 } 576 my $images = parse_md_fast($mdcParser, $output) or die ("Unable to parse metadata config doc"); 577 578 return $images; 541 my $results = (); 542 if (($img_type eq "raw") or ($img_type eq "chip")) { 543 544 my $runs = lookup_runs_by_camid_and_coords($ipprc, $image_db, $img_type, 545 $ra, $dec, $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose); 546 547 foreach my $run (@$runs) { 548 next if $component and ($run->{component} ne $component); 549 my $these_results = lookup($ipprc, $image_db, "byid", $img_type, $run->{id}, 550 $tess_id, $run->{component}, $need_magic, 551 $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose); 552 553 next if !$these_results; 554 push @$results, @$these_results; 555 } 556 557 } else { 558 # this should be checked elsewhere 559 die "unexpected image type $img_type" if ($img_type ne "warp") 560 and ($img_type ne "stack") and ($img_type ne "diff"); 561 562 my $skycells = lookup_skycell_by_coords($ipprc, $tess_id, $component, $ra, $dec, $verbose); 563 564 foreach my $skycell (@$skycells) { 565 my $these_results = lookup($ipprc, $image_db, "byskycell", $img_type, undef, 566 $skycell->{tess_id}, $skycell->{component}, $need_magic, 567 $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose); 568 569 next if !$these_results; 570 push @$results, @$these_results; 571 } 572 } 573 574 return $results; 575 } 576 577 # lookup_runs_by_camid_and_coords 578 # given an ra, dec, and optionally other paramters, find camera runs for exposures 579 # that are within some distance of the coordinates 580 sub lookup_runs_by_camid_and_coords { 581 my $ipprc = shift; 582 my $image_db = shift; 583 my $img_type = shift; 584 my $ra = shift; 585 my $dec = shift; 586 my $need_magic = shift; 587 my $dateobs_begin = shift; 588 my $dateobs_end = shift; 589 my $filter = shift; 590 my $data_group = shift; 591 my $verbose = shift; 592 593 my $camruns; 594 my $missing_tools; 595 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); 596 my $dvoImagesAtCoords = can_run('dvoImagesAtCoords') or (warn "Can't find dvoImagesAtCoords" and $missing_tools = 1); 597 if ($missing_tools) { 598 warn("Can't find required tools."); 599 exit ($PS_EXIT_CONFIG_ERROR); 600 } 601 602 { 603 my $command = "$camtool -dbname $image_db -processedexp"; 604 $command .= " -ra $ra -decl $dec -radius 3"; 605 $command .= " -dateobs_begin $dateobs_begin" if $dateobs_begin; 606 $command .= " -dateobs_end $dateobs_end" if $dateobs_end ; 607 $command .= " -filter $filter" if $filter; 608 # NOTE: we are applying the data_group to the camera run. 609 # If we're looking for chip stage images there is no guarentee that 610 # chipRun.data_group = camRun.data_group. In practice this is almost 611 # always the case. If this turns out to be a problem we can defer 612 # the data_group test to when we look up the chipProcessedImfiles 613 $command .= " -data_group $data_group" if $data_group; 614 $command .= " -destreaked" if $need_magic; 615 # run the tool and parse the output 616 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 617 run(command => $command, verbose => $verbose); 618 unless ($success) { 619 print STDERR @$stderr_buf; 620 return undef; 621 } 622 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 623 624 my $output = join "", @$stdout_buf; 625 if (!$output) { 626 print STDERR "no output returned from $command\n" if $verbose; 627 return undef; 628 } 629 $camruns = parse_md_fast($mdcParser, $output); 630 } 631 if (!$camruns) { 632 return undef; 633 } 634 my $runs; 635 foreach my $camRun (@$camruns) { 636 next if $camRun->{quality}; 637 next if $camRun->{fault}; 638 # XXX Use file rule 639 my $astrom = $camRun->{path_base} . ".smf"; 640 my $astrom_resolved = $ipprc->file_resolve($astrom); 641 next if !$astrom_resolved; 642 643 my $command = "$dvoImagesAtCoords -astrom $astrom_resolved $ra $dec"; 644 # run the tool and parse the output 645 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 646 run(command => $command, verbose => $verbose); 647 unless ($success) { 648 my $result_code = $error_code >> 8; 649 if ($result_code == $PSTAMP_NO_OVERLAP) { 650 print STDERR "no overlap for $astrom\n" if $verbose; 651 next; 652 } 653 # unexpected result code 654 die "unexpected result code: $result_code from $command\n"; 655 } 656 657 my $output = join "", @$stdout_buf; 658 if (!$output) { 659 # this shouldn't happen when dvoImagesAtCoord exits with zero status 660 die "no output returned from $command\n"; 661 } 662 663 # dvoImagesAtCoords should return a single line 664 # rownum ra dec class_id 665 my @lines = split "\n", $output; 666 my $n = scalar @lines; 667 if ($n != 1) { 668 print STDERR "unexpected number of lines returned by dvoImagesAtCoords: $n\n"; 669 670 # XXX: There is a bug in dvo where each component is listed twice 671 # When that gets fixed remove the conditional and just die 672 die "unexpected number lines returned by dvoImagesAtCoords: $n" 673 if ($n != 2) or ($lines[0] ne $lines[1]); 674 } 675 676 my (undef, $ra_out, $dec_out, $class_id) = split " ", $lines[0]; 677 if (!$class_id) { 678 die "unexpected output from dvoImagesAtCoords: $lines[0]"; 679 } 680 # build the hash to return 681 my $run = { 682 exp_id => $camRun->{exp_id}, 683 exp_name => $camRun->{exp_name}, 684 chip_id => $camRun->{chip_id}, 685 cam_id => $camRun->{cam_id}, 686 astrom => $astrom_resolved, 687 class_id => $class_id, 688 component => $class_id 689 }; 690 if ($img_type eq "chip") { 691 $run->{id} = $run->{chip_id}; 692 } else { 693 $run->{id} = $run->{exp_id}; 694 } 695 push @$runs, $run; 696 } 697 698 return $runs; 699 } 700 701 sub lookup_skycell_by_coords { 702 my $ipprc = shift; 703 my $requested_tess_id = shift; 704 my $requested_skycell = shift; 705 my $ra = shift; 706 my $dec = shift; 707 my $verbose = shift; 708 709 my $missing_tools; 710 my $whichimage = can_run('whichimage') or (warn "Can't find whichimage" and $missing_tools = 1); 711 if ($missing_tools) { 712 warn("Can't find required tools."); 713 exit ($PS_EXIT_CONFIG_ERROR); 714 } 715 716 $requested_tess_id = "" if isnull($requested_tess_id); 717 $requested_skycell = "" if isnull($requested_skycell); 718 719 my @lines; 720 { 721 my $command = "$whichimage $ra $dec"; 722 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 723 run(command => $command, verbose => $verbose); 724 unless ($success) { 725 print STDERR @$stderr_buf; 726 return undef; 727 } 728 729 my $output = join "", @$stdout_buf; 730 if (!$output) { 731 print STDERR "no output returned from $command\n" if $verbose; 732 return undef; 733 } 734 @lines = split "\n", $output; 735 if (!scalar @lines) { 736 # can this happen? if $output is not null? 737 print STDERR "no output returned from $command\n" if $verbose; 738 return undef; 739 } 740 } 741 my $runs; 742 foreach my $line (@lines) { 743 my ($ra_out, $dec_out, $tess_id, $skycell_id) = split " ", $line; 744 die "unexpected output from whichimage" if !$tess_id or !$skycell_id; 745 746 if ($requested_tess_id) { 747 next if ($requested_tess_id ne $tess_id); 748 } else { 749 # skip these obsolete tesselations unless they were explicitly asked for 750 # should I do this? 751 next if $tess_id eq "FIXNS"; 752 next if $tess_id eq "ALLSKY"; 753 } 754 next if $requested_skycell and ($skycell_id ne $requested_skycell); 755 756 # build the hash to return 757 my $run = { 758 tess_id => $tess_id, 759 component => $skycell_id, 760 }; 761 push @$runs, $run; 762 } 763 764 return $runs; 579 765 } 580 766 … … 707 893 my $val = shift; 708 894 709 return (!defined($val) or ( lc($val) eq "null"));895 return (!defined($val) or ($val eq "") or (lc($val) eq "null")); 710 896 } 711 897 -
trunk/pstamp/scripts/pstampparse.pl
r27122 r27140 218 218 } 219 219 220 # user requested us to search all components. Set to "" 220 221 $search_component = "" if $search_component eq "all"; 221 222 … … 265 266 print STDERR "center must be specified in sky coordintes for bycoord" if $verbose; 266 267 insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST); 267 $num_jobs++;268 next;269 }270 if ($stage eq "stack") {271 print STDERR "lookup bycoord is not yet implemented for stage stack" if $verbose;272 insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);273 268 $num_jobs++; 274 269 next;
Note:
See TracChangeset
for help on using the changeset viewer.
