Changeset 20101
- Timestamp:
- Oct 13, 2008, 11:36:56 AM (18 years ago)
- Location:
- trunk/ippScripts/scripts
- Files:
-
- 5 edited
-
diff_skycell.pl (modified) (5 diffs)
-
register_exp.pl (modified) (5 diffs)
-
register_imfile.pl (modified) (7 diffs)
-
stack_skycell.pl (modified) (5 diffs)
-
warp_skycell.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/diff_skycell.pl
r20062 r20101 18 18 use IPC::Cmd 0.36 qw( can_run run ); 19 19 use PS::IPP::Metadata::Config; 20 use PS::IPP::Metadata::Stats;21 20 use PS::IPP::Metadata::List qw( parse_md_list ); 22 21 use Data::Dumper; … … 53 52 $ipprc->redirect_output($logDest) if $redirect; 54 53 55 my $STATS =56 [57 # PPSTATS KEYWORD STATISTIC DIFFTOOL FLAG58 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg", dtype => "float" },59 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev", dtype => "float" },60 { name => "TIME_SUB", type => "sum", flag => "-dtime_diff", dtype => "float" },61 { name => "TIME_MATCH", type => "sum", flag => "-dtime_match", dtype => "float" },62 { name => "TIME_PHOT", type => "sum", flag => "-dtime_phot", dtype => "float" },63 { name => "SUBTRACTION.STAMPS", type => "mean", flag => "-stamps_num", dtype => "int" },64 { name => "SUBTRACTION.DEV.MEAN", type => "mean", flag => "-stamps_mean", dtype => "float" },65 { name => "SUBTRACTION.DEV.RMS", type => "mean", flag => "-stamps_rms", dtype => "float" },66 { name => "SUBTRACTION.NORM", type => "mean", flag => "-norm", dtype => "float" },67 { name => "SUBTRACTION.BGDIFF", type => "mean", flag => "-bg_diff", dtype => "float" },68 { name => "SUBTRACTION.MX", type => "mean", flag => "-kernel_x", dtype => "float" },69 { name => "SUBTRACTION.MY", type => "mean", flag => "-kernel_y", dtype => "float" },70 { name => "SUBTRACTION.MXX", type => "mean", flag => "-kernel_xx", dtype => "float" },71 { name => "SUBTRACTION.MXY", type => "mean", flag => "-kernel_xy", dtype => "float" },72 { name => "SUBTRACTION.MYY", type => "mean", flag => "-kernel_yy", dtype => "float" },73 { name => "NUM_SOURCES", type => "sum", flag => "-sources", dtype => "int" },74 { name => "GOOD_PIXEL_FRAC", type => "mean", flag => "-good_frac", dtype => "float" },75 ];76 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser77 78 54 # Look for programs we need 79 55 my $missing_tools; 80 56 my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1); 81 57 my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" and $missing_tools = 1); 58 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 82 59 if ($missing_tools) { 83 60 warn("Can't find required tools."); … … 204 181 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot); 205 182 183 my $cmdflags; 184 206 185 # Perform subtraction 207 186 unless ($no_op) { … … 233 212 # &my_die("Couldn't find expected output file: $bin1Name", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name); 234 213 # &my_die("Couldn't find expected output file: $bin2Name", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name); 235 &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats); 236 237 # Get the statistics on the residual image 238 my $statsFile; # File handle 239 open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $diff_id, $PS_EXIT_SYS_ERROR); 240 my @contents = <$statsFile>; # Contents of file 241 close $statsFile; 242 my $metadata = $mdcParser->parse(join "", @contents) or 243 &my_die("Unable to parse metadata config doc", $diff_id, $PS_EXIT_PROG_ERROR); 244 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $diff_id, $PS_EXIT_PROG_ERROR); 214 215 my $outputStatsReal = $ipprc->file_resolve($outputStats); 216 &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless unless -f $outputStatsReal; 217 218 # measure chip stats 219 $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL"; 220 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 221 run(command => $command, verbose => $verbose); 222 unless ($success) { 223 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 224 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $error_code); 225 } 226 foreach my $line (@$stdout_buf) { 227 $cmdflags .= " $line"; 228 } 229 chomp $cmdflags; 245 230 } 246 231 … … 250 235 { 251 236 my $command = "$difftool -adddiffskyfile -diff_id $diff_id -uri $outputName -path_base $outroot"; 252 $command .= $stats->cmdflags();237 $command .= " $cmdflags"; 253 238 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 254 239 $command .= " -hostname $host" if defined $host; -
trunk/ippScripts/scripts/register_exp.pl
r19779 r20101 19 19 use IPC::Cmd 0.36 qw( can_run run ); 20 20 use PS::IPP::Metadata::Config; 21 use PS::IPP::Metadata::Stats;22 21 use PS::IPP::Config 1.01 qw( :standard ); 23 22 … … 51 50 my $DETREND_FLAG = "-end_stage reg"; # Flag to use to mark detrend exposure 52 51 53 # values to extract from output metadata and the stats to calculate54 my $STATS =55 [ # register imfile56 # label STATISTIC CHIPTOOL FLAG57 { name => "exp_name", type => "constant", flag => "-exp_name", dtype => "string" }, # File level58 { name => "telescope", type => "constant", flag => "-telescope", dtype => "string" }, # File level59 { name => "camera", type => "constant", flag => "-inst", dtype => "string" }, # File level60 { name => "filelevel", type => "constant", flag => "-filelevel", dtype => "string" }, # File level61 { name => "object", type => "constant", flag => "-object", dtype => "string" },62 { name => "exp_type", type => "constant", flag => "-exp_type", dtype => "string" }, # File level63 { name => "filter", type => "constant", flag => "-filter", dtype => "string" }, # File level64 { name => "comment", type => "constant", flag => "-comment", dtype => "string" }, # ObsComment65 { name => "dateobs", type => "constant", flag => "-dateobs", dtype => "string" }, # File level66 { name => "ccd_temp", type => "mean", flag => "-ccd_temp", dtype => "float" }, # CCD temperature67 { name => "exp_time", type => "mean", flag => "-exp_time", dtype => "float" }, # Exposure time68 { name => "sat_pixel_frac", type => "mean", flag => "-sat_pixel_frac", dtype => "float" }, # Fraction of saturated pixels69 { name => "airmass", type => "mean", flag => "-airmass", dtype => "float" }, # Airmass70 { name => "ra", type => "mean", flag => "-ra", dtype => "float" }, # Right ascension71 { name => "decl", type => "mean", flag => "-decl", dtype => "float" }, # Declination72 { name => "posang", type => "mean", flag => "-posang", dtype => "float" }, # Position angle73 { name => "alt", type => "mean", flag => "-alt", dtype => "float" }, # Altitude74 { name => "az", type => "mean", flag => "-az", dtype => "float" }, # Azimuth75 { name => "m1_x", type => "constant", flag => "-m1_x", dtype => "float" }, # M1X76 { name => "m1_y", type => "constant", flag => "-m1_y", dtype => "float" }, # M1Y77 { name => "m1_z", type => "constant", flag => "-m1_z", dtype => "float" }, # M1Z78 { name => "m1_tip", type => "constant", flag => "-m1_tip", dtype => "float" }, # M1TIP79 { name => "m1_tilt", type => "constant", flag => "-m1_tilt", dtype => "float" }, # M1TILT80 { name => "m2_x", type => "constant", flag => "-m2_x", dtype => "float" }, # M2X81 { name => "m2_y", type => "constant", flag => "-m2_y", dtype => "float" }, # M2Y82 { name => "m2_z", type => "constant", flag => "-m2_z", dtype => "float" }, # M2Z83 { name => "m2_tip", type => "constant", flag => "-m2_tip", dtype => "float" }, # M2TIP84 { name => "m2_tilt", type => "constant", flag => "-m2_tilt", dtype => "float" }, # M2TILT85 { name => "env_temperature", type => "constant", flag => "-env_temperature", dtype => "float" }, # external temp86 { name => "env_humidity", type => "constant", flag => "-env_humidity", dtype => "float" }, # external humidity87 { name => "env_wind_speed", type => "constant", flag => "-env_wind_speed", dtype => "float" }, # external wind speed88 { name => "env_wind_dir", type => "constant", flag => "-env_wind_dir", dtype => "float" }, # external wind direction89 90 { name => "teltemp_m1", type => "constant", flag => "-teltemp_m1", dtype => "float" }, # Primary mirror temps (C)91 { name => "teltemp_m1cell", type => "constant", flag => "-teltemp_m1cell", dtype => "float" }, # Primary mirror support temps (C)92 { name => "teltemp_m2", type => "constant", flag => "-teltemp_m2", dtype => "float" }, # Secondary mirror temps (C93 { name => "teltemp_spider", type => "constant", flag => "-teltemp_spider", dtype => "float" }, # Spider temperatures (C)94 { name => "teltemp_truss", type => "constant", flag => "-teltemp_truss", dtype => "float" }, # Mid truss temperatures (C95 { name => "teltemp_extra", type => "constant", flag => "-teltemp_extra", dtype => "float" }, # Miscellaneous temperatures (C)96 97 { name => "sun_angle", type => "constant", flag => "-sun_angle", dtype => "float" }, # Angle to sun98 { name => "sun_alt", type => "constant", flag => "-sun_alt", dtype => "float" }, # Altitude of sun99 { name => "moon_angle", type => "constant", flag => "-moon_angle", dtype => "float" }, # Angle to moon100 { name => "moon_alt", type => "constant", flag => "-moon_alt", dtype => "float" }, # Altitude of moon101 { name => "moon_phase", type => "constant", flag => "-moon_phase", dtype => "float" }, # Phase of moon102 103 { name => "pon_time", type => "mean", flag => "-pon_time", dtype => "float" }, # time since last power on104 { name => "bg", type => "mean", flag => "-bg", dtype => "float" }, # background105 { name => "bg", type => "stdev", flag => "-bg_mean_stdev", dtype => "float" }, # Azimuth106 { name => "bg_stdev", type => "rms", flag => "-bg_stdev", dtype => "float" }, # Azimuth107 ];108 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser109 110 52 # Look for commands we need 111 53 my $missing_tools; … … 136 78 } 137 79 138 # Parse the output 139 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 140 my $metadata = $mdcParser->parse(join "", @$stdout_buf); 141 unless ($metadata) { 142 &my_die ("Unable to parse metadata config doc", $exp_id, $PS_EXIT_PROG_ERROR); 80 # since I can't figure out how to do input and output within PERL, I'm writing to a temp file 81 my ($statFile, $statName) = tempfile( "/tmp/$exp_id.register.XXXX", UNLINK => !$save_temps ); 82 print "saving stats to $statName\n"; 83 foreach my $line (@$stdout_buf) { 84 print $statFile $line; 85 } 86 close $statFile; 87 88 # parse the stats in the metadata file 89 $command = "$ppStatsFromMetadata $statName - REGISTER_EXP"; 90 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 91 run(command => $command, verbose => $verbose); 92 unless ($success) { 93 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 94 warn("Unable to perform ppStatsFromMetadata: $error_code\n"); 95 exit($error_code); 143 96 } 144 97 145 # extract the stats from the metadata 146 unless ($stats->parse($metadata)) { 147 &my_die ("Unable to find all values", $exp_id, $PS_EXIT_CONFIG_ERROR); 98 foreach my $line (@$stdout_buf) { 99 $cmdflags .= " $line"; 148 100 } 149 101 } 150 102 151 # we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type 152 if (uc($stats->value_for_flag ("-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 153 if (uc($stats->value_for_flag ("-inst")) eq "NULL") { &my_die ("inst not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 154 if (uc($stats->value_for_flag ("-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 155 if (uc($stats->value_for_flag ("-exp_type")) eq "NULL") { &my_die ("exp_type not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 156 if (uc($stats->value_for_flag ("-exp_name")) eq "NULL") { &my_die ("exp_name not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 103 # we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_name, -exp_type 104 if (uc(&value_for_flag ($cmdflags, "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 105 if (uc(&value_for_flag ($cmdflags, "-inst")) eq "NULL") { &my_die ("inst not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 106 if (uc(&value_for_flag ($cmdflags, "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 107 if (uc(&value_for_flag ($cmdflags, "-exp_name")) eq "NULL") { &my_die ("exp_name not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 108 109 my $exp_type = &value_for_flag ("-exp_type"); 110 if (uc($exp_type) eq "NULL") { &my_die ("exp_type not found", $exp_id, $PS_EXIT_CONFIG_ERROR); } 157 111 158 112 my $command = "$regtool -addprocessedexp"; … … 161 115 $command .= " -hostname $host" if defined $host; 162 116 $command .= " -dbname $dbname" if defined $dbname; 163 $command .= $stats->cmdflags(); 164 165 my $exp_type = $stats->value_for_flag ("-exp_type"); 117 $command .= " $cmdflags"; 166 118 167 119 # Add the detrend flag, if needed … … 206 158 } 207 159 160 sub value_for_flag 161 { 162 my $cmdflags = shift; 163 my $flag = shift; 164 165 my $value = 0.0; 166 if ($cmdflags =~ m|$flag|) { 167 ($value) = $cmdflags =~ m|$flag\s+(\S+)|; 168 } 169 $value; 170 } 171 208 172 sub my_die 209 173 { -
trunk/ippScripts/scripts/register_imfile.pl
r19733 r20101 20 20 use PS::IPP::Config 1.01 qw( :standard ); 21 21 use PS::IPP::Metadata::Config; 22 use PS::IPP::Metadata::Stats;23 22 24 23 my $PI = 3.141592653589793238462643383279502; … … 57 56 my $RECIPE = "REGISTER"; # Recipe to use for ppStats 58 57 59 # values to extract from output metadata and the stats to calculate60 my $STATS =61 [62 # PPSTATS KEYWORD STATISTIC CHIPTOOL FLAG63 { name => "FILE.LEVEL", type => "constant", flag => "-filelevel", dtype => "string" }, # File level64 { name => "CLASS.ID", type => "constant", flag => "-class_id", dtype => "string" }, # Real Class ID65 { name => "FPA.OBJECT", type => "constant", flag => "-object", dtype => "string" }, # Object66 { name => "FPA.OBSTYPE", type => "constant", flag => "-exp_type", dtype => "string" }, # Exposure type67 { name => "FPA.FILTER", type => "constant", flag => "-filter", dtype => "string" }, # Filter used68 { name => "FPA.COMMENT", type => "constant", flag => "-comment", dtype => "string" }, # Obs Comment69 { name => "FPA.AIRMASS", type => "constant", flag => "-airmass", dtype => "float" }, # Airmass70 { name => "FPA.RA", type => "constant", flag => "-ra", dtype => "float" }, # Right ascension71 { name => "FPA.DEC", type => "constant", flag => "-decl", dtype => "float" }, # Declination72 { name => "FPA.ALT", type => "constant", flag => "-alt", dtype => "float" }, # Altitude73 { name => "FPA.AZ", type => "constant", flag => "-az", dtype => "float" }, # Azimuth74 { name => "FPA.POSANGLE", type => "constant", flag => "-posang", dtype => "float" }, # Position angle75 { name => "FPA.TIME", type => "constant", flag => "-dateobs", dtype => "string" }, # Date of observation (UTC)76 { name => "FPA.TELESCOPE", type => "constant", flag => "-telescope", dtype => "string" }, # Telescope77 { name => "FPA.CAMERA", type => "constant", flag => "-inst", dtype => "string" }, # Instrument78 { name => "FPA.LONGITUDE", type => "constant", flag => "-longitude", dtype => "float" }, # Site longitude79 { name => "FPA.LATITUDE", type => "constant", flag => "-latitude", dtype => "float" }, # Site latitude80 { name => "FPA.ELEVATION", type => "constant", flag => "-elevation", dtype => "float" }, # Site elevation81 { name => "FPA.M1X", type => "constant", flag => "-m1_x", dtype => "float" }, # M1X82 { name => "FPA.M1Y", type => "constant", flag => "-m1_y", dtype => "float" }, # M1Y83 { name => "FPA.M1Z", type => "constant", flag => "-m1_z", dtype => "float" }, # M1Z84 { name => "FPA.M1TIP", type => "constant", flag => "-m1_tip", dtype => "float" }, # M1TIP85 { name => "FPA.M1TILT", type => "constant", flag => "-m1_tilt", dtype => "float" }, # M1TILT86 { name => "FPA.M2X", type => "constant", flag => "-m2_x", dtype => "float" }, # M2X87 { name => "FPA.M2Y", type => "constant", flag => "-m2_y", dtype => "float" }, # M2Y88 { name => "FPA.M2Z", type => "constant", flag => "-m2_z", dtype => "float" }, # M2Z89 { name => "FPA.M2TIP", type => "constant", flag => "-m2_tip", dtype => "float" }, # M2TIP90 { name => "FPA.M2TILT", type => "constant", flag => "-m2_tilt", dtype => "float" }, # M2TILT91 { name => "FPA.ENV.TEMP", type => "constant", flag => "-env_temperature", dtype => "float" }, # external temp92 { name => "FPA.ENV.HUMID", type => "constant", flag => "-env_humidity", dtype => "float" }, # external humidity93 { name => "FPA.ENV.WIND", type => "constant", flag => "-env_wind_speed", dtype => "float" }, # external wind speed94 { name => "FPA.ENV.DIR", type => "constant", flag => "-env_wind_dir", dtype => "float" }, # external wind direction95 96 { name => "FPA.TELTEMP.M1", type => "constant", flag => "-teltemp_m1", dtype => "float" }, # Primary mirror temps (C)97 { name => "FPA.TELTEMP.M1CELL", type => "constant", flag => "-teltemp_m1cell", dtype => "float" }, # Primary mirror support temps (C)98 { name => "FPA.TELTEMP.M2", type => "constant", flag => "-teltemp_m2", dtype => "float" }, # Secondary mirror temps (C99 { name => "FPA.TELTEMP.SPIDER", type => "constant", flag => "-teltemp_spider", dtype => "float" }, # Spider temperatures (C)100 { name => "FPA.TELTEMP.TRUSS", type => "constant", flag => "-teltemp_truss", dtype => "float" }, # Mid truss temperatures (C101 { name => "FPA.TELTEMP.EXTRA", type => "constant", flag => "-teltemp_extra", dtype => "float" }, # Miscellaneous temperatures (C)102 103 { name => "FPA.PON.TIME", type => "constant", flag => "-pon_time", dtype => "float" }, # time since last power on104 { name => "CHIP.TEMP", type => "mean", flag => "-ccd_temp", dtype => "float" }, # CCD temperature105 { name => "CELL.EXPOSURE", type => "mean", flag => "-exp_time", dtype => "float" }, # Exposure time106 { name => "SAT_PIXEL_FRAC", type => "mean", flag => "-sat_pixel_frac", dtype => "float" }, # fraction of saturated pixels107 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg", dtype => "float" },108 { name => "ROBUST_MEDIAN", type => "stdev", flag => "-bg_mean_stdev", dtype => "float" },109 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev", dtype => "float" },110 ];111 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser112 113 58 # Look for programs we need 114 59 my $missing_tools; 115 my $regtool = can_run('regtool') 116 or (warn "Can't find regtool" and $missing_tools = 1); 117 my $ppStats = can_run('ppStats') 118 or (warn "Can't find ppStats" and $missing_tools = 1); 60 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1); 61 my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1); 62 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 119 63 120 64 if ($missing_tools) { … … 135 79 # Run ppStats on the input file 136 80 { 137 # extract the data from the image header; -level is used to get FILE.LEVEL and CLASS.ID 138 my $command = "$ppStats $uri -recipe PPSTATS $RECIPE -level"; # Command to run ppStats 81 my $command = "$ppStats $uri -recipe PPSTATS $RECIPE -level | $ppStatsFromMetadata - - REGISTER_IMFILE"; # Command to run ppStats and ppStatsFromMetadata 139 82 $command .= " -dbname $dbname" if defined $dbname; 140 83 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 144 87 &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $error_code); 145 88 } 146 147 # Parse the output 148 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 149 my $metadata = $mdcParser->parse(join "", @$stdout_buf); # XXX is this join necessary? 150 unless ($metadata) { 151 &my_die ("Unable to parse metadata config doc", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_PROG_ERROR); 152 } 153 154 # extract the stats from the metadata 155 unless ($stats->parse($metadata)) { 156 &my_die ("Unable to find all values", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); 157 } 89 foreach my $line (@$stdout_buf) { 90 $cmdflags .= " $line"; 91 } 92 chomp $cmdflags; 158 93 } 159 94 … … 162 97 163 98 # we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type 164 if (uc( $stats->value_for_flag ("-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }165 if (uc( $stats->value_for_flag ("-inst")) eq "NULL") { &my_die ("inst not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }166 if (uc( $stats->value_for_flag ("-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }167 if (uc( $stats->value_for_flag ("-class_id")) eq "NULL") { &my_die ("class_id not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }168 if (uc( $stats->value_for_flag ("-exp_type")) eq "NULL") { &my_die ("exp_type not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }99 if (uc(&value_for_flag ($cmdflags, "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); } 100 if (uc(&value_for_flag ($cmdflags, "-inst")) eq "NULL") { &my_die ("inst not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); } 101 if (uc(&value_for_flag ($cmdflags, "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); } 102 if (uc(&value_for_flag ($cmdflags, "-class_id")) eq "NULL") { &my_die ("class_id not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); } 103 if (uc(&value_for_flag ($cmdflags, "-exp_type")) eq "NULL") { &my_die ("exp_type not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); } 169 104 170 105 my $command = "$regtool -addprocessedimfile"; … … 175 110 $command .= " -hostname $host" if defined $host; 176 111 $command .= " -dbname $dbname" if defined $dbname; 177 $command .= $stats->cmdflags();112 $command .= " $cmdflags"; 178 113 179 114 # determine solar-system parameters 180 my $longitude = $stats->value_for_flag ("-longitude");181 my $latitude = $stats->value_for_flag ("-latitude");182 my $elevation = $stats->value_for_flag ("-elevation");183 my $ra = $stats->value_for_flag ("-ra");184 my $dec = $stats->value_for_flag ("-decl");185 my $dateobs = $stats->value_for_flag ("-dateobs");115 my $longitude = &value_for_flag ($cmdflags, "-longitude"); 116 my $latitude = &value_for_flag ($cmdflags, "-latitude"); 117 my $elevation = &value_for_flag ($cmdflags, "-elevation"); 118 my $ra = &value_for_flag ($cmdflags, "-ra"); 119 my $dec = &value_for_flag ($cmdflags, "-decl"); 120 my $dateobs = &value_for_flag ($cmdflags, "-dateobs"); 186 121 187 122 # if the needed data is available, pass it to sunmoon: … … 238 173 return @output; 239 174 } 175 } 176 177 sub value_for_flag 178 { 179 my $cmdflags = shift; 180 my $flag = shift; 181 182 my $value = 0.0; 183 if ($cmdflags =~ m|$flag|) { 184 ($value) = $cmdflags =~ m|$flag\s+(\S+)|; 185 } 186 $value; 240 187 } 241 188 -
trunk/ippScripts/scripts/stack_skycell.pl
r19938 r20101 19 19 use IPC::Cmd 0.36 qw( can_run run ); 20 20 use PS::IPP::Metadata::Config; 21 use PS::IPP::Metadata::Stats;22 21 use PS::IPP::Metadata::List qw( parse_md_list ); 23 22 use Data::Dumper; … … 67 66 $ipprc->redirect_output($logDest) if $redirect; 68 67 69 my $STATS =70 [71 # PPSTATS KEYWORD STATISTIC STACKTOOL FLAG72 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg", dtype => "float" },73 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev", dtype => "float" },74 { name => "TIME_STACK", type => "sum", flag => "-dtime_stack", dtype => "float" },75 { name => "TIME_MATCH", type => "mean", flag => "-dtime_match_mean", dtype => "float" },76 { name => "TIME_MATCH", type => "stdev", flag => "-dtime_match_stdev", dtype => "float" },77 { name => "TIME_INITIAL", type => "sum", flag => "-dtime_initial", dtype => "float" },78 { name => "TIME_REJECT", type => "sum", flag => "-dtime_reject", dtype => "float" },79 { name => "TIME_FINAL", type => "sum", flag => "-dtime_final", dtype => "float" },80 { name => "TIME_PHOT", type => "sum", flag => "-dtime_phot", dtype => "float" },81 { name => "STAMP.MEAN", type => "mean", flag => "-match_mean", dtype => "float" },82 { name => "STAMP.MEAN", type => "stdev", flag => "-match_stdev", dtype => "float" },83 { name => "STAMP.RMS", type => "rms", flag => "-match_rms", dtype => "float" },84 { name => "STAMP.NUM", type => "mean", flag => "-stamps_mean", dtype => "float" },85 { name => "STAMP.NUM", type => "stdev", flag => "-stamps_stdev", dtype => "float" },86 { name => "STAMP.NUM", type => "min", flag => "-stamps_min", dtype => "int" },87 { name => "TIME_PHOT", type => "sum", flag => "-dtime_phot", dtype => "float" },88 { name => "REJECT_IMAGES", type => "sum", flag => "-reject_images", dtype => "int" },89 { name => "REJECT_PIXELS", type => "mean", flag => "-reject_pix_mean", dtype => "float" },90 { name => "REJECT_PIXELS", type => "stdev", flag => "-reject_pix_stdev", dtype => "float" },91 { name => "NUM_SOURCES", type => "sum", flag => "-sources", dtype => "int" },92 { name => "GOOD_PIXEL_FRAC", type => "mean", flag => "-good_frac", dtype => "float" },93 ];94 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser95 96 68 # Look for programs we need 97 69 my $missing_tools; 98 70 my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1); 99 71 my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1); 72 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 100 73 if ($missing_tools) { 101 74 warn("Can't find required tools."); … … 208 181 # doesn't know how to resolve paths. (The information is stored in the configuration file) 209 182 $configuration = $ipprc->file_resolve($configuration) if ($run_state eq 'update'); 183 184 my $cmdflags; 210 185 211 186 # Perform stacking … … 244 219 245 220 if ($do_stats) { 246 &my_die("Couldn't find expected output file: $outputStats", $stack_id, $PS_EXIT_SYS_ERROR) 247 unless $ipprc->file_exists($outputStats); 248 # Get the statistics on the stacked image 249 my $statsFile; # File handle 250 open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $stack_id, $PS_EXIT_SYS_ERROR); 251 my @contents = <$statsFile>; # Contents of file 252 close $statsFile; 253 my $metadata = $mdcParser->parse(join "", @contents) or 254 &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR); 255 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $stack_id, $PS_EXIT_PROG_ERROR); 221 my $outputStatsReal = $ipprc->file_resolve($outputStats); 222 &my_die("Couldn't find expected output file: $outputStats", $stack_id, $PS_EXIT_SYS_ERROR) unless unless -f $outputStatsReal; 223 224 # measure chip stats 225 $command = "$ppStatsFromMetadata $outputStatsReal - STACK_SKYCELL"; 226 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 227 run(command => $command, verbose => $verbose); 228 unless ($success) { 229 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 230 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $stack_id, $error_code); 231 } 232 foreach my $line (@$stdout_buf) { 233 $cmdflags .= " $line"; 234 } 235 chomp $cmdflags; 256 236 } 257 237 } … … 272 252 } 273 253 $command .= " $mode -stack_id $stack_id"; 274 $command .= $stats->cmdflags()if $do_stats;254 $command .= " $cmdflags" if $do_stats; 275 255 $command .= " -dbname $dbname" if defined $dbname; 276 256 -
trunk/ippScripts/scripts/warp_skycell.pl
r19938 r20101 22 22 use Pod::Usage qw( pod2usage ); 23 23 use PS::IPP::Metadata::Config; 24 use PS::IPP::Metadata::Stats;25 24 use PS::IPP::Metadata::List qw( parse_md_list ); 26 25 use PS::IPP::Config 1.01 qw( :standard ); … … 63 62 $ipprc->redirect_output($logDest) if $redirect; 64 63 65 my $STATS =66 [67 # PPSTATS KEYWORD STATISTIC WARPTOOL FLAG68 { name => "ROBUST_MEDIAN", type => "mean", flag => "-bg", dtype => "float" },69 { name => "ROBUST_STDEV", type => "rms", flag => "-bg_stdev", dtype => "float" },70 { name => "DT_WARP", type => "sum", flag => "-dtime_warp", dtype => "float" },71 { name => "GOOD_PIXEL_FRAC", type => "mean", flag => "-good_frac", dtype => "float" },72 { name => "RANGE.XMIN", type => "mean", flag => "-xmin", dtype => "int" },73 { name => "RANGE.XMAX", type => "mean", flag => "-xmax", dtype => "int" },74 { name => "RANGE.YMIN", type => "mean", flag => "-ymin", dtype => "int" },75 { name => "RANGE.YMAX", type => "mean", flag => "-ymax", dtype => "int" },76 ];77 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser78 79 64 # Look for programs we need 80 65 my $missing_tools; … … 82 67 my $pswarp = can_run('pswarp') or (warn "Can't find pswarp" and $missing_tools = 1); 83 68 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 69 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 84 70 if ($missing_tools) { 85 71 warn("Can't find required tools."); … … 180 166 181 167 # Run pswarp 168 my $cmdflags; 182 169 my $accept = 1; # Accept the skycell? 183 170 my $do_stats; … … 216 203 if ($do_stats) { 217 204 # Check first for the stats file, and if the ACCEPT flag is set. 218 &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats); 219 # Get the statistics on the warped image 220 my $statsFile; # File handle 221 open $statsFile, $ipprc->file_resolve($outputStats) or die "Can't open statistics file $outputStats: $!\n"; 222 my @contents = <$statsFile>; # Contents of file 223 close $statsFile; 224 my $contents = join "", @contents; 225 226 my $metadata = $mdcParser->parse($contents) 227 or &my_die("Unable to parse metadata config", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR); 228 $accept = metadataLookupBool($metadata, "ACCEPT"); 229 230 # $accept is set above based on the fraction of lit pixels 231 # XXX for some files, there may not be enough stars to find a good psf. these should be dropped as well 205 my $outputStatsReal = $ipprc->file_resolve($outputStats); 206 &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal; 207 208 # measure chip stats 209 $command = "$ppStatsFromMetadata $outputStatsReal - WARP_SKYFILE"; 210 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 211 run(command => $command, verbose => $verbose); 212 unless ($success) { 213 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 214 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR); 215 } 216 foreach my $line (@$stdout_buf) { 217 $cmdflags .= " $line"; 218 } 219 chomp $cmdflags; 220 221 # the stats includes ACCEPT as a boolean: convert the T/F value to 0/1 222 my $acceptFlag = &value_for_flag ($cmdflags, "-accept"); 223 $accept = ($acceptFlag = "T") ? 1 : 0; 232 224 if ($accept && !$ipprc->file_exists($outputPSF)) { 233 225 $accept = 0; … … 235 227 236 228 if ($accept) { 237 $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);238 239 229 &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage); 240 230 &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 241 231 &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight); 242 232 &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 243 # &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);244 # &my_die("Couldn't find expected output file: $outputBin1", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);245 # &my_die("Couldn't find expected output file: $outputBin2", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);246 233 } 247 234 … … 256 243 $command .= " -uri $outputImage" if $accept; 257 244 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 258 $command .= $stats->cmdflags()if $accept;245 $command .= " $cmdflags" if $accept; 259 246 $command .= " -hostname $host" if defined $host; 260 247 $command .= " -dbname $dbname" if defined $dbname; … … 285 272 } 286 273 } 274 } 275 276 sub value_for_flag 277 { 278 my $cmdflags = shift; 279 my $flag = shift; 280 281 my $value = 0.0; 282 if ($cmdflags =~ m|$flag|) { 283 ($value) = $cmdflags =~ m|$flag\s+(\S+)|; 284 } 285 $value; 287 286 } 288 287
Note:
See TracChangeset
for help on using the changeset viewer.
