IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 30, 2006, 1:24:21 PM (20 years ago)
Author:
jhoblitt
Message:

expand tabs

File:
1 edited

Legend:

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

    r8551 r8709  
    1616use constant PHASE0_URI => 'uri'; # Key for the URI
    1717use constant PHASE0_CLASSID => 'class_id'; # Key for the class id
    18 use constant PHASE0_BG => 'bg'; # Key for the background
     18use constant PHASE0_BG => 'bg';        # Key for the background
    1919use constant PHASE0_BG_STDEV => 'bg_stdev'; # Key for the background standard deviation
    2020use constant PHASE0_BG_MEAN_STDEV => 'bg_mean_stdev'; # Key for the mean of the background standard deviation
     
    2626# These values should be constant for all components
    2727use constant CONSTANTS => [
    28                            "filter", # Filter used
    29                            "airmass", # Airmass
    30                            "ra", # Right ascension
    31                            "decl", # Declination
    32                            "posang", # Position angle
    33                            "alt", # Altitude
    34                            "az", # Azimuth
    35                            "ccd_temp" # CCD temperature
    36                        ];
     28                           "filter", # Filter used
     29                           "airmass", # Airmass
     30                           "ra", # Right ascension
     31                           "decl", # Declination
     32                           "posang", # Position angle
     33                           "alt", # Altitude
     34                           "az", # Azimuth
     35                           "ccd_temp" # CCD temperature
     36                       ];
    3737
    3838# These values may vary across components; we will take the average
    3939use constant VARIABLES => [
    40                            "exp_time", # Exposure time
    41 ###                        "time" # Time of exposure --- not yet implemented
    42                            ];
     40                           "exp_time", # Exposure time
     41###                           "time" # Time of exposure --- not yet implemented
     42                           ];
    4343
    4444if (scalar @ARGV == 0 || scalar @ARGV >= 2) {
    4545    die "Perform phase 0 processing at the exposure level.\n\n" .
    46         "Usage: $0 EXP_ID\n\n";
     46        "Usage: $0 EXP_ID\n\n";
    4747}
    48 my $expid = shift @ARGV;        # Exposure id
     48my $expid = shift @ARGV;        # Exposure id
    4949
    5050
     
    5757die "Can't find required tools.\n" if $missing_tools;
    5858
    59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     59my $mdcParser = PS::IPP::Metadata::Config->new;        # Parser for metadata config files
    6060
    6161# Get the list of imfiles
     
    6464    my $command = "$p0tool -rawimfile -exp_id $expid";
    6565    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    66         run(command => $command, verbose => 1);
     66        run(command => $command, verbose => 1);
    6767    die "Unable to perform p0tool on exposure id $expid: $error_code\n" if not $success;
    6868    my $metadata = $mdcParser->parse(join "", @$stdout_buf); # Parsed metadata
     
    7171
    7272# Process the values
    73 my %values;                     # Values to update
     73my %values;                        # Values to update
    7474foreach my $variable (@{VARIABLES()}) {
    7575    $values{$variable} = [];
    7676}
    77 my @backgrounds;                # Array of backgrounds
    78 my @stdevs;                     # Array of background standard deviations\
    79 my $obsType;                    # Observation type
     77my @backgrounds;                # Array of backgrounds
     78my @stdevs;                        # Array of background standard deviations\
     79my $obsType;                        # Observation type
    8080 
    8181foreach my $imfile (@$imfiles) {
    8282    foreach my $constant (@{CONSTANTS()}) {
    83         my $value = get_value($imfile, $constant); # Value for imfile
    84         if (not defined $values{$constant}) {
    85             $values{$constant} = $value;
    86         } elsif ($values{$constant} ne $value) {
    87             die "Value of $constant for " . $imfile->{PHASE0_CLASSID} .
    88                 " doesn't match previous value.\n";
    89         }
     83        my $value = get_value($imfile, $constant); # Value for imfile
     84        if (not defined $values{$constant}) {
     85            $values{$constant} = $value;
     86        } elsif ($values{$constant} ne $value) {
     87            die "Value of $constant for " . $imfile->{PHASE0_CLASSID} .
     88                " doesn't match previous value.\n";
     89        }
    9090    }
    9191   
    9292    foreach my $variable (@{VARIABLES()}) {
    93         my $value = get_value($imfile, $variable); # Value for imfile
    94         my $array = $values{$variable}; # Array of data
    95         push @$array, $value;
     93        my $value = get_value($imfile, $variable); # Value for imfile
     94        my $array = $values{$variable};        # Array of data
     95        push @$array, $value;
    9696    }
    9797   
     
    104104    my $type = get_value($imfile, TYPE());
    105105    if (not defined $obsType) {
    106         $obsType = $type;
     106        $obsType = $type;
    107107    } elsif ($obsType ne $type) {
    108         die "Observation types differ.\n";
     108        die "Observation types differ.\n";
    109109    }
    110110}
     
    116116    # Add the values of interest
    117117    foreach my $constant (@{CONSTANTS()}) {
    118         $command .= " -" . $constant . " " . $values{$constant};
     118        $command .= " -" . $constant . " " . $values{$constant};
    119119    }
    120120    foreach my $variable (@{VARIABLES()}) {
    121         my $array = $values{$variable}; # Array of values
    122         my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
    123         $stats->add_data(@$array);
    124         $command .= " -" . $variable . " " . $stats->mean();
     121        my $array = $values{$variable};        # Array of values
     122        my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
     123        $stats->add_data(@$array);
     124        $command .= " -" . $variable . " " . $stats->mean();
    125125    }
    126126
    127127    # Add the statistics
    128128    {
    129         my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
    130         $stats->add_data(@backgrounds);
    131         $command .= " -" . PHASE0_BG() . " " . $stats->mean();
    132         if (scalar @backgrounds == 1) {
    133             $command .= ' -' . PHASE0_BG_STDEV() . " 0.0";
    134         } else {
    135             $command .= " -" . PHASE0_BG_STDEV() . " " . $stats->standard_deviation();
    136         }
     129        my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
     130        $stats->add_data(@backgrounds);
     131        $command .= " -" . PHASE0_BG() . " " . $stats->mean();
     132        if (scalar @backgrounds == 1) {
     133            $command .= ' -' . PHASE0_BG_STDEV() . " 0.0";
     134        } else {
     135            $command .= " -" . PHASE0_BG_STDEV() . " " . $stats->standard_deviation();
     136        }
    137137    }
    138138    {
    139         my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
    140         $stats->add_data(@stdevs);
    141         $command .= " -" . PHASE0_BG_MEAN_STDEV() . " " . $stats->mean();
     139        my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
     140        $stats->add_data(@stdevs);
     141        $command .= " -" . PHASE0_BG_MEAN_STDEV() . " " . $stats->mean();
    142142    }
    143143   
    144144    # Add the detrend flag
    145145    foreach my $detrendType (@{DETRENDS()}) {
    146         if (lc($obsType) eq lc($detrendType)) {
    147             $command .= " " . DETREND_FLAG;
    148             last;
    149         }
     146        if (lc($obsType) eq lc($detrendType)) {
     147            $command .= " " . DETREND_FLAG;
     148            last;
     149        }
    150150    }
    151151 
    152152    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    153         run(command => $command, verbose => 1);
     153        run(command => $command, verbose => 1);
    154154    die "Unable to run phase0 update for $expid: $error_code\n" if not $success;
    155155}
     
    160160# Get the value for a particular imfile, along with a strong check for its existence
    161161sub get_value {
    162     my $imfile = shift;         # The hash of values
    163     my $name = shift;           # The name of the value to check
     162    my $imfile = shift;                # The hash of values
     163    my $name = shift;                # The name of the value to check
    164164
    165165    my $source = $imfile->{PHASE0_CLASSID()}; # Where it comes from
Note: See TracChangeset for help on using the changeset viewer.