IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14048


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

Location:
trunk/ippScripts/scripts
Files:
9 edited

Legend:

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

    r14009 r14048  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
     18use PS::IPP::Metadata::Stats;
     19
    1820use PS::IPP::Metadata::List qw( parse_md_list );
    1921use File::Temp qw( tempfile );
     
    3335use Pod::Usage qw( pod2usage );
    3436
    35 my ($det_id, $iter, $det_type, $camera, $dbname, $workdir, $no_update, $no_op);
     37my ($det_id, $iter, $det_type, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
    3638GetOptions(
    37     'det_id|d=s'        => \$det_id,
    38     'iteration|i=s'     => \$iter,
    39     'camera|c=s'        => \$camera,
    40     'det_type|t=s'      => \$det_type,
    41     'dbname|d=s'        => \$dbname, # Database name
    42     'workdir|w=s'       => \$workdir,   # Working directory, for output files
    43     'no-update'         => \$no_update,
    44     'no-op'             => \$no_op,
    45 ) or pod2usage( 2 );
     39           'det_id|d=s'        => \$det_id,
     40           'iteration|i=s'     => \$iter,
     41           'camera|c=s'        => \$camera,
     42           'det_type|t=s'      => \$det_type,
     43           'dbname|d=s'        => \$dbname, # Database name
     44           'workdir|w=s'       => \$workdir,    # Working directory, for output files
     45           'reduction|=s'      => \$reduction,
     46           'no-update'         => \$no_update,
     47           'no-op'             => \$no_op,
     48           ) or pod2usage( 2 );
    4649
    4750pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    5861$reduction = 'DETREND' unless defined $reduction;
    5962
    60 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_IMAGE' . uc($det_type); # Recipe to use
     63my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_IMAGE_' . uc($det_type)); # Recipe to use
    6164&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1;
    6265
    63 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_IMAGE' . uc($det_type); # Recipe to use
     66my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_IMAGE_' . uc($det_type)); # Recipe to use
    6467&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2;
    6568
     
    6972# XXX  (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1
    7073my $STATS =
    71    [   
    72        #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
    73        { name => "bg",             type => "mean",  flag => "-bg" },
    74        { name => "bg",             type => "stdev", flag => "-bg_mean_stdev" },
    75        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev" },
    76        # { name => "bg_mean_stdev",  type => "rms",   flag => "-bg_mean_stdev" },
    77    ];
     74    [   
     75        #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
     76        { name => "bg",             type => "mean",  flag => "-bg" },
     77        { name => "bg",             type => "stdev", flag => "-bg_mean_stdev" },
     78        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev" },
     79        # { name => "bg_mean_stdev",  type => "rms",   flag => "-bg_mean_stdev" },
     80        ];
    7881
    7982# Look for programs we need
     
    8790
    8891# Get list of component files
    89 my $files;                      # Array of component files
     92my ($files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    9093{
    91     my $command = "$dettool -normalizedimfile -det_id $det_id -iteration $iter"; # Command to run
     94    $command = "$dettool -normalizedimfile -det_id $det_id -iteration $iter"; # Command to run
    9295    $command .= " -dbname $dbname" if defined $dbname;
    93     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     96    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    9497        run(command => $command, verbose => 1);
    9598    unless ($success) {
     
    131134unless ($no_op) {
    132135    # Make the jpeg for binning 1
    133     {
    134         my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
    135         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    136             run(command => $command, verbose => 1);
    137         &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
    138     }
     136    $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
     137    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     138        run(command => $command, verbose => 1);
     139    &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
    139140   
    140141    # Make the jpeg for binning 2
    141     {
    142         my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
    143         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    144             run(command => $command, verbose => 1);
    145         &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
    146     }
     142    $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
     143    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     144        run(command => $command, verbose => 1);
     145    &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
     146
    147147}
    148148
    149149# command to update the database
    150 my $command = "$dettool -addnormalizedexp";
     150$command = "$dettool -addnormalizedexp";
    151151$command .= " -det_id $det_id";
    152152$command .= " -iteration $iter";
     
    164164# Add the processed file to the database
    165165unless ($no_update) {
    166     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     166    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    167167        run(command => $command, verbose => 1);
    168168    unless ($success) {
  • trunk/ippScripts/scripts/detrend_process_exp.pl

    r14009 r14048  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
     18use PS::IPP::Metadata::Stats;
     19
    1820use PS::IPP::Metadata::List qw( parse_md_list );
    1921use File::Temp qw( tempfile );
     
    3335use Pod::Usage qw( pod2usage );
    3436
    35 my ($det_id, $det_type, $exp_tag, $camera, $dbname, $workdir, $no_update, $no_op);
     37my ($det_id, $exp_id, $det_type, $exp_tag, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
    3638GetOptions(
    3739    'det_id|d=s'        => \$det_id,
    3840    'det_type|t=s'      => \$det_type,
    39     'exp_tag|e=s'       => \$exp_tag,
     41    'exp_id|d=s'        => \$exp_id,
     42    'exp_tag|=s'        => \$exp_tag,
    4043    'camera|c=s'        => \$camera,
    4144    'dbname|d=s'        => \$dbname, # Database name
    4245    'workdir|w=s'       => \$workdir,   # Working directory, for output files
     46    'reduction|=s'      => \$reduction,
    4347    'no-update'         => \$no_update,
    4448    'no-op'             => \$no_op,
     
    4650
    4751pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    48 pod2usage( -msg => "Required options: --det_id --det_type --exp_tag --camera",
     52pod2usage( -msg => "Required options: --det_id --det_type --exp_id --exp_tag --camera",
    4953           -exitval => 3)
    5054    unless defined $det_id
    5155    and defined $det_type
     56    and defined $exp_id
    5257    and defined $exp_tag
    5358    and defined $camera;
     
    5863$reduction = 'DETREND' unless defined $reduction;
    5964
    60 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_IMAGE' . uc($det_type); # Recipe to use
    61 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1;
    62 
    63 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_IMAGE' . uc($det_type); # Recipe to use
    64 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2;
     65my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_IMAGE_' . uc($det_type)); # Recipe to use
     66&my_die("Unrecognised detrend type: $det_type", $det_id, $exp_id, $PS_EXIT_PROG_ERROR) unless defined $recipe1;
     67
     68my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_IMAGE_' . uc($det_type)); # Recipe to use
     69&my_die("Unrecognised detrend type: $det_type", $det_id, $exp_id, $PS_EXIT_PROG_ERROR) unless defined $recipe2;
    6570
    6671# values to extract from output metadata and the stats to calculate
     
    8792
    8893# Get list of component files
    89 my $files;                      # Array of component files
     94my ($files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    9095{
    91     my $command = "$dettool -processedimfile -det_id $det_id -exp_tag $exp_tag"; # Command to run
     96    $command = "$dettool -processedimfile -det_id $det_id -exp_id $exp_id"; # Command to run
    9297    $command .= " -dbname $dbname" if defined $dbname;
    93     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    94         run(command => $command, verbose => 1);
    95     unless ($success) {
    96         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    97         &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $exp_tag, $error_code);
     98    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     99        run(command => $command, verbose => 1);
     100    unless ($success) {
     101        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     102        &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $exp_id, $error_code);
    98103    }
    99104
     
    101106    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    102107    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    103         &my_die("Unable to parse metadata config doc", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR);
     108        &my_die("Unable to parse metadata config doc", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
    104109
    105110    # parse the file info in the metadata
    106111    $files = parse_md_list($metadata) or
    107         &my_die("Unable to parse metadata list", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR);
     112        &my_die("Unable to parse metadata list", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
    108113
    109114    # parse the stats in the metadata
    110115    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    111116    unless ($stats->parse($metadata)) {
    112         &my_die("Unable to find all values in statistics output.\n", $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
     117        &my_die("Unable to find all values in statistics output.\n", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
    113118    }
    114119}
     
    132137unless ($no_op) {
    133138    # Make the jpeg for binning 1
    134     {
    135         my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
    136         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    137             run(command => $command, verbose => 1);
    138         unless ($success) {
    139             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    140             &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $error_code);
    141         }
    142         &my_die("Unable to find expected output file: $jpeg1", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1);
    143     }
     139    $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
     140    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     141        run(command => $command, verbose => 1);
     142    unless ($success) {
     143        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     144        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_id, $error_code);
     145    }
     146    &my_die("Unable to find expected output file: $jpeg1", $det_id, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1);
    144147   
    145148    # Make the jpeg for binning 2
    146     {
    147         my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
    148         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    149             run(command => $command, verbose => 1);
    150         unless ($success) {
    151             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    152             &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $error_code);
    153         }
    154         &my_die("Unable to find expected output file: $jpeg2", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2);
    155     }
     149    $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
     150    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     151        run(command => $command, verbose => 1);
     152    unless ($success) {
     153        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     154        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_id, $error_code);
     155    }
     156    &my_die("Unable to find expected output file: $jpeg2", $det_id, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2);
    156157}
    157158
    158159# Command to update the database
    159 my $command = "$dettool -addprocessedexp";
     160$command = "$dettool -addprocessedexp";
    160161$command .= " -det_id $det_id";
    161 $command .= " -exp_tag $exp_tag";
     162$command .= " -exp_id $exp_id";
    162163$command .= " -recip $recipe1,$recipe2 -path_base $outputRoot";
    163164$command .= " -dbname $dbname" if defined $dbname;
     
    172173# Add the processed file to the database
    173174unless ($no_update) {
    174     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     175    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    175176        run(command => $command, verbose => 1);
    176177    unless ($success) {
     
    187188    my $msg = shift; # Warning message on die
    188189    my $det_id = shift;         # Detrend identifier
    189     my $exp_tag = shift; # Exposure tag
     190    my $exp_id = shift; # Exposure tag
    190191    my $exit_code = shift; # Exit code to add
    191192
    192193    carp($msg);
    193     if ($det_id and $exp_tag and not $no_update) {
     194    if ($det_id and $exp_id and not $no_update) {
    194195        my $command = "$dettool -addprocessedexp";
    195196        $command .= " -det_id $det_id";
    196         $command .= " -exp_tag $exp_tag";
     197        $command .= " -exp_id $exp_id";
    197198        $command .= " -code $exit_code";
    198199        $command .= " -dbname $dbname" if defined $dbname;
  • trunk/ippScripts/scripts/detrend_process_imfile.pl

    r14009 r14048  
    3232use Pod::Usage qw( pod2usage );
    3333
    34 my ($det_id, $exp_tag, $class_id, $det_type, $input_uri, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
     34my ($det_id, $exp_id, $class_id, $det_type, $exp_tag, $input_uri, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
    3535GetOptions(
    3636    'det_id|d=s'        => \$det_id,
    37     'exp_tag|e=s'       => \$exp_tag,
     37    'exp_id|e=s'        => \$exp_id,
    3838    'class_id|i=s'      => \$class_id,
    3939    'det_type|t=s'      => \$det_type,
     40    'exp_tag|=s'        => \$exp_tag,
    4041    'input_uri|u=s'     => \$input_uri,
    4142    'camera|c=s'        => \$camera,
     
    4849
    4950pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    50 pod2usage( -msg => "Required options: --det_id --exp_tag --class_id --det_type --input_uri --camera",
     51pod2usage( -msg => "Required options: --det_id --exp_id --class_id --det_type --exp_tag --input_uri --camera",
    5152           -exitval => 3)
    5253    unless defined $det_id
    53     and defined $exp_tag
     54    and defined $exp_id
    5455    and defined $class_id
    5556    and defined $det_type
     57    and defined $exp_tag
    5658    and defined $input_uri
    5759    and defined $camera;
     
    8385$ppImage .= " -dbname $dbname" if defined $dbname;
    8486
    85 &my_die("Couldn't find input file: $input_uri\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
     87&my_die("Couldn't find input file: $input_uri\n", $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
    8688
    8789$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     
    8991my $outputRoot  = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, $input_uri );
    9092
    91 my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    92 my $outputBin1  = $ipprc->filename("PPIMAGE.BIN1",   $outputRoot, $class_id);
    93 my $outputBin2  = $ipprc->filename("PPIMAGE.BIN2",   $outputRoot, $class_id);
    94 my $outputStats = $ipprc->filename("PPIMAGE.STATS",  $outputRoot, $class_id);
     93my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
     94my $outputBin1  = $ipprc->filename("PPIMAGE.BIN1",   $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
     95my $outputBin2  = $ipprc->filename("PPIMAGE.BIN2",   $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
     96my $outputStats = $ipprc->filename("PPIMAGE.STATS",  $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    9597
    9698# Run ppImage
     
    105107    unless ($success) {
    106108        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    107         &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $class_id, $error_code);
     109        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_id, $class_id, $error_code);
    108110    }
    109111
    110     &my_die("Couldn't find expected output file: $outputImage", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage);
    111     &my_die("Couldn't find expected output file: $outputStats", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    112     &my_die("Couldn't find expected output file: $outputBin1", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin1);
    113     &my_die("Couldn't find expected output file: $outputBin2", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin2);
     112    &my_die("Couldn't find expected output file: $outputImage", $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage);
     113    &my_die("Couldn't find expected output file: $outputStats", $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
     114    &my_die("Couldn't find expected output file: $outputBin1",  $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin1);
     115    &my_die("Couldn't find expected output file: $outputBin2",  $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin2);
    114116
    115117    # Get the statistics on the processed image
     
    122124    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    123125    my $metadata = $mdcParser->parse(join "", @contents)
    124         or &my_die("Unable to parse metadata config", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     126        or &my_die("Unable to parse metadata config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    125127
    126128    # extract the stats from the metadata
    127129    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    128     $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     130    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    129131}
    130132
     
    132134my $command = "$dettool -addprocessedimfile";
    133135$command .= " -det_id $det_id";
    134 $command .= " -exp_tag $exp_tag";
     136$command .= " -exp_id $exp_id";
    135137$command .= " -class_id $class_id";
    136138$command .= " -recip $reduction";
     
    162164    my $msg = shift; # Warning message on die
    163165    my $det_id = shift;         # Detrend identifier
    164     my $exp_tag = shift; # Exposure tag
     166    my $exp_id = shift; # Exposure tag
    165167    my $class_id = shift; # Class identifier
    166168    my $exit_code = shift; # Exit code to add
    167169
    168170    carp($msg);
    169     if ($det_id and $exp_tag and $class_id and not $no_update) {
     171    if ($det_id and $exp_id and $class_id and not $no_update) {
    170172        my $command = "$dettool -addprocessedimfile";
    171173        $command .= " -det_id $det_id";
    172         $command .= " -exp_tag $exp_tag";
     174        $command .= " -exp_id $exp_id";
    173175        $command .= " -class_id $class_id";
    174176        $command .= " -code $exit_code";
  • trunk/ippScripts/scripts/detrend_reject_exp.pl

    r14009 r14048  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
     18use PS::IPP::Metadata::Stats;
     19
    1820use PS::IPP::Metadata::List qw( parse_md_list );
    1921use Statistics::Descriptive;
     
    8688
    8789# Get list of component files
    88 my $exposures;                  # Array of exposures
     90my ($exposures, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    8991{
    9092    # dettool command to select exp data for this det_run
    91     my $command = "$dettool -residexp";
     93    $command = "$dettool -residexp";
    9294    $command .= " -det_id $det_id";
    9395    $command .= " -iteration $iter";
    9496    $command .= " -dbname $dbname" if defined $dbname;
    95     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     97    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    9698        run(command => $command, verbose => 1);
    9799    unless ($success) {
     
    118120}
    119121
    120 my @expTags;                    # Array of exposure IDs
    121 my @accept;                     # Array of accept flags
    122 my @include;                    # Array of include flags
    123 foreach my $exposure (@$exposures) {
    124     &my_die("Unable to find exposure id.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{exp_tag};
    125     &my_die("Unable to find accept.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{accept};
    126     &my_die("Unable to find include.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{include};
    127 }
    128 
     122# we use the statistics of the ensemble to accept/reject exposurs
    129123my $ensMeanMean       = &STATS_value_for_flag ($REJSTATS, "ensMeanMean");     
    130124my $ensMeanStdev      = &STATS_value_for_flag ($REJSTATS, "ensMeanStdev");     
     
    147141unless ($no_op) {
    148142    $logFile = $ipprc->file_create_append( $logName );
    149     print $logFile "Ensemble mean $meanEnsemble +/- $stdevEnsemble, stdev $meanStdevEnsemble\n\n";
     143    print $logFile "Ensemble mean $ensMeanMean +/- $ensMeanStdevMean, stdev $ensStdevMean\n\n";
    150144}
    151145
     
    153147my $numChanges = 0;             # Number of exposures with changed status
    154148my $numReject = 0;              # Number of exposures rejected
    155 
    156 for (my $i = 0; $i < scalar @$exposures; $i++) {
    157     my $file      = $files[$i];
    158     my $mean      = $file->{bg};        # Mean for this exposure
    159     my $stdev     = $file->{bg_stdev}; # Stdev for this exposure
    160     my $meanStdev = $file->{bg_mean_stdev}; # Stdev of Means for this exposure
    161 
    162     my $expTag  = $exposure->{exp_tag};
    163     my $accept  = $exposure->{accept};
    164     my $include = $exposure->{include};
     149my $firstElement = 1;
     150
     151foreach my $exposure (@$exposures) {
     152    my $mean      = $exposure->{bg};    # Mean for this exposure
     153    my $stdev     = $exposure->{bg_stdev}; # Stdev for this exposure
     154    my $meanStdev = $exposure->{bg_mean_stdev}; # Stdev of Means for this exposure
     155    my $expID     = $exposure->{exp_id};
     156    my $accept    = $exposure->{accept};
     157    my $include   = $exposure->{include};
     158
     159    &my_die("Unable to find exposure id.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $expID;
     160    &my_die("Unable to find accept.\n",      $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $accept;
     161    &my_die("Unable to find include.\n",     $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $include;
    165162
    166163    my $reject = 0;             # Reject this exposure?
    167164
    168     my $command = "$dettool -updateresidexp";
     165    $command = "$dettool -updateresidexp";
    169166    $command .= " -det_id $det_id";
    170167    $command .= " -iteration $iter";
    171     $command .= " -exp_tag $expTag";
     168    $command .= " -exp_id $expID";
    172169    $command .= " -dbname $dbname" if defined $dbname;
    173170   
     
    175172        # Rejected this at an earlier stage
    176173        unless ($no_op) {
    177             print $logFile "Rejecting $expTag based on earlier determination.\n";
     174            print $logFile "Rejecting $expID based on earlier determination.\n";
    178175        }
    179176        $reject = 1;
     
    185182        # Make sure something gets rejected (just once!), just so that
    186183        # we can trace the full range of the workflow
    187         if ($i == 0 and $iter == 0) {
     184        if ($firstElement and $iter == 0) {
    188185            $reject = 1;
    189186        }
     
    194191        my $delta = abs($mean - $ensMeanMean);
    195192        if ($delta > ($reject_mean * $ensMeanStdev)) {
    196             print $logFile "Rejecting $expTag based on ensemble mean value: ";
     193            print $logFile "Rejecting $expID based on ensemble mean value: ";
    197194            $reject = 1;
    198195            #goto UPDATE;
    199196        } else {
    200             print $logFile "$expTag OK against ensemble mean: ";
     197            print $logFile "$expID OK against ensemble mean: ";
    201198        }
    202199        print $logFile "$mean --> $delta vs " . $reject_mean * $ensMeanStdev . "\n";
    203200    } else {
    204         print $logFile "No rejection of $expTag for ensemble mean\n";
     201        print $logFile "No rejection of $expID for ensemble mean\n";
    205202    }
    206203
     
    208205        my $delta = abs($stdev - $ensStdevMean);
    209206        if ($delta > ($reject_stdev * $ensStdevStdev)) {
    210             print $logFile "Rejecting $expTag based on ensemble stdev: ";
     207            print $logFile "Rejecting $expID based on ensemble stdev: ";
    211208            $reject = 1;
    212209            #goto UPDATE;
    213210        } else {
    214             print $logFile "$expTag OK against ensemble stdev: ";
     211            print $logFile "$expID OK against ensemble stdev: ";
    215212        }
    216213        print $logFile "$stdev --> $delta sigma vs " . $reject_stdev * $ensStdevStdev . "\n";
    217214    } else {
    218         print $logFile "No rejection of $expTag for ensemble stdev\n";
     215        print $logFile "No rejection of $expID for ensemble stdev\n";
    219216    }
    220217   
     
    222219        my $delta = abs($meanStdev - $ensMeanStdevMean);
    223220        if ($delta > ($reject_meanstdev * $ensMeanStdevStdev)) {
    224             print $logFile "Rejecting $expTag based on ensemble mean stdev: ";
     221            print $logFile "Rejecting $expID based on ensemble mean stdev: ";
    225222            $reject = 1;
    226223            #goto UPDATE;
    227224        } else {
    228             print $logFile "$expTag OK against ensemble mean stdev: ";
     225            print $logFile "$expID OK against ensemble mean stdev: ";
    229226        }
    230227        print $logFile "$meanStdev --> $delta sigma vs " . $reject_meanstdev * $ensMeanStdevStdev. "\n";
    231228    } else {
    232         print $logFile "No rejection of $expTag for ensemble mean stdev\n";
     229        print $logFile "No rejection of $expID for ensemble mean stdev\n";
    233230    }
    234231
     
    242239    if ((not $include and not $reject) or ($include and $reject)) {
    243240        unless ($no_op) {
    244             print $logFile "Status of $expTag has changed.\n";
     241            print $logFile "Status of $expID has changed.\n";
    245242        }
    246243        $numChanges++;
     
    249246    unless ($no_update) {
    250247        # Update
    251         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     248        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    252249            run(command => $command, verbose => 1);
    253250        unless ($success) {
     
    268265
    269266# Rejecting everything --- stop before something bad happens!
    270 if ($numReject == scalar @means) {
     267if ($numReject == scalar @$exposures) {
    271268    $master = 0;
    272269    $stop = 1;
     
    279276}
    280277
    281 my $command = "$dettool -adddetrunsummary";
     278$command = "$dettool -adddetrunsummary";
    282279$command .= " -det_id $det_id";
    283280$command .= " -iteration $iter";
     
    294291# Put results into the database
    295292unless ($no_update) {
    296     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     293    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    297294        run(command => $command, verbose => 1);
    298295    unless ($success) {
     
    310307    $command .= " -dbname $dbname" if defined $dbname;
    311308
    312     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     309    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    313310        run(command => $command, verbose => 1);
    314311    unless ($success) {
  • 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;
  • trunk/ippScripts/scripts/detrend_resid.pl

    r14009 r14048  
    3232use Pod::Usage qw( pod2usage );
    3333
    34 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op);
     34my ($det_id, $iter, $exp_id, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op);
    3535GetOptions(
    3636    'det_id|d=s'        => \$det_id,
    3737    'iteration=s'       => \$iter,
    38     'exp_tag|e=s'       => \$exp_tag,
     38    'exp_id|e=s'        => \$exp_id,
     39    'exp_tag|=s'        => \$exp_tag,
    3940    'class_id|i=s'      => \$class_id,
    4041    'det_type|t=s'      => \$det_type,
     
    5152
    5253pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    53 pod2usage( -msg => "Required options: --det_id --iteration --exp_tag --class_id --det_type --camera --input_uri --mode --detrend (not for 'verify' mode)",
     54pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --class_id --det_type --camera --input_uri --mode --detrend (not for 'verify' mode)",
    5455           -exitval => 3)
    5556    unless defined $det_id
    5657    and defined $iter
     58    and defined $exp_id
    5759    and defined $exp_tag
    5860    and defined $class_id
     
    7375    $recipe = uc($det_type) . '_VERIFY';
    7476} else {
    75     &my_die("Unrecognised mode: $mode", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     77    &my_die("Unrecognised mode: $mode", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    7678}
    7779$recipe = $ipprc->reduction($reduction, $recipe);
     
    139141    if (lc($mode) ne 'verify') {
    140142        my $detFlag = DETRENDS->{lc($det_type)};
    141         &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR) unless defined $detFlag;
     143        &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR) unless defined $detFlag;
    142144        $command .= " $detFlag $detrend";
    143145    }
     
    147149    unless ($success) {
    148150        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    149         &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $exp_tag, $class_id, $error_code);
    150     }
    151     &my_die("Couldn't find expected output file: $outputName", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputName);
    152     &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    153     &my_die("Couldn't find expected output file: $bin1Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin1Name);
    154     &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin2Name);
     151        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
     152    }
     153    &my_die("Couldn't find expected output file: $outputName", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputName);
     154    &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
     155    &my_die("Couldn't find expected output file: $bin1Name", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin1Name);
     156    &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin2Name);
    155157
    156158    # Load the raw output stats file
    157159    my $statsFile;              # File handle
    158     open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
     160    open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
    159161    my @contents = <$statsFile>; # Contents of file
    160162    close $statsFile;
     
    162164    # Parse the stats file contents into a metadata
    163165    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    164     my $metadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     166    my $metadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    165167
    166168    # Parse the statistics on the residual image
    167169    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    168     $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);
     170    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    169171
    170172    # run ppStats on the binned image
     
    174176    unless ($success) {
    175177        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    176         &my_die("Unable to perform ppStats: $error_code", $det_id, $iter, $exp_tag, $class_id, $error_code);
     178        &my_die("Unable to perform ppStats: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
    177179    }
    178180
    179181    # parse the binned image statistics
    180     my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     182    my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    181183
    182184    my $binnedStats = PS::IPP::Metadata::Stats->new($BINNED_STATS); # Stats parser
    183     $binnedStats->parse($binnedMetadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     185    $binnedStats->parse($binnedMetadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
    184186}
    185187
     
    188190$command .= " -det_id $det_id";
    189191$command .= " -iteration $iter";
    190 $command .= " -exp_tag $exp_tag";
     192$command .= " -exp_id $exp_id";
    191193$command .= " -class_id $class_id";
    192194$command .= " -recip $recipe";
     
    196198
    197199# add in the elements from the selected stats above
    198 foreach my $entry (@$STATS @$BINNED_STATS) {
     200foreach my $entry (@$STATS, @$BINNED_STATS) {
    199201    my $value = $entry->{value};
    200202    my $flag = $entry->{flag};
     
    220222    my $det_id = shift;         # Detrend identifier
    221223    my $iter = shift;           # Iteration
    222     my $exp_tag = shift; # Exposure tag
     224    my $exp_id = shift; # Exposure tag
    223225    my $class_id = shift; # Class identifier
    224226    my $exit_code = shift; # Exit code to add
    225227
    226228    carp($msg);
    227     if ($det_id and $iter and $exp_tag and not $no_update) {
     229    if ($det_id and $iter and $exp_id and not $no_update) {
    228230        my $command = "$dettool -addresidimfile";
    229231        $command .= " -det_id $det_id";
    230232        $command .= " -iteration $iter";
    231         $command .= " -exp_tag $exp_tag";
     233        $command .= " -exp_id $exp_id";
    232234        $command .= " -class_id $class_id";
    233235        $command .= " -code $exit_code";
  • trunk/ippScripts/scripts/detrend_stack.pl

    r14009 r14048  
    8888}
    8989
    90 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
    91 
    92 my $outputRoot  = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} );
    93 my $outputStack = $outputRoot . '.fits'; # Output name
    94 my $outputStats = $outputRoot . '.stats'; # Statistics name
    95 
    9690# Get list of files to stack
    97 my $files;                      # Array of files to be stacked
     91my ($files, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    9892{
    99     my $command = "$dettool -processedimfile -included";
     93    $command = "$dettool -processedimfile -included";
    10094    $command .= " -det_id $det_id";
    10195    $command .= " -class_id $class_id";
    10296    $command .= " -dbname $dbname" if defined $dbname;
    10397
    104     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     98    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    10599        run(command => $command, verbose => $verbose);
    106100    unless ($success) {
     
    116110}
    117111
    118 my $command = "$ppMerge $outputStack"; # Command to run
     112$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     113
     114my $outputRoot  = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} );
     115my $outputStack = $outputRoot . '.fits'; # Output name
     116my $outputStats = $outputRoot . '.stats'; # Statistics name
     117
     118$command = "$ppMerge $outputStack"; # Command to run
    119119foreach my $file (@$files) {
    120120    $command .= ' ' . $file->{uri};
     
    128128unless ($no_op) {
    129129   
    130     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     130    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    131131        run(command => $command, verbose => $verbose);
    132132    unless ($success) {
  • trunk/ippScripts/scripts/register_exp.pl

    r14039 r14048  
    1919use IPC::Cmd 0.36 qw( can_run run );
    2020use PS::IPP::Metadata::Config;
    21 use PS::IPP::Metadata::List qw( parse_md_list );
    22 use Statistics::Descriptive;
     21use PS::IPP::Metadata::Stats;
    2322
    2423use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    6261       { name => "exp_name",       type => "constant",   flag => "-exp_name" }, # File level
    6362       { name => "telescope",      type => "constant",   flag => "-telescope" }, # File level
    64        { name => "inst",           type => "constant",   flag => "-inst" }, # File level
     63       { name => "camera",         type => "constant",   flag => "-inst" }, # File level
    6564       { name => "filelevel",      type => "constant",   flag => "-filelevel" }, # File level
    6665       { name => "object",         type => "constant",   flag => "-object" },
     
    120119    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    121120    unless ($stats->parse($metadata)) {
    122         &my_die ("Unable to find all values", $exp_id, $class_id, $PS_EXIT_CONFIG_ERROR);
    123     }
    124 }
     121        &my_die ("Unable to find all values", $exp_id, $PS_EXIT_CONFIG_ERROR);
     122    }
     123}
     124
     125# we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type
     126if (uc(&STATS_value_for_flag ($STATS, "-telescope")) eq "NAN") { &my_die ("telescope not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     127if (uc(&STATS_value_for_flag ($STATS, "-inst"))      eq "NAN") { &my_die ("inst      not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     128if (uc(&STATS_value_for_flag ($STATS, "-filelevel")) eq "NAN") { &my_die ("filelevel not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     129if (uc(&STATS_value_for_flag ($STATS, "-exp_type"))  eq "NAN") { &my_die ("exp_type  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     130if (uc(&STATS_value_for_flag ($STATS, "-exp_name"))  eq "NAN") { &my_die ("exp_name  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
    125131
    126132my $command = "$regtool -addprocessedexp";
  • trunk/ippScripts/scripts/register_imfile.pl

    r14039 r14048  
    2020use PS::IPP::Metadata::Config;
    2121use PS::IPP::Metadata::Stats;
    22 use Data::Dumper;
    2322
    2423use PS::IPP::Config qw(
     
    3837use Pod::Usage qw( pod2usage );
    3938
    40 my ($cache, $exp_id, $tmp_class_id, $exp_name, $uri, $workdir, $dbname, $no_update, $no_op);
     39my ($cache, $exp_id, $tmp_class_id, $tmp_exp_name, $uri, $workdir, $dbname, $no_update, $no_op);
    4140GetOptions(
    4241    'caches'           => \$cache,
    4342    'exp_id|e=s'       => \$exp_id,
    4443    'tmp_class_id|i=s' => \$tmp_class_id,
    45     'exp_name|n=s'     => \$exp_name,
     44    'tmp_exp_name|n=s' => \$tmp_exp_name,
    4645    'uri|u=s'          => \$uri,
    4746    'workdir|w=s'      => \$workdir, # Working directory for output files
     
    5251
    5352pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    54 pod2usage( -msg => "Required options: --exp_id --tmp_class_id --exp_name --uri",
     53pod2usage( -msg => "Required options: --exp_id --tmp_class_id --tmp_exp_name --uri",
    5554           -exitval => 3) unless
    5655    defined $exp_id and
    5756    defined $tmp_class_id and
    58     defined $exp_name and
     57    defined $tmp_exp_name and
    5958    defined $uri;
    6059
     
    114113    unless ($success) {
    115114        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    116         &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $exp_name, $tmp_class_id, $error_code);
     115        &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $tmp_exp_name, $tmp_class_id, $error_code);
    117116    }
    118117   
     
    121120    my $metadata = $mdcParser->parse(join "", @$stdout_buf); # XXX is this join necessary?
    122121    unless ($metadata) {
    123         &my_die ("Unable to parse metadata config doc", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_PROG_ERROR);
     122        &my_die ("Unable to parse metadata config doc", $exp_id, $tmp_exp_name, $tmp_class_id, $PS_EXIT_PROG_ERROR);
    124123    }
    125124
     
    127126    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    128127    unless ($stats->parse($metadata)) {
    129         &my_die ("Unable to find all values", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR);
     128        &my_die ("Unable to find all values", $exp_id, $tmp_exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR);
    130129    }
    131130}
    132131
    133132# we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type
    134 if (uc(&STATS_value_for_flag ($STATS, "-telescope")) eq "NAN") { &my_die ("telescope not found", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
    135 if (uc(&STATS_value_for_flag ($STATS, "-inst"))      eq "NAN") { &my_die ("inst      not found", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
    136 if (uc(&STATS_value_for_flag ($STATS, "-filelevel")) eq "NAN") { &my_die ("filelevel not found", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
    137 if (uc(&STATS_value_for_flag ($STATS, "-class_id"))  eq "NAN") { &my_die ("class_id  not found", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
    138 if (uc(&STATS_value_for_flag ($STATS, "-exp_type"))  eq "NAN") { &my_die ("exp_type  not found", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
     133if (uc(&STATS_value_for_flag ($STATS, "-telescope")) eq "NAN") { &my_die ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
     134if (uc(&STATS_value_for_flag ($STATS, "-inst"))      eq "NAN") { &my_die ("inst      not found", $exp_id, $tmp_exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
     135if (uc(&STATS_value_for_flag ($STATS, "-filelevel")) eq "NAN") { &my_die ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
     136if (uc(&STATS_value_for_flag ($STATS, "-class_id"))  eq "NAN") { &my_die ("class_id  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
     137if (uc(&STATS_value_for_flag ($STATS, "-exp_type"))  eq "NAN") { &my_die ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR); }
    139138
    140139my $command = "$regtool -addprocessedimfile";
    141140$command .= " -exp_id $exp_id";
    142 $command .= " -exp_name $exp_name"; # keep the supplied exp_name (could be derived from the file)
     141$command .= " -exp_name $tmp_exp_name"; # keep the supplied exp_name (could be derived from the file)
    143142$command .= " -tmp_class_id $tmp_class_id"; # the original class_id supplied by the user, replace by ppStats CLASS.ID
    144143$command .= " -dbname $dbname" if defined $dbname;
Note: See TracChangeset for help on using the changeset viewer.