IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12863


Ignore:
Timestamp:
Apr 17, 2007, 1:55:48 PM (19 years ago)
Author:
eugene
Message:

setting the tessalation based on the PSWARP recipe, extract skycells

File:
1 edited

Legend:

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

    r12800 r12863  
    2626    $PS_EXIT_DATA_ERROR
    2727    $PS_EXIT_TIMEOUT_ERROR
     28    _mdLookupStr
    2829    );
    2930my $ipprc = PS::IPP::Config->new(); # IPP configuration
     
    4950) unless defined $warp_id
    5051    and defined $camera;
     52
     53$ipprc->define_camera($camera);
    5154
    5255# Look for programs we need
     
    8891}
    8992
     93# determine the imfile/skycell overlaps
     94my @overlaps = ();
     95
    9096unless ($no_op) {
    9197    ## Calculate the overlaps between imfiles and skycells
    9298
    93     # XXX where does the catdir come from (recipe file for pswarp?)
    9499    # the tess_id is the catdir used to define the tessalation
    95     $tess_id = $catdir;
     100    my $command = "ppConfigDump -camera $camera -dump-recipe PSWARP -";
     101    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     102        run(command => $command, verbose => 1);
     103    unless ($success) {
     104        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     105        &my_die("Unable to perform ppConfigDump: $error_code", $error_code);
     106    }
     107    my $parser = PS::IPP::Metadata::Config->new;        # Parser for metadata config files
     108    my $recipe = $parser->parse( join '', @$stdout_buf);
     109    my $tess_id = _mdLookupStr($recipe, 'DVO.TESSALATION');
     110    print STDERR "tessalation: $tess_id\n";
     111
    96112    # we have two options for the astrometry file:
    97113    # - saved by chiptool, in which case there may be a different one for each imfile
    98114    # - saved by camtool, in which case there may only be a single astrom file
    99115    my $psastroFile;
     116
     117    # XXX select this value from the recipe files (psastro? maybe not...?)
    100118    my $camAstrom = 1;
    101119    if ($camAstrom) {
     
    103121        my $camRoot = $ipprc->convert_filename_absolute( $imfile->{cam_path_base} );
    104122        $psastroFile = $ipprc->filename("PSASTRO.OUTPUT", $camRoot); # MEF psastro output
     123
     124        my @dirlist = File::Spec->splitdir( $psastroFile );
     125        my $psastroRootFile = pop @dirlist;
     126        print STDERR "psastroRootFile: $psastroRootFile\n";
    105127
    106128        # run the dvoImageOverlaps program to get the overlaps with this image
     
    112134            &my_die("Unable to perform dvoImageOverlaps: $error_code", $warp_id, $error_code);
    113135        }
    114         my @matchlist = split ('\n', $stdout_buf);
     136        my @matchlist = split ('\n', (join "", @$stdout_buf));
     137
     138        #my $Nmatch = @matchlist;
     139        #print STDERR "Nmatch: $Nmatch\n";
     140        #foreach my $line (@matchlist) {
     141        #    print STDERR "line: $line\n";
     142        #}
    115143
    116144        # dvoImageOverlaps -D CATDIR tessalation (megacam) :: returns:
     
    120148
    121149        # now match the imfiles to this list
    122         my @overlaps = ();
    123         foreach $imfile (@$imfiles) {
    124             my $class_id = $imfile->{class_id};
    125             my $chipRoot = $ipprc->convert_filename_absolute( $imfile->{chip_path_base} );
    126             my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
    127            
    128             my $entry = "$psastroFile\[$extname\]";
     150        my @unique_skycells = ();
     151        my %found_skycells = ();
     152        foreach my $imfile (@$imfiles) {
     153            my $fileLevel = $imfile->{filelevel};
     154            my $entry = "";
     155            if ($fileLevel eq "chip") {
     156                my $class_id = $imfile->{class_id};
     157                my $chipRoot = $ipprc->convert_filename_absolute( $imfile->{chip_path_base} );
     158                my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
     159               
     160                print STDERR "class: $class_id, chiproot: $chipRoot, extname: $extname\n";
     161
     162                $entry = "$psastroRootFile\[$extname\]";
     163            } else {
     164                $entry = "$psastroRootFile";
     165            }
    129166            my @skycells = &select_skycells ($entry, @matchlist);
    130             foreach $skycell (@skycells) {
     167            foreach my $skycell (@skycells) {
    131168                my %overlap = ();
    132169                $overlap{skycell_id} = $skycell;
    133                 $overlap{tess_id}    = $catdir;
     170                $overlap{tess_id}    = $tess_id;
    134171                $overlap{cam_id}     = $imfile->{cam_id};
    135172                $overlap{class_id}   = $imfile->{class_id};
    136173                $overlap{fault}      = $imfile->{fault};
    137                 push @overlaps \$overlap;
     174                push @overlaps, \%overlap;
     175
     176                printf STDERR "overlap: %s : %s\n", $skycell, $imfile->{cam_id};
     177
     178                # generate a unique list of the skycells
     179                unless ($found_skycells{$skycell}) {
     180                    push @unique_skycells, $skycell;
     181                    $found_skycells{$skycell} = 1;
     182                }
    138183            }
    139184        }
     185
     186        # extract the skycells to names of the form $camRoot.skycell...
     187        # with calls to dvoImageExtract
     188        my $skycellDir = "$camRoot/skycells";
     189        system "mkdir -p $skycellDir" unless -d $skycellDir;
     190
     191        foreach my $skycell (@unique_skycells) {
     192            vsystem ("dvoImageExtract -D CATDIR $tess_id $skycell -o $skycellDir/$skycell");
     193        }
     194
    140195    } else {
    141         my @overlaps = ();
    142         foreach $imfile (@$imfiles) {
     196        foreach my $imfile (@$imfiles) {
    143197            my $class_id = $imfile->{class_id};
    144198            my $chipRoot = $ipprc->convert_filename_absolute( $imfile->{chip_path_base} );
     
    163217            my @skycells = &select_skycells ($psastroFile, @matchlist);
    164218            # XXX should I check and warn if int(@skycells) != int(@matchlist) ?
    165             foreach $skycell (@skycells) {
     219            foreach my $skycell (@skycells) {
    166220                my %overlap = ();
    167221                $overlap{skycell_id} = $skycell;
    168                 $overlap{tess_id}    = $catdir;
     222                $overlap{tess_id}    = $tess_id;
    169223                $overlap{cam_id}     = $imfile->{cam_id};
    170224                $overlap{class_id}   = $imfile->{class_id};
    171225                $overlap{fault}      = $imfile->{fault};
    172                 push @overlaps \$overlap;
     226                push @overlaps, \%overlap;
     227
     228                print STDERR "overlap: $skycell -> $imfile->{cam_id}\n";
    173229            }
    174230        }
     
    176232} else {
    177233    # create an overlap with an entry for each skycell:imfile match
    178     my @overlaps = ();
    179234    foreach my $imfile (@$imfiles) {
    180235        my %overlap = ();
     
    184239        $overlap{class_id}   = $imfile->{class_id};
    185240        $overlap{fault}      = $imfile->{fault};
    186         push @overlaps \$overlap;
     241        push @overlaps, \%overlap;
    187242    }
    188243}
     
    247302    my @list = @_;
    248303
     304    my $skycell;
    249305    my @skycells = ();
    250306
    251307    foreach my $line (@list) {
    252308        if ($line =~ m|$entry|) {
    253             ($skycell) = $line =~ m|$entry\s+:\s+(\S+)|;
     309            ($skycell) = $line =~ m|$entry\S*\s+:\s+(\S+)|;
    254310            push @skycells, $skycell;
    255311        }
    256312    }
    257     return @skycells;
     313    @skycells;
     314}
     315
     316sub vsystem {
     317    print STDERR "@_\n";
     318    my $status = system ("@_");
     319    $status;
    258320}
    259321
Note: See TracChangeset for help on using the changeset viewer.