Changeset 14009 for trunk/ippScripts/scripts/detrend_process_exp.pl
- Timestamp:
- Jul 4, 2007, 1:53:22 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/detrend_process_exp.pl (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_process_exp.pl
r13760 r14009 17 17 use PS::IPP::Metadata::Config; 18 18 use PS::IPP::Metadata::List qw( parse_md_list ); 19 use Statistics::Descriptive;19 use File::Temp qw( tempfile ); 20 20 21 21 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 29 29 ); 30 30 my $ipprc = PS::IPP::Config->new(); # IPP configuration 31 use File::Temp qw( tempfile );32 31 33 32 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); … … 47 46 48 47 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 49 pod2usage( 50 -msg => "Required options: --det_id --det_type --exp_tag --camera", 51 -exitval => 3, 52 ) unless defined $det_id 48 pod2usage( -msg => "Required options: --det_id --det_type --exp_tag --camera", 49 -exitval => 3) 50 unless defined $det_id 53 51 and defined $det_type 54 52 and defined $exp_tag … … 57 55 $ipprc->define_camera($camera); 58 56 59 # Recipes to use , as a function of the detrend type60 use constant RECIPES => { 61 'bin1' => { # We're creating a master --- already processed the input 62 'bias' => 'PPIMAGE_J1_IMAGE_B', # Bias only 63 'dark' => 'PPIMAGE_J1_IMAGE_B', # Dark only 64 'shutter' => 'PPIMAGE_J1_IMAGE_F', # Shutter only 65 'flat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 66 'domeflat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 67 'skyflat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 68 'fringe' => 'PPIMAGE_J1_IMAGE_R', # Fringe only 69 }, 70 'bin2' => { # We're checking the master --- input is not already processed 71 'bias' => 'PPIMAGE_J2_IMAGE_B', # Bias only 72 'dark' => 'PPIMAGE_J2_IMAGE_B', # Dark only 73 'shutter' => 'PPIMAGE_J2_IMAGE_F', # Shutter only 74 'flat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 75 'domeflat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 76 'skyflat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 77 'fringe' => 'PPIMAGE_J2_IMAGE_R', # Fringe only 78 },79 };57 # Recipes to use based on reduction class 58 $reduction = 'DETREND' unless defined $reduction; 59 60 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_IMAGE' . uc($det_type); # Recipe to use 61 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1; 62 63 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_IMAGE' . uc($det_type); # Recipe to use 64 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2; 65 66 # values to extract from output metadata and the stats to calculate 67 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A) 68 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 69 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 70 my $STATS = 71 [ 72 # KEYWORD STATISTIC CHIPTOOL FLAG 73 { name => "bg", type => "mean", flag => "-bg" }, 74 { name => "bg", type => "stdev", flag => "-bg_mean_stdev" }, 75 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 76 # { name => "bg_mean_stdev", type => "rms", flag => "-bg_mean_stdev" }, 77 ]; 80 78 81 79 # Look for programs we need … … 87 85 exit($PS_EXIT_CONFIG_ERROR); 88 86 } 89 90 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files91 87 92 88 # Get list of component files … … 101 97 &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $exp_tag, $error_code); 102 98 } 99 100 # convert stdout to a metadata 101 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 103 102 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 104 103 &my_die("Unable to parse metadata config doc", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR); 104 105 # parse the file info in the metadata 105 106 $files = parse_md_list($metadata) or 106 107 &my_die("Unable to parse metadata list", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR); 107 } 108 109 # Gather the statistics 110 my ($bg, $bg_stdev, $bg_mean_stdev); # The statistics triplet 111 { 112 my @backgrounds; # Array of backgrounds in each component 113 my @variances; # Array of variances for each component 114 foreach my $file (@$files) { 115 &my_die("Unable to find class id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id}; 116 my $class_id = $file->{class_id}; 117 &my_die("Unable to find bg for class_id=$class_id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg}; 118 &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev}; 119 push @backgrounds, $file->{bg}; 120 push @variances, $file->{bg_stdev}**2; 121 } 122 123 { 124 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 125 $stats->add_data(@backgrounds); 126 $bg = ($stats->mean() or 'NAN'); 127 $bg_mean_stdev = ($stats->standard_deviation() or 'NAN'); 128 } 129 { 130 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 131 $stats->add_data(@variances); 132 $bg_stdev = (sqrt( $stats->mean() ) or 'NAN'); 108 109 # parse the stats in the metadata 110 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 111 unless ($stats->parse($metadata)) { 112 &my_die("Unable to find all values in statistics output.\n", $chip_id, $class_id, $PS_EXIT_PROG_ERROR); 133 113 } 134 114 } … … 137 117 my ($list1File, $list1Name) = tempfile( "$exp_tag.detproc.$det_id.b1.list.XXXX", UNLINK => 1 ); 138 118 my ($list2File, $list2Name) = tempfile( "$exp_tag.detproc.$det_id.b2.list.XXXX", UNLINK => 1 ); 139 my @means; # Array of means140 my @stdevs; # Array of stdevs141 119 foreach my $file (@$files) { 142 120 print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n"); 143 121 print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n"); 144 push @means, $file->{bg};145 push @stdevs, $file->{bg_stdev};146 122 } 147 123 close $list1File; … … 153 129 my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1 154 130 my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2 155 156 # Recipes to use in processing157 my $recipe1 = RECIPES->{"bin1"}->{lc($det_type)};158 &my_die("Unrecognised detrend type: $det_type", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe1;159 160 my $recipe2 = RECIPES->{"bin2"}->{lc($det_type)};161 &my_die("Unrecognised detrend type: $det_type", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe2;162 131 163 132 unless ($no_op) { … … 187 156 } 188 157 158 # Command to update the database 159 my $command = "$dettool -addprocessedexp"; 160 $command .= " -det_id $det_id"; 161 $command .= " -exp_tag $exp_tag"; 162 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot"; 163 $command .= " -dbname $dbname" if defined $dbname; 164 165 # add in the elements from the selected stats above 166 foreach my $entry (@$STATS) { 167 my $value = $entry->{value}; 168 my $flag = $entry->{flag}; 169 $command .= " $flag $value"; 170 } 171 172 # Add the processed file to the database 189 173 unless ($no_update) { 190 my $command = "$dettool -addprocessedexp -det_id $det_id -exp_tag $exp_tag";191 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot";192 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";193 $command .= " -dbname $dbname" if defined $dbname;194 174 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 195 175 run(command => $command, verbose => 1); … … 199 179 exit($error_code); 200 180 } 201 } 202 181 } else { 182 print "skipping command: $command\n"; 183 } 203 184 204 185 sub my_die … … 211 192 carp($msg); 212 193 if ($det_id and $exp_tag and not $no_update) { 213 my $command = "$dettool -addprocessedexp -det_id $det_id -exp_tag $exp_tag -code $exit_code"; 194 my $command = "$dettool -addprocessedexp"; 195 $command .= " -det_id $det_id"; 196 $command .= " -exp_tag $exp_tag"; 197 $command .= " -code $exit_code"; 214 198 $command .= " -dbname $dbname" if defined $dbname; 215 199 ### system ($command);
Note:
See TracChangeset
for help on using the changeset viewer.
