IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19161


Ignore:
Timestamp:
Aug 21, 2008, 5:31:31 PM (18 years ago)
Author:
bills
Message:

implement lookup of astrometry file for an exposure.
various other bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/lib/PStamp/Job.pm

    r19001 r19161  
    5151        my $results = lookup_bycoord($ipprc, $image_db, $x, $y, $mjd_min, $mjd_max, $filter, $verbose);
    5252
    53         # If the type is raw we're done, otherwise we have more work to do
    54         if ($img_type eq "raw") {
    55             return $results;
    56         }
    5753        $req_type = "byexp";
    5854        $id = $results->{exp_name};
     
    9086    my $want_astrom;
    9187    my $use_class_id;
     88
     89    # special class_id value "null" means all
     90    if ($class_id eq "null") {
     91        $class_id = undef;
     92    }
    9293
    9394    if ($img_type eq "raw") {
     
    112113        $weight_name  = "PSWARP.OUTPUT.WEIGHT";
    113114        $base_name    = "path_base"; # name of the field for the warptool output
    114         $want_astrom  = 1;
    115         $use_class_id = 1;
    116115    } elsif ($img_type eq "diff") {
    117116        $command = "$difftool -diffskyfile -dbname $image_db";
     
    179178            $out->{weight} = $ipprc->filename($weight_name, $base, $class_id) if $weight_name;
    180179        }
    181         $out->{astrom} = find_astrometry($ipprc, $image) if $want_astrom;
    182180        $out->{camera} = $camera;
     181        $out->{astrom} = find_astrometry($ipprc, $image_db, $image, $verbose) if $want_astrom;
    183182
    184183        push @$output, $out;
     
    255254}
    256255
     256# find the astrometry file for a given exposure
     257# return undef if no completed camRun exists
    257258sub find_astrometry {
    258         #
    259         #XXX need to get this from the config as in warp_overlap.pl
    260 #        $astrom_name = "PSASTRO.OUTPUT.MEF";
    261 #        $astrom_name = "PSASTRO.OUTPUT";
    262 #       $out->{astrom} = $ipprc->filename($astrom_name, $base, $class_id) if $astrom_name;
    263     return undef;
     259    my $ipprc = shift;
     260    my $image_db = shift;
     261    my $image = shift;      # hashref to output of the lookup tool
     262    my $verbose = shift;
     263
     264    my $missing_tools;
     265    my $camtool = can_run("camtool") or (warn "Can't find camtool" and $missing_tools = 1);
     266    my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     267    if ($missing_tools) {
     268        warn("Can't find required tools.");
     269        exit ($PS_EXIT_CONFIG_ERROR);
     270    }
     271
     272    my $command = "$camtool -dbname $image_db -processedexp -exp_id $image->{exp_id}";
     273    # run the tool and parse the output
     274    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     275                run(command => $command, verbose => $verbose);
     276    unless ($success) {
     277        print STDERR @$stderr_buf;
     278        return undef;
     279    }
     280
     281    my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     282
     283    my $output = join "", @$stdout_buf;
     284    if (!$output) {
     285        print STDERR "no output returned from $command\n" if $verbose;
     286        return undef;
     287    }
     288    my $camruns = parse_md_fast($mdcParser, $output);
     289    if (!$camruns) {
     290        return undef;
     291    }
     292
     293    # If there are multiple cam runs for this exposure, take the last one
     294    # assuming that it has the best astrometry
     295    my $camdata = pop @$camruns;
     296    if (!$camdata) {
     297        # no cam runs for this exposure id therefore best astrometry is whatever is in the header
     298        return undef;
     299    }
     300    my $camRoot = $camdata->{path_base};
     301    my $camera = $image->{camera};
     302    my $astromSource;
     303    {
     304       my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -";
     305        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     306            run(command => $command, verbose => $verbose);
     307        unless ($success) {
     308            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     309            die("Unable to perform ppConfigDump: $error_code");
     310        }
     311        my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     312            die("Unable to parse metadata config doc");
     313        $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
     314    }
     315
     316    my $astromFile = $ipprc->filename($astromSource, $camRoot);
     317
     318    return $astromFile;
    264319}
    265320
Note: See TracChangeset for help on using the changeset viewer.