- Timestamp:
- May 5, 2011, 10:05:10 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110404/ippScripts/scripts/staticsky.pl
r31164 r31439 32 32 my $staticskytool = can_run('staticskytool') or (warn "Can't find staticskytool" and $missing_tools = 1); 33 33 my $psphotStack = can_run('psphotStack') or (warn "Can't find psphotStack" and $missing_tools = 1); 34 my $psphot = can_run('psphot') or (warn "Can't find psphot" and $missing_tools = 1); 34 35 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 36 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 35 37 if ($missing_tools) { 36 38 warn("Can't find required tools."); … … 96 98 } 97 99 100 # Recipes to use based on reduction class 101 $reduction = 'DEFAULT' unless defined $reduction; 102 103 98 104 # generate the input 99 105 print $listFile "INPUT MULTI\n"; 100 106 my $nInputs = @$files; 101 107 102 my $configuration = $ipprc->filename("PSPHOT.STACK.CONFIG", $outroot); 103 104 foreach my $file (@$files) { 105 print $listFile "INPUT METADATA\n"; 106 107 # XXX if we take the input from 'warp', we will need to make different selections here 108 my $path_base = $file->{path_base}; 109 print "input: $path_base\n"; 110 111 my $imageCnv = $ipprc->filename("PPSTACK.OUTPUT", $path_base ); # Image name 112 my $maskCnv = $ipprc->filename("PPSTACK.OUTPUT.MASK", $path_base ); # Mask name 113 my $weightCnv = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name 114 115 my $imageRaw = $ipprc->filename("PPSTACK.UNCONV", $path_base ); # Image name 116 my $maskRaw = $ipprc->filename("PPSTACK.UNCONV.MASK", $path_base ); # Mask name 117 my $weightRaw = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name 118 119 my $sources = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $path_base ); # Sources name 120 121 # XXX is this the correct PSF file? 122 my $psfCnv = $ipprc->filename("PPSTACK.TARGET.PSF", $path_base ); # PSF name 123 124 # XXX we could make some different choices if some inputs do not exist... 125 &my_die("Couldn't find input: $imageRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageRaw"); 126 &my_die("Couldn't find input: $maskRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskRaw"); 127 &my_die("Couldn't find input: $weightRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightRaw"); 128 &my_die("Couldn't find input: $imageCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageCnv"); 129 &my_die("Couldn't find input: $maskCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskCnv"); 130 &my_die("Couldn't find input: $weightCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightCnv"); 131 &my_die("Couldn't find input: $psfCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfCnv"); 132 &my_die("Couldn't find input: $sources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources"); 133 134 print $listFile " RAW:IMAGE STR " . $imageRaw . "\n"; 135 print $listFile " RAW:MASK STR " . $maskRaw . "\n"; 136 print $listFile " RAW:VARIANCE STR " . $weightRaw . "\n"; 137 138 print $listFile " CNV:IMAGE STR " . $imageCnv . "\n"; 139 print $listFile " CNV:MASK STR " . $maskCnv . "\n"; 140 print $listFile " CNV:VARIANCE STR " . $weightCnv . "\n"; 141 print $listFile " CNV:PSF STR " . $psfCnv . "\n"; 142 143 print $listFile " SOURCES STR " . $sources . "\n"; 144 145 print $listFile "END\n\n"; 146 } 147 148 # Recipes to use based on reduction class 149 $reduction = 'DEFAULT' unless defined $reduction; 150 my $recipe_psphot = $ipprc->reduction($reduction, 'STACKPHOT_PSPHOT'); # Recipe to use for psphot 151 my $recipe_ppsub = $ipprc->reduction($reduction, 'STACKPHOT_PPSUB'); # Recipe to use for ppsub 152 my $recipe_ppstack = $ipprc->reduction($reduction, 'STACKPHOT_PPSTACK'); # Recipe to use for ppstack 153 unless ($recipe_psphot) { 154 &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR); 155 } 156 157 print "reduction: $reduction\n"; 158 print "recipe_psphot: $recipe_psphot\n"; 159 print "recipe_ppsub: $recipe_ppsub\n"; 160 print "recipe_ppstack: $recipe_ppstack\n"; 161 162 # my $cmdflags; 163 164 # Perform stack photometry analysis 165 { 166 my $command = "$psphotStack $outroot"; 167 $command .= " -input $listName"; 168 $command .= " -threads $threads" if defined $threads; 169 $command .= " -recipe PSPHOT $recipe_psphot"; 170 $command .= " -recipe PPSUB $recipe_ppsub"; 171 $command .= " -recipe PPSTACK $recipe_ppstack"; 172 $command .= " -dumpconfig $configuration"; 173 $command .= " -tracedest $traceDest -log $logDest"; 174 # $command .= " -dbname $dbname" if defined $dbname; 175 # $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id; 176 # $command .= " -source_id $source_id" if defined $source_id; 177 178 unless ($no_op) { 179 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 180 unless ($success) { 181 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 182 &my_die("Unable to perform psphotStack: $error_code", $sky_id, $error_code); 183 } 184 185 # my $outputStatsReal = $ipprc->file_resolve($outputStats); 186 # &my_die("Couldn't find expected output file: $outputStats", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal); 187 188 # measure chip stats 189 # $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL"; 190 # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 191 # run(command => $command, verbose => $verbose); 192 # unless ($success) { 193 # $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 194 # &my_die("Unable to perform ppStatsFromMetadata: $error_code", $sky_id, $error_code); 195 # } 196 # foreach my $line (@$stdout_buf) { 197 # $cmdflags .= " $line"; 198 # } 199 # chomp $cmdflags; 200 201 # my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 202 203 my $quality = 0; 204 if (!$quality) { 205 206 # Get the output filenames 207 # we have one set of output files per input file set 208 for (my $i = 0; $i < @$files; $i++) { 209 my $outputName = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $i); 210 my $outputMask = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $i); 211 my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $i); 212 my $outputSources = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $i); 213 214 # XXX these are optional and not generated by default 215 # &my_die("Couldn't find expected output file: $outputName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName); 216 # &my_die("Couldn't find expected output file: $outputMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 217 # &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance); 218 &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 219 } 220 221 #my $configuration = $ipprc->filename("PPSUB.CONFIG", $outroot); 222 #my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot); 223 #my $traceDest = $ipprc->filename("TRACE.EXP", $outroot); 224 225 my $chisqName = $ipprc->filename("PSPHOT.CHISQ.IMAGE", $outroot); 226 my $chisqMask = $ipprc->filename("PSPHOT.CHISQ.MASK", $outroot); 227 my $chisqVariance = $ipprc->filename("PSPHOT.CHISQ.VARIANCE", $outroot); 228 229 # XXX check the recipe -- should we expect these to exist? 230 # &my_die("Couldn't find expected output file: $chisqName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName); 231 # &my_die("Couldn't find expected output file: $chisqMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask); 232 # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance); 233 } 234 } else { 235 print "Not executing: $command\n"; 236 } 108 if ($nInputs > 1) { 109 my $recipe_psphot = $ipprc->reduction($reduction, 'STACKPHOT_PSPHOT'); # Recipe to use for psphot 110 my $recipe_ppsub = $ipprc->reduction($reduction, 'STACKPHOT_PPSUB'); # Recipe to use for ppsub 111 my $recipe_ppstack = $ipprc->reduction($reduction, 'STACKPHOT_PPSTACK'); # Recipe to use for ppstack 112 unless ($recipe_psphot) { 113 &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR); 114 } 115 116 print "reduction: $reduction\n"; 117 print "recipe_psphot: $recipe_psphot\n"; 118 print "recipe_ppsub: $recipe_ppsub\n"; 119 print "recipe_ppstack: $recipe_ppstack\n"; 120 my $configuration = $ipprc->filename("PSPHOT.STACK.CONFIG", $outroot); 121 122 foreach my $file (@$files) { 123 print $listFile "INPUT METADATA\n"; 124 125 # XXX if we take the input from 'warp', we will need to make different selections here 126 my $path_base = $file->{path_base}; 127 print "input: $path_base\n"; 128 129 my $imageCnv = $ipprc->filename("PPSTACK.OUTPUT", $path_base ); # Image name 130 my $maskCnv = $ipprc->filename("PPSTACK.OUTPUT.MASK", $path_base ); # Mask name 131 my $weightCnv = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name 132 133 my $imageRaw = $ipprc->filename("PPSTACK.UNCONV", $path_base ); # Image name 134 my $maskRaw = $ipprc->filename("PPSTACK.UNCONV.MASK", $path_base ); # Mask name 135 my $weightRaw = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name 136 137 my $sources = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $path_base ); # Sources name 138 139 # XXX is this the correct PSF file? 140 my $psfCnv = $ipprc->filename("PPSTACK.TARGET.PSF", $path_base ); # PSF name 141 142 # XXX we could make some different choices if some inputs do not exist... 143 &my_die("Couldn't find input: $imageRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageRaw"); 144 &my_die("Couldn't find input: $maskRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskRaw"); 145 &my_die("Couldn't find input: $weightRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightRaw"); 146 &my_die("Couldn't find input: $imageCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageCnv"); 147 &my_die("Couldn't find input: $maskCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskCnv"); 148 &my_die("Couldn't find input: $weightCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightCnv"); 149 &my_die("Couldn't find input: $psfCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfCnv"); 150 &my_die("Couldn't find input: $sources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources"); 151 152 print $listFile " RAW:IMAGE STR " . $imageRaw . "\n"; 153 print $listFile " RAW:MASK STR " . $maskRaw . "\n"; 154 print $listFile " RAW:VARIANCE STR " . $weightRaw . "\n"; 155 156 print $listFile " CNV:IMAGE STR " . $imageCnv . "\n"; 157 print $listFile " CNV:MASK STR " . $maskCnv . "\n"; 158 print $listFile " CNV:VARIANCE STR " . $weightCnv . "\n"; 159 print $listFile " CNV:PSF STR " . $psfCnv . "\n"; 160 161 print $listFile " SOURCES STR " . $sources . "\n"; 162 163 print $listFile "END\n\n"; 164 } 165 166 # my $cmdflags; 167 168 # Perform stack photometry analysis 169 { 170 my $command = "$psphotStack $outroot"; 171 $command .= " -input $listName"; 172 $command .= " -threads $threads" if defined $threads; 173 $command .= " -recipe PSPHOT $recipe_psphot"; 174 $command .= " -recipe PPSUB $recipe_ppsub"; 175 $command .= " -recipe PPSTACK $recipe_ppstack"; 176 $command .= " -dumpconfig $configuration"; 177 $command .= " -tracedest $traceDest -log $logDest"; 178 # $command .= " -dbname $dbname" if defined $dbname; 179 180 unless ($no_op) { 181 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 182 unless ($success) { 183 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 184 &my_die("Unable to perform psphotStack: $error_code", $sky_id, $error_code); 185 } 186 187 # my $outputStatsReal = $ipprc->file_resolve($outputStats); 188 # &my_die("Couldn't find expected output file: $outputStats", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal); 189 190 # measure chip stats 191 # $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL"; 192 # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 193 # run(command => $command, verbose => $verbose); 194 # unless ($success) { 195 # $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 196 # &my_die("Unable to perform ppStatsFromMetadata: $error_code", $sky_id, $error_code); 197 # } 198 # foreach my $line (@$stdout_buf) { 199 # $cmdflags .= " $line"; 200 # } 201 # chomp $cmdflags; 202 203 # my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 204 205 my $quality = 0; 206 if (!$quality) { 207 208 # Get the output filenames 209 # we have one set of output files per input file set 210 for (my $i = 0; $i < @$files; $i++) { 211 my $outputName = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $i); 212 my $outputMask = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $i); 213 my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $i); 214 my $outputSources = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $i); 215 216 # XXX these are optional and not generated by default 217 # &my_die("Couldn't find expected output file: $outputName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName); 218 # &my_die("Couldn't find expected output file: $outputMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 219 # &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance); 220 &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 221 } 222 223 #my $configuration = $ipprc->filename("PPSUB.CONFIG", $outroot); 224 #my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot); 225 #my $traceDest = $ipprc->filename("TRACE.EXP", $outroot); 226 227 my $chisqName = $ipprc->filename("PSPHOT.CHISQ.IMAGE", $outroot); 228 my $chisqMask = $ipprc->filename("PSPHOT.CHISQ.MASK", $outroot); 229 my $chisqVariance = $ipprc->filename("PSPHOT.CHISQ.VARIANCE", $outroot); 230 231 # XXX check the recipe -- should we expect these to exist? 232 # &my_die("Couldn't find expected output file: $chisqName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName); 233 # &my_die("Couldn't find expected output file: $chisqMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask); 234 # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance); 235 } 236 } else { 237 print "Not executing: $command\n"; 238 } 239 } 240 } else { 241 # single input. Run psphot 242 # find the recipe 243 my $recipe_psphot = $ipprc->reduction($reduction, 'STACKPHOT_SINGLE_PSPHOT'); # Recipe to use for psphot 244 unless ($recipe_psphot) { 245 &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR); 246 } 247 248 print "reduction: $reduction\n"; 249 print "recipe_psphot: $recipe_psphot\n"; 250 251 my $configuration = $ipprc->filename("PSPHOT.SKY.CONFIG", $outroot); 252 253 my $file = $files->[0]; 254 255 # XXX if we take the input from 'warp', we will need to make different selections here 256 my $path_base = $file->{path_base}; 257 print "input: $path_base\n"; 258 259 # examine the recipe to determine whether to analyze the "raw" or convolved images 260 my $command = "$ppConfigDump -camera $camera -dump-recipe PSPHOT -recipe PSPHOT $recipe_psphot -"; 261 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 262 run(command => $command, verbose => 0); 263 unless ($success) { 264 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 265 &my_die("Unable to perform ppConfigDump: $error_code", $sky_id, $PS_EXIT_SYS_ERROR); 266 } 267 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 268 &my_die("Unable to parse metadata config doc", $sky_id, $PS_EXIT_SYS_ERROR); 269 270 my $use_raw = metadataLookupBool($recipeData, 'PSPHOT.STACK.USE.RAW'); 271 272 my ($image, $mask, $variance); 273 if ($use_raw) { 274 $image = $ipprc->filename("PPSTACK.UNCONV", $path_base ); # Image name 275 $mask = $ipprc->filename("PPSTACK.UNCONV.MASK", $path_base ); # Mask name 276 $variance = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name 277 } else { 278 $image = $ipprc->filename("PPSTACK.OUTPUT", $path_base ); # Image name 279 $mask = $ipprc->filename("PPSTACK.OUTPUT.MASK", $path_base ); # Mask name 280 $variance = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name 281 } 282 283 my $output_sources_filerule = "PSPHOT.OUT.CMF.MEF"; 284 my $output_psf_filerule = "PSPHOT.PSF.SKY.SAVE"; 285 286 # XXX we could make some different choices if some inputs do not exist... 287 &my_die("Couldn't find input: $image", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$image"); 288 &my_die("Couldn't find input: $mask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$mask"); 289 &my_die("Couldn't find input: $variance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$variance"); 290 291 # Perform stack photometry analysis 292 { 293 my $command = "$psphot $outroot"; 294 $command .= " -file $image"; 295 $command .= " -mask $mask"; 296 $command .= " -variance $variance"; 297 $command .= " -threads $threads" if defined $threads; 298 $command .= " -recipe PSPHOT $recipe_psphot"; 299 $command .= " -dumpconfig $configuration" if $configuration; 300 $command .= " -tracedest $traceDest -log $logDest"; 301 $command .= " -F PSPHOT.OUTPUT $output_sources_filerule"; 302 $command .= " -F PSPHOT.PSF.SAVE $output_psf_filerule"; 303 304 unless ($no_op) { 305 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 306 unless ($success) { 307 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 308 &my_die("Unable to perform psphot: $error_code", $sky_id, $error_code); 309 } 310 311 my $quality = 0; 312 if (!$quality) { 313 my $outputSources = $ipprc->filename($output_sources_filerule, $outroot); 314 &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 315 my $outputPSF = $ipprc->filename($output_psf_filerule, $outroot); 316 &my_die("Couldn't find expected output file: $outputPSF", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF); 317 } 318 319 &my_die("Couldn't find expected output file: $configuration", $sky_id, $PS_EXIT_SYS_ERROR) 320 unless $ipprc->file_exists($configuration); 321 } else { 322 print "Not executing: $command\n"; 323 } 324 } 237 325 } 238 326
Note:
See TracChangeset
for help on using the changeset viewer.
