IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 21, 2008, 5:31:39 PM (18 years ago)
Author:
eugene
Message:

converting statistics analysis from perl script support to ppStatsFromMetadata (which can use pslib robust stats)

File:
1 edited

Legend:

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

    r19621 r19627  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
    18 use PS::IPP::Metadata::Stats;
    1918use PS::IPP::Config 1.01 qw( :standard );
     19
     20# XXX drop (moved to ppStatsFromMetadata)
     21# use PS::IPP::Metadata::Stats;
    2022
    2123my $ipprc = PS::IPP::Config->new(); # IPP configuration
     
    8890print "real recipe: $recipe\n";
    8991
    90 # values to extract from output metadata and the stats to calculate
    91 my $STATS =
    92    [
    93        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
    94        { name => "ROBUST_MEDIAN",      type => "mean",  flag => "-bg",             dtype => "float" },
    95        { name => "ROBUST_MEDIAN",      type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
    96        { name => "ROBUST_STDEV",       type => "rms",   flag => "-bg_stdev",       dtype => "float" },
    97        { name => "SAMPLE_SKEWNESS",    type => "mean",  flag => "-bg_skewness",    dtype => "float" },
    98        { name => "SAMPLE_KURTOSIS",    type => "mean",  flag => "-bg_kurtosis",    dtype => "float" },
    99        { name => "FRINGE_0",           type => "mean",  flag => "-fringe_0",       dtype => "float" },
    100        { name => "FRINGE_ERR_0",       type => "rms",   flag => "-fringe_1",       dtype => "float" },
    101        { name => "FRINGE_0",           type => "stdev", flag => "-fringe_2",       dtype => "float" },
    102        { name => "FRINGE_RESID_0",     type => "mean",  flag => "-fringe_resid_0", dtype => "float" },
    103        { name => "FRINGE_RESID_ERR_0", type => "rms",   flag => "-fringe_resid_1", dtype => "float" },
    104        { name => "FRINGE_RESID_0",     type => "stdev", flag => "-fringe_resid_2", dtype => "float" },
    105    ];
    106 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    107 
    108 my $BINNED_STATS =
    109    [
    110        { name => "ROBUST_STDEV",   type => "rms",   flag => "-bin_stdev" },
    111    ];
    112 my $binnedStats = PS::IPP::Metadata::Stats->new($BINNED_STATS); # Stats parser
    113 
    11492# Flags to specify the particular detrend to use
    11593use constant DETRENDS => {
     
    140118my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    141119my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
     120my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    142121if ($missing_tools) {
    143122    warn("Can't find required tools.");
     
    161140my $outputStats = $ipprc->filename("PPIMAGE.STATS",  $outroot, $class_id);
    162141my $traceDest   = $ipprc->filename("TRACE.IMFILE",   $outroot, $class_id);
     142
     143my $cmdflags;
    163144
    164145# Run ppImage & ppStats
     
    184165        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
    185166    }
     167
    186168    &my_die("Couldn't find expected output file: $outputName", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputName);
    187     &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    188169    &my_die("Couldn't find expected output file: $bin1Name", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin1Name);
    189170    &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin2Name);
    190171
    191     # Load the raw output stats file
    192     my $statsFile;              # File handle
    193     open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
    194     my @contents = <$statsFile>; # Contents of file
    195     close $statsFile;
    196 
    197     # Parse the stats file contents into a metadata
    198     my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    199     my $metadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    200 
    201     # Parse the statistics on the residual image
    202     $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
     172    my $outputStatsReal = $ipprc->file_resolve($outputStats);
     173    &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
     174
     175    # ppStatsFromMetadata $outputStats - DETREND_RESID_IMFILE
     176    $command = "$ppStatsFromMetadata $outputStatsReal - DETREND_RESID_IMFILE";
     177    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     178        run(command => $command, verbose => $verbose);
     179    unless ($success) {
     180        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     181        &my_die("Unable to perform ppStatsFromMetadata: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
     182    }
     183    $cmdflags = $stdout_buf; chomp $cmdflags;
    203184
    204185    # run ppStats on the binned image
    205     $command = "$ppStats -recipe PPSTATS RESIDUAL $bin2Name";
     186    $command = "$ppStats -recipe PPSTATS RESIDUAL $bin2Name | $ppStatsFromMetadata - - DETREND_RESID_IMFILE_BINNED";
    206187    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    207188        run(command => $command, verbose => $verbose);
     
    210191        &my_die("Unable to perform ppStats: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
    211192    }
    212 
    213     # Parse the output contents into a metadata
    214     my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    215 
    216     # parse the binned image statistics
    217     $binnedStats->parse($binnedMetadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
     193    $cmdflags .= $stdout_buf; chomp $cmdflags;
    218194}
    219195
     
    230206$command .= " -path_base $outroot";
    231207$command .= " -dbname $dbname" if defined $dbname;
    232 $command .= $stats->cmdflags();
    233 $command .= $binnedStats->cmdflags();
     208$command .= $cmdflags;
    234209
    235210# Add the processed file to the database
Note: See TracChangeset for help on using the changeset viewer.