IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29501


Ignore:
Timestamp:
Oct 20, 2010, 3:38:35 PM (16 years ago)
Author:
bills
Message:

merge in new magic scripts

Location:
tags/ipp-20100823/ippScripts/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-20100823/ippScripts/scripts/magic_destreak.pl

    r28931 r29501  
    4242# Parse the command-line arguments
    4343my ($magic_ds_id, $camera, $streaks, $inv_streaks, $exp_id, $stage, $stage_id, $component, $uri, $path_base, $cam_path_base, $cam_reduction);
     44my ($streaks_path_base, $inv_streaks_path_base);
    4445my ($outroot, $recoveryroot, $magicked);
    4546my ($replace, $release);
     
    4950           'magic_ds_id=s'  => \$magic_ds_id,# Magic destreak run identifier
    5051           'camera=s'       => \$camera,     # camera for evaluating file rules
     52           'streaks_path_base=s'      => \$streaks_path_base,    # path_base for streaks data
     53           'inv_streaks_path_base=s'  => \$inv_streaks_path_base, #path_base for streaks from inverse diff
     54           'inv_streaks=s'  => \$inv_streaks,# file containing the list of streaks from the inverse diff
    5155           'streaks=s'      => \$streaks,    # file containing the list of streaks
    5256           'inv_streaks=s'  => \$inv_streaks,# file containing the list of streaks from the inverse diff
     
    7882    defined $camera and
    7983    defined $streaks and
     84    defined $streaks_path_base and
    8085    defined $stage and
    8186    defined $stage_id and
     
    108113    &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    109114}
     115$inv_streaks_path_base = undef if defined($inv_streaks_path_base) and ($inv_streaks_path_base eq "NULL");
    110116$inv_streaks = undef if defined($inv_streaks) and ($inv_streaks eq "NULL");
    111117
     
    240246    my ($allstreaks_fh, $allstreaks_name);
    241247
     248    # Set name of streaks files from their path_base. Note. ne 'NULL' test is for backward compatability
     249    # with runs that don't have path_base set yet
     250    if ($streaks_path_base ne 'NULL') {
     251        $streaks = "$streaks_path_base.streaks";
     252    }
     253    if ($inv_streaks_path_base and ($inv_streaks_path_base ne 'NULL')) {
     254        $inv_streaks = "$inv_streaks_path_base.streaks";
     255    }
     256
     257    my $streaks_resolved = $ipprc->file_resolve($streaks) or &my_die("failed to resolve streaks file $streaks", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR);
     258    my $inv_streaks_resolved;
     259    if ($inv_streaks) {
     260        $inv_streaks_resolved = $ipprc->file_resolve($inv_streaks) or &my_die("failed to resolve inverse streaks file $inv_streaks", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR);
     261    }
     262       
     263
    242264    if ($stage eq "raw") {
    243265        $image = $uri;
     
    301323        $sources    = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $path_base);
    302324
    303         if ($inv_streaks) {
     325        if ($inv_streaks_resolved) {
    304326            # create a temporary file containing the contents of the
    305327            # two streaks files
     
    307329                    UNLINK => !$save_temps);
    308330
    309             combine_streaks($allstreaks_fh, $streaks, $inv_streaks);
     331            combine_streaks($allstreaks_fh, $streaks_resolved, $inv_streaks_resolved);
    310332
    311333            # apply the combined streaks to both the forward and inverse diffs
    312             $streaks = $allstreaks_name;
     334            $streaks_resolved = $allstreaks_name;
    313335        }
    314336    }
    315337
    316338    {
    317         my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
     339        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks_resolved -image $image";
    318340
    319341        $command .= " -stats $statsFile";
     
    340362        }
    341363    }
    342     if (($stage eq "diff") and $inv_streaks) {
     364    if (($stage eq "diff") and $inv_streaks_resolved) {
    343365        $image   = $ipprc->filename("PPSUB.INVERSE", $path_base);
    344366        $mask    = $ipprc->filename("PPSUB.INVERSE.MASK", $path_base);
     
    349371        my $invStatsFile = "$outroot/$exp_id.mds.$magic_ds_id.$stage_id.$component.inv.stats";
    350372
    351         my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
     373        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks_resolved -image $image";
    352374        $command .= " -stats $invStatsFile";
    353375
  • tags/ipp-20100823/ippScripts/scripts/magic_process.pl

    r28137 r29501  
    1717use IPC::Cmd 0.36 qw( can_run run );
    1818use File::Temp qw( tempfile );
     19use File::Copy;
    1920use PS::IPP::Metadata::Config;
    2021use PS::IPP::Metadata::List qw( parse_md_list );
     
    4142
    4243# Parse the command-line arguments
    43 my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile);
     44my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile, $final_outroot);
    4445
    4546GetOptions(
     
    4950           'dbname=s'        => \$dbname,     # Database name
    5051           'baseroot=s'      => \$baseroot,   # Output root name
     52           'final-outroot=s' => \$final_outroot,   # location for final outputs
    5153           'save-temps'      => \$save_temps, # Save temporary files?
    5254           'verbose'         => \$verbose,    # Print stuff?
     
    8688
    8789my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     90
     91# list of VerifyStreaks input and output files to copy to nebulous
     92my @verify_outputs = qw(
     93clusterPos.txt
     94duplicate.png
     95mask.png
     96original.png
     97original.fits
     98residual.png
     99residual.fits
     100clusters.list
     101);
    88102
    89103### Get a list of inputs
     
    311325}
    312326
    313 
    314327### Input result into database
    315328{
     
    334347
    335348if ($node eq "root") {
     349    # XXXX: Since we just added the result above, all of these my_dies are going to fail
     350    # with a duplicate row error.
     351    # see more comments below
    336352    my $streaks_file = "$outroot.streaks";
    337353    my $resolved = $ipprc->file_resolve($streaks_file);
     
    349365    }
    350366
    351     &run_verifystreaks($baseroot);
    352367
    353368    my $exp_id;                 # Exposure identifier
     
    366381    }
    367382
     383    &run_verifystreaks($baseroot, $exp_id);
     384
    368385    {
    369386        my $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path); # Astrometry file
     
    383400    }
    384401
     402    my $output_streaks = $final_outroot . ".streaks";
     403    if ($output_streaks and ($output_streaks ne $streaks_file)) {
     404        copy_to_nebulous($ipprc, $streaks_file, $output_streaks, 1);
     405        foreach my $f (@verify_outputs) {
     406            my $src = "$baseroot.verify/${exp_id}_$f";
     407            my $dest = "$final_outroot.${f}";
     408            copy_to_nebulous($ipprc, $src, $dest, 1);
     409        }
     410    } else {
     411        $output_streaks = $streaks_file;
     412    }
    385413
    386414    {
    387415        my $command = "$magictool -addmask";
    388416        $command   .= " -magic_id $magic_id";
    389         $command   .= " -uri $streaks_file";
     417        $command   .= " -uri $final_outroot";
    390418        $command   .= " -streaks $num_streaks";
    391419        $command   .= " -dbname $dbname" if defined $dbname;
     
    397425            unless ($success) {
    398426                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    399                 # This isn't going to work because our result was already entered.
     427                # XXX: This my_die isn't going to work because the result for the root node was already
     428                # added to the database up above.
     429                # There is a magicMask has a fault column. Maybe we should
     430                # use that and add a new revert mode that deletes the magicMask and the magicNodeResult
     431                # for the root node.
    400432                &my_die("Unable to perform magictool -addmask: $error_code", $magic_id, $node, $error_code);
    401433            }
     
    406438}
    407439
     440
    408441### Pau.
    409442
     
    411444
    412445    my $baseroot = shift;
     446    my $exp_id = shift;
    413447
    414448    unless ($VerifyStreaks) {
     
    431465    my @files = <$baseroot.*.clusters>;
    432466
    433     unless (open ($FILE, ">$outdir/clusters.list")) {
    434         print "failed to create cluster file $outdir/clusters.list\n";
     467    my $clusters_list = "$outdir/${exp_id}_clusters.list";
     468    unless (open ($FILE, ">$clusters_list")) {
     469        print "failed to create cluster file $clusters_list\n";
    435470        return 1;
    436471    }
     
    441476    close ($FILE);
    442477    if ($status) {
    443         print "failed to create cluster file $outdir/clusters.list\n";
     478        print "failed to create cluster file $clusters_list\n";
    444479        return 1;
    445480    }
    446481
    447     my $command = "$VerifyStreaks --out $outdir --clusters $outdir/clusters.list $baseroot.root.streakMap";
     482    my $command = "$VerifyStreaks --out $outdir --clusters $clusters_list $baseroot.root.streakMap";
    448483
    449484    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    513548}
    514549
     550# Copy a file to nebulous and optionally replicate it
     551# We should consider making this an ipprc function. For now try it here so we can print
     552# the right error messages
     553sub copy_to_nebulous {
     554    my $ipprc = shift;
     555    my $src = shift;
     556    my $dest = shift;
     557    my $replicate = shift;
     558
     559    print "copying $src to $dest\n";
     560
     561    $ipprc->file_exists($src) or
     562        &my_die("expected output file does not exist: $src", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     563
     564    # copy the file to it's final destination - which is presumably in nebulous
     565    # we delete it so that all instances are deleted in case it has been replicated
     566    if ($ipprc->file_exists($dest)) {
     567        $ipprc->file_delete($dest) or
     568                &my_die("failed to delete existing file: $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     569    }
     570    my $dest_resolved = $ipprc->file_resolve($dest, 'create');
     571    &my_die("failed to resolve $dest", $PS_EXIT_UNKNOWN_ERROR) if !$dest_resolved;
     572
     573    copy ($src, $dest_resolved) or
     574        &my_die("failed to copy $src to $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     575
     576    if ($replicate and (file_scheme($dest) eq 'neb')) {
     577        my $neb = $ipprc->nebulous();
     578        $neb->setxattr($dest, 'user.copies', 2, 'create') or
     579            &my_die("failed to set user.copies for $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     580
     581        $neb->replicate($dest) or
     582            &my_die("failed to replicate $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     583    }
     584}
     585
    515586sub my_die
    516587{
Note: See TracChangeset for help on using the changeset viewer.