IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 11, 2006, 6:24:04 PM (20 years ago)
Author:
Paul Price
Message:

Updating following the big workflow discussion.

File:
1 edited

Legend:

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

    r8256 r8309  
    66use IPC::Cmd qw( can_run run );
    77use PS::IPP::Metadata::Config;
     8use PS::IPP::Metadata::Stats;
    89use Data::Dumper;
    910
    10 use constant RECIPE => "PPSTATS_PHASE0_IMFILE"; # Recipe to use for ppStats
     11use constant RECIPE => "PPSTATS_PHASE0"; # Recipe to use for ppStats
    1112
    12 # Switches for p0search
    13 use constant P0SEARCH_MODE => '-updateimfile'; # Mode for p0search
    14 use constant P0SEARCH_EXPID => '-exp_id'; # Switch to specify the exposure id
    15 use constant P0SEARCH_CLASSID => '-class_id'; # Switch to specify the class id
    16 use constant P0SEARCH_BG => '-bg'; # Switch to add the background
    17 use constant P0SEARCH_BGSD => '-background_stdev'; # Switch to add the bg stdev
    18 use constant P0SEARCH_EXPTIME => '-exp_time'; # Switch to add the exposure time
     13# These values should be constant for all components
     14# The key is the name in the ppStats output; the value is the switch for "phase0 -updateexp"
     15use constant CONSTANTS => {
     16    "FPA.FILTER"   => "-filter", # Filter used
     17    "FPA.AIRMASS"  => "-airmass", # Airmass
     18    "FPA.RA"       => "-ra",    # Right ascension
     19    "FPA.DEC"      => "-decl",  # Declination
     20    "TELALT"       => "-alt",   # Altitude
     21    "TELAZ"        => "-az",    # Azimuth
     22    "DETTEM"       => "-ccd_temp", # CCD temperature
     23    "FPA.POSANGLE" => "-posang", # Position angle
     24    };
    1925
     26# These values may vary across components; we will take the average
     27# The key is the name in the ppStats output; the value is the switch for "phase0 -updateexp"
     28use constant VARIABLES => {
     29    "CELL.EXPOSURE" => "-exp_time" # Exposure time
     30    };
     31
     32
     33# Switches for p0tool
     34use constant P0TOOL_MODE => '-updateimfile'; # Mode for p0tool
     35use constant P0TOOL_EXPID => '-exp_id'; # Switch to specify the exposure id
     36use constant P0TOOL_CLASSID => '-class_id'; # Switch to specify the class id
     37use constant P0TOOL_BG_MEAN => '-bg'; # Switch to add the background
     38use constant P0TOOL_BG_STDEV => '-bg_stdev'; # Switch to add the bg stdev
     39use constant P0TOOL_BG_MEAN_STDEV => '-bg_mean_stdev'; # Switch to add the bg mean stdev
     40
     41# Parse command-line arguments
    2042if (scalar @ARGV == 0 || scalar @ARGV > 3) {
    2143    die "Perform phase 0 processing at the imfile level.\n\n" .
     
    2749my $file = shift @ARGV;         # Input filename
    2850
    29 # Look for commands we need
     51
     52# Look for programs we need
    3053my $missing_tools;
    31 my $p0search = can_run('p0search')
    32     or (warn "can't find p0search" and $missing_tools = 1);
    33 my $ppStats = can_run('ppStats')
    34     or (warn "can't find ppStats" and $missing_tools = 1);
     54my $p0tool = can_run('p0tool') or (warn "Can't find p0tool" and $missing_tools = 1);
     55my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
    3556die "Can't find required tools.\n" if $missing_tools;
    3657
    37 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    38 
    3958# Run ppStats on the input file
    40 my $parsed;                     # Parsed metadata
     59my $stats;
    4160{
    4261    my $command = "$ppStats $file -recipe PPSTATS " . RECIPE; # Command to run ppStats
     
    4463        run(command => $command, verbose => 1);
    4564    die "Unable to perform ppStats on exposure id $expid: $error_code\n" if not $success;
    46     $parsed = $mdcParser->parse(join "", @$stdout_buf);
     65   
     66    # Parse the output
     67    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
     68    my $metadata = $mdcParser->parse(join "", @$stdout_buf);
     69    my @constants = keys %{CONSTANTS()}; # List of constants to parse out
     70    my @variables = keys %{VARIABLES()}; # List of variables to parse out
     71    $stats = PS::IPP::Metadata::Stats->new(\@constants, \@variables); # Stats parser
     72    $stats->parse($metadata) or die "Unable to find all values.\n";
    4773}
    48 
    49 my $bg = 0;                     # Mean background level
    50 my $sd = 0;                     # Mean standard deviation
    51 my $expTime = 0;                # Mean exposure time
    52 my $bgNum = 0;                  # Number of background entries
    53 my $sdNum = 0;                  # Number of standard deviation entries
    54 my $expTimeNum = 0;             # Number of exposure time entries
    55 foreach my $fpaItem (@$parsed) {
    56     if ($fpaItem->{class} eq "metadata") {
    57         my $chipName = $fpaItem->{name}; # Name of chip
    58         my $chipData = $fpaItem->{value}; # Chip-level data
    59         foreach my $chipItem (@$chipData) {
    60             if ($chipItem->{class} eq "metadata") {
    61                 my $cellName = $chipItem->{name}; # Name of cell
    62                 my $cellData = $chipItem->{value}; # Cell-level data
    63                 foreach my $cellItem (@$cellData) {
    64                     if ($cellItem->{name} =~ /^(SAMPLE|ROBUST|FITTED|CLIPPED)/) {
    65                         # It's a statistic of some sort
    66                         if ($cellItem->{name} =~ /STDEV$/) {
    67                             $sd += $cellItem->{value};
    68                             $sdNum++;
    69                         } else {
    70                             $bg += $cellItem->{value};
    71                             $bgNum++;
    72                         }
    73                     } elsif ($cellItem->{name} =~ /CELL\.EXPOSURE/) {
    74                         $expTime += $cellItem->{value};
    75                         $expTimeNum++;
    76                     }
    77                 }
    78             }
    79         }
    80     }
    81 }
    82 die "Unable to find statistics.\n" if ($bgNum == 0 or $sdNum == 0);
    83 $bg /= $bgNum;
    84 $sd /= $sdNum;
    85 die "Unable to find exposure times.\n" if ($expTimeNum == 0);
    86 $expTime /= $expTimeNum;
    8774
    8875# Push the results into the database
    8976{
    90     my $command = "$p0search " . P0SEARCH_MODE . " " . P0SEARCH_EXPID() . " $expid " .
    91         P0SEARCH_CLASSID() . " $classid " . P0SEARCH_BG() ." $bg " . P0SEARCH_BGSD() ." $sd " .
    92         P0SEARCH_EXPTIME() . " $expTime"; # Command to run p0search
     77    my $command = $p0tool . " " . P0TOOL_MODE() . " " . P0TOOL_EXPID() . " " . $expid . " " .
     78        P0TOOL_CLASSID() . " " . $classid; # Command to run p0tool
     79   
     80    foreach my $constant (keys %{CONSTANTS()}) {
     81        $command .= " " . CONSTANTS->{$constant} . " " . ($stats->data($constant))->{value};
     82    }
     83    foreach my $variable (keys %{VARIABLES()}) {
     84        # Just use the mean value
     85        $command .= " " . VARIABLES->{$variable} . " " . ($stats->data($variable))->{mean};
     86    }
     87   
     88    $command .= " " . P0TOOL_BG_MEAN() . " " . $stats->bg_mean();
     89    $command .= " " . P0TOOL_BG_STDEV() . " " . $stats->bg_stdev();
     90    $command .= " " . P0TOOL_BG_MEAN_STDEV() . " " . $stats->bg_mean_stdev();
     91 
    9392    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    9493        run(command => $command, verbose => 1);
    95     die "Unable to perform p0search -updateimfile: $error_code\n" if not $success;
     94    die "Unable to perform p0tool -updateimfile: $error_code\n" if not $success;
    9695}
     96
     97# Pau.
     98
     99__END__
Note: See TracChangeset for help on using the changeset viewer.