IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2008, 2:24:27 PM (18 years ago)
Author:
bills
Message:

update processing for camera stage

File:
1 edited

Legend:

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

    r19396 r19561  
    2525my $ipprc = PS::IPP::Config->new(); # IPP configuration
    2626
    27 my ($warp_id, $skycell_id, $tess_dir, $camera, $dbname, $outroot, $threads, $verbose, $no_update, $no_op, $redirect, $save_temps);
     27my ($warp_id, $skycell_id, $tess_dir, $camera, $dbname, $outroot, $threads, $run_state, $verbose, $no_update, $no_op, $redirect, $save_temps);
    2828GetOptions(
    2929    'warp_id|i=s'       => \$warp_id, # Warp identifier
     
    3333    'dbname|d=s'        => \$dbname, # Database name
    3434    'outroot=s'         => \$outroot, # Output root name
    35     'threads=s'         => \$threads,   # Number of threads to use for ppImage
     35    'threads=s'         => \$threads,   # Number of threads to use for pswarp
     36    'run-state=s'       => \$run_state,  # 'new' or 'update'
    3637    'verbose'           => \$verbose,   # Print to stdout
    3738    'no-update'         => \$no_update, # Don't update the database?
     
    4344pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    4445pod2usage(
    45     -msg => "Required options: --warp_id --skycell_id --tess_dir --camera --outroot",
     46    -msg => "Required options: --warp_id --skycell_id --tess_dir --camera --outroot --run-state",
    4647    -exitval => 3,
    4748) unless defined $warp_id
     
    4950    and defined $tess_dir
    5051    and defined $camera
    51     and defined $outroot;
     52    and defined $outroot
     53    and defined $run_state;
    5254
    5355$ipprc->define_camera($camera);
    5456
    5557my $logDest = $ipprc->filename("LOG.EXP", $outroot, $skycell_id);
     58$logDest .= ".update" if ($run_state eq 'update');
    5659
    5760$ipprc->redirect_output($logDest) if $redirect;
     
    127130my $configuration =  $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id);
    128131
     132if ($run_state eq 'update') {
     133    $traceDest .= ".update";
     134    $outputStats .= ".update";
     135}
     136
    129137my $skyFile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id );
    130138$ipprc->skycell_file( $tess_dir, $skycell_id, $skyFile, $verbose ) or &my_die("Unable to generate template skycell", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR);
     
    170178# Run pswarp
    171179my $accept = 1;                 # Accept the skycell?
     180my $do_stats;
    172181unless ($no_op) {
    173182    my $command = "$pswarp";
     
    177186    $command .= " -astromlist $astromName";
    178187    $command .= " $outroot $skyFile";
    179     $command .= " -stats $outputStats";
    180     $command .= " -recipe PPSTATS WARPSTATS";
    181188    $command .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE";
    182189    $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF";
     
    185192    $command .= " -tracedest $traceDest -log $logDest";
    186193    $command .= " -threads $threads" if defined $threads;
    187     $command .= " -dumpconfig $configuration";
    188194    $command .= " -dbname $dbname" if defined $dbname;
     195    if ($run_state eq 'new') {
     196        $command .= " -dumpconfig $configuration";
     197        $do_stats = 1;
     198    } else {
     199        $command .= " -ipprc $configuration";
     200    }
     201    if ($do_stats) {
     202        $command .= " -recipe PPSTATS WARPSTATS";
     203        $command .= " -stats $outputStats";
     204    }
    189205
    190206    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    195211    }
    196212
    197     # Check first for the stats file, and if the ACCEPT flag is set.
    198     &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
    199     # Get the statistics on the warped image
    200     my $statsFile;              # File handle
    201     open $statsFile, $ipprc->file_resolve($outputStats) or die "Can't open statistics file $outputStats: $!\n";
    202     my @contents = <$statsFile>; # Contents of file
    203     close $statsFile;
    204     my $contents = join "", @contents;
    205 
    206     my $metadata = $mdcParser->parse($contents)
    207         or &my_die("Unable to parse metadata config", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
    208     $accept = metadataLookupBool($metadata, "ACCEPT");
    209 
    210     # $accept is set above based on the fraction of lit pixels
    211     # XXX for some files, there may not be enough stars to find a good psf.  these should be dropped as well
    212     if ($accept && !$ipprc->file_exists($outputPSF)) {
    213         $accept = 0;
    214     }
    215 
    216     if ($accept) {
    217         $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
    218 
    219         &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
    220         &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
    221         &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
    222         &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    223 #    &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);
    224 #    &my_die("Couldn't find expected output file: $outputBin1", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
    225 #    &my_die("Couldn't find expected output file: $outputBin2", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
    226     }
    227 }
    228 
    229 unless ($no_update) {
    230     # XXX change -tess_id to -tess_dir when db is updated
    231     my $command = "$warptool -addwarped";
    232     $command .= " -warp_id $warp_id";
    233     $command .= " -skycell_id $skycell_id";
    234     $command .= " -tess_id $tess_dir";
    235     $command .= " -path_base $outroot"; # needed for logfile lookups
    236     $command .= " -ignore"           if not $accept; # Completed succesfully, but can't produce product
    237     $command .= " -uri $outputImage" if $accept;
    238     $command .= $stats->cmdflags()   if $accept;
    239     $command .= " -hostname $host"   if defined $host;
    240     $command .= " -dbname $dbname"   if defined $dbname;
    241 
    242     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    243         run(command => $command, verbose => $verbose);
    244     unless ($success) {
    245         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    246         warn("Unable to perform warptool -addwarped: $error_code\n");
    247         exit($error_code);
     213    if ($do_stats) {
     214        # Check first for the stats file, and if the ACCEPT flag is set.
     215        &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
     216        # Get the statistics on the warped image
     217        my $statsFile;              # File handle
     218        open $statsFile, $ipprc->file_resolve($outputStats) or die "Can't open statistics file $outputStats: $!\n";
     219        my @contents = <$statsFile>; # Contents of file
     220        close $statsFile;
     221        my $contents = join "", @contents;
     222
     223        my $metadata = $mdcParser->parse($contents)
     224            or &my_die("Unable to parse metadata config", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
     225        $accept = metadataLookupBool($metadata, "ACCEPT");
     226
     227        # $accept is set above based on the fraction of lit pixels
     228        # XXX for some files, there may not be enough stars to find a good psf.  these should be dropped as well
     229        if ($accept && !$ipprc->file_exists($outputPSF)) {
     230            $accept = 0;
     231        }
     232
     233        if ($accept) {
     234            $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
     235
     236            &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
     237            &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
     238            &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
     239            &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
     240    #    &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);
     241    #    &my_die("Couldn't find expected output file: $outputBin1", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
     242    #    &my_die("Couldn't find expected output file: $outputBin2", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
     243        }
     244
     245        unless ($no_update) {
     246            # XXX change -tess_id to -tess_dir when db is updated
     247            my $command = "$warptool -addwarped";
     248            $command .= " -warp_id $warp_id";
     249            $command .= " -skycell_id $skycell_id";
     250            $command .= " -tess_id $tess_dir";
     251            $command .= " -path_base $outroot"; # needed for logfile lookups
     252            $command .= " -ignore"           if not $accept; # Completed succesfully, but can't produce product
     253            $command .= " -uri $outputImage" if $accept;
     254            $command .= $stats->cmdflags()   if $accept;
     255            $command .= " -hostname $host"   if defined $host;
     256            $command .= " -dbname $dbname"   if defined $dbname;
     257
     258            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     259                run(command => $command, verbose => $verbose);
     260            unless ($success) {
     261                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     262                warn("Unable to perform warptool -addwarped: $error_code\n");
     263                exit($error_code);
     264            }
     265        }
     266    } else {
     267        # $run_state eq 'update'
     268        unless ($no_update) {
     269            my $command = "$warptool -tofullskyfile";
     270            $command .= " -warp_id $warp_id";
     271            $command .= " -skycell_id $skycell_id";
     272            $command .= " -dbname $dbname"   if defined $dbname;
     273
     274            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     275                run(command => $command, verbose => $verbose);
     276            unless ($success) {
     277                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     278                warn("Unable to perform warptool -addwarped: $error_code\n");
     279                exit($error_code);
     280            }
     281        }
    248282    }
    249283}
     
    260294    if (defined $warp_id and defined $skycell_id and defined $tess_dir and not $no_update) {
    261295        # XXX change -tess_id to -tess_dir when db is updated
    262         my $command = "$warptool -addwarped";
     296        my $command = "$warptool";
     297        if ($run_state eq 'new') {
     298            $command .= " -addwarped";
     299            $command .= " -tess_id $tess_dir";
     300            $command .= " -path_base $outroot";
     301            $command .= " -hostname $host" if defined $host;
     302        } else {
     303            $command .= " -updateskyfile";
     304        }
    263305        $command .= " -warp_id $warp_id";
    264306        $command .= " -skycell_id $skycell_id";
    265         $command .= " -tess_id $tess_dir";
    266307        $command .= " -code $exit_code";
    267         $command .= " -path_base $outroot";
    268         $command .= " -hostname $host" if defined $host;
    269308        $command .= " -dbname $dbname" if defined $dbname;
    270309        run(command => $command, verbose => $verbose);
Note: See TracChangeset for help on using the changeset viewer.