IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 2, 2006, 5:37:36 PM (20 years ago)
Author:
Paul Price
Message:

For bias and dark, don't do the normalisation calculation, but push in 1 for each exposure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/detrend_norm_calc.pl

    r9121 r9140  
    1717my ($detId,                     # Detrend id
    1818    $iter,                      # Iteration
     19    $detType,                   # Detrend type
    1920    $no_update                  # Don't update the database?
    2021    );
     
    2223        'det_id|d=s'    => \$detId,
    2324        'iteration|i=s' => \$iter,
     25        'det_type|t=s'  => \$detType,
    2426        'no-update'     => \$no_update
    2527        ) or pod2usage( 2 );
    2628
    2729pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    28 pod2usage( -msg => "Required options --det_id --iteration --camera --det_type",
     30pod2usage( -msg => "Required options --det_id --iteration --det_type --det_type",
    2931           -exitval => 3,
    3032           ) unless defined $detId
    31     and defined $iter;
     33    and defined $iter
     34    and defined $detType;
    3235
    3336
    3437use constant STATISTIC => 'bg'; # Background statistic to use from the database
     38# Define which detrend types we normalise
     39use constant NORMALIZE => {
     40    'bias' => 0,
     41    'dark' => 0,
     42    'flat' => 1
     43    };
     44
    3545
    3646# Look for programs we need
     
    3949my $ppNormCalc = can_run('ppNormCalc') or (warn "Can't find ppNormCalc" and $missing_tools = 1);
    4050die "Can't find required tools.\n" if $missing_tools;
     51
     52die "Unrecognised detrend type: $detType\n" unless exists NORMALIZE()->{lc($detType)};
     53
    4154
    4255my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    5972}
    6073
    61 my %matrix; # Matrix of statistics as a function of exposures and classes
    62 foreach my $file (@$files) {
    63     my $expTag = $file->{'exp_tag'}; # Exposure ID
    64     my $classId = $file->{'class_id'}; # Class ID
    65     my $stat = $file->{STATISTIC()}; # Statistic of interest
    6674
    67     # Create matrix elements
    68     $matrix{$expTag} = {} if not defined $matrix{$expId};
    69     $matrix{$expTag}->{$classId} = $stat;
     75my $norms;                      # MDC with normalisations
     76if (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    }
    70127}
    71128
    72 # Generate the input for ppNormCalc
    73 my $normData;                   # Normalisation data
    74 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 ppNormCalc
    83 my $norms;
    84 {
    85     my ( $stdout, $stderr ); # Buffers for running program
    86     my @command = split /\s+/, $ppNormCalc;
    87     print "Running [$ppNormCalc]...\n";
    88     run \@command, \$normData, \$stdout, \$stderr or
    89         die "Unable to perform ppNormCalc: $?";
    90     print $stdout . "\n";
    91 
    92     # Parse the output
    93     $norms = $mdcParser->parse($stdout)
    94         or die "unable to parse metadata config doc";
    95 }
    96129
    97130# Process output normalisations
Note: See TracChangeset for help on using the changeset viewer.