Changeset 20101 for trunk/ippScripts/scripts/register_imfile.pl
- Timestamp:
- Oct 13, 2008, 11:36:56 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/register_imfile.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
