Changeset 14115 for trunk/ippScripts/scripts/camera_exp.pl
- Timestamp:
- Jul 10, 2007, 3:18:44 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/camera_exp.pl (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/camera_exp.pl
r13824 r14115 16 16 use IPC::Cmd 0.36 qw( can_run run ); 17 17 use PS::IPP::Metadata::Config; 18 use PS::IPP::Metadata::Stats; 18 19 use PS::IPP::Metadata::List qw( parse_md_list ); 19 use Statistics::Descriptive; 20 20 21 use File::Temp qw( tempfile ); 21 22 … … 34 35 use Pod::Usage qw( pod2usage ); 35 36 36 my ($exp_ id, $cam_id, $recipe, $camera, $dbname, $workdir, $dvodb, $no_update, $no_op);37 my ($exp_tag, $cam_id, $recipe, $camera, $dbname, $workdir, $reduction, $dvodb, $no_update, $no_op); 37 38 GetOptions( 38 'exp_ id=s' => \$exp_id, # Exposure identifier39 'exp_tag=s' => \$exp_tag, # Exposure identifier 39 40 'cam_id=s' => \$cam_id, # Camtool identifier 40 41 'recipe=s' => \$recipe, # Recipe to use … … 42 43 'dbname|d=s' => \$dbname, # Database name 43 44 'workdir|w=s' => \$workdir, # Working directory 45 'reduction=s' => \$reduction, # Reduction class 44 46 'dvodb|w=s' => \$dvodb, # output DVO database 45 47 'no-update' => \$no_update, # Update the database? … … 49 51 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 50 52 pod2usage( 51 -msg => "Required options: --exp_ id--cam_id --camera",53 -msg => "Required options: --exp_tag --cam_id --camera", 52 54 -exitval => 3, 53 ) unless defined $exp_ id55 ) unless defined $exp_tag 54 56 and defined $cam_id 55 57 and defined $camera; … … 57 59 $ipprc->define_camera($camera); 58 60 59 use constant RECIPE1 => 'PPIMAGE_J1'; # Recipe to use for ppImage to make JPEGs 60 use constant RECIPE2 => 'PPIMAGE_J2'; # Recipe to use for ppImage to make JPEGs 61 61 # Recipes to use based on reduction class 62 $reduction = 'DEFAULT' unless defined $reduction; 63 64 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1'); # Recipe to use 65 &my_die("Unrecognised JPEG recipe", $cam_id, $PS_EXIT_PROG_ERROR) unless defined $recipe1; 66 67 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2'); # Recipe to use 68 &my_die("Unrecognised JPEG recipe", $cam_id, $PS_EXIT_PROG_ERROR) unless defined $recipe2; 69 70 # values to extract from output metadata and the stats to calculate 71 my $CHIPSTATS = 72 [ 73 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 74 { name => "bg", type => "mean", flag => "-bg", dtype => "float" }, 75 { name => "bg_mean_stdev", type => "stdev", flag => "-bg_mean_stdev", dtype => "float" }, 76 { name => "bg_stdev", type => "rms", flag => "-bg_stdev", dtype => "float" }, 77 78 # these should be coming from the psastro results for Nimfile > 1, 79 { name => "sigma_ra", type => "rms", flag => "-sigma_ra", dtype => "float" }, 80 { name => "sigma_dec", type => "rms", flag => "-sigma_dec", dtype => "float" }, 81 { name => "n_stars", type => "sum", flag => "-n_stars", dtype => "int" }, 82 { name => "n_astrom", type => "sum", flag => "-n_astrom", dtype => "int" }, 83 84 { name => "fwhm", type => "mean", flag => "-fwhm", dtype => "float" }, 85 86 # these are not defined for the database table camProcessedExp 87 # { name => "ap_resid", type => "mean", flag => "-ap_resid", dtype => "float" }, 88 # { name => "ap_resid_stdev", type => "rms", flag => "-ap_resid_stdev", dtype => "float" }, 89 # { name => "fringe_0", type => "mean", flag => "-fringe_0", dtype => "float" }, 90 # { name => "fringe_1", type => "rms", flag => "-fringe_1", dtype => "float" }, 91 # { name => "fringe_0", type => "stdev", flag => "-fringe_2", dtype => "float" }, 92 ]; 93 my $chipStats = PS::IPP::Metadata::Stats->new($CHIPSTATS); # Stats parser 62 94 63 95 # Look for programs we need … … 90 122 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 91 123 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR); 124 125 # extract the metadata for the files into a hash list 92 126 $files = parse_md_list($metadata) or 93 127 &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR); 94 } 95 96 # Gather the statistics 97 my ($bg, $bg_stdev, $bg_mean_stdev); # The statistics triplet 98 { 99 my @backgrounds; # Array of backgrounds in each component 100 my @variances; # Array of variances for each component 101 # my @ra; # Array of ra errors 102 # my @dec; # Array of dec errors 103 # my @zp; # Array of photometric zero points 104 foreach my $file (@$files) { 105 &my_die("Unable to find class id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id}; 106 my $class_id = $file->{class_id}; 107 &my_die("Unable to find bg for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{bg}; 108 &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev}; 109 # &my_die("Unable to find sigma_ra for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_ra}; 110 # &my_die("Unable to find sigma_dec for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_dec}; 111 # &my_die("Unable to find zp for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{zp}; 112 push @backgrounds, $file->{bg}; 113 push @variances, $file->{bg_stdev}**2; 114 } 115 116 { 117 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 118 $stats->add_data(@backgrounds); 119 $bg = ($stats->mean() or 'NAN'); 120 $bg_mean_stdev = ($stats->standard_deviation() or 'NAN'); 121 } 122 { 123 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 124 $stats->add_data(@variances); 125 $bg_stdev = (sqrt( $stats->mean() ) or 'NAN'); 126 } 127 } 128 129 my ($list1File, $list1Name) = tempfile( "$exp_id.cam$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1 130 my ($list2File, $list2Name) = tempfile( "$exp_id.cam$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2 131 my ($list3File, $list3Name) = tempfile( "$exp_id.cam$cam_id.b3.list.XXXX", UNLINK => 1 ); # For astrometry 132 133 my @means; # Array of means 134 my @stdevs; # Array of stdevs 128 129 # extract the stats from the metadata 130 unless ($chipStats->parse($metadata)) { 131 &my_die("Unable to find all values in statistics output.\n", $cam_id, $PS_EXIT_PROG_ERROR); 132 } 133 } 134 135 my ($list1File, $list1Name) = tempfile( "$exp_tag.cm.$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1 136 my ($list2File, $list2Name) = tempfile( "$exp_tag.cm.$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2 137 my ($list3File, $list3Name) = tempfile( "$exp_tag.cm.$cam_id.b3.list.XXXX", UNLINK => 1 ); # For astrometry 138 135 139 my $chipObjects; 136 140 foreach my $file (@$files) { … … 143 147 print $list2File ($ipprc->filename("PPIMAGE.BIN2", $file->{path_base}, $class_id) . "\n"); 144 148 print $list3File ($chipObjects . "\n"); 145 push @means, $file->{bg};146 push @stdevs, $file->{bg_stdev};147 149 } 148 150 close $list1File; … … 151 153 152 154 # Output products 153 $workdir = caturi( $workdir, $exp_id ) if defined $workdir; 154 my $outputRoot = $ipprc->file_prepare( "$exp_id.cam$cam_id", $workdir, ${$files}[0]->{path_base} ); 155 my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1 156 my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2 155 $workdir = caturi( $workdir, $exp_tag ) if defined $workdir; 156 my $outputRoot = $ipprc->file_prepare( "$exp_tag.cm.$cam_id", $workdir, ${$files}[0]->{path_base} ); 157 158 my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1 159 my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2 157 160 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT.MEF", $outputRoot); # MEF psastro output 158 161 … … 167 170 # run psastro +mosastro on the set of chips 168 171 # XXX note that this is wrong if imfiles are cells 172 # XXX add a ppStats call which will collect the astrometry stats 169 173 if (scalar @$files > 1) { 170 174 my $command = "$psastro -list $list3Name $outputRoot +mosastro -chipastro " . … … 202 206 # Make the jpeg for binning 1 203 207 { 204 my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE " . RECIPE1; # Command to run208 my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run 205 209 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 206 210 run(command => $command, verbose => 1); … … 214 218 # Make the jpeg for binning 2 215 219 { 216 my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE " . RECIPE2; # Command to run220 my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run 217 221 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 218 222 run(command => $command, verbose => 1); … … 224 228 } 225 229 } 230 231 my $fpaCommand = "$camtool -addprocessedexp"; 232 $fpaCommand .= " -cam_id $cam_id"; 233 $fpaCommand .= " -uri UNKNOWN"; 234 $fpaCommand .= " -path_base $outputRoot"; 235 $fpaCommand .= " -dbname $dbname" if defined $dbname; 236 $fpaCommand .= $chipStats->cmdflags(); 226 237 227 238 # Add the result into the database 228 239 unless ($no_update) { 229 230 my $command = "$camtool -addprocessedexp";231 $command .= " -cam_id $cam_id -uri UNKNOWN -path_base $outputRoot";232 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";233 $command .= " -sigma_ra 0.0 -sigma_dec 0.0";234 $command .= " -zp_mean 0.0 -zp_stdev 0.0";235 $command .= " -fwhm 0.0 -fwhm_range 0.0";236 $command .= " -n_stars 0 -n_extended 0 -n_cr 0 -n_astrom 0";237 $command .= " -dbname $dbname" if defined $dbname;238 239 240 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 240 run(command => $ command, verbose => 1);241 run(command => $fpaCommand, verbose => 1); 241 242 unless ($success) { 242 243 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); … … 244 245 exit($error_code); 245 246 } 247 } else { 248 print "skipping command: $fpaCommand\n"; 246 249 } 247 250
Note:
See TracChangeset
for help on using the changeset viewer.
