IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 31, 2008, 4:54:16 PM (18 years ago)
Author:
bills
Message:

At each stage save the lists of various input files to a file.
These will be conatenated together to build the
input lists for subsequent stages.
Various other changes to adapt to the new interface for RemoveStreaks

File:
1 edited

Legend:

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

    r18784 r20495  
    1515
    1616use IPC::Cmd 0.36 qw( can_run run );
     17use File::Temp qw( tempfile );
    1718use PS::IPP::Metadata::Config;
    1819use PS::IPP::Metadata::List qw( parse_md_list );
     
    3031# Parse the command-line arguments
    3132my ($magic_id, $node, $camera, $dbname, $outroot, $save_temps, $verbose, $no_update, $no_op, $redirect);
     33my $skycellroot;
    3234GetOptions(
    3335           'magic_id=s'      => \$magic_id,   # Magic identifier
     
    4143           'no-op'           => \$no_op,      # Don't do any operations?
    4244           'redirect-output' => \$redirect,   # Redirect output?
     45           'skycellroot=s'   => \$skycellroot, # root of the warps to find skycells (temporary)
    4346           ) or pod2usage( 2 );
    4447
     
    5356$ipprc->define_camera($camera);
    5457
     58# Remove streaks doesn't know about nebulous. It expects to be able to append strings to outroot
     59# to form valid file names.
     60# So forbid nebulous path in outroot. We could relax this by change RemoveStreaks to take all
     61# of the file names as arguments
     62if ($outroot =~ 'neb:/') {
     63    &my_die("RemoveStreaks does not support nebulous paths in outroot", $magic_id, $node,
     64        $PS_EXIT_CONFIG_ERROR);
     65}
     66
     67# resolve any path:// or file:// in outroot
     68$outroot = $ipprc->file_resolve($outroot);
     69   
     70
    5571my $logDest = $ipprc->filename("LOG.EXP", $outroot, $magic_id) or
    5672    &my_die("Missing entry from camera config", $magic_id, $PS_EXIT_CONFIG_ERROR);
     
    88104
    89105
     106my @outputs = ("${outroot}.clusters", "${outroot}_hough.fits", "${outroot}.streaks");
    90107### Do the heavy lifting
    91 my @basenames;                  # Base names of inputs
    92 {
     108{
     109    my $mode;
    93110    my $command;                # Command to execute
     111    $command = "$streaks --outroot $outroot";
    94112    if (scalar @$inputs == 1 and $node ne "root") {
     113        #
     114        #  RemoveStreak --detect --image filename --mask maskname --weight weightname --outroot path_base
     115        #
    95116        # Leaf node: 'detect' stage
    96         $command = "$streaks --detect";
    97 
    98         my $node = $$inputs[0];     # Input node
    99         push @basenames, $ipprc->file_resolve( $node->{path_base} );
     117        $mode = 'detect';
     118        my $innode = $$inputs[0];     # Input node
     119
     120        my ($image, $mask, $weight) = resolve_inputs($innode);
     121
     122        $command .= " --detect --image $image --mask $mask --weight $weight";
     123
     124        # create the list of inputs used at this stage. At higher levels the
     125        # thes files will get catenated together to create the file for the subsquent stage
     126       
     127        my ($ifh, $image_list)  = open_list_file($outroot, "image.list");
     128        print $ifh "$image\n";
     129        close $ifh;
     130        my ($mfh, $mask_list)   = open_list_file($outroot, "mask.list");
     131        print $mfh "$mask\n";
     132        close $mfh;
     133        my ($wfh, $weight_list) = open_list_file($outroot, "weight.list");
     134        print $wfh "$weight\n";
     135        close $wfh;
     136
     137        # work around missing wcs in difference images. Use the skycells from warp stage
     138        my ($sfh, $skycell_list);
     139        if ($skycellroot) {
     140           ($sfh, $skycell_list) = open_list_file($outroot, "wcs.list");
     141            # at this level the skycell_id is equal to the node
     142            my $skycell_id = $node;
     143            my $skycell = $ipprc->file_resolve("${skycellroot}.${skycell_id}.skycell");
     144            print $sfh "$skycell\n";
     145            close $sfh;
     146        }
    100147    } else {
     148        #
     149        # RemoveStreak --merge --inputs input.list --images image0_1.list \
     150        #                      --masks mask0_1.list --weight weights0_1.list
     151        #                      --outroot outroot
     152
    101153        # Branch node: 'merge' stage
    102         $command = "$streaks --merge";
    103 
    104         # Concatenate the names
    105         foreach my $node (@$inputs) {
    106             push @basenames, $ipprc->file_resolve( $node->{path_base} );
    107         }
    108     }
    109 
    110     $command .= ' ' . join(' ', @basenames);
     154        $mode = 'merge';
     155
     156        my ($infh, $input_list) = open_list_file($outroot, "input.list");
     157        my ($ifh, $image_list)  = open_list_file($outroot, "image.list");
     158        my ($mfh, $mask_list)   = open_list_file($outroot, "mask.list");
     159        my ($wfh, $weight_list) = open_list_file($outroot, "weight.list");
     160        my ($sfh, $skycell_list);
     161        if ($skycellroot) {
     162           ($sfh, $skycell_list) = open_list_file($outroot, "wcs.list");
     163        }
     164
     165        eval {
     166            foreach my $innode (@$inputs) {
     167                my ($image, $mask, $weight) = resolve_inputs($innode);
     168
     169                my $in_uri = $innode->{uri};
     170
     171                print $infh "$in_uri\n";
     172                cat_list_to_list($ifh, $in_uri, "image.list");
     173                cat_list_to_list($mfh, $in_uri, "mask.list");
     174                cat_list_to_list($wfh, $in_uri, "weight.list");
     175                cat_list_to_list($sfh, $in_uri, "wcs.list") if $skycell_list;
     176
     177            }
     178            close $infh;
     179            close $ifh;
     180            close $mfh;
     181            close $wfh;
     182            close $sfh if $skycell_list;
     183
     184            $command .= " --merge --inputs $input_list";
     185            $command .= " --images $image_list --masks $mask_list --weights $weight_list" ;
     186            $command .= " --wcsList $skycell_list" if $skycell_list;
     187        };
     188        if ($@) {
     189            &my_die("failed to create file lists: $@", $PS_EXIT_UNKNOWN_ERROR, $magic_id, $node,
     190                $PS_EXIT_UNKNOWN_ERROR);
     191        }
     192    }
    111193
    112194    unless ($no_op) {
     195        # RemoveStreaks fails if the output file already exists
     196        foreach my $output (@outputs) {
     197            unlink($output) if -e $output;
     198        }
     199
    113200        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    114201            run(command => $command, verbose => $verbose);
     
    118205        }
    119206
    120         foreach my $basename (@basenames) {
    121             file_check( $basename . '.clusters' );
    122             file_check( $basename . '.streaks' );
    123             file_check( $basename . '_hough.fits' );
     207        foreach my $output (@outputs) {
     208            file_check( $output );
    124209        }
    125210    } else {
     
    154239
    155240### Pau.
     241
     242sub open_list_file {
     243    my $outroot = shift;
     244    my $extension = shift;
     245
     246    my $filename = "$outroot.$extension";
     247
     248    my $fh;
     249    open $fh, ">$filename" or die "failed to open list file $filename";
     250
     251    return ($fh, $filename);
     252}
     253
     254sub cat_list_to_list   { # ($infh, $in_uri, "input.list");
     255    my $out = shift;        # output file handle
     256    my $uri = shift;        # uri to append ...
     257    my $extension = shift;  # extension to
     258    my $filename = "$uri.$extension";
     259
     260    my $in;
     261    open $in, "<$filename" or die "failed to open list file: $filename";
     262    my $contents = <$in>;
     263    print $out $contents;
     264}
     265
     266sub resolve_inputs {
     267    my $node = shift;
     268    my $input_base = $node->{path_base};
     269    my $image = $ipprc->file_resolve($ipprc->filename("PPSUB.OUTPUT", $input_base));
     270    my $mask  = $ipprc->file_resolve($ipprc->filename("PPSUB.OUTPUT.MASK", $input_base));
     271    my $weight= $ipprc->file_resolve($ipprc->filename("PPSUB.OUTPUT.WEIGHT", $input_base));
     272
     273    return ($image, $mask, $weight);
     274}
    156275
    157276sub file_check
Note: See TracChangeset for help on using the changeset viewer.