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/detrend_stack.pl

    r19374 r19942  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
    18 use PS::IPP::Metadata::Stats;
    1918use PS::IPP::Metadata::List qw( parse_md_list );
    2019use PS::IPP::Config 1.01 qw( :standard );
     
    6766my $recipe = $ipprc->reduction($reduction, $det_type . '_STACK'); # Recipe name to use
    6867
    69 # values to extract from output metadata and the stats to calculate
    70 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A)
    71 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0     (B)
    72 # XXX  (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1
    73 my $STATS =
    74    [
    75        #          KEYWORD          STATISTIC            DETTOOL FLAG
    76        { name => "ROBUST_MEDIAN",  type => "clipmean",  flag => "-bg",             dtype => "float" },
    77        { name => "ROBUST_MEDIAN",  type => "clipstdev", flag => "-bg_mean_stdev",  dtype => "float" },
    78        { name => "ROBUST_STDEV",   type => "rms",       flag => "-bg_stdev",       dtype => "float" },
    79    ];
    80 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    81 
    8268# Look for programs we need
    8369my $missing_tools;
    8470my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    8571my $ppMerge = can_run('ppMerge') or (warn "Can't find ppMerge" and $missing_tools = 1);
     72my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    8673if ($missing_tools) {
    8774    warn("Can't find required tools.");
     
    11299
    113100# The stats recipe depends on the detrend type
    114 my $STATRECIPES = {'FLATMASK'         => 'CHIPSTATS',
    115                    'DARKMASK'         => 'CHIPSTATS',
    116                    'MASK'             => 'CHIPSTATS',
    117                    'BIAS'             => 'CHIPSTATS',
     101my $STATRECIPES = {'FLATMASK'         => 'DETSTATS',
     102                   'DARKMASK'         => 'DETSTATS',
     103                   'MASK'             => 'DETSTATS',
     104                   'BIAS'             => 'DETSTATS',
    118105                   'DARK'             => 'DARKSTATS',
    119106                   'DARK_PREMASK'     => 'DARKSTATS',
    120107                   'SHUTTER'          => 'DARKSTATS',
    121                    'FLAT_PREMASK'     => 'CHIPSTATS',
    122                    'DOMEFLAT_PREMASK' => 'CHIPSTATS',
    123                    'SKYFLAT_PREMASK'  => 'CHIPSTATS',
    124                    'FLAT_RAW'         => 'CHIPSTATS',
    125                    'DOMEFLAT_RAW'     => 'CHIPSTATS',
    126                    'SKYFLAT_RAW'      => 'CHIPSTATS',
    127                    'FLAT'             => 'CHIPSTATS',
    128                    'DOMEFLAT'         => 'CHIPSTATS',
    129                    'SKYFLAT'          => 'CHIPSTATS',
    130                    'FRINGE'           => 'CHIPSTATS',
     108                   'FLAT_PREMASK'     => 'DETSTATS',
     109                   'DOMEFLAT_PREMASK' => 'DETSTATS',
     110                   'SKYFLAT_PREMASK'  => 'DETSTATS',
     111                   'FLAT_RAW'         => 'DETSTATS',
     112                   'DOMEFLAT_RAW'     => 'DETSTATS',
     113                   'SKYFLAT_RAW'      => 'DETSTATS',
     114                   'FLAT'             => 'DETSTATS',
     115                   'DOMEFLAT'         => 'DETSTATS',
     116                   'SKYFLAT'          => 'DETSTATS',
     117                   'FRINGE'           => 'DETSTATS',
    131118              };
    132119my $statrecipe = $STATRECIPES->{$det_type}; # File rule for output
     120
     121my $cmdflags;
    133122
    134123# Get list of files to stack
     
    217206    &my_die("Unable to find expected output file: $outputCount\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputCount);
    218207    &my_die("Unable to find expected output file: $outputSigma\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputSigma);
    219     &my_die("Unable to find expected output file: $outputStats\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    220 
    221     # Get the statistics on the stacked image
    222     open(my $statsFile, $ipprc->file_resolve("$outputStats")) or
    223         &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    224     my $contents = do { local $/; <$statsFile> }; # Contents of file
    225     close($statsFile);
    226 
    227     my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    228     my $metadata = $mdcParser->parse($contents) or
    229         &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    230 
    231     $stats->parse($metadata)  or
    232         &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
     208
     209    my $outputStatsReal = $ipprc->file_resolve($outputStats);
     210    &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
     211
     212    # parse stats from metadata
     213    $command = "$ppStatsFromMetadata $outputStatsReal - DETREND_STACK";
     214    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     215        run(command => $command, verbose => $verbose);
     216    unless ($success) {
     217        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     218        &my_die("Unable to perform ppStatsFromMetadata: $error_code", $det_id, $iter, $class_id, $error_code);
     219    }
     220    foreach my $line (@$stdout_buf) {
     221        $cmdflags .= " $line";
     222    }
     223    chomp $cmdflags;
    233224}
    234225
     
    241232$command .= " -recip $recipe";
    242233$command .= " -dbname $dbname" if defined $dbname;
    243 $command .= $stats->cmdflags();
     234$command .= " $cmdflags";
    244235
    245236# Add the resultant into the database
Note: See TracChangeset for help on using the changeset viewer.