IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 13, 2008, 11:36:56 AM (18 years ago)
Author:
eugene
Message:

converting to ppStatsFromMetadata

File:
1 edited

Legend:

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

    r19938 r20101  
    2222use Pod::Usage qw( pod2usage );
    2323use PS::IPP::Metadata::Config;
    24 use PS::IPP::Metadata::Stats;
    2524use PS::IPP::Metadata::List qw( parse_md_list );
    2625use PS::IPP::Config 1.01 qw( :standard );
     
    6362$ipprc->redirect_output($logDest) if $redirect;
    6463
    65 my $STATS =
    66    [
    67        #          PPSTATS KEYWORD         STATISTIC          WARPTOOL FLAG
    68        { name => "ROBUST_MEDIAN",   type => "mean", flag => "-bg",         dtype => "float" },
    69        { name => "ROBUST_STDEV",    type => "rms",  flag => "-bg_stdev",   dtype => "float" },
    70        { name => "DT_WARP",         type => "sum",  flag => "-dtime_warp", dtype => "float" },
    71        { name => "GOOD_PIXEL_FRAC", type => "mean", flag => "-good_frac",  dtype => "float" },
    72        { name => "RANGE.XMIN",      type => "mean", flag => "-xmin",       dtype => "int"   },
    73        { name => "RANGE.XMAX",      type => "mean", flag => "-xmax",       dtype => "int"   },
    74        { name => "RANGE.YMIN",      type => "mean", flag => "-ymin",       dtype => "int"   },
    75        { name => "RANGE.YMAX",      type => "mean", flag => "-ymax",       dtype => "int"   },
    76    ];
    77 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    78 
    7964# Look for programs we need
    8065my $missing_tools;
     
    8267my $pswarp = can_run('pswarp') or (warn "Can't find pswarp" and $missing_tools = 1);
    8368my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     69my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    8470if ($missing_tools) {
    8571    warn("Can't find required tools.");
     
    180166
    181167# Run pswarp
     168my $cmdflags;
    182169my $accept = 1;                 # Accept the skycell?
    183170my $do_stats;
     
    216203    if ($do_stats) {
    217204        # Check first for the stats file, and if the ACCEPT flag is set.
    218         &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
    219         # Get the statistics on the warped image
    220         my $statsFile;              # File handle
    221         open $statsFile, $ipprc->file_resolve($outputStats) or die "Can't open statistics file $outputStats: $!\n";
    222         my @contents = <$statsFile>; # Contents of file
    223         close $statsFile;
    224         my $contents = join "", @contents;
    225 
    226         my $metadata = $mdcParser->parse($contents)
    227             or &my_die("Unable to parse metadata config", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
    228         $accept = metadataLookupBool($metadata, "ACCEPT");
    229 
    230         # $accept is set above based on the fraction of lit pixels
    231         # XXX for some files, there may not be enough stars to find a good psf.  these should be dropped as well
     205        my $outputStatsReal = $ipprc->file_resolve($outputStats);
     206        &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
     207
     208        # measure chip stats
     209        $command = "$ppStatsFromMetadata $outputStatsReal - WARP_SKYFILE";
     210        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     211            run(command => $command, verbose => $verbose);
     212        unless ($success) {
     213            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     214            &my_die("Unable to perform ppStatsFromMetadata: $error_code", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR);
     215        }
     216        foreach my $line (@$stdout_buf) {
     217            $cmdflags .= " $line";
     218        }
     219        chomp $cmdflags;
     220
     221        # the stats includes ACCEPT as a boolean: convert the T/F value to 0/1
     222        my $acceptFlag = &value_for_flag ($cmdflags, "-accept");
     223        $accept = ($acceptFlag = "T") ? 1 : 0;
    232224        if ($accept && !$ipprc->file_exists($outputPSF)) {
    233225            $accept = 0;
     
    235227
    236228        if ($accept) {
    237             $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
    238 
    239229            &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
    240230            &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
    241231            &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
    242232            &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    243     #    &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);
    244     #    &my_die("Couldn't find expected output file: $outputBin1", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
    245     #    &my_die("Couldn't find expected output file: $outputBin2", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
    246233        }
    247234
     
    256243            $command .= " -uri $outputImage" if $accept;
    257244            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    258             $command .= $stats->cmdflags()  if $accept;
     245            $command .= " $cmdflags" if $accept;
    259246            $command .= " -hostname $host"   if defined $host;
    260247            $command .= " -dbname $dbname"   if defined $dbname;
     
    285272        }
    286273    }
     274}
     275
     276sub value_for_flag
     277{
     278    my $cmdflags = shift;
     279    my $flag = shift;
     280
     281    my $value = 0.0;
     282    if ($cmdflags =~ m|$flag|) {
     283        ($value) = $cmdflags =~ m|$flag\s+(\S+)|;
     284    }
     285    $value;
    287286}
    288287
Note: See TracChangeset for help on using the changeset viewer.