Changeset 19942 for trunk/ippScripts/scripts/camera_exp.pl
- Timestamp:
- Oct 7, 2008, 9:56:11 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/camera_exp.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/camera_exp.pl
r19938 r19942 19 19 use IPC::Cmd 0.36 qw( can_run run ); 20 20 use PS::IPP::Metadata::Config; 21 use PS::IPP::Metadata::Stats;22 21 use PS::IPP::Metadata::List qw( parse_md_list ); 23 22 use PS::IPP::Config 1.01 qw( :standard ); … … 79 78 &my_die("Unrecognised ADDSTAR recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe1; 80 79 81 # values to extract from output metadata and the stats to calculate82 # these should be coming from the psastro results83 my $CHIPSTATS =84 [85 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG86 { 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 parser103 104 # values to extract from camera-level output metadata and the stats to calculate105 my $CAMSTATS =106 [107 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG108 { 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 parser116 117 80 # Look for programs we need 118 81 my $missing_tools; … … 120 83 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1); 121 84 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 85 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 122 86 123 87 # test for addstar and psastro: … … 131 95 132 96 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 97 98 my $cmdflags; 133 99 134 100 # Get list of component files … … 150 116 &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR); 151 117 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"; 155 138 } 156 139 } … … 248 231 if ($chipObjectsExist) { 249 232 # run psastro on the chipObjects, producing fpaObjects 250 # XXX add a ppStats call which will collect the astrometry stats251 233 my $command; 252 234 $command = "$psastro -list $list3Name $outroot"; … … 256 238 my $do_stats; 257 239 if ($run_state eq 'new') { 258 $command .= " -stats $fpaStats -recipe PPSTATS C HIPSTATS";240 $command .= " -stats $fpaStats -recipe PPSTATS CAMSTATS"; 259 241 $command .= " -dumpconfig $configuration"; 260 242 $do_stats = 1; … … 275 257 276 258 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; 296 274 } 297 275 … … 340 318 } 341 319 342 343 320 my $fpaCommand = "$camtool -cam_id $cam_id"; 344 321 if ($run_state eq 'new') { … … 346 323 $fpaCommand .= " -uri UNKNOWN"; 347 324 $fpaCommand .= " -path_base $outroot"; 348 $fpaCommand .= $chipStats->cmdflags(); 349 $fpaCommand .= $camStats->cmdflags(); 325 $fpaCommand .= " $cmdflags"; 350 326 $fpaCommand .= " -hostname $host" if defined $host; 351 327 $fpaCommand .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
Note:
See TracChangeset
for help on using the changeset viewer.
