IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19782


Ignore:
Timestamp:
Sep 28, 2008, 11:40:31 AM (18 years ago)
Author:
eugene
Message:

convert to ppStatsFromMetadata for robust stats

Location:
trunk/ippScripts/scripts
Files:
2 edited

Legend:

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

    r19374 r19782  
    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 );
    2019
     
    8887my $det_type_real = DETTYPE()->{lc($det_type)};
    8988
    90 # values to extract from output metadata and the stats to calculate
    91 my $STATS =
    92    [
    93        #          PPSTATS KEYWORD  STATISTIC            DETTOOL FLAG
    94        { name => "ROBUST_MEDIAN",  type => "clipmean",  flag => "-bg",            dtype => "float" },
    95        { name => "ROBUST_MEDIAN",  type => "clipstdev", flag => "-bg_mean_stdev", dtype => "float" },
    96        { name => "ROBUST_STDEV",   type => "rms",       flag => "-bg_stdev",      dtype => "float" },
    97    ];
    98 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    99 
    10089# Look for programs we need
    10190my $missing_tools;
    10291my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    10392my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
     93my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    10494if ($missing_tools) {
    10595    warn("Can't find required tools.");
     
    126116my $statsName = $ipprc->filename("PPIMAGE.STATS", $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
    127117my $traceDest = $ipprc->filename("TRACE.IMFILE",  $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
     118
     119my $cmdflags;
    128120
    129121# Run normalisation
     
    157149    &my_die("Can't find expected output file: $b1name",    $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b1name);
    158150    &my_die("Can't find expected output file: $b2name",    $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b2name);
    159     &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($statsName);
    160 
    161     # Get the statistics on the normalised image
    162     my $statsFile; # File handle
    163     open $statsFile, $ipprc->file_resolve($statsName) or &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    164     &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless defined $statsFile;
    165     my @contents = <$statsFile>; # Contents of file
    166     close $statsFile;
    167 
    168     # parse the statistics MDC file
    169     my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    170     my $metadata = $mdcParser->parse(join "", @contents);
    171     unless ($metadata) {
    172         &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    173     }
    174 
    175     # extract the stats from the metadata
    176     unless ($stats->parse($metadata)) {
    177         &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    178     }
     151
     152    my $statsNameReal = $ipprc->file_resolve($statsName);
     153    &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $statsNameReal;
     154
     155    # ppStatsFromMetadata $outputStats - DETREND_RESID_IMFILE
     156    $command = "$ppStatsFromMetadata $statsNameReal - DETREND_RESID_IMFILE";
     157    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     158        run(command => $command, verbose => $verbose);
     159    unless ($success) {
     160        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     161        &my_die("Unable to perform ppStatsFromMetadata: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
     162    }
     163    foreach my $line (@$stdout_buf) {
     164        $cmdflags .= " $line";
     165    }
     166    chomp $cmdflags;
    179167}
    180168
     
    187175$command .= " -path_base $outroot";
    188176$command .= " -dbname $dbname" if defined $dbname;
    189 $command .= $stats->cmdflags();
     177$command .= " $cmdflags";
    190178
    191179# Add the processed file to the database
  • trunk/ippScripts/scripts/detrend_norm_exp.pl

    r19660 r19782  
    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 );
    2019use PS::IPP::Metadata::List qw( parse_md_list );
     
    6261&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe;
    6362
    64 # values to extract from output metadata and the stats to calculate
    65 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A)
    66 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0     (B)
    67 # XXX  (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1
    68 my $STATS =
    69     [
    70         #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
    71         { name => "bg",             type => "mean",  flag => "-bg",            dtype => "float" },
    72         { name => "bg",             type => "stdev", flag => "-bg_mean_stdev", dtype => "float" },
    73         { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",      dtype => "float" },
    74         # { name => "bg_mean_stdev",  type => "rms",   flag => "-bg_mean_stdev" },
    75         ];
    76 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    77 
    7863# Look for programs we need
    7964my $missing_tools;
    8065my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    8166my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
     67my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    8268if ($missing_tools) {
    8369    warn("Can't find required tools.");
     
    8672
    8773# Get list of component files
     74my $cmdflags;
    8875my ($files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    8976{
     
    9885        &my_die("Unable to get list of normalized imfiles from dettool: $error_code", $det_id, $iter, $error_code);
    9986    }
     87    # XXX report an error message if stdout_buf is empty
    10088
    10189    # convert stdout to a metadata
     
    10896        &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR);
    10997
    110     # parse the stats in the metadata
    111     unless ($stats->parse($metadata)) {
    112         &my_die("Unable to find all values in statistics output.\n", $det_id, $iter, $PS_EXIT_PROG_ERROR);
    113     }
     98    # since I can't figure out how to do input and output within PERL, I'm writing to a temp file
     99    my ($statFile, $statName) = tempfile( "/tmp/$camera.$det_type.norm.$det_id.$iter.stats.XXXX", UNLINK => !$save_temps );
     100    foreach my $line (@$stdout_buf) {
     101        print $statFile $line;
     102    }
     103    close $statFile;
     104
     105    $command = "$ppStatsFromMetadata $statName - DETREND_NORM_EXP";
     106    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     107        run(command => $command, verbose => $verbose);
     108    unless ($success) {
     109        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     110        warn("Unable to perform ppStatsFromMetadata: $error_code\n");
     111        exit($error_code);
     112    }
     113
     114    foreach my $line (@$stdout_buf) {
     115        $cmdflags .= " $line";
     116    }
     117    print "cmdflags: $cmdflags\n";
    114118}
    115119
     
    162166$command .= " -path_base $outroot ";
    163167$command .= " -dbname $dbname" if defined $dbname;
    164 $command .= $stats->cmdflags();
     168$command .= " $cmdflags";
    165169
    166170# Add the processed file to the database
Note: See TracChangeset for help on using the changeset viewer.