Changeset 14021
- Timestamp:
- Jul 5, 2007, 1:32:33 PM (19 years ago)
- Location:
- trunk/ippScripts/scripts
- Files:
-
- 3 edited
-
ipp_serial_inject.pl (modified) (7 diffs)
-
register_exp.pl (modified) (8 diffs)
-
register_imfile.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/ipp_serial_inject.pl
r13751 r14021 1 1 #!/usr/bin/env perl 2 2 3 # this program injects a list of single-file exposures into the db, taking the 4 # filename (without .fits) as the exp_tag. 3 # this program injects a list of single-file exposures into the db, 4 # taking the filename (without .fits) as the exp_tag. the user 5 # supplies a temporary telescope and instrument name. these are used 6 # for informational purposes only until the registration step can 7 # determine the true telescope and instrument name from the image 8 # headers. 9 10 # this program should not fail because of the data format or the 11 # configuration, except for the very basic database setup. 5 12 6 13 use warnings; … … 8 15 9 16 use IPC::Cmd 0.36 qw( can_run run ); 10 use PS::IPP::Metadata::Config;11 use PS::IPP::Metadata::List qw( parse_md_list );12 17 use File::Spec; 13 # use File::Find::Rule;14 18 use PS::IPP::Config; 15 my $ipprc = PS::IPP::Config->new(); 16 my $ mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files19 20 my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions 17 21 18 22 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); … … 20 24 21 25 # Parse the command-line arguments 22 my ($workdir, $dbname );26 my ($workdir, $dbname, $telescope, $instrument, $help); 23 27 GetOptions( 24 'workdir|w=s' => \$workdir, # working directory for output files 25 'dbname|d=s' => \$dbname # Database name 28 'workdir|w=s' => \$workdir, # working directory for output files 29 'dbname|d=s' => \$dbname, # Database name 30 'telescope|t=s' => \$telescope, # user-supplied telescope name 31 'instrument|i=s' => \$instrument, # user-supplied instrument name 32 'help' => \$help # give help listing 26 33 ) or pod2usage( 2 ); 27 34 28 pod2usage( -msg => "Usage: $0 [--workdir path] [--dbname dbname] (files)", -exitval => 2 ) if scalar @ARGV == 0; 35 pod2usage( -msg => "inject one or many files into the IPP pipeline database", -exitval => 2 36 37 pod2usage( -msg => "Usage: $0 --telescope (name) --instrument (name) [--workdir path] [--dbname dbname] (files)", 38 -exitval => 2 ) if 39 scalar @ARGV == 0; 40 41 pod2usage( -msg => "Required options: --telescope (name) --instrument (name)", 42 -exitval => 3) unless 43 defined $telescope and 44 defined $instrument; 29 45 30 46 my $pxinject = can_run('pxinject') or die "Can't find pxinject\n"; 31 my $ppStats = can_run('ppStats') or die "Can't find ppStats\n";32 47 33 48 # if workdir is not defined, assign the current path … … 40 55 foreach my $file ( @ARGV ) { 41 56 my $absfile = File::Spec->rel2abs( $file ); 42 inject($absfile, $workdir, $dbname );57 inject($absfile, $workdir, $dbname, $telescope, $instrument); 43 58 $num ++; 44 59 } … … 48 63 sub inject 49 64 { 50 my $absfile = shift; # absolute path for this file 51 my $workdir = shift; # absolute path for output directory 52 my $dbname = shift; 65 my $absfile = shift; # absolute path for this file 66 my $workdir = shift; # absolute path for output directory 67 my $dbname = shift; # IPP database to use 68 my $telescope = shift; # user-specified telescope 69 my $instrument = shift; # user-specified instrument 53 70 54 71 my ( $vol, $path, $name ) = File::Spec->splitpath( $absfile ); 55 my ( $exp ) = $name =~ /(.*)\.fits/;72 my ( $exp_name ) = $name =~ /(.*)\.fits/; 56 73 57 74 my $relfile = $ipprc->convert_filename_relative( $absfile ); 58 75 59 my $command_type = "$ppStats -recipe PPSTATS INJECT $absfile"; 60 61 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command_type, verbose => 1); 62 die "Unable to perform ppStats: $error_code\n" if not $success; 63 my $metadata = $mdcParser->parse(join "", @$stdout_buf) 64 or die "unable to parse metadata config doc"; 65 66 my $type; 67 my $telescope; 68 my $instrument; 69 foreach my $row (@$metadata) { 70 if ($row->{name} eq "FPA.TELESCOPE") { $telescope = $row->{value}; } 71 if ($row->{name} eq "FPA.INSTRUMENT") { $instrument = $row->{value}; } # this entry must return the camera in the ipp/config system which we load 72 } 73 74 my $command_exp = "$pxinject -newExp -exp_id $exp -inst $instrument -telescope $telescope -imfiles 1 -workdir $workdir" ; # Command to run 76 my $command_exp = "$pxinject -newExp -exp_name $exp_name -inst $instrument -telescope $telescope -imfiles 1 -workdir $workdir" ; # Command to run 75 77 if ($dbname) { 76 78 $command_exp = "$command_exp -dbname $dbname"; … … 79 81 my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) = 80 82 run( command => $command_exp, verbose => 1 ); 81 die "Unable to inject $exp : $error_code_exp\n" if not $success_exp;83 die "Unable to inject $exp_name: $error_code_exp\n" if not $success_exp; 82 84 83 85 my @line = split(/\s+/, $$stdout_buf_exp[0]); # The output line, containing the exposure tag 84 my $exp_ tag= $line[2]; # The exposure tag86 my $exp_id = $line[2]; # The exposure tag 85 87 86 my $command_imfile = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -uri $relfile"; # Command to run 88 # XXX the class_id used here should be temporary : register should replace it with the true class_id 89 my $command_imfile = "$pxinject -newImfile -exp_id $exp_id -exp_name $exp_name -class fpa -class_id fpa -uri $relfile"; # Command to run 87 90 if ($dbname) { 88 91 $command_imfile = "$command_imfile -dbname $dbname"; … … 90 93 91 94 my ( $success_imfile, $error_code_imfile, $full_buf_imfile, $stdout_buf_imfile, $stderr_buf_imfile ) = run( command => $command_imfile, verbose => 1 ); 92 die "Unable to inject $exp imfile: $error_code_imfile\n" if not $success_imfile;95 die "Unable to inject $exp_name imfile: $error_code_imfile\n" if not $success_imfile; 93 96 94 97 return 1; -
trunk/ippScripts/scripts/register_exp.pl
r13785 r14021 1 1 #!/usr/bin/env perl 2 2 3 use Carp; 3 4 use warnings; 4 5 use strict; … … 9 10 print "\n\n"; 10 11 print "Starting script $0 on $host\n\n"; 12 13 use vars qw( $VERSION ); 14 $VERSION = '0.01'; 11 15 12 16 use Cache::File; … … 31 35 ); 32 36 33 my ($cache, $exp_tag, $workdir, $dbname, $no_update, $no_op); 34 37 my ($cache, $exp_id, $exp_tag, $workdir, $dbname, $no_update, $no_op); 35 38 GetOptions( 36 39 'caches' => \$cache, 37 'exp_tag|e=s' => \$exp_tag, 40 'exp_id|e=s' => \$exp_id, 41 'exp_tag|t=s' => \$exp_tag, 38 42 'workdir|w=s' => \$workdir, # Working directory for output files 39 43 'dbname|d=s' => \$dbname, # Database name … … 43 47 44 48 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 45 pod2usage( 46 -msg => "Required options: --exp_tag", 47 -exitval => 3, 48 ) unless defined $exp_tag; 49 50 # Define setup 51 use constant TYPE => "exp_type"; # Observation type keyword 52 53 # should we reverse this? add -detrend UNLESS type is OBJECT? (we can always queue to chip by hand...) 54 # use constant DETRENDS => [ "bias", "zero", "dark", "shutter", "flat", "fringe", "domeflat", "skyflat" ]; # Observation types to mark as detrend 55 # use constant DETREND_FLAG => "-detrend"; # Flag to use to mark detrend exposure 56 57 use constant SCIENCE => [ "object" ]; # Observation types to NOT mark as detrend 58 use constant DETREND_FLAG => "-detrend"; # Flag to use to mark detrend exposure 59 60 use constant REGISTER_URI => 'uri'; # Key for the URI 61 use constant REGISTER_CLASSID => 'class_id'; # Key for the class id 62 use constant REGISTER_BG => 'bg'; # Key for the background 63 use constant REGISTER_BG_STDEV => 'bg_stdev'; # Key for the background standard deviation 64 use constant REGISTER_BG_MEAN_STDEV => 'bg_mean_stdev'; # Key for the mean of the background standard deviation 65 66 # These values should be constant for all components 67 use constant CONSTANTS => [ 68 "filelevel", # File level 69 "object", # Object 70 "exp_type", # Exposure type 71 "filter", # Filter used 72 "dateobs", # Time of exposure 73 ]; 74 75 # These values may vary across components; we will take the average 76 use constant VARIABLES => [ 77 "ccd_temp", # CCD temperature 78 "exp_time", # Exposure time 79 "sat_pixel_frac", # Fraction of saturated pixels 80 "airmass", # Airmass 81 "ra", # Right ascension 82 "decl", # Declination 83 "posang", # Position angle 84 "alt", # Altitude 85 "az", # Azimuth 86 ]; 87 49 pod2usage( -msg => "Required options: --exp_id --exp_tag", 50 -exitval => 3) unless 51 defined $exp_id and 52 defined $exp_tag; 53 54 # add -detrend UNLESS type is one of SCIENCE listed below (eg, OBJECT) 55 my @SCIENCE = ( "object" ); # Observation types to NOT mark as detrend 56 my $DETREND_FLAG = "-detrend"; # Flag to use to mark detrend exposure 57 58 # values to extract from output metadata and the stats to calculate 59 my $STATS = 60 [ 61 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 62 { name => "exp_name", type => "constant", flag => "-exp_name" }, # File level 63 { name => "telescope", type => "constant", flag => "-telescope" }, # File level 64 { name => "inst", type => "constant", flag => "-inst" }, # File level 65 { name => "filelevel", type => "constant", flag => "-filelevel" }, # File level 66 { name => "object", type => "constant", flag => "-object" }, 67 { name => "exp_type", type => "constant", flag => "-exp_type" }, # File level 68 { name => "filter", type => "constant", flag => "-filter" }, # File level 69 { name => "dateobs", type => "constant", flag => "-dateobs" }, # File level 70 { name => "ccd_temp", type => "mean", flag => "-ccd_temp" }, # CCD temperature 71 { name => "exp_time", type => "mean", flag => "-exp_time" }, # Exposure time 72 { name => "sat_pixel_frac", type => "mean", flag => "-sat_pixel_frac" }, # Fraction of saturated pixels 73 { name => "airmass", type => "mean", flag => "-airmass" }, # Airmass 74 { name => "ra", type => "mean", flag => "-ra" }, # Right ascension 75 { name => "decl", type => "mean", flag => "-decl" }, # Declination 76 { name => "posang", type => "mean", flag => "-posang" }, # Position angle 77 { name => "alt", type => "mean", flag => "-alt" }, # Altitude 78 { name => "az", type => "mean", flag => "-az" }, # Azimuth 79 { name => "bg", type => "mean", flag => "-bg" }, # Azimuth 80 { name => "bg", type => "stdev", flag => "-bg_mean_stdev" }, # Azimuth 81 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, # Azimuth 82 ]; 88 83 89 84 # Look for commands we need … … 98 93 99 94 # setup cache interface 100 101 95 my $c = Cache::File->new( 102 96 cache_root => File::Spec->catdir($ENV{'HOME'}, '.pxtools', basename($0)), … … 104 98 ); 105 99 106 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 107 108 # Get the list of imfiles 109 my $imfiles; 110 { 111 my $command = "$regtool -processedimfile -exp_tag $exp_tag"; 100 # Get the list of imfiles & their stats 101 { 102 my $command = "$regtool -processedimfile -exp_id $exp_id"; 112 103 $command .= " -dbname $dbname" if defined $dbname; 113 104 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 115 106 unless ($success) { 116 107 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 117 warn ("Unable to perform regtool -processedimfile on exposure id $exp_ tag: $error_code");108 warn ("Unable to perform regtool -processedimfile on exposure id $exp_id: $error_code"); 118 109 exit ($error_code); 119 110 } 120 111 112 # Parse the output 113 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 121 114 my $metadata = $mdcParser->parse(join "", @$stdout_buf); 122 115 unless ($metadata) { 123 warn ("Unable to parse metadata config doc"); 124 &my_die ($exp_tag, $PS_EXIT_PROG_ERROR); 125 } 126 $imfiles = parse_md_list($metadata); # Data for imfiles 127 } 128 129 # Process the values 130 my %values; # Values to update 131 foreach my $variable (@{VARIABLES()}) { 132 $values{$variable} = []; 133 } 134 my @backgrounds; # Array of backgrounds 135 my @variances; # Array of background standard deviations\ 136 my $obsType; # Observation type 137 138 foreach my $imfile (@$imfiles) { 139 foreach my $constant (@{CONSTANTS()}) { 140 my $value = get_value($imfile, $constant); # Value for imfile 141 if (not defined $values{$constant}) { 142 $values{$constant} = $value; 143 } 144 if ($values{$constant} ne $value) { 145 warn ("Value of $constant for " . $imfile->{REGISTER_CLASSID()} . 146 " doesn't match previous value"); 147 &my_die($exp_tag, $PS_EXIT_PROG_ERROR); 148 } 149 } 150 151 foreach my $variable (@{VARIABLES()}) { 152 my $value = get_value($imfile, $variable); # Value for imfile 153 my $array = $values{$variable}; # Array of data 154 push @$array, $value; 155 } 156 157 my $bg = get_value($imfile, REGISTER_BG()); 158 push @backgrounds, $bg; 159 160 my $stdev = get_value($imfile, REGISTER_BG_MEAN_STDEV()); 161 push @variances, $stdev**2; 162 } 163 164 if (0) { 165 # XXX for a test, randomly declare a failure and return to pantasks 166 my $rnd = rand(1); 167 if ($rnd > 0.5) { 168 warn ("random failure"); 169 &my_die ($exp_tag, $PS_EXIT_DATA_ERROR); 170 } 116 &my_die ("Unable to parse metadata config doc", $exp_id, $PS_EXIT_PROG_ERROR); 117 } 118 119 # extract the stats from the metadata 120 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 121 unless ($stats->parse($metadata)) { 122 &my_die ("Unable to find all values", $exp_id, $class_id, $PS_EXIT_CONFIG_ERROR); 123 } 124 } 125 126 my $command = "$regtool -addprocessedexp"; 127 $command .= " -exp_id $exp_id"; 128 $command .= " -exp_tag $exp_tag"; 129 $command .= " -dbname $dbname" if defined $dbname; 130 131 # add in the elements from the selected stats above 132 foreach my $entry (@$STATS) { 133 my $value = $entry->{value}; 134 my $flag = $entry->{flag}; 135 $command .= " $flag $value"; 136 } 137 138 my $exp_type = &STATS_value_for_flag ("-exp_type"); 139 140 # Add the detrend flag, if needed 141 foreach my $scienceType (@SCIENCE) { 142 if (lc($exp_type) =~ /$scienceType/) { 143 last; 144 } 145 $command .= " $DETREND_FLAG"; 171 146 } 172 147 173 148 # Output results to the database 174 149 unless ($no_update) { 175 my $command = "$regtool -addprocessedexp -exp_tag $exp_tag"; # Command to execute176 177 # Add the values of interest178 foreach my $constant (@{CONSTANTS()}) {179 my $value = $values{$constant};180 if ($value =~ /\s/) {181 # Quote spaces182 $value = "\'$value\'";183 }184 $command .= " -$constant $value";185 }186 foreach my $variable (@{VARIABLES()}) {187 my $array = $values{$variable}; # Array of values188 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator189 $stats->add_data(@$array);190 191 $command .= " -$variable " . $stats->mean();192 }193 194 # Add the statistics195 my $meanStats = Statistics::Descriptive::Sparse->new; # Statistics calculator196 $meanStats->add_data(@backgrounds);197 my $stdevStats = Statistics::Descriptive::Sparse->new; # Statistics calculator198 $stdevStats->add_data(@variances);199 my $bg = ($meanStats->mean() or 'NAN');200 my $bg_stdev = (sqrt($stdevStats->mean()) or 'NAN');201 my $bg_mean_stdev = ($meanStats->standard_deviation() or 'NAN');202 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";203 204 # Add the detrend flag205 foreach my $scienceType (@{SCIENCE()}) {206 if (lc($values{TYPE()}) =~ /$scienceType/) {207 last;208 }209 $command .= ' ' . DETREND_FLAG;210 }211 212 $command .= " -dbname $dbname" if defined $dbname;213 214 150 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 215 151 cache_run(command => $command, verbose => 1); 216 152 unless ($success) { 217 153 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 218 warn ("Unable to run regtool -addprocessedexp for $exp_ tag: $error_code");154 warn ("Unable to run regtool -addprocessedexp for $exp_id: $error_code"); 219 155 exit($error_code); 220 156 } 157 } else { 158 print "skipping command: $command\n"; 221 159 } 222 160 223 161 ### Pau. 224 225 # Get the value for a particular imfile, along with a strong check for its existence226 sub get_value {227 my $imfile = shift; # The hash of values228 my $name = shift; # The name of the value to check229 230 my $source = $imfile->{REGISTER_CLASSID()}; # Where it comes from231 232 unless (defined $imfile->{$name}) {233 warn ("Couldn't find value of $name for class_id=$source");234 &my_die ($exp_tag, $PS_EXIT_PROG_ERROR);235 }236 return $imfile->{$name};237 }238 162 239 163 sub cache_run … … 253 177 sub my_die 254 178 { 255 my $exp_tag = $_[0]; 256 my $exit_code = $_[1]; 257 if ($exp_tag and not $no_update) { 258 my $command = "$regtool -addprocessedexp -exp_tag $exp_tag -code $exit_code"; 179 my $msg = shift; # Warning message on die 180 my $exp_id = shift; 181 my $exit_code = shift; 182 183 carp($msg); 184 if ($exp_id and not $no_update) { 185 my $command = "$regtool -addprocessedexp -exp_id $exp_id -code $exit_code"; 259 186 $command .= " -dbname $dbname" if defined $dbname; 260 187 ### system($command); 261 188 } 262 189 exit $exit_code; 190 } 191 192 sub STATS_value_for_flag 193 { 194 my $STATS = shift; 195 my $flag = shift; 196 197 foreach my $entry (@$STATS) { 198 if ($flag eq $entry->{flag}) { 199 return $entry->{value}; 200 } 201 } 202 return 'NAN'; 263 203 } 264 204 -
trunk/ippScripts/scripts/register_imfile.pl
r14009 r14021 1 1 #!/usr/bin/env perl 2 2 3 use Carp; 3 4 use warnings; 4 5 use strict; … … 37 38 use Pod::Usage qw( pod2usage ); 38 39 39 my ($cache, $exp_tag, $class_id, $uri, $workdir, $dbname, $no_update, $no_op); 40 40 my ($cache, $exp_id, $class_id, $exp_name, $uri, $workdir, $dbname, $no_update, $no_op); 41 41 GetOptions( 42 42 'caches' => \$cache, 43 'exp_ tag|e=s' => \$exp_tag,43 'exp_id|e=s' => \$exp_id, 44 44 'class_id|i=s' => \$class_id, 45 'exp_name|n=s' => \$exp_name, 45 46 'uri|u=s' => \$uri, 46 47 'workdir|w=s' => \$workdir, # Working directory for output files … … 51 52 52 53 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 53 pod2usage( 54 -msg => "Required options: --exp_tag --class_id --uri", 55 -exitval => 3,56 ) unless defined $exp_tag 57 and defined $class_id58 anddefined $uri;54 pod2usage( -msg => "Required options: --exp_id --class_id --exp_name --uri", 55 -exitval => 3) unless 56 defined $exp_id and 57 defined $class_id and 58 defined $exp_name and 59 defined $uri; 59 60 60 61 my $RECIPE = "REGISTER"; # Recipe to use for ppStats 61 62 62 # These values should be constant for all components 63 # The key is the name in the ppStats output; the value is the switch for "phase0 -updateexp" 64 use constant CONSTANTS => { 65 "FILE.LEVEL" => "-filelevel", # File level 66 "FPA.OBJECT" => "-object", # Object 67 "FPA.OBSTYPE" => "-exp_type", # Exposure type 68 "FPA.FILTER" => "-filter", # Filter used 69 "FPA.AIRMASS" => "-airmass", # Airmass 70 "FPA.RA" => "-ra", # Right ascension 71 "FPA.DEC" => "-decl", # Declination 72 "FPA.ALT" => "-alt", # Altitude 73 "FPA.AZ" => "-az", # Azimuth 74 "FPA.POSANGLE" => "-posang", # Position angle 75 "FPA.TIME" => "-dateobs", # Date of observation (UTC) 76 }; 77 78 # These values may vary across components; we will take the average 79 # The key is the name in the ppStats output; the value is the switch for "phase0 -updateexp" 80 use constant VARIABLES => { 81 "CHIP.TEMP" => "-ccd_temp", # CCD temperature 82 "CELL.EXPOSURE" => "-exp_time", # Exposure time 83 "SAT_PIXEL_FRAC" => "-sat_pixel_frac" # fraction of saturated pixels 84 }; 85 63 # values to extract from output metadata and the stats to calculate 64 my $STATS = 65 [ 66 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 67 { name => "FILE.LEVEL", type => "constant", flag => "-filelevel" }, # File level 68 { name => "CLASS.ID", type => "constant", flag => "-class_id" }, # Real Class ID 69 { name => "FPA.OBJECT", type => "constant", flag => "-object" }, # Object 70 { name => "FPA.OBSTYPE", type => "constant", flag => "-exp_type" }, # Exposure type 71 { name => "FPA.FILTER", type => "constant", flag => "-filter" }, # Filter used 72 { name => "FPA.AIRMASS", type => "constant", flag => "-airmass" }, # Airmass 73 { name => "FPA.RA", type => "constant", flag => "-ra" }, # Right ascension 74 { name => "FPA.DEC", type => "constant", flag => "-decl" }, # Declination 75 { name => "FPA.ALT", type => "constant", flag => "-alt" }, # Altitude 76 { name => "FPA.AZ", type => "constant", flag => "-az" }, # Azimuth 77 { name => "FPA.POSANGLE", type => "constant", flag => "-posang" }, # Position angle 78 { name => "FPA.TIME", type => "constant", flag => "-dateobs" }, # Date of observation (UTC) 79 { name => "FPA.TELESCOPE", type => "constant", flag => "-telescope" }, # Telescope 80 { name => "FPA.INSTRUMENT", type => "constant", flag => "-inst" }, # Instrument 81 { name => "CHIP.TEMP" type => "mean", flag => "-ccd_temp" }, # CCD temperature 82 { name => "CELL.EXPOSURE" type => "mean", flag => "-exp_time" }, # Exposure time 83 { name => "SAT_PIXEL_FRAC" type => "mean", flag => "-sat_pixel_frac" } # fraction of saturated pixels 84 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg" }, 85 { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev" }, 86 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev" }, 87 ]; 86 88 87 89 # Look for programs we need … … 105 107 106 108 # Run ppStats on the input file 107 my $stats;108 109 { 110 # extract the data from the image header; -level is used to get FILE.LEVEL and CLASS.ID 109 111 my $command = "$ppStats $uri -recipe PPSTATS $RECIPE -level"; # Command to run ppStats 110 112 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 112 114 unless ($success) { 113 115 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 114 warn ("Unable to perform ppStats on exposure id $exp_tag: $error_code"); 115 &my_die ($exp_tag, $class_id, $error_code); 116 &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $class_id, $error_code); 116 117 } 117 118 … … 120 121 my $metadata = $mdcParser->parse(join "", @$stdout_buf); # XXX is this join necessary? 121 122 unless ($metadata) { 122 warn ("Unable to parse metadata config doc"); 123 &my_die ($exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 123 &my_die ("Unable to parse metadata config doc", $exp_id, $class_id, $PS_EXIT_PROG_ERROR); 124 124 } 125 my @constants = keys %{CONSTANTS()}; # List of constants to parse out126 my @variables = keys %{VARIABLES()}; # List of variables to parse out127 125 128 $stats = PS::IPP::Metadata::Stats->new(\@constants, \@variables); # Stats parser 126 # extract the stats from the metadata 127 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 129 128 unless ($stats->parse($metadata)) { 130 warn ("Unable to find all values"); 131 &my_die ($exp_tag, $class_id, $PS_EXIT_CONFIG_ERROR); 129 &my_die ("Unable to find all values", $exp_id, $class_id, $PS_EXIT_CONFIG_ERROR); 132 130 } 131 } 132 133 my $command = "$regtool -addprocessedimfile"; 134 $command .= " -exp_id $exp_id"; 135 $command .= " -temp_class_id $class_id"; # the original class_id supplied by the user, replace by ppStats CLASS.ID 136 $command .= " -exp_name $exp_name"; # keep the supplied exp_name (could be derived from the file) 137 $command .= " -dbname $dbname" if defined $dbname; 138 139 # add in the elements from the selected stats above 140 foreach my $entry (@$STATS) { 141 my $value = $entry->{value}; 142 my $flag = $entry->{flag}; 143 $command .= " $flag $value"; 133 144 } 134 145 135 146 # Push the results into the database 136 147 unless ($no_update) { 137 my $command = "$regtool -addprocessedimfile -exp_tag $exp_tag -class_id $class_id"; # Command to run regtool138 139 foreach my $constant (keys %{CONSTANTS()}) {140 my $value = ($stats->data($constant))->{value};141 if ($value =~ /\s/) {142 # Quote arguments with whitespace143 $value = "\'$value\'";144 }145 $command .= ' ' . CONSTANTS->{$constant} . ' ' . $value;146 }147 148 foreach my $variable (keys %{VARIABLES()}) {149 # Just use the mean value150 $command .= ' ' . VARIABLES->{$variable} . ' ' . ($stats->data($variable))->{mean};151 }152 153 my $bg = $stats->bg_mean();154 my $bg_stdev = $stats->bg_stdev();155 my $bg_mean_stdev = $stats->bg_mean_stdev();156 157 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";158 $command .= " -dbname $dbname" if defined $dbname;159 160 148 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 161 149 run(command => $command, verbose => 1); 162 163 150 unless ($success) { 164 151 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 165 # If we can't run -addprocessedimfile, we can't actually set the error code. If this is not166 # a database error, it is probably a programming error (in regtool or the passed args)167 152 warn ("Unable to perform regtool -addprocessedimfile: $error_code"); 168 153 exit($error_code); … … 186 171 sub my_die 187 172 { 188 my $exp_tag = $_[0]; 189 my $class_id = $_[1]; 190 my $exit_code = $_[2]; 191 if ($exp_tag && $class_id and not $no_update) { 192 my $command = "$regtool -addprocessedimfile -exp_tag $exp_tag -class_id $class_id -code $exit_code"; 173 my $msg = shift; # Warning message on die 174 my $exp_id = shift; 175 my $class_id = shift; 176 my $exit_code = shift; 177 178 carp($msg); 179 if ($exp_id && $class_id and not $no_update) { 180 my $command = "$regtool -addprocessedimfile"; 181 $command .= " -exp_id $exp_id"; 182 $command .= " -class_id $class_id"; 183 $command .= " -code $exit_code"; 193 184 $command .= " -dbname $dbname" if defined $dbname; 194 185 ### system ($command);
Note:
See TracChangeset
for help on using the changeset viewer.
