Changeset 14009 for trunk/ippScripts/scripts/detrend_stack.pl
- Timestamp:
- Jul 4, 2007, 1:53:22 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/detrend_stack.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_stack.pl
r13989 r14009 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 PS::IPP::Metadata::Stats;20 20 21 21 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 41 41 'camera|c=s' => \$camera, 42 42 'dbname|d=s' => \$dbname, # Database name 43 'workdir|w=s' => \$workdir, # Working directory, for output files43 'workdir|w=s' => \$workdir, # Working directory, for output files 44 44 'reduction=s' => \$reduction, # Reduction class for processing 45 45 'no-update' => \$no_update, … … 49 49 50 50 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 51 pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera", -exitval => 3 ) 51 pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera", 52 -exitval => 3) 52 53 unless defined $det_id 53 54 and defined $iter … … 64 65 $reduction = "DETREND" unless defined $reduction; 65 66 my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_STACK'); # Recipe name to use 67 68 # values to extract from output metadata and the stats to calculate 69 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A) 70 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 71 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 72 my $STATS = 73 [ 74 # KEYWORD STATISTIC CHIPTOOL FLAG 75 { name => "bg", type => "mean", flag => "-bg" }, 76 { name => "bg", type => "stdev", flag => "-bg_mean_stdev" }, 77 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 78 # { name => "bg_mean_stdev", type => "rms", flag => "-bg_mean_stdev" }, 79 ]; 66 80 67 81 # Look for programs we need … … 74 88 } 75 89 76 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 90 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 91 92 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} ); 93 my $outputStack = $outputRoot . '.fits'; # Output name 94 my $outputStats = $outputRoot . '.stats'; # Statistics name 77 95 78 96 # Get list of files to stack 79 97 my $files; # Array of files to be stacked 80 98 { 81 my $command = "$dettool -processedimfile -det_id $det_id -class_id $class_id -included"; # Command to run 99 my $command = "$dettool -processedimfile -included"; 100 $command .= " -det_id $det_id"; 101 $command .= " -class_id $class_id"; 82 102 $command .= " -dbname $dbname" if defined $dbname; 103 83 104 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 84 105 run(command => $command, verbose => $verbose); … … 87 108 &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $iter, $class_id, $error_code); 88 109 } 110 111 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 89 112 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 90 113 &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); … … 93 116 } 94 117 95 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 96 97 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} ); 98 my $outputStack = $outputRoot . '.fits'; # Output name 99 my $outputStats = $outputRoot . '.stats'; # Statistics name 118 my $command = "$ppMerge $outputStack"; # Command to run 119 foreach my $file (@$files) { 120 $command .= ' ' . $file->{uri}; 121 } 122 $command .= " -recipe PPMERGE $recipe"; 123 $command .= ' -type ' . uc($det_type); # Type of stacking to perform 124 $command .= " -stats $outputStats"; # Statistics output filename 125 $command .= " -recipe PPSTATS CHIPSTATS"; 100 126 101 127 # Stack the files 102 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser103 128 unless ($no_op) { 104 my $command = "$ppMerge $outputStack"; # Command to run105 foreach my $file (@$files) {106 $command .= ' ' . $file->{uri};107 }108 $command .= " -recipe PPMERGE $recipe";109 $command .= ' -type ' . uc($det_type); # Type of stacking to perform110 $command .= " -stats $outputStats"; # Statistics output filename111 $command .= " -recipe PPSTATS CHIPSTATS";112 129 113 130 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 129 146 my $metadata = $mdcParser->parse($contents) or 130 147 &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR); 131 $stats = PS::IPP::Metadata::Stats->new(); # Stats parser 148 149 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 132 150 $stats->parse($metadata) or 133 151 &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR); 134 152 } 135 153 136 my $bg = $stats->bg_mean(); 137 my $bg_stdev = $stats->bg_stdev(); 138 my $bg_mean_stdev = $stats->bg_mean_stdev(); 154 # Command to update the database 155 $command = "$dettool -addstacked"; 156 $command .= " -det_id $det_id -iteration $iter"; 157 $command .= " -class_id $class_id"; 158 $command .= " -uri $outputStack"; 159 $command .= " -recip $recipe"; 160 $command .= " -dbname $dbname" if defined $dbname; 161 162 # add in the elements from the selected stats above 163 foreach my $entry (@$STATS) { 164 my $value = $entry->{value}; 165 my $flag = $entry->{flag}; 166 $command .= " $flag $value"; 167 } 139 168 140 169 # Add the resultant into the database 141 170 unless ($no_update) { 142 my $command = "$dettool -addstacked";143 $command .= " -det_id $det_id -iteration $iter";144 $command .= " -class_id $class_id";145 $command .= " -uri $outputStack";146 $command .= " -recip $recipe";147 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";148 $command .= " -dbname $dbname" if defined $dbname;149 150 171 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 151 172 run(command => $command, verbose => $verbose); … … 155 176 exit($error_code); 156 177 } 157 } 158 178 } else { 179 print "skipping command: $command\n"; 180 } 159 181 160 182 sub my_die … … 168 190 carp($msg); 169 191 if ($det_id and $iter and $class_id and not $no_update) { 170 my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code"; 192 my $command = "$dettool -addstacked"; 193 $command .= " -det_id $det_id"; 194 $command .= " -iteration $iter"; 195 $command .= " -class_id $class_id"; 196 $command .= " -code $exit_code"; 171 197 $command .= " -dbname $dbname" if defined $dbname; 172 198 ### system ($command);
Note:
See TracChangeset
for help on using the changeset viewer.
