IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 13, 2008, 11:36:56 AM (18 years ago)
Author:
eugene
Message:

converting to ppStatsFromMetadata

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/register_exp.pl

    r19779 r20101  
    1919use IPC::Cmd 0.36 qw( can_run run );
    2020use PS::IPP::Metadata::Config;
    21 use PS::IPP::Metadata::Stats;
    2221use PS::IPP::Config 1.01 qw( :standard );
    2322
     
    5150my $DETREND_FLAG = "-end_stage reg"; # Flag to use to mark detrend exposure
    5251
    53 # values to extract from output metadata and the stats to calculate
    54 my $STATS =
    55    [   #          register imfile
    56        #          label             STATISTIC          CHIPTOOL FLAG
    57        { name => "exp_name",        type => "constant",   flag => "-exp_name",        dtype => "string" }, # File level
    58        { name => "telescope",       type => "constant",   flag => "-telescope",       dtype => "string" }, # File level
    59        { name => "camera",          type => "constant",   flag => "-inst",            dtype => "string" }, # File level
    60        { name => "filelevel",       type => "constant",   flag => "-filelevel",       dtype => "string" }, # File level
    61        { name => "object",          type => "constant",   flag => "-object",          dtype => "string" },
    62        { name => "exp_type",        type => "constant",   flag => "-exp_type",        dtype => "string" }, # File level
    63        { name => "filter",          type => "constant",   flag => "-filter",          dtype => "string" }, # File level
    64        { name => "comment",         type => "constant",   flag => "-comment",         dtype => "string" }, # ObsComment
    65        { name => "dateobs",         type => "constant",   flag => "-dateobs",         dtype => "string" }, # File level
    66        { name => "ccd_temp",        type => "mean",       flag => "-ccd_temp",        dtype => "float"  }, # CCD temperature
    67        { name => "exp_time",        type => "mean",       flag => "-exp_time",        dtype => "float"  }, # Exposure time
    68        { name => "sat_pixel_frac",  type => "mean",       flag => "-sat_pixel_frac",  dtype => "float"  }, # Fraction of saturated pixels
    69        { name => "airmass",         type => "mean",       flag => "-airmass",         dtype => "float"  }, # Airmass
    70        { name => "ra",              type => "mean",       flag => "-ra",              dtype => "float"  }, # Right ascension
    71        { name => "decl",            type => "mean",       flag => "-decl",            dtype => "float"  }, # Declination
    72        { name => "posang",          type => "mean",       flag => "-posang",          dtype => "float"  }, # Position angle
    73        { name => "alt",             type => "mean",       flag => "-alt",             dtype => "float"  }, # Altitude
    74        { name => "az",              type => "mean",       flag => "-az",              dtype => "float"  }, # Azimuth
    75        { name => "m1_x",            type => "constant",   flag => "-m1_x",            dtype => "float"  }, # M1X
    76        { name => "m1_y",            type => "constant",   flag => "-m1_y",            dtype => "float"  }, # M1Y
    77        { name => "m1_z",            type => "constant",   flag => "-m1_z",            dtype => "float"  }, # M1Z
    78        { name => "m1_tip",          type => "constant",   flag => "-m1_tip",          dtype => "float"  }, # M1TIP
    79        { name => "m1_tilt",         type => "constant",   flag => "-m1_tilt",         dtype => "float"  }, # M1TILT
    80        { name => "m2_x",            type => "constant",   flag => "-m2_x",            dtype => "float"  }, # M2X
    81        { name => "m2_y",            type => "constant",   flag => "-m2_y",            dtype => "float"  }, # M2Y
    82        { name => "m2_z",            type => "constant",   flag => "-m2_z",            dtype => "float"  }, # M2Z
    83        { name => "m2_tip",          type => "constant",   flag => "-m2_tip",          dtype => "float"  }, # M2TIP
    84        { name => "m2_tilt",         type => "constant",   flag => "-m2_tilt",         dtype => "float"  }, # M2TILT
    85        { name => "env_temperature", type => "constant",   flag => "-env_temperature", dtype => "float"  }, # external temp
    86        { name => "env_humidity",    type => "constant",   flag => "-env_humidity",    dtype => "float"  }, # external humidity
    87        { name => "env_wind_speed",  type => "constant",   flag => "-env_wind_speed",  dtype => "float"  }, # external wind speed
    88        { name => "env_wind_dir",    type => "constant",   flag => "-env_wind_dir",    dtype => "float"  }, # external wind direction
    89 
    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 (C
    93        { 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 (C
    95        { 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 sun
    98        { name => "sun_alt",         type => "constant",   flag => "-sun_alt",         dtype => "float"  }, # Altitude of sun
    99        { name => "moon_angle",      type => "constant",   flag => "-moon_angle",      dtype => "float"  }, # Angle to moon
    100        { name => "moon_alt",        type => "constant",   flag => "-moon_alt",        dtype => "float"  }, # Altitude of moon
    101        { name => "moon_phase",      type => "constant",   flag => "-moon_phase",      dtype => "float"  }, # Phase of moon
    102 
    103        { name => "pon_time",        type => "mean",       flag => "-pon_time",        dtype => "float"  }, # time since last power on
    104        { name => "bg",              type => "mean",       flag => "-bg",              dtype => "float"  }, # background
    105        { name => "bg",              type => "stdev",      flag => "-bg_mean_stdev",   dtype => "float"  }, # Azimuth
    106        { name => "bg_stdev",        type => "rms",        flag => "-bg_stdev",        dtype => "float"  }, # Azimuth
    107        ];
    108 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
    109 
    11052# Look for commands we need
    11153my $missing_tools;
     
    13678    }
    13779
    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);
    14396    }
    14497
    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";
    148100    }
    149101}
    150102
    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
     104if (uc(&value_for_flag ($cmdflags, "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     105if (uc(&value_for_flag ($cmdflags, "-inst"))      eq "NULL") { &my_die ("inst      not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     106if (uc(&value_for_flag ($cmdflags, "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     107if (uc(&value_for_flag ($cmdflags, "-exp_name"))  eq "NULL") { &my_die ("exp_name  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
     108
     109my $exp_type = &value_for_flag ("-exp_type");
     110if (uc($exp_type) eq "NULL") { &my_die ("exp_type  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
    157111
    158112my $command = "$regtool -addprocessedexp";
     
    161115$command .= " -hostname $host" if defined $host;
    162116$command .= " -dbname $dbname" if defined $dbname;
    163 $command .= $stats->cmdflags();
    164 
    165 my $exp_type = $stats->value_for_flag ("-exp_type");
     117$command .= " $cmdflags";
    166118
    167119# Add the detrend flag, if needed
     
    206158}
    207159
     160sub 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
    208172sub my_die
    209173{
Note: See TracChangeset for help on using the changeset viewer.