IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 3, 2013, 1:43:50 PM (13 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130509/ippScripts/scripts/camera_exp.pl

    r35367 r35747  
    5353    'skip-binned'       => \$skip_binned, # override recipe - don't create binned images
    5454    'skip-refmask'      => \$skip_masks, # override recipe - don't create refmask
    55     'bkg-only'          => \$bkg_only,  # override recipe - only do background continuity
     55#    'bkg-only'          => \$bkg_only,  # override recipe - only do background continuity
    5656    'verbose'           => \$verbose,   # Print to stdout
    5757    'no-update'         => \$no_update, # Update the database?
     
    8080my $replicateOutputs = 1;
    8181
     82$ipprc->outroot_prepare($outroot);
     83
    8284my $logDest;
    8385my $traceDest;
     
    114116my $bkg_recipe     = 'PPIMAGE_BKGCONT'; # Add to reduction?
    115117my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     118
     119my $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}
    116132
    117133my $cmdflags;
     
    158174    chomp $cmdflags;
    159175
    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
     191my $do_masks;               # Produce masks?
    196192if (!$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');
    209194}
    210195
     
    220205my ($list5File, $list5Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b5.list.XXXX", UNLINK => !$save_temps ); # For background models
    221206
    222 # XXX we perform astrometry iff photometry output exists
     207
     208my $do_stats;
     209my $do_bkg;
     210my $do_jpegs;
     211my $fpaStats;
     212my $psastroInputArg;
     213if ($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
    223262my @outMasks;                   # Names of output masks
    224263my @bkg_models;                 # Names of output background models
    225264foreach my $file (@$files) {
     265    # we perform astrometry iff photometry output exists
    226266    next if $file->{quality} != 0;
     267
    227268    # use the path_base as OUTPUT root and convert the filenames with ipprc->filename:
    228269    my $class_id = $file->{class_id};
     
    239280    print $list5File ($ipprc->filename("PSPHOT.BACKMDL", $file->{path_base}, $class_id) . "\n");
    240281
    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;
    243284}
    244285close $list1File;
     
    247288close $list4File;
    248289close $list5File;
    249 # Output products
    250 $ipprc->outroot_prepare($outroot);
     290
     291# Prepare the Output products
    251292
    252293# 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;
     294my $jpeg1      = prepare_output("PPIMAGE.JPEG1",      $outroot, undef, 1) if $do_jpegs;
     295my $jpeg2      = prepare_output("PPIMAGE.JPEG2",      $outroot, undef, 1) if $do_jpegs;
     296my $fpaObjects = prepare_output("PSASTRO.OUTPUT",     $outroot, undef, 1) if !$bkg_only;
     297
     298my $configuration;
    260299if ($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);
    263301} 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
    266307
    267308unless ($no_op) {
     
    269310    ## build the output JPEG images first so we get them even if the astrometry fails
    270311
    271     # Make the jpeg for binning 1
    272     if (!$skip_binned and ($run_state eq 'new')) {
     312    if ($do_jpegs) {
     313        # Make the jpeg for binning 1
    273314        my $command = "$ppImage -list $list1Name $outroot"; # Command to run
    274315        $command .= " -recipe PPIMAGE $recipe1";
     
    282323        }
    283324        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
    289329        $command .= " -recipe PPIMAGE $recipe2";
    290330        $command .= " -dbname $dbname" if defined $dbname;
    291331
    292         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     332        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    293333            run(command => $command, verbose => $verbose);
    294334        unless ($success) {
     
    302342        # run psastro on the chipObjects, producing fpaObjects
    303343        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;
    307347        $command .= " $outroot";
    308348        $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;
    310350        $command .= " -tracedest $traceDest -log $logDest";
    311351        $command .= " -dbname $dbname" if defined $dbname;
     
    314354            $command .= " -dumpconfig $configuration";
    315355        } elsif ($run_state eq 'update') {
    316             $command .= " -ipprc $configuration";
     356            $command .= " -ipprc $configuration" if $configuration;
    317357        } else {
    318358            &my_die("invalid value for run-state: $run_state", $cam_id, $PS_EXIT_CONFIG_ERROR);
     
    362402        }
    363403    }
     404
    364405    # Construct FPA continuity corrected background images
    365406    if ($camera =~ /ISP/) {
    366407        print "Skipping FPA continuity corrected background images for ISP\n";
    367     } else {
     408    } elsif ($do_bkg) {
    368409        my $command;
    369410        $command = "$ppImage";
     
    381422            check_output($bkgModel, $replicateOutputs);
    382423        }
    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        }
    384436    }
    385437}
Note: See TracChangeset for help on using the changeset viewer.