Changeset 9140 for trunk/ippScripts/scripts/detrend_norm_calc.pl
- Timestamp:
- Oct 2, 2006, 5:37:36 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/detrend_norm_calc.pl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_norm_calc.pl
r9121 r9140 17 17 my ($detId, # Detrend id 18 18 $iter, # Iteration 19 $detType, # Detrend type 19 20 $no_update # Don't update the database? 20 21 ); … … 22 23 'det_id|d=s' => \$detId, 23 24 'iteration|i=s' => \$iter, 25 'det_type|t=s' => \$detType, 24 26 'no-update' => \$no_update 25 27 ) or pod2usage( 2 ); 26 28 27 29 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 28 pod2usage( -msg => "Required options --det_id --iteration -- camera--det_type",30 pod2usage( -msg => "Required options --det_id --iteration --det_type --det_type", 29 31 -exitval => 3, 30 32 ) unless defined $detId 31 and defined $iter; 33 and defined $iter 34 and defined $detType; 32 35 33 36 34 37 use constant STATISTIC => 'bg'; # Background statistic to use from the database 38 # Define which detrend types we normalise 39 use constant NORMALIZE => { 40 'bias' => 0, 41 'dark' => 0, 42 'flat' => 1 43 }; 44 35 45 36 46 # Look for programs we need … … 39 49 my $ppNormCalc = can_run('ppNormCalc') or (warn "Can't find ppNormCalc" and $missing_tools = 1); 40 50 die "Can't find required tools.\n" if $missing_tools; 51 52 die "Unrecognised detrend type: $detType\n" unless exists NORMALIZE()->{lc($detType)}; 53 41 54 42 55 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files … … 59 72 } 60 73 61 my %matrix; # Matrix of statistics as a function of exposures and classes62 foreach my $file (@$files) {63 my $expTag = $file->{'exp_tag'}; # Exposure ID64 my $classId = $file->{'class_id'}; # Class ID65 my $stat = $file->{STATISTIC()}; # Statistic of interest66 74 67 # Create matrix elements 68 $matrix{$expTag} = {} if not defined $matrix{$expId}; 69 $matrix{$expTag}->{$classId} = $stat; 75 my $norms; # MDC with normalisations 76 if (NORMALIZE()->{lc($detType)}) { 77 78 my %matrix; # Matrix of statistics as a function of exposures and classes 79 foreach my $file (@$files) { 80 my $expTag = $file->{'exp_tag'}; # Exposure ID 81 my $classId = $file->{'class_id'}; # Class ID 82 my $stat = $file->{STATISTIC()}; # Statistic of interest 83 84 # Create matrix elements 85 $matrix{$expTag} = {} if not defined $matrix{$expTag}; 86 $matrix{$expTag}->{$classId} = $stat; 87 } 88 89 # Generate the input for ppNormCalc 90 my $normData; # Normalisation data 91 foreach my $expTag (keys %matrix) { 92 $normData .= "$expTag\tMETADATA\n"; 93 foreach my $classId (keys %{$matrix{$expTag}}) { 94 $normData .= "\t" . $classId . "\tF32\t" . $matrix{$expTag}->{$classId} . "\n"; 95 } 96 $normData .= "END\n\n"; 97 } 98 99 # Run ppNormCalc 100 { 101 my ( $stdout, $stderr ); # Buffers for running program 102 my @command = split /\s+/, $ppNormCalc; 103 print "Running [$ppNormCalc]...\n"; 104 run \@command, \$normData, \$stdout, \$stderr or 105 die "Unable to perform ppNormCalc: $?"; 106 print $stdout . "\n"; 107 108 # Parse the output 109 $norms = $mdcParser->parse($stdout) 110 or die "unable to parse metadata config doc"; 111 } 112 113 } else { 114 # It's something that doesn't need normalisation --- just push in a normalisation of 1 115 my %classes; # List of unique classes 116 foreach my $file (@$files) { 117 my $classId = $file->{'class_id'}; # Class Id 118 $classes{$classId} = 1; 119 } 120 121 foreach my $classId (keys %classes) { 122 my %mdValue; # Metadata value for this class id 123 $mdValue{name} = $classId; 124 $mdValue{value} = 1.0; 125 push @$norms, \%mdValue; 126 } 70 127 } 71 128 72 # Generate the input for ppNormCalc73 my $normData; # Normalisation data74 foreach my $expTag (keys %matrix) {75 $normData .= "$expTag\tMETADATA\n";76 foreach my $classId (keys %{$matrix{$expTag}}) {77 $normData .= "\t" . $classId . "\tF32\t" . $matrix{$expTag}->{$classId} . "\n";78 }79 $normData .= "END\n\n";80 }81 82 # Run ppNormCalc83 my $norms;84 {85 my ( $stdout, $stderr ); # Buffers for running program86 my @command = split /\s+/, $ppNormCalc;87 print "Running [$ppNormCalc]...\n";88 run \@command, \$normData, \$stdout, \$stderr or89 die "Unable to perform ppNormCalc: $?";90 print $stdout . "\n";91 92 # Parse the output93 $norms = $mdcParser->parse($stdout)94 or die "unable to parse metadata config doc";95 }96 129 97 130 # Process output normalisations
Note:
See TracChangeset
for help on using the changeset viewer.
