Changeset 14009 for trunk/ippScripts/scripts/chip_imfile.pl
- Timestamp:
- Jul 4, 2007, 1:53:22 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/chip_imfile.pl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/chip_imfile.pl
r13989 r14009 1 1 #!/usr/bin/env perl 2 2 3 use Carp; 3 4 use warnings; 4 5 use strict; 5 use Carp;6 6 7 7 ## report the program and machine … … 11 11 print "Starting script $0 on $host\n\n"; 12 12 13 use vars qw( $VERSION ); 14 $VERSION = '0.01'; 15 13 16 use IPC::Cmd 0.36 qw( can_run run ); 14 17 use PS::IPP::Metadata::Config; 15 18 use PS::IPP::Metadata::Stats; 16 use Data::Dumper; 19 17 20 use PS::IPP::Config qw($PS_EXIT_SUCCESS 18 21 $PS_EXIT_UNKNOWN_ERROR … … 30 33 31 34 # Parse the command-line arguments 32 my ($exp_id, # Exposure identifier 33 $chip_id, # Chiptool identifier 34 $class_id, # Class identifier 35 $input, # Input FITS file 36 $camera, # Camera 37 $dbname, # Database name 38 $workdir, # Working directory, for output files 39 $reduction, # Reduction class 40 $no_update, # Don't update the database? 41 $no_op, # Don't do any operations? 42 ); 35 my ($exp_id, $chip_id, $class_id, $input_uri, $camera, $dbname, $workdir, $reduction, $no_update, $no_op); 43 36 GetOptions( 44 'exp_id=s' => \$exp_id, 45 'chip_id=s' => \$chip_id, 46 'class_id=s' => \$class_id, 47 ' uri|u=s' => \$input,48 'camera|c=s' => \$camera, 49 'dbname|d=s' => \$dbname, # Database name50 'workdir|w=s' => \$workdir, 51 'reduction=s' => \$reduction, 52 'no-update' => \$no_update, 53 'no-op' => \$no_op, 37 'exp_id=s' => \$exp_id, # Exposure identifier 38 'chip_id=s' => \$chip_id, # Chiptool identifier 39 'class_id=s' => \$class_id, # Class identifier 40 'input_uri|u=s' => \$input_uri, # Input FITS file 41 'camera|c=s' => \$camera, # Camera 42 'dbname|d=s' => \$dbname, # Database name 43 'workdir|w=s' => \$workdir, # Working directory, for output files 44 'reduction=s' => \$reduction, # Reduction class 45 'no-update' => \$no_update, # Don't update the database? 46 'no-op' => \$no_op, # Don't do any operations? 54 47 ) or pod2usage( 2 ); 55 48 56 49 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 57 pod2usage( 58 -msg => "Required options: --exp_id --chip_id --class_id --uri --camera", 59 -exitval => 3, 60 ) unless defined $exp_id 50 pod2usage( -msg => "Required options: --exp_id --chip_id --class_id --uri --camera", 51 -exitval => 3) 52 unless defined $exp_id 61 53 and defined $chip_id 62 54 and defined $class_id 63 and defined $input 55 and defined $input_uri 64 56 and defined $camera; 65 57 66 58 $ipprc->define_camera($camera); 59 60 # Recipes to use based on reduction class 67 61 $reduction = 'DEFAULT' unless defined $reduction; 68 62 my $recipe = $ipprc->reduction($reduction, 'CHIP'); # Recipe to use 63 64 # values to extract from output metadata and the stats to calculate 65 my $STATS = 66 [ 67 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 68 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg" }, 69 { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev" }, 70 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev" }, 71 { name => "FRINGE_0", type => "rms", flag => "-fringe_0" }, 72 { name => "FRINGE_RESID_0", type => "rms", flag => "-fringe_1" }, 73 { name => "FRINGE_ERR_0", type => "rms", flag => "-fringe_2" }, 74 { name => "OVER_VAL", type => "mean", flag => "-bias" }, 75 { name => "FWHM", type => "mean", flag => "-fwhm" }, 76 { name => "APMIFIT", type => "mean", flag => "-ap_resid" }, 77 { name => "DAPMIFIT", type => "rms", flag => "-ap_resid_stdev" }, 78 { name => "CERROR", type => "rms", flag => "-sigma_ra" }, 79 { name => "CERROR", type => "rms", flag => "-sigma_dec" }, 80 { name => "NSTARS", type => "sum", flag => "-n_stars" }, 81 { name => "NASTRO", type => "sum", flag => "-n_astrom" }, 82 ]; 69 83 70 84 # Look for programs we need … … 76 90 exit($PS_EXIT_CONFIG_ERROR); 77 91 } 78 $ppImage .= " -dbname $dbname" if defined $dbname; 79 80 &my_die("Couldn't find input file: $input\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input); 92 93 &my_die("Couldn't find input file: $input_uri\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri); 81 94 82 95 $workdir = caturi( $workdir, $exp_id ) if defined $workdir; 83 96 84 my $outputRoot = $ipprc->file_prepare( "$exp_id.chp$chip_id", $workdir, $input ); 85 my $outputImage = $ipprc->filename("PPIMAGE.CHIP", $outputRoot, $class_id); 86 my $outputMask = $ipprc->filename("PPIMAGE.CHIP.MASK", $outputRoot, $class_id); 87 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 88 my $outputBin2 = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 89 my $outputStats = $outputRoot . '.' . $class_id . '.stats'; 90 91 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser 97 my $outputRoot = $ipprc->file_prepare( "$exp_id.chp$chip_id", $workdir, $input_uri ); 98 99 my $outputImage = $ipprc->filename("PPIMAGE.CHIP", $outputRoot, $class_id); 100 my $outputMask = $ipprc->filename("PPIMAGE.CHIP.MASK", $outputRoot, $class_id); 101 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 102 my $outputBin2 = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 103 my $outputStats = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id); 104 105 # Run ppImage 92 106 unless ($no_op) { 93 # Run ppImage 94 print "outputImage: $outputImage\n"; 95 print "outputBin1: $outputBin1\n"; 96 print "outputStats: $outputStats\n"; 97 98 my $command = "$ppImage -file $input $outputRoot"; 107 my $command = "$ppImage -file $input_uri $outputRoot"; 99 108 $command .= " -recipe PPIMAGE $recipe"; 100 109 $command .= " -recipe PPSTATS CHIPSTATS"; 101 $command .= " -stats $outputStats"; # Command to run ppImage 110 $command .= " -stats $outputStats"; 111 $command .= " -dbname $dbname" if defined $dbname; 102 112 103 113 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 119 129 my @contents = <$statsFile>; # Contents of file 120 130 close $statsFile; 121 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 122 my $metadata = $mdcParser->parse(join "", @contents) or 131 132 # parse the statistics MDC file 133 my $mdcParser = PS::IPP::Metadata::Config->new(); # Parser for metadata config files 134 my $metadata = $mdcParser->parse(join "", @contents); 135 unless ($metadata) { 123 136 &my_die("Unable to parse metadata config doc", $chip_id, $class_id, $PS_EXIT_PROG_ERROR); 124 $stats->parse($metadata) or 137 } 138 139 # extract the stats from the metadata 140 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 141 unless ($stats->parse($metadata)) { 125 142 &my_die("Unable to find all values in statistics output.\n", $chip_id, $class_id, $PS_EXIT_PROG_ERROR); 143 } 144 } 145 146 # command to update database 147 my $command = "$chiptool -addprocessedimfile"; 148 $command .= " -chip_id $chip_id"; 149 $command .= " -class_id $class_id"; 150 $command .= " -uri $outputImage"; 151 $command .= " -path_base $outputRoot"; 152 $command .= " -dbname $dbname" if defined $dbname; 153 154 # add in the elements from the selected stats above 155 foreach my $entry (@$STATS) { 156 my $value = $entry->{value}; 157 my $flag = $entry->{flag}; 158 $command .= " $flag $value"; 126 159 } 127 160 128 161 # Add the processed file to the database 129 my $bg = $stats->bg_mean();130 my $bg_stdev = $stats->bg_stdev();131 my $bg_mean_stdev = $stats->bg_mean_stdev();132 my $fringe_0 = ${$stats->fringe_mean()}[0];133 my $fringe_1 = ${$stats->fringe_err()}[0];134 my $fringe_2 = ${$stats->fringe_mean_stdev()}[0];135 my $dfringe_0 = ${$stats->dfringe_mean()}[0];136 my $dfringe_1 = ${$stats->dfringe_err()}[0];137 my $dfringe_2 = ${$stats->dfringe_mean_stdev()}[0];138 139 162 unless ($no_update) { 140 # Command to run chiptool141 my $command = "$chiptool -addprocessedimfile";142 $command .= " -chip_id $chip_id";143 $command .= " -class_id $class_id";144 $command .= " -uri $outputImage";145 $command .= " -path_base $outputRoot";146 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";147 $command .= " -fringe_0 $fringe_0 -fringe_1 $fringe_1 -fringe_2 $fringe_2";148 $command .= " -user_1 $dfringe_0 -user_2 $dfringe_1 -user_3 $dfringe_2";149 # XXX add sigma_ra, etc here150 $command .= " -dbname $dbname" if defined $dbname;151 152 163 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 153 164 run(command => $command, verbose => 1); … … 157 168 exit($error_code); 158 169 } 159 } 160 170 } else { 171 print "skipping command: $command\n"; 172 } 161 173 162 174 sub my_die
Note:
See TracChangeset
for help on using the changeset viewer.
