IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 7, 2008, 9:56:11 AM (18 years ago)
Author:
eugene
Message:

converting to ppStatsFromMetadata

File:
1 edited

Legend:

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

    r19938 r19942  
    1919use IPC::Cmd 0.36 qw( can_run run );
    2020use PS::IPP::Metadata::Config;
    21 use PS::IPP::Metadata::Stats;
    2221use PS::IPP::Metadata::List qw( parse_md_list );
    2322use PS::IPP::Config 1.01 qw( :standard );
     
    7978&my_die("Unrecognised ADDSTAR recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe1;
    8079
    81 # values to extract from output metadata and the stats to calculate
    82 # these should be coming from the psastro results
    83 my $CHIPSTATS =
    84     [
    85         #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
    86         { name => "bg",             type => "mean",  flag => "-bg",             dtype => "float" },
    87         { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",       dtype => "float" },
    88         { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
    89         { name => "bias",           type => "mean",  flag => "-bias",           dtype => "float" },
    90         { name => "bias_stdev",     type => "rms",   flag => "-bias_stdev",     dtype => "float" },
    91         { name => "fringe_0",       type => "mean",  flag => "-fringe_0",       dtype => "float" },
    92         { name => "fringe_1",       type => "rms",   flag => "-fringe_1",       dtype => "float" },
    93         { name => "fringe_2",       type => "stdev", flag => "-fringe_2",       dtype => "float" },
    94         { name => "ap_resid",       type => "mean",  flag => "-ap_resid",       dtype => "float" },
    95         { name => "ap_resid_stdev", type => "rms",   flag => "-ap_resid_stdev", dtype => "float" },
    96         { name => "fwhm_major",     type => "mean",  flag => "-fwhm_major",     dtype => "float" },
    97         { name => "fwhm_minor",     type => "mean",  flag => "-fwhm_minor",     dtype => "float" },
    98         { name => "n_stars",        type => "sum",   flag => "-n_stars",        dtype => "int"   },
    99         { name => "n_extended",     type => "sum",   flag => "-n_extended",     dtype => "int"   },
    100         { name => "n_cr",           type => "sum",   flag => "-n_cr",           dtype => "int"   },
    101         ];
    102 my $chipStats = PS::IPP::Metadata::Stats->new($CHIPSTATS); # Stats parser
    103 
    104 # values to extract from camera-level output metadata and the stats to calculate
    105 my $CAMSTATS =
    106    [
    107        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
    108       { name => "CERROR",         type => "rms",   flag => "-sigma_ra",       dtype => "float" },
    109       { name => "CERROR",         type => "rms",   flag => "-sigma_dec",      dtype => "float" },
    110 #      { name => "DT_ASTR",        type => "sum",   flag => "-dtime_astrom",   dtype => "float" },
    111       { name => "NASTRO",         type => "sum",   flag => "-n_astrom",       dtype => "int"   },
    112 #     { name => "ZP??",           type => "mean",  flag => "-zp_mean",        dtype => "float" },
    113 #     { name => "ZP??",           type => "rms",   flag => "-zp_stdev",       dtype => "float" },
    114    ];
    115 my $camStats = PS::IPP::Metadata::Stats->new($CAMSTATS); # Stats parser
    116 
    11780# Look for programs we need
    11881my $missing_tools;
     
    12083my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    12184my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     85my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    12286
    12387# test for addstar and psastro:
     
    13195
    13296my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     97
     98my $cmdflags;
    13399
    134100# Get list of component files
     
    150116        &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR);
    151117
    152     # extract the stats from the metadata
    153     unless ($chipStats->parse($metadata)) {
    154         &my_die("Unable to find all values in statistics output.\n", $cam_id, $PS_EXIT_PROG_ERROR);
     118    # since I can't figure out how to do input and output within PERL, I'm writing to a temp file
     119    my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.cm.$cam_id.stats.XXXX", UNLINK => !$save_temps );
     120    print "saving stats to $statName\n";
     121    foreach my $line (@$stdout_buf) {
     122        print $statFile $line;
     123    }
     124    close $statFile;
     125
     126    # parse the stats in the metadata file
     127    $command = "$ppStatsFromMetadata $statName - CAMERA_EXP_IMFILE";
     128    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     129        run(command => $command, verbose => $verbose);
     130    unless ($success) {
     131        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     132        warn("Unable to perform ppStatsFromMetadata: $error_code\n");
     133        exit($error_code);
     134    }
     135
     136    foreach my $line (@$stdout_buf) {
     137        $cmdflags .= " $line";
    155138    }
    156139}
     
    248231    if ($chipObjectsExist) {
    249232        # run psastro on the chipObjects, producing fpaObjects
    250         # XXX add a ppStats call which will collect the astrometry stats
    251233        my $command;
    252234        $command  = "$psastro -list $list3Name $outroot";
     
    256238        my $do_stats;
    257239        if ($run_state eq 'new') {
    258             $command .= " -stats $fpaStats -recipe PPSTATS CHIPSTATS";
     240            $command .= " -stats $fpaStats -recipe PPSTATS CAMSTATS";
    259241            $command .= " -dumpconfig $configuration";
    260242            $do_stats = 1;
     
    275257
    276258        if ($do_stats) {
    277             &my_die("Unable to find expected output file: $fpaStats",   $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
    278 
    279             # Get the statistics on the processed image
    280             my $statsFile;              # File handle
    281             open $statsFile, $ipprc->file_resolve($fpaStats) or &my_die("Can't open statistics file $fpaStats: $!", $cam_id, $PS_EXIT_SYS_ERROR);
    282             my @contents = <$statsFile>; # Contents of file
    283             close $statsFile;
    284 
    285             # parse the statistics MDC file
    286             my $mdcParser = PS::IPP::Metadata::Config->new();   # Parser for metadata config files
    287             my $metadata = $mdcParser->parse(join "", @contents);
    288             unless ($metadata) {
    289                 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
    290             }
    291 
    292             # extract the stats from the metadata
    293             unless ($camStats->parse($metadata)) {
    294                 &my_die("Failure extracting metadata from the statistics output file.\n", $cam_id, $PS_EXIT_PROG_ERROR);
    295             }
     259            my $fpaStatsReal = $ipprc->file_resolve($fpaStats);
     260            &my_die("Couldn't find expected output file: $fpaStats", $cam_id, $PS_EXIT_SYS_ERROR) unless -f $fpaStatsReal;
     261
     262            # parse stats from metadata
     263            $command = "$ppStatsFromMetadata $fpaStatsReal - CAMERA_EXP_FPA";
     264            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     265                run(command => $command, verbose => $verbose);
     266            unless ($success) {
     267                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     268                &my_die("Unable to perform ppStatsFromMetadata: $error_code", $cam_id, $error_code);
     269            }
     270            foreach my $line (@$stdout_buf) {
     271                $cmdflags .= " $line";
     272            }
     273            chomp $cmdflags;
    296274        }
    297275
     
    340318}
    341319
    342 
    343320my $fpaCommand = "$camtool -cam_id $cam_id";
    344321if ($run_state eq 'new') {
     
    346323    $fpaCommand .= " -uri UNKNOWN";
    347324    $fpaCommand .= " -path_base $outroot";
    348     $fpaCommand .= $chipStats->cmdflags();
    349     $fpaCommand .= $camStats->cmdflags();
     325    $fpaCommand .= " $cmdflags";
    350326    $fpaCommand .= " -hostname $host" if defined $host;
    351327    $fpaCommand .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
Note: See TracChangeset for help on using the changeset viewer.