IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39000 for trunk/tools


Ignore:
Timestamp:
Oct 29, 2015, 11:00:35 AM (11 years ago)
Author:
bills
Message:

move list of P2 columns to the script
Add mode --check which uses mana to look for delta columns
with differences larger than 1e-9.
get stilts jar location from $ENV{JARFILE} if not defined use bill's

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/bills/adddeltacolumns

    r38860 r39000  
    11#!/usr/bin/env perl
    22
    3 # take a file that describes the conversion beteween ipp smf and cmf columns and psps column and create a
    4 # stilts filter command that will add a column to a table with the difference between the
    5 # Detection value and the expected value
     3# given a table file that contains rows from a P2 detections table (either from the
     4# results of a PSPS query # or ipp2psps P2 batch file)
     5# build a set of delta columns which give the difference between the p2 columns and
     6# the expected value.
     7# The list of columns and the formulas are given in this file by way of a perl here document.
     8# optionally check that the differences are small
    69
    710use strict;
    811use warnings;
    912
     13use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     14use Pod::Usage qw( pod2usage );
     15use File::Temp qw( tempdir  tempfile );
     16
     17
    1018my $verbose;
     19my $checkdeltas;
     20my $save_temps;
     21
     22GetOptions(
     23    "check"             =>  \$checkdeltas,
     24    "verbose|v"         =>  \$verbose,
     25    "save-temps"        =>  \$save_temps,
     26) or pod2usage( 2 );
     27
    1128
    1229my $in = shift;
    1330my $out = shift;
    14 die "usage $0 <input matched detections> <output>\n" unless $in and $out;
    15 my $confdir = '/home/panstarrs/bills/ipp/tools/bills';
    16 my $conversionFile = 'p2columns.txt';
    17 my $stiltsJar =  '/home/panstarrs/bills/jars/stilts.jar';
     31
     32die "usage $0 <input matched detections table> <output> [--check]\n" unless $in and $out;
     33
     34my $jardir = $ENV{JARDIR};
     35$jardir =  '/home/panstarrs/bills/jars' unless $jardir;
     36
     37my $stiltsJar =  "$jardir/stilts.jar";
    1838my $stilts = "java -jar $stiltsJar";
    1939
    20 open C, "<$confdir/p2columns.txt" or die "failed to open p2columns.txt\n";
     40my $p2columns = getp2columns();
     41
     42my @lines = split "\n", $p2columns;
    2143
    2244my $cmd="'addcol -after zp zpFactor 3630.78*pow(10,-0.4*zp);";
    2345
    24 foreach my $line (<C>) {
     46# foreach my $line (<C>) {
     47my @deltas;
     48foreach my $line (@lines) {
    2549    next if $line =~ '^#';
    2650    next if !$line;
     
    3458    my $equation = "$ipp$conversion";
    3559    $equation = "$p2-$equation";
    36     $cmd .=  "addcol -after $p2 d_$p2 $equation;";
     60    my $dcol = "d_$p2";
     61    $cmd .=  "addcol -after $p2 $dcol $equation;";
     62    push @deltas, $dcol;
    3763}
    3864$cmd .= "'";
     
    4268print "$command\n" if $verbose;
    4369
    44 system $command;
     70my $rc = system $command;
     71if ($rc) {
     72    exit $rc >> 8;
     73}
     74
     75if ($checkdeltas) {
     76    my ($manafile, $mananame) = tempfile( "/var/tmp/manacmds.XXXX", UNLINK => !$save_temps);
     77    print "$mananame\n" if $save_temps;
     78    print $manafile (<<HERE);
     79\$limit = 1e-9
     80output /dev/null
     81macro checkdelta
     82    \$col = \$1
     83    \$thislimit = \$limit
     84    \$length = \$col[]
     85    for i 0 10
     86        subset d = \$col where abs(\$col) > \$thislimit
     87        \$noutliers = d[]
     88        if (\$noutliers > 0)
     89            echo \$col has \$noutliers out of \$length with difference > \$thislimit
     90            \$thislimit = \$thislimit * 10
     91        else
     92            return
     93        end
     94    end
     95end
     96HERE
     97
     98    print $manafile "\nmacro dotests\n";
     99    foreach my $col (@deltas) {
     100        print $manafile "    checkdelta $col\n";
     101    }
     102    print $manafile "end\n";
     103
     104    print $manafile "datafile $out\n";
     105    print $manafile "read -fits Joined";
     106    foreach my $col (@deltas) {
     107        print $manafile " $col";
     108    }
     109    print $manafile "\n";
     110
     111
     112    print $manafile "output stdout\n";
     113    print $manafile "dotests\n";
     114    close $manafile;
     115
     116    system "echo input $mananame | mana";
     117}
     118exit 0;
     119
     120
     121sub getp2columns {
     122
     123my $list = <<END_OF_LIST;
     124# Note zpFactor = 3630.78*pow(10, -0.4*zp)
     125
     126objID
     127uniquePspsP2id
     128detectID
     129ippObjID
     130ippDetectID     IPP_IDET
     131filterID
     132surveyID
     133imageID
     134randomDetID
     135dvoRegionID
     136obsTime
     137xPos            X_PSF
     138yPos            Y_PSF
     139xPosErr         X_PSF_SIG
     140yPosErr         Y_PSF_SIG
     141pltScale        PLTSCALE
     142posAngle        POSANGLE
     143ra
     144dec
     145raErr           X_PSF_SIG               *abs(PLTSCALE)
     146decErr          Y_PSF_SIG               *abs(PLTSCALE)
     147extNSigma       EXT_NSIGMA
     148zp
     149telluricExt
     150expTime
     151airMass
     152psfFlux         PSF_INST_FLUX           *zpFactor/expTime
     153psfFluxErr      PSF_INST_FLUX_SIG       *zpFactor/expTime
     154psfMajorFWHM    PSF_FWHM_MAJ            *abs(PLTSCALE)
     155psfMinorFWHM    PSF_FWHM_MIN            *abs(PLTSCALE)
     156psfTheta        PSF_THETA
     157psfCore         PSF_CORE
     158psfQf           PSF_QF
     159psfQfPerfect    PSF_QF_PERFECT
     160psfChiSq        PSF_CHISQ
     161psfLikelihood                 # actually psfLikelihood(EXT_NSIGMA). We assume the formula is ok.
     162momentXX        MOMENTS_XX              *PLTSCALE*PLTSCALE
     163momentXY        MOMENTS_XY              *PLTSCALE*PLTSCALE
     164momentYY        MOMENTS_YY              *PLTSCALE*PLTSCALE
     165momentR1        MOMENTS_R1              *abs(PLTSCALE)
     166momentRH        MOMENTS_RH              *sqrt(abs(PLTSCALE))
     167momentM3C       MOMENTS_M3C             *PLTSCALE*PLTSCALE
     168momentM3S       MOMENTS_M3S             *PLTSCALE*PLTSCALE
     169momentM4C       MOMENTS_M4C             *PLTSCALE*PLTSCALE
     170momentM4S       MOMENTS_M4S             *PLTSCALE*PLTSCALE
     171apFlux          AP_FLUX                 *zpFactor/expTime
     172apFluxErr       AP_FLUX_SIG             *zpFactor/expTime
     173apFillF         AP_NPIX                 /(3.14159265359*pow(AP_MAG_RADIUS-0.5,2))
     174apRadius        AP_MAG_RADIUS           *abs(PLTSCALE)
     175kronFlux        KRON_FLUX               *zpFactor/expTime
     176kronFluxErr     KRON_FLUX_ERR           *zpFactor/expTime
     177kronRad         MOMENTS_R1              *2.5*abs(PLTSCALE)
     178sky             SKY                     /PLTSCALE/PLTSCALE*zpFactor/expTime
     179skyErr          SKY_SIGMA               /PLTSCALE/PLTSCALE*zpFactor/expTime
     180infoFlag        FLAGS
     181infoFlag2       FLAGS2
     182infoFlag3
     183processingVersion
     184END_OF_LIST
     185    return $list;
     186}
Note: See TracChangeset for help on using the changeset viewer.