IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23209


Ignore:
Timestamp:
Mar 6, 2009, 11:22:53 AM (17 years ago)
Author:
eugene
Message:

modify the detrend sequence to generate the detResidImfiles before generating the detNormalizedStat and supply a per-imfile normalization

Location:
branches/eam_branches/eam_branch_20090303/ippScripts/scripts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/eam_branch_20090303/ippScripts/scripts/detrend_norm_apply.pl

    r22430 r23209  
    4040    'iteration|n=s'     => \$iter,       # Iteration
    4141    'class_id|i=s'      => \$class_id,   # Class ID
    42     'value|v=s'         => \$value,      # Value to multiple (for normalisation)
     42    'value|v=s'         => \$value,      # Value to apply (for normalisation)
    4343    'input_uri|u=s'     => \$input_uri,  # Input file
    4444    'camera|c=s'        => \$camera,     # Camera
  • branches/eam_branches/eam_branch_20090303/ippScripts/scripts/detrend_norm_calc.pl

    r22430 r23209  
    9595my @files;                      # The input files
    9696{
    97     my $command = "$dettool -processedimfile";
    98     $command .= " -det_id $det_id"; # Command to run
     97    my $command = "$dettool -residimfile";
     98    $command .= " -det_id $det_id";
     99    $command .= " -iteration $iter";
    99100    $command .= " -included"; # only use the inputs for this detrend run to calculate the norm
    100101    $command .= " -dbname $dbname" if defined $dbname;
     
    103104    print "Running [$command]...\n" if $verbose;
    104105    if (not run(\@command, \$stdin, \$stdout, \$stderr)) {
    105         &my_die("Unable to perform dettool -processedimfile on detrend $det_id/$iter: $?",
     106        &my_die("Unable to perform dettool -residimfile on detrend $det_id/$iter: $?",
    106107                $det_id, $iter, $PS_EXIT_SYS_ERROR);
    107108    }
  • branches/eam_branches/eam_branch_20090303/ippScripts/scripts/detrend_resid_exp.pl

    r22430 r23209  
    9696&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe;
    9797
     98# variables used for I/O
     99my ($command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
     100
     101# Get list of normalizations by class_id : stored as $norms; save to temp file for ppImage runs below
     102my (%norms, $normsName);
     103{
     104    # dettool command to select imfile data for this exp_id
     105    $command  = "$dettool -normalizedstat";
     106    $command .= " -det_id $det_id";
     107    $command .= " -iteration $iter";
     108    $command .= " -dbname $dbname" if defined $dbname;
     109    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     110        run(command => $command, verbose => $verbose);
     111    unless ($success) {
     112        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     113        warn("Unable to perform dettool -residimfile: $error_code\n");
     114        exit($error_code);
     115    }
     116    if (@$stdout_buf == 0) {
     117        &my_die("No normalizations were found", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     118    }
     119
     120    # Parse the stdout buffer into a metadata
     121    my $mdcParser = PS::IPP::Metadata::Config->new;
     122    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     123        &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
     124
     125    # parse the file info in the metadata
     126    my $normsMD = parse_md_list($metadata) or
     127        &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
     128
     129
     130    # write the normalizations to a file as a metadata config file in the form: class_id F32 value
     131    # XXX a possible optimization: if there is only one imfile, skip normalization
     132    my $normsFile;
     133    ($normsFile, $normsName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.norms.XXXX", UNLINK => !$save_temps );
     134    print "saving norms to $normsName\n";
     135    foreach my $norm (@$normsMD) {
     136        my $class_id = $norm->{class_id};
     137        my $normalization = $norm->{norm};
     138
     139        $norms{$class_id} = $normalization;
     140        printf $normsFile "$class_id F32 $normalization\n",
     141    }
     142    close $normsFile;
     143}
     144
    98145# Get list of imfile files
    99146my $cmdflags;
    100 my ($files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
     147my (@files);
    101148{
    102149    # dettool command to select imfile data for this exp_id
     
    113160        exit($error_code);
    114161    }
    115     # XXX report an error message if stdout_buf is empty
     162    if (@$stdout_buf == 0) {
     163        &my_die("No imfiles were found", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     164    }
    116165
    117166    # Parse the stdout buffer into a metadata
     
    120169        &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
    121170
     171    # since I can't figure out how to do input and output within PERL, I'm writing the (modified) metadata to a temp file
     172    my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.stats.XXXX", UNLINK => !$save_temps );
     173
    122174    # parse the file info in the metadata
    123     $files = parse_md_list($metadata) or
    124         &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
    125 
    126     # since I can't figure out how to do input and output within PERL, I'm writing to a temp file
    127     my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.stats.XXXX", UNLINK => !$save_temps );
    128     print "saving stats to $statName\n";
    129     foreach my $line (@$stdout_buf) {
    130         print $statFile $line;
     175    # as we parse the list of files and their stats, apply the normalization to the relevant fields
     176    # also, write out the modified metadata set
     177    foreach my $mdItem (@$metadata) {
     178        if ($mdItem->{class} ne "metadata") {
     179            carp "MD element ", $mdItem->{name}, " isn't of type METADATA --- ignored.\n";
     180            next;
     181        }
     182        my %hash;               # Hash element
     183        my $mdComponents = $mdItem->{value}; # Components of the metadata
     184
     185        # determine the class_id for this block:
     186        my $class_id;
     187        foreach my $data (@$mdComponents) {
     188            unless ($data->{name} eq "class_id") { next; }
     189            $class_id = $data->{value};
     190            last;
     191        }
     192
     193        # a new metadata block
     194        print $statFile "rawResidImfile  METADATA\n";
     195
     196        # modify and save the data in this block:
     197        foreach my $data (@$mdComponents) {
     198            my $norm = $norms{$class_id};
     199
     200            # fields to modify by the normalization:
     201            if ($data->{name} eq "bg")            { $data->{value} *= $norm; }
     202            if ($data->{name} eq "bg_stdev")      { $data->{value} *= $norm; }
     203            if ($data->{name} eq "bg_mean_stdev") { $data->{value} *= $norm; }
     204            if ($data->{name} eq "bg_skewness")   { $data->{value} *= $norm; }
     205            if ($data->{name} eq "bg_kurtosis")   { $data->{value} *= $norm; }
     206            if ($data->{name} eq "bin_stdev")     { $data->{value} *= $norm; }
     207
     208            # write out the metadata, save on the array of hashes
     209            print $statFile "  $data->{name}  $data->{type}  $data->{value}\n";
     210            $hash{$data->{name}} = $data->{value};
     211        }
     212        print $statFile "END\n";
     213        push @files, \%hash;
    131214    }
    132215    close $statFile;
     
    162245my ($list1File, $list1Name) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.b1.list.XXXX", UNLINK => !$save_temps );
    163246my ($list2File, $list2Name) = tempfile( "/tmp/$exp_tag.detresid.$det_id.$iter.b2.list.XXXX", UNLINK => !$save_temps );
    164 foreach my $file (@$files) {
     247foreach my $file (@files) {
    165248    print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n");
    166249    print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n");
     
    173256unless ($no_op) {
    174257    # Make the jpeg for binning 1
     258    # XXX EAM : supply the collection of normalizations as a metadata
    175259    $command = "$ppImage -list $list1Name $outroot"; # Command to run
    176260    $command .= " -recipe PPIMAGE PPIMAGE_J1";
    177261    $command .= " -recipe JPEG $recipe";
     262    $command .= " -normlist $normsName";
    178263    $command .= " -dbname $dbname" if defined $dbname;
    179264    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    186271
    187272    # Make the jpeg for binning 2
     273    # XXX EAM : supply the collection of normalizations as a metadata
    188274    $command = "$ppImage -list $list2Name $outroot"; # Command to run
    189275    $command .= " -recipe PPIMAGE PPIMAGE_J2";
    190276    $command .= " -recipe JPEG $recipe";
     277    $command .= " -normlist $normsName";
    191278    $command .= " -dbname $dbname" if defined $dbname;
    192279    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    223310my @fluxes;
    224311
    225 foreach my $file (@$files) {
     312foreach my $file (@files) {
    226313    my $name      = $file->{class_id};
    227314    my $mean      = $file->{bg};        # Mean for this imfile
Note: See TracChangeset for help on using the changeset viewer.