IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 20, 2007, 2:24:57 PM (19 years ago)
Author:
Paul Price
Message:

Take astrometry file rule from PSWARP recipe, ASTROM.SOURCE. If this value is NULL, then use the imfile as the astrometry source.

File:
1 edited

Legend:

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

    r14511 r14567  
    5959my $dvoImageOverlaps = can_run('dvoImageOverlaps') or (warn "Can't find dvoImageOverlaps" and $missing_tools = 1);
    6060my $dvoImageExtract = can_run('dvoImageExtract') or (warn "Can't find dvoImageExtract" and $missing_tools = 1);
    61 if ($missing_tools) {
     61my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     62if ($missing_tools) {
    6263    warn("Can't find required tools.");
    6364    exit($PS_EXIT_CONFIG_ERROR);
    6465}
     66
     67my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6568
    6669# Get list of component imfiles for exposure
     
    7578        &my_die("Unable to perform warptool -imfile: $error_code", $warp_id, $error_code);
    7679    }
    77 
    78     my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
     80   
    7981    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    8082        &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);
     
    8385}
    8486
     87# Where do we get the astrometry source from?
     88my $astromSource;               # The astrometry source
     89{
     90    my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -";
     91    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     92        run(command => $command, verbose => 1);
     93    unless ($success) {
     94        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     95        &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code);
     96    }
     97    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     98        &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);
     99    $astromSource = metadataLookupStr('ASTROM.SOURCE');
     100}
     101
    85102# Determine the imfile/skycell overlaps
    86103my @overlaps = ();
     
    88105unless ($no_op) {
    89106    # Calculate the overlaps between imfiles and skycells
    90 
     107   
    91108    my $tessellations = $ipprc->tessellations(); # Hash of defined tessellations
    92109    foreach my $tess_id ( keys %$tessellations ) {
     
    99116        my $tess_dir = $ipprc->convert_filename_absolute( $$tessellations{$tess_id} ); # Catdir for DVO
    100117        print STDERR "tessellation: $tess_id, $tess_dir\n";
    101 
    102         my $imfile = $imfiles->[0];
    103         my $camRoot = $imfile->{cam_path_base};
    104         my $psastroFile = $ipprc->filename("PSASTRO.OUTPUT.MEF", $camRoot); # MEF psastro output
    105        
    106         my @dirlist = File::Spec->splitdir( $psastroFile );
    107         my $psastroRootFile = pop @dirlist;
    108         print STDERR "psastroRootFile: $psastroRootFile\n";
    109        
    110         # run the dvoImageOverlaps program to get the overlaps with this image
    111         my $command = "$dvoImageOverlaps -accept-astrom -D CATDIR $tess_dir " . $ipprc->file_resolve($psastroFile);
    112         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    113             run(command => $command, verbose => 1);
    114         unless ($success) {
    115             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    116             &my_die("Unable to perform dvoImageOverlaps: $error_code", $warp_id, $error_code);
    117         }
    118         my @matchlist = split ('\n', (join "", @$stdout_buf));
    119        
    120         # The command "dvoImageOverlaps -accept-astrom -D CATDIR tessellation (megacam)" returns:
    121         # 729534pa.cmf[ccd00.hdr]  :  skycell.051.fits
    122         # PSASTRO.OUTPUT[CMF.HEAD] : SKYCELL
    123         # [CMF.HEAD] is optionally used for MEF files (SIMPLE or MOSAIC)
    124        
    125         # now match the imfiles to this list
    126         my @unique_skycells = ();
    127         my %found_skycells = ();
    128         foreach my $imfile (@$imfiles) {
    129             my $fileLevel = $imfile->{filelevel};
    130             my $entry = "";
    131             if (lc($fileLevel) eq "chip") {
    132                 my $class_id = $imfile->{class_id};
    133                 my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} );
    134                 my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
    135                
    136                 print STDERR "class: $class_id, chiproot: $chipRoot, extname: $extname\n";
    137                
    138                 $entry = $psastroRootFile . '\[' . $extname . '\]';
    139             } else {
    140                 $entry = "$psastroRootFile";
     118       
     119        my %unique_skycells = (); # Identified skycells (all unique by virtue of hash property)
     120       
     121        if ($astromSource and $astromSource ne 'NULL') {
     122            # We have an astrometry file from psastro
     123            my $imfile = $imfiles->[0];
     124            my $camRoot = $imfile->{cam_path_base};
     125            my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file
     126           
     127            my @matchlist = get_overlaps($astromFile, $tess_dir); # List of overlaps
     128           
     129            # Match each of the imfiles to this list
     130            foreach my $imfile (@$imfiles) {
     131                extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
    141132            }
    142 
    143             my @skycells = &select_skycells ($entry, @matchlist);
    144             foreach my $skycell (@skycells) {
    145                 my %overlap = ();
    146                 $overlap{skycell_id} = $skycell;
    147                 $overlap{tess_id}    = $tess_id;
    148                 $overlap{cam_id}     = $imfile->{cam_id};
    149                 $overlap{class_id}   = $imfile->{class_id};
    150                 $overlap{fault}      = $imfile->{fault};
    151                 push @overlaps, \%overlap;
    152                
    153                 printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id};
    154                
    155                 # generate a unique list of the skycells
    156                 unless ($found_skycells{$skycell}) {
    157                     push @unique_skycells, $skycell;
    158                     $found_skycells{$skycell} = 1;
    159                 }
     133        } else {
     134            # We have the imfiles themselves for the WCS
     135            foreach my $imfile (@$imfiles) {
     136                my $astromFile = $imfile->{chip_uri}; # Astrometry file
     137                my @matchlist = get_overlaps($astromFile, $tess_dir); # List of overlaps
     138                extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
    160139            }
    161140        }
    162 
     141       
    163142        # Extract the skycells to images, used as warp templates.
    164         foreach my $skycell_id (@unique_skycells) {
     143        foreach my $skycell_id (keys %unique_skycells) {
    165144            my $skyDir = caturi($workdir, "tess_" . $tess_id, "sky_" . $skycell_id );
    166145            my $skyFile = $ipprc->file_prepare( $skycell_id, $skyDir );
     
    211190    my $command = "$warptool -addoverlap -mapfile $overlapName"; # Command to run warptool
    212191    $command .= " -dbname $dbname" if defined $dbname;
    213 
     192   
    214193    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    215194        run(command => $command, verbose => 1);
     
    233212}
    234213
     214# Run dvoImageOverlaps to get the overlaps; return the output
     215sub get_overlaps
     216{
     217    my $filename = shift;       # Filename on which to run dvoImageOverlaps
     218    my $tess_dir = shift;       # Tessellation directory
     219
     220    my $command = "$dvoImageOverlaps -D CATDIR $tess_dir " . $ipprc->file_resolve($filename);
     221    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     222        run(command => $command, verbose => 1);
     223    unless ($success) {
     224        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     225        &my_die("Unable to perform dvoImageOverlaps: $error_code", $warp_id, $error_code);
     226    }
     227    return split ('\n', (join "", @$stdout_buf));
     228}   
     229
     230# Extract a list of overlaps for an imfile
     231#
     232# The command "dvoImageOverlaps -accept-astrom -D CATDIR tessellation (megacam)" returns:
     233# 729534pa.cmf[ccd00.hdr]  :  skycell.051.fits
     234# PSASTRO.OUTPUT[CMF.HEAD] : SKYCELL
     235# [CMF.HEAD] is optionally used for MEF files (SIMPLE or MOSAIC)
     236sub extract_overlaps
     237{
     238    my $matches = shift;        # Reference to list of skycells from dvoImageOverlaps
     239    my $imfile = shift;         # Imfile information
     240    my $filename = shift;       # Filename used with dvoImageOverlaps
     241    my $tess_id = shift;        # Tessellation identifier
     242    my $overlaps = shift;       # Reference to list of overlaps
     243    my $unique_skycells = shift; # Reference to hash of found skycells
     244
     245    # Get rid of the path
     246    my @dirlist = File::Spec->splitdir( $filename ); # The elements of the full path
     247    $filename = pop @dirlist;
     248
     249    # Work out how to identify this imfile in the output
     250    my $fileLevel = $imfile->{filelevel};
     251    my $entry;  # How to identify this imfile in the dvoImageOverlaps output
     252    if (lc($fileLevel) eq "chip") {
     253        my $class_id = $imfile->{class_id};
     254        my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} );
     255        my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
     256       
     257        print STDERR "class: $class_id, chiproot: $chipRoot, extname: $extname\n";
     258       
     259        $entry = $filename . '\[' . $extname . '\]';
     260    } else {
     261        $entry = $filename;
     262    }
     263
     264    my @skycells = &select_skycells($entry, @$matches); # Matching skycells
     265    foreach my $skycell (@skycells) {
     266        my %overlap = ();       # Overlap information for warptool
     267        $overlap{skycell_id} = $skycell;
     268        $overlap{tess_id}    = $tess_id;
     269        $overlap{cam_id}     = $imfile->{cam_id};
     270        $overlap{class_id}   = $imfile->{class_id};
     271        $overlap{fault}      = $imfile->{fault};
     272        push @$overlaps, \%overlap;
     273       
     274        printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id};
     275       
     276        $unique_skycells->{$skycell} = 1;
     277    }
     278
     279    return;
     280}
     281   
     282# Find skycells in the list that come from a particular entry
    235283sub select_skycells
    236284{
     
    250298        }
    251299    }
    252     @skycells;
     300    return @skycells;
    253301}
    254302
Note: See TracChangeset for help on using the changeset viewer.