IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 26, 2007, 7:34:41 AM (19 years ago)
Author:
eugene
Message:

defining dark trend

File:
1 edited

Legend:

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

    r13848 r13979  
    11#!/usr/bin/env perl
    22
    3 use warnings;
    4 use strict;
     3# use warnings;
     4# use strict;
    55use Carp;
     6use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     7use Pod::Usage qw( pod2usage );
     8use IPC::Cmd 0.36 qw( can_run run );
    69
    7 # USAGE: ipp_darkstats.pl --dbname (name) --det_id (id)
     10use PS::IPP::Metadata::List qw( parse_md_list );
     11
     12use PS::IPP::Config qw($PS_EXIT_SUCCESS         
     13                       $PS_EXIT_UNKNOWN_ERROR
     14                       $PS_EXIT_SYS_ERROR
     15                       $PS_EXIT_CONFIG_ERROR
     16                       $PS_EXIT_PROG_ERROR
     17                       $PS_EXIT_DATA_ERROR
     18                       $PS_EXIT_TIMEOUT_ERROR
     19                       caturi
     20                       );                        # tools to parse the IPP configuration information
     21
     22my $ipprc = PS::IPP::Config->new(); # IPP configuration
     23
     24my ($dbname, $det_id, $camera);
     25
     26GetOptions('dbname=s'    => \$dbname,
     27           'det_id=s'    => \$det_id,
     28           'camera|c=s'  => \$camera,
     29           ) or pod2usage( 2 );
     30
     31pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     32
     33pod2usage(
     34          -msg => "USAGE: ipp_darkstats.pl --dbname (name) --det_id (id) --camera (name)",
     35          -exitval => 3,
     36          ) unless defined $dbname and defined $det_id and defined $camera;
     37
     38$ipprc->define_camera($camera);
    839
    940###  Get list of dark imfile results
    1041
    1142# define the dettool command
    12 my $command = "$dettool -processedimfile -select_state stop"; # Command to run
     43my $command = "dettool -processedimfile -select_state stop"; # Command to run
    1344$command .= " -det_id $det_id";
    1445$command .= " -dbname $dbname" if defined $dbname;
     
    1647# run the dettool command and catch the output
    1748my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    18     run(command => $command, verbose => 1);
     49    run(command => $command, verbose => 0);
    1950unless ($success) {
    2051    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    21     &my_die("Unable to perform dettool: $error_code", $det_id, $error_code);
     52    &my_die("Unable to perform dettool: $error_code", $error_code);
    2253}
    2354
    2455# parse the output into a list
     56my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    2557my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    26     &my_die("Unable to parse metadata config doc", $det_id, $PS_EXIT_PROG_ERROR);
    27 my $files = parse_md_list($metadata) or
    28     &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR);
     58    &my_die("Unable to parse metadata config doc", $PS_EXIT_PROG_ERROR);
     59my $list = parse_md_list($metadata) or
     60    &my_die("Unable to parse metadata list", $PS_EXIT_PROG_ERROR);
    2961
    30 # XXX finish this off:
     62my @bg_data;
     63my @bg_stdev_data;
     64my @bg_name;
     65my @bg_exptime;
     66
     67# we now have a list of imfiles; we need to extract the background for each cell
     68# from the stats files for each imfile
     69foreach my $item (@$list) {
     70    my $path_base = $item->{path_base};
     71    my $class_id = $item->{class_id};
     72    my $exp_time = $item->{exp_time};
     73
     74    my $rootName  = $ipprc->file_resolve ($path_base);
     75    my $statsName = "$rootName.$class_id.stats";
     76
     77    # print STDERR "rootName: $rootName\n";
     78    # print STDERR "statsName: $statsName\n";
     79
     80    my $statsFile;
     81    open $statsFile, $statsName;
     82    my @contents = <$statsFile>;
     83    close ($statsFile);
     84
     85    # print STDERR "contents: @contents\n";
     86
     87    my $parser = PS::IPP::Metadata::Config->new;        # Parser for metadata config files
     88    my $statsList = $parser->parse(join "", @contents) or &my_die("Unable to parse metadata for imfile stats", $PS_EXIT_SYS_ERROR);
     89
     90    &parse_stats_table ($exp_time, $class_id, $statsList);
     91}
     92
     93print STDERR "dumping stats\n";
     94
     95for (my $i = 0; $i < @bg_data; $i++) {
     96    $name1 = "$bg_name[$i].bg";
     97    $name2 = "$bg_name[$i].exp";
     98    push @{$name1}, $bg_data[$i];
     99    push @{$name2}, $bg_exptime[$i];
     100}
     101
     102exit 0;
     103
     104sub parse_stats_table
     105{
     106    my ($exp_time, $tag, $md) = @_;
     107
     108    # descend through the fpa       
     109    foreach my $entry (@$md) {
     110        # print STDERR "name: $entry->{name}, class: $entry->{class}\n";
     111        # recurse on nested metadata
     112        if ($entry->{class} eq 'metadata') {
     113            my $newtag = $tag . ":" . $entry->{name};
     114            &parse_stats_table ($exp_time, $newtag, $entry->{value});
     115        }
     116
     117        if ($entry->{name} =~ /^(SAMPLE|ROBUST|FITTED|CLIPPED)_/) {
     118            # It's a statistic of some sort
     119            if ($entry->{name} =~ /_STDEV$/) {
     120                push @bg_stdev_data, $entry->{value};
     121            } else {
     122                push @bg_data, $entry->{value};
     123            }
     124            push @bg_name, $tag;
     125            push @bg_exptime, $exp_time;
     126            next;
     127        }
     128    }
     129    return 1;
     130}
     131
     132sub my_die
     133{
     134    my $msg = shift; # Warning message on die
     135    my $exit_code = shift; # Exit code to add
     136
     137    carp($msg);
     138    exit $exit_code;
     139}
    31140
    32141# - get the exp_time as well from dettool
Note: See TracChangeset for help on using the changeset viewer.