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_process_imfile.pl

    r13989 r14009  
    4848
    4949pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    50 pod2usage(
    51     -msg => "Required options: --det_id --exp_tag --class_id --det_type --input_uri --camera",
    52     -exitval => 3,
    53 ) unless defined $det_id
     50pod2usage( -msg => "Required options: --det_id --exp_tag --class_id --det_type --input_uri --camera",
     51           -exitval => 3)
     52    unless defined $det_id
    5453    and defined $exp_tag
    5554    and defined $class_id
     
    6160$ipprc->define_camera($camera);
    6261
     62# Recipes to use as a function of detrend type
    6363$reduction = "DETREND" unless defined $reduction;
    6464my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_PROCESS'); # Recipe name to use
     65
     66# values to extract from output metadata and the stats to calculate
     67my $STATS =
     68   [   
     69       #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
     70       { name => "ROBUST_MEDIAN",  type => "mean",  flag => "-bg" },
     71       { name => "ROBUST_MEDIAN",  type => "stdev", flag => "-bg_mean_stdev" },
     72       { name => "ROBUST_STDEV",   type => "rms",   flag => "-bg_stdev" },
     73   ];
    6574
    6675# Look for programs we need
     
    7483$ppImage .= " -dbname $dbname" if defined $dbname;
    7584
     85&my_die("Couldn't find input file: $input_uri\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
     86
    7687$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
    7788
    78 my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, $input_uri );
     89my $outputRoot  = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, $input_uri );
     90
    7991my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    80 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
    81 my $outputBin2 = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
    82 my $outputStats = $outputRoot . '.' . $class_id . '.stats';
     92my $outputBin1  = $ipprc->filename("PPIMAGE.BIN1",  $outputRoot, $class_id);
     93my $outputBin2  = $ipprc->filename("PPIMAGE.BIN2",  $outputRoot, $class_id);
     94my $outputStats = $ipprc->filename("PPIMAGE.STATS",  $outputRoot, $class_id);
    8395
    8496# Run ppImage
    85 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    8697unless ($no_op) {
    8798    my $command = "$ppImage -file $input_uri $outputRoot";
     
    96107        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $class_id, $error_code);
    97108    }
     109
    98110    &my_die("Couldn't find expected output file: $outputImage", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage);
    99111    &my_die("Couldn't find expected output file: $outputStats", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
     
    106118    my @contents = <$statsFile>; # Contents of file
    107119    close $statsFile;
     120
     121    # parse the statistics MDC file
    108122    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    109123    my $metadata = $mdcParser->parse(join "", @contents)
    110124        or &my_die("Unable to parse metadata config", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     125
     126    # extract the stats from the metadata
     127    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    111128    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    112129}
    113130
    114 my $bg            = $stats->bg_mean();
    115 my $bg_stdev      = $stats->bg_stdev();
    116 my $bg_mean_stdev = $stats->bg_mean_stdev();
     131# command to update database
     132my $command = "$dettool -addprocessedimfile";
     133$command .= " -det_id $det_id";
     134$command .= " -exp_tag $exp_tag";
     135$command .= " -class_id $class_id";
     136$command .= " -recip $reduction";
     137$command .= " -uri $outputImage -path_base $outputRoot";
     138$command .= " -dbname $dbname" if defined $dbname;
     139
     140# add in the elements from the selected stats above
     141foreach my $entry (@$STATS) {
     142    my $value = $entry->{value};
     143    my $flag = $entry->{flag};
     144    $command .= " $flag $value";
     145}
    117146
    118147# Add the processed file to the database
    119148unless ($no_update) {
    120     my $command = "$dettool -addprocessedimfile";
    121     $command .= " -det_id $det_id";
    122     $command .= " -exp_tag $exp_tag";
    123     $command .= " -class_id $class_id";
    124     $command .= " -recip $recipe";
    125     $command .= " -uri $outputImage -path_base $outputRoot";
    126     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
    127     $command .= " -dbname $dbname" if defined $dbname;
    128 
    129149    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    130150        run(command => $command, verbose => 1);
     
    134154        exit($error_code);
    135155    }
     156} else {
     157    print "skipping command: $command\n";
    136158}
    137159
     
    146168    carp($msg);
    147169    if ($det_id and $exp_tag and $class_id and not $no_update) {
    148         my $command = "$dettool -addprocessedimfile -det_id $det_id -exp_tag $exp_tag -class_id $class_id -code $exit_code";
     170        my $command = "$dettool -addprocessedimfile";
     171        $command .= " -det_id $det_id";
     172        $command .= " -exp_tag $exp_tag";
     173        $command .= " -class_id $class_id";
     174        $command .= " -code $exit_code";
    149175        $command .= " -dbname $dbname" if defined $dbname;
    150176###        system ($command);
Note: See TracChangeset for help on using the changeset viewer.