IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 4, 2007, 1:53:22 PM (19 years ago)
Author:
eugene
Message:

extensive changes to use new stats calculation tools; general cleanups

File:
1 edited

Legend:

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

    r13989 r14009  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
     18use PS::IPP::Metadata::Stats;
    1819use PS::IPP::Metadata::List qw( parse_md_list );
    19 use PS::IPP::Metadata::Stats;
    2020
    2121use PS::IPP::Config qw($PS_EXIT_SUCCESS
     
    4141    'camera|c=s'        => \$camera,
    4242    'dbname|d=s'        => \$dbname, # Database name
    43     'workdir|w=s'       => \$workdir,   # Working directory, for output files
     43    'workdir|w=s'       => \$workdir, # Working directory, for output files
    4444    'reduction=s'       => \$reduction, # Reduction class for processing
    4545    'no-update'         => \$no_update,
     
    4949
    5050pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    51 pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera", -exitval => 3 )
     51pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera",
     52           -exitval => 3)
    5253    unless defined $det_id
    5354    and defined $iter
     
    6465$reduction = "DETREND" unless defined $reduction;
    6566my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_STACK'); # Recipe name to use
     67
     68# values to extract from output metadata and the stats to calculate
     69# XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A)
     70# XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0     (B)
     71# XXX  (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1
     72my $STATS =
     73   [   
     74       #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
     75       { name => "bg",             type => "mean",  flag => "-bg" },
     76       { name => "bg",             type => "stdev", flag => "-bg_mean_stdev" },
     77       { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev" },
     78       # { name => "bg_mean_stdev",  type => "rms",   flag => "-bg_mean_stdev" },
     79   ];
    6680
    6781# Look for programs we need
     
    7488}
    7589
    76 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     90$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     91
     92my $outputRoot  = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} );
     93my $outputStack = $outputRoot . '.fits'; # Output name
     94my $outputStats = $outputRoot . '.stats'; # Statistics name
    7795
    7896# Get list of files to stack
    7997my $files;                      # Array of files to be stacked
    8098{
    81     my $command = "$dettool -processedimfile -det_id $det_id -class_id $class_id -included"; # Command to run
     99    my $command = "$dettool -processedimfile -included";
     100    $command .= " -det_id $det_id";
     101    $command .= " -class_id $class_id";
    82102    $command .= " -dbname $dbname" if defined $dbname;
     103
    83104    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    84105        run(command => $command, verbose => $verbose);
     
    87108        &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $iter, $class_id, $error_code);
    88109    }
     110
     111    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    89112    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    90113        &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     
    93116}
    94117
    95 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
    96 
    97 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} );
    98 my $outputStack = $outputRoot . '.fits'; # Output name
    99 my $outputStats = $outputRoot . '.stats'; # Statistics name
     118my $command = "$ppMerge $outputStack"; # Command to run
     119foreach my $file (@$files) {
     120    $command .= ' ' . $file->{uri};
     121}
     122$command .= " -recipe PPMERGE $recipe";
     123$command .= ' -type ' . uc($det_type); # Type of stacking to perform
     124$command .= " -stats $outputStats";     # Statistics output filename
     125$command .= " -recipe PPSTATS CHIPSTATS";
    100126
    101127# Stack the files
    102 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    103128unless ($no_op) {
    104     my $command = "$ppMerge $outputStack"; # Command to run
    105     foreach my $file (@$files) {
    106         $command .= ' ' . $file->{uri};
    107     }
    108     $command .= " -recipe PPMERGE $recipe";
    109     $command .= ' -type ' . uc($det_type); # Type of stacking to perform
    110     $command .= " -stats $outputStats"; # Statistics output filename
    111     $command .= " -recipe PPSTATS CHIPSTATS";
    112129   
    113130    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    129146    my $metadata = $mdcParser->parse($contents) or
    130147        &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    131     $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
     148
     149    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    132150    $stats->parse($metadata)  or
    133151        &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    134152}
    135153
    136 my $bg            = $stats->bg_mean();
    137 my $bg_stdev      = $stats->bg_stdev();
    138 my $bg_mean_stdev = $stats->bg_mean_stdev();
     154# Command to update the database
     155$command  = "$dettool -addstacked";
     156$command .= " -det_id $det_id -iteration $iter";
     157$command .= " -class_id $class_id";
     158$command .= " -uri $outputStack";
     159$command .= " -recip $recipe";
     160$command .= " -dbname $dbname" if defined $dbname;
     161
     162# add in the elements from the selected stats above
     163foreach my $entry (@$STATS) {
     164    my $value = $entry->{value};
     165    my $flag = $entry->{flag};
     166    $command .= " $flag $value";
     167}
    139168
    140169# Add the resultant into the database
    141170unless ($no_update) {
    142     my $command = "$dettool -addstacked";
    143     $command .= " -det_id $det_id -iteration $iter";
    144     $command .= " -class_id $class_id";
    145     $command .= " -uri $outputStack";
    146     $command .= " -recip $recipe";
    147     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
    148     $command .= " -dbname $dbname" if defined $dbname;
    149 
    150171    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    151172        run(command => $command, verbose => $verbose);
     
    155176        exit($error_code);
    156177    }
    157 }
    158 
     178} else {
     179    print "skipping command: $command\n";
     180}
    159181
    160182sub my_die
     
    168190    carp($msg);
    169191    if ($det_id and $iter and $class_id and not $no_update) {
    170         my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code";
     192        my $command = "$dettool -addstacked";
     193        $command .= " -det_id $det_id";
     194        $command .= " -iteration $iter";
     195        $command .= " -class_id $class_id";
     196        $command .= " -code $exit_code";
    171197        $command .= " -dbname $dbname" if defined $dbname;
    172198###        system ($command);
Note: See TracChangeset for help on using the changeset viewer.