Changeset 8309 for trunk/ippScripts/scripts/phase0imfile.pl
- Timestamp:
- Aug 11, 2006, 6:24:04 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/phase0imfile.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/phase0imfile.pl
r8256 r8309 6 6 use IPC::Cmd qw( can_run run ); 7 7 use PS::IPP::Metadata::Config; 8 use PS::IPP::Metadata::Stats; 8 9 use Data::Dumper; 9 10 10 use constant RECIPE => "PPSTATS_PHASE0 _IMFILE"; # Recipe to use for ppStats11 use constant RECIPE => "PPSTATS_PHASE0"; # Recipe to use for ppStats 11 12 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" 15 use 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 }; 19 25 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" 28 use constant VARIABLES => { 29 "CELL.EXPOSURE" => "-exp_time" # Exposure time 30 }; 31 32 33 # Switches for p0tool 34 use constant P0TOOL_MODE => '-updateimfile'; # Mode for p0tool 35 use constant P0TOOL_EXPID => '-exp_id'; # Switch to specify the exposure id 36 use constant P0TOOL_CLASSID => '-class_id'; # Switch to specify the class id 37 use constant P0TOOL_BG_MEAN => '-bg'; # Switch to add the background 38 use constant P0TOOL_BG_STDEV => '-bg_stdev'; # Switch to add the bg stdev 39 use constant P0TOOL_BG_MEAN_STDEV => '-bg_mean_stdev'; # Switch to add the bg mean stdev 40 41 # Parse command-line arguments 20 42 if (scalar @ARGV == 0 || scalar @ARGV > 3) { 21 43 die "Perform phase 0 processing at the imfile level.\n\n" . … … 27 49 my $file = shift @ARGV; # Input filename 28 50 29 # Look for commands we need 51 52 # Look for programs we need 30 53 my $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); 54 my $p0tool = can_run('p0tool') or (warn "Can't find p0tool" and $missing_tools = 1); 55 my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1); 35 56 die "Can't find required tools.\n" if $missing_tools; 36 57 37 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files38 39 58 # Run ppStats on the input file 40 my $ parsed; # Parsed metadata59 my $stats; 41 60 { 42 61 my $command = "$ppStats $file -recipe PPSTATS " . RECIPE; # Command to run ppStats … … 44 63 run(command => $command, verbose => 1); 45 64 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"; 47 73 } 48 49 my $bg = 0; # Mean background level50 my $sd = 0; # Mean standard deviation51 my $expTime = 0; # Mean exposure time52 my $bgNum = 0; # Number of background entries53 my $sdNum = 0; # Number of standard deviation entries54 my $expTimeNum = 0; # Number of exposure time entries55 foreach my $fpaItem (@$parsed) {56 if ($fpaItem->{class} eq "metadata") {57 my $chipName = $fpaItem->{name}; # Name of chip58 my $chipData = $fpaItem->{value}; # Chip-level data59 foreach my $chipItem (@$chipData) {60 if ($chipItem->{class} eq "metadata") {61 my $cellName = $chipItem->{name}; # Name of cell62 my $cellData = $chipItem->{value}; # Cell-level data63 foreach my $cellItem (@$cellData) {64 if ($cellItem->{name} =~ /^(SAMPLE|ROBUST|FITTED|CLIPPED)/) {65 # It's a statistic of some sort66 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;87 74 88 75 # Push the results into the database 89 76 { 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 93 92 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 94 93 run(command => $command, verbose => 1); 95 die "Unable to perform p0 search-updateimfile: $error_code\n" if not $success;94 die "Unable to perform p0tool -updateimfile: $error_code\n" if not $success; 96 95 } 96 97 # Pau. 98 99 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
