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_imfile.pl

    r19733 r20101  
    2020use PS::IPP::Config 1.01 qw( :standard );
    2121use PS::IPP::Metadata::Config;
    22 use PS::IPP::Metadata::Stats;
    2322
    2423my $PI = 3.141592653589793238462643383279502;
     
    5756my $RECIPE = "REGISTER"; # Recipe to use for ppStats
    5857
    59 # values to extract from output metadata and the stats to calculate
    60 my $STATS =
    61    [
    62        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
    63        { name => "FILE.LEVEL",     type => "constant", flag => "-filelevel",       dtype => "string" }, # File level
    64        { name => "CLASS.ID",       type => "constant", flag => "-class_id",        dtype => "string" }, # Real Class ID
    65        { name => "FPA.OBJECT",     type => "constant", flag => "-object",          dtype => "string" }, # Object
    66        { name => "FPA.OBSTYPE",    type => "constant", flag => "-exp_type",        dtype => "string" }, # Exposure type
    67        { name => "FPA.FILTER",     type => "constant", flag => "-filter",          dtype => "string" }, # Filter used
    68        { name => "FPA.COMMENT",    type => "constant", flag => "-comment",         dtype => "string" }, # Obs Comment
    69        { name => "FPA.AIRMASS",    type => "constant", flag => "-airmass",         dtype => "float"  }, # Airmass
    70        { name => "FPA.RA",         type => "constant", flag => "-ra",              dtype => "float"  }, # Right ascension
    71        { name => "FPA.DEC",        type => "constant", flag => "-decl",            dtype => "float"  }, # Declination
    72        { name => "FPA.ALT",        type => "constant", flag => "-alt",             dtype => "float"  }, # Altitude
    73        { name => "FPA.AZ",         type => "constant", flag => "-az",              dtype => "float"  }, # Azimuth
    74        { name => "FPA.POSANGLE",   type => "constant", flag => "-posang",          dtype => "float"  }, # Position angle
    75        { name => "FPA.TIME",       type => "constant", flag => "-dateobs",         dtype => "string" }, # Date of observation (UTC)
    76        { name => "FPA.TELESCOPE",  type => "constant", flag => "-telescope",       dtype => "string" }, # Telescope
    77        { name => "FPA.CAMERA",     type => "constant", flag => "-inst",            dtype => "string" }, # Instrument
    78        { name => "FPA.LONGITUDE",  type => "constant", flag => "-longitude",       dtype => "float"  }, # Site longitude
    79        { name => "FPA.LATITUDE",   type => "constant", flag => "-latitude",        dtype => "float"  }, # Site latitude
    80        { name => "FPA.ELEVATION",  type => "constant", flag => "-elevation",       dtype => "float"  }, # Site elevation
    81        { name => "FPA.M1X",        type => "constant", flag => "-m1_x",            dtype => "float"  }, # M1X
    82        { name => "FPA.M1Y",        type => "constant", flag => "-m1_y",            dtype => "float"  }, # M1Y
    83        { name => "FPA.M1Z",        type => "constant", flag => "-m1_z",            dtype => "float"  }, # M1Z
    84        { name => "FPA.M1TIP",      type => "constant", flag => "-m1_tip",          dtype => "float"  }, # M1TIP
    85        { name => "FPA.M1TILT",     type => "constant", flag => "-m1_tilt",         dtype => "float"  }, # M1TILT
    86        { name => "FPA.M2X",        type => "constant", flag => "-m2_x",            dtype => "float"  }, # M2X
    87        { name => "FPA.M2Y",        type => "constant", flag => "-m2_y",            dtype => "float"  }, # M2Y
    88        { name => "FPA.M2Z",        type => "constant", flag => "-m2_z",            dtype => "float"  }, # M2Z
    89        { name => "FPA.M2TIP",      type => "constant", flag => "-m2_tip",          dtype => "float"  }, # M2TIP
    90        { name => "FPA.M2TILT",     type => "constant", flag => "-m2_tilt",         dtype => "float"  }, # M2TILT
    91        { name => "FPA.ENV.TEMP",   type => "constant", flag => "-env_temperature", dtype => "float"  }, # external temp
    92        { name => "FPA.ENV.HUMID",  type => "constant", flag => "-env_humidity",    dtype => "float"  }, # external humidity
    93        { name => "FPA.ENV.WIND",   type => "constant", flag => "-env_wind_speed",  dtype => "float"  }, # external wind speed
    94        { name => "FPA.ENV.DIR",    type => "constant", flag => "-env_wind_dir",    dtype => "float"  }, # external wind direction
    95 
    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 (C
    99        { 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 (C
    101        { 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 on
    104        { name => "CHIP.TEMP",      type => "mean",     flag => "-ccd_temp",        dtype => "float"  }, # CCD temperature
    105        { name => "CELL.EXPOSURE",  type => "mean",     flag => "-exp_time",        dtype => "float"  }, # Exposure time
    106        { name => "SAT_PIXEL_FRAC", type => "mean",     flag => "-sat_pixel_frac",  dtype => "float"  }, # fraction of saturated pixels
    107        { 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 parser
    112 
    11358# Look for programs we need
    11459my $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);
     60my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
     61my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
     62my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    11963
    12064if ($missing_tools) {
     
    13579# Run ppStats on the input file
    13680{
    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
    13982    $command .= " -dbname $dbname" if defined $dbname;
    14083    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    14487        &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $error_code);
    14588    }
    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;
    15893}
    15994
     
    16297
    16398# 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); }
     99if (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); }
     100if (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); }
     101if (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); }
     102if (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); }
     103if (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); }
    169104
    170105my $command = "$regtool -addprocessedimfile";
     
    175110$command .= " -hostname $host" if defined $host;
    176111$command .= " -dbname $dbname" if defined $dbname;
    177 $command .= $stats->cmdflags();
     112$command .= " $cmdflags";
    178113
    179114# 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");
     115my $longitude = &value_for_flag ($cmdflags, "-longitude");
     116my $latitude  = &value_for_flag ($cmdflags, "-latitude");
     117my $elevation = &value_for_flag ($cmdflags, "-elevation");
     118my $ra        = &value_for_flag ($cmdflags, "-ra");
     119my $dec       = &value_for_flag ($cmdflags, "-decl");
     120my $dateobs   = &value_for_flag ($cmdflags, "-dateobs");
    186121
    187122# if the needed data is available, pass it to sunmoon:
     
    238173        return @output;
    239174    }
     175}
     176
     177sub 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;
    240187}
    241188
Note: See TracChangeset for help on using the changeset viewer.