Changeset 17646
- Timestamp:
- May 12, 2008, 4:15:35 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/warp_overlap.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/warp_overlap.pl
r17518 r17646 23 23 24 24 use PS::IPP::Config qw($PS_EXIT_SUCCESS 25 $PS_EXIT_UNKNOWN_ERROR26 $PS_EXIT_SYS_ERROR27 $PS_EXIT_CONFIG_ERROR28 $PS_EXIT_PROG_ERROR29 $PS_EXIT_DATA_ERROR30 $PS_EXIT_TIMEOUT_ERROR31 metadataLookupStr32 metadataLookupBool33 caturi34 file_scheme35 );25 $PS_EXIT_UNKNOWN_ERROR 26 $PS_EXIT_SYS_ERROR 27 $PS_EXIT_CONFIG_ERROR 28 $PS_EXIT_PROG_ERROR 29 $PS_EXIT_DATA_ERROR 30 $PS_EXIT_TIMEOUT_ERROR 31 metadataLookupStr 32 metadataLookupBool 33 caturi 34 file_scheme 35 ); 36 36 37 37 my $ipprc = PS::IPP::Config->new(); # IPP configuration … … 44 44 'dbname|d=s' => \$dbname, # Database name 45 45 'verbose' => \$verbose, # Print to stdout 46 'no-update' => \$no_update, # Don't update the database?46 'no-update' => \$no_update, # Don't update the database? 47 47 'no-op' => \$no_op, # Don't do any operations 48 48 'save-temps' => \$save_temps, # Save temporary files? … … 66 66 if ($missing_tools) { 67 67 warn("Can't find required tools."); 68 exit($PS_EXIT_CONFIG_ERROR); 69 } 70 71 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files68 exit($PS_EXIT_CONFIG_ERROR); 69 } 70 71 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 72 72 73 73 # Get list of component imfiles for exposure … … 77 77 $command .= " -dbname $dbname" if defined $dbname; 78 78 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 79 run(command => $command, verbose => $verbose);79 run(command => $command, verbose => $verbose); 80 80 unless ($success) { 81 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);82 &my_die("Unable to perform warptool -imfile: $error_code", $warp_id, $error_code);83 } 84 81 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 82 &my_die("Unable to perform warptool -imfile: $error_code", $warp_id, $error_code); 83 } 84 85 85 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 86 &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);87 $imfiles = parse_md_list($metadata) or 88 &my_die("Unable to parse metadata list", $warp_id, $PS_EXIT_PROG_ERROR);86 &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR); 87 $imfiles = parse_md_list($metadata) or 88 &my_die("Unable to parse metadata list", $warp_id, $PS_EXIT_PROG_ERROR); 89 89 } 90 90 91 91 # Where do we get the astrometry source from? 92 my $astromSource; # The astrometry source93 my $astromAccept; # Accept the astrometry unconditionally?94 my $astromDepth; # File level of the astrometry source (SPLIT or MEF)?92 my $astromSource; # The astrometry source 93 my $astromAccept; # Accept the astrometry unconditionally? 94 my $astromDepth; # File level of the astrometry source (SPLIT or MEF)? 95 95 { 96 96 my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -"; 97 97 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 98 run(command => $command, verbose => $verbose);98 run(command => $command, verbose => $verbose); 99 99 unless ($success) { 100 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);101 &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code);100 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 101 &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code); 102 102 } 103 103 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 104 &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);104 &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR); 105 105 $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE'); 106 106 $astromAccept = metadataLookupBool($metadata, 'ASTROM.ACCEPT'); … … 116 116 my $tess_dir = $ipprc->tessellation_catdir( $tess_id ); # Tessellation catdir for DVO 117 117 $tess_dir = $ipprc->convert_filename_absolute( $tess_dir ); 118 118 119 119 my %unique_skycells = (); # Identified skycells (all unique by virtue of hash property) 120 120 121 121 # XXX this is a bit too hard wired: the concept is that astrometry comes from the MOSAIC vs CHIP output 122 122 # XXX we have moved the astrometry analysis to the camera stage only: we should always have the source be MEF 123 123 if ($astromSource eq 'PSASTRO.OUTPUT.MEF') { 124 # We have a MEF astrometry file from psastro125 my $imfile = $imfiles->[0];126 my $camRoot = $imfile->{cam_path_base};127 my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file128 129 my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps130 if (! @matchlist) {131 &my_die("Unable to perform dvoImageOverlaps: missing astrometry", $warp_id, $PS_EXIT_DATA_ERROR);132 } 133 # Match each of the imfiles to this list134 foreach my $imfile (@$imfiles) {135 extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);136 }124 # We have a MEF astrometry file from psastro 125 my $imfile = $imfiles->[0]; 126 my $camRoot = $imfile->{cam_path_base}; 127 my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file 128 129 my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps 130 if (! @matchlist) { 131 &my_die("Unable to perform dvoImageOverlaps: missing astrometry", $warp_id, $PS_EXIT_DATA_ERROR); 132 } 133 # Match each of the imfiles to this list 134 foreach my $imfile (@$imfiles) { 135 extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells); 136 } 137 137 } else { 138 # We have per-imfile astrometry139 foreach my $imfile (@$imfiles) {140 my $astromFile;141 if ($astromSource eq 'PSASTRO.OUTPUT') {142 my $chipRoot = $imfile->{chip_path_base};143 my $classID = $imfile->{class_id};144 $astromFile = $ipprc->filename($astromSource, $chipRoot, $classID); # Astrometry file145 } else {146 $astromFile = $imfile->{chip_uri}; # Astrometry file147 }148 my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps149 if (! @matchlist and $verbose) {150 print "skipping $astromFile\n";151 } 152 153 extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);154 }138 # We have per-imfile astrometry 139 foreach my $imfile (@$imfiles) { 140 my $astromFile; 141 if ($astromSource eq 'PSASTRO.OUTPUT') { 142 my $chipRoot = $imfile->{chip_path_base}; 143 my $classID = $imfile->{class_id}; 144 $astromFile = $ipprc->filename($astromSource, $chipRoot, $classID); # Astrometry file 145 } else { 146 $astromFile = $imfile->{chip_uri}; # Astrometry file 147 } 148 my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps 149 if (! @matchlist and $verbose) { 150 print "skipping $astromFile\n"; 151 } 152 153 extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells); 154 } 155 155 } 156 156 } else { 157 157 # create an overlap with an entry for each skycell:imfile match 158 158 foreach my $imfile (@$imfiles) { 159 my %overlap = ();160 $overlap{skycell_id} = 'default';161 $overlap{tess_id} = 'default';162 $overlap{cam_id} = $imfile->{cam_id};163 $overlap{class_id} = $imfile->{class_id};164 $overlap{fault} = $imfile->{fault};165 push @overlaps, \%overlap;159 my %overlap = (); 160 $overlap{skycell_id} = 'default'; 161 $overlap{tess_id} = 'default'; 162 $overlap{cam_id} = $imfile->{cam_id}; 163 $overlap{class_id} = $imfile->{class_id}; 164 $overlap{fault} = $imfile->{fault}; 165 push @overlaps, \%overlap; 166 166 } 167 167 } 168 168 169 169 # XXX this file needs some additional error checking: if no overlaps are found, we 170 # keep running this step over and over (a successful warptool -addoverlap prevents 170 # keep running this step over and over (a successful warptool -addoverlap prevents 171 171 # successive warptime -imfile from running. 172 172 … … 192 192 my $command = "$warptool -addoverlap -mapfile $overlapName"; # Command to run warptool 193 193 $command .= " -dbname $dbname" if defined $dbname; 194 194 195 195 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 196 run(command => $command, verbose => $verbose);196 run(command => $command, verbose => $verbose); 197 197 unless ($success) { 198 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);199 warn("Unable to perform warptool -addoverlap: $error_code\n");200 exit($error_code);198 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 199 warn("Unable to perform warptool -addoverlap: $error_code\n"); 200 exit($error_code); 201 201 } 202 202 } … … 204 204 sub my_die 205 205 { 206 my $msg = shift; # Warning message on die207 my $warp_id = shift; # Warp identifier208 my $exit_code = shift; # Exit code to add206 my $msg = shift; # Warning message on die 207 my $warp_id = shift; # Warp identifier 208 my $exit_code = shift; # Exit code to add 209 209 210 210 warn($msg); … … 217 217 sub get_overlaps 218 218 { 219 my $filename = shift; # Filename on which to run dvoImageOverlaps220 my $tess_dir = shift; # Tessellation directory221 my $accept = shift; # Do we use the -accept-astrom flag?219 my $filename = shift; # Filename on which to run dvoImageOverlaps 220 my $tess_dir = shift; # Tessellation directory 221 my $accept = shift; # Do we use the -accept-astrom flag? 222 222 223 223 my $command = "$dvoImageOverlaps -D CATDIR $tess_dir " . $ipprc->file_resolve($filename); 224 224 $command .= ' -accept-astrom' if $accept; 225 225 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 226 run(command => $command, verbose => $verbose);226 run(command => $command, verbose => $verbose); 227 227 if (!$success) { 228 print "Missing astrometry for $filename --- check ASTROM.SOURCE in PSWARP recipe\n"; 229 return 0; 228 print "Unable to calculate overlaps from $filename\n"; 229 print "STDOUT:\n$stdout_buf\n"; 230 print "STDERR:\n$stderr_buf\n"; 231 return 0; 230 232 } 231 233 return split ('\n', (join "", @$stdout_buf)); 232 } 234 } 233 235 234 236 # Extract a list of overlaps for an imfile … … 240 242 sub extract_overlaps 241 243 { 242 my $matches = shift; # Reference to list of skycells from dvoImageOverlaps243 my $imfile = shift; # Imfile information244 my $filename = shift; # Filename used with dvoImageOverlaps245 my $tess_id = shift; # Tessellation identifier246 my $overlaps = shift; # Reference to list of overlaps244 my $matches = shift; # Reference to list of skycells from dvoImageOverlaps 245 my $imfile = shift; # Imfile information 246 my $filename = shift; # Filename used with dvoImageOverlaps 247 my $tess_id = shift; # Tessellation identifier 248 my $overlaps = shift; # Reference to list of overlaps 247 249 my $unique_skycells = shift; # Reference to hash of found skycells 248 250 … … 253 255 # Work out how to identify this imfile in the output 254 256 my $fileLevel = $imfile->{filelevel}; 255 my $entry; # How to identify this imfile in the dvoImageOverlaps output257 my $entry; # How to identify this imfile in the dvoImageOverlaps output 256 258 if ((lc($fileLevel) eq "chip") && (lc($astromDepth) eq "mef")) { 257 my $class_id = $imfile->{class_id};258 my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} );259 my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output260 261 262 $entry = $filename . '\[' . $extname . '\]';263 print STDERR "entry: $entry, class: $class_id, extname: $extname, chiproot: $chipRoot\n" if $verbose;259 my $class_id = $imfile->{class_id}; 260 my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} ); 261 my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output 262 263 264 $entry = $filename . '\[' . $extname . '\]'; 265 print STDERR "entry: $entry, class: $class_id, extname: $extname, chiproot: $chipRoot\n" if $verbose; 264 266 } else { 265 $entry = $filename;266 print STDERR "entry: $entry\n" if $verbose;267 } 268 269 my @skycells = &select_skycells($entry, @$matches); # Matching skycells267 $entry = $filename; 268 print STDERR "entry: $entry\n" if $verbose; 269 } 270 271 my @skycells = &select_skycells($entry, @$matches); # Matching skycells 270 272 my $Nskycells = @skycells; 271 273 printf STDERR "Nskycells: $Nskycells\n" if $verbose; 272 274 foreach my $skycell (@skycells) { 273 my %overlap = ();# Overlap information for warptool274 $overlap{skycell_id} = $skycell;275 $overlap{tess_id} = $tess_id;276 $overlap{cam_id} = $imfile->{cam_id};277 $overlap{class_id} = $imfile->{class_id};278 $overlap{fault} = $imfile->{fault};279 push @$overlaps, \%overlap;280 281 printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id} if $verbose;282 283 $unique_skycells->{$skycell} = 1;275 my %overlap = (); # Overlap information for warptool 276 $overlap{skycell_id} = $skycell; 277 $overlap{tess_id} = $tess_id; 278 $overlap{cam_id} = $imfile->{cam_id}; 279 $overlap{class_id} = $imfile->{class_id}; 280 $overlap{fault} = $imfile->{fault}; 281 push @$overlaps, \%overlap; 282 283 printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id} if $verbose; 284 285 $unique_skycells->{$skycell} = 1; 284 286 } 285 287 286 288 return; 287 289 } 288 290 289 291 # Find skycells in the list that come from a particular entry 290 sub select_skycells 291 { 292 my $entry = shift; # File+Ext to search for293 my @list = @_; # List of "File+Ext : skycell"292 sub select_skycells 293 { 294 my $entry = shift; # File+Ext to search for 295 my @list = @_; # List of "File+Ext : skycell" 294 296 295 297 my @skycells = (); 296 my %unique = (); # Ensure we only return unique skycells for this entry298 my %unique = (); # Ensure we only return unique skycells for this entry 297 299 298 300 foreach my $line (@list) { 299 if ($line =~ m|$entry|) {300 my ($skycell) = $line =~ m|$entry\S*\s+:\s+(\S+)|;301 if (not defined $unique{$skycell}) {302 push @skycells, $skycell;303 $unique{$skycell} = 1;304 }305 }301 if ($line =~ m|$entry|) { 302 my ($skycell) = $line =~ m|$entry\S*\s+:\s+(\S+)|; 303 if (not defined $unique{$skycell}) { 304 push @skycells, $skycell; 305 $unique{$skycell} = 1; 306 } 307 } 306 308 } 307 309 return @skycells;
Note:
See TracChangeset
for help on using the changeset viewer.
