IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38516


Ignore:
Timestamp:
Jun 22, 2015, 3:24:54 PM (11 years ago)
Author:
bills
Message:

Changes to staticsky task and script to support update mode. Remove dead code from staticsky.pl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/staticsky.pl

    r37915 r38516  
    4343    print "USAGE: staticsky.pl --sky_id (sky_id) --outroot (root) --camera (camera) [options]\n";
    4444    print "  --sky_id (sky_id)   : run identifier\n";
     45    print "  --run-state (state) : run state (new or update)\n";
    4546    print "  --camera (camera)   : Camera name\n";
    4647    print "  --dbname (dbname)   : Database name\n";
     
    6263
    6364my ($sky_id, $camera, $dbname, $threads, $outroot, $reduction, $require_sources, $verbose, $no_update, $no_op, $redirect, $save_temps);
     65my $run_state ='new';
     66
    6467GetOptions(
    6568    'sky_id=s'          => \$sky_id, # Diff identifier
     69    'run-state=s'       => \$run_state,
    6670    'camera|c=s'        => \$camera, # Camera name
    6771    'dbname|d=s'        => \$dbname, # Database name
     
    8892    defined $camera;
    8993
     94
     95&my_die("unexpected run state: $run_state",  $sky_id, $PS_EXIT_PROG_ERROR) unless ($run_state eq 'new') or ($run_state eq 'update');
     96my $updatemode = $run_state eq 'update';
     97
    9098my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $sky_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    9199
     
    126134my $nInputs = @$files;
    127135
    128 if (1) {
     136{
    129137        my $recipe_psphot  = $ipprc->reduction($reduction, 'STACKPHOT_PSPHOT'); # Recipe to use for psphot
    130138        my $recipe_ppsub   = $ipprc->reduction($reduction, 'STACKPHOT_PPSUB'); # Recipe to use for ppsub
     
    163171            my $expnumRaw = $ipprc->filename("PPSTACK.UNCONV.EXPNUM",   $path_base ); # Expnum name
    164172
    165             my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
     173            my $sources;
     174            my ($psfRaw, $backmdlRaw);
     175            if (!$updatemode) {
     176                # sources from stack run.
     177                # XXX: We don't need this file anymore.
     178                $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
     179            } else {
     180                # name of output sources from this run when in new state
     181                $require_sources = 1 unless $no_op;
     182                $sources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $stack_id);
     183                # During update we rename the sources file to this
     184                my $originalSources = "$sources.original";
     185                if (!$ipprc->file_exists($originalSources)) {
     186                    if ($ipprc->file_exists($sources)) {
     187                        unless ($no_op) {
     188                            if (!$ipprc->file_rename($sources, $originalSources)) {
     189                                &my_die("failed to rename $sources $originalSources",  $sky_id, $PS_EXIT_PROG_ERROR);
     190                            }
     191                        }
     192                    } else {
     193                        # maybe this should be a fault 2
     194                        &my_die("failed to to find either sources file to update as either $sources or $originalSources",  $sky_id, $PS_EXIT_PROG_ERROR);
     195                    }
     196                }
     197                $sources = $originalSources;
     198                $psfRaw  = $ipprc->filename("PSPHOT.STACK.PSF.SAVE", $outroot, $stack_id);
     199                $backmdlRaw  = $ipprc->filename("PSPHOT.STACK.BACKMDL", $outroot, $stack_id);
     200            }
     201
    166202
    167203            # XXX is this the correct PSF file?
     
    194230                print $listFile "  SOURCES       STR  " . $sources   . "\n";
    195231            }
     232            if ($updatemode) {
     233                &my_die("Couldn't find input: $psfRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfRaw");
     234                &my_die("Couldn't find input: $backmdlRaw",    $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$backmdlRaw");
     235                print $listFile "  RAW:PSF       STR  " . $psfRaw . "\n";
     236                print $listFile "  RAW:BACKMDL   STR  " . $backmdlRaw . "\n";
     237            }
    196238            if ($needConvolvedImages) {
    197239                print $listFile "  CNV:IMAGE     STR  " . $imageCnv  . "\n";
     
    205247        }
    206248
    207         # my $cmdflags;
     249        close $listFile;
    208250
    209251        # Perform stack photometry analysis
    210252        {
    211253            my $command = "$psphotStack $outroot";
     254            $command .= " -updatemode" if $updatemode;
    212255            $command .= " -input $listName";
    213256            $command .= " -threads $threads" if defined $threads;
     
    275318                    # &my_die("Couldn't find expected output file: $chisqMask",           $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
    276319                    # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
     320
     321                    if (!$updatemode) {
     322                        # XXX: should be checking for existence of psf and backmdl output files
     323                    }
    277324                }
    278325            } else {
     
    280327            }
    281328        }
    282 } else {
    283     # XXX This mode is no longer used. We run psphotStack even if there is only one filter
    284         # single input. Run psphot
    285         # find the recipe
    286         my $recipe_psphot  = $ipprc->reduction($reduction, 'STACKPHOT_SINGLE_PSPHOT'); # Recipe to use for psphot
    287         unless ($recipe_psphot) {
    288             &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR);
    289         }
    290 
    291         print "reduction:      $reduction\n";
    292         print "recipe_psphot:  $recipe_psphot\n";
    293 
    294         my $configuration = $ipprc->filename("PSPHOT.SKY.CONFIG", $outroot);
    295 
    296         my $file = $files->[0];
    297 
    298         # XXX if we take the input from 'warp', we will need to make different selections here
    299         my $path_base = $file->{path_base};
    300         print "input: $path_base\n";
    301 
    302         # examine the recipe to determine whether to analyze the "raw" or convolved images
    303         my $command = "$ppConfigDump -camera $camera -dump-recipe PSPHOT -recipe PSPHOT $recipe_psphot -";
    304         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    305         run(command => $command, verbose => 0);
    306         unless ($success) {
    307             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    308             &my_die("Unable to perform ppConfigDump: $error_code", $sky_id, $PS_EXIT_SYS_ERROR);
    309         }
    310         my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
    311             &my_die("Unable to parse metadata config doc", $sky_id, $PS_EXIT_SYS_ERROR);
    312 
    313         my $use_raw = metadataLookupBool($recipeData, 'PSPHOT.STACK.USE.RAW');
    314 
    315         my ($image, $mask, $variance, $expnum);
    316         if ($use_raw) {
    317             $image  = $ipprc->filename("PPSTACK.UNCONV",          $path_base ); # Image name
    318             $mask   = $ipprc->filename("PPSTACK.UNCONV.MASK",     $path_base ); # Mask name
    319             $variance = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name
    320             $expnum = $ipprc->filename("PPSTACK.OUTPUT.EXPNUM", $path_base ); # Expnum name
    321         } else {
    322             $image  = $ipprc->filename("PPSTACK.OUTPUT",          $path_base ); # Image name
    323             $mask   = $ipprc->filename("PPSTACK.OUTPUT.MASK",     $path_base ); # Mask name
    324             $variance = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name
    325             $expnum = $ipprc->filename("PPSTACK.OUTPUT.EXPNUM", $path_base ); # Expnum name
    326         }
    327 
    328         my $output_sources_filerule = "PSPHOT.OUT.CMF.MEF";
    329         my $output_psf_filerule = "PSPHOT.PSF.SKY.SAVE";
    330 
    331         # XXX we could make some different choices if some inputs do not exist...
    332         &my_die("Couldn't find input: $image",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$image");
    333         &my_die("Couldn't find input: $mask",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$mask");
    334         &my_die("Couldn't find input: $variance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$variance");
    335         &my_die("Couldn't find input: $expnum", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$expnum");
    336 
    337         # Perform stack photometry analysis
    338         {
    339             my $command = "$psphot $outroot";
    340             $command .= " -file $image";
    341             $command .= " -mask $mask";
    342             $command .= " -variance $variance";
    343             $command .= " -expnum $expnum";
    344             $command .= " -threads $threads" if defined $threads;
    345             $command .= " -recipe PSPHOT  $recipe_psphot";
    346             $command .= " -dumpconfig $configuration" if $configuration;
    347             $command .= " -tracedest $traceDest -log $logDest";
    348             $command .= " -F PSPHOT.OUTPUT $output_sources_filerule";
    349             $command .= " -F PSPHOT.PSF.SAVE $output_psf_filerule";
    350 
    351             unless ($no_op) {
    352                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    353                 unless ($success) {
    354                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    355                     &my_die("Unable to perform psphot: $error_code", $sky_id, $error_code);
    356                 }
    357 
    358                 my $quality = 0;
    359                 if (!$quality) {
    360                     my $outputSources  = $ipprc->filename($output_sources_filerule, $outroot);
    361                     &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    362                     my $outputPSF  = $ipprc->filename($output_psf_filerule, $outroot);
    363                     &my_die("Couldn't find expected output file: $outputPSF", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);
    364                 }
    365 
    366                 &my_die("Couldn't find expected output file: $configuration", $sky_id, $PS_EXIT_SYS_ERROR)
    367                     unless $ipprc->file_exists($configuration);
    368             } else {
    369                 print "Not executing: $command\n";
    370             }
    371         }
    372329}
    373330
     
    377334    {
    378335        my $command = "$staticskytool -sky_id $sky_id";
    379         $command .= " -addresult -path_base $outroot";
    380         $command .= " -num_inputs $nInputs";
    381         # $command .= " $cmdflags";
    382         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    383         $command .= " -hostname $host" if defined $host;
    384         $command .= " -dbname $dbname" if defined $dbname;
     336        if ($updatemode) {
     337            $command .= " -updaterun -set_state full";
     338        } else {
     339            $command .= " -addresult -path_base $outroot";
     340            $command .= " -num_inputs $nInputs";
     341            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     342            $command .= " -hostname $host" if defined $host;
     343            $command .= " -dbname $dbname" if defined $dbname;
     344        }
    385345
    386346        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    388348        unless ($success) {
    389349            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    390             my $err_message = "Unable to perform staticskytool -addresult";
     350            my $err_message = "Unable to perform: $command\n";
    391351            warn($err_message);
    392352            exit $error_code;
     
    406366    warn($msg);
    407367    if (defined $sky_id and not $no_update) {
     368       
    408369        my $command = "$staticskytool -sky_id $sky_id -fault $exit_code";
    409         $command .= " -addresult";
    410         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    411         $command .= " -hostname $host" if defined $host;
    412         $command .= " -path_base $outroot" if defined $outroot;
    413         $command .= " -dbname $dbname" if defined $dbname;
     370        if ($updatemode) {
     371            $command .= " -updateresult";
     372        } else {
     373            $command .= " -addresult";
     374            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     375            $command .= " -hostname $host" if defined $host;
     376            $command .= " -path_base $outroot" if defined $outroot;
     377            $command .= " -dbname $dbname" if defined $dbname;
     378        }
    414379        run(command => $command, verbose => $verbose);
    415380    }
Note: See TracChangeset for help on using the changeset viewer.