IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20101


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

converting to ppStatsFromMetadata

Location:
trunk/ippScripts/scripts
Files:
5 edited

Legend:

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

    r20062 r20101  
    1818use IPC::Cmd 0.36 qw( can_run run );
    1919use PS::IPP::Metadata::Config;
    20 use PS::IPP::Metadata::Stats;
    2120use PS::IPP::Metadata::List qw( parse_md_list );
    2221use Data::Dumper;
     
    5352$ipprc->redirect_output($logDest) if $redirect;
    5453
    55 my $STATS =
    56    [
    57        #          PPSTATS KEYWORD         STATISTIC          DIFFTOOL FLAG
    58        { 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 parser
    77 
    7854# Look for programs we need
    7955my $missing_tools;
    8056my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
    8157my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" and $missing_tools = 1);
     58my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    8259if ($missing_tools) {
    8360    warn("Can't find required tools.");
     
    204181my $traceDest = $ipprc->filename("TRACE.EXP", $outroot);
    205182
     183my $cmdflags;
     184
    206185# Perform subtraction
    207186unless ($no_op) {
     
    233212#    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
    234213#    &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;
    245230}
    246231
     
    250235    {
    251236        my $command = "$difftool -adddiffskyfile -diff_id $diff_id -uri $outputName -path_base $outroot";
    252         $command .= $stats->cmdflags();
     237        $command .= " $cmdflags";
    253238        $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    254239        $command .= " -hostname $host" if defined $host;
  • 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{
  • 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
  • trunk/ippScripts/scripts/stack_skycell.pl

    r19938 r20101  
    1919use IPC::Cmd 0.36 qw( can_run run );
    2020use PS::IPP::Metadata::Config;
    21 use PS::IPP::Metadata::Stats;
    2221use PS::IPP::Metadata::List qw( parse_md_list );
    2322use Data::Dumper;
     
    6766$ipprc->redirect_output($logDest) if $redirect;
    6867
    69 my $STATS =
    70    [
    71        #          PPSTATS KEYWORD         STATISTIC          STACKTOOL FLAG
    72        { 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 parser
    95 
    9668# Look for programs we need
    9769my $missing_tools;
    9870my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
    9971my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
     72my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    10073if ($missing_tools) {
    10174    warn("Can't find required tools.");
     
    208181# doesn't know how to resolve paths. (The information is stored in the configuration file)
    209182$configuration = $ipprc->file_resolve($configuration) if ($run_state eq 'update');
     183
     184my $cmdflags;
    210185
    211186# Perform stacking
     
    244219
    245220    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;
    256236    }
    257237}
     
    272252        }
    273253        $command .= " $mode -stack_id $stack_id";
    274         $command .= $stats->cmdflags() if $do_stats;
     254        $command .= " $cmdflags" if $do_stats;
    275255        $command .= " -dbname $dbname" if defined $dbname;
    276256
  • trunk/ippScripts/scripts/warp_skycell.pl

    r19938 r20101  
    2222use Pod::Usage qw( pod2usage );
    2323use PS::IPP::Metadata::Config;
    24 use PS::IPP::Metadata::Stats;
    2524use PS::IPP::Metadata::List qw( parse_md_list );
    2625use PS::IPP::Config 1.01 qw( :standard );
     
    6362$ipprc->redirect_output($logDest) if $redirect;
    6463
    65 my $STATS =
    66    [
    67        #          PPSTATS KEYWORD         STATISTIC          WARPTOOL FLAG
    68        { 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 parser
    78 
    7964# Look for programs we need
    8065my $missing_tools;
     
    8267my $pswarp = can_run('pswarp') or (warn "Can't find pswarp" and $missing_tools = 1);
    8368my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     69my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    8470if ($missing_tools) {
    8571    warn("Can't find required tools.");
     
    180166
    181167# Run pswarp
     168my $cmdflags;
    182169my $accept = 1;                 # Accept the skycell?
    183170my $do_stats;
     
    216203    if ($do_stats) {
    217204        # 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;
    232224        if ($accept && !$ipprc->file_exists($outputPSF)) {
    233225            $accept = 0;
     
    235227
    236228        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 
    239229            &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
    240230            &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
    241231            &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
    242232            &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);
    246233        }
    247234
     
    256243            $command .= " -uri $outputImage" if $accept;
    257244            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    258             $command .= $stats->cmdflags()  if $accept;
     245            $command .= " $cmdflags" if $accept;
    259246            $command .= " -hostname $host"   if defined $host;
    260247            $command .= " -dbname $dbname"   if defined $dbname;
     
    285272        }
    286273    }
     274}
     275
     276sub 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;
    287286}
    288287
Note: See TracChangeset for help on using the changeset viewer.