IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/ippScripts/scripts/magic_process.pl

    r24763 r27840  
    88use Sys::Hostname;
    99my $host = hostname();
     10my $date = `date`;
    1011print "\n\n";
    11 print "Starting script $0 on $host\n\n";
     12print "Starting script $0 on $host at $date\n\n";
    1213
    1314use vars qw( $VERSION );
     
    3031my $missing_tools;
    3132my $magictool      = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
     33my $difftool       = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
     34my $ppSubConvolve = can_run('ppSubConvolve') or (warn "Can't find ppSubConvolve" and $missing_tools = 1);
    3235my $detectstreaks = can_run('DetectStreaks') or (warn "Can't find DetectStreaks" and $missing_tools = 1);
     36my $VerifyStreaks = can_run('VerifyStreaks') or (warn "Can't find VerifyStreaks, will not produce png images");
    3337if ($missing_tools) {
    3438    warn("Can't find required tools.");
     
    3741
    3842# Parse the command-line arguments
    39 my ($magic_id, $node, $camera, $dbname, $outroot, $save_temps, $verbose, $no_update, $no_op, $logfile);
     43my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile);
    4044
    4145GetOptions(
     
    4448           'camera=s'        => \$camera,     # Camera name
    4549           'dbname=s'        => \$dbname,     # Database name
    46            'outroot=s'       => \$outroot,    # Output root name
     50           'baseroot=s'      => \$baseroot,   # Output root name
    4751           'save-temps'      => \$save_temps, # Save temporary files?
    4852           'verbose'         => \$verbose,    # Print stuff?
     
    5357
    5458pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    55 pod2usage( -msg => "Required options: --magic_id --camera --node --outroot",
     59pod2usage( -msg => "Required options: --magic_id --camera --node --baseroot",
    5660           -exitval => 3) unless
    5761    defined $magic_id and
    5862    defined $node and
    5963    defined $camera and
    60     defined $outroot;
     64    defined $baseroot;
    6165
    6266my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_id, $node, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    6367$ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_id, $node, $PS_EXIT_SYS_ERROR ) if $logfile;
    6468
    65 # DetectStreaks doesn't know about nebulous. It expects to be able to append strings to outroot
    66 # to form valid file names.
    67 # So forbid nebulous path in outroot. We could relax this by change DetectStreaks to take all
    68 # of the file names as arguments or by teaching it about Nebulous
    69 if ($outroot =~ 'neb:/') {
     69# DetectStreaks doesn't know about nebulous. It expects to be able to
     70# append strings to baseroot to form valid file names.  So forbid
     71# nebulous path in baseroot. We could relax this by change
     72# DetectStreaks to take all of the file names as arguments or by
     73# teaching it about Nebulous
     74if ($baseroot =~ 'neb:/') {
    7075    &my_die("DetectStreaks does not support nebulous paths in outroot", $magic_id, $node, $PS_EXIT_CONFIG_ERROR);
    7176}
    7277
     78# most filenames are of the form $baseroot.$node.*, but VerifyStreaks
     79# needs access to $baseroot.*, so we construct $outroot =
     80# $baseroot.$node in here
     81
    7382# resolve any path:// or file:// in outroot
    74 $outroot = $ipprc->file_resolve($outroot);
     83$baseroot = $ipprc->file_resolve($baseroot);
     84my $outroot = "$baseroot.$node";
     85$ipprc->outroot_prepare($outroot);
    7586
    7687my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    103114    $command .= " --verbose" if $verbose;
    104115
    105     # added per Paul Sydney's request Jan 6, 2009
    106     # removed per Paul Sydney March 30, 2009
    107     # $command .= " -D 3";
    108 
    109 
    110     # added per Paul Sydney's Jan 8, 2009 to help solve the STS problem
    111     # removed because it didn't help the STS problem and it quadrupled the number of false streaks for m31
    112     # Paul asked me to remove this parameter Jan 20,2009
    113 #    $command .= " -C 0";
    114 
    115 
    116 #    $command .= " -u 6";
    117 #    $command .= " --test";
    118 
     116    ### To enable debugging output:
     117    #    $command .= " --test";
     118
     119    ### per email from Paul Sydney 2010.02.11, we should use threshold of 2.35 to catch the faint streak(s)
     120    $command .= " --threshold 2.35";
     121
     122    my @deletions;          # Files to delete
    119123    if (scalar @$inputs == 1 and $node ne "root") {
    120124        #
     
    136140        }
    137141
    138         my $template = resolve_template($innode);
    139         &my_die("failed to resolve template", $magic_id, $node, $PS_EXIT_DATA_ERROR)
    140             unless defined $template;
     142        my $diff_base = $innode->{diff_path_base}; # Base name for diff
     143        my $tempName = $innode->{inverse} ? "PPSUB.INPUT.CONV" : "PPSUB.REF.CONV"; # File rule of interest
     144        my $template = $ipprc->file_resolve($ipprc->filename($tempName, $diff_base));
     145
     146        # Delete the convolved products when done (we can recreate them as we need)
     147        push @deletions, $ipprc->filename($tempName . ".MASK", $diff_base);
     148        push @deletions, $ipprc->filename($tempName . ".VARIANCE", $diff_base);
     149
     150        unless (defined $template and $ipprc->file_exists($template)) {
     151            # Template doesn't exist (or can't be found); try to recreate it
     152            my $tempPath = "/tmp/magic.$magic_id.$node.template";
     153
     154            my $kernel = $ipprc->filename("PPSUB.OUTPUT.KERNELS", $diff_base); # Name of kernel file
     155            &my_die("Unable to find kernel file", $magic_id, $node, $PS_EXIT_DATA_ERROR) unless $ipprc->file_exists($kernel);
     156
     157            my ($image, $mask);   # Image and mask
     158            {
     159                my $command = "$difftool -inputskyfile -diff_id $diff_id -skycell_id $node"; # Command to run
     160                $command .= " -dbname $dbname" if defined $dbname;
     161                if ($innode->{inverse}) {
     162                    # Want the input because we're magicking the reference
     163                    $command .= " -input";
     164                } else {
     165                    # Want the reference because we're magicking the input
     166                    $command .= " -template";
     167                }
     168
     169                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     170                    run(command => $command, verbose => $verbose);
     171                unless ($success) {
     172                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     173                    &my_die("Unable to determine convolution inputs: $error_code", $magic_id, $node, $error_code);
     174                }
     175
     176                my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     177                    &my_die("Unable to parse metadata config doc", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     178
     179                my $inputs = parse_md_list($metadata) or
     180                    &my_die("Unable to parse metadata list", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     181                &my_die("Unexpected number of outputs", $magic_id, $node, $PS_EXIT_PROG_ERROR) unless scalar @$inputs == 1;
     182                my $input = $$inputs[0];
     183                my $path = $input->{path_base}; # Path of interest
     184                if (defined $input->{warp_id} and $input->{warp_id} > 0) {
     185                    $image = $ipprc->filename("PSWARP.OUTPUT", $path);
     186                    $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path);
     187                } elsif (defined $input->{stack_id} and $input->{stack_id} > 0) {
     188                    $image = $ipprc->filename("PPSTACK.UNCONV", $path);
     189                    $mask = $ipprc->filename("PPSTACK.UNCONV.MASK", $path);
     190                }
     191                &my_die("Unable to determine image and mask name", $magic_id, $node, $PS_EXIT_PROG_ERROR) unless defined $image and defined $mask;
     192            }
     193
     194            {
     195                &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);
     196
     197                my $command = "$ppSubConvolve $tempPath -image $image -mask $mask -kernel $kernel";
     198                $command .= " -reference" unless $innode->{inverse};
     199                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     200                    run(command => $command, verbose => $verbose);
     201                unless ($success) {
     202                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     203                    &my_die("Unable to create template image: $error_code", $magic_id, $node, $error_code);
     204                }
     205
     206                $template = $ipprc->filename("PPSUB.INPUT.CONV", $tempPath) or &my_die("Unable to determine filename for created template", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     207                $template = $ipprc->file_resolve($template) or &my_die("Unable to resolve filename for created template", $magic_id, $node, $PS_EXIT_PROG_ERROR);
     208                &my_die("Unable to find created template", $magic_id, $node, $PS_EXIT_PROG_ERROR) unless $ipprc->file_exists($template);
     209            }
     210        }
     211
     212        &my_die("Cannot find template", $magic_id, $node, $PS_EXIT_DATA_ERROR) unless defined $template and $ipprc->file_exists($template);
     213        push @deletions, $template;
    141214
    142215        $command .= " --detect --image $image --mask $mask --weight $weight -k $template";
    143 
    144         # XXX: get all of these parameters from a recipe
    145 
    146         # set threshold to 2.3 sigma (Default specified by Paul Sydney)
    147         $command .= ' -t 2.3';
    148 
    149         # set threshold to 2.75 sigma (Test by EAM : uncorrelated noise is typically ~20% higher than expected)
    150         # XXX we have fixed the output variance to address this
    151         # $command .= ' -t 2.75';
    152 
    153         # set threshold to 4 sigma (for testing)
    154         # $command .= ' -t 4';
    155 
    156         # set Minimum percent visible required between pixels clusters in a valid streak [0.0 - 1.0]
    157         # default is 0.2
    158         $command .= ' -P 0.2';
    159 
    160         #$command .= ' -t 4' . ' -P 0.25';
    161 
    162         # add -S "Number of pixels to shift for determining maximum differences in mean images default:8"
    163         $command .= ' -S';
    164 
    165         # add 3 x 3 binning
    166         $command .= ' -b 3';
    167216
    168217        # create the list of inputs used at this stage. At higher levels the
     
    248297            file_check( $output );
    249298        }
     299
     300        foreach my $file (@deletions) {
     301            print "Deleting $file...\n";
     302            $ipprc->file_delete($file);
     303        }
     304
    250305    } else {
    251306        print "Skipping command: $command\n";
    252307    }
     308
    253309}
    254310
     
    290346    }
    291347
     348    &run_verifystreaks($baseroot);
     349
    292350    my $command = "$magictool -addmask";
    293351    $command   .= " -magic_id $magic_id";
     
    310368}
    311369
    312 
    313 
    314370### Pau.
     371
     372sub run_verifystreaks {
     373
     374    my $baseroot = shift;
     375
     376    unless ($VerifyStreaks) {
     377        print STDERR "skipping VerifyStreaks\n";
     378        return 1;
     379    }
     380
     381    # VerifyStreaks --out $outdir --clusters $outdir/clusters.list $rootname.root.streakMap
     382
     383    my $outdir = "$baseroot.verify";
     384
     385    my($status) = system ("mkdir -p $outdir");
     386    if ($status) {
     387        print STDERR "failed to create output directory $outdir\n";
     388        return 1;
     389    }
     390
     391    my $FILE;
     392
     393    my @files = <$baseroot.*.clusters>;
     394
     395    unless (open ($FILE, ">$outdir/clusters.list")) {
     396        print "failed to create cluster file $outdir/clusters.list\n";
     397        return 1;
     398    }
     399    foreach my $file (@files) {
     400        $file =~ s|.clusters$||;
     401        print $FILE "$file\n";
     402    }
     403    close ($FILE);
     404    if ($status) {
     405        print "failed to create cluster file $outdir/clusters.list\n";
     406        return 1;
     407    }
     408
     409    my $command = "$VerifyStreaks --out $outdir --clusters $outdir/clusters.list $baseroot.root.streakMap";
     410
     411    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     412        run(command => $command, verbose => $verbose);
     413    unless ($success) {
     414        print "failed to run VerifyStreaks:\n";
     415        return 1;
     416    }
     417
     418    return 0;
     419}
    315420
    316421sub open_list_file {
     
    363468}
    364469
    365 sub resolve_template
    366 {
    367     my $node = shift;
    368 
    369     my $path_base = $node->{diff_path_base}; # Base name for name
    370     my $image = $node->{inverse} ? "PPSUB.INPUT.CONV" : "PPSUB.REF.CONV"; # File rule of interest
    371 
    372     $image = $ipprc->file_resolve($ipprc->filename($image, $path_base));
    373 
    374     return $image
    375 }
    376 
    377470sub file_check
    378471{
     
    397490        $command .= " -node $node";
    398491        $command .= " -fault $exit_code";
     492        $command .= " -path_base $outroot" if defined $outroot;
    399493        $command .= " -dbname $dbname" if defined $dbname;
    400494        system($command);
Note: See TracChangeset for help on using the changeset viewer.