Changeset 14009
- Timestamp:
- Jul 4, 2007, 1:53:22 PM (19 years ago)
- Location:
- trunk/ippScripts/scripts
- Files:
-
- 11 edited
-
chip_imfile.pl (modified) (6 diffs)
-
detrend_norm_apply.pl (modified) (8 diffs)
-
detrend_norm_calc.pl (modified) (7 diffs)
-
detrend_norm_exp.pl (modified) (9 diffs)
-
detrend_process_exp.pl (modified) (11 diffs)
-
detrend_process_imfile.pl (modified) (7 diffs)
-
detrend_reject_exp.pl (modified) (14 diffs)
-
detrend_reject_imfile.pl (modified) (18 diffs)
-
detrend_resid.pl (modified) (10 diffs)
-
detrend_stack.pl (modified) (10 diffs)
-
register_imfile.pl (modified) (2 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 -
trunk/ippScripts/scripts/detrend_norm_apply.pl
r13989 r14009 11 11 print "Starting script $0 on $host\n\n"; 12 12 13 use vars qw( $VERSION ); 14 $VERSION = '0.01'; 15 16 use IPC::Cmd 0.36 qw( can_run run ); 17 use PS::IPP::Metadata::Config; 13 18 use PS::IPP::Metadata::Stats; 14 use IPC::Cmd 0.36 qw( can_run run );15 use Data::Dumper;16 19 17 20 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 30 33 31 34 # Parse the command-line 32 my ($det_id, # Detrend ID 33 $iter, # Iteration 34 $class_id, # Class ID 35 $value, # Value to multiple (for normalisation) 36 $input, # Input file 37 $camera, # Camera 38 $det_type, # Detrend type 39 $dbname, # Database name 40 $workdir, # Working directory, for output files 41 $no_update, # Don't update the database 42 $no_op, # Don't do any operations 43 ); 35 my ($det_id, $iter, $class_id, $value, $input_uri, $camera, $det_type, $dbname, $workdir, $no_update, $no_op); 44 36 GetOptions( 45 'det_id|d=s' => \$det_id, 46 'iteration|n=s' => \$iter, 47 'class_id|i=s' => \$class_id, 48 'value|v=s' => \$value, 49 'input_uri|u=s' => \$input ,50 'camera|c=s' => \$camera, 51 'det_type|t=s' => \$det_type, 52 'dbname|d=s' => \$dbname, 53 'workdir|w=s' => \$workdir, # Working directory, for output files54 'no-update' => \$no_update, 55 'no-op' => \$no_op, 37 'det_id|d=s' => \$det_id, # Detrend ID 38 'iteration|n=s' => \$iter, # Iteration 39 'class_id|i=s' => \$class_id, # Class ID 40 'value|v=s' => \$value, # Value to multiple (for normalisation) 41 'input_uri|u=s' => \$input_uri, # Input file 42 'camera|c=s' => \$camera, # Camera 43 'det_type|t=s' => \$det_type, # Detrend type 44 'dbname|d=s' => \$dbname, # Database name 45 'workdir|w=s' => \$workdir, # Working directory, for output files 46 'no-update' => \$no_update, # Don't update the database 47 'no-op' => \$no_op, # Don't do any operations 56 48 ) or pod2usage( 2 ); 57 49 58 50 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 59 51 pod2usage( -msg => "Required options: --det_id --iteration --class_id --value --input_uri --camera --det_type", 60 -exitval => 3, 61 )unless defined $det_id52 -exitval => 3) 53 unless defined $det_id 62 54 and defined $iter 63 55 and defined $class_id 64 56 and defined $value 65 and defined $input 57 and defined $input_uri 66 58 and defined $camera 67 59 and defined $det_type; … … 69 61 $ipprc->define_camera($camera); 70 62 71 72 63 my $RECIPE_PPIMAGE = 'PPIMAGE_N'; # Recipe to use with ppImage 73 64 my $RECIPE_PPSTATS = 'CHIPSTATS'; # Recipe to use with ppStats 65 66 # values to extract from output metadata and the stats to calculate 67 my $STATS = 68 [ 69 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 70 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg" }, 71 { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev" }, 72 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev" }, 73 ]; 74 74 75 75 # Look for programs we need … … 77 77 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1); 78 78 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1); 79 80 79 if ($missing_tools) { 81 80 warn("Can't find required tools."); … … 83 82 } 84 83 84 &my_die("Couldn't find input file: $input_uri\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri); 85 85 86 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 86 87 87 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir, $input ); 88 my $output = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id); 89 my $b1name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 90 my $b2name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 91 my $statsName = $outputRoot . '.' . $class_id . '.stats'; # Statistics file 88 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir, $input_uri ); 89 90 my $output = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id); 91 my $b1name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 92 my $b2name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 93 my $statsName = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id); 92 94 93 95 # Run normalisation 94 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser95 96 unless ($no_op) { 96 my $command = "$ppImage -file $input $outputRoot";97 my $command = "$ppImage -file $input_uri $outputRoot"; 97 98 $command .= " -norm $value -stats $statsName"; 98 99 $command .= " -recipe PPIMAGE $RECIPE_PPIMAGE"; … … 117 118 my @contents = <$statsFile>; # Contents of file 118 119 close $statsFile; 120 121 # parse the statistics MDC file 119 122 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 120 my $metadata = $mdcParser->parse(join "", @contents) 121 or &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); 122 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); 123 my $metadata = $mdcParser->parse(join "", @contents); 124 unless ($metadata) { 125 &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); 126 } 127 128 # extract the stats from the metadata 129 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 130 unless ($stats->parse($metadata)) { 131 &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); 132 } 123 133 } 124 134 125 # Update the database 126 my $bg = $stats->bg_mean(); 127 my $bg_stdev = $stats->bg_stdev(); 128 my $bg_mean_stdev = $stats->bg_mean_stdev(); 135 # Command to update the database 136 my $command = "$dettool -addnormalizedimfile"; 137 $command .= " -det_id $det_id"; 138 $command .= " -iteration $iter"; 139 $command .= " -class_id $class_id"; 140 $command .= " -uri $output"; 141 $command .= " -path_base $outputRoot"; 142 $command .= " -dbname $dbname" if defined $dbname; 129 143 144 # add in the elements from the selected stats above 145 foreach my $entry (@$STATS) { 146 my $value = $entry->{value}; 147 my $flag = $entry->{flag}; 148 $command .= " $flag $value"; 149 } 150 151 # Add the processed file to the database 130 152 unless ($no_update) { 131 my $command = "$dettool -addnormalizedimfile -det_id $det_id -iteration $iter -class_id $class_id ".132 "-uri $output -path_base $outputRoot"; # Command to run133 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";134 $command .= " -dbname $dbname" if defined $dbname;135 136 153 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 137 154 run(command => $command, verbose => 1); … … 141 158 exit($error_code); 142 159 } 160 } else { 161 print "skipping command: $command\n"; 143 162 } 144 163 … … 153 172 carp($msg); 154 173 if ($det_id and $iter and $class_id and not $no_update) { 155 my $command = "$dettool -addnormalizedimfile -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code"; 174 my $command = "$dettool -addnormalizedimfile"; 175 $command .= " -det_id $det_id"; 176 $command .= " -iteration $iter"; 177 $command .= " -class_id $class_id"; 178 $command .= " -code $exit_code"; 156 179 $command .= " -dbname $dbname" if defined $dbname; 157 180 ### system ($command); -
trunk/ippScripts/scripts/detrend_norm_calc.pl
r13732 r14009 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 ); 14 use IPC::Run qw( run );17 use IPC::Run 0.36 qw( run ); 15 18 use PS::IPP::Metadata::Config; 16 19 use PS::IPP::Metadata::List qw( parse_md_list ); 17 use Data::Dumper; 18 19 use PS::IPP::Config qw( 20 $PS_EXIT_SUCCESS 21 $PS_EXIT_UNKNOWN_ERROR 22 $PS_EXIT_SYS_ERROR 23 $PS_EXIT_CONFIG_ERROR 24 $PS_EXIT_PROG_ERROR 25 $PS_EXIT_DATA_ERROR 26 $PS_EXIT_TIMEOUT_ERROR 27 ); 20 21 use PS::IPP::Config qw($PS_EXIT_SUCCESS 22 $PS_EXIT_UNKNOWN_ERROR 23 $PS_EXIT_SYS_ERROR 24 $PS_EXIT_CONFIG_ERROR 25 $PS_EXIT_PROG_ERROR 26 $PS_EXIT_DATA_ERROR 27 $PS_EXIT_TIMEOUT_ERROR 28 ); 28 29 29 30 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 30 31 use Pod::Usage qw( pod2usage ); 31 32 32 33 33 # Parse command-line arguments 34 my ($det_id, # Detrend id 35 $iter, # Iteration 36 $detType, # Detrend type 37 $workdir, # Working directory for output files 38 $dbname, # Database name 39 $no_update, # Don't update the database? 40 $no_op, # Don't do operations 41 ); 34 my ($det_id, $iter, $detType, $workdir, $dbname, $no_update, $no_op); 42 35 GetOptions( 43 'det_id|d=s' => \$det_id, 44 'iteration|i=s' => \$iter, 45 'det_type|t=s' => \$detType, 46 'workdir|w=s' => \$workdir, 47 'dbname|d=s' => \$dbname, # Database name48 'no-update' => \$no_update, 49 'no-op' => \$no_op, 36 'det_id|d=s' => \$det_id, # Detrend id 37 'iteration|i=s' => \$iter, # Iteration 38 'det_type|t=s' => \$detType, # Detrend type 39 'workdir|w=s' => \$workdir, # Working directory for output files 40 'dbname|d=s' => \$dbname, # Database name 41 'no-update' => \$no_update, # Don't update the database? 42 'no-op' => \$no_op, # Don't do operations 50 43 ) or pod2usage( 2 ); 51 44 … … 53 46 pod2usage( -msg => "Required options --det_id --iteration --det_type", 54 47 -exitval => 3, 55 ) unless defined $det_id 48 ) 49 unless defined $det_id 56 50 and defined $iter 57 51 and defined $detType; 58 52 59 60 53 use constant STATISTIC => 'bg'; # Background statistic to use from the database 54 61 55 # Define which detrend types we normalise 62 56 use constant NORMALIZE => { … … 70 64 }; 71 65 72 73 66 # Look for programs we need 74 67 my $missing_tools; … … 80 73 } 81 74 82 &my_die("Unrecognised detrend type: $detType", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless 83 exists NORMALIZE()->{lc($detType)}; 75 &my_die("Unrecognised detrend type: $detType", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless exists NORMALIZE()->{lc($detType)}; 84 76 85 77 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files … … 172 164 } 173 165 166 my $commandBase = "$dettool -addnormalizedstat"; 167 $commandBase .= " -det_id $det_id"; 168 $commandBase .= " -iteration $iter"; 169 $commandBase .= " -dbname $dbname" if defined $dbname; 174 170 175 171 # Process output normalisations 176 172 unless ($no_update) { 177 173 foreach my $normItem (@$norms) { 174 178 175 my $className = $normItem->{name}; # Name of component 179 176 my $normalisation = $normItem->{value}; # Normalisation for component 180 177 181 my $command = "$dettool -addnormalizedstat -det_id $det_id -iteration $iter -class_id $className ". 182 "-norm $normalisation"; # Command to run 183 $command .= " -dbname $dbname" if defined $dbname; 178 my $command = $commandBase; 179 $command .= " -class_id $className"; 180 $command .= " -norm $normalisation"; 181 184 182 my @command = split /\s+/, $command; 185 183 … … 192 190 print $stdout . "\n"; 193 191 } 192 } else { 193 print "skipping command: $commandBase\n"; 194 194 } 195 195 … … 203 203 carp($msg); 204 204 if ($det_id and $iter and not $no_update) { 205 my $command = "$dettool -addnormalizedstat -det_id $det_id -iteration $iter -code $exit_code"; 205 my $command = "$dettool -addnormalizedstat"; 206 $command .= " -det_id $det_id"; 207 $command .= " -iteration $iter"; 208 $command .= " -code $exit_code"; 206 209 $command .= " -dbname $dbname" if defined $dbname; 207 210 ### system ($command); -
trunk/ippScripts/scripts/detrend_norm_exp.pl
r13760 r14009 17 17 use PS::IPP::Metadata::Config; 18 18 use PS::IPP::Metadata::List qw( parse_md_list ); 19 use Statistics::Descriptive;20 19 use File::Temp qw( tempfile ); 21 20 … … 47 46 48 47 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 49 pod2usage( 50 -msg => "Required options: --det_id --iteration --camera --det_type", 51 -exitval => 3, 52 ) unless defined $det_id 53 and defined $iter 54 and defined $camera 55 and defined $det_type; 48 pod2usage( -msg => "Required options: --det_id --iteration --camera --det_type", 49 -exitval => 3) 50 unless defined $det_id 51 and defined $iter 52 and defined $camera 53 and defined $det_type; 56 54 57 55 $ipprc->define_camera($camera); 58 56 59 # Recipes to use , as a function of the detrend type60 use constant RECIPES => { 61 'bin1' => { # We're creating a master --- already processed the input 62 'bias' => 'PPIMAGE_J1_IMAGE_B', # Bias only 63 'dark' => 'PPIMAGE_J1_IMAGE_B', # Dark only 64 'shutter' => 'PPIMAGE_J1_IMAGE_F', # Shutter only 65 'flat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 66 'domeflat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 67 'skyflat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 68 'fringe' => 'PPIMAGE_J1_IMAGE_R', # Fringe only 69 }, 70 'bin2' => { # We're checking the master --- input is not already processed 71 'bias' => 'PPIMAGE_J2_IMAGE_B', # Bias only 72 'dark' => 'PPIMAGE_J2_IMAGE_B', # Dark only 73 'shutter' => 'PPIMAGE_J2_IMAGE_F', # Shutter only 74 'flat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 75 'domeflat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 76 'skyflat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 77 'fringe' => 'PPIMAGE_J2_IMAGE_R', # Fringe only 78 },79 };57 # Recipes to use based on reduction class 58 $reduction = 'DETREND' unless defined $reduction; 59 60 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_IMAGE' . uc($det_type); # Recipe to use 61 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1; 62 63 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_IMAGE' . uc($det_type); # Recipe to use 64 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2; 65 66 # values to extract from output metadata and the stats to calculate 67 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A) 68 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 69 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 70 my $STATS = 71 [ 72 # KEYWORD STATISTIC CHIPTOOL FLAG 73 { name => "bg", type => "mean", flag => "-bg" }, 74 { name => "bg", type => "stdev", flag => "-bg_mean_stdev" }, 75 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 76 # { name => "bg_mean_stdev", type => "rms", flag => "-bg_mean_stdev" }, 77 ]; 80 78 81 79 # Look for programs we need … … 87 85 exit($PS_EXIT_CONFIG_ERROR); 88 86 } 89 90 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files91 87 92 88 # Get list of component files … … 101 97 &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $error_code); 102 98 } 99 100 # convert stdout to a metadata 101 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 103 102 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 104 103 &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR); 104 105 # parse the file info in the metadata 105 106 $files = parse_md_list($metadata) or 106 107 &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR); 107 } 108 109 # Gather the statistics 110 my ($bg, $bg_stdev, $bg_mean_stdev); # The statistics triplet 111 { 112 my @backgrounds; # Array of backgrounds in each component 113 my @variances; # Array of variances for each component 114 foreach my $file (@$files) { 115 &my_die("Unable to find class id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id}; 116 my $class_id = $file->{class_id}; 117 &my_die("Unable to find bg for class_id=$class_id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{bg}; 118 &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev}; 119 push @backgrounds, $file->{bg}; 120 push @variances, $file->{bg_stdev}**2; 121 } 122 123 { 124 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 125 $stats->add_data(@backgrounds); 126 $bg = ($stats->mean() or 'NAN'); 127 $bg_mean_stdev = ($stats->standard_deviation() or 'NAN'); 128 } 129 { 130 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 131 $stats->add_data(@variances); 132 $bg_stdev = (sqrt( $stats->mean() ) or 'NAN'); 108 109 # parse the stats in the metadata 110 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 111 unless ($stats->parse($metadata)) { 112 &my_die("Unable to find all values in statistics output.\n", $det_id, $iter, $PS_EXIT_PROG_ERROR); 133 113 } 134 114 } … … 136 116 my ($list1File, $list1Name) = tempfile( "$camera.$det_type.norm.$det_id.$iter.b1.list.XXXX", UNLINK => 1 ); 137 117 my ($list2File, $list2Name) = tempfile( "$camera.$det_type.norm.$det_id.$iter.b2.list.XXXX", UNLINK => 1 ); 138 my @means; # Array of means139 my @stdevs; # Array of stdevs140 118 foreach my $file (@$files) { 141 119 print $list1File ( $ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n"); 142 120 print $list2File ( $ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n"); 143 push @means, $file->{bg};144 push @stdevs, $file->{bg_stdev};145 121 } 146 122 close $list1File; … … 152 128 my $jpeg1Name = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1 153 129 my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2 154 155 # Recipes to use in processing156 my $recipe1 = RECIPES->{"bin1"}->{lc($det_type)};157 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1;158 159 my $recipe2 = RECIPES->{"bin2"}->{lc($det_type)};160 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2;161 130 162 131 unless ($no_op) { … … 178 147 } 179 148 149 # command to update the database 150 my $command = "$dettool -addnormalizedexp"; 151 $command .= " -det_id $det_id"; 152 $command .= " -iteration $iter"; 153 $command .= " -recip $recipe1,$recipe2"; 154 $command .= " -path_base $outputRoot "; 155 $command .= " -dbname $dbname" if defined $dbname; 156 157 # add in the elements from the selected stats above 158 foreach my $entry (@$STATS) { 159 my $value = $entry->{value}; 160 my $flag = $entry->{flag}; 161 $command .= " $flag $value"; 162 } 163 164 # Add the processed file to the database 180 165 unless ($no_update) { 181 my $command = "$dettool -addnormalizedexp -det_id $det_id -iteration $iter";182 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot ";183 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";184 $command .= " -dbname $dbname" if defined $dbname;185 166 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 186 167 run(command => $command, verbose => 1); … … 189 170 &my_die("Unable to perform dettool -addnormalizedexp: $error_code", $det_id, $iter, $error_code); 190 171 } 191 } 192 172 } else { 173 print "skipping command: $command\n"; 174 } 193 175 194 176 sub my_die … … 201 183 carp($msg); 202 184 if ($det_id and $iter and not $no_update) { 203 my $command = "$dettool -addprocessedimfile -det_id $det_id -iter $iter -code $exit_code"; 185 my $command = "$dettool -addprocessedimfile"; 186 $command .= " -det_id $det_id"; 187 $command .= " -iter $iter"; 188 $command .= " -code $exit_code"; 204 189 $command .= " -dbname $dbname" if defined $dbname; 205 190 ### system ($command); -
trunk/ippScripts/scripts/detrend_process_exp.pl
r13760 r14009 17 17 use PS::IPP::Metadata::Config; 18 18 use PS::IPP::Metadata::List qw( parse_md_list ); 19 use Statistics::Descriptive;19 use File::Temp qw( tempfile ); 20 20 21 21 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 29 29 ); 30 30 my $ipprc = PS::IPP::Config->new(); # IPP configuration 31 use File::Temp qw( tempfile );32 31 33 32 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); … … 47 46 48 47 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 49 pod2usage( 50 -msg => "Required options: --det_id --det_type --exp_tag --camera", 51 -exitval => 3, 52 ) unless defined $det_id 48 pod2usage( -msg => "Required options: --det_id --det_type --exp_tag --camera", 49 -exitval => 3) 50 unless defined $det_id 53 51 and defined $det_type 54 52 and defined $exp_tag … … 57 55 $ipprc->define_camera($camera); 58 56 59 # Recipes to use , as a function of the detrend type60 use constant RECIPES => { 61 'bin1' => { # We're creating a master --- already processed the input 62 'bias' => 'PPIMAGE_J1_IMAGE_B', # Bias only 63 'dark' => 'PPIMAGE_J1_IMAGE_B', # Dark only 64 'shutter' => 'PPIMAGE_J1_IMAGE_F', # Shutter only 65 'flat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 66 'domeflat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 67 'skyflat' => 'PPIMAGE_J1_IMAGE_F', # Flat-field only 68 'fringe' => 'PPIMAGE_J1_IMAGE_R', # Fringe only 69 }, 70 'bin2' => { # We're checking the master --- input is not already processed 71 'bias' => 'PPIMAGE_J2_IMAGE_B', # Bias only 72 'dark' => 'PPIMAGE_J2_IMAGE_B', # Dark only 73 'shutter' => 'PPIMAGE_J2_IMAGE_F', # Shutter only 74 'flat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 75 'domeflat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 76 'skyflat' => 'PPIMAGE_J2_IMAGE_F', # Flat-field only 77 'fringe' => 'PPIMAGE_J2_IMAGE_R', # Fringe only 78 },79 };57 # Recipes to use based on reduction class 58 $reduction = 'DETREND' unless defined $reduction; 59 60 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_IMAGE' . uc($det_type); # Recipe to use 61 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1; 62 63 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_IMAGE' . uc($det_type); # Recipe to use 64 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2; 65 66 # values to extract from output metadata and the stats to calculate 67 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A) 68 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 69 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 70 my $STATS = 71 [ 72 # KEYWORD STATISTIC CHIPTOOL FLAG 73 { name => "bg", type => "mean", flag => "-bg" }, 74 { name => "bg", type => "stdev", flag => "-bg_mean_stdev" }, 75 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 76 # { name => "bg_mean_stdev", type => "rms", flag => "-bg_mean_stdev" }, 77 ]; 80 78 81 79 # Look for programs we need … … 87 85 exit($PS_EXIT_CONFIG_ERROR); 88 86 } 89 90 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files91 87 92 88 # Get list of component files … … 101 97 &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $exp_tag, $error_code); 102 98 } 99 100 # convert stdout to a metadata 101 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 103 102 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 104 103 &my_die("Unable to parse metadata config doc", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR); 104 105 # parse the file info in the metadata 105 106 $files = parse_md_list($metadata) or 106 107 &my_die("Unable to parse metadata list", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR); 107 } 108 109 # Gather the statistics 110 my ($bg, $bg_stdev, $bg_mean_stdev); # The statistics triplet 111 { 112 my @backgrounds; # Array of backgrounds in each component 113 my @variances; # Array of variances for each component 114 foreach my $file (@$files) { 115 &my_die("Unable to find class id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id}; 116 my $class_id = $file->{class_id}; 117 &my_die("Unable to find bg for class_id=$class_id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg}; 118 &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev}; 119 push @backgrounds, $file->{bg}; 120 push @variances, $file->{bg_stdev}**2; 121 } 122 123 { 124 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 125 $stats->add_data(@backgrounds); 126 $bg = ($stats->mean() or 'NAN'); 127 $bg_mean_stdev = ($stats->standard_deviation() or 'NAN'); 128 } 129 { 130 my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator 131 $stats->add_data(@variances); 132 $bg_stdev = (sqrt( $stats->mean() ) or 'NAN'); 108 109 # parse the stats in the metadata 110 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 111 unless ($stats->parse($metadata)) { 112 &my_die("Unable to find all values in statistics output.\n", $chip_id, $class_id, $PS_EXIT_PROG_ERROR); 133 113 } 134 114 } … … 137 117 my ($list1File, $list1Name) = tempfile( "$exp_tag.detproc.$det_id.b1.list.XXXX", UNLINK => 1 ); 138 118 my ($list2File, $list2Name) = tempfile( "$exp_tag.detproc.$det_id.b2.list.XXXX", UNLINK => 1 ); 139 my @means; # Array of means140 my @stdevs; # Array of stdevs141 119 foreach my $file (@$files) { 142 120 print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n"); 143 121 print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n"); 144 push @means, $file->{bg};145 push @stdevs, $file->{bg_stdev};146 122 } 147 123 close $list1File; … … 153 129 my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1 154 130 my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2 155 156 # Recipes to use in processing157 my $recipe1 = RECIPES->{"bin1"}->{lc($det_type)};158 &my_die("Unrecognised detrend type: $det_type", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe1;159 160 my $recipe2 = RECIPES->{"bin2"}->{lc($det_type)};161 &my_die("Unrecognised detrend type: $det_type", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe2;162 131 163 132 unless ($no_op) { … … 187 156 } 188 157 158 # Command to update the database 159 my $command = "$dettool -addprocessedexp"; 160 $command .= " -det_id $det_id"; 161 $command .= " -exp_tag $exp_tag"; 162 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot"; 163 $command .= " -dbname $dbname" if defined $dbname; 164 165 # add in the elements from the selected stats above 166 foreach my $entry (@$STATS) { 167 my $value = $entry->{value}; 168 my $flag = $entry->{flag}; 169 $command .= " $flag $value"; 170 } 171 172 # Add the processed file to the database 189 173 unless ($no_update) { 190 my $command = "$dettool -addprocessedexp -det_id $det_id -exp_tag $exp_tag";191 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot";192 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";193 $command .= " -dbname $dbname" if defined $dbname;194 174 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 195 175 run(command => $command, verbose => 1); … … 199 179 exit($error_code); 200 180 } 201 } 202 181 } else { 182 print "skipping command: $command\n"; 183 } 203 184 204 185 sub my_die … … 211 192 carp($msg); 212 193 if ($det_id and $exp_tag and not $no_update) { 213 my $command = "$dettool -addprocessedexp -det_id $det_id -exp_tag $exp_tag -code $exit_code"; 194 my $command = "$dettool -addprocessedexp"; 195 $command .= " -det_id $det_id"; 196 $command .= " -exp_tag $exp_tag"; 197 $command .= " -code $exit_code"; 214 198 $command .= " -dbname $dbname" if defined $dbname; 215 199 ### system ($command); -
trunk/ippScripts/scripts/detrend_process_imfile.pl
r13989 r14009 48 48 49 49 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 50 pod2usage( 51 -msg => "Required options: --det_id --exp_tag --class_id --det_type --input_uri --camera", 52 -exitval => 3, 53 ) unless defined $det_id 50 pod2usage( -msg => "Required options: --det_id --exp_tag --class_id --det_type --input_uri --camera", 51 -exitval => 3) 52 unless defined $det_id 54 53 and defined $exp_tag 55 54 and defined $class_id … … 61 60 $ipprc->define_camera($camera); 62 61 62 # Recipes to use as a function of detrend type 63 63 $reduction = "DETREND" unless defined $reduction; 64 64 my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_PROCESS'); # Recipe name to use 65 66 # values to extract from output metadata and the stats to calculate 67 my $STATS = 68 [ 69 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 70 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg" }, 71 { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev" }, 72 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev" }, 73 ]; 65 74 66 75 # Look for programs we need … … 74 83 $ppImage .= " -dbname $dbname" if defined $dbname; 75 84 85 &my_die("Couldn't find input file: $input_uri\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri); 86 76 87 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 77 88 78 my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, $input_uri ); 89 my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, $input_uri ); 90 79 91 my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id); 80 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1",$outputRoot, $class_id);81 my $outputBin2 = $ipprc->filename("PPIMAGE.BIN2",$outputRoot, $class_id);82 my $outputStats = $ outputRoot . '.' . $class_id . '.stats';92 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 93 my $outputBin2 = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 94 my $outputStats = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id); 83 95 84 96 # Run ppImage 85 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser86 97 unless ($no_op) { 87 98 my $command = "$ppImage -file $input_uri $outputRoot"; … … 96 107 &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $class_id, $error_code); 97 108 } 109 98 110 &my_die("Couldn't find expected output file: $outputImage", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage); 99 111 &my_die("Couldn't find expected output file: $outputStats", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats); … … 106 118 my @contents = <$statsFile>; # Contents of file 107 119 close $statsFile; 120 121 # parse the statistics MDC file 108 122 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 109 123 my $metadata = $mdcParser->parse(join "", @contents) 110 124 or &my_die("Unable to parse metadata config", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 125 126 # extract the stats from the metadata 127 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 111 128 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 112 129 } 113 130 114 my $bg = $stats->bg_mean(); 115 my $bg_stdev = $stats->bg_stdev(); 116 my $bg_mean_stdev = $stats->bg_mean_stdev(); 131 # command to update database 132 my $command = "$dettool -addprocessedimfile"; 133 $command .= " -det_id $det_id"; 134 $command .= " -exp_tag $exp_tag"; 135 $command .= " -class_id $class_id"; 136 $command .= " -recip $reduction"; 137 $command .= " -uri $outputImage -path_base $outputRoot"; 138 $command .= " -dbname $dbname" if defined $dbname; 139 140 # add in the elements from the selected stats above 141 foreach my $entry (@$STATS) { 142 my $value = $entry->{value}; 143 my $flag = $entry->{flag}; 144 $command .= " $flag $value"; 145 } 117 146 118 147 # Add the processed file to the database 119 148 unless ($no_update) { 120 my $command = "$dettool -addprocessedimfile";121 $command .= " -det_id $det_id";122 $command .= " -exp_tag $exp_tag";123 $command .= " -class_id $class_id";124 $command .= " -recip $recipe";125 $command .= " -uri $outputImage -path_base $outputRoot";126 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";127 $command .= " -dbname $dbname" if defined $dbname;128 129 149 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 130 150 run(command => $command, verbose => 1); … … 134 154 exit($error_code); 135 155 } 156 } else { 157 print "skipping command: $command\n"; 136 158 } 137 159 … … 146 168 carp($msg); 147 169 if ($det_id and $exp_tag and $class_id and not $no_update) { 148 my $command = "$dettool -addprocessedimfile -det_id $det_id -exp_tag $exp_tag -class_id $class_id -code $exit_code"; 170 my $command = "$dettool -addprocessedimfile"; 171 $command .= " -det_id $det_id"; 172 $command .= " -exp_tag $exp_tag"; 173 $command .= " -class_id $class_id"; 174 $command .= " -code $exit_code"; 149 175 $command .= " -dbname $dbname" if defined $dbname; 150 176 ### system ($command); -
trunk/ippScripts/scripts/detrend_reject_exp.pl
r13962 r14009 47 47 48 48 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 49 pod2usage( 50 -msg => "Required options: --det_id --iteration --det_type --camera", 51 -exitval => 3, 52 ) unless defined $det_id 49 pod2usage( -msg => "Required options: --det_id --iteration --det_type --camera", 50 -exitval => 3) 51 unless defined $det_id 53 52 and defined $iter 54 53 and defined $det_type 55 54 and defined $camera; 56 55 56 # values to extract from output metadata and the stats to calculate 57 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A) 58 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 59 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 60 my $STATS = 61 [ 62 # KEYWORD STATISTIC CHIPTOOL FLAG 63 { name => "bg", type => "mean", flag => "-bg" }, 64 { name => "bg_mean_stdev", type => "stdev", flag => "-bg_mean_stdev" }, 65 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 66 ]; 67 68 my $REJSTATS = 69 [ 70 # KEYWORD STATISTIC CHIPTOOL FLAG 71 { name => "bg", type => "mean", flag => "ensMeanMean" }, 72 { name => "bg", type => "stdev", flag => "ensMeanStdev" }, 73 { name => "bg_mean_stdev", type => "mean", flag => "ensMeanStdevMean" }, 74 { name => "bg_mean_stdev", type => "stdev", flag => "ensMeanStdevStdev" }, 75 { name => "bg_stdev", type => "mean", flag => "ensStdevMean" }, 76 { name => "bg_stdev", type => "stdev", flag => "ensStdevStdev" }, 77 ]; 57 78 58 79 # Look for programs we need … … 64 85 } 65 86 66 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files67 68 87 # Get list of component files 69 88 my $exposures; # Array of exposures 70 89 { 71 my $command = "$dettool -residexp -det_id $det_id -iteration $iter"; # Command to run 90 # dettool command to select exp data for this det_run 91 my $command = "$dettool -residexp"; 92 $command .= " -det_id $det_id"; 93 $command .= " -iteration $iter"; 72 94 $command .= " -dbname $dbname" if defined $dbname; 73 95 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 78 100 } 79 101 102 # Parse the stdout buffer into a metadata 103 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 80 104 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 81 105 &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR); 82 # XXX need to test that the result list is 0 length and return with a different error 106 107 # parse the file info in the metadata 83 108 $exposures = parse_md_list($metadata) or 84 109 &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR); 110 111 # Parse the statistics on the residual image 112 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 113 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $PS_EXIT_PROG_ERROR); 114 115 # Parse the statistics for rejections 116 my $rejstats = PS::IPP::Metadata::Stats->new($REJSTATS); # Stats parser 117 $rejstats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $PS_EXIT_PROG_ERROR); 85 118 } 86 119 87 120 my @expTags; # Array of exposure IDs 88 my @means; # Array of means89 my @stdevs; # Array of standard deviations90 my @meanStdevs; # Array of standard deviations of the mean (normalised by the mean)91 my @variances; # Array of variances92 121 my @accept; # Array of accept flags 93 122 my @include; # Array of include flags 94 123 foreach my $exposure (@$exposures) { 95 124 &my_die("Unable to find exposure id.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{exp_tag}; 96 &my_die("Unable to find mean.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{bg};97 &my_die("Unable to find stdev.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{bg_stdev};98 &my_die("Unable to find mean stdev.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{bg_mean_stdev};99 125 &my_die("Unable to find accept.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{accept}; 100 126 &my_die("Unable to find include.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{include}; 101 push @expTags, $exposure->{exp_tag}; 102 push @means, $exposure->{bg}; 103 push @stdevs, $exposure->{bg_stdev}; 104 # XXX why are we using mean_stdev / bd? 105 # push @meanStdevs, $exposure->{bg_mean_stdev} / $exposure->{bg}; 106 push @meanStdevs, $exposure->{bg_mean_stdev}; 107 push @variances, $exposure->{bg_stdev}**2; 108 push @accept, $exposure->{accept}; 109 push @include, $exposure->{include}; 110 } 111 my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator 112 $meanStats->add_data(@means); 113 my $stdevStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator 114 $stdevStats->add_data(@stdevs); 115 my $meanStdevStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator 116 $meanStdevStats->add_data(@meanStdevs); 127 } 128 129 my $ensMeanMean = &STATS_value_for_flag ($REJSTATS, "ensMeanMean"); 130 my $ensMeanStdev = &STATS_value_for_flag ($REJSTATS, "ensMeanStdev"); 131 my $ensMeanStdevMean = &STATS_value_for_flag ($REJSTATS, "ensMeanStdevMean"); 132 my $ensMeanStdevStdev = &STATS_value_for_flag ($REJSTATS, "ensMeanStdevStdev"); 133 my $ensStdevMean = &STATS_value_for_flag ($REJSTATS, "ensStdevMean"); 134 my $ensStdevStdev = &STATS_value_for_flag ($REJSTATS, "ensStdevStdev"); 117 135 118 136 $ipprc->define_camera($camera); 119 137 # Rejection thresholds 120 my $reject_mean = rejection_limit( 'ENSEMBLE.MEAN',$det_type, $filter );121 my $reject_stdev = rejection_limit( 'ENSEMBLE.STDEV',$det_type, $filter );138 my $reject_mean = rejection_limit( 'ENSEMBLE.MEAN', $det_type, $filter ); 139 my $reject_stdev = rejection_limit( 'ENSEMBLE.STDEV', $det_type, $filter ); 122 140 my $reject_meanstdev = rejection_limit( 'ENSEMBLE.MEANSTDEV', $det_type, $filter ); 123 141 … … 129 147 unless ($no_op) { 130 148 $logFile = $ipprc->file_create_append( $logName ); 131 print $logFile "Ensemble mean " . $meanStats->mean() . " +/- " . $meanStats->standard_deviation . 132 ", stdev " . $stdevStats->mean() . " +/- " . $stdevStats->standard_deviation() . "\n\n"; 149 print $logFile "Ensemble mean $meanEnsemble +/- $stdevEnsemble, stdev $meanStdevEnsemble\n\n"; 133 150 } 134 151 … … 136 153 my $numChanges = 0; # Number of exposures with changed status 137 154 my $numReject = 0; # Number of exposures rejected 138 my $command; 139 my $reject; 140 my $expTag; 141 for (my $i = 0; $i < scalar @means; $i++) { 142 $expTag = $expTags[$i]; # Exposure ID 143 $command = "$dettool -updateresidexp -det_id $det_id -iteration $iter -exp_tag $expTag"; # Command to run 155 156 for (my $i = 0; $i < scalar @$exposures; $i++) { 157 my $file = $files[$i]; 158 my $mean = $file->{bg}; # Mean for this exposure 159 my $stdev = $file->{bg_stdev}; # Stdev for this exposure 160 my $meanStdev = $file->{bg_mean_stdev}; # Stdev of Means for this exposure 161 162 my $expTag = $exposure->{exp_tag}; 163 my $accept = $exposure->{accept}; 164 my $include = $exposure->{include}; 165 166 my $reject = 0; # Reject this exposure? 167 168 my $command = "$dettool -updateresidexp"; 169 $command .= " -det_id $det_id"; 170 $command .= " -iteration $iter"; 171 $command .= " -exp_tag $expTag"; 144 172 $command .= " -dbname $dbname" if defined $dbname; 145 173 146 $reject = 0; # Reject this exposure? 147 148 if (not $accept[$i]) { 174 if (not $accept) { 149 175 # Rejected this at an earlier stage 150 176 unless ($no_op) { … … 165 191 } 166 192 167 if ($reject_mean > 0 and defined $meanStats->standard_deviation()) {168 my $d Mean = abs($means[$i] - $meanStats->mean());169 if ($d Mean > ($reject_mean * $meanStats->standard_deviation())) {193 if ($reject_mean > 0 and $ensMeanStdev > 0) { 194 my $delta = abs($mean - $ensMeanMean); 195 if ($delta > ($reject_mean * $ensMeanStdev)) { 170 196 print $logFile "Rejecting $expTag based on ensemble mean value: "; 171 197 $reject = 1; … … 174 200 print $logFile "$expTag OK against ensemble mean: "; 175 201 } 176 print $logFile "$mean s[$i] --> $dMean vs " . $reject_mean * $meanStats->standard_deviation(). "\n";202 print $logFile "$mean --> $delta vs " . $reject_mean * $ensMeanStdev . "\n"; 177 203 } else { 178 204 print $logFile "No rejection of $expTag for ensemble mean\n"; 179 205 } 180 206 181 if ($reject_stdev > 0 and defined $stdevStats->standard_deviation()> 0) {182 my $d Mean = abs($stdevs[$i] - $stdevStats->mean());183 if ($d Mean > ($reject_stdev * $stdevStats->standard_deviation())) {207 if ($reject_stdev > 0 and $ensStdevStdev > 0) { 208 my $delta = abs($stdev - $ensStdevMean); 209 if ($delta > ($reject_stdev * $ensStdevStdev)) { 184 210 print $logFile "Rejecting $expTag based on ensemble stdev: "; 185 211 $reject = 1; … … 188 214 print $logFile "$expTag OK against ensemble stdev: "; 189 215 } 190 print $logFile "$stdev s[$i] --> $dMean sigma vs " . $reject_stdev * $stdevStats->standard_deviation(). "\n";216 print $logFile "$stdev --> $delta sigma vs " . $reject_stdev * $ensStdevStdev . "\n"; 191 217 } else { 192 218 print $logFile "No rejection of $expTag for ensemble stdev\n"; 193 219 } 194 220 195 if ($reject_meanstdev > 0 and defined $meanStdevStats->standard_deviation()> 0) {196 my $d Mean = abs($meanStdevs[$i] - $meanStdevStats->mean());197 if ($d Mean > ($reject_meanstdev * $meanStdevStats->standard_deviation())) {221 if ($reject_meanstdev > 0 and $ensMeanStdevStdev > 0) { 222 my $delta = abs($meanStdev - $ensMeanStdevMean); 223 if ($delta > ($reject_meanstdev * $ensMeanStdevStdev)) { 198 224 print $logFile "Rejecting $expTag based on ensemble mean stdev: "; 199 225 $reject = 1; … … 202 228 print $logFile "$expTag OK against ensemble mean stdev: "; 203 229 } 204 print $logFile "$meanStdev s[$i] --> $dMean sigma vs " . $reject_meanstdev. "\n";230 print $logFile "$meanStdev --> $delta sigma vs " . $reject_meanstdev * $ensMeanStdevStdev. "\n"; 205 231 } else { 206 232 print $logFile "No rejection of $expTag for ensemble mean stdev\n"; … … 214 240 215 241 # Check for status changes 216 if ((not $include [$i] and not $reject) or ($include[$i]and $reject)) {242 if ((not $include and not $reject) or ($include and $reject)) { 217 243 unless ($no_op) { 218 244 print $logFile "Status of $expTag has changed.\n"; … … 253 279 } 254 280 281 my $command = "$dettool -adddetrunsummary"; 282 $command .= " -det_id $det_id"; 283 $command .= " -iteration $iter"; 284 $command .= " -accept" if $master; 285 $command .= " -dbname $dbname" if defined $dbname; 286 287 # add in the elements from the selected stats above 288 foreach my $entry (@$STATS) { 289 my $value = $entry->{value}; 290 my $flag = $entry->{flag}; 291 $command .= " $flag $value"; 292 } 293 255 294 # Put results into the database 256 295 unless ($no_update) { 257 258 { 259 # Add the summary 260 my $varianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator 261 $varianceStats->add_data(@variances); 262 263 my $bg = ($meanStats->mean() or 'NAN'); 264 my $bg_stdev = (sqrt( $varianceStats->mean() ) or 'NAN'); 265 my $bg_mean_stdev = ($meanStats->standard_deviation() or 'NAN'); 266 267 my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter"; 268 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev"; 269 $command .= " -accept" if $master; 270 $command .= " -dbname $dbname" if defined $dbname; 271 272 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 273 run(command => $command, verbose => 1); 274 unless ($success) { 275 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 276 warn("Unable to perform dettool -adddetrunsummary: $error_code"); 277 exit($error_code); 278 } 279 } 280 281 # Re-run processing if required 282 { 283 my $command = "$dettool -updatedetrun -det_id $det_id"; 284 if ($stop) { 285 $command .= ' -state stop'; 286 } else { 287 $command .= ' -again'; 288 } 289 290 $command .= " -dbname $dbname" if defined $dbname; 291 292 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 293 run(command => $command, verbose => 1); 294 unless ($success) { 295 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 296 warn("Unable to perform dettool -updatedetrun: $error_code"); 297 exit($error_code); 298 } 299 } 296 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 297 run(command => $command, verbose => 1); 298 unless ($success) { 299 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 300 warn("Unable to perform dettool -adddetrunsummary: $error_code"); 301 exit($error_code); 302 } 303 304 $command = "$dettool -updatedetrun -det_id $det_id"; 305 if ($stop) { 306 $command .= ' -state stop'; 307 } else { 308 $command .= ' -again'; 309 } 310 $command .= " -dbname $dbname" if defined $dbname; 311 312 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 313 run(command => $command, verbose => 1); 314 unless ($success) { 315 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 316 warn("Unable to perform dettool -updatedetrun: $error_code"); 317 exit($error_code); 318 } 319 } else { 320 print "skipping command: $command\n"; 300 321 } 301 322 … … 317 338 carp($msg); 318 339 if ($det_id and $iter and not $no_update) { 319 my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter -code $exit_code"; 340 my $command = "$dettool -adddetrunsummary"; 341 $command .= " -det_id $det_id"; 342 $command .= " -iteration $iter"; 343 $command .= " -code $exit_code"; 320 344 $command .= " -dbname $dbname" if defined $dbname; 321 345 ### system ($command); … … 323 347 exit $exit_code; 324 348 } 325 326 327 349 328 350 # Retrieve the requested rejection limit, dying unless extant … … 342 364 } 343 365 366 sub STATS_value_for_flag 367 { 368 my $STATS = shift; 369 my $flag = shift; 370 371 foreach my $entry (@$STATS) { 372 if ($flag eq $entry->{flag}) { 373 return $entry->{value}; 374 } 375 } 376 return 'NAN'; 377 } 344 378 345 379 __END__ -
trunk/ippScripts/scripts/detrend_reject_imfile.pl
r13989 r14009 22 22 use IPC::Cmd 0.36 qw( can_run run ); # tools to run UNIX programs with control over I/O 23 23 use PS::IPP::Metadata::Config; # tools to parse the psMetadataConfig files 24 use PS::IPP::Metadata::List qw( parse_md_list ); # ?24 use PS::IPP::Metadata::List qw( parse_md_list ); # tools to parse a metadata into a hash list 25 25 use Statistics::Descriptive; # tools for calculating basic statistical quantities 26 26 use File::Temp qw( tempfile ); # tools to construct temp files 27 27 28 use PS::IPP::Config qw($PS_EXIT_SUCCESS 28 29 $PS_EXIT_UNKNOWN_ERROR … … 56 57 57 58 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 58 pod2usage( 59 -msg => "Required options: --det_id --iteration --exp_tag --det_type --camera", 60 -exitval => 3, 61 ) unless defined $det_id 59 pod2usage( -msg => "Required options: --det_id --iteration --exp_tag --det_type --camera", 60 -exitval => 3) 61 unless defined $det_id 62 62 and defined $iter 63 63 and defined $exp_tag … … 68 68 $ipprc->define_camera($camera); 69 69 70 # Recipes to use, as a function of the detrend type 71 use constant RECIPES => { 72 'bin1' => { # We're creating a master --- already processed the input 73 'bias' => 'PPIMAGE_J1_RESID_B', # Bias only 74 'dark' => 'PPIMAGE_J1_RESID_B', # Dark only 75 'shutter' => 'PPIMAGE_J1_RESID_F', # Shutter only 76 'flat' => 'PPIMAGE_J1_RESID_F', # Flat-field only 77 'domeflat' => 'PPIMAGE_J1_RESID_F', # Flat-field only 78 'skyflat' => 'PPIMAGE_J1_RESID_F', # Flat-field only 79 'fringe' => 'PPIMAGE_J1_RESID_R', # Fringe only 80 }, 81 'bin2' => { # We're checking the master --- input is not already processed 82 'bias' => 'PPIMAGE_J2_RESID_B', # Bias only 83 'dark' => 'PPIMAGE_J2_RESID_B', # Dark only 84 'shutter' => 'PPIMAGE_J2_RESID_F', # Shutter only 85 'flat' => 'PPIMAGE_J2_RESID_F', # Flat-field only 86 'domeflat' => 'PPIMAGE_J2_RESID_F', # Flat-field only 87 'skyflat' => 'PPIMAGE_J2_RESID_F', # Flat-field only 88 'fringe' => 'PPIMAGE_J2_RESID_R', # Fringe only 89 }, 90 }; 70 # Recipes to use based on reduction class 71 $reduction = 'DETREND' unless defined $reduction; 72 73 my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1_RESID' . uc($det_type); # Recipe to use 74 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe1; 75 76 my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2_RESID' . uc($det_type); # Recipe to use 77 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe2; 78 79 # values to extract from output metadata and the stats to calculate 80 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A) 81 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 82 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 83 my $STATS = 84 [ 85 # KEYWORD STATISTIC CHIPTOOL FLAG 86 { name => "bg", type => "mean", flag => "-bg" }, 87 { name => "bg_mean_stdev", type => "stdev", flag => "-bg_mean_stdev" }, 88 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 89 { name => "bin_stdev", type => "rms", flag => "-bin_stdev" }, 90 { name => "fringe_0", type => "mean", flag => "-fringe_0" }, 91 { name => "fringe_1", type => "rms", flag => "-fringe_1" }, 92 { name => "fringe_0", type => "stdev", flag => "-fringe_2" }, 93 { name => "user_1", type => "mean", flag => "-user_1" }, # fringe residual 94 { name => "user_2", type => "rms", flag => "-user_2" }, # fringe residual 95 { name => "user_3", type => "stdev", flag => "-user_1" }, # fringe residual 96 ]; 91 97 92 98 # Look for programs we need … … 98 104 exit($PS_EXIT_CONFIG_ERROR); 99 105 } 100 101 # Parser for psMetadataConfig files (used for output from dettool)102 my $mdcParser = PS::IPP::Metadata::Config->new;103 106 104 107 # Get list of imfile files … … 120 123 # XXX report an error message if stdout_buf is empty 121 124 125 # Parse the stdout buffer into a metadata 126 my $mdcParser = PS::IPP::Metadata::Config->new; 122 127 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 123 128 &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR); 124 129 130 # parse the file info in the metadata 125 131 $files = parse_md_list($metadata) or 126 132 &my_die("Unable to parse metadata list", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR); 133 134 # Parse the statistics on the residual image 135 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 136 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 127 137 } 128 138 … … 136 146 my $logFile; 137 147 unless ($no_op) { 138 # XXX this will fail if the file exists (because of Nebulous rules)139 148 $logFile = $ipprc->file_create_append( $logName ); 140 149 } 141 142 #### build the JPEG images ####143 150 144 151 # XXX in debug mode, unlink = 0 … … 152 159 close $list2File; 153 160 154 # Recipes to use in processing 155 my $recipe1 = RECIPES->{"bin1"}->{lc($det_type)}; 156 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe1; 157 158 my $recipe2 = RECIPES->{"bin2"}->{lc($det_type)}; 159 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe2; 160 161 162 # build the JPEG images 161 163 unless ($no_op) { 162 164 … … 206 208 207 209 # storage variables 208 my @means; # Array of means209 my @fluxes; # Array of means / exptimes210 my @variances; # Array of variances211 my @binVariances; # Array of binned variances212 my @meanStdevs; # Array of mean stdevs213 my @names; # Array of names (class_id)214 my @fringe_means;215 my @fringe_vars;216 my @dfringe_means;217 my @dfringe_vars;218 210 219 211 # load the arrays from the imfile output table 220 212 foreach my $file (@$files) { 221 push @means, $file->{bg}; # mean background counts222 213 if ($file->{exp_time} > 0.0) { 223 214 push @fluxes, $file->{bg} / $file->{exp_time}; # mean background counts / sec … … 225 216 push @fluxes, $file->{bg}; 226 217 } 227 push @meanStdevs, $file->{bg_mean_stdev}; # stdev of the mean counts (for imfile components)228 push @variances, $file->{bg_stdev}*$file->{bg_stdev}; # total variance from all imfile components229 push @binVariances, $file->{bin_stdev}*$file->{bin_stdev}; # total variance of binned images over all imfile components230 push @names, $file->{class_id}; # name of the component231 push @fringe_means, $file->{fringe_0}; # fringe amplitude mean for imfile232 push @fringe_vars, $file->{fringe_1}*$file->{fringe_1}; # fringe variance233 push @dfringe_means, $file->{user_1}; # fringe residual mean for imfile234 push @dfringe_vars, $file->{user_2}*$file->{user_2}; # fringe residual variance235 # push @fringe_mean_stdev, $file->{fringe_2}; # fringe amplitude stdev for imfile236 218 } 237 219 … … 239 221 # it is VALID to reject on more than one criterion 240 222 &my_die("Number of means and number of variances differ!", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless scalar @means == scalar @variances; 241 for (my $i = 0; $i < scalar @means; $i++) { 242 my $flux = $fluxes[$i]; # Flux for this imfile 243 my $mean = $means[$i]; # Mean for this imfile 223 224 # storage array 225 my @fluxes; 226 227 for (my $i = 0; $i < scalar @$files; $i++) { 228 my $file = $files[$i]; 229 my $name = $file->{class_id}; 230 my $mean = $file->{bg}; # Mean for this imfile 231 my $stdev = $file->{bg_stdev}; # Stdev for this imfile 232 my $meanStdev = $file->{bg_mean_stdev}; # Stdev of Means for this imfile 233 my $binStdev = $file->{bin_stdev}; # Binned Stdev for this imfile 234 235 # calculate and save the fluxes 236 my $flux = $mean / $file->{exp_time}; 237 if ($file->{exp_time} == 0.0) { 238 push @fluxes, $mean; 239 } 240 push @fluxes, $flux; 241 244 242 $mean -= $expected; 245 my $stdev = sqrt($variances[$i]); # Stdev for this imfile246 my $binStdev = sqrt($binVariances[$i]); # Stdev for this imfile247 my $name = $names[$i];248 243 249 244 last if $no_op; … … 301 296 # component means is larger than the limit 302 297 if ($reject_imfile_meanstdev > 0) { 303 if ($meanStdevs [$i]> $reject_imfile_meanstdev) {298 if ($meanStdevs > $reject_imfile_meanstdev) { 304 299 print $logFile "Rejecting exposure based on bad imfile mean stdev for $name: "; 305 300 $reject = 1; … … 307 302 print $logFile "Imfile mean stdev for $name meets requirements: "; 308 303 } 309 print $logFile "$meanStdevs [$i]vs $reject_imfile_meanstdev\n";304 print $logFile "$meanStdevs vs $reject_imfile_meanstdev\n"; 310 305 } else { 311 306 print $logFile "No rejection on imfile mean stdev for $name\n"; … … 356 351 } 357 352 358 # calculate the exposure ensemble statistics 359 my $meanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means 360 $meanStats->add_data(@means); 353 # basic ensemble stats 354 my $mean = &STATS_value_for_flag ($STATS, "-bg"); 355 my $meanStdev = &STATS_value_for_flag ($STATS, "-bg_mean_stdev"); 356 my $stdev = &STATS_value_for_flag ($STATS, "-bg_stdev"); 357 my $binStdev = &STATS_value_for_flag ($STATS, "-bin_stdev"); 358 my $fringe_mean = &STATS_value_for_flag ($STATS, "-fringe_0"); 359 my $fringe_err = &STATS_value_for_flag ($STATS, "-fringe_1"); 360 my $fringe_mean_stdev = &STATS_value_for_flag ($STATS, "-fringe_2"); 361 my $dfringe_mean = &STATS_value_for_flag ($STATS, "-user_1"); 362 my $dfringe_err = &STATS_value_for_flag ($STATS, "-user_2"); 363 my $dfringe_mean_stdev = &STATS_value_for_flag ($STATS, "-user_3"); 364 365 # other stats (flux depends on bg and exp_time) 361 366 my $fluxStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means 362 367 $fluxStats->add_data(@fluxes); 363 my $varianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for variances364 $varianceStats->add_data(@variances);365 my $binVarianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for variances366 $binVarianceStats->add_data(@binVariances);367 368 # background stats369 my $mean = $meanStats->mean(); # Mean of the imfile means370 368 my $flux = $fluxStats->mean(); # Mean of the imfile means 371 my $meanStdev = $meanStats->standard_deviation(); # Stdev of the imfile means 372 if (not defined $meanStdev) { 373 # this is the case for Nimfile == 1 374 $meanStdev = 0; 375 } 376 my $stdev = sqrt($varianceStats->mean()); # Root-Mean-Square of the imfile stdevs (root mean of variances) 377 my $binStdev = sqrt($binVarianceStats->mean()); # Root-Mean-Square of the imfile stdevs (root mean of variances) 369 370 # other stats 378 371 my $exp_sn = 0.0; 379 372 if ($stdev > 0) { $exp_sn = $mean / $stdev; } 380 381 # prepare fringe amplitude stats382 my $fringeMeanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means383 $fringeMeanStats->add_data(@fringe_means);384 my $fringeVarStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means385 $fringeVarStats->add_data(@fringe_vars);386 387 # fringe amplitude stats388 my $fringe_mean = $fringeMeanStats->mean();389 my $fringe_err = sqrt($fringeVarStats->mean());390 my $fringe_mean_stdev = $fringeMeanStats->standard_deviation();391 if (not defined $fringe_mean_stdev) {392 $fringe_mean_stdev = 0;393 }394 395 # prepare fringe residual stast396 my $dfringeMeanStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means397 $dfringeMeanStats->add_data(@dfringe_means);398 my $dfringeVarStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means399 $dfringeVarStats->add_data(@dfringe_vars);400 401 # fringe amplitude stats402 my $dfringe_mean = $dfringeMeanStats->mean();403 my $dfringe_err = sqrt($dfringeVarStats->mean());404 my $dfringe_mean_stdev = $dfringeMeanStats->standard_deviation();405 if (not defined $dfringe_mean_stdev) {406 $dfringe_mean_stdev = 0;407 }408 373 409 374 ## Reject based on the exposure ensemble stats … … 514 479 } 515 480 516 # Add the result into the database 517 my $bg = $mean; 518 my $bg_stdev = $stdev; 519 my $bg_mean_stdev = $meanStdev; 520 my $bin_stdev = $binStdev; 481 my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag"; 482 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot "; 483 $command .= ' -reject' if $reject; 484 $command .= " -dbname $dbname" if defined $dbname; 485 486 # add in the elements from the selected stats above 487 foreach my $entry (@$STATS) { 488 my $value = $entry->{value}; 489 my $flag = $entry->{flag}; 490 $command .= " $flag $value"; 491 } 521 492 522 493 unless ($no_update) { 523 my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag";524 $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot ";525 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev -bin_stdev $bin_stdev";526 $command .= " -fringe_0 $fringe_mean -fringe_1 $fringe_err -fringe_2 $fringe_mean_stdev";527 $command .= " -user_1 $dfringe_mean -user_2 $dfringe_err -user_3 $dfringe_mean_stdev";528 $command .= ' -reject' if $reject;529 $command .= " -dbname $dbname" if defined $dbname;530 494 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 531 495 run(command => $command, verbose => 1); … … 535 499 exit($error_code); 536 500 } 501 } else { 502 print "skipping command: $command\n"; 537 503 } 538 504 … … 555 521 carp($msg); 556 522 if ($det_id and $iter and $exp_tag and not $no_update) { 557 my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag -code $exit_code"; 523 my $command = "$dettool -addresidexp"; 524 $command .= " -det_id $det_id"; 525 $command .= " -iteration $iter"; 526 $command .= " -exp_tag $exp_tag"; 527 $command .= " -code $exit_code"; 558 528 $command .= " -dbname $dbname" if defined $dbname; 559 529 ### system ($command); … … 561 531 exit $exit_code; 562 532 } 563 564 533 565 534 # Retrieve the requested rejection limit, dying if not extant … … 579 548 } 580 549 581 582 550 sub STATS_value_for_flag 551 { 552 my $STATS = shift; 553 my $flag = shift; 554 555 foreach my $entry (@$STATS) { 556 if ($flag eq $entry->{flag}) { 557 return $entry->{value}; 558 } 559 } 560 return 'NAN'; 561 } 583 562 584 563 __END__ -
trunk/ippScripts/scripts/detrend_resid.pl
r13973 r14009 17 17 use PS::IPP::Metadata::Config; 18 18 use PS::IPP::Metadata::Stats; 19 use Data::Dumper;20 19 21 20 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 33 32 use Pod::Usage qw( pod2usage ); 34 33 35 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend, 36 $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op); 34 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op); 37 35 GetOptions( 38 36 'det_id|d=s' => \$det_id, … … 53 51 54 52 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 55 pod2usage( 56 -msg => "Required options: --det_id --iteration --exp_tag --class_id --det_type --camera --input_uri --mode --detrend (not for 'verify' mode)", 57 -exitval => 3, 58 ) unless defined $det_id 53 pod2usage( -msg => "Required options: --det_id --iteration --exp_tag --class_id --det_type --camera --input_uri --mode --detrend (not for 'verify' mode)", 54 -exitval => 3) 55 unless defined $det_id 59 56 and defined $iter 60 57 and defined $exp_tag … … 68 65 $ipprc->define_camera($camera); 69 66 67 # Recipes to use as a function of detrend type and mode 70 68 $reduction = 'DETREND' unless defined $reduction; 71 69 my $recipe; # Name of recipe to use … … 78 76 } 79 77 $recipe = $ipprc->reduction($reduction, $recipe); 78 79 # values to extract from output metadata and the stats to calculate 80 my $STATS = 81 [ 82 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG 83 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg" }, 84 { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev" }, 85 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev" }, 86 { name => "FRINGE_0", type => "mean", flag => "-fringe_0" }, 87 { name => "FRINGE_ERR_0", type => "rms", flag => "-fringe_1" }, 88 { name => "FRINGE_0", type => "stdev", flag => "-fringe_2" }, 89 { name => "FRINGE_RESID_0", type => "mean", flag => "-user_1" }, 90 { name => "FRINGE_RESID_ERR_0", type => "rms", flag => "-user_2" }, 91 { name => "FRINGE_RESID_0", type => "stdev", flag => "-user_3" }, 92 ]; 93 my $BINNED_STATS = 94 [ 95 { name => "ROBUST_STDEV", type => "rms", flag => "-bin_stdev" }, 96 ]; 80 97 81 98 # Flags to specify the particular detrend to use … … 106 123 107 124 my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detresid.$det_id.$iter", $workdir, $input_uri ); 108 my $outputName = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id); 109 my $bin1Name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 110 my $bin2Name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 111 my $outputStats = $outputRoot . '.' . $class_id . '.stats'; 125 126 my $outputName = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id); 127 my $bin1Name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id); 128 my $bin2Name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id); 129 my $outputStats = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id); 112 130 113 131 # Run ppImage & ppStats 114 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser115 my $binnedStats = PS::IPP::Metadata::Stats->new(); # Stats parser116 132 unless ($no_op) { 117 133 my $command = "$ppImage -file $input_uri $outputRoot"; … … 144 160 close $statsFile; 145 161 146 # Parse the stat istics on the residual image162 # Parse the stats file contents into a metadata 147 163 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 148 164 my $metadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 165 166 # Parse the statistics on the residual image 167 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 149 168 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 150 169 … … 160 179 # parse the binned image statistics 161 180 my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 181 182 my $binnedStats = PS::IPP::Metadata::Stats->new($BINNED_STATS); # Stats parser 162 183 $binnedStats->parse($binnedMetadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR); 163 184 } 164 185 186 # Command to update the database 187 my $command = "$dettool -addresidimfile"; 188 $command .= " -det_id $det_id"; 189 $command .= " -iteration $iter"; 190 $command .= " -exp_tag $exp_tag"; 191 $command .= " -class_id $class_id"; 192 $command .= " -recip $recipe"; 193 $command .= " -uri $outputName"; 194 $command .= " -path_base $outputRoot"; 195 $command .= " -dbname $dbname" if defined $dbname; 196 197 # add in the elements from the selected stats above 198 foreach my $entry (@$STATS @$BINNED_STATS) { 199 my $value = $entry->{value}; 200 my $flag = $entry->{flag}; 201 $command .= " $flag $value"; 202 } 203 165 204 # Add the processed file to the database 166 # these value must be defined (NAN if not valid), or we raise a programming error167 my $bg = $stats->bg_mean();168 my $bg_stdev = $stats->bg_stdev();169 my $bg_mean_stdev = $stats->bg_mean_stdev();170 my $bin_stdev = $binnedStats->bg_stdev();171 my $fringe_0 = ${$stats->fringe_mean()}[0];172 my $fringe_1 = ${$stats->fringe_err()}[0];173 my $fringe_2 = ${$stats->fringe_mean_stdev()}[0];174 my $dfringe_0 = ${$stats->dfringe_mean()}[0];175 my $dfringe_1 = ${$stats->dfringe_err()}[0];176 my $dfringe_2 = ${$stats->dfringe_mean_stdev()}[0];177 178 print "bg_mean_stdev: " . $bg_mean_stdev . "\n";179 print "stats : bg_mean_stdev: " . $stats->bg_mean_stdev() . "\n";180 181 205 unless ($no_update) { 182 my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter";183 $command .= " -exp_tag $exp_tag -class_id $class_id";184 $command .= " -recip $recipe -uri $outputName -path_base $outputRoot";185 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";186 $command .= " -bin_stdev $bin_stdev";187 $command .= " -fringe_0 $fringe_0 -fringe_1 $fringe_1 -fringe_2 $fringe_2";188 $command .= " -user_1 $dfringe_0 -user_2 $dfringe_1 -user_3 $dfringe_2";189 $command .= " -dbname $dbname" if defined $dbname;190 191 206 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 192 207 run(command => $command, verbose => 1); … … 196 211 exit($error_code); 197 212 } 213 } else { 214 print "skipping command: $command\n"; 198 215 } 199 216 … … 209 226 carp($msg); 210 227 if ($det_id and $iter and $exp_tag and not $no_update) { 211 my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter -exp_tag $exp_tag -class_id $class_id -code $exit_code"; 228 my $command = "$dettool -addresidimfile"; 229 $command .= " -det_id $det_id"; 230 $command .= " -iteration $iter"; 231 $command .= " -exp_tag $exp_tag"; 232 $command .= " -class_id $class_id"; 233 $command .= " -code $exit_code"; 212 234 $command .= " -dbname $dbname" if defined $dbname; 213 235 ### system ($command); -
trunk/ippScripts/scripts/detrend_stack.pl
r13989 r14009 16 16 use IPC::Cmd 0.36 qw( can_run run ); 17 17 use PS::IPP::Metadata::Config; 18 use PS::IPP::Metadata::Stats; 18 19 use PS::IPP::Metadata::List qw( parse_md_list ); 19 use PS::IPP::Metadata::Stats;20 20 21 21 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 41 41 'camera|c=s' => \$camera, 42 42 'dbname|d=s' => \$dbname, # Database name 43 'workdir|w=s' => \$workdir, # Working directory, for output files43 'workdir|w=s' => \$workdir, # Working directory, for output files 44 44 'reduction=s' => \$reduction, # Reduction class for processing 45 45 'no-update' => \$no_update, … … 49 49 50 50 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 51 pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera", -exitval => 3 ) 51 pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera", 52 -exitval => 3) 52 53 unless defined $det_id 53 54 and defined $iter … … 64 65 $reduction = "DETREND" unless defined $reduction; 65 66 my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_STACK'); # Recipe name to use 67 68 # values to extract from output metadata and the stats to calculate 69 # XXX -bg_mean_stdev should take rms of bg_mean_stdev if bg_mean_stdev != 0 (A) 70 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0 (B) 71 # XXX (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1 72 my $STATS = 73 [ 74 # KEYWORD STATISTIC CHIPTOOL FLAG 75 { name => "bg", type => "mean", flag => "-bg" }, 76 { name => "bg", type => "stdev", flag => "-bg_mean_stdev" }, 77 { name => "bg_stdev", type => "rms", flag => "-bg_stdev" }, 78 # { name => "bg_mean_stdev", type => "rms", flag => "-bg_mean_stdev" }, 79 ]; 66 80 67 81 # Look for programs we need … … 74 88 } 75 89 76 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 90 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 91 92 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} ); 93 my $outputStack = $outputRoot . '.fits'; # Output name 94 my $outputStats = $outputRoot . '.stats'; # Statistics name 77 95 78 96 # Get list of files to stack 79 97 my $files; # Array of files to be stacked 80 98 { 81 my $command = "$dettool -processedimfile -det_id $det_id -class_id $class_id -included"; # Command to run 99 my $command = "$dettool -processedimfile -included"; 100 $command .= " -det_id $det_id"; 101 $command .= " -class_id $class_id"; 82 102 $command .= " -dbname $dbname" if defined $dbname; 103 83 104 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 84 105 run(command => $command, verbose => $verbose); … … 87 108 &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $iter, $class_id, $error_code); 88 109 } 110 111 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 89 112 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 90 113 &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); … … 93 116 } 94 117 95 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir; 96 97 my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} ); 98 my $outputStack = $outputRoot . '.fits'; # Output name 99 my $outputStats = $outputRoot . '.stats'; # Statistics name 118 my $command = "$ppMerge $outputStack"; # Command to run 119 foreach my $file (@$files) { 120 $command .= ' ' . $file->{uri}; 121 } 122 $command .= " -recipe PPMERGE $recipe"; 123 $command .= ' -type ' . uc($det_type); # Type of stacking to perform 124 $command .= " -stats $outputStats"; # Statistics output filename 125 $command .= " -recipe PPSTATS CHIPSTATS"; 100 126 101 127 # Stack the files 102 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser103 128 unless ($no_op) { 104 my $command = "$ppMerge $outputStack"; # Command to run105 foreach my $file (@$files) {106 $command .= ' ' . $file->{uri};107 }108 $command .= " -recipe PPMERGE $recipe";109 $command .= ' -type ' . uc($det_type); # Type of stacking to perform110 $command .= " -stats $outputStats"; # Statistics output filename111 $command .= " -recipe PPSTATS CHIPSTATS";112 129 113 130 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 129 146 my $metadata = $mdcParser->parse($contents) or 130 147 &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR); 131 $stats = PS::IPP::Metadata::Stats->new(); # Stats parser 148 149 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser 132 150 $stats->parse($metadata) or 133 151 &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR); 134 152 } 135 153 136 my $bg = $stats->bg_mean(); 137 my $bg_stdev = $stats->bg_stdev(); 138 my $bg_mean_stdev = $stats->bg_mean_stdev(); 154 # Command to update the database 155 $command = "$dettool -addstacked"; 156 $command .= " -det_id $det_id -iteration $iter"; 157 $command .= " -class_id $class_id"; 158 $command .= " -uri $outputStack"; 159 $command .= " -recip $recipe"; 160 $command .= " -dbname $dbname" if defined $dbname; 161 162 # add in the elements from the selected stats above 163 foreach my $entry (@$STATS) { 164 my $value = $entry->{value}; 165 my $flag = $entry->{flag}; 166 $command .= " $flag $value"; 167 } 139 168 140 169 # Add the resultant into the database 141 170 unless ($no_update) { 142 my $command = "$dettool -addstacked";143 $command .= " -det_id $det_id -iteration $iter";144 $command .= " -class_id $class_id";145 $command .= " -uri $outputStack";146 $command .= " -recip $recipe";147 $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";148 $command .= " -dbname $dbname" if defined $dbname;149 150 171 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 151 172 run(command => $command, verbose => $verbose); … … 155 176 exit($error_code); 156 177 } 157 } 158 178 } else { 179 print "skipping command: $command\n"; 180 } 159 181 160 182 sub my_die … … 168 190 carp($msg); 169 191 if ($det_id and $iter and $class_id and not $no_update) { 170 my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code"; 192 my $command = "$dettool -addstacked"; 193 $command .= " -det_id $det_id"; 194 $command .= " -iteration $iter"; 195 $command .= " -class_id $class_id"; 196 $command .= " -code $exit_code"; 171 197 $command .= " -dbname $dbname" if defined $dbname; 172 198 ### system ($command); -
trunk/ippScripts/scripts/register_imfile.pl
r13989 r14009 98 98 99 99 # setup cache interface 100 100 # XXX why is this being cached? 101 101 my $c = Cache::File->new( 102 102 cache_root => File::Spec->catdir($ENV{'HOME'}, '.pxtools', basename($0)), … … 125 125 my @constants = keys %{CONSTANTS()}; # List of constants to parse out 126 126 my @variables = keys %{VARIABLES()}; # List of variables to parse out 127 127 128 $stats = PS::IPP::Metadata::Stats->new(\@constants, \@variables); # Stats parser 128 129 unless ($stats->parse($metadata)) { 129 130 warn ("Unable to find all values"); 130 131 &my_die ($exp_tag, $class_id, $PS_EXIT_CONFIG_ERROR); 131 }132 133 if (0) {134 # XXX for a test, randomly declare a failure and return to pantasks135 my $rnd = rand(1);136 if ($rnd > 0.5) {137 warn ("random failure");138 &my_die ($exp_tag, $class_id, $PS_EXIT_DATA_ERROR);139 }140 132 } 141 133 }
Note:
See TracChangeset
for help on using the changeset viewer.
