Changeset 8709
- Timestamp:
- Aug 30, 2006, 1:24:21 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/phase0exp.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/phase0exp.pl
r8551 r8709 16 16 use constant PHASE0_URI => 'uri'; # Key for the URI 17 17 use constant PHASE0_CLASSID => 'class_id'; # Key for the class id 18 use constant PHASE0_BG => 'bg'; # Key for the background18 use constant PHASE0_BG => 'bg'; # Key for the background 19 19 use constant PHASE0_BG_STDEV => 'bg_stdev'; # Key for the background standard deviation 20 20 use constant PHASE0_BG_MEAN_STDEV => 'bg_mean_stdev'; # Key for the mean of the background standard deviation … … 26 26 # These values should be constant for all components 27 27 use constant CONSTANTS => [ 28 "filter", # Filter used29 "airmass", # Airmass30 "ra", # Right ascension31 "decl", # Declination32 "posang", # Position angle33 "alt", # Altitude34 "az", # Azimuth35 "ccd_temp" # CCD temperature36 ];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 ]; 37 37 38 38 # These values may vary across components; we will take the average 39 39 use constant VARIABLES => [ 40 "exp_time", # Exposure time41 ### "time" # Time of exposure --- not yet implemented42 ];40 "exp_time", # Exposure time 41 ### "time" # Time of exposure --- not yet implemented 42 ]; 43 43 44 44 if (scalar @ARGV == 0 || scalar @ARGV >= 2) { 45 45 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"; 47 47 } 48 my $expid = shift @ARGV; # Exposure id48 my $expid = shift @ARGV; # Exposure id 49 49 50 50 … … 57 57 die "Can't find required tools.\n" if $missing_tools; 58 58 59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 60 60 61 61 # Get the list of imfiles … … 64 64 my $command = "$p0tool -rawimfile -exp_id $expid"; 65 65 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 66 run(command => $command, verbose => 1);66 run(command => $command, verbose => 1); 67 67 die "Unable to perform p0tool on exposure id $expid: $error_code\n" if not $success; 68 68 my $metadata = $mdcParser->parse(join "", @$stdout_buf); # Parsed metadata … … 71 71 72 72 # Process the values 73 my %values; # Values to update73 my %values; # Values to update 74 74 foreach my $variable (@{VARIABLES()}) { 75 75 $values{$variable} = []; 76 76 } 77 my @backgrounds; # Array of backgrounds78 my @stdevs; # Array of background standard deviations\79 my $obsType; # Observation type77 my @backgrounds; # Array of backgrounds 78 my @stdevs; # Array of background standard deviations\ 79 my $obsType; # Observation type 80 80 81 81 foreach my $imfile (@$imfiles) { 82 82 foreach my $constant (@{CONSTANTS()}) { 83 my $value = get_value($imfile, $constant); # Value for imfile84 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 } 90 90 } 91 91 92 92 foreach my $variable (@{VARIABLES()}) { 93 my $value = get_value($imfile, $variable); # Value for imfile94 my $array = $values{$variable};# Array of data95 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; 96 96 } 97 97 … … 104 104 my $type = get_value($imfile, TYPE()); 105 105 if (not defined $obsType) { 106 $obsType = $type;106 $obsType = $type; 107 107 } elsif ($obsType ne $type) { 108 die "Observation types differ.\n";108 die "Observation types differ.\n"; 109 109 } 110 110 } … … 116 116 # Add the values of interest 117 117 foreach my $constant (@{CONSTANTS()}) { 118 $command .= " -" . $constant . " " . $values{$constant};118 $command .= " -" . $constant . " " . $values{$constant}; 119 119 } 120 120 foreach my $variable (@{VARIABLES()}) { 121 my $array = $values{$variable};# Array of values122 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator123 $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(); 125 125 } 126 126 127 127 # Add the statistics 128 128 { 129 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator130 $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 } 137 137 } 138 138 { 139 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator140 $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(); 142 142 } 143 143 144 144 # Add the detrend flag 145 145 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 } 150 150 } 151 151 152 152 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 153 run(command => $command, verbose => 1);153 run(command => $command, verbose => 1); 154 154 die "Unable to run phase0 update for $expid: $error_code\n" if not $success; 155 155 } … … 160 160 # Get the value for a particular imfile, along with a strong check for its existence 161 161 sub get_value { 162 my $imfile = shift; # The hash of values163 my $name = shift; # The name of the value to check162 my $imfile = shift; # The hash of values 163 my $name = shift; # The name of the value to check 164 164 165 165 my $source = $imfile->{PHASE0_CLASSID()}; # Where it comes from
Note:
See TracChangeset
for help on using the changeset viewer.
