- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/flatcorr_proc.pl (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_branches/ippScripts/scripts/flatcorr_proc.pl
r23688 r27839 11 11 # dvoMakeCorr -file outgrid.fits -ref ref.fits outcorr 12 12 13 # dettool -register -det_type FLATCORR -filelevel (level) -workdir -inst, etc 14 15 # foreach $imfile () 13 # dettool -register -det_type FLATCORR -filelevel (level) -workdir -inst, etc 14 15 # foreach $imfile () 16 16 # dettool -register_imfile -uri, etc, etc 17 17 … … 23 23 use Sys::Hostname; 24 24 my $host = hostname(); 25 my $date = `date`; 25 26 print "\n\n"; 26 print "Starting script $0 on $host \n\n";27 print "Starting script $0 on $host at $date\n\n"; 27 28 28 29 use vars qw( $VERSION ); … … 42 43 use Pod::Usage qw( pod2usage ); 43 44 44 my ($corr_id, $det_type, $dvodb, $camera, $region, $filter, $dbname, $workdir, $ verbose, $no_update, $no_op);45 my ($corr_id, $det_type, $dvodb, $camera, $region, $filter, $dbname, $workdir, $make_correction, $verbose, $no_update, $no_op); 45 46 GetOptions( 46 47 'corr_id|i=s' => \$corr_id, … … 52 53 'dbname|d=s' => \$dbname,# Database name 53 54 'workdir|w=s' => \$workdir, # Working directory for output files 54 'verbose' => \$verbose, # Print to stdout 55 'make_correction' => \$make_correction, # Generate the correction image and save to the detrend database 56 'verbose' => \$verbose, # Print to stdout 55 57 'no-update' => \$no_update, 56 58 'no-op' => \$no_op, … … 73 75 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1); 74 76 my $dvoMakeCorr = can_run('dvoMakeCorr') or (warn "Can't find dvoMakeCorr" and $missing_tools = 1); 75 my $detselect = can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1);76 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);77 my $flatcorr = can_run('flatcorr') or (warn "Can't find flatcorr" and $missing_tools = 1);78 79 if ($missing_tools) { 77 my $detselect = can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1); 78 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1); 79 my $flatcorr = can_run('flatcorr') or (warn "Can't find flatcorr" and $missing_tools = 1); 80 81 if ($missing_tools) { 80 82 warn ("Can't find required tools"); 81 exit($PS_EXIT_CONFIG_ERROR); 83 exit($PS_EXIT_CONFIG_ERROR); 82 84 } 83 85 … … 86 88 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 87 89 88 # XXX either workdir needs to be non-nebulous here, or addstar / relphot need to handle 89 # nebulous interactions... 90 # dvodb must be non-nebulous; workdir may be in nebulous 90 91 my $outgrid = "$dvodb/flatcorr/$camera.$filter.$corr_id"; 91 92 my $outcorr = "$workdir/$camera.$filter.$corr_id"; … … 95 96 $ipprc->outroot_prepare($outcorr); 96 97 97 if (not -e "$dvodb/flatcorr") { 98 if (not -e "$dvodb/flatcorr") { 98 99 mkdir "$dvodb/flatcorr" or &my_die ("Unable to make output directory for relphot $dvodb/flatcorr", $corr_id, 3); 99 100 } … … 105 106 106 107 # Run addstar -resort to ensure the db is indexed 108 # XXX addstar should be able to recognize and skip indexed tables 107 109 { 108 110 my $command = "$addstar -resort"; … … 111 113 112 114 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 113 run(command => $command, verbose => $verbose);114 115 unless ($success) { 116 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);117 &my_die ("Unable to perform addstar -resort for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code);115 run(command => $command, verbose => $verbose); 116 117 unless ($success) { 118 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 119 &my_die ("Unable to perform addstar -resort for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code); 118 120 } 119 121 } … … 134 136 135 137 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 136 run(command => $command, verbose => $verbose); 137 138 unless ($success) { 139 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 140 &my_die ("Unable to perform relphot -grid for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code); 138 run(command => $command, verbose => $verbose); 139 140 unless ($success) { 141 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 142 &my_die ("Unable to perform relphot -grid for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code); 143 } 144 } 145 146 if ($make_correction) { 147 148 # get a single input exposure 149 # flatcorr -inputexp -corr_id $corr_id -limit 1 150 my $chip_id = &get_chip_id(); 151 152 # get the list of imfiles for the single input exposure 153 # flatcorr -inputimfile -chip_id $chip_id 154 my $files = &get_imfiles($chip_id); 155 156 # set up the detrend run to store the corrected imfiles 157 my $det_id = &get_det_id($$files[0]); 158 159 # make the (full-sized) detrend correction images 160 &make_detrend_imfiles($det_id, $files); 161 162 # set the detrun state to 'stop' 163 my $command = "$dettool -updatedetrun"; 164 $command .= " -det_id $det_id"; 165 $command .= " -state stop"; 166 $command .= " -dbname $dbname" if defined $dbname; 167 168 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 169 run(command => $command, verbose => $verbose); 170 171 unless ($success) { 172 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 173 warn ("Unable to perform dettool -updatedetrun: $error_code"); 174 exit($error_code); 175 } 176 } 177 178 # Push the results into the database 179 { 180 my $command = "$flatcorr -addprocess"; 181 $command .= " -corr_id $corr_id"; 182 $command .= " -hostname $host" if defined $host; 183 $command .= " -dbname $dbname" if defined $dbname; 184 185 unless ($no_update) { 186 187 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 188 run(command => $command, verbose => $verbose); 189 unless ($success) { 190 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 191 warn ("Unable to perform regtool -addprocessedimfile: $error_code"); 192 exit($error_code); 193 } 194 } else { 195 print "skipping command: $command\n"; 141 196 } 142 197 } … … 144 199 # get a single input exposure 145 200 # flatcorr -inputexp -corr_id $corr_id -limit 1 146 my $chip_id; 147 { 201 sub get_chip_id { 202 148 203 my $command = "$flatcorr -inputexp"; 149 204 $command .= " -corr_id $corr_id"; … … 164 219 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 165 220 166 # check for existence 221 # check for existence 167 222 my $file = $$files[0]; 168 $chip_id = $file->{chip_id}; 223 my $chip_id = $file->{chip_id}; 224 225 return $chip_id; 169 226 } 170 227 171 228 # get the list of imfiles for the single input exposure 172 229 # flatcorr -inputimfile -chip_id $chip_id 173 my $files; 174 { 230 sub get_imfiles { 231 my $chip_id = shift; 232 175 233 my $command = "$flatcorr -inputimfile"; 176 234 $command .= " -chip_id $chip_id"; … … 187 245 188 246 # extract the metadata for the files into a hash list 189 $files = parse_md_list($metadata) or247 my $files = parse_md_list($metadata) or 190 248 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 249 250 return $files; 191 251 } 192 252 193 253 # set up the detrend run to store the corrected imfiles 194 my $det_id; 195 { 196 # get the filelevel from one of these chips 197 my $file = $$files[0]; 254 sub get_det_id { 255 # get the filelevel from the supplied chip 256 my $file = shift; 198 257 199 258 my $filelevel = $file->{filelevel}; … … 215 274 216 275 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 217 run(command => $command, verbose => $verbose);218 219 unless ($success) { 220 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);221 &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);276 run(command => $command, verbose => $verbose); 277 278 unless ($success) { 279 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 280 &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 222 281 } 223 282 … … 230 289 231 290 # $file = $$output[0]; 232 $det_id = $$output[0]->{det_id}; 233 } 234 235 # use input chip image as a reference image 236 foreach my $file (@$files) { 237 # create the detrend correction for the imfiles based on the input imfiles 238 my $reffile = $file->{uri}; 239 my $class_id = $file->{class_id}; 240 241 my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id); 242 unless ($uri) { 243 &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR); 244 } 245 246 my $command = "$dvoMakeCorr $outcorr"; 247 $command .= " -file $outgrid.fits"; 248 $command .= " -ref $reffile"; 249 250 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 251 run(command => $command, verbose => $verbose); 252 253 unless ($success) { 254 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 255 &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 256 } 257 258 # register the detrend correction imfile 259 $command = "$dettool -register_detrend_imfile"; 260 $command .= " -det_id $det_id"; 261 $command .= " -class_id $class_id"; 262 $command .= " -uri $uri"; 263 $command .= " -dbname $dbname" if defined $dbname; 264 265 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 266 run(command => $command, verbose => $verbose); 267 268 unless ($success) { 269 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 270 &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 271 } 272 } 273 274 # set the detrun state to 'stop' 275 { 276 my $command = "$dettool -updatedetrun"; 277 $command .= " -det_id $det_id"; 278 $command .= " -state stop"; 279 $command .= " -dbname $dbname" if defined $dbname; 280 281 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 282 run(command => $command, verbose => $verbose); 283 284 unless ($success) { 285 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 286 warn ("Unable to perform dettool -updatedetrun: $error_code"); 287 exit($error_code); 288 } 289 } 290 291 # Push the results into the database 292 { 293 my $command = "$flatcorr -addprocess"; 294 $command .= " -corr_id $corr_id"; 295 $command .= " -hostname $host" if defined $host; 296 $command .= " -dbname $dbname" if defined $dbname; 297 298 unless ($no_update) { 299 300 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 301 run(command => $command, verbose => $verbose); 302 unless ($success) { 303 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 304 warn ("Unable to perform regtool -addprocessedimfile: $error_code"); 305 exit($error_code); 306 } 307 } else { 308 print "skipping command: $command\n"; 291 my $det_id = $$output[0]->{det_id}; 292 return $det_id; 293 } 294 295 # use input chip images as reference images to make the detrend correction images 296 sub make_detrend_imfiles { 297 my $det_id = shift; 298 my $files = shift; 299 300 foreach my $file (@$files) { 301 # create the detrend correction for the imfiles based on the input imfiles 302 my $reffile = $file->{uri}; 303 my $class_id = $file->{class_id}; 304 305 my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id); 306 unless ($uri) { 307 &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR); 308 } 309 310 my $command = "$dvoMakeCorr $outcorr"; 311 $command .= " -file $outgrid.fits"; 312 $command .= " -ref $reffile"; 313 314 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 315 run(command => $command, verbose => $verbose); 316 317 unless ($success) { 318 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 319 &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 320 } 321 322 # register the detrend correction imfile 323 $command = "$dettool -register_detrend_imfile"; 324 $command .= " -det_id $det_id"; 325 $command .= " -class_id $class_id"; 326 $command .= " -uri $uri"; 327 $command .= " -dbname $dbname" if defined $dbname; 328 329 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 330 run(command => $command, verbose => $verbose); 331 332 unless ($success) { 333 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 334 &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 335 } 309 336 } 310 337 } … … 319 346 if (not $no_update) { 320 347 my $command = "$flatcorr -addprocess"; 321 $command .= " -corr_id $corr_id";348 $command .= " -corr_id $corr_id"; 322 349 $command .= " -fault $exit_code"; 323 350 $command .= " -hostname $host" if defined $host;
Note:
See TracChangeset
for help on using the changeset viewer.
