IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 5, 2010, 10:16:10 AM (16 years ago)
Author:
Paul Price
Message:

Merging branches/pap_delete/ into trunk after successful testing. This provides automatic deletion of the convolved images from the diff stage.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/ippScripts/scripts/magic_process.pl

    r27240 r27596  
    3030my $missing_tools;
    3131my $magictool      = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
     32my $difftool       = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
     33my $ppSubConvolve = can_run('ppSubConvolve') or (warn "Can't find ppSubConvolve" and $missing_tools = 1);
    3234my $detectstreaks = can_run('DetectStreaks') or (warn "Can't find DetectStreaks" and $missing_tools = 1);
    3335my $VerifyStreaks = can_run('VerifyStreaks') or (warn "Can't find VerifyStreaks, will not produce png images");
     
    8082$baseroot = $ipprc->file_resolve($baseroot);
    8183my $outroot = "$baseroot.$node";
     84$ipprc->outroot_prepare($outroot);
    8285
    8386my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    116119    $command .= " --threshold 2.35";
    117120
     121    my @deletions;          # Files to delete
    118122    if (scalar @$inputs == 1 and $node ne "root") {
    119123        #
     
    135139        }
    136140
    137         my $template = resolve_template($innode);
    138         &my_die("failed to resolve template", $magic_id, $node, $PS_EXIT_DATA_ERROR)
    139             unless defined $template;
     141        my $diff_base = $innode->{diff_path_base}; # Base name for diff
     142        my $tempName = $innode->{inverse} ? "PPSUB.INPUT.CONV" : "PPSUB.REF.CONV"; # File rule of interest
     143        my $template = $ipprc->file_resolve($ipprc->filename($tempName, $diff_base));
     144        &my_die("failed to resolve template", $magic_id, $node, $PS_EXIT_DATA_ERROR) unless defined $template;
     145
     146        # Delete the convolved products when done (we can recreate them as we need)
     147        push @deletions, $template;
     148        push @deletions, $ipprc->filename($tempName . ".MASK", $diff_base);
     149        push @deletions, $ipprc->filename($tempName . ".VARIANCE", $diff_base);
     150
     151        unless ($ipprc->file_exists($template)) {
     152            # Template doesn't exist (or can't be found); try to recreate it
     153            my $tempPath = "/tmp/magic.$magic_id.$node.template";
     154
     155            my $kernel = $ipprc->filename("PPSUB.OUTPUT.KERNELS", $diff_base); # Name of kernel file
     156            &my_die("Unable to find kernel file", $magic_id, $node, $PS_EXIT_DATA_ERROR) unless $ipprc->file_exists($kernel);
     157
     158            my ($image, $mask);   # Image and mask
     159            {
     160                my $command = "$difftool -inputskyfile -diff_id $diff_id -skycell_id $node"; # Command to run
     161                $command .= " -dbname $dbname" if defined $dbname;
     162                if ($innode->{inverse}) {
     163                    # Want the input because we're magicking the reference
     164                    $command .= " -input";
     165                } else {
     166                    # Want the reference because we're magicking the input
     167                    $command .= " -template";
     168                }
     169
     170                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     171                    run(command => $command, verbose => $verbose);
     172                unless ($success) {
     173                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     174                    &my_die("Unable to determine convolution inputs: $error_code", $magic_id, $node, $error_code);
     175                }
     176
     177                my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     178                    &my_die("Unable to parse metadata config doc", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     179
     180                my $inputs = parse_md_list($metadata) or
     181                    &my_die("Unable to parse metadata list", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     182                &my_die("Unexpected number of outputs", $magic_id, $node, $PS_EXIT_PROG_ERROR) unless scalar @$inputs == 1;
     183                my $input = $$inputs[0];
     184                my $path = $input->{path_base}; # Path of interest
     185                if (defined $input->{warp_id} and $input->{warp_id} > 0) {
     186                    $image = $ipprc->filename("PSWARP.OUTPUT", $path);
     187                    $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path);
     188                } elsif (defined $input->{stack_id} and $input->{stack_id} > 0) {
     189                    $image = $ipprc->filename("PPSTACK.UNCONV", $path);
     190                    $mask = $ipprc->filename("PPSTACK.UNCONV.MASK", $path);
     191                }
     192                &my_die("Unable to determine image and mask name", $magic_id, $node, $PS_EXIT_PROG_ERROR) unless defined $image and defined $mask;
     193            }
     194
     195            {
     196                &my_die("Unable to find image and mask", $magic_id, $node, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($image) and $ipprc->file_exists($mask);
     197
     198                my $command = "$ppSubConvolve $tempPath -image $image -mask $mask -kernel $kernel";
     199                $command .= " -reference" unless $innode->{inverse};
     200                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     201                    run(command => $command, verbose => $verbose);
     202                unless ($success) {
     203                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     204                    &my_die("Unable to create template image: $error_code", $magic_id, $node, $error_code);
     205                }
     206
     207                $template = $ipprc->filename("PPSUB.INPUT.CONV", $tempPath) or &my_die("Unable to determine filename for created template", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     208                $template = $ipprc->file_resolve($template) or &my_die("Unable to resolve filename for created template", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     209                &my_die("Unable to find created template", $magic_id, $node, $PS_EXIT_PROG_ERROR) unless $ipprc->file_exists($template);
     210                push @deletions, $template;
     211            }
     212        }
    140213
    141214        $command .= " --detect --image $image --mask $mask --weight $weight -k $template";
     
    223296            file_check( $output );
    224297        }
     298
     299        foreach my $file (@deletions) {
     300            print "Deleting $file...\n";
     301            $ipprc->file_delete($file);
     302        }
     303
    225304    } else {
    226305        print "Skipping command: $command\n";
    227306    }
     307
    228308}
    229309
     
    387467}
    388468
    389 sub resolve_template
    390 {
    391     my $node = shift;
    392 
    393     my $path_base = $node->{diff_path_base}; # Base name for name
    394     my $image = $node->{inverse} ? "PPSUB.INPUT.CONV" : "PPSUB.REF.CONV"; # File rule of interest
    395 
    396     $image = $ipprc->file_resolve($ipprc->filename($image, $path_base));
    397 
    398     return $image
    399 }
    400 
    401469sub file_check
    402470{
Note: See TracChangeset for help on using the changeset viewer.