IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 6, 2007, 3:44:38 PM (19 years ago)
Author:
eugene
Message:

rework for consistency with the changes to the database and PS-IPP-Config

File:
1 edited

Legend:

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

    r14009 r14048  
    2222use IPC::Cmd 0.36 qw( can_run run );             # tools to run UNIX programs with control over I/O
    2323use PS::IPP::Metadata::Config;                   # tools to parse the psMetadataConfig files
     24use PS::IPP::Metadata::Stats;
     25
    2426use PS::IPP::Metadata::List qw( parse_md_list ); # tools to parse a metadata into a hash list
    2527use Statistics::Descriptive;                     # tools for calculating basic statistical quantities
     
    4143
    4244# parse the command-line options
    43 my ($det_id, $iter, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $workdir, $no_update, $no_op);
     45my ($det_id, $iter, $exp_id, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $workdir, $reduction, $no_update, $no_op);
    4446GetOptions(
    4547           'det_id|d=s'        => \$det_id,
    4648           'iteration=s'       => \$iter,
    47            'exp_tag|e=s'       => \$exp_tag,
     49           'exp_id|e=s'        => \$exp_id,
     50           'exp_tag|=s'        => \$exp_tag,
    4851           'det_type|t=s'      => \$det_type,
    4952           'camera=s'          => \$camera,
     
    5255           'dbname|d=s'        => \$dbname, # Database name
    5356           'workdir|w=s'       => \$workdir, # Working directory, for output files
     57           'reduction|=s'      => \$reduction,
    5458           'no-update'         => \$no_update,
    5559           'no-op'             => \$no_op,
     
    5761
    5862pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    59 pod2usage( -msg => "Required options: --det_id --iteration --exp_tag --det_type --camera",
     63pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --det_type --camera",
    6064           -exitval => 3)
    6165    unless defined $det_id
    6266    and defined $iter
     67    and defined $exp_id
    6368    and defined $exp_tag
    6469    and defined $det_type
     
    7176$reduction = 'DETREND' unless defined $reduction;
    7277
    73 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_RESID' . uc($det_type); # Recipe to use
     78my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_RESID_' . uc($det_type)); # Recipe to use
    7479&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1;
    7580
    76 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_RESID' . uc($det_type); # Recipe to use
     81my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_RESID_' . uc($det_type)); # Recipe to use
    7782&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2;
    7883
     
    8287# XXX  (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1
    8388my $STATS =
    84    [   
    85        #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
    86        { name => "bg",             type => "mean",  flag => "-bg" },
    87        { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev" },
    88        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev" },
    89        { name => "bin_stdev",      type => "rms",   flag => "-bin_stdev" },
    90        { name => "fringe_0",       type => "mean",  flag => "-fringe_0" },
    91        { name => "fringe_1",       type => "rms",   flag => "-fringe_1" },
    92        { name => "fringe_0",       type => "stdev", flag => "-fringe_2" },
    93        { name => "user_1",         type => "mean",  flag => "-user_1" }, # fringe residual
    94        { name => "user_2",         type => "rms",   flag => "-user_2" }, # fringe residual
    95        { name => "user_3",         type => "stdev", flag => "-user_1" }, # fringe residual
    96    ];
     89    [   
     90        #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
     91        { name => "bg",             type => "mean",  flag => "-bg" },
     92        { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev" },
     93        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev" },
     94        { name => "bin_stdev",      type => "rms",   flag => "-bin_stdev" },
     95        { name => "fringe_0",       type => "mean",  flag => "-fringe_0" },
     96        { name => "fringe_1",       type => "rms",   flag => "-fringe_1" },
     97        { name => "fringe_0",       type => "stdev", flag => "-fringe_2" },
     98        { name => "user_1",         type => "mean",  flag => "-user_1" }, # fringe residual
     99        { name => "user_2",         type => "rms",   flag => "-user_2" }, # fringe residual
     100        { name => "user_3",         type => "stdev", flag => "-user_1" }, # fringe residual
     101        ];
    97102
    98103# Look for programs we need
     
    106111
    107112# Get list of imfile files
    108 my $files;                      # Array of imfile files
     113my ($files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    109114{
    110     # dettool command to select imfile data for this exp_tag
    111     my $command = "$dettool -residimfile";
     115    # dettool command to select imfile data for this exp_id
     116    $command = "$dettool -residimfile";
    112117    $command .= " -det_id $det_id";
    113118    $command .= " -iteration $iter";
    114     $command .= " -exp_tag $exp_tag";
     119    $command .= " -exp_id $exp_id";
    115120    $command .= " -dbname $dbname" if defined $dbname;
    116     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     121    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    117122        run(command => $command, verbose => 1);
    118123    unless ($success) {
     
    126131    my $mdcParser = PS::IPP::Metadata::Config->new;     
    127132    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    128         &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR);
     133        &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
    129134
    130135    # parse the file info in the metadata
    131136    $files = parse_md_list($metadata) or
    132         &my_die("Unable to parse metadata list", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR);
     137        &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
    133138
    134139    # Parse the statistics on the residual image
    135140    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    136     $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     141    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
    137142}
    138143
     
    162167# build the JPEG images
    163168unless ($no_op) {
    164 
    165169    # Make the jpeg for binning 1
    166     {
    167         my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
    168         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    169             run(command => $command, verbose => 1);
    170         unless ($success) {
    171             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    172             &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code);
    173         }
    174         &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
    175     }
     170    $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
     171    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     172        run(command => $command, verbose => 1);
     173    unless ($success) {
     174        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     175        &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code);
     176    }
     177    &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
    176178   
    177179    # Make the jpeg for binning 2
    178     {
    179         my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
    180         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    181             run(command => $command, verbose => 1);
    182         unless ($success) {
    183             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    184             &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code);
    185         }
    186         &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
    187     }
     180    $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
     181    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     182        run(command => $command, verbose => 1);
     183    unless ($success) {
     184        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     185        &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code);
     186    }
     187    &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
    188188}
    189189
     
    207207my $reject_exp_bin_sn       = rejection_limit( 'EXP.BIN.SN',       $det_type, $filter );
    208208
    209 # storage variables
    210 
    211 # load the arrays from the imfile output table
    212 foreach my $file (@$files) {
    213     if ($file->{exp_time} > 0.0) {
    214         push @fluxes,           $file->{bg} / $file->{exp_time};       # mean background counts / sec
    215     } else {
    216         push @fluxes,           $file->{bg};
    217     }
    218 }
    219 
    220 # Reject based on the stats of the imfiles
    221 # it is VALID to reject on more than one criterion
    222 &my_die("Number of means and number of variances differ!", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless scalar @means == scalar @variances;
    223 
    224209# storage array
    225210my @fluxes;
    226211
    227 for (my $i = 0; $i < scalar @$files; $i++) {
    228     my $file      = $files[$i];
     212foreach my $file (@$files) {
    229213    my $name      = $file->{class_id};
    230214    my $mean      = $file->{bg};        # Mean for this imfile
     
    234218
    235219    # calculate and save the fluxes
    236     my $flux      = $mean / $file->{exp_time};
     220    my $flux;
    237221    if ($file->{exp_time} == 0.0) {
    238         push @fluxes, $mean;
     222        $flux = $mean;
     223    } else {
     224        $flux = $mean / $file->{exp_time};
    239225    }
    240226    push @fluxes, $flux;
     
    296282    # component means is larger than the limit
    297283    if ($reject_imfile_meanstdev > 0) {
    298         if ($meanStdevs > $reject_imfile_meanstdev) {
     284        if ($meanStdev > $reject_imfile_meanstdev) {
    299285            print $logFile "Rejecting exposure based on bad imfile mean stdev for $name: ";
    300286            $reject = 1;
     
    302288            print $logFile "Imfile mean stdev for $name meets requirements: ";
    303289        }
    304         print $logFile "$meanStdevs vs $reject_imfile_meanstdev\n";
     290        print $logFile "$meanStdev vs $reject_imfile_meanstdev\n";
    305291    } else {
    306292        print $logFile "No rejection on imfile mean stdev for $name\n";
     
    479465}
    480466
    481 my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag";
     467$command  = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_id $exp_id";
    482468$command .= " -recip $recipe1,$recipe2 -path_base $outputRoot ";
    483469$command .= ' -reject' if $reject;
     
    492478
    493479unless ($no_update) {
    494     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     480    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    495481        run(command => $command, verbose => 1);
    496482    unless ($success) {
     
    516502    my $det_id = shift;         # Detrend identifier
    517503    my $iter = shift;           # Iteration
    518     my $exp_tag = shift; # Exposure tag
     504    my $exp_id = shift; # Exposure tag
    519505    my $exit_code = shift; # Exit code to add
    520506
    521507    carp($msg);
    522     if ($det_id and $iter and $exp_tag and not $no_update) {
     508    if ($det_id and $iter and $exp_id and not $no_update) {
    523509        my $command = "$dettool -addresidexp";
    524510        $command .= " -det_id $det_id";
    525511        $command .= " -iteration $iter";
    526         $command .= " -exp_tag $exp_tag";
     512        $command .= " -exp_id $exp_id";
    527513        $command .= " -code $exit_code";
    528514        $command .= " -dbname $dbname" if defined $dbname;
Note: See TracChangeset for help on using the changeset viewer.