- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/magic_process.pl (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippScripts/scripts/magic_process.pl
r24763 r27840 8 8 use Sys::Hostname; 9 9 my $host = hostname(); 10 my $date = `date`; 10 11 print "\n\n"; 11 print "Starting script $0 on $host \n\n";12 print "Starting script $0 on $host at $date\n\n"; 12 13 13 14 use vars qw( $VERSION ); … … 30 31 my $missing_tools; 31 32 my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1); 33 my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1); 34 my $ppSubConvolve = can_run('ppSubConvolve') or (warn "Can't find ppSubConvolve" and $missing_tools = 1); 32 35 my $detectstreaks = can_run('DetectStreaks') or (warn "Can't find DetectStreaks" and $missing_tools = 1); 36 my $VerifyStreaks = can_run('VerifyStreaks') or (warn "Can't find VerifyStreaks, will not produce png images"); 33 37 if ($missing_tools) { 34 38 warn("Can't find required tools."); … … 37 41 38 42 # Parse the command-line arguments 39 my ($magic_id, $node, $camera, $dbname, $ outroot, $save_temps, $verbose, $no_update, $no_op, $logfile);43 my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile); 40 44 41 45 GetOptions( … … 44 48 'camera=s' => \$camera, # Camera name 45 49 'dbname=s' => \$dbname, # Database name 46 ' outroot=s' => \$outroot,# Output root name50 'baseroot=s' => \$baseroot, # Output root name 47 51 'save-temps' => \$save_temps, # Save temporary files? 48 52 'verbose' => \$verbose, # Print stuff? … … 53 57 54 58 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 55 pod2usage( -msg => "Required options: --magic_id --camera --node -- outroot",59 pod2usage( -msg => "Required options: --magic_id --camera --node --baseroot", 56 60 -exitval => 3) unless 57 61 defined $magic_id and 58 62 defined $node and 59 63 defined $camera and 60 defined $ outroot;64 defined $baseroot; 61 65 62 66 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_id, $node, $PS_EXIT_CONFIG_ERROR ); # IPP configuration 63 67 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_id, $node, $PS_EXIT_SYS_ERROR ) if $logfile; 64 68 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 74 if ($baseroot =~ 'neb:/') { 70 75 &my_die("DetectStreaks does not support nebulous paths in outroot", $magic_id, $node, $PS_EXIT_CONFIG_ERROR); 71 76 } 72 77 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 73 82 # resolve any path:// or file:// in outroot 74 $outroot = $ipprc->file_resolve($outroot); 83 $baseroot = $ipprc->file_resolve($baseroot); 84 my $outroot = "$baseroot.$node"; 85 $ipprc->outroot_prepare($outroot); 75 86 76 87 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files … … 103 114 $command .= " --verbose" if $verbose; 104 115 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 119 123 if (scalar @$inputs == 1 and $node ne "root") { 120 124 # … … 136 140 } 137 141 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; 141 214 142 215 $command .= " --detect --image $image --mask $mask --weight $weight -k $template"; 143 144 # XXX: get all of these parameters from a recipe145 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 this151 # $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.2158 $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 binning166 $command .= ' -b 3';167 216 168 217 # create the list of inputs used at this stage. At higher levels the … … 248 297 file_check( $output ); 249 298 } 299 300 foreach my $file (@deletions) { 301 print "Deleting $file...\n"; 302 $ipprc->file_delete($file); 303 } 304 250 305 } else { 251 306 print "Skipping command: $command\n"; 252 307 } 308 253 309 } 254 310 … … 290 346 } 291 347 348 &run_verifystreaks($baseroot); 349 292 350 my $command = "$magictool -addmask"; 293 351 $command .= " -magic_id $magic_id"; … … 310 368 } 311 369 312 313 314 370 ### Pau. 371 372 sub 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 } 315 420 316 421 sub open_list_file { … … 363 468 } 364 469 365 sub resolve_template366 {367 my $node = shift;368 369 my $path_base = $node->{diff_path_base}; # Base name for name370 my $image = $node->{inverse} ? "PPSUB.INPUT.CONV" : "PPSUB.REF.CONV"; # File rule of interest371 372 $image = $ipprc->file_resolve($ipprc->filename($image, $path_base));373 374 return $image375 }376 377 470 sub file_check 378 471 { … … 397 490 $command .= " -node $node"; 398 491 $command .= " -fault $exit_code"; 492 $command .= " -path_base $outroot" if defined $outroot; 399 493 $command .= " -dbname $dbname" if defined $dbname; 400 494 system($command);
Note:
See TracChangeset
for help on using the changeset viewer.
