Changeset 18020 for trunk/ippScripts/scripts/fake_imfile.pl
- Timestamp:
- Jun 9, 2008, 11:23:08 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/fake_imfile.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/fake_imfile.pl
r17671 r18020 14 14 ## to select the desired locations in pixel coord. 15 15 16 # XXX : seeing needs to be determined from the input PSF (not currently done in ppSim) 17 # ppSim output -input input.fits -cmf input.cmf -psf input.psf -seeing 0.563760 -recipe PPSIM FAKEPHOT 18 16 19 use Carp; 17 20 use warnings; … … 38 41 39 42 # Parse the command-line arguments 40 my ( $exp_id, $ exp_tag, $chip_id, $class_id, $uri, $camera, $outroot, $dbname, $reduction, $verbose,41 $ no_update, $no_op );43 my ( $exp_id, $fake_id, $class_id, $chiproot, $camroot, $camera, $outroot, 44 $dbname, $reduction, $verbose, $no_update, $no_op ); 42 45 GetOptions( 43 46 'exp_id=s' => \$exp_id, # Exposure identifier 44 'exp_tag=s' => \$exp_tag, # Exposure identifier 45 'chip_id=s' => \$chip_id, # Chiptool identifier 47 'fake_id=s' => \$fake_id, # Chiptool identifier 46 48 'class_id=s' => \$class_id, # Class identifier 47 'uri|u=s' => \$uri, # Input FITS file 49 'chiproot=s' => \$chiproot, # Input Chip files (root) 50 'camroot=s' => \$camroot, # Input Camera files (root) 48 51 'camera|c=s' => \$camera, # Camera 49 52 'outroot|w=s' => \$outroot, # output file base name … … 56 59 57 60 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 58 pod2usage( -msg => "Required options: --exp_id -- exp_tag --chip_id --class_id --uri--camera --outroot",61 pod2usage( -msg => "Required options: --exp_id --fake_id --class_id --chiproot --camroot --camera --outroot", 59 62 -exitval => 3) unless 60 63 defined $exp_id and 61 defined $exp_tag and 62 defined $chip_id and 64 defined $fake_id and 63 65 defined $class_id and 64 defined $uri and 66 defined $chiproot and 67 defined $camroot and 65 68 defined $camera and 66 69 defined $outroot; … … 69 72 70 73 # Recipes to use based on reduction class 71 # the CHIP recipe should not perform astrometry anymore (2008.04.08)72 73 74 $reduction = 'DEFAULT' unless defined $reduction; 74 my $recipe = $ipprc->reduction($reduction, ' CHIP'); # Recipe to use75 my $recipe = $ipprc->reduction($reduction, 'FAKEPHOT'); # Recipe to use 75 76 unless ($recipe) { 76 &my_die("Couldn't find selected reduction for CHIP: $reduction\n", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);77 &my_die("Couldn't find selected reduction for FAKE: $reduction\n", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 77 78 } 78 79 79 80 # values to extract from output metadata and the stats to calculate 80 # XXX commented-out entries are not yet defined in the output files 81 # XXX EAM : we are removing the astrometry analysis from chip, so we 82 # do not bother to calculate those stats. 83 my $STATS = 84 [ 85 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 86 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg", dtype => "float" }, 87 { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev", dtype => "float" }, 88 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev", dtype => "float" }, 89 { name => "OVER_VAL", type => "mean", flag => "-bias", dtype => "float" }, 90 { name => "OVER_VAL", type => "stdev", flag => "-bias_stdev", dtype => "float" }, 91 { name => "FRINGE_0", type => "rms", flag => "-fringe_0", dtype => "float" }, 92 { name => "FRINGE_RESID_0", type => "rms", flag => "-fringe_1", dtype => "float" }, 93 { name => "FRINGE_ERR_0", type => "rms", flag => "-fringe_2", dtype => "float" }, 94 # { name => "CERROR", type => "rms", flag => "-sigma_ra", dtype => "float" }, 95 # { name => "CERROR", type => "rms", flag => "-sigma_dec", dtype => "float" }, 96 { name => "APMIFIT", type => "mean", flag => "-ap_resid", dtype => "float" }, 97 { name => "DAPMIFIT", type => "rms", flag => "-ap_resid_stdev", dtype => "float" }, 98 # { name => "ZP??", type => "mean", flag => "-zp_mean", dtype => "float" }, 99 # { name => "ZP??", type => "rms", flag => "-zp_stdev", dtype => "float" }, 100 { name => "FWHM_X", type => "mean", flag => "-fwhm_major", dtype => "float" }, 101 { name => "FWHM_Y", type => "mean", flag => "-fwhm_minor", dtype => "float" }, 102 { name => "DT_DET", type => "sum", flag => "-dtime_detrend", dtype => "float" }, 103 { name => "DT_PHOT", type => "sum", flag => "-dtime_photom", dtype => "float" }, 104 # { name => "DT_ASTR", type => "sum", flag => "-dtime_astrom", dtype => "float" }, 105 { name => "NSTARS", type => "sum", flag => "-n_stars", dtype => "int" }, 106 # { name => "?", type => "sum", flag => "-n_extended", dtype => "int" }, 107 # { name => "?", type => "sum", flag => "-n_cr", dtype => "int" }, 108 # { name => "NASTRO", type => "sum", flag => "-n_astrom", dtype => "int" }, 109 ]; 110 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 81 # XXX not sure if this is needed by fake_imfile.pl 82 # my $STATS = 83 # [ 84 # # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 85 # { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg", dtype => "float" }, 86 # { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev", dtype => "float" }, 87 # { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev", dtype => "float" }, 88 # ]; 89 # my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 111 90 112 91 # Look for programs we need 113 92 my $missing_tools; 114 my $ chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);115 my $pp Image = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);93 my $faketool = can_run('faketool') or (warn "Can't find faketool" and $missing_tools = 1); 94 my $ppSim = can_run('ppSim') or (warn "Can't find ppSim" and $missing_tools = 1); 116 95 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 117 96 if ($missing_tools) { … … 122 101 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 123 102 124 &my_die("Couldn't find input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri);125 126 103 # outroot examples (HOST components must be set) 127 104 # file://data/ipp004.0/gpc1/20080130 … … 133 110 134 111 ## these names are used in ppImage, and thus may be URIs 135 my $outputImage = $ipprc->filename("PPIMAGE.CHIP", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 136 my $outputMask = $ipprc->filename("PPIMAGE.CHIP.MASK", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 137 my $outputWeight = $ipprc->filename("PPIMAGE.CHIP.WEIGHT", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 138 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 139 my $outputBin2 = $ipprc->filename("PPIMAGE.BIN2", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 140 my $outputStats = $ipprc->filename("PPIMAGE.STATS", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 141 my $traceDest = $ipprc->filename("TRACE.IMFILE", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 142 my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR); 143 144 # Run ppImage 145 unless ($no_op) { 146 ## XXX can we convert ppImage log and trace to use the filerules to generate consistent names 147 ## XXX also stats: output should be implied by $outroot 148 my $command = "$ppImage -file $uri $outroot"; 149 $command .= " -recipe PPIMAGE $recipe"; 150 $command .= " -recipe PPSTATS CHIPSTATS"; 151 $command .= " -stats $outputStats"; 112 my $chipImage = $ipprc->filename("PPIMAGE.CHIP", $chiproot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 113 my $chipMask = $ipprc->filename("PPIMAGE.CHIP.MASK", $chiproot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 114 my $chipWeight = $ipprc->filename("PPIMAGE.CHIP.WEIGHT", $chiproot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 115 my $chipPSF = $ipprc->filename("PSPHOT.PSF.SAVE", $chiproot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 116 my $cameraObjects = $ipprc->filename("PSASTRO.OUTPUT", $camroot) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 117 my $traceDest = $ipprc->filename("TRACE.IMFILE", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 118 my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR); 119 120 # XXX check for existence of input data 121 # &my_die("Couldn't find input file: $uri\n", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri); 122 123 ## get the PPSIM recipe for this camera and FAKEPHOT reduction 124 my $command = "$ppConfigDump -camera $camera -dump-recipe PPSIM -recipe PPSIM $recipe -"; 125 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 126 run(command => $command, verbose => $verbose); 127 unless ($success) { 128 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 129 &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR); 130 } 131 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 132 &my_die("Unable to parse metadata config doc", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR); 133 134 ## allow the output images to be optional, depending on the recipe / reduction class 135 my $skipFake = metadataLookupBool($recipeData, 'SKIP.FAKE'); 136 137 # Run ppSim 138 unless ($no_op || $skipFake) { 139 # examine the PPSIM recipe to decide if we need to run this or opt out 140 141 my $command = "$ppSim $outroot"; 142 $command .= " -input $chipImage"; 143 # XXX add input mask and weight to ppSim 144 # $command .= " -mask $chipMask"; 145 # $command .= " -weight $chipWeight"; 146 $command .= " -cmf $cameraObjects"; 147 $command .= " -psf $chipPSF"; 148 $command .= " -recipe PPSIM $recipe"; 152 149 $command .= " -dbname $dbname" if defined $dbname; 153 $command .= " -tracedest $traceDest -log $logDest"; 150 $command .= " -tracedest $traceDest"; 151 $command .= " -log $logDest"; 154 152 155 153 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 157 155 unless ($success) { 158 156 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 159 &my_die("Unable to perform pp Image: $error_code", $exp_id, $chip_id, $class_id, $error_code);157 &my_die("Unable to perform ppSim: $error_code", $exp_id, $fake_id, $class_id, $error_code); 160 158 } 161 159 162 ## get the ppImage recipe for this camera and CHIP reduction 163 $command = "$ppConfigDump -camera $camera -dump-recipe PPIMAGE -recipe PPIMAGE $recipe -"; 164 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 165 run(command => $command, verbose => $verbose); 166 unless ($success) { 167 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 168 &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 169 } 170 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 171 &my_die("Unable to parse metadata config doc", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 172 173 ## allow the output images to be optional, depending on the recipe / reduction class 174 my $outputImageExpect = metadataLookupBool($recipeData, 'CHIP.FITS'); 175 if ($outputImageExpect) { 176 &my_die("Couldn't find expected output file: $outputImage\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage); 177 } 178 179 my $outputMaskExpect = metadataLookupBool($recipeData, 'CHIP.MASK.FITS'); 180 if ($outputMaskExpect) { 181 &my_die("Couldn't find expected output file: $outputMask\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 182 } 183 184 my $outputWeightExpect = metadataLookupBool($recipeData, 'CHIP.WEIGHT.FITS'); 185 if ($outputWeightExpect) { 186 &my_die("Couldn't find expected output file: $outputWeight\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight); 187 } 188 189 &my_die("Couldn't find expected output file: $outputBin1\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1); 190 &my_die("Couldn't find expected output file: $outputBin2\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2); 191 &my_die("Couldn't find expected output file: $outputStats\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats); 192 160 # XXX check for output files? 161 # &my_die("Couldn't find expected output file: $outputBin1\n", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1); 162 163 # XXX use this to parse the output metadata : eg, detection limits, Nfakes, Nforced 193 164 # Get the statistics on the processed image 194 my $statsFile; # File handle 195 open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 196 my @contents = <$statsFile>; # Contents of file 197 close $statsFile; 198 199 # parse the statistics MDC file 200 my $mdcParser = PS::IPP::Metadata::Config->new(); # Parser for metadata config files 201 my $metadata = $mdcParser->parse(join "", @contents); 202 unless ($metadata) { 203 &my_die("Unable to parse metadata config doc", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR); 204 } 205 206 # extract the stats from the metadata 207 unless ($stats->parse($metadata)) { 208 &my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR); 209 } 165 # my $statsFile; # File handle 166 # open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR); 167 # my @contents = <$statsFile>; # Contents of file 168 # close $statsFile; 169 # 170 # # parse the statistics MDC file 171 # my $mdcParser = PS::IPP::Metadata::Config->new(); # Parser for metadata config files 172 # my $metadata = $mdcParser->parse(join "", @contents); 173 # unless ($metadata) { 174 # &my_die("Unable to parse metadata config doc", $exp_id, $fake_id, $class_id, $PS_EXIT_PROG_ERROR); 175 # } 176 # 177 # # extract the stats from the metadata 178 # unless ($stats->parse($metadata)) { 179 # &my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $fake_id, $class_id, $PS_EXIT_PROG_ERROR); 180 # } 181 } else { 182 print "skipping ppSim processing\n"; 210 183 } 211 184 212 185 # command to update database 213 my $command = "$chiptool -addprocessedimfile"; 186 $command = "$faketool -addprocessedimfile"; 187 $command .= " -fake_id $fake_id"; 214 188 $command .= " -exp_id $exp_id"; 215 $command .= " -chip_id $chip_id";216 189 $command .= " -class_id $class_id"; 217 $command .= " -uri $outputImage";218 190 $command .= " -path_base $outroot"; 219 191 $command .= " -dbname $dbname" if defined $dbname; 220 $command .= $stats->cmdflags(); 192 # XXX add this after defined 193 # $command .= $stats->cmdflags(); 221 194 222 195 # Add the processed file to the database … … 226 199 unless ($success) { 227 200 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 228 warn("Unable to perform chiptool -addprocessedimfile: $error_code\n");201 warn("Unable to perform faketool -addprocessedimfile: $error_code\n"); 229 202 exit($error_code); 230 203 } … … 236 209 { 237 210 my $msg = shift; # Warning message on die 238 my $exp_id = shift; # Chiptoolidentifier239 my $ chip_id = shift; # Chiptoolidentifier211 my $exp_id = shift; # rawExp identifier 212 my $fake_id = shift; # fakeRun identifier 240 213 my $class_id = shift; # Class identifier 241 214 my $exit_code = shift; # Exit code to add 242 215 243 216 carp($msg); 244 if (defined $chip_id and defined $class_id and not $no_update) { 245 my $command = "$chiptool -addprocessedimfile"; 217 if (defined $exp_id and defined $fake_id and defined $class_id and not $no_update) { 218 my $command = "$faketool -addprocessedimfile"; 219 $command .= " -fake_id $fake_id"; 246 220 $command .= " -exp_id $exp_id"; 247 $command .= " -chip_id $chip_id";248 221 $command .= " -class_id $class_id"; 222 $command .= " -path_base $outroot"; 249 223 $command .= " -code $exit_code"; 250 $command .= " -uri $outputImage";251 224 $command .= " -dbname $dbname" if defined $dbname; 252 225 system ($command);
Note:
See TracChangeset
for help on using the changeset viewer.
