Changeset 14567
- Timestamp:
- Aug 20, 2007, 2:24:57 PM (19 years ago)
- Location:
- trunk/ippScripts/scripts
- Files:
-
- 2 edited
-
warp_overlap.pl (modified) (8 diffs)
-
warp_skycell.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/warp_overlap.pl
r14511 r14567 59 59 my $dvoImageOverlaps = can_run('dvoImageOverlaps') or (warn "Can't find dvoImageOverlaps" and $missing_tools = 1); 60 60 my $dvoImageExtract = can_run('dvoImageExtract') or (warn "Can't find dvoImageExtract" and $missing_tools = 1); 61 if ($missing_tools) { 61 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 62 if ($missing_tools) { 62 63 warn("Can't find required tools."); 63 64 exit($PS_EXIT_CONFIG_ERROR); 64 65 } 66 67 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 65 68 66 69 # Get list of component imfiles for exposure … … 75 78 &my_die("Unable to perform warptool -imfile: $error_code", $warp_id, $error_code); 76 79 } 77 78 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 80 79 81 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 80 82 &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR); … … 83 85 } 84 86 87 # Where do we get the astrometry source from? 88 my $astromSource; # The astrometry source 89 { 90 my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -"; 91 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 92 run(command => $command, verbose => 1); 93 unless ($success) { 94 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 95 &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code); 96 } 97 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 98 &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR); 99 $astromSource = metadataLookupStr('ASTROM.SOURCE'); 100 } 101 85 102 # Determine the imfile/skycell overlaps 86 103 my @overlaps = (); … … 88 105 unless ($no_op) { 89 106 # Calculate the overlaps between imfiles and skycells 90 107 91 108 my $tessellations = $ipprc->tessellations(); # Hash of defined tessellations 92 109 foreach my $tess_id ( keys %$tessellations ) { … … 99 116 my $tess_dir = $ipprc->convert_filename_absolute( $$tessellations{$tess_id} ); # Catdir for DVO 100 117 print STDERR "tessellation: $tess_id, $tess_dir\n"; 101 102 my $imfile = $imfiles->[0]; 103 my $camRoot = $imfile->{cam_path_base}; 104 my $psastroFile = $ipprc->filename("PSASTRO.OUTPUT.MEF", $camRoot); # MEF psastro output 105 106 my @dirlist = File::Spec->splitdir( $psastroFile ); 107 my $psastroRootFile = pop @dirlist; 108 print STDERR "psastroRootFile: $psastroRootFile\n"; 109 110 # run the dvoImageOverlaps program to get the overlaps with this image 111 my $command = "$dvoImageOverlaps -accept-astrom -D CATDIR $tess_dir " . $ipprc->file_resolve($psastroFile); 112 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 113 run(command => $command, verbose => 1); 114 unless ($success) { 115 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 116 &my_die("Unable to perform dvoImageOverlaps: $error_code", $warp_id, $error_code); 117 } 118 my @matchlist = split ('\n', (join "", @$stdout_buf)); 119 120 # The command "dvoImageOverlaps -accept-astrom -D CATDIR tessellation (megacam)" returns: 121 # 729534pa.cmf[ccd00.hdr] : skycell.051.fits 122 # PSASTRO.OUTPUT[CMF.HEAD] : SKYCELL 123 # [CMF.HEAD] is optionally used for MEF files (SIMPLE or MOSAIC) 124 125 # now match the imfiles to this list 126 my @unique_skycells = (); 127 my %found_skycells = (); 128 foreach my $imfile (@$imfiles) { 129 my $fileLevel = $imfile->{filelevel}; 130 my $entry = ""; 131 if (lc($fileLevel) eq "chip") { 132 my $class_id = $imfile->{class_id}; 133 my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} ); 134 my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output 135 136 print STDERR "class: $class_id, chiproot: $chipRoot, extname: $extname\n"; 137 138 $entry = $psastroRootFile . '\[' . $extname . '\]'; 139 } else { 140 $entry = "$psastroRootFile"; 118 119 my %unique_skycells = (); # Identified skycells (all unique by virtue of hash property) 120 121 if ($astromSource and $astromSource ne 'NULL') { 122 # We have an astrometry file from psastro 123 my $imfile = $imfiles->[0]; 124 my $camRoot = $imfile->{cam_path_base}; 125 my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file 126 127 my @matchlist = get_overlaps($astromFile, $tess_dir); # List of overlaps 128 129 # Match each of the imfiles to this list 130 foreach my $imfile (@$imfiles) { 131 extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells); 141 132 } 142 143 my @skycells = &select_skycells ($entry, @matchlist); 144 foreach my $skycell (@skycells) { 145 my %overlap = (); 146 $overlap{skycell_id} = $skycell; 147 $overlap{tess_id} = $tess_id; 148 $overlap{cam_id} = $imfile->{cam_id}; 149 $overlap{class_id} = $imfile->{class_id}; 150 $overlap{fault} = $imfile->{fault}; 151 push @overlaps, \%overlap; 152 153 printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id}; 154 155 # generate a unique list of the skycells 156 unless ($found_skycells{$skycell}) { 157 push @unique_skycells, $skycell; 158 $found_skycells{$skycell} = 1; 159 } 133 } else { 134 # We have the imfiles themselves for the WCS 135 foreach my $imfile (@$imfiles) { 136 my $astromFile = $imfile->{chip_uri}; # Astrometry file 137 my @matchlist = get_overlaps($astromFile, $tess_dir); # List of overlaps 138 extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells); 160 139 } 161 140 } 162 141 163 142 # Extract the skycells to images, used as warp templates. 164 foreach my $skycell_id ( @unique_skycells) {143 foreach my $skycell_id (keys %unique_skycells) { 165 144 my $skyDir = caturi($workdir, "tess_" . $tess_id, "sky_" . $skycell_id ); 166 145 my $skyFile = $ipprc->file_prepare( $skycell_id, $skyDir ); … … 211 190 my $command = "$warptool -addoverlap -mapfile $overlapName"; # Command to run warptool 212 191 $command .= " -dbname $dbname" if defined $dbname; 213 192 214 193 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 215 194 run(command => $command, verbose => 1); … … 233 212 } 234 213 214 # Run dvoImageOverlaps to get the overlaps; return the output 215 sub get_overlaps 216 { 217 my $filename = shift; # Filename on which to run dvoImageOverlaps 218 my $tess_dir = shift; # Tessellation directory 219 220 my $command = "$dvoImageOverlaps -D CATDIR $tess_dir " . $ipprc->file_resolve($filename); 221 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 222 run(command => $command, verbose => 1); 223 unless ($success) { 224 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 225 &my_die("Unable to perform dvoImageOverlaps: $error_code", $warp_id, $error_code); 226 } 227 return split ('\n', (join "", @$stdout_buf)); 228 } 229 230 # Extract a list of overlaps for an imfile 231 # 232 # The command "dvoImageOverlaps -accept-astrom -D CATDIR tessellation (megacam)" returns: 233 # 729534pa.cmf[ccd00.hdr] : skycell.051.fits 234 # PSASTRO.OUTPUT[CMF.HEAD] : SKYCELL 235 # [CMF.HEAD] is optionally used for MEF files (SIMPLE or MOSAIC) 236 sub extract_overlaps 237 { 238 my $matches = shift; # Reference to list of skycells from dvoImageOverlaps 239 my $imfile = shift; # Imfile information 240 my $filename = shift; # Filename used with dvoImageOverlaps 241 my $tess_id = shift; # Tessellation identifier 242 my $overlaps = shift; # Reference to list of overlaps 243 my $unique_skycells = shift; # Reference to hash of found skycells 244 245 # Get rid of the path 246 my @dirlist = File::Spec->splitdir( $filename ); # The elements of the full path 247 $filename = pop @dirlist; 248 249 # Work out how to identify this imfile in the output 250 my $fileLevel = $imfile->{filelevel}; 251 my $entry; # How to identify this imfile in the dvoImageOverlaps output 252 if (lc($fileLevel) eq "chip") { 253 my $class_id = $imfile->{class_id}; 254 my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} ); 255 my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output 256 257 print STDERR "class: $class_id, chiproot: $chipRoot, extname: $extname\n"; 258 259 $entry = $filename . '\[' . $extname . '\]'; 260 } else { 261 $entry = $filename; 262 } 263 264 my @skycells = &select_skycells($entry, @$matches); # Matching skycells 265 foreach my $skycell (@skycells) { 266 my %overlap = (); # Overlap information for warptool 267 $overlap{skycell_id} = $skycell; 268 $overlap{tess_id} = $tess_id; 269 $overlap{cam_id} = $imfile->{cam_id}; 270 $overlap{class_id} = $imfile->{class_id}; 271 $overlap{fault} = $imfile->{fault}; 272 push @$overlaps, \%overlap; 273 274 printf STDERR "overlap: %s : %s , %s\n", $skycell, $imfile->{cam_id}, $imfile->{class_id}; 275 276 $unique_skycells->{$skycell} = 1; 277 } 278 279 return; 280 } 281 282 # Find skycells in the list that come from a particular entry 235 283 sub select_skycells 236 284 { … … 250 298 } 251 299 } 252 @skycells;300 return @skycells; 253 301 } 254 302 -
trunk/ippScripts/scripts/warp_skycell.pl
r14391 r14567 94 94 } 95 95 96 # Where do we get the astrometry source from? 97 my $astromSource; # The astrometry source 98 { 99 my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -"; 100 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 101 run(command => $command, verbose => 1); 102 unless ($success) { 103 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 104 &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code); 105 } 106 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 107 &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR); 108 $astromSource = metadataLookupStr('ASTROM.SOURCE'); 109 } 110 96 111 $workdir = caturi( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id ) if defined $workdir; 97 112 my $outputRoot = $ipprc->file_prepare( "$tess_id.$skycell_id.wrp$warp_id", $workdir, $$imfiles[0]->{uri} ); … … 113 128 my $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $imfile->{chip_path_base}, $imfile->{class_id}); # Mask name 114 129 my $weight = $ipprc->filename("PPIMAGE.CHIP.WEIGHT", $imfile->{chip_path_base}, $imfile->{class_id}); # Mask name 115 my $astrom = $ipprc->filename("PSASTRO.OUTPUT.MEF", $imfile->{cam_path_base}); # Astrometry file name116 130 117 131 &my_die("Couldn't find input file: $image", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($image); 118 132 &my_die("Couldn't find input file: $mask", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($mask); 119 &my_die("Couldn't find input file: $astrom", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($astrom); 133 134 my $astrom; # Astrometry file 135 if ($astromSource and $astromSource ne 'NULL') { 136 $astrom = $ipprc->filename($astromSource, $imfile->{cam_path_base}); 137 &my_die("Couldn't find input file: $astrom", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($astrom); 138 } 120 139 121 140 print $imageFile ( $image . "\n"); 122 141 print $maskFile ( $mask . "\n"); 123 142 print $weightFile ( $weight . "\n"); 124 if (defined $inputAstrom) { 143 144 if (defined $inputAstrom and defined $astrom) { 125 145 &my_die("Astrometry files don't match: $inputAstrom vs $astrom", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless $inputAstrom eq $astrom; 126 146 } else { … … 137 157 $command .= " -masklist $maskName"; 138 158 $command .= " -weightlist $weightName"; 139 $command .= " -astrom $inputAstrom" ;159 $command .= " -astrom $inputAstrom" if defined $inputAstrom; 140 160 $command .= " $outputRoot $skyFile"; 141 161 $command .= " -stats $outputStats";
Note:
See TracChangeset
for help on using the changeset viewer.
