IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14039


Ignore:
Timestamp:
Jul 5, 2007, 6:16:04 PM (19 years ago)
Author:
eugene
Message:

updates to new regtool / pxinject apis

Location:
trunk/ippScripts
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/Build.PL

    r13150 r14039  
    4242                               scripts/stack_skycell.pl
    4343                               scripts/ipp_serial_inject.pl
     44                               scripts/ipp_serial_inject_split.pl
    4445                               scripts/ipp_serial_inject_mosaic.pl
    4546                               scripts/ipp_serial_register.pl
  • trunk/ippScripts/scripts/ipp_serial_inject.pl

    r14021 r14039  
    33# this program injects a list of single-file exposures into the db,
    44# taking the filename (without .fits) as the exp_tag.  the user
    5 # supplies a temporary telescope and instrument name.  these are used
     5# supplies a temporary telescope and camera name.  these are used
    66# for informational purposes only until the registration step can
    7 # determine the true telescope and instrument name from the image
     7# determine the true telescope and camera name from the image
    88# headers.
    99
     
    2424
    2525# Parse the command-line arguments
    26 my ($workdir, $dbname, $telescope, $instrument, $help);
     26my ($workdir, $dbname, $telescope, $camera, $help);
    2727GetOptions(
    2828    'workdir|w=s'    => \$workdir, # working directory for output files
    2929    'dbname|d=s'     => \$dbname, # Database name
    3030    'telescope|t=s'  => \$telescope, # user-supplied telescope name
    31     'instrument|i=s' => \$instrument, # user-supplied instrument name
     31    'camera|i=s'     => \$camera, # user-supplied camera name
    3232    'help'           => \$help # give help listing
    3333) or pod2usage( 2 );
    3434
    35 pod2usage( -msg => "inject one or many files into the IPP pipeline database", -exitval => 2
     35pod2usage( -msg => "inject one or many files into the IPP pipeline database",
     36           -exitval => 2) if
     37    defined $help;
    3638
    37 pod2usage( -msg => "Usage: $0 --telescope (name) --instrument (name) [--workdir path] [--dbname dbname] (files)",
     39pod2usage( -msg => "Usage: $0 --telescope (name) --camera (name) [--workdir path] [--dbname dbname] (files)",
    3840           -exitval => 2 ) if
    39            scalar @ARGV == 0;
     41    scalar @ARGV == 0;
    4042
    41 pod2usage( -msg => "Required options: --telescope (name) --instrument (name)",
     43pod2usage( -msg => "Required options: --telescope (name) --camera (name)",
    4244           -exitval => 3) unless
    43            defined $telescope and
    44            defined $instrument;
     45    defined $telescope and
     46    defined $camera;
    4547
    4648my $pxinject = can_run('pxinject') or die "Can't find pxinject\n";
     
    5456my $num = 0;
    5557foreach my $file ( @ARGV ) {
     58    # check for file existence
     59    if (! -e $file) { die "file $file not found\n"; }
    5660    my $absfile = File::Spec->rel2abs( $file );
    57     inject($absfile, $workdir, $dbname, $telescope, $instrument);
     61    inject($absfile, $workdir, $dbname, $telescope, $camera);
    5862    $num ++;
    5963}
     
    6771    my $dbname = shift;         # IPP database to use
    6872    my $telescope = shift;      # user-specified telescope
    69     my $instrument = shift;     # user-specified instrument
     73    my $camera = shift; # user-specified camera
    7074
    7175    my ( $vol, $path, $name ) = File::Spec->splitpath( $absfile );
     
    7478    my $relfile = $ipprc->convert_filename_relative( $absfile );
    7579
    76     my $command_exp = "$pxinject -newExp -exp_name $exp_name -inst $instrument -telescope $telescope -imfiles 1 -workdir $workdir" ; # Command to run
    77     if ($dbname) {
    78         $command_exp = "$command_exp -dbname $dbname";
    79     }
     80    # the telescope, instrument, and exp_name used here are temporary : register replaces them with the true values
     81    my $command_exp = "$pxinject -newExp";
     82    $command_exp .= " -tmp_exp_name $exp_name";
     83    $command_exp .= " -tmp_inst $camera";
     84    $command_exp .= " -tmp_telescope $telescope";
     85    $command_exp .= " -workdir $workdir";
     86    $command_exp .= " -dbname $dbname" if defined $dbname;
    8087
    8188    my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) =
     
    8693    my $exp_id = $line[2];      # The exposure tag
    8794   
    88     # XXX the class_id used here should be temporary : register should replace it with the true class_id
    89     my $command_imfile = "$pxinject -newImfile -exp_id $exp_id -exp_name $exp_name -class fpa -class_id fpa -uri $relfile"; # Command to run
    90     if ($dbname) {
    91         $command_imfile = "$command_imfile -dbname $dbname";
    92     }
     95    # the class_id used here is temporary : register replaces it with the true class_id
     96    my $command_imfile = "$pxinject -newImfile";
     97    $command_imfile .= " -exp_id $exp_id";
     98    $command_imfile .= " -tmp_class_id fpa";
     99    $command_imfile .= " -uri $relfile";
     100    $command_imfile .= " -dbname $dbname" if defined ($dbname);
    93101   
    94102    my ( $success_imfile, $error_code_imfile, $full_buf_imfile, $stdout_buf_imfile, $stderr_buf_imfile ) = run( command => $command_imfile, verbose => 1 );
    95103    die "Unable to inject $exp_name imfile: $error_code_imfile\n" if not $success_imfile;
     104
     105    # the class_id used here is temporary : register replaces it with the true class_id
     106    my $command_update = "$pxinject -updatenewExp";
     107    $command_update .= " -exp_id $exp_id";
     108    $command_update .= " -state run";
     109    $command_update .= " -dbname $dbname" if defined ($dbname);
     110   
     111    my ( $success_update, $error_code_update, $full_buf_update, $stdout_buf_update, $stderr_buf_update ) = run( command => $command_update, verbose => 1 );
     112    die "Unable to update $exp_name: $error_code_update\n" if not $success_update;
    96113
    97114    return 1;
  • trunk/ippScripts/scripts/ipp_serial_inject_mosaic.pl

    r13275 r14039  
    11#!/usr/bin/env perl
     2
     3# this program injects a set of multi-file exposures into the db.  the
     4# program takes a list of base exposure names and injects all files
     5# associated with the exposure.  It constructs the expected filenames
     6# from the exposure tag and rules for the camera.  This program is for
     7# the test only since it requires too much information at the inject
     8# stage.  use 'ipp_serial_inject.pl' for single-file images and
     9# 'ipp_serial_inject_split.pl' for multiple file images in split
     10# format
     11
     12# this program should not fail because of the data format or the
     13# configuration, except for the very basic database setup.
    214
    315use warnings;
     
    7587}
    7688
    77 foreach my $exp ( @ARGV ) {
    78     my $command = "$pxinject -newExp -exp_id $exp -inst $camera -telescope $telescope -workdir $workdir -dbname $dbname -imfiles " . (scalar @classes or 1) ; # Command to run
     89foreach my $exp_name ( @ARGV ) {
     90    my $command = "$pxinject -newExp";
     91    " -exp_name $exp_name";
     92    " -inst $camera";
     93    " -telescope $telescope";
     94    " -workdir $workdir";
     95    " -dbname $dbname" if defined $dbname;
     96    " -imfiles " . (scalar @classes or 1) ; # Command to run
     97
    7998    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8099        run( command => $command, verbose => 1 );
    81     die "Unable to inject $exp: $error_code\n" if not $success;
     100    die "Unable to inject $exp_name: $error_code\n" if not $success;
    82101   
    83102    my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag
    84     my $exp_tag = $line[2];     # The exposure tag
     103    my $exp_id = $line[2];      # The exposure tag
    85104    for (my $i = 0; $i < scalar @classes; $i++) {
    86105        my $class_id = $classes[$i];
    87106        my $file_id = $files[$i];
    88         my $filename = $exp . $file_id . '.fits';
    89         $filename = caturi( $exp, $filename ) if defined $add_dir;
     107        my $filename = $exp_name . $file_id . '.fits';
     108        $filename = caturi( $exp_name, $filename ) if defined $add_dir;
    90109        $filename = caturi( $path, $filename );
    91110
     
    93112
    94113        $filename = $ipprc->convert_filename_relative( $filename );
    95         my $command = "$pxinject -newImfile -exp_tag $exp_tag -class chip -class_id $class_id -uri $filename -dbname $dbname"; # Command to run
     114        my $command = "$pxinject -newImfile";
     115        " -exp_id $exp_id";
     116        " -exp_name $exp_name";
     117        " -class chip";
     118        " -class_id $class_id";
     119        " -uri $filename";
     120        " -dbname $dbname" if defined ($dbname); # Command to run
     121
    96122        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    97123            run( command => $command, verbose => 1 );
  • trunk/ippScripts/scripts/register_exp.pl

    r14021 r14039  
    136136}
    137137
    138 my $exp_type = &STATS_value_for_flag ("-exp_type");
     138my $exp_type = &STATS_value_for_flag ($STATS, "-exp_type");
    139139
    140140# Add the detrend flag, if needed
  • trunk/ippScripts/scripts/register_imfile.pl

    r14021 r14039  
    3838use Pod::Usage qw( pod2usage );
    3939
    40 my ($cache, $exp_id, $class_id, $exp_name, $uri, $workdir, $dbname, $no_update, $no_op);
     40my ($cache, $exp_id, $tmp_class_id, $exp_name, $uri, $workdir, $dbname, $no_update, $no_op);
    4141GetOptions(
    42     'caches'        => \$cache,
    43     'exp_id|e=s'    => \$exp_id,
    44     'class_id|i=s'  => \$class_id,
    45     'exp_name|n=s'  => \$exp_name,
    46     'uri|u=s'       => \$uri,
    47     'workdir|w=s'   => \$workdir, # Working directory for output files
    48     'dbname|d=s'    => \$dbname,# Database name
    49     'no-update'     => \$no_update,
    50     'no-op'         => \$no_op,
     42    'caches'           => \$cache,
     43    'exp_id|e=s'       => \$exp_id,
     44    'tmp_class_id|i=s' => \$tmp_class_id,
     45    'exp_name|n=s'     => \$exp_name,
     46    'uri|u=s'          => \$uri,
     47    'workdir|w=s'      => \$workdir, # Working directory for output files
     48    'dbname|d=s'       => \$dbname,# Database name
     49    'no-update'        => \$no_update,
     50    'no-op'            => \$no_op,
    5151) or pod2usage( 2 );
    5252
    5353pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    54 pod2usage( -msg => "Required options: --exp_id --class_id --exp_name --uri",
     54pod2usage( -msg => "Required options: --exp_id --tmp_class_id --exp_name --uri",
    5555           -exitval => 3) unless
    5656    defined $exp_id and
    57     defined $class_id and
     57    defined $tmp_class_id and
    5858    defined $exp_name and
    5959    defined $uri;
     
    7979       { name => "FPA.TELESCOPE",  type => "constant", flag => "-telescope" }, # Telescope
    8080       { name => "FPA.INSTRUMENT", type => "constant", flag => "-inst" },      # Instrument
    81        { name => "CHIP.TEMP"       type => "mean",     flag => "-ccd_temp" }, # CCD temperature
    82        { name => "CELL.EXPOSURE"   type => "mean",     flag => "-exp_time" }, # Exposure time
    83        { name => "SAT_PIXEL_FRAC"  type => "mean",     flag => "-sat_pixel_frac" } # fraction of saturated pixels
     81       { name => "CHIP.TEMP",      type => "mean",     flag => "-ccd_temp" }, # CCD temperature
     82       { name => "CELL.EXPOSURE",  type => "mean",     flag => "-exp_time" }, # Exposure time
     83       { name => "SAT_PIXEL_FRAC", type => "mean",     flag => "-sat_pixel_frac" }, # fraction of saturated pixels
    8484       { name => "ROBUST_MEDIAN",  type => "mean",     flag => "-bg" },
    8585       { name => "ROBUST_MEDIAN",  type => "stdev",    flag => "-bg_mean_stdev" },
     
    114114    unless ($success) {
    115115        $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, $class_id, $error_code);
     116        &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $exp_name, $tmp_class_id, $error_code);
    117117    }
    118118   
     
    121121    my $metadata = $mdcParser->parse(join "", @$stdout_buf); # XXX is this join necessary?
    122122    unless ($metadata) {
    123         &my_die ("Unable to parse metadata config doc", $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
     123        &my_die ("Unable to parse metadata config doc", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_PROG_ERROR);
    124124    }
    125125
     
    127127    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    128128    unless ($stats->parse($metadata)) {
    129         &my_die ("Unable to find all values", $exp_id, $class_id, $PS_EXIT_CONFIG_ERROR);
    130     }
    131 }
     129        &my_die ("Unable to find all values", $exp_id, $exp_name, $tmp_class_id, $PS_EXIT_CONFIG_ERROR);
     130    }
     131}
     132
     133# we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type
     134if (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); }
     135if (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); }
     136if (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); }
     137if (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); }
     138if (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); }
    132139
    133140my $command = "$regtool -addprocessedimfile";
    134141$command .= " -exp_id $exp_id";
    135 $command .= " -temp_class_id $class_id"; # the original class_id supplied by the user, replace by ppStats CLASS.ID
    136142$command .= " -exp_name $exp_name"; # keep the supplied exp_name (could be derived from the file)
     143$command .= " -tmp_class_id $tmp_class_id"; # the original class_id supplied by the user, replace by ppStats CLASS.ID
    137144$command .= " -dbname $dbname" if defined $dbname;
    138145
     
    153160        exit($error_code);
    154161    }
     162} else {
     163    print "skipping command: $command\n";
    155164}
    156165
     
    173182    my $msg = shift; # Warning message on die
    174183    my $exp_id = shift;
    175     my $class_id = shift;
     184    my $exp_name = shift;
     185    my $tmp_class_id = shift;
    176186    my $exit_code = shift;
    177187
     188    # for failed imfiles, we insert UNKNOWN for inst, telescope, class_id
     189
    178190    carp($msg);
    179     if ($exp_id && $class_id and not $no_update) {
     191    if ($exp_id && $tmp_class_id and not $no_update) {
    180192        my $command = "$regtool -addprocessedimfile";
    181193        $command .= " -exp_id $exp_id";
    182         $command .= " -class_id $class_id";
     194        $command .= " -exp_name $exp_name";
     195        $command .= " -tmp_class_id $tmp_class_id";
     196        $command .= " -telescope UNKNOWN";
     197        $command .= " -inst UNKNOWN";
     198        $command .= " -class_id $tmp_class_id";
    183199        $command .= " -code $exit_code";
    184200        $command .= " -dbname $dbname" if defined $dbname;
    185 ###        system ($command);
     201        system ($command);
    186202    }
    187203    exit $exit_code;
     204}
     205
     206sub STATS_value_for_flag
     207{
     208    my $STATS = shift;
     209    my $flag  = shift;
     210
     211    foreach my $entry (@$STATS) {
     212        if ($flag eq $entry->{flag}) {
     213            return $entry->{value};
     214        }
     215    }
     216    return 'NAN';
    188217}
    189218
Note: See TracChangeset for help on using the changeset viewer.