- Timestamp:
- Jul 3, 2013, 1:43:50 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130509/ippScripts/scripts/camera_exp.pl
r35367 r35747 53 53 'skip-binned' => \$skip_binned, # override recipe - don't create binned images 54 54 'skip-refmask' => \$skip_masks, # override recipe - don't create refmask 55 'bkg-only' => \$bkg_only, # override recipe - only do background continuity55 # 'bkg-only' => \$bkg_only, # override recipe - only do background continuity 56 56 'verbose' => \$verbose, # Print to stdout 57 57 'no-update' => \$no_update, # Update the database? … … 80 80 my $replicateOutputs = 1; 81 81 82 $ipprc->outroot_prepare($outroot); 83 82 84 my $logDest; 83 85 my $traceDest; … … 114 116 my $bkg_recipe = 'PPIMAGE_BKGCONT'; # Add to reduction? 115 117 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 118 119 my $recipeData; 120 { 121 # Get the PSASTRO recipe 122 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -"; 123 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 124 run(command => $command, verbose => $verbose); 125 unless ($success) { 126 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 127 &my_die("Unable to perform ppConfigDump: $error_code", $cam_id, $PS_EXIT_CONFIG_ERROR); 128 } 129 $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 130 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_CONFIG_ERROR); 131 } 116 132 117 133 my $cmdflags; … … 158 174 chomp $cmdflags; 159 175 160 { # Determine if FWHM is too large to bother continuing. 161 my $maxFWHM = 0; 162 # XXX: temporary hack if this is a CNP exposure set maxFWHM to a large 163 # value. 164 # Before the next tag we will put this into a recipe 165 if ($outroot =~ /CNP/) { 166 $maxFWHM = 25; 167 } else { 168 my $command = "$ppConfigDump -camera $camera -get-key MAX_ALLOWED_FWHM"; 169 my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 170 run(command => $command, verbose => $verbose); 171 unless ($success) { 172 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 173 &my_die("Unable to perform ppConfigDump: $error_code", $cam_id, $PS_EXIT_CONFIG_ERROR); 174 } 175 if (@$stdout_buf) { 176 my $cameraConfig = $mdcParser->parse(join "", @$stdout_buf) or 177 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_CONFIG_ERROR); 178 $maxFWHM = metadataLookupStr($cameraConfig, 'MAX_ALLOWED_FWHM'); 179 } 180 } 181 if ($maxFWHM) { 182 my $expFWHM; 183 ($expFWHM) = $cmdflags =~ /-fwhm_major (\d+)/; 184 185 if ($expFWHM > $maxFWHM) { 186 print "Setting quality to 4007 due to large FWHM: exposure: $expFWHM maximum: $maxFWHM\n"; 187 $cmdflags .= " -quality 4007 "; # This corresponds to PSASTRO_ERR_DATA 188 $no_op = 1; 189 } 190 } 191 } 192 } 193 194 195 my $produceMasks; # Produce masks? 176 # Determine if FWHM is too large to bother continuing. 177 my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.ALLOWED.FWHM'); 178 if ($maxFWHM) { 179 my $expFWHM; 180 ($expFWHM) = $cmdflags =~ /-fwhm_major (\d+)/; 181 182 if ($expFWHM > $maxFWHM) { 183 print "Setting quality to 4007 due to large FWHM: exposure: $expFWHM maximum: $maxFWHM\n"; 184 $cmdflags .= " -quality 4007 "; # This corresponds to PSASTRO_ERR_DATA 185 $no_op = 1; 186 } 187 } 188 } 189 190 191 my $do_masks; # Produce masks? 196 192 if (!$skip_masks) { 197 # Get the PSASTRO recipe 198 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -"; 199 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 200 run(command => $command, verbose => $verbose); 201 unless ($success) { 202 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 203 &my_die("Unable to perform ppConfigDump: $error_code", $cam_id, $PS_EXIT_CONFIG_ERROR); 204 } 205 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 206 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_CONFIG_ERROR); 207 208 $produceMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK'); 193 $do_masks = metadataLookupBool($recipeData, 'REFSTAR_MASK'); 209 194 } 210 195 … … 220 205 my ($list5File, $list5Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b5.list.XXXX", UNLINK => !$save_temps ); # For background models 221 206 222 # XXX we perform astrometry iff photometry output exists 207 208 my $do_stats; 209 my $do_bkg; 210 my $do_jpegs; 211 my $fpaStats; 212 my $psastroInputArg; 213 if ($run_state eq 'new') { 214 $do_stats = 1; 215 $do_bkg = 1; 216 $do_jpegs = !$skip_binned; 217 $fpaStats = prepare_output("PSASTRO.STATS", $outroot, undef, 1); 218 $psastroInputArg = " -list $list3Name"; 219 } else { 220 # for $run_state eq 'update' we only rebuild the masks using psastro 221 $do_stats = 0; 222 $do_jpegs = 0; 223 $do_bkg = 1; # we could skip this step if camProcessedExp.backgroun_model is non zero 224 225 if (!$do_masks) { 226 &my_die("run_state is update but do_masks is F. I have nothing to do!!", $cam_id, $PS_EXIT_UNKNOWN_ERROR) 227 } 228 229 # the input to psastro is the original PSASTRO.OUTPUT 230 231 # Check for file with rule PSASTRO.OUTPUT.ORGINAL 232 # This file will exist if we attempted to update this camRun before but faulted 233 # XXX: make sure cleanup deals with these files 234 my $inputObjects = $ipprc->filename("PSASTRO.OUTPUT.ORIGINAL", $outroot, undef); 235 if (!$ipprc->file_exists($inputObjects)) { 236 # not found so original file should still be in place. 237 # Rename it. 238 my $originalObjects = $ipprc->filename("PSASTRO.OUTPUT", $outroot, undef); 239 if ($ipprc->file_exists($originalObjects)) { 240 241 unless ($ipprc->file_rename($originalObjects, $inputObjects)) { 242 &my_die("failed to rename $originalObjects to $inputObjects", $cam_id, $PS_EXIT_UNKNOWN_ERROR); 243 } 244 245 # ok ready to go 246 } else { 247 print STDERR "failed to find input objects to update\n"; 248 print STDERR "Original file name: $originalObjects\n"; 249 print STDERR "Saved file name: $inputObjects\n"; 250 251 &my_die("Cannot proceed.", $cam_id, $PS_EXIT_DATA_ERROR); 252 253 # XXX: actually we could use the chip stage cmfs as inputs and turn on astrometry 254 # ... except that somebody (me) got the bright idea to save space and 255 # changed chip stage cleanup to remove them. So we're kind of stuck. 256 } 257 } 258 $psastroInputArg = " -file $inputObjects -skipastro"; 259 } 260 261 223 262 my @outMasks; # Names of output masks 224 263 my @bkg_models; # Names of output background models 225 264 foreach my $file (@$files) { 265 # we perform astrometry iff photometry output exists 226 266 next if $file->{quality} != 0; 267 227 268 # use the path_base as OUTPUT root and convert the filenames with ipprc->filename: 228 269 my $class_id = $file->{class_id}; … … 239 280 print $list5File ($ipprc->filename("PSPHOT.BACKMDL", $file->{path_base}, $class_id) . "\n"); 240 281 241 push @outMasks, prepare_output("PSASTRO.OUTPUT.MASK", $outroot, $class_id, 1) if $ produceMasks;242 push @bkg_models, prepare_output("PPIMAGE.BACKMDL", $outroot, $class_id, 1) ;282 push @outMasks, prepare_output("PSASTRO.OUTPUT.MASK", $outroot, $class_id, 1) if $do_masks; 283 push @bkg_models, prepare_output("PPIMAGE.BACKMDL", $outroot, $class_id, 1) if $do_bkg; 243 284 } 244 285 close $list1File; … … 247 288 close $list4File; 248 289 close $list5File; 249 # Output products 250 $ipprc->outroot_prepare($outroot); 290 291 # Prepare the Output products 251 292 252 293 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs 253 my $jpeg1 = prepare_output("PPIMAGE.JPEG1", $outroot, undef, 1); 254 my $jpeg2 = prepare_output("PPIMAGE.JPEG2", $outroot, undef, 1); 255 my $fpaObjects = prepare_output("PSASTRO.OUTPUT", $outroot, undef, 1); 256 my $configuration = prepare_output("PSASTRO.CONFIG", $outroot, undef, 1); 257 258 my $do_stats; 259 my $fpaStats; 294 my $jpeg1 = prepare_output("PPIMAGE.JPEG1", $outroot, undef, 1) if $do_jpegs; 295 my $jpeg2 = prepare_output("PPIMAGE.JPEG2", $outroot, undef, 1) if $do_jpegs; 296 my $fpaObjects = prepare_output("PSASTRO.OUTPUT", $outroot, undef, 1) if !$bkg_only; 297 298 my $configuration; 260 299 if ($run_state eq 'new') { 261 $do_stats = 1; 262 $fpaStats = prepare_output("PSASTRO.STATS", $outroot, undef, 1); 300 $configuration = prepare_output("PSASTRO.CONFIG", $outroot, undef, 1); 263 301 } else { 264 $do_stats = 0; 265 } 302 # Do not use the original recipes for updates because they might contain the 303 # recipe values that caused the masks to get fouled up in the first place 304 # $configuration = $ipprc->filename("PSASTRO.CONFIG", $outroot, undef); 305 } 306 266 307 267 308 unless ($no_op) { … … 269 310 ## build the output JPEG images first so we get them even if the astrometry fails 270 311 271 # Make the jpeg for binning 1272 if (!$skip_binned and ($run_state eq 'new')) {312 if ($do_jpegs) { 313 # Make the jpeg for binning 1 273 314 my $command = "$ppImage -list $list1Name $outroot"; # Command to run 274 315 $command .= " -recipe PPIMAGE $recipe1"; … … 282 323 } 283 324 check_output($jpeg1, $replicateOutputs); 284 } 285 286 # Make the jpeg for binning 2 287 if (!$skip_binned and ($run_state eq 'new')) { 288 my $command = "$ppImage -list $list2Name $outroot"; # Command to run 325 326 # Make the jpeg for binning 2 327 328 $command = "$ppImage -list $list2Name $outroot"; # Command to run 289 329 $command .= " -recipe PPIMAGE $recipe2"; 290 330 $command .= " -dbname $dbname" if defined $dbname; 291 331 292 my( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =332 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 293 333 run(command => $command, verbose => $verbose); 294 334 unless ($success) { … … 302 342 # run psastro on the chipObjects, producing fpaObjects 303 343 my $command; 304 $command = "$psastro";305 $command .= " -list $list3Name";306 $command .= " -masklist $list4Name" if $ produceMasks;344 $command = $psastro; 345 $command .= " $psastroInputArg"; 346 $command .= " -masklist $list4Name" if $do_masks; 307 347 $command .= " $outroot"; 308 348 $command .= " -recipe PSASTRO $recipe_psastro"; 309 $command .= " -Db PSASTRO:REFSTAR_MASK F" if $skip_masks;349 $command .= " -Db PSASTRO:REFSTAR_MASK F" if !$do_masks; 310 350 $command .= " -tracedest $traceDest -log $logDest"; 311 351 $command .= " -dbname $dbname" if defined $dbname; … … 314 354 $command .= " -dumpconfig $configuration"; 315 355 } elsif ($run_state eq 'update') { 316 $command .= " -ipprc $configuration" ;356 $command .= " -ipprc $configuration" if $configuration; 317 357 } else { 318 358 &my_die("invalid value for run-state: $run_state", $cam_id, $PS_EXIT_CONFIG_ERROR); … … 362 402 } 363 403 } 404 364 405 # Construct FPA continuity corrected background images 365 406 if ($camera =~ /ISP/) { 366 407 print "Skipping FPA continuity corrected background images for ISP\n"; 367 } els e{408 } elsif ($do_bkg) { 368 409 my $command; 369 410 $command = "$ppImage"; … … 381 422 check_output($bkgModel, $replicateOutputs); 382 423 } 383 $cmdflags = $cmdflags . " -background_model 1 "; 424 if ($run_state eq 'new') { 425 $cmdflags .= " -background_model 1 "; 426 } else { 427 my $command = "camtool -updateprocessedexp -set_background_model 1 -fault 0 -cam_id $cam_id"; 428 $command .= " -dbname $dbname" if $dbname; 429 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 430 run(command => $command, verbose => $verbose); 431 unless ($success) { 432 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 433 &my_die("Unable to updateprocessedexp to set background_model: $error_code", $cam_id, $error_code); 434 } 435 } 384 436 } 385 437 }
Note:
See TracChangeset
for help on using the changeset viewer.
