IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 11, 2009, 3:54:00 PM (17 years ago)
Author:
watersc1
Message:

Bringing branch up-to-date at revision 25049

Location:
branches/czw_branch/cleanup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup

  • branches/czw_branch/cleanup/ippScripts/scripts/magic_destreak.pl

    r24951 r25051  
    3838
    3939# Parse the command-line arguments
    40 my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $inverse, $cam_path_base);
     40my ($magic_ds_id, $camera, $streaks, $inv_streaks, $stage, $stage_id, $component, $uri, $path_base, $cam_path_base);
    4141my ($outroot, $recoveryroot);
    4242my ($replace, $release);
     
    4747           'camera=s'       => \$camera,     # camera for evaluating file rules
    4848           'streaks=s'      => \$streaks,    # file containing the list of streaks
     49           'inv_streaks=s'  => \$inv_streaks,# file containing the list of streaks from the inverse diff
    4950           'stage=s'        => \$stage,      # raw, chip, warp, or diff
    5051           'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
     
    5253           'uri=s'          => \$uri,        # uri of the input image
    5354           'path_base=s'    => \$path_base,  # path_base of the input
    54            'inverse'        => \$inverse,    # Inverse subtraction?
    5555           'cam_path_base=s'=> \$cam_path_base,  # path_base from camera stage (for chip and raw)
    5656           'outroot=s'      => \$outroot,     # "directory" for temporary images (may be nebulous)
     
    9494} elsif ($stage ne "camera") {
    9595    &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    96 }
     96}   
     97$inv_streaks = undef if defined($inv_streaks) and ($inv_streaks eq "NULL");
    9798
    9899my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    205206
    206207    my ($image, $mask, $ch_mask, $weight, $astrom, $sources);
     208
     209    # if we're destreaking a bothways diff need to combine the
     210    # two streaks files
     211    my ($allstreaks_fh, $allstreaks_name);
    207212
    208213    if ($stage eq "raw") {
     
    234239        $sources    = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $path_base);
    235240    } elsif ($stage eq "diff") {
    236         my $name = $inverse ? "PPSUB.INVERSE" : "PPSUB.OUTPUT"; # Base name for images
    237         $image  = $ipprc->filename($name, $path_base);
    238         $mask   = $ipprc->filename("$name.MASK", $path_base);
    239         $weight = $ipprc->filename("$name.VARIANCE", $path_base);
     241        $image  = $ipprc->filename("PPSUB.OUTPUT", $path_base);
     242        $mask   = $ipprc->filename("PPSUB.OUTPUT.MASK", $path_base);
     243        $weight = $ipprc->filename("PPSUB.OUTPUT.VARIANCE", $path_base);
    240244        $sources    = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $path_base);
     245
     246        if ($inv_streaks) {
     247            # create a temporary file containing the contents of the
     248            # two streaks files
     249            ($allstreaks_fh, $allstreaks_name) = tempfile ("/tmp/all.streaks.XXXX",
     250                    UNLINK => !$save_temps);
     251
     252            combine_streaks($allstreaks_fh, $streaks, $inv_streaks);
     253
     254            # apply the combined streaks to both the forward and inverse diffs
     255            $streaks = $allstreaks_name;
     256        }
    241257    }
    242258
     
    266282        }
    267283    }
     284    if (($stage eq "diff") and $inv_streaks) {
     285        $image   = $ipprc->filename("PPSUB.INVERSE", $path_base);
     286        $mask    = $ipprc->filename("PPSUB.INVERSE.MASK", $path_base);
     287        $weight  = $ipprc->filename("PPSUB.INVERSE.VARIANCE", $path_base);
     288        $sources = $ipprc->filename("PPSUB.INVERSE.SOURCES", $path_base);
     289
     290        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
     291
     292        $command .= " -recovery $recoveryroot" if defined $recoveryroot;
     293        $command .= " -mask $mask" if defined $mask;
     294        $command .= " -weight $weight" if defined $weight;
     295        $command .= " -sources $sources" if defined $sources;
     296        $command .= " -replace" if $replace;
     297        $command .= " -release" if $release;
     298        $command .= " -dbname $dbname" if defined $dbname;
     299        unless (defined $no_op) {
     300            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     301                run(command => $command, verbose => $verbose);
     302            unless ($success) {
     303                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     304                &my_die("Unable to perform streaksremove: $error_code", $magic_ds_id, $component, $error_code);
     305            }
     306        } else {
     307            print "skipping command $command\n";
     308        }
     309    }
    268310} else {
    269311    # camera stage. The only work to do is to censor the detections file
     
    376418}
    377419
     420sub combine_streaks
     421{
     422    my $fout = shift;
     423    my $fn1 = shift;
     424    my $fn2 = shift;
     425
     426    my ($n1, @streaks1) = read_streaks_file($fn1);
     427    my_die("failed to read streaks from $fn1", $magic_ds_id, $component,
     428        $PS_EXIT_UNKNOWN_ERROR) if $n1 < 0;
     429
     430    my ($n2, @streaks2) = read_streaks_file($fn2);
     431    my_die("failed to read streaks from $fn2", $magic_ds_id, $component,
     432        $PS_EXIT_UNKNOWN_ERROR) if $n2 < 0;
     433
     434    print $fout $n1 + $n2 . "\n";
     435
     436    foreach my $line (@streaks1, @streaks2) {
     437        print $fout $line;
     438    }
     439
     440    close $fout
     441        or my_die("failed to close combined streaks file", $magic_ds_id,
     442                     $component, $PS_EXIT_UNKNOWN_ERROR);
     443}
     444
     445sub read_streaks_file
     446{
     447    my $filename = shift;
     448    my $fh;
     449    open $fh, "<$filename" or my_die("failed to open $filename",
     450                    $magic_ds_id, $component, $PS_EXIT_UNKNOWN_ERROR);
     451
     452    # first line is the number of streaks
     453    my $line = <$fh>;
     454    chomp $line;
     455    my $nstreaks = $line;
     456
     457    my @streaks;
     458
     459    foreach $line (<$fh>) {
     460        push @streaks, $line;
     461    }
     462
     463    close $fh;
     464
     465    return ($nstreaks, @streaks);
     466}
     467
    378468
    379469sub my_die
Note: See TracChangeset for help on using the changeset viewer.