IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 12, 2008, 4:15:35 PM (18 years ago)
Author:
Paul Price
Message:

Fixing error message.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/warp_overlap.pl

    r17518 r17646  
    2323
    2424use PS::IPP::Config qw($PS_EXIT_SUCCESS
    25                        $PS_EXIT_UNKNOWN_ERROR
    26                        $PS_EXIT_SYS_ERROR
    27                        $PS_EXIT_CONFIG_ERROR
    28                        $PS_EXIT_PROG_ERROR
    29                        $PS_EXIT_DATA_ERROR
    30                        $PS_EXIT_TIMEOUT_ERROR
    31                        metadataLookupStr
    32                        metadataLookupBool
    33                        caturi
    34                        file_scheme
    35                        );
     25                       $PS_EXIT_UNKNOWN_ERROR
     26                       $PS_EXIT_SYS_ERROR
     27                       $PS_EXIT_CONFIG_ERROR
     28                       $PS_EXIT_PROG_ERROR
     29                       $PS_EXIT_DATA_ERROR
     30                       $PS_EXIT_TIMEOUT_ERROR
     31                       metadataLookupStr
     32                       metadataLookupBool
     33                       caturi
     34                       file_scheme
     35                       );
    3636
    3737my $ipprc = PS::IPP::Config->new(); # IPP configuration
     
    4444    'dbname|d=s'        => \$dbname, # Database name
    4545    'verbose'           => \$verbose,   # Print to stdout
    46     'no-update'         => \$no_update, # Don't update the database?
     46    'no-update'         => \$no_update, # Don't update the database?
    4747    'no-op'             => \$no_op, # Don't do any operations
    4848    'save-temps'        => \$save_temps, # Save temporary files?
     
    6666if ($missing_tools) {
    6767    warn("Can't find required tools.");
    68     exit($PS_EXIT_CONFIG_ERROR); 
    69 }
    70 
    71 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     68    exit($PS_EXIT_CONFIG_ERROR);
     69}
     70
     71my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    7272
    7373# Get list of component imfiles for exposure
     
    7777    $command .= " -dbname $dbname" if defined $dbname;
    7878    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    79         run(command => $command, verbose => $verbose);
     79        run(command => $command, verbose => $verbose);
    8080    unless ($success) {
    81         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    82         &my_die("Unable to perform warptool -imfile: $error_code", $warp_id, $error_code);
    83     }
    84    
     81        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     82        &my_die("Unable to perform warptool -imfile: $error_code", $warp_id, $error_code);
     83    }
     84
    8585    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    86         &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);
    87     $imfiles = parse_md_list($metadata) or 
    88         &my_die("Unable to parse metadata list", $warp_id, $PS_EXIT_PROG_ERROR);
     86        &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);
     87    $imfiles = parse_md_list($metadata) or
     88        &my_die("Unable to parse metadata list", $warp_id, $PS_EXIT_PROG_ERROR);
    8989}
    9090
    9191# Where do we get the astrometry source from?
    92 my $astromSource;               # The astrometry source
    93 my $astromAccept;               # Accept the astrometry unconditionally?
    94 my $astromDepth;                # File level of the astrometry source (SPLIT or MEF)?
     92my $astromSource;               # The astrometry source
     93my $astromAccept;               # Accept the astrometry unconditionally?
     94my $astromDepth;                # File level of the astrometry source (SPLIT or MEF)?
    9595{
    9696    my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -";
    9797    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    98         run(command => $command, verbose => $verbose);
     98        run(command => $command, verbose => $verbose);
    9999    unless ($success) {
    100         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    101         &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code);
     100        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     101        &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code);
    102102    }
    103103    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    104         &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);
     104        &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);
    105105    $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
    106106    $astromAccept = metadataLookupBool($metadata, 'ASTROM.ACCEPT');
     
    116116    my $tess_dir = $ipprc->tessellation_catdir( $tess_id ); # Tessellation catdir for DVO
    117117    $tess_dir = $ipprc->convert_filename_absolute( $tess_dir );
    118        
     118
    119119    my %unique_skycells = (); # Identified skycells (all unique by virtue of hash property)
    120    
     120
    121121    # XXX this is a bit too hard wired: the concept is that astrometry comes from the MOSAIC vs CHIP output
    122122    # XXX we have moved the astrometry analysis to the camera stage only: we should always have the source be MEF
    123123    if ($astromSource eq 'PSASTRO.OUTPUT.MEF') {
    124         # We have a MEF astrometry file from psastro
    125         my $imfile = $imfiles->[0];
    126         my $camRoot = $imfile->{cam_path_base};
    127         my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file
    128        
    129         my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps
    130         if (! @matchlist) {
    131             &my_die("Unable to perform dvoImageOverlaps: missing astrometry", $warp_id, $PS_EXIT_DATA_ERROR);
    132         }           
    133         # Match each of the imfiles to this list
    134         foreach my $imfile (@$imfiles) {
    135             extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
    136         }
     124        # We have a MEF astrometry file from psastro
     125        my $imfile = $imfiles->[0];
     126        my $camRoot = $imfile->{cam_path_base};
     127        my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file
     128
     129        my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps
     130        if (! @matchlist) {
     131            &my_die("Unable to perform dvoImageOverlaps: missing astrometry", $warp_id, $PS_EXIT_DATA_ERROR);
     132        }
     133        # Match each of the imfiles to this list
     134        foreach my $imfile (@$imfiles) {
     135            extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
     136        }
    137137    } else {
    138         # We have per-imfile astrometry
    139         foreach my $imfile (@$imfiles) {
    140             my $astromFile;
    141             if ($astromSource eq 'PSASTRO.OUTPUT') {
    142                 my $chipRoot = $imfile->{chip_path_base};
    143                 my $classID = $imfile->{class_id};
    144                 $astromFile = $ipprc->filename($astromSource, $chipRoot, $classID); # Astrometry file
    145             } else {
    146                 $astromFile = $imfile->{chip_uri}; # Astrometry file
    147             }
    148             my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps
    149             if (! @matchlist and $verbose) {
    150                 print "skipping $astromFile\n";
    151             }       
    152            
    153             extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
    154         }
     138        # We have per-imfile astrometry
     139        foreach my $imfile (@$imfiles) {
     140            my $astromFile;
     141            if ($astromSource eq 'PSASTRO.OUTPUT') {
     142                my $chipRoot = $imfile->{chip_path_base};
     143                my $classID = $imfile->{class_id};
     144                $astromFile = $ipprc->filename($astromSource, $chipRoot, $classID); # Astrometry file
     145            } else {
     146                $astromFile = $imfile->{chip_uri}; # Astrometry file
     147            }
     148            my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps
     149            if (! @matchlist and $verbose) {
     150                print "skipping $astromFile\n";
     151            }
     152
     153            extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
     154        }
    155155    }
    156156} else {
    157157    # create an overlap with an entry for each skycell:imfile match
    158158    foreach my $imfile (@$imfiles) {
    159         my %overlap = ();
    160         $overlap{skycell_id} = 'default';
    161         $overlap{tess_id}    = 'default';
    162         $overlap{cam_id}     = $imfile->{cam_id};
    163         $overlap{class_id}   = $imfile->{class_id};
    164         $overlap{fault}      = $imfile->{fault};
    165         push @overlaps, \%overlap;
     159        my %overlap = ();
     160        $overlap{skycell_id} = 'default';
     161        $overlap{tess_id}    = 'default';
     162        $overlap{cam_id}     = $imfile->{cam_id};
     163        $overlap{class_id}   = $imfile->{class_id};
     164        $overlap{fault}      = $imfile->{fault};
     165        push @overlaps, \%overlap;
    166166    }
    167167}
    168168
    169169# XXX this file needs some additional error checking: if no overlaps are found, we
    170 # keep running this step over and over (a successful warptool -addoverlap prevents 
     170# keep running this step over and over (a successful warptool -addoverlap prevents
    171171# successive warptime -imfile from running.
    172172
     
    192192    my $command = "$warptool -addoverlap -mapfile $overlapName"; # Command to run warptool
    193193    $command .= " -dbname $dbname" if defined $dbname;
    194    
     194
    195195    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    196         run(command => $command, verbose => $verbose);
     196        run(command => $command, verbose => $verbose);
    197197    unless ($success) {
    198         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    199         warn("Unable to perform warptool -addoverlap: $error_code\n");
    200         exit($error_code);
     198        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     199        warn("Unable to perform warptool -addoverlap: $error_code\n");
     200        exit($error_code);
    201201    }
    202202}
     
    204204sub my_die
    205205{
    206     my $msg = shift;            # Warning message on die
    207     my $warp_id = shift;        # Warp identifier
    208     my $exit_code = shift;      # Exit code to add
     206    my $msg = shift;            # Warning message on die
     207    my $warp_id = shift;        # Warp identifier
     208    my $exit_code = shift;      # Exit code to add
    209209
    210210    warn($msg);
     
    217217sub get_overlaps
    218218{
    219     my $filename = shift;       # Filename on which to run dvoImageOverlaps
    220     my $tess_dir = shift;       # Tessellation directory
    221     my $accept = shift;         # Do we use the -accept-astrom flag?
     219    my $filename = shift;       # Filename on which to run dvoImageOverlaps
     220    my $tess_dir = shift;       # Tessellation directory
     221    my $accept = shift;         # Do we use the -accept-astrom flag?
    222222
    223223    my $command = "$dvoImageOverlaps -D CATDIR $tess_dir " . $ipprc->file_resolve($filename);
    224224    $command .= ' -accept-astrom' if $accept;
    225225    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    226         run(command => $command, verbose => $verbose);
     226        run(command => $command, verbose => $verbose);
    227227    if (!$success) {
    228         print "Missing astrometry for $filename --- check ASTROM.SOURCE in PSWARP recipe\n";
    229         return 0;
     228        print "Unable to calculate overlaps from $filename\n";
     229        print "STDOUT:\n$stdout_buf\n";
     230        print "STDERR:\n$stderr_buf\n";
     231        return 0;
    230232    }
    231233    return split ('\n', (join "", @$stdout_buf));
    232 }   
     234}
    233235
    234236# Extract a list of overlaps for an imfile
     
    240242sub extract_overlaps
    241243{
    242     my $matches = shift;        # Reference to list of skycells from dvoImageOverlaps
    243     my $imfile = shift;         # Imfile information
    244     my $filename = shift;       # Filename used with dvoImageOverlaps
    245     my $tess_id = shift;        # Tessellation identifier
    246     my $overlaps = shift;       # Reference to list of overlaps
     244    my $matches = shift;        # Reference to list of skycells from dvoImageOverlaps
     245    my $imfile = shift;         # Imfile information
     246    my $filename = shift;       # Filename used with dvoImageOverlaps
     247    my $tess_id = shift;        # Tessellation identifier
     248    my $overlaps = shift;       # Reference to list of overlaps
    247249    my $unique_skycells = shift; # Reference to hash of found skycells
    248250
     
    253255    # Work out how to identify this imfile in the output
    254256    my $fileLevel = $imfile->{filelevel};
    255     my $entry;  # How to identify this imfile in the dvoImageOverlaps output
     257    my $entry;  # How to identify this imfile in the dvoImageOverlaps output
    256258    if ((lc($fileLevel) eq "chip") && (lc($astromDepth) eq "mef")) {
    257         my $class_id = $imfile->{class_id};
    258         my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} );
    259         my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
    260        
    261        
    262         $entry = $filename . '\[' . $extname . '\]';
    263         print STDERR "entry: $entry, class: $class_id, extname: $extname, chiproot: $chipRoot\n" if $verbose;
     259        my $class_id = $imfile->{class_id};
     260        my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} );
     261        my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
     262
     263
     264        $entry = $filename . '\[' . $extname . '\]';
     265        print STDERR "entry: $entry, class: $class_id, extname: $extname, chiproot: $chipRoot\n" if $verbose;
    264266    } else {
    265         $entry = $filename;
    266         print STDERR "entry: $entry\n" if $verbose;
    267     }
    268 
    269     my @skycells = &select_skycells($entry, @$matches); # Matching skycells
     267        $entry = $filename;
     268        print STDERR "entry: $entry\n" if $verbose;
     269    }
     270
     271    my @skycells = &select_skycells($entry, @$matches); # Matching skycells
    270272    my $Nskycells = @skycells;
    271273    printf STDERR "Nskycells: $Nskycells\n" if $verbose;
    272274    foreach my $skycell (@skycells) {
    273         my %overlap = ();       # Overlap information for warptool
    274         $overlap{skycell_id} = $skycell;
    275         $overlap{tess_id}    = $tess_id;
    276         $overlap{cam_id}     = $imfile->{cam_id};
    277         $overlap{class_id}   = $imfile->{class_id};
    278         $overlap{fault}      = $imfile->{fault};
    279         push @$overlaps, \%overlap;
    280        
    281         printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id} if $verbose;
    282        
    283         $unique_skycells->{$skycell} = 1;
     275        my %overlap = ();       # Overlap information for warptool
     276        $overlap{skycell_id} = $skycell;
     277        $overlap{tess_id}    = $tess_id;
     278        $overlap{cam_id}     = $imfile->{cam_id};
     279        $overlap{class_id}   = $imfile->{class_id};
     280        $overlap{fault}      = $imfile->{fault};
     281        push @$overlaps, \%overlap;
     282
     283        printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id} if $verbose;
     284
     285        $unique_skycells->{$skycell} = 1;
    284286    }
    285287
    286288    return;
    287289}
    288    
     290
    289291# Find skycells in the list that come from a particular entry
    290 sub select_skycells 
    291 {
    292     my $entry = shift;          # File+Ext to search for
    293     my @list = @_;              # List of "File+Ext : skycell"
     292sub select_skycells
     293{
     294    my $entry = shift;          # File+Ext to search for
     295    my @list = @_;              # List of "File+Ext : skycell"
    294296
    295297    my @skycells = ();
    296     my %unique = ();            # Ensure we only return unique skycells for this entry
     298    my %unique = ();            # Ensure we only return unique skycells for this entry
    297299
    298300    foreach my $line (@list) {
    299         if ($line =~ m|$entry|) {
    300             my ($skycell) = $line =~ m|$entry\S*\s+:\s+(\S+)|;
    301             if (not defined $unique{$skycell}) {
    302                 push @skycells, $skycell;
    303                 $unique{$skycell} = 1;
    304             }
    305         }
     301        if ($line =~ m|$entry|) {
     302            my ($skycell) = $line =~ m|$entry\S*\s+:\s+(\S+)|;
     303            if (not defined $unique{$skycell}) {
     304                push @skycells, $skycell;
     305                $unique{$skycell} = 1;
     306            }
     307        }
    306308    }
    307309    return @skycells;
Note: See TracChangeset for help on using the changeset viewer.