- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/flatcorr_proc.pl (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippScripts/scripts/flatcorr_proc.pl
r25816 r27838 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 } … … 104 105 my ($DECs, $DECe) = split (",", $coords[1]); 105 106 106 # Run addstar -resort to ensure the db is indexed 107 # Run addstar -resort to ensure the db is indexed 107 108 # XXX addstar should be able to recognize and skip indexed tables 108 109 { 109 my $command = "$addstar -resort"; 110 my $command = "$addstar -resort"; 110 111 $command .= " -D CATDIR $dvodb"; 111 112 $command .= " -region $RAs $RAe $DECs $DECe"; 112 113 113 114 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 114 run(command => $command, verbose => $verbose);115 116 unless ($success) { 117 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);118 &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); 119 120 } 120 121 } … … 135 136 136 137 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 137 run(command => $command, verbose => $verbose); 138 139 unless ($success) { 140 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 141 &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"; 142 196 } 143 197 } … … 145 199 # get a single input exposure 146 200 # flatcorr -inputexp -corr_id $corr_id -limit 1 147 my $chip_id; 148 { 201 sub get_chip_id { 202 149 203 my $command = "$flatcorr -inputexp"; 150 204 $command .= " -corr_id $corr_id"; … … 165 219 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 166 220 167 # check for existence 221 # check for existence 168 222 my $file = $$files[0]; 169 $chip_id = $file->{chip_id}; 223 my $chip_id = $file->{chip_id}; 224 225 return $chip_id; 170 226 } 171 227 172 228 # get the list of imfiles for the single input exposure 173 229 # flatcorr -inputimfile -chip_id $chip_id 174 my $files; 175 { 230 sub get_imfiles { 231 my $chip_id = shift; 232 176 233 my $command = "$flatcorr -inputimfile"; 177 234 $command .= " -chip_id $chip_id"; … … 188 245 189 246 # extract the metadata for the files into a hash list 190 $files = parse_md_list($metadata) or247 my $files = parse_md_list($metadata) or 191 248 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 249 250 return $files; 192 251 } 193 252 194 253 # set up the detrend run to store the corrected imfiles 195 my $det_id; 196 { 197 # get the filelevel from one of these chips 198 my $file = $$files[0]; 254 sub get_det_id { 255 # get the filelevel from the supplied chip 256 my $file = shift; 199 257 200 258 my $filelevel = $file->{filelevel}; … … 216 274 217 275 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 218 run(command => $command, verbose => $verbose);219 220 unless ($success) { 221 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);222 &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); 223 281 } 224 282 … … 231 289 232 290 # $file = $$output[0]; 233 $det_id = $$output[0]->{det_id}; 234 } 235 236 # use input chip image as a reference image 237 foreach my $file (@$files) { 238 # create the detrend correction for the imfiles based on the input imfiles 239 my $reffile = $file->{uri}; 240 my $class_id = $file->{class_id}; 241 242 my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id); 243 unless ($uri) { 244 &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR); 245 } 246 247 my $command = "$dvoMakeCorr $outcorr"; 248 $command .= " -file $outgrid.fits"; 249 $command .= " -ref $reffile"; 250 251 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 252 run(command => $command, verbose => $verbose); 253 254 unless ($success) { 255 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 256 &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 257 } 258 259 # register the detrend correction imfile 260 $command = "$dettool -register_detrend_imfile"; 261 $command .= " -det_id $det_id"; 262 $command .= " -class_id $class_id"; 263 $command .= " -uri $uri"; 264 $command .= " -dbname $dbname" if defined $dbname; 265 266 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 267 run(command => $command, verbose => $verbose); 268 269 unless ($success) { 270 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 271 &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 272 } 273 } 274 275 # set the detrun state to 'stop' 276 { 277 my $command = "$dettool -updatedetrun"; 278 $command .= " -det_id $det_id"; 279 $command .= " -state stop"; 280 $command .= " -dbname $dbname" if defined $dbname; 281 282 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 283 run(command => $command, verbose => $verbose); 284 285 unless ($success) { 286 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 287 warn ("Unable to perform dettool -updatedetrun: $error_code"); 288 exit($error_code); 289 } 290 } 291 292 # Push the results into the database 293 { 294 my $command = "$flatcorr -addprocess"; 295 $command .= " -corr_id $corr_id"; 296 $command .= " -hostname $host" if defined $host; 297 $command .= " -dbname $dbname" if defined $dbname; 298 299 unless ($no_update) { 300 301 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 302 run(command => $command, verbose => $verbose); 303 unless ($success) { 304 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 305 warn ("Unable to perform regtool -addprocessedimfile: $error_code"); 306 exit($error_code); 307 } 308 } else { 309 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 } 310 336 } 311 337 } … … 320 346 if (not $no_update) { 321 347 my $command = "$flatcorr -addprocess"; 322 $command .= " -corr_id $corr_id";348 $command .= " -corr_id $corr_id"; 323 349 $command .= " -fault $exit_code"; 324 350 $command .= " -hostname $host" if defined $host;
Note:
See TracChangeset
for help on using the changeset viewer.
