Changeset 39000
- Timestamp:
- Oct 29, 2015, 11:00:35 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/tools/bills/adddeltacolumns (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/bills/adddeltacolumns
r38860 r39000 1 1 #!/usr/bin/env perl 2 2 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 6 9 7 10 use strict; 8 11 use warnings; 9 12 13 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 14 use Pod::Usage qw( pod2usage ); 15 use File::Temp qw( tempdir tempfile ); 16 17 10 18 my $verbose; 19 my $checkdeltas; 20 my $save_temps; 21 22 GetOptions( 23 "check" => \$checkdeltas, 24 "verbose|v" => \$verbose, 25 "save-temps" => \$save_temps, 26 ) or pod2usage( 2 ); 27 11 28 12 29 my $in = shift; 13 30 my $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 32 die "usage $0 <input matched detections table> <output> [--check]\n" unless $in and $out; 33 34 my $jardir = $ENV{JARDIR}; 35 $jardir = '/home/panstarrs/bills/jars' unless $jardir; 36 37 my $stiltsJar = "$jardir/stilts.jar"; 18 38 my $stilts = "java -jar $stiltsJar"; 19 39 20 open C, "<$confdir/p2columns.txt" or die "failed to open p2columns.txt\n"; 40 my $p2columns = getp2columns(); 41 42 my @lines = split "\n", $p2columns; 21 43 22 44 my $cmd="'addcol -after zp zpFactor 3630.78*pow(10,-0.4*zp);"; 23 45 24 foreach my $line (<C>) { 46 # foreach my $line (<C>) { 47 my @deltas; 48 foreach my $line (@lines) { 25 49 next if $line =~ '^#'; 26 50 next if !$line; … … 34 58 my $equation = "$ipp$conversion"; 35 59 $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; 37 63 } 38 64 $cmd .= "'"; … … 42 68 print "$command\n" if $verbose; 43 69 44 system $command; 70 my $rc = system $command; 71 if ($rc) { 72 exit $rc >> 8; 73 } 74 75 if ($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 80 output /dev/null 81 macro 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 95 end 96 HERE 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 } 118 exit 0; 119 120 121 sub getp2columns { 122 123 my $list = <<END_OF_LIST; 124 # Note zpFactor = 3630.78*pow(10, -0.4*zp) 125 126 objID 127 uniquePspsP2id 128 detectID 129 ippObjID 130 ippDetectID IPP_IDET 131 filterID 132 surveyID 133 imageID 134 randomDetID 135 dvoRegionID 136 obsTime 137 xPos X_PSF 138 yPos Y_PSF 139 xPosErr X_PSF_SIG 140 yPosErr Y_PSF_SIG 141 pltScale PLTSCALE 142 posAngle POSANGLE 143 ra 144 dec 145 raErr X_PSF_SIG *abs(PLTSCALE) 146 decErr Y_PSF_SIG *abs(PLTSCALE) 147 extNSigma EXT_NSIGMA 148 zp 149 telluricExt 150 expTime 151 airMass 152 psfFlux PSF_INST_FLUX *zpFactor/expTime 153 psfFluxErr PSF_INST_FLUX_SIG *zpFactor/expTime 154 psfMajorFWHM PSF_FWHM_MAJ *abs(PLTSCALE) 155 psfMinorFWHM PSF_FWHM_MIN *abs(PLTSCALE) 156 psfTheta PSF_THETA 157 psfCore PSF_CORE 158 psfQf PSF_QF 159 psfQfPerfect PSF_QF_PERFECT 160 psfChiSq PSF_CHISQ 161 psfLikelihood # actually psfLikelihood(EXT_NSIGMA). We assume the formula is ok. 162 momentXX MOMENTS_XX *PLTSCALE*PLTSCALE 163 momentXY MOMENTS_XY *PLTSCALE*PLTSCALE 164 momentYY MOMENTS_YY *PLTSCALE*PLTSCALE 165 momentR1 MOMENTS_R1 *abs(PLTSCALE) 166 momentRH MOMENTS_RH *sqrt(abs(PLTSCALE)) 167 momentM3C MOMENTS_M3C *PLTSCALE*PLTSCALE 168 momentM3S MOMENTS_M3S *PLTSCALE*PLTSCALE 169 momentM4C MOMENTS_M4C *PLTSCALE*PLTSCALE 170 momentM4S MOMENTS_M4S *PLTSCALE*PLTSCALE 171 apFlux AP_FLUX *zpFactor/expTime 172 apFluxErr AP_FLUX_SIG *zpFactor/expTime 173 apFillF AP_NPIX /(3.14159265359*pow(AP_MAG_RADIUS-0.5,2)) 174 apRadius AP_MAG_RADIUS *abs(PLTSCALE) 175 kronFlux KRON_FLUX *zpFactor/expTime 176 kronFluxErr KRON_FLUX_ERR *zpFactor/expTime 177 kronRad MOMENTS_R1 *2.5*abs(PLTSCALE) 178 sky SKY /PLTSCALE/PLTSCALE*zpFactor/expTime 179 skyErr SKY_SIGMA /PLTSCALE/PLTSCALE*zpFactor/expTime 180 infoFlag FLAGS 181 infoFlag2 FLAGS2 182 infoFlag3 183 processingVersion 184 END_OF_LIST 185 return $list; 186 }
Note:
See TracChangeset
for help on using the changeset viewer.
