Changeset 20378
- Timestamp:
- Oct 24, 2008, 3:03:22 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_correct_imfile.pl
r20100 r20378 10 10 print "\n\n"; 11 11 print "Starting script $0 on $host\n\n"; 12 print "command: @ARGV\n\n"; 12 13 13 14 use vars qw( $VERSION ); … … 23 24 use Pod::Usage qw( pod2usage ); 24 25 25 my ( $det_id, $ exp_id, $class_id, $det_type, $exp_tag, $input_uri, $camera, $dbname, $workdir, $reduction,26 $verbose, $no_update, $no_op, $outroot, $redirect, $corr_ id, $corr_type, $corr_uri );26 my ( $det_id, $class_id, $det_type, $input_uri, $camera, $dbname, 27 $verbose, $no_update, $no_op, $outroot, $redirect, $corr_uri ); 27 28 GetOptions( 28 29 'det_id|d=s' => \$det_id, 29 'exp_id|e=s' => \$exp_id,30 30 'class_id|i=s' => \$class_id, 31 31 'det_type|t=s' => \$det_type, 32 'exp_tag|=s' => \$exp_tag,33 32 'input_uri|u=s' => \$input_uri, 34 'corr_ id|u=s' => \$corr_id,35 ' corr_type|u=s' => \$corr_type,33 'corr_uri|u=s' => \$corr_uri, 34 'outroot|o=s' => \$outroot, 36 35 'camera|c=s' => \$camera, 37 36 'dbname|d=s' => \$dbname, # Database name 38 'workdir|w=s' => \$workdir, # Working directory, for output files39 37 'verbose' => \$verbose, # Print to stdout 40 38 'no-update' => \$no_update, 41 39 'no-op' => \$no_op, 42 'outroot' => \$outroot,43 40 'redirect-output' => \$redirect, 44 41 ) or pod2usage( 2 ); 45 42 46 43 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 47 pod2usage( -msg => "Required options: --det_id -- exp_id --class_id --det_type --exp_tag --input_uri --camera",44 pod2usage( -msg => "Required options: --det_id --class_id --det_type --input_uri --camera --outroot", 48 45 -exitval => 3) 49 46 unless defined $det_id 50 and defined $exp_id51 47 and defined $class_id 52 48 and defined $det_type 53 and defined $exp_tag54 49 and defined $input_uri 50 and defined $outroot 55 51 and defined $camera; 56 52 … … 59 55 60 56 if ($redirect) { 61 die "must suplly --outroot with --redirect-output" if !defined ($outroot); 62 my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id) 63 or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_CONFIG_ERROR); 57 my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id) 58 or &my_die("Missing entry from camera config", $det_id, $class_id, $PS_EXIT_CONFIG_ERROR); 64 59 $ipprc->redirect_output($logDest); 65 60 } 66 61 67 # Recipes to use as a function of detrend type 68 $reduction = "DETREND" unless defined $reduction; 69 my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_PROCESS'); # Recipe name to use 62 # Recipes to use as a function of detrend type 63 # XXX there are no recipe options for dvoApplyCorr... 64 # XXX in the future, we may define corrections other than the flat-field correction 65 # $reduction = "DETREND" unless defined $reduction; 66 # my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_CORRECT'); # Recipe name to use 67 68 # XXX for now, check and warn, but don't exit on unexpected det_types 69 # det_type is type of the CORRECTED (output) file 70 if ($det_type ne "FLAT") { warn ("unexpected input detrend type: correcting data of type $det_type"); } 70 71 71 72 # Look for programs we need 72 73 my $missing_tools; 73 74 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1); 74 my $dvo corr = can_run('dvoApplyCorr') or (warn "Can't find dvoApplyCorr" and $missing_tools = 1);75 my $dvoApplyCorr = can_run('dvoApplyCorr') or (warn "Can't find dvoApplyCorr" and $missing_tools = 1); 75 76 if ($missing_tools) { 76 77 warn("Can't find required tools."); … … 78 79 } 79 80 80 &my_die("Couldn't find input file: $input_uri\n", $det_id, $ exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);81 &my_die("Couldn't find input file: $input_uri\n", $det_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri); 81 82 82 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 83 84 # detselect -select -det_id $corr_id -class_id $class_id; 85 86 my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, $input_uri ); 87 my $outputImage = $ipprc->filename("DVOCORR.OUTPUT", $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR); 83 my $outputImage = $ipprc->filename("DVOFLAT.OUTPUT", $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $class_id, $PS_EXIT_PROG_ERROR); 88 84 89 85 # Run dvoApplyCorr 90 86 unless ($no_op) { 91 my $command = "$dvocorr -file $input_uri $outputRoot"; 92 $command .= " -corr $corr_uri"; 87 # unless explicitly supplied, the correction image is determined by dvoApplyCorr via look up to the detrend database 88 my $command = "$dvoApplyCorr -file $input_uri $outroot"; 89 $command .= " -corr $corr_uri" if defined $corr_uri; 90 $command .= " -dbname $dbname" if defined $dbname; 93 91 94 92 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 96 94 unless ($success) { 97 95 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 98 &my_die("Unable to perform ppImage: $error_code", $det_id, $ exp_id, $class_id, $error_code);96 &my_die("Unable to perform ppImage: $error_code", $det_id, $class_id, $error_code); 99 97 } 100 98 101 &my_die("Couldn't find expected output file: $outputImage", $det_id, $ exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage);99 &my_die("Couldn't find expected output file: $outputImage", $det_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage); 102 100 } 103 101 104 102 # command to update database 105 my $command = "$dettool -addcorrect edimfile";103 my $command = "$dettool -addcorrectimfile"; 106 104 $command .= " -det_id $det_id"; 107 $command .= " -exp_id $exp_id";108 105 $command .= " -class_id $class_id"; 109 106 $command .= " -uri $outputImage"; 110 $command .= " -path_base $out putRoot";107 $command .= " -path_base $outroot"; 111 108 $command .= " -dbname $dbname" if defined $dbname; 112 109 … … 117 114 unless ($success) { 118 115 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 119 warn("Unable to perform dettool -addcorrect edimfile: $error_code\n");116 warn("Unable to perform dettool -addcorrectimfile: $error_code\n"); 120 117 exit($error_code); 121 118 } … … 128 125 my $msg = shift; # Warning message on die 129 126 my $det_id = shift; # Detrend identifier 130 my $exp_id = shift; # Exposure tag131 127 my $class_id = shift; # Class identifier 132 128 my $exit_code = shift; # Exit code to add 133 129 134 130 carp($msg); 135 if (defined $det_id and defined $ exp_id and defined $class_id and not $no_update) {136 my $command = "$dettool -addcorrect edimfile";131 if (defined $det_id and defined $class_id and not $no_update) { 132 my $command = "$dettool -addcorrectimfile"; 137 133 $command .= " -det_id $det_id"; 138 $command .= " -exp_id $exp_id";139 134 $command .= " -class_id $class_id"; 140 $command .= " -path_base $out putRoot";135 $command .= " -path_base $outroot"; 141 136 $command .= " -code $exit_code"; 142 137 $command .= " -dbname $dbname" if defined $dbname;
Note:
See TracChangeset
for help on using the changeset viewer.
