Changeset 20495 for trunk/ippScripts/scripts/magic_process.pl
- Timestamp:
- Oct 31, 2008, 4:54:16 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/magic_process.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/magic_process.pl
r18784 r20495 15 15 16 16 use IPC::Cmd 0.36 qw( can_run run ); 17 use File::Temp qw( tempfile ); 17 18 use PS::IPP::Metadata::Config; 18 19 use PS::IPP::Metadata::List qw( parse_md_list ); … … 30 31 # Parse the command-line arguments 31 32 my ($magic_id, $node, $camera, $dbname, $outroot, $save_temps, $verbose, $no_update, $no_op, $redirect); 33 my $skycellroot; 32 34 GetOptions( 33 35 'magic_id=s' => \$magic_id, # Magic identifier … … 41 43 'no-op' => \$no_op, # Don't do any operations? 42 44 'redirect-output' => \$redirect, # Redirect output? 45 'skycellroot=s' => \$skycellroot, # root of the warps to find skycells (temporary) 43 46 ) or pod2usage( 2 ); 44 47 … … 53 56 $ipprc->define_camera($camera); 54 57 58 # Remove streaks doesn't know about nebulous. It expects to be able to append strings to outroot 59 # to form valid file names. 60 # So forbid nebulous path in outroot. We could relax this by change RemoveStreaks to take all 61 # of the file names as arguments 62 if ($outroot =~ 'neb:/') { 63 &my_die("RemoveStreaks does not support nebulous paths in outroot", $magic_id, $node, 64 $PS_EXIT_CONFIG_ERROR); 65 } 66 67 # resolve any path:// or file:// in outroot 68 $outroot = $ipprc->file_resolve($outroot); 69 70 55 71 my $logDest = $ipprc->filename("LOG.EXP", $outroot, $magic_id) or 56 72 &my_die("Missing entry from camera config", $magic_id, $PS_EXIT_CONFIG_ERROR); … … 88 104 89 105 106 my @outputs = ("${outroot}.clusters", "${outroot}_hough.fits", "${outroot}.streaks"); 90 107 ### Do the heavy lifting 91 my @basenames; # Base names of inputs 92 { 108 { 109 my $mode; 93 110 my $command; # Command to execute 111 $command = "$streaks --outroot $outroot"; 94 112 if (scalar @$inputs == 1 and $node ne "root") { 113 # 114 # RemoveStreak --detect --image filename --mask maskname --weight weightname --outroot path_base 115 # 95 116 # Leaf node: 'detect' stage 96 $command = "$streaks --detect"; 97 98 my $node = $$inputs[0]; # Input node 99 push @basenames, $ipprc->file_resolve( $node->{path_base} ); 117 $mode = 'detect'; 118 my $innode = $$inputs[0]; # Input node 119 120 my ($image, $mask, $weight) = resolve_inputs($innode); 121 122 $command .= " --detect --image $image --mask $mask --weight $weight"; 123 124 # create the list of inputs used at this stage. At higher levels the 125 # thes files will get catenated together to create the file for the subsquent stage 126 127 my ($ifh, $image_list) = open_list_file($outroot, "image.list"); 128 print $ifh "$image\n"; 129 close $ifh; 130 my ($mfh, $mask_list) = open_list_file($outroot, "mask.list"); 131 print $mfh "$mask\n"; 132 close $mfh; 133 my ($wfh, $weight_list) = open_list_file($outroot, "weight.list"); 134 print $wfh "$weight\n"; 135 close $wfh; 136 137 # work around missing wcs in difference images. Use the skycells from warp stage 138 my ($sfh, $skycell_list); 139 if ($skycellroot) { 140 ($sfh, $skycell_list) = open_list_file($outroot, "wcs.list"); 141 # at this level the skycell_id is equal to the node 142 my $skycell_id = $node; 143 my $skycell = $ipprc->file_resolve("${skycellroot}.${skycell_id}.skycell"); 144 print $sfh "$skycell\n"; 145 close $sfh; 146 } 100 147 } else { 148 # 149 # RemoveStreak --merge --inputs input.list --images image0_1.list \ 150 # --masks mask0_1.list --weight weights0_1.list 151 # --outroot outroot 152 101 153 # Branch node: 'merge' stage 102 $command = "$streaks --merge"; 103 104 # Concatenate the names 105 foreach my $node (@$inputs) { 106 push @basenames, $ipprc->file_resolve( $node->{path_base} ); 107 } 108 } 109 110 $command .= ' ' . join(' ', @basenames); 154 $mode = 'merge'; 155 156 my ($infh, $input_list) = open_list_file($outroot, "input.list"); 157 my ($ifh, $image_list) = open_list_file($outroot, "image.list"); 158 my ($mfh, $mask_list) = open_list_file($outroot, "mask.list"); 159 my ($wfh, $weight_list) = open_list_file($outroot, "weight.list"); 160 my ($sfh, $skycell_list); 161 if ($skycellroot) { 162 ($sfh, $skycell_list) = open_list_file($outroot, "wcs.list"); 163 } 164 165 eval { 166 foreach my $innode (@$inputs) { 167 my ($image, $mask, $weight) = resolve_inputs($innode); 168 169 my $in_uri = $innode->{uri}; 170 171 print $infh "$in_uri\n"; 172 cat_list_to_list($ifh, $in_uri, "image.list"); 173 cat_list_to_list($mfh, $in_uri, "mask.list"); 174 cat_list_to_list($wfh, $in_uri, "weight.list"); 175 cat_list_to_list($sfh, $in_uri, "wcs.list") if $skycell_list; 176 177 } 178 close $infh; 179 close $ifh; 180 close $mfh; 181 close $wfh; 182 close $sfh if $skycell_list; 183 184 $command .= " --merge --inputs $input_list"; 185 $command .= " --images $image_list --masks $mask_list --weights $weight_list" ; 186 $command .= " --wcsList $skycell_list" if $skycell_list; 187 }; 188 if ($@) { 189 &my_die("failed to create file lists: $@", $PS_EXIT_UNKNOWN_ERROR, $magic_id, $node, 190 $PS_EXIT_UNKNOWN_ERROR); 191 } 192 } 111 193 112 194 unless ($no_op) { 195 # RemoveStreaks fails if the output file already exists 196 foreach my $output (@outputs) { 197 unlink($output) if -e $output; 198 } 199 113 200 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 114 201 run(command => $command, verbose => $verbose); … … 118 205 } 119 206 120 foreach my $basename (@basenames) { 121 file_check( $basename . '.clusters' ); 122 file_check( $basename . '.streaks' ); 123 file_check( $basename . '_hough.fits' ); 207 foreach my $output (@outputs) { 208 file_check( $output ); 124 209 } 125 210 } else { … … 154 239 155 240 ### Pau. 241 242 sub open_list_file { 243 my $outroot = shift; 244 my $extension = shift; 245 246 my $filename = "$outroot.$extension"; 247 248 my $fh; 249 open $fh, ">$filename" or die "failed to open list file $filename"; 250 251 return ($fh, $filename); 252 } 253 254 sub cat_list_to_list { # ($infh, $in_uri, "input.list"); 255 my $out = shift; # output file handle 256 my $uri = shift; # uri to append ... 257 my $extension = shift; # extension to 258 my $filename = "$uri.$extension"; 259 260 my $in; 261 open $in, "<$filename" or die "failed to open list file: $filename"; 262 my $contents = <$in>; 263 print $out $contents; 264 } 265 266 sub resolve_inputs { 267 my $node = shift; 268 my $input_base = $node->{path_base}; 269 my $image = $ipprc->file_resolve($ipprc->filename("PPSUB.OUTPUT", $input_base)); 270 my $mask = $ipprc->file_resolve($ipprc->filename("PPSUB.OUTPUT.MASK", $input_base)); 271 my $weight= $ipprc->file_resolve($ipprc->filename("PPSUB.OUTPUT.WEIGHT", $input_base)); 272 273 return ($image, $mask, $weight); 274 } 156 275 157 276 sub file_check
Note:
See TracChangeset
for help on using the changeset viewer.
