- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/diff_skycell.pl (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippScripts/scripts/diff_skycell.pl
r24179 r27840 7 7 use Sys::Hostname; 8 8 my $host = hostname(); 9 my $date = `date`; 9 10 print "\n\n"; 10 print "Starting script $0 on $host \n\n";11 print "Starting script $0 on $host at $date\n\n"; 11 12 12 13 use DateTime; … … 35 36 } 36 37 37 my ($diff_id, $dbname, $threads, $outroot, $reduction, $inverse, $ verbose, $no_update, $no_op, $redirect);38 my ($diff_id, $dbname, $threads, $outroot, $reduction, $inverse, $run_state, $verbose, $no_update, $no_op, $redirect); 38 39 my ($skycell_id, $diff_skyfile_id); 40 my ($use_convolved); 39 41 GetOptions( 40 42 'diff_id=s' => \$diff_id, # Diff identifier … … 43 45 'dbname|d=s' => \$dbname, # Database name 44 46 'threads=s' => \$threads, # Number of threads to use 47 'run-state=s' => \$run_state, # state for run: 'new' or 'update' 45 48 'outroot=s' => \$outroot, # Output root name 46 49 'inverse' => \$inverse, # Make inverse subtraction? 47 50 'reduction=s' => \$reduction, # Reduction class 51 'use_convolved' => \$use_convolved, # Use convolved stacks instead of unconvolved. 48 52 'verbose' => \$verbose, # Print to stdout 49 53 'no-update' => \$no_update, # Don't update the database? … … 54 58 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 55 59 pod2usage( 56 -msg => "Required options: --diff_id --skycell_id --outroot ",60 -msg => "Required options: --diff_id --skycell_id --outroot --run-state --diff_skyfile_id", 57 61 -exitval => 3, 58 62 ) unless defined $diff_id 59 63 and defined $skycell_id 60 64 and defined $diff_skyfile_id 65 and defined $run_state 61 66 and defined $outroot; 62 67 … … 66 71 # my $logDest = $ipprc->filename("LOG.EXP", $outroot); 67 72 my $logDest = "$outroot.log"; 73 $logDest .= ".update" if $run_state eq "update"; 68 74 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect; 69 75 … … 97 103 my $camera; # Camera 98 104 my ($inputMagic, $templateMagic); # Are the inputs been magicked? 105 my ($saveInConv, $saveRefConv); # Save the input or reference convolved images? 106 # Prescan to decide if this is or is not a stack stack diff. The check above confirms we only have two entries. 107 if ((${ $files }[0]->{warp_id} == 0)&& 108 (${ $files }[1]->{warp_id} == 0)) { 109 # Both are zero, so stack stack diff; 110 unless ($use_convolved) { 111 $use_convolved = 0; 112 } 113 } 114 else { 115 # We're in some sort of warp stack or warp warp (don't care about the last one.) 116 $use_convolved = 1; 117 } 118 99 119 foreach my $file (@$files) { 100 120 if (defined $file->{template} and $file->{template}) { 101 $template = $file->{uri};121 # $template = $file->{uri}; 102 122 $templatePath = $file->{path_base}; 103 123 if ($file->{warp_id} == 0) { 104 $templateMask = "PPSTACK.OUTPUT.MASK"; 105 $templateVariance = "PPSTACK.OUTPUT.VARIANCE"; 124 if ($use_convolved) { 125 $template = "PPSTACK.OUTPUT"; 126 $templateMask = "PPSTACK.OUTPUT.MASK"; 127 $templateVariance = "PPSTACK.OUTPUT.VARIANCE"; 128 } 129 else { 130 $template = "PPSTACK.UNCONV"; 131 $templateMask = "PPSTACK.UNCONV.MASK"; 132 $templateVariance = "PPSTACK.UNCONV.VARIANCE"; 133 } 106 134 $templateSources = "PSPHOT.OUT.CMF.MEF"; ## this must be consistent with the value in stack_skycell.pl:161 107 135 # template is a stack so it doesn't need to be magicked … … 109 137 ## use an explicit stack name for psphot output objects 110 138 } else { 139 $template = "PSWARP.OUTPUT"; 111 140 $templateMask = "PSWARP.OUTPUT.MASK"; 112 141 $templateVariance = "PSWARP.OUTPUT.VARIANCE"; 113 142 $templateSources = "PSWARP.OUTPUT.SOURCES"; 114 143 $templateMagic = $file->{magicked}; 144 $saveRefConv = 1; 115 145 } 116 146 } else { 117 $input = $file->{uri};147 # $input = $file->{uri}; 118 148 $inputPath = $file->{path_base}; 119 149 $inputMagic = $file->{magicked}; # if input is a stack the output can't be "magicked" 120 150 if ($file->{warp_id} == 0) { 121 $inputMask = "PPSTACK.OUTPUT.MASK"; 122 $inputVariance = "PPSTACK.OUTPUT.VARIANCE"; 151 if ($use_convolved) { 152 $input = "PPSTACK.OUTPUT"; 153 $inputMask = "PPSTACK.OUTPUT.MASK"; 154 $inputVariance = "PPSTACK.OUTPUT.VARIANCE"; 155 } 156 else { 157 $input = "PPSTACK.UNCONV"; 158 $inputMask = "PPSTACK.UNCONV.MASK"; 159 $inputVariance = "PPSTACK.UNCONV.VARIANCE"; 160 } 123 161 $inputSources = "PSPHOT.OUT.CMF.MEF"; ## this must be consistent with the value in stack_skycell.pl:161 124 162 } else { 163 $input = "PSWARP.OUTPUT"; 125 164 $inputMask = "PSWARP.OUTPUT.MASK"; 126 165 $inputVariance = "PSWARP.OUTPUT.VARIANCE"; 127 166 $inputSources = "PSWARP.OUTPUT.SOURCES"; 167 $saveInConv = 1; 128 168 } 129 169 } … … 134 174 $tess_id = $file->{tess_id}; 135 175 } 136 if (defined $skycell_id) { 137 &my_die("Skycell identifiers don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless 138 $file->{skycell_id} eq $skycell_id; 139 } else { 140 $skycell_id = $file->{skycell_id}; 141 } 176 &my_die("Skycell identifiers don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless 177 $file->{skycell_id} eq $skycell_id; 142 178 if (defined $camera) { 143 179 &my_die("Cameras don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera; … … 155 191 # The output file will be considered magicked if the input has been magicked and the 156 192 # template is either a stack or a warp that has been magicked. 157 # note that difftool -inputskyfile outputs the magicked boolean as an int not T or F 158 # because the output is constructed from a union of two selects 159 my $magicked = $inputMagic && $templateMagic; 193 my $magicked = $inputMagic && $templateMagic ? $inputMagic : 0; 160 194 161 195 # Recipes to use based on reduction class … … 166 200 &my_die("Couldn't find selected reduction for DIFF_PPSUB and DIFF_PSPHOT: $reduction\n", $diff_id, $skycell_id, $PS_EXIT_CONFIG_ERROR); 167 201 } 202 203 print "reduction: $reduction\n"; 204 print "recipe_ppSub: $recipe_ppSub\n"; 168 205 169 206 # print "templateMask: $templateMask\n"; … … 176 213 # print "inputSources: $inputSources\n"; 177 214 215 $input = $ipprc->filename($input, $inputPath); 178 216 $inputMask = $ipprc->filename($inputMask, $inputPath); 179 217 $inputVariance = $ipprc->filename($inputVariance, $inputPath); 180 218 $inputSources = $ipprc->filename($inputSources, $inputPath); 181 219 220 $template = $ipprc->filename($template, $templatePath); 182 221 $templateMask = $ipprc->filename($templateMask, $templatePath); 183 222 $templateVariance = $ipprc->filename($templateVariance, $templatePath); 184 223 $templateSources = $ipprc->filename($templateSources, $templatePath); 185 224 225 print "template: $template\n"; 186 226 print "templateMask: $templateMask\n"; 187 227 print "templatePath: $templatePath\n"; 228 print "input: $input\n"; 188 229 print "inputMask: $inputMask\n"; 189 230 print "inputPath: $inputPath\n"; … … 213 254 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot); 214 255 256 if ($run_state eq 'update') { 257 $traceDest .= '.update'; 258 $outputStats .= '.update'; 259 } 260 215 261 my ($inverseName, $inverseMask, $inverseVariance, $inverseSources); 216 262 if ($inverse) { … … 224 270 225 271 # Perform subtraction 226 unless ($no_op){272 { 227 273 my $command = "$ppSub $outroot"; 228 274 $command .= " -inimage $input"; … … 236 282 $command .= " -stats $outputStats"; 237 283 $command .= " -threads $threads" if defined $threads; 284 if ($run_state eq "new") { 285 $command .= " -dumpconfig $configuration"; 286 } else { 287 my $configurationReal = $ipprc->file_resolve($configuration) or &my_die("Couldn't resolve configuration file: $configuration", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR); 288 $command .= " -ipprc $configurationReal"; 289 } 290 $command .= " -save-inconv" if defined $saveInConv; 291 $command .= " -save-refconv" if defined $saveRefConv; 238 292 $command .= " -recipe PPSUB $recipe_ppSub"; 239 293 $command .= " -recipe PSPHOT $recipe_psphot"; … … 242 296 $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF"; 243 297 $command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF"; 244 $command .= " -photometry"; 298 if ($run_state eq "new") { 299 $command .= " -photometry"; 300 } 245 301 $command .= " -inverse" if $inverse; 246 302 $command .= " -tracedest $traceDest -log $logDest"; 247 $command .= " -dumpconfig $configuration";248 303 $command .= " -dbname $dbname" if defined $dbname; 249 304 $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id; 250 305 $command .= " -source_id $source_id" if defined $source_id; 251 306 252 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 253 run(command => $command, verbose => $verbose); 254 unless ($success) { 255 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 256 &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code); 257 } 258 259 my $outputStatsReal = $ipprc->file_resolve($outputStats); 260 &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal; 261 262 # measure chip stats 263 $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL"; 264 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 265 run(command => $command, verbose => $verbose); 266 unless ($success) { 267 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 268 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code); 269 } 270 foreach my $line (@$stdout_buf) { 271 $cmdflags .= " $line"; 272 } 273 chomp $cmdflags; 274 275 my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 276 277 if (!$quality) { 278 &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName); 279 &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 280 &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance); 281 &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 282 &my_die("Couldn't find expected output file: $jpeg1Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name); 283 &my_die("Couldn't find expected output file: $jpeg2Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name); 284 if ($inverse) { 285 &my_die("Couldn't find expected output file: $inverseName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName); 286 &my_die("Couldn't find expected output file: $inverseMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask); 287 &my_die("Couldn't find expected output file: $inverseVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance); 288 &my_die("Couldn't find expected output file: $inverseSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources); 289 } 290 } 291 } 292 293 unless ($no_update) { 294 295 # Add the subtraction result 296 { 297 my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -path_base $outroot"; 298 $command .= " $cmdflags"; 299 $command .= " -magicked" if $magicked; 300 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 301 $command .= " -hostname $host" if defined $host; 302 $command .= " -dbname $dbname" if defined $dbname; 303 307 unless ($no_op) { 304 308 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 305 309 run(command => $command, verbose => $verbose); 306 310 unless ($success) { 307 311 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 308 &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $skycell_id, $error_code); 312 &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code); 313 } 314 315 my $outputStatsReal = $ipprc->file_resolve($outputStats); 316 &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal); 317 318 # measure chip stats 319 $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL"; 320 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 321 run(command => $command, verbose => $verbose); 322 unless ($success) { 323 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 324 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code); 325 } 326 foreach my $line (@$stdout_buf) { 327 $cmdflags .= " $line"; 328 } 329 chomp $cmdflags; 330 331 my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 332 333 if (!$quality) { 334 &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName); 335 &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 336 &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance); 337 &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 338 &my_die("Couldn't find expected output file: $jpeg1Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name); 339 &my_die("Couldn't find expected output file: $jpeg2Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name); 340 if ($inverse) { 341 &my_die("Couldn't find expected output file: $inverseName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName); 342 &my_die("Couldn't find expected output file: $inverseMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask); 343 &my_die("Couldn't find expected output file: $inverseVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance); 344 &my_die("Couldn't find expected output file: $inverseSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources); 345 if ($run_state eq 'new') { 346 &my_die("Couldn't find expected output file: $configuration", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($configuration); 347 } 348 } 349 } 350 } else { 351 print "Not executing: $command\n"; 352 } 353 } 354 355 unless ($no_update) { 356 357 # Add the subtraction result 358 { 359 my $command = "$difftool -diff_id $diff_id -skycell_id $skycell_id"; 360 $command .= " -magicked $magicked" if $magicked; 361 if ($run_state eq 'new') { 362 $command .= " -adddiffskyfile -path_base $outroot"; 363 $command .= " $cmdflags"; 364 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 365 $command .= " -hostname $host" if defined $host; 366 } else { 367 $command .= " -tofullskyfile"; 368 } 369 $command .= " -dbname $dbname" if defined $dbname; 370 371 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 372 run(command => $command, verbose => $verbose); 373 unless ($success) { 374 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 375 my $err_message = $run_state eq "update" ? 376 "Unable to perform difftool -adddiffskyfile" : 377 "Unable to perform difftool -tofullskyfile"; 378 &my_die("$err_message: $error_code", $diff_id, $skycell_id, $error_code); 309 379 } 310 380 } … … 323 393 warn($msg); 324 394 if (defined $diff_id and defined $skycell_id and not $no_update) { 325 my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -fault $exit_code"; 326 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 327 $command .= " -hostname $host" if defined $host; 328 $command .= " -path_base $outroot" if defined $outroot; 329 $command .= " -dbname $dbname" if defined $dbname; 395 my $command = "$difftool -diff_id $diff_id -skycell_id $skycell_id -fault $exit_code"; 396 if ($run_state eq 'new') { 397 $command .= " -adddiffskyfile"; 398 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 399 $command .= " -hostname $host" if defined $host; 400 $command .= " -path_base $outroot" if defined $outroot; 401 $command .= " -dbname $dbname" if defined $dbname; 402 } else { 403 $command .= " -updatediffskyfile"; 404 } 330 405 run(command => $command, verbose => $verbose); 331 406 }
Note:
See TracChangeset
for help on using the changeset viewer.
