Changeset 20074
- Timestamp:
- Oct 12, 2008, 1:50:15 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/PStamp/lib/PStamp/Job.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PStamp/lib/PStamp/Job.pm
r19761 r20074 44 44 # we die in response to bad data in request files 45 45 die "Unknown req_type: $req_type" if ($req_type ne "byid") and ($req_type ne "byexp") 46 and ($req_type ne "bycoord"); 47 if ($req_type eq "bycoord") { 46 and ($req_type ne "bycoord") and ($req_type ne "bydiff"); 47 if (($req_type eq "byid") and ($img_type eq "diff")) { 48 # lookups of all of the information for diff images requires a two level lookup to 49 # get the exposure information. Switching the req_type allows us to keep that code 50 # in one place 51 $req_type = "bydiff"; 52 } 53 if ($req_type eq "bydiff") { 54 my $results = lookup_bydiff($ipprc, $image_db, $id, $img_type, $verbose); 55 if (!$results) { 56 return undef; 57 } 58 if ($img_type eq "diff") { 59 return [$results]; 60 } elsif (($img_type eq "raw") or ($img_type eq "chip")) { 61 $req_type = "byexp"; 62 $id = $results->{exp_name}; 63 return undef if !$id; 64 # fall through and lookup byexp 65 } elsif ($img_type eq "warp") { 66 $req_type = "byid"; 67 $id = $results->{warp_id}; 68 return undef if !$id; 69 # fall through and lookup by warp_id 70 } elsif ($img_type eq "stack") { 71 $req_type = "byid"; 72 $id = $results->{stack_id}; 73 return undef if !$id; 74 # fall though and lookup by stack id 75 } else { 76 # shouldn't I check this elsewhere? 77 print STDERR "Error: $img_type is an unknown image type\n"; 78 return undef; 79 } 80 81 } elsif ($req_type eq "bycoord") { 48 82 49 83 # run … … 52 86 my $results = lookup_bycoord($ipprc, $image_db, $x, $y, $mjd_min, $mjd_max, $filter, $verbose); 53 87 88 # now take the results and lookup byexp 89 # XXX: This needs work. What stops results from returning multiple images???? 90 # We should loop over the set of images returned building up the full results array 54 91 $req_type = "byexp"; 55 92 $id = $results->{exp_name}; … … 97 134 $id_opt = "-exp_id"; 98 135 $command .= " -class_id $class_id" if $class_id; 99 $want_astrom = 0;136 $want_astrom = 1; 100 137 $use_class_id = 1; 101 138 } elsif ($img_type eq "chip") { … … 162 199 foreach my $image (@$images) { 163 200 my $base; 201 202 next if ($img_type eq "warp" and $image->{ignored}); 203 164 204 if ($base_name) { 165 205 $base = $image->{$base_name}; … … 170 210 if (!$camera) { 171 211 # This assumes that all images have the same camera 172 $ipprc->define_camera($image->{camera});173 212 $camera = $image->{camera}; 213 $ipprc->define_camera($camera); 174 214 } 175 215 my $out = {}; 176 216 $out->{exp_id} = $image->{exp_id}; 217 $out->{exp_name} = $image->{exp_name}; 177 218 $out->{image} = $image->{uri}; 178 219 $out->{state} = $image->{state}; # state is undef for rawExp, but that's ok 179 220 $class_id = $image->{class_id} if $use_class_id; 180 181 221 182 222 # find the mask and weight images … … 199 239 200 240 return $output; 241 } 242 sub lookup_bydiff { 243 my $ipprc = shift; 244 my $image_db = shift; 245 my $id = shift; 246 my $img_type = shift; 247 my $verbose = shift; 248 249 my $missing_tools; 250 my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1); 251 if ($missing_tools) { 252 warn("Can't find required tools."); 253 exit ($PS_EXIT_CONFIG_ERROR); 254 } 255 256 my $command = "$difftool -diffskyfile -diff_id $id -dbname $image_db"; 257 258 # run the tool and parse the output 259 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 260 run(command => $command, verbose => $verbose); 261 unless ($success) { 262 # not sure if we should die here 263 print STDERR @$stderr_buf; 264 return undef; 265 } 266 267 my $buf = join "", @$stdout_buf; 268 if (!$buf) { 269 return undef; 270 } 271 272 my $mdcParser = PS::IPP::Metadata::Config->new; 273 my $images = parse_md_fast($mdcParser, $buf) 274 or die ("Unable to parse metadata config doc"); 275 276 my $n = @$images; 277 if ($n > 1) { 278 die ("difftool returned an unexpected number of diffskyfiles: $n"); 279 } elsif ($n == 0) { 280 return undef; 281 } 282 283 my $image = $images->[0]; 284 285 # The standard way to do a diff is warp - stack 286 # so we interpret the requested image in that way 287 288 # XXX the query currently returns max long long for null 289 # this line is ready if we switch the code to return zero for null 290 my $stack_id = $image->{stack_id_temp_1}; 291 if ($stack_id and ($stack_id != 9223372036854775807)) { 292 $image->{stack_id} = $stack_id; 293 } 294 295 # XXX the query currently returns max long long for null 296 # this line is ready if we switch the code to return zero for null 297 my $warp_id = $image->{warp_id_temp_0}; 298 if ($warp_id and ($warp_id != 9223372036854775807)) { 299 $image->{warp_id} = $warp_id; 300 301 ## now use the warp and go get the exposure information 302 $command = "warptool -warped -warp_id $warp_id -dbname $image_db -limit 1"; 303 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 304 run(command => $command, verbose => $verbose); 305 unless ($success) { 306 # not sure if we should die here 307 print STDERR @$stderr_buf; 308 return undef; 309 } 310 311 my $buf = join "", @$stdout_buf; 312 if (!$buf) { 313 return undef; 314 } 315 316 my $mdcParser = PS::IPP::Metadata::Config->new; 317 my $warps = parse_md_fast($mdcParser, $buf) 318 or die ("Unable to parse metadata config doc"); 319 my $warp = $warps->[0]; 320 321 $image->{exp_id} = $warp->{exp_id}; 322 $image->{exp_name} = $warp->{exp_name}; 323 $image->{camera} = $warp->{camera}; 324 } 325 326 if ($img_type eq "diff") { 327 # the $image is going to be returned directly so we need to do some more processing 328 $image->{image} = $image->{uri}; 329 if ($image->{camera}) { 330 $ipprc->define_camera($image->{camera}); 331 $image->{mask} = $ipprc->filename("PPSUB.OUTPUT.MASK", $image->{path_base}); 332 $image->{weight} = $ipprc->filename("PPSUB.OUTPUT.WEIGHT", $image->{path_base}); 333 } else { 334 # XXX this will only happen if the minuend is not a warp 335 print STDERR "WARNING: cannot resolve camera so cannot get weight and mask images\n"; 336 } 337 } 338 339 return $image; 201 340 } 202 341
Note:
See TracChangeset
for help on using the changeset viewer.
