IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 23, 2008, 5:10:21 PM (18 years ago)
Author:
Paul Price
Message:

Adding hostname to database values.

File:
1 edited

Legend:

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

    r17671 r17803  
    2929     $no_op, $save_temps );
    3030GetOptions(
    31            'exp_tag=s'          => \$exp_tag, # Exposure identifier
    32            'cam_id=s'          => \$cam_id, # Camtool identifier
    33            'recipe=s'          => \$recipe, # Recipe to use
    34            'camera|c=s'        => \$camera, # Camera
    35            'dbname|d=s'        => \$dbname, # Database name
    36            'outroot|w=s'       => \$outroot, # output file base name
    37            'reduction=s'       => \$reduction, # Reduction class                       
    38            'dvodb|w=s'         => \$dvodb,  # output DVO database
    39            'verbose'           => \$verbose,   # Print to stdout
    40            'no-update'         => \$no_update, # Update the database?
    41            'no-op'             => \$no_op, # Don't do any operations?
    42            'save-temps'        => \$save_temps, # Save temporary files?
    43            ) or pod2usage( 2 );
     31           'exp_tag=s'          => \$exp_tag, # Exposure identifier
     32           'cam_id=s'          => \$cam_id, # Camtool identifier
     33           'recipe=s'          => \$recipe, # Recipe to use
     34           'camera|c=s'        => \$camera, # Camera
     35           'dbname|d=s'        => \$dbname, # Database name
     36           'outroot|w=s'       => \$outroot, # output file base name
     37           'reduction=s'       => \$reduction, # Reduction class
     38           'dvodb|w=s'         => \$dvodb,  # output DVO database
     39           'verbose'           => \$verbose,   # Print to stdout
     40           'no-update'         => \$no_update, # Update the database?
     41           'no-op'             => \$no_op, # Don't do any operations?
     42           'save-temps'        => \$save_temps, # Save temporary files?
     43           ) or pod2usage( 2 );
    4444
    4545pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    4646pod2usage(
    47           -msg => "Required options: --exp_tag --cam_id --camera --outroot",
    48           -exitval => 3,
    49           ) unless
     47          -msg => "Required options: --exp_tag --cam_id --camera --outroot",
     48          -exitval => 3,
     49          ) unless
    5050    defined $exp_tag and
    5151    defined $cam_id and
     
    6666# values to extract from output metadata and the stats to calculate
    6767# these should be coming from the psastro results
    68 my $CHIPSTATS = 
    69     [   
    70         #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
    71         { name => "bg",             type => "mean",  flag => "-bg",             dtype => "float" },
    72         { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",       dtype => "float" }, 
    73         { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
    74         { name => "bias",           type => "mean",  flag => "-bias",           dtype => "float" }, 
    75         { name => "bias_stdev",     type => "rms",   flag => "-bias_stdev",     dtype => "float" }, 
    76         { name => "fringe_0",       type => "mean",  flag => "-fringe_0",       dtype => "float" }, 
    77         { name => "fringe_1",       type => "rms",   flag => "-fringe_1",       dtype => "float" }, 
    78         { name => "fringe_0",       type => "stdev", flag => "-fringe_2",       dtype => "float" }, 
    79         { name => "sigma_ra",       type => "rms",   flag => "-sigma_ra",       dtype => "float" }, 
    80         { name => "sigma_dec",      type => "rms",   flag => "-sigma_dec",      dtype => "float" }, 
    81         { name => "ap_resid",       type => "mean",  flag => "-ap_resid",       dtype => "float" }, 
    82         { name => "ap_resid_stdev", type => "rms",   flag => "-ap_resid_stdev", dtype => "float" }, 
    83         { name => "zp_mean",        type => "mean",  flag => "-zp_mean",        dtype => "float" }, 
    84         { name => "zp_stdev",       type => "rms",   flag => "-zp_stdev",       dtype => "float" }, 
    85         { name => "fwhm_major",     type => "mean",  flag => "-fwhm_major",     dtype => "float" }, 
    86         { name => "fwhm_minor",     type => "mean",  flag => "-fwhm_minor",     dtype => "float" }, 
    87         { name => "dtime_detrend",  type => "sum",   flag => "-dtime_detrend",  dtype => "float" }, 
    88         { name => "dtime_photom",   type => "sum",   flag => "-dtime_photom",   dtype => "float" }, 
    89         { name => "dtime_astrom",   type => "sum",   flag => "-dtime_astrom",   dtype => "float" }, 
    90         { name => "n_stars",        type => "sum",   flag => "-n_stars",        dtype => "int"   }, 
    91         { name => "n_extended",     type => "sum",   flag => "-n_extended",     dtype => "int"   }, 
    92         { name => "n_cr",           type => "sum",   flag => "-n_cr",           dtype => "int"   }, 
    93         { name => "n_astrom",       type => "sum",   flag => "-n_astrom",       dtype => "int"   }, 
     68my $CHIPSTATS =
     69    [
     70        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
     71        { name => "bg",             type => "mean",  flag => "-bg",             dtype => "float" },
     72        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",       dtype => "float" },
     73        { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
     74        { name => "bias",           type => "mean",  flag => "-bias",           dtype => "float" },
     75        { name => "bias_stdev",     type => "rms",   flag => "-bias_stdev",     dtype => "float" },
     76        { name => "fringe_0",       type => "mean",  flag => "-fringe_0",       dtype => "float" },
     77        { name => "fringe_1",       type => "rms",   flag => "-fringe_1",       dtype => "float" },
     78        { name => "fringe_0",       type => "stdev", flag => "-fringe_2",       dtype => "float" },
     79        { name => "sigma_ra",       type => "rms",   flag => "-sigma_ra",       dtype => "float" },
     80        { name => "sigma_dec",      type => "rms",   flag => "-sigma_dec",      dtype => "float" },
     81        { name => "ap_resid",       type => "mean",  flag => "-ap_resid",       dtype => "float" },
     82        { name => "ap_resid_stdev", type => "rms",   flag => "-ap_resid_stdev", dtype => "float" },
     83        { name => "zp_mean",        type => "mean",  flag => "-zp_mean",        dtype => "float" },
     84        { name => "zp_stdev",       type => "rms",   flag => "-zp_stdev",       dtype => "float" },
     85        { name => "fwhm_major",     type => "mean",  flag => "-fwhm_major",     dtype => "float" },
     86        { name => "fwhm_minor",     type => "mean",  flag => "-fwhm_minor",     dtype => "float" },
     87        { name => "dtime_detrend",  type => "sum",   flag => "-dtime_detrend",  dtype => "float" },
     88        { name => "dtime_photom",   type => "sum",   flag => "-dtime_photom",   dtype => "float" },
     89        { name => "dtime_astrom",   type => "sum",   flag => "-dtime_astrom",   dtype => "float" },
     90        { name => "n_stars",        type => "sum",   flag => "-n_stars",        dtype => "int"   },
     91        { name => "n_extended",     type => "sum",   flag => "-n_extended",     dtype => "int"   },
     92        { name => "n_cr",           type => "sum",   flag => "-n_cr",           dtype => "int"   },
     93        { name => "n_astrom",       type => "sum",   flag => "-n_astrom",       dtype => "int"   },
    9494
    9595
    9696# these are not defined for the database table camProcessedExp
    97         ];
     97        ];
    9898my $chipStats = PS::IPP::Metadata::Stats->new($CHIPSTATS); # Stats parser
    9999
     
    108108my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
    109109
    110 if ($missing_tools) { 
     110if ($missing_tools) {
    111111    warn("Can't find required tools.");
    112     exit($PS_EXIT_CONFIG_ERROR); 
    113 }
    114 
    115 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     112    exit($PS_EXIT_CONFIG_ERROR);
     113}
     114
     115my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    116116
    117117# Get list of component files
    118 my $files;                      # Array of component files
     118my $files;                      # Array of component files
    119119{
    120120    my $command = "$camtool -pendingimfile -cam_id $cam_id"; # Command to run
    121121    $command .= " -dbname $dbname" if defined $dbname;
    122122    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    123         run(command => $command, verbose => $verbose);
     123        run(command => $command, verbose => $verbose);
    124124    unless ($success) {
    125         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    126         &my_die("Unable to perform camtool: $error_code", $cam_id, $error_code);
     125        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     126        &my_die("Unable to perform camtool: $error_code", $cam_id, $error_code);
    127127    }
    128128    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    129         &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
     129        &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
    130130
    131131    # extract the metadata for the files into a hash list
    132132    $files = parse_md_list($metadata) or
    133         &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR);
     133        &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR);
    134134
    135135    # extract the stats from the metadata
    136136    unless ($chipStats->parse($metadata)) {
    137         &my_die("Unable to find all values in statistics output.\n", $cam_id, $PS_EXIT_PROG_ERROR);
     137        &my_die("Unable to find all values in statistics output.\n", $cam_id, $PS_EXIT_PROG_ERROR);
    138138    }
    139139}
     
    145145
    146146# XXX we perform astrometry iff photometry output exists
    147 my $chipObjects; 
     147my $chipObjects;
    148148my $chipObjectsExist = 0;
    149149foreach my $file (@$files) {
     
    160160    # if any of the output chip photometry files exist, we can run psastro / addstar below
    161161    if ($ipprc->file_exists($chipObjects)) {
    162         $chipObjectsExist = 1;
     162        $chipObjectsExist = 1;
    163163    }
    164164}
     
    171171
    172172# the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
    173 my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    174 my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
     173my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
     174my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    175175my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    176176my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    177 my $logDest    = $ipprc->filename("LOG.EXP",            $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
     177my $logDest    = $ipprc->filename("LOG.EXP",            $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    178178
    179179# convert supplied DVO database name to UNIX filename
     
    190190    # Make the jpeg for binning 1
    191191    {
    192         my $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
    193         $command .= " -dbname $dbname" if defined $dbname;
    194 
    195         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    196             run(command => $command, verbose => $verbose);
    197         unless ($success) {
    198             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    199             &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
    200         }
    201         &my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg1);
     192        my $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
     193        $command .= " -dbname $dbname" if defined $dbname;
     194
     195        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     196            run(command => $command, verbose => $verbose);
     197        unless ($success) {
     198            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     199            &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
     200        }
     201        &my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg1);
    202202    }
    203203
    204204    # Make the jpeg for binning 2
    205205    {
    206         my $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
    207         $command .= " -dbname $dbname" if defined $dbname;
    208 
    209         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    210             run(command => $command, verbose => $verbose);
    211         unless ($success) {
    212             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    213             &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
    214         }
    215         &my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg2);
     206        my $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
     207        $command .= " -dbname $dbname" if defined $dbname;
     208
     209        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     210            run(command => $command, verbose => $verbose);
     211        unless ($success) {
     212            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     213            &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
     214        }
     215        &my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg2);
    216216    }
    217217
    218218    # only run psastro / addstar if any of the output chip astrometry files exist (should we test for successful astrometry?)
    219219    if ($chipObjectsExist) {
    220         # run psastro on the chipObjects, producing fpaObjects
    221         # XXX add a ppStats call which will collect the astrometry stats
    222         my $command;
    223         $command  = "$psastro -list $list3Name $outroot";
    224         $command .= " -tracedest $traceDest -log $logDest";
    225         $command .= " -dbname $dbname" if defined $dbname;
    226 
    227         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    228             run(command => $command, verbose => $verbose);
    229         unless ($success) {
    230             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    231             &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
    232         }
    233         # XXX do we want to give an error if astrometry fails here?
    234         &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
    235        
    236         # run addstar on the output fpaObjects (if a DVO database is defined)
    237         if (defined $dvodbReal) {
    238             # XXX this construct requires the user to have a valid .ptolemyrc
    239             # XXX which in turn points at ippconfig/dvo.site
    240             # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
    241             # XXX this needs to be converted to addstar_client...
    242 
    243             my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
    244             my $command;
    245             $command  = "$addstar -D CAMERA $camdir -update";
    246             $command .= " -D CATDIR $dvodbReal";
    247 
    248             my $realFile = $ipprc->file_resolve($fpaObjects);
    249             $command .= " $realFile";
    250 
    251             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    252                 run(command => $command, verbose => $verbose);
    253             unless ($success) {
    254                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    255                 &my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
    256             }
    257         }
     220        # run psastro on the chipObjects, producing fpaObjects
     221        # XXX add a ppStats call which will collect the astrometry stats
     222        my $command;
     223        $command  = "$psastro -list $list3Name $outroot";
     224        $command .= " -tracedest $traceDest -log $logDest";
     225        $command .= " -dbname $dbname" if defined $dbname;
     226
     227        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     228            run(command => $command, verbose => $verbose);
     229        unless ($success) {
     230            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     231            &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
     232        }
     233        # XXX do we want to give an error if astrometry fails here?
     234        &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
     235
     236        # run addstar on the output fpaObjects (if a DVO database is defined)
     237        if (defined $dvodbReal) {
     238            # XXX this construct requires the user to have a valid .ptolemyrc
     239            # XXX which in turn points at ippconfig/dvo.site
     240            # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
     241            # XXX this needs to be converted to addstar_client...
     242
     243            my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
     244            my $command;
     245            $command  = "$addstar -D CAMERA $camdir -update";
     246            $command .= " -D CATDIR $dvodbReal";
     247
     248            my $realFile = $ipprc->file_resolve($fpaObjects);
     249            $command .= " $realFile";
     250
     251            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     252                run(command => $command, verbose => $verbose);
     253            unless ($success) {
     254                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     255                &my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
     256            }
     257        }
    258258    }
    259259}
     
    263263$fpaCommand .= " -uri UNKNOWN";
    264264$fpaCommand .= " -path_base $outroot";
     265$fpaCommand .= " -hostname $host" if defined $host;
    265266$fpaCommand .= " -dbname $dbname" if defined $dbname;
    266267$fpaCommand .= $chipStats->cmdflags();
     
    269270unless ($no_update) {
    270271    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    271         run(command => $fpaCommand, verbose => $verbose);
     272        run(command => $fpaCommand, verbose => $verbose);
    272273    unless ($success) {
    273         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    274         warn("Unable to add result to database: $error_code\n");
    275         exit($error_code);
     274        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     275        warn("Unable to add result to database: $error_code\n");
     276        exit($error_code);
    276277    }
    277278} else {
     
    288289    carp($msg);
    289290    if (defined $cam_id and not $no_update) {
    290         my $command = "$camtool -addprocessedexp -cam_id $cam_id -uri UNKNOWN -code $exit_code";
    291         $command .= " -dbname $dbname" if defined $dbname;
     291        my $command = "$camtool -addprocessedexp -cam_id $cam_id -uri UNKNOWN -code $exit_code";
     292        $command .= " -hostname $host" if defined $host;
     293        $command .= " -dbname $dbname" if defined $dbname;
    292294        system ($command);
    293295    }
Note: See TracChangeset for help on using the changeset viewer.