IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

converting to ppStatsFromMetadata

File:
1 edited

Legend:

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

    r19938 r19942  
    1919use IPC::Cmd 0.36 qw( can_run run );
    2020use PS::IPP::Metadata::Config;
    21 use PS::IPP::Metadata::Stats;
    2221use PS::IPP::Config 1.01 qw( :standard );
    2322
     
    7473}
    7574
    76 # values to extract from output metadata and the stats to calculate
    77 # XXX commented-out entries are not yet defined in the output files
    78 my $STATS =
    79    [
    80        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
    81        { name => "ROBUST_MEDIAN",  type => "mean",  flag => "-bg",             dtype => "float" },
    82        { name => "ROBUST_MEDIAN",  type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
    83        { name => "ROBUST_STDEV",   type => "rms",   flag => "-bg_stdev",       dtype => "float" },
    84        { name => "OVER_VAL",       type => "mean",  flag => "-bias",           dtype => "float" },
    85        { name => "OVER_VAL",       type => "stdev", flag => "-bias_stdev",     dtype => "float" },
    86        { name => "FRINGE_0",       type => "rms",   flag => "-fringe_0",       dtype => "float" },
    87        { name => "FRINGE_RESID_0", type => "rms",   flag => "-fringe_1",       dtype => "float" },
    88        { name => "FRINGE_ERR_0",   type => "rms",   flag => "-fringe_2",       dtype => "float" },
    89        { name => "APMIFIT",        type => "mean",  flag => "-ap_resid",       dtype => "float" },
    90        { name => "DAPMIFIT",       type => "rms",   flag => "-ap_resid_stdev", dtype => "float" },
    91        { name => "FWHM_X",         type => "mean",  flag => "-fwhm_major",     dtype => "float" },
    92        { name => "FWHM_Y",         type => "mean",  flag => "-fwhm_minor",     dtype => "float" },
    93        { name => "DT_DET",         type => "sum",   flag => "-dtime_detrend",  dtype => "float" },
    94        { name => "DT_PHOT",        type => "sum",   flag => "-dtime_photom",   dtype => "float" },
    95        { name => "DT_TOTAL",       type => "sum",   flag => "-dtime_total",    dtype => "float" },
    96        { name => "NSTARS",         type => "sum",   flag => "-n_stars",        dtype => "int"   },
    97 #      { name => "?",              type => "sum",   flag => "-n_extended",     dtype => "int"   },
    98 #      { name => "?",              type => "sum",   flag => "-n_cr",           dtype => "int"   },
    99    ];
    100 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    101 
    10275# Look for programs we need
    10376my $missing_tools;
     
    10578my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    10679my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     80my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    10781if ($missing_tools) {
    10882    warn("Can't find required tools.");
     
    137111}
    138112
     113my $cmdflags;
     114
    139115# Run ppImage
    140116unless ($no_op) {
    141     ## XXX can we convert ppImage log and trace to use the filerules to generate consistent names
    142     ## XXX also stats: output should be implied by $outroot
    143117    my $command;
    144118    my $do_stats;
     
    205179        &my_die("Couldn't find expected output file: $outputStats\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
    206180
    207         # Get the statistics on the processed image
    208         my $statsFile;              # File handle
    209         open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    210         my @contents = <$statsFile>; # Contents of file
    211         close $statsFile;
    212 
    213         # parse the statistics MDC file
    214         my $mdcParser = PS::IPP::Metadata::Config->new();   # Parser for metadata config files
    215         my $metadata = $mdcParser->parse(join "", @contents);
    216         unless ($metadata) {
    217             &my_die("Unable to parse metadata config doc", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
    218         }
    219 
    220         # extract the stats from the metadata
    221         unless ($stats->parse($metadata)) {
    222             &my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
    223         }
     181        my $outputStatsReal = $ipprc->file_resolve($outputStats);
     182        &my_die("Couldn't find expected output file: $outputStats", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
     183
     184        # measure chip stats
     185        $command = "$ppStatsFromMetadata $outputStatsReal - CHIP_IMFILE";
     186        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     187            run(command => $command, verbose => $verbose);
     188        unless ($success) {
     189            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     190            &my_die("Unable to perform ppStatsFromMetadata: $error_code", $exp_id, $chip_id, $class_id, $error_code);
     191        }
     192        foreach my $line (@$stdout_buf) {
     193            $cmdflags .= " $line";
     194        }
     195        chomp $cmdflags;
    224196    }
    225197}
     
    236208    $command .= " -hostname $host" if defined $host;
    237209    $command .= " -dbname $dbname" if defined $dbname;
    238     $command .= $stats->cmdflags();
     210    $command .= " $cmdflags";
    239211    $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    240212} else {
Note: See TracChangeset for help on using the changeset viewer.