Changeset 25916 for trunk/ippScripts/scripts/flatcorr_proc.pl
- Timestamp:
- Oct 21, 2009, 3:28:07 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/flatcorr_proc.pl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/flatcorr_proc.pl
r25816 r25916 42 42 use Pod::Usage qw( pod2usage ); 43 43 44 my ($corr_id, $det_type, $dvodb, $camera, $region, $filter, $dbname, $workdir, $ verbose, $no_update, $no_op);44 my ($corr_id, $det_type, $dvodb, $camera, $region, $filter, $dbname, $workdir, $make_correction, $verbose, $no_update, $no_op); 45 45 GetOptions( 46 46 'corr_id|i=s' => \$corr_id, … … 52 52 'dbname|d=s' => \$dbname,# Database name 53 53 'workdir|w=s' => \$workdir, # Working directory for output files 54 'verbose' => \$verbose, # Print to stdout 54 'make_correction' => \$make_correction, # Generate the correction image and save to the detrend database 55 'verbose' => \$verbose, # Print to stdout 55 56 'no-update' => \$no_update, 56 57 'no-op' => \$no_op, … … 86 87 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 87 88 88 # XXX either workdir needs to be non-nebulous here, or addstar / relphot need to handle 89 # nebulous interactions... 89 # dvodb must be non-nebulous; workdir may be in nebulous 90 90 my $outgrid = "$dvodb/flatcorr/$camera.$filter.$corr_id"; 91 91 my $outcorr = "$workdir/$camera.$filter.$corr_id"; … … 143 143 } 144 144 145 # get a single input exposure 146 # flatcorr -inputexp -corr_id $corr_id -limit 1 147 my $chip_id; 148 { 149 my $command = "$flatcorr -inputexp"; 150 $command .= " -corr_id $corr_id"; 151 $command .= " -limit 1"; 152 $command .= " -dbname $dbname" if defined $dbname; 153 154 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 155 run(command => $command, verbose => $verbose); 156 unless ($success) { 157 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 158 &my_die("Unable to perform camtool: $error_code", $corr_id, $error_code); 159 } 160 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 161 &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR); 162 163 # extract the metadata for the files into a hash list 164 my $files = parse_md_list($metadata) or 165 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 166 167 # check for existence 168 my $file = $$files[0]; 169 $chip_id = $file->{chip_id}; 170 } 171 172 # get the list of imfiles for the single input exposure 173 # flatcorr -inputimfile -chip_id $chip_id 174 my $files; 175 { 176 my $command = "$flatcorr -inputimfile"; 177 $command .= " -chip_id $chip_id"; 178 $command .= " -dbname $dbname" if defined $dbname; 179 180 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 181 run(command => $command, verbose => $verbose); 182 unless ($success) { 183 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 184 &my_die("Unable to perform camtool: $error_code", $corr_id, $error_code); 185 } 186 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 187 &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR); 188 189 # extract the metadata for the files into a hash list 190 $files = parse_md_list($metadata) or 191 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 192 } 193 194 # 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]; 199 200 my $filelevel = $file->{filelevel}; 201 my $telescope = $file->{telescope}; 202 203 my $command = "$dettool -register_detrend"; 204 $command .= " -det_type $det_type"; 205 $command .= " -filelevel $filelevel"; 206 $command .= " -workdir $workdir"; 207 $command .= " -inst $camera"; 208 $command .= " -telescope $telescope"; 209 $command .= " -filter $filter"; 210 $command .= " -dbname $dbname" if defined $dbname; 211 212 ## the flat-field correction is valid for any airmass, exptime, solangle 213 ## for now, we assume the posangle and ccd_temp are not important 214 ## XXX someone needs to set the use_begin, use_end values?? 215 ## XXX inherit a label from the flatcorrRun? 216 217 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); 223 } 224 225 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 226 &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR); 227 228 # extract the metadata for the files into a hash list 229 my $output = parse_md_list($metadata) or 230 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 231 232 # $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 { 145 if ($make_correction) { 146 147 # get a single input exposure 148 # flatcorr -inputexp -corr_id $corr_id -limit 1 149 my $chip_id = &get_chip_id(); 150 151 # get the list of imfiles for the single input exposure 152 # flatcorr -inputimfile -chip_id $chip_id 153 my $files = &get_imfiles($chip_id); 154 155 # set up the detrend run to store the corrected imfiles 156 my $det_id = &get_det_id($$files[0]); 157 158 # make the (full-sized) detrend correction images 159 &make_detrend_imfiles($det_id, $files); 160 161 # set the detrun state to 'stop' 277 162 my $command = "$dettool -updatedetrun"; 278 163 $command .= " -det_id $det_id"; … … 311 196 } 312 197 198 # get a single input exposure 199 # flatcorr -inputexp -corr_id $corr_id -limit 1 200 sub get_chip_id { 201 202 my $command = "$flatcorr -inputexp"; 203 $command .= " -corr_id $corr_id"; 204 $command .= " -limit 1"; 205 $command .= " -dbname $dbname" if defined $dbname; 206 207 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 208 run(command => $command, verbose => $verbose); 209 unless ($success) { 210 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 211 &my_die("Unable to perform camtool: $error_code", $corr_id, $error_code); 212 } 213 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 214 &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR); 215 216 # extract the metadata for the files into a hash list 217 my $files = parse_md_list($metadata) or 218 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 219 220 # check for existence 221 my $file = $$files[0]; 222 my $chip_id = $file->{chip_id}; 223 224 return $chip_id; 225 } 226 227 # get the list of imfiles for the single input exposure 228 # flatcorr -inputimfile -chip_id $chip_id 229 sub get_imfiles { 230 my $chip_id = shift; 231 232 my $command = "$flatcorr -inputimfile"; 233 $command .= " -chip_id $chip_id"; 234 $command .= " -dbname $dbname" if defined $dbname; 235 236 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 237 run(command => $command, verbose => $verbose); 238 unless ($success) { 239 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 240 &my_die("Unable to perform camtool: $error_code", $corr_id, $error_code); 241 } 242 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 243 &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR); 244 245 # extract the metadata for the files into a hash list 246 my $files = parse_md_list($metadata) or 247 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 248 249 return $files; 250 } 251 252 # set up the detrend run to store the corrected imfiles 253 sub get_det_id { 254 # get the filelevel from the supplied chip 255 my $file = shift; 256 257 my $filelevel = $file->{filelevel}; 258 my $telescope = $file->{telescope}; 259 260 my $command = "$dettool -register_detrend"; 261 $command .= " -det_type $det_type"; 262 $command .= " -filelevel $filelevel"; 263 $command .= " -workdir $workdir"; 264 $command .= " -inst $camera"; 265 $command .= " -telescope $telescope"; 266 $command .= " -filter $filter"; 267 $command .= " -dbname $dbname" if defined $dbname; 268 269 ## the flat-field correction is valid for any airmass, exptime, solangle 270 ## for now, we assume the posangle and ccd_temp are not important 271 ## XXX someone needs to set the use_begin, use_end values?? 272 ## XXX inherit a label from the flatcorrRun? 273 274 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 275 run(command => $command, verbose => $verbose); 276 277 unless ($success) { 278 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 279 &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 280 } 281 282 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 283 &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR); 284 285 # extract the metadata for the files into a hash list 286 my $output = parse_md_list($metadata) or 287 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 288 289 # $file = $$output[0]; 290 my $det_id = $$output[0]->{det_id}; 291 return $det_id; 292 } 293 294 # use input chip images as reference images to make the detrend correction images 295 sub make_detrend_imfiles { 296 my $det_id = shift; 297 my $files = shift; 298 299 foreach my $file (@$files) { 300 # create the detrend correction for the imfiles based on the input imfiles 301 my $reffile = $file->{uri}; 302 my $class_id = $file->{class_id}; 303 304 my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id); 305 unless ($uri) { 306 &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR); 307 } 308 309 my $command = "$dvoMakeCorr $outcorr"; 310 $command .= " -file $outgrid.fits"; 311 $command .= " -ref $reffile"; 312 313 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 314 run(command => $command, verbose => $verbose); 315 316 unless ($success) { 317 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 318 &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 319 } 320 321 # register the detrend correction imfile 322 $command = "$dettool -register_detrend_imfile"; 323 $command .= " -det_id $det_id"; 324 $command .= " -class_id $class_id"; 325 $command .= " -uri $uri"; 326 $command .= " -dbname $dbname" if defined $dbname; 327 328 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 329 run(command => $command, verbose => $verbose); 330 331 unless ($success) { 332 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 333 &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR); 334 } 335 } 336 } 337 313 338 sub my_die 314 339 {
Note:
See TracChangeset
for help on using the changeset viewer.
