IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 5, 2006, 4:45:46 PM (20 years ago)
Author:
jhoblitt
Message:

move the guts of the existing parser out of ->parse() and into it's own ->_parse_megacam() method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Metadata/Stats.pm

    r8740 r8743  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Stats.pm,v 1.7 2006-09-06 01:53:49 jhoblitt Exp $
     3# $Id: Stats.pm,v 1.8 2006-09-06 02:45:46 jhoblitt Exp $
    44
    55package PS::IPP::Metadata::Stats;
     
    6161    # count of parse errors
    6262    my $errors = 0;
     63
     64    $self->_parse_megacam($md);
     65
     66    # Check that we found everything for the constants
     67    my $constants = $self->constants();        # Array of constants
     68    if (defined $constants) {
     69        foreach my $constant (@$constants) {
     70            if (not defined $self->{data}->{$constant}->{value}) {
     71                carp "Unable to find value for ", $constant, "\n";
     72                $errors++;
     73            }
     74        }
     75    }
     76
     77    # Get mean, stdev for the variables
     78    my $variables = $self->variables();        # Array of variables
     79    if (defined $variables) {
     80        foreach my $variable (@$variables) {
     81            my $info = $self->{data}->{$variable}; # The information about this particular variable
     82            my $array = $info->{data}; # The array of values collected
     83            if (scalar @$array == 0) {
     84                carp "Unable to find any values for ", $variable, "\n";
     85                $errors++;
     86                next;
     87            }
     88
     89            # Get statistics on the value
     90            my $stats = Statistics::Descriptive::Sparse->new(); # Statistics calculator
     91            $stats->add_data(@$array);
     92            $info->{mean} = $stats->mean();
     93            $info->{stdev} = $stats->standard_deviation();
     94        }
     95    }
     96   
     97    # Get mean, stdev, mean stdev for the background
     98    if (scalar @{$self->{bg_data}} > 0) {
     99        my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics for mean
     100        $meanStats->add_data(@{$self->{bg_data}});
     101        $self->bg_mean($meanStats->mean());
     102        $self->bg_stdev($meanStats->standard_deviation());
     103    } else {
     104        $self->bg_mean(undef);
     105        $self->bg_stdev(undef);
     106    }
     107    if (scalar @{$self->{bg_stdev_data}} > 0) {
     108        my $stdevStats = Statistics::Descriptive::Sparse->new(); # Statistics for standard deviation
     109        $stdevStats->add_data(@{$self->{bg_stdev_data}});
     110        $self->bg_mean_stdev($stdevStats->mean());
     111    } else {
     112        $self->bg_mean_stdev(undef);
     113    }
     114
     115    if ($errors) {
     116        carp "a total of $errors parse errors occured";
     117        return;
     118    }
     119
     120    return $self;
     121}
     122
     123sub _parse_megacam
     124{
     125    my ($self, $md) = @_;
    63126
    64127    # Descend the FPA hierarchy
     
    105168        }
    106169    }
    107 
    108     # Check that we found everything for the constants
    109     my $constants = $self->constants();        # Array of constants
    110     if (defined $constants) {
    111         foreach my $constant (@$constants) {
    112             if (not defined $self->{data}->{$constant}->{value}) {
    113                 carp "Unable to find value for ", $constant, "\n";
    114                 $errors++;
    115             }
    116         }
    117     }
    118 
    119     # Get mean, stdev for the variables
    120     my $variables = $self->variables();        # Array of variables
    121     if (defined $variables) {
    122         foreach my $variable (@$variables) {
    123             my $info = $self->{data}->{$variable}; # The information about this particular variable
    124             my $array = $info->{data}; # The array of values collected
    125             if (scalar @$array == 0) {
    126                 carp "Unable to find any values for ", $variable, "\n";
    127                 $errors++;
    128                 next;
    129             }
    130 
    131             # Get statistics on the value
    132             my $stats = Statistics::Descriptive::Sparse->new(); # Statistics calculator
    133             $stats->add_data(@$array);
    134             $info->{mean} = $stats->mean();
    135             $info->{stdev} = $stats->standard_deviation();
    136         }
    137     }
    138170   
    139     # Get mean, stdev, mean stdev for the background
    140     if (scalar @{$self->{bg_data}} > 0) {
    141         my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics for mean
    142         $meanStats->add_data(@{$self->{bg_data}});
    143         $self->bg_mean($meanStats->mean());
    144         $self->bg_stdev($meanStats->standard_deviation());
    145     } else {
    146         $self->bg_mean(undef);
    147         $self->bg_stdev(undef);
    148     }
    149     if (scalar @{$self->{bg_stdev_data}} > 0) {
    150         my $stdevStats = Statistics::Descriptive::Sparse->new(); # Statistics for standard deviation
    151         $stdevStats->add_data(@{$self->{bg_stdev_data}});
    152         $self->bg_mean_stdev($stdevStats->mean());
    153     } else {
    154         $self->bg_mean_stdev(undef);
    155     }
    156 
    157     if ($errors) {
    158         carp "a total of $errors parse errors occured";
    159         return;
    160     }
    161 
    162171    return $self;
    163172}
Note: See TracChangeset for help on using the changeset viewer.