Changeset 8236 for trunk/ippScripts/scripts/phase0exp.pl
- Timestamp:
- Aug 8, 2006, 2:54:43 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/phase0exp.pl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/phase0exp.pl
r8197 r8236 10 10 use constant RECIPE => "PPSTATS_PHASE0"; # Recipe to use for ppStats 11 11 12 use constant TYPE => "OBSTYPE"; # Observation type keyword 13 use constant DETRENDS => ( "bias", "dark", "flat", "fringe" ); # Observation types to mark as detrend 14 use constant DETREND_FLAG => "-detrend"; # Flag to use to mark detrend exposure 15 16 use constant IMFILE_URI => 'uri'; # Key for the URI out of p0search -pendingimfile 17 use constant IMFILE_BG => 'background'; # Key for the background out of p0search -pendingimfile 18 use constant IMFILE_BGSD => 'background_stdev'; # Key for the background standard deviation 19 20 use constant EXP_BG => '-background'; # Switch to add background for exposure 21 use constant EXP_BGSD => '-background_stdev'; # Switch to add background standard deviation 22 use constant EXP_BGMEANSD => '-background_mean_stdev'; # Switch to add mean of background standard deviation 23 12 24 # These values should be constant for all components 13 use constant CONSTANTS => ( 14 "OBSTYPE", # Observation type 15 "DETTEM", # Detector temperature 16 "FPA.FILTER", # Filter used 17 "FPA.RA", # Right ascension 18 "FPA.DEC", # Declination 19 "FPA.AIRMASS", # Airmass 20 "TELALT", # Altitude 21 "TELAZ", # Azimuth 22 "FPA.POSANGLE" # Position angle 23 ); 25 use constant CONSTANTS => { 26 "FPA.FILTER" => "-filter", # Filter used 27 "FPA.AIRMASS" => "-airmass", # Airmass 28 "FPA.RA" => "-ra", # Right ascension 29 "FPA.DEC" => "-decl", # Declination 30 "FPA.POSANGLE" => "-posang", # Position angle 31 "TELALT" => "-alt", # Altitude 32 "TELAZ" => "-az", # Azimuth 33 "DETTEM" => "-ccd_temp" # CCD temperature 34 }; 24 35 25 36 # These values may vary across components; we will take the average 26 use constant VARIABLES => (27 "CELL.EXPOSURE" , # Exposure time37 use constant VARIABLES => { 38 "CELL.EXPOSURE" => "-exp_time", # Exposure time 28 39 ### "CELL.TIME" # Time of exposure --- not yet implemented 29 ); 30 if (scalar @ARGV == 0) { 31 die "Perform phase 0 processing on the component files of an FPA.\n\n" . 32 "Usage: $0 FPA_FILE_1.fits FPA_FILE_2.fits FPA_FILE_3.fits ...\n\n"; 40 }; 41 42 if (scalar @ARGV == 0 || scalar @ARGV >= 2) { 43 die "Perform phase 0 processing at the exposure level.\n\n" . 44 "Usage: $0 EXP_ID\n\n"; 33 45 } 34 46 … … 36 48 # Look for commands we need 37 49 my $missing_tools; 50 my $p0search = can_run('p0search') 51 or (warn "can't find p0search" and $missing_tools = 1); 38 52 my $ppStats = can_run('ppStats') 39 53 or (warn "can't find ppStats" and $missing_tools = 1); 40 54 die "Can't find required tools.\n" if $missing_tools; 41 55 42 my @filenames = @ARGV; # Input files, all for one FPA 56 my $expid = shift @ARGV; # Exposure id 57 58 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 59 60 # Get the list of filenames 61 my $filenames; # Hash of input files, with their background and stdev 62 { 63 my $command = "$p0search -pendingimfile -exp_id $expid"; 64 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 65 run(command => $command, verbose => 0); 66 die "Unable to perform ppStats on exposure id $expid: $error_code\n" if not $success; 67 my $parsed = $mdcParser->parse(join "", @$stdout_buf); # Parsed metadata 68 $filenames = mdFileInfo($parsed); # Get filenames from the output 69 } 70 43 71 my %values; # Values to return 44 45 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 46 47 foreach my $fileName (@filenames) { 72 foreach my $fileName (keys %$filenames) { 48 73 my $command = "$ppStats $fileName -recipe PPSTATS " . RECIPE; # Command to run 49 74 print "Executing: $command\n"; … … 56 81 } 57 82 58 foreach my $constant (CONSTANTS) { 83 my $command = "$p0search -updateexp"; # Command to execute to update exposure parameters 84 85 foreach my $constant (keys %{CONSTANTS()}) { 59 86 if (not defined $values{$constant}) { 60 87 die "Couldn't find value for $constant.\n"; 61 88 } 89 my $switch = CONSTANTS->{$constant}; # The switch to use on the value 62 90 my $value = $values{$constant}; # The value of interest 63 print "$constant: $value\n";64 } 65 66 foreach my $variable ( VARIABLES) {91 $command .= " $switch $value"; 92 } 93 94 foreach my $variable (keys %{VARIABLES()}) { 67 95 if (not defined $values{$variable}) { 68 96 die "Couldn't find value for $variable.\n"; 69 97 } 98 my $switch = VARIABLES->{$variable}; # The switch to use on the value 70 99 # Take the mean 71 100 my $value = $values{$variable}->{value} / $values{$variable}->{num}; # Value of interest 72 print "$variable: $value\n"; 73 } 101 $command .= " $switch $value"; 102 } 103 104 ### Now to do the background: mean background, SD of backgrounds, mean of background SDs 105 my $bgMean = 0; # Mean background 106 my $bgsdMean = 0; # Mean of background SDs 107 foreach my $filename (keys %$filenames) { 108 my $stats = $filenames->{$filename}; # Statistics for that file 109 $bgMean += $stats->{bg}; 110 $bgsdMean += $stats->{bgsd}; 111 } 112 $bgMean /= scalar(keys %$filenames); 113 $bgsdMean /= scalar(keys %$filenames); 114 my $bgSD = 0; # SD of backgrounds 115 foreach my $filename (keys %$filenames) { 116 my $stats = $filenames->{$filename}; # Statistics for that file 117 $bgSD += ($stats->{bg} - $bgMean)**2; 118 } 119 $bgSD = sqrt($bgSD / (scalar(keys %$filenames) - 1)); 120 121 $command .= " " . EXP_BGMEAN() . " $bgMean " . EXP_BGSD() . " $bgSD " . EXP_BGSDMEAN() . " $bgsdMean"; 122 123 print "$command"; 124 125 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 126 run(command => $command, verbose => 0); 127 die "Unable to run phase0 update for $expid: $error_code\n" if not $success; 128 74 129 75 130 ### Pau. 131 132 133 # Parse a metadata containing a list of files; return a hash keyed by the URI, containing bg and sd 134 sub mdFileInfo 135 { 136 my $mdItemArray = shift; # Array of metadata items from "p0search -pendingimfile" 137 138 my %uriHash; # Hash of URIs to return 139 IMFILE: foreach my $mdItem (@$mdItemArray) { 140 die "Unexpected format for filenames: does not consist solely of METADATAs.\n" 141 if $mdItem->{class} ne "metadata"; 142 my %imfileInfo = values2hash($mdItem->{value}); # File information 143 die "Unexpected format for filenames: METADATAs do not contain " . IMFILE_URI . " element.\n" 144 if not defined $imfileInfo{IMFILE_URI}; 145 die "Unexpected format for filenames: METADATAs do not contain " . IMFILE_BG . " element.\n" 146 if not defined $imfileInfo{IMFILE_BG}; 147 die "Unexpected format for filenames: METADATAs do not contain " . IMFILE_BGSD . " element.\n" 148 if not defined $imfileInfo{IMFILE_BGSD}; 149 $uriHash{$imfileInfo{IMFILE_URI}} = { 'bg' => $imfileInfo{IMFILE_BG}, 150 'bgsd' => $imfileInfo{IMFILE_BGSD} 151 }; 152 } 153 154 return \%uriHash; 155 } 156 76 157 77 158 # Parse a metadata, looking for the appropriate values … … 89 170 90 171 return if not defined $mdItem->{name}; 172 173 if ($mdItem->{name} eq TYPE) { 174 foreach my $type (DETRENDS) { 175 if (lc($mdItem->{value}) eq lc($type)) { 176 $values->{TYPE} = 1; 177 next MDITEM; 178 } 179 } 180 # If we got here, it's not a detrend 181 $values->{TYPE} = 0; 182 next MDITEM; 183 } 91 184 92 foreach my $constant ( CONSTANTS) {185 foreach my $constant (keys %{CONSTANTS()}) { 93 186 if ($mdItem->{name} eq $constant) { 94 187 if (defined $values->{$constant} and $mdItem->{value} ne $values->{$constant}) { … … 100 193 } 101 194 102 foreach my $variable ( VARIABLES) {195 foreach my $variable (keys %{VARIABLES()}) { 103 196 if ($mdItem->{name} eq $variable) { 104 197 $values->{$variable}->{value} += $mdItem->{value}; … … 109 202 } 110 203 } 204 205 206 # Convert values to a hash 207 sub values2hash 208 { 209 my $values = shift; 210 211 my %hash; 212 foreach my $data (@$values) { 213 $hash{$data->{name}} = $data->{value}; 214 } 215 216 return \%hash; 217 }
Note:
See TracChangeset
for help on using the changeset viewer.
