IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 10, 2007, 3:18:44 PM (19 years ago)
Author:
eugene
Message:

applying the update to Stats.pm using dtype and new methods

File:
1 edited

Legend:

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

    r13824 r14115  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use PS::IPP::Metadata::Config;
     18use PS::IPP::Metadata::Stats;
    1819use PS::IPP::Metadata::List qw( parse_md_list );
    19 use Statistics::Descriptive;
     20
    2021use File::Temp qw( tempfile );
    2122
     
    3435use Pod::Usage qw( pod2usage );
    3536
    36 my ($exp_id, $cam_id, $recipe, $camera, $dbname, $workdir, $dvodb, $no_update, $no_op);
     37my ($exp_tag, $cam_id, $recipe, $camera, $dbname, $workdir, $reduction, $dvodb, $no_update, $no_op);
    3738GetOptions(
    38            'exp_id=s'          => \$exp_id, # Exposure identifier
     39           'exp_tag=s'          => \$exp_tag, # Exposure identifier
    3940           'cam_id=s'          => \$cam_id, # Camtool identifier
    4041           'recipe=s'          => \$recipe, # Recipe to use
     
    4243           'dbname|d=s'        => \$dbname, # Database name
    4344           'workdir|w=s'       => \$workdir, # Working directory
     45           'reduction=s'       => \$reduction, # Reduction class                       
    4446           'dvodb|w=s'         => \$dvodb,  # output DVO database
    4547           'no-update'         => \$no_update, # Update the database?
     
    4951pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5052pod2usage(
    51     -msg => "Required options: --exp_id --cam_id --camera",
     53    -msg => "Required options: --exp_tag --cam_id --camera",
    5254    -exitval => 3,
    53 ) unless defined $exp_id
     55) unless defined $exp_tag
    5456    and defined $cam_id
    5557    and defined $camera;
     
    5759$ipprc->define_camera($camera);
    5860
    59 use constant RECIPE1 => 'PPIMAGE_J1'; # Recipe to use for ppImage to make JPEGs
    60 use constant RECIPE2 => 'PPIMAGE_J2'; # Recipe to use for ppImage to make JPEGs
    61 
     61# Recipes to use based on reduction class
     62$reduction = 'DEFAULT' unless defined $reduction;
     63
     64my $recipe1 = $ipprc->reduction($reduction, 'JPEG_BIN1'); # Recipe to use
     65&my_die("Unrecognised JPEG recipe", $cam_id, $PS_EXIT_PROG_ERROR) unless defined $recipe1;
     66
     67my $recipe2 = $ipprc->reduction($reduction, 'JPEG_BIN2'); # Recipe to use
     68&my_die("Unrecognised JPEG recipe", $cam_id, $PS_EXIT_PROG_ERROR) unless defined $recipe2;
     69
     70# values to extract from output metadata and the stats to calculate
     71my $CHIPSTATS =
     72   [   
     73       #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
     74        { name => "bg",             type => "mean",  flag => "-bg",             dtype => "float" },
     75        { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
     76        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",       dtype => "float" }, 
     77
     78# these should be coming from the psastro results for Nimfile > 1,
     79        { name => "sigma_ra",       type => "rms",   flag => "-sigma_ra",       dtype => "float" }, 
     80        { name => "sigma_dec",      type => "rms",   flag => "-sigma_dec",      dtype => "float" }, 
     81        { name => "n_stars",        type => "sum",   flag => "-n_stars",        dtype => "int"   }, 
     82        { name => "n_astrom",       type => "sum",   flag => "-n_astrom",       dtype => "int"   }, 
     83
     84        { name => "fwhm",           type => "mean",  flag => "-fwhm",           dtype => "float" }, 
     85
     86# these are not defined for the database table camProcessedExp
     87#       { name => "ap_resid",       type => "mean",  flag => "-ap_resid",       dtype => "float" }, 
     88#       { name => "ap_resid_stdev", type => "rms",   flag => "-ap_resid_stdev", dtype => "float" }, 
     89#       { name => "fringe_0",       type => "mean",  flag => "-fringe_0",       dtype => "float" }, 
     90#       { name => "fringe_1",       type => "rms",   flag => "-fringe_1",       dtype => "float" }, 
     91#       { name => "fringe_0",       type => "stdev", flag => "-fringe_2",       dtype => "float" }, 
     92   ];
     93my $chipStats = PS::IPP::Metadata::Stats->new($CHIPSTATS); # Stats parser
    6294
    6395# Look for programs we need
     
    90122    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    91123        &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
     124
     125    # extract the metadata for the files into a hash list
    92126    $files = parse_md_list($metadata) or
    93127        &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR);
    94 }
    95 
    96 # Gather the statistics
    97 my ($bg, $bg_stdev, $bg_mean_stdev); # The statistics triplet
    98 {
    99     my @backgrounds;            # Array of backgrounds in each component
    100     my @variances;              # Array of variances for each component
    101 #    my @ra;                    # Array of ra errors
    102 #    my @dec;                   # Array of dec errors
    103 #    my @zp;                    # Array of photometric zero points
    104     foreach my $file (@$files) {
    105         &my_die("Unable to find class id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id};
    106         my $class_id = $file->{class_id};
    107         &my_die("Unable to find bg for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{bg};
    108         &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev};
    109 #       &my_die("Unable to find sigma_ra for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_ra};
    110 #       &my_die("Unable to find sigma_dec for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_dec};
    111 #       &my_die("Unable to find zp for class_id=$class_id", $cam_id, $PS_EXIT_SYS_ERROR) unless defined $file->{zp};
    112         push @backgrounds, $file->{bg};
    113         push @variances, $file->{bg_stdev}**2;
    114     }
    115 
    116     {
    117         my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
    118         $stats->add_data(@backgrounds);
    119         $bg = ($stats->mean() or 'NAN');
    120         $bg_mean_stdev = ($stats->standard_deviation() or 'NAN');
    121     }
    122     {
    123         my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
    124         $stats->add_data(@variances);
    125         $bg_stdev = (sqrt( $stats->mean() ) or 'NAN');
    126     }
    127 }
    128 
    129 my ($list1File, $list1Name) = tempfile( "$exp_id.cam$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1
    130 my ($list2File, $list2Name) = tempfile( "$exp_id.cam$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2
    131 my ($list3File, $list3Name) = tempfile( "$exp_id.cam$cam_id.b3.list.XXXX", UNLINK => 1 ); # For astrometry
    132 
    133 my @means;                      # Array of means
    134 my @stdevs;                     # Array of stdevs
     128
     129    # extract the stats from the metadata
     130    unless ($chipStats->parse($metadata)) {
     131        &my_die("Unable to find all values in statistics output.\n", $cam_id, $PS_EXIT_PROG_ERROR);
     132    }
     133}
     134
     135my ($list1File, $list1Name) = tempfile( "$exp_tag.cm.$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1
     136my ($list2File, $list2Name) = tempfile( "$exp_tag.cm.$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2
     137my ($list3File, $list3Name) = tempfile( "$exp_tag.cm.$cam_id.b3.list.XXXX", UNLINK => 1 ); # For astrometry
     138
    135139my $chipObjects;
    136140foreach my $file (@$files) {
     
    143147    print $list2File ($ipprc->filename("PPIMAGE.BIN2", $file->{path_base}, $class_id) . "\n");
    144148    print $list3File ($chipObjects . "\n");
    145     push @means, $file->{bg};
    146     push @stdevs, $file->{bg_stdev};
    147149}
    148150close $list1File;
     
    151153
    152154# Output products
    153 $workdir = caturi( $workdir, $exp_id ) if defined $workdir;
    154 my $outputRoot = $ipprc->file_prepare( "$exp_id.cam$cam_id", $workdir, ${$files}[0]->{path_base} );
    155 my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
    156 my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
     155$workdir = caturi( $workdir, $exp_tag ) if defined $workdir;
     156my $outputRoot = $ipprc->file_prepare( "$exp_tag.cm.$cam_id", $workdir, ${$files}[0]->{path_base} );
     157
     158my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
     159my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
    157160my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT.MEF", $outputRoot); # MEF psastro output
    158161
     
    167170    # run psastro +mosastro on the set of chips
    168171    # XXX note that this is wrong if imfiles are cells
     172    # XXX add a ppStats call which will collect the astrometry stats
    169173    if (scalar @$files > 1) {
    170174        my $command = "$psastro -list $list3Name $outputRoot +mosastro -chipastro " .
     
    202206    # Make the jpeg for binning 1
    203207    {
    204         my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE " . RECIPE1; # Command to run
     208        my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
    205209        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    206210            run(command => $command, verbose => 1);
     
    214218    # Make the jpeg for binning 2
    215219    {
    216         my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE " . RECIPE2; # Command to run
     220        my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
    217221        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    218222            run(command => $command, verbose => 1);
     
    224228    }
    225229}
     230
     231my $fpaCommand = "$camtool -addprocessedexp";
     232$fpaCommand .= " -cam_id $cam_id";
     233$fpaCommand .= " -uri UNKNOWN";
     234$fpaCommand .= " -path_base $outputRoot";
     235$fpaCommand .= " -dbname $dbname" if defined $dbname;
     236$fpaCommand .= $chipStats->cmdflags();
    226237
    227238# Add the result into the database
    228239unless ($no_update) {
    229 
    230     my $command = "$camtool -addprocessedexp";
    231     $command .= " -cam_id $cam_id -uri UNKNOWN -path_base $outputRoot";
    232     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
    233     $command .= " -sigma_ra 0.0 -sigma_dec 0.0";
    234     $command .= " -zp_mean 0.0 -zp_stdev 0.0";
    235     $command .= " -fwhm 0.0 -fwhm_range 0.0";
    236     $command .= " -n_stars 0 -n_extended 0 -n_cr 0 -n_astrom 0";
    237     $command .= " -dbname $dbname" if defined $dbname;
    238 
    239240    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    240         run(command => $command, verbose => 1);
     241        run(command => $fpaCommand, verbose => 1);
    241242    unless ($success) {
    242243        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     
    244245        exit($error_code);
    245246    }
     247} else {
     248    print "skipping command: $fpaCommand\n";
    246249}
    247250
Note: See TracChangeset for help on using the changeset viewer.