Changeset 19373
- Timestamp:
- Sep 4, 2008, 2:25:06 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/flatcorr_proc.pl (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/flatcorr_proc.pl
r19327 r19373 34 34 use PS::IPP::Metadata::Config; 35 35 use PS::IPP::Metadata::Stats; 36 use PS::IPP::Metadata::List qw( parse_md_list ); 36 37 use PS::IPP::Config 1.01 qw( :standard ); 37 38 … … 42 43 use Pod::Usage qw( pod2usage ); 43 44 44 my ($corr_id, $dvodb, $region, $filter, $dbname, $workdir, $ no_update, $no_op);45 my ($corr_id, $dvodb, $region, $filter, $dbname, $workdir, $verbose, $no_update, $no_op); 45 46 GetOptions( 46 47 'corr_id|i=s' => \$corr_id, … … 50 51 'dbname|d=s' => \$dbname,# Database name 51 52 'workdir|w=s' => \$workdir, # Working directory for output files 53 'verbose' => \$verbose, # Print to stdout 52 54 'no-update' => \$no_update, 53 55 'no-op' => \$no_op, … … 66 68 my $missing_tools; 67 69 my $relphot = can_run('relphot') or (warn "Can't find relphot" and $missing_tools = 1); 70 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1); 68 71 my $dvoMakeCorr = can_run('dvoMakeCorr') or (warn "Can't find dvoMakeCorr" and $missing_tools = 1); 69 72 my $detselect = can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1); … … 76 79 } 77 80 78 my ($outgrid, $outcorr);79 80 $outgrid = "$workdir/grid.$corr_id.fits";81 $outcorr = "$workdir/corr.$corr_id";81 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 82 83 my $outgrid = "$workdir/grid.$corr_id.fits"; 84 my $outcorr = "$workdir/corr.$corr_id"; 82 85 83 86 # parse the region (RAs,RAe:DECs,DECe) : item = +/-NNN.NNNN … … 86 89 my ($DECs, $DECe) = split (",", $coords[1]); 87 90 91 # Run addstar -resort to ensure the db is indexed 92 { 93 my $command = "echo $addstar -resort"; 94 $command .= " -D CATDIR $dvodb"; 95 $command .= " -region $RAs $RAe $DECs $DECe"; 96 97 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 98 run(command => $command, verbose => $verbose); 99 100 unless ($success) { 101 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 102 &my_die ("Unable to perform addstar -resort for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code); 103 } 104 } 105 88 106 # Run relphot (filter) for the specified region (need to clarify the options like imfreeze) 89 107 { 90 my $command = " $relphot $filter";91 $command .= " -D CATDIR $dvodb";92 $command .= " -region $RAs $RAe $DECs $DECe";93 $command .= " -grid $outgrid";94 $command .= " -imfreeze";95 96 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 97 cache_run(command => $command, verbose => 1);98 99 unless ($success) { 100 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 101 &my_die ("Unable to perform relphot -grid on region $region: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);108 my $command = "echo $relphot $filter"; 109 $command .= " -D CATDIR $dvodb"; 110 $command .= " -region $RAs $RAe $DECs $DECe"; 111 $command .= " -grid $outgrid"; 112 $command .= " -imfreeze"; 113 114 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 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 relphot -grid for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code); 102 120 } 103 121 } … … 107 125 my $chip_id; 108 126 { 109 my $command = "$flatcorr -inputexp -corr_id $corr_id -limit 1"; # Command to run 110 $command .= " -dbname $dbname" if defined $dbname; 127 my $command = "$flatcorr -inputexp"; 128 $command .= " -corr_id $corr_id"; 129 $command .= " -limit 1"; 130 $command .= " -dbname $dbname" if defined $dbname; 131 111 132 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 112 133 run(command => $command, verbose => $verbose); … … 119 140 120 141 # extract the metadata for the files into a hash list 121 $files = parse_md_list($metadata) or142 my $files = parse_md_list($metadata) or 122 143 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 123 144 124 # check for existence 145 # check for existence 125 146 my $file = $$files[0]; 126 147 $chip_id = $file->{chip_id}; … … 131 152 my $files; 132 153 { 133 my $command = "$flatcorr -inputimfile -chip_id $chip_id"; # Command to run 134 $command .= " -dbname $dbname" if defined $dbname; 154 my $command = "$flatcorr -inputimfile"; 155 $command .= " -chip_id $chip_id"; 156 $command .= " -dbname $dbname" if defined $dbname; 157 135 158 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 136 159 run(command => $command, verbose => $verbose); … … 150 173 my $det_id; 151 174 { 175 # get the filelevel from one of these chips 176 my $file = $$files[0]; 177 178 my $filelevel = $file->{filelevel}; 179 my $camera = $file->{camera}; 180 my $telescope = $file->{telescope}; 181 my $filter = $file->{filter}; 182 183 ## XXX the flat-field correction is only defined for a single 184 ## camera. we are grabbing the camera here, but we are assuming 185 ## the flatcorrRun was defined for only a single camera. 186 $ipprc->define_camera($camera); 187 152 188 my $command = "$dettool -register_detrend"; 153 $command .= "-det_type FLATCORR"; 154 $command .= "-file_level $fileLevel"; 155 $command .= "-workdir $workdir"; 156 $command .= "-inst $inst"; 157 $command .= " -dbname $dbname" if defined $dbname; 158 ## XXX what else do we need, and where do we get it? 159 160 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 161 cache_run(command => $command, verbose => 1); 189 $command .= " -det_type FLATCORR"; 190 $command .= " -filelevel $filelevel"; 191 $command .= " -workdir $workdir"; 192 $command .= " -inst $camera"; 193 $command .= " -telescope $telescope"; 194 $command .= " -filter $filter"; 195 $command .= " -dbname $dbname" if defined $dbname; 196 197 ## the flat-field correction is valid for any airmass, exptime, solangle 198 ## for now, we assume the posangle and ccd_temp are not important 199 ## XXX someone needs to set the use_begin, use_end values?? 200 ## XXX inherit a label from the flatcorrRun? 201 202 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 203 run(command => $command, verbose => 1); 162 204 163 205 unless ($success) { … … 173 215 &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR); 174 216 175 my $file = $$output[0]; 176 177 $det_id = $file->{det_id}; 217 # $file = $$output[0]; 218 $det_id = $$output[0]->{det_id}; 178 219 } 179 220 … … 184 225 my $class_id = $file->{class_id}; 185 226 186 my $uri = ipprc_filename ($outcorr, "DVO.CORR", class_id); 187 188 my $command = "$dvoMakeCorr -file $outgrid -ref $reffile $outcorr"; 189 190 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 191 cache_run(command => $command, verbose => 1); 227 my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id); 228 unless ($uri) { 229 &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR); 230 } 231 232 my $command = "echo $dvoMakeCorr $outcorr"; 233 $command .= " -file $outgrid"; 234 $command .= " -ref $reffile"; 235 236 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 237 run(command => $command, verbose => 1); 192 238 193 239 unless ($success) { … … 197 243 198 244 # register the detrend correction imfile 199 my$command = "$dettool -register_detrend_imfile";245 $command = "$dettool -register_detrend_imfile"; 200 246 $command .= " -det_id $det_id"; 201 247 $command .= " -class_id $class_id"; … … 203 249 $command .= " -dbname $dbname" if defined $dbname; 204 250 205 my( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =206 cache_run(command => $command, verbose => 1);251 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 252 run(command => $command, verbose => 1); 207 253 208 254 unless ($success) { … … 212 258 } 213 259 214 my $command = "$dettool -updatedetrun"; 215 $command .= " -det_id $det_id"; 216 $command .= " -state XXX";217 $command .= " -dbname $dbname" if defined $dbname;218 219 # Push the results into the database 220 unless ($no_update) { 260 # set the detrun state to 'stop' 261 { 262 my $command = "$dettool -updatedetrun"; 263 $command .= " -det_id $det_id"; 264 $command .= " -state stop"; 265 $command .= " -dbname $dbname" if defined $dbname; 266 221 267 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 222 268 run(command => $command, verbose => 1); 269 223 270 unless ($success) { 224 271 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); … … 226 273 exit($error_code); 227 274 } 228 } else { 229 print "skipping command: $command\n"; 230 } 231 232 my $command = "$flatcorr -addprocess"; 233 $command .= " -corr_id $corr_id"; 234 $command .= " -dbname $dbname" if defined $dbname; 275 } 235 276 236 277 # Push the results into the database 237 unless ($no_update) { 238 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 239 run(command => $command, verbose => 1); 240 unless ($success) { 241 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 242 warn ("Unable to perform regtool -addprocessedimfile: $error_code"); 243 exit($error_code); 244 } 245 } else { 246 print "skipping command: $command\n"; 278 { 279 my $command = "$flatcorr -addprocess"; 280 $command .= " -corr_id $corr_id"; 281 $command .= " -hostname $host" if defined $host; 282 $command .= " -dbname $dbname" if defined $dbname; 283 284 unless ($no_update) { 285 286 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 287 run(command => $command, verbose => 1); 288 unless ($success) { 289 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 290 warn ("Unable to perform regtool -addprocessedimfile: $error_code"); 291 exit($error_code); 292 } 293 } else { 294 print "skipping command: $command\n"; 295 } 247 296 } 248 297 … … 250 299 { 251 300 my $msg = shift; # Warning message on die 252 my $dvo_id = shift; 253 my $region = shift; 254 my $last_step = shift; 255 my $status = shift; 256 my $dbname = shift; 301 my $corr_id = shift; 302 my $exit_code = shift; 257 303 258 304 carp($msg); 259 if (defined $dvo_id && defined $region && defined $last_step && defined $status and not $no_update) { 260 my $command = "$caltool -addcalrun"; 261 $command .= " -dvo_id $dvo_id"; 262 $command .= " -region $region"; 263 $command .= " -last_step $last_step"; 264 $command .= " -status $status"; 305 if (not $no_update) { 306 my $command = "$flatcorr -addprocess"; 307 $command .= " -corr_id $corr_id"; 308 $command .= " -code $exit_code"; 309 $command .= " -hostname $host" if defined $host; 265 310 $command .= " -dbname $dbname" if defined $dbname; 266 311 system ($command);
Note:
See TracChangeset
for help on using the changeset viewer.
