Index: /branches/eam_branches/ipp-20121219/ippScripts/scripts/nightly_science.pl
===================================================================
--- /branches/eam_branches/ipp-20121219/ippScripts/scripts/nightly_science.pl	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippScripts/scripts/nightly_science.pl	(revision 34902)
@@ -1025,5 +1025,5 @@
 		}
 		foreach my $skycell (sort (keys (%skycells))) {
-		    $skycell_select .= " -skycell $skycell ";
+		    $skycell_select .= " -select_skycell_id $skycell ";
 		}
 		$cmd .= " -select_label $science_config{$target}{ADDITIONAL_STACK_LABEL} $skycell_select ";
Index: /branches/eam_branches/ipp-20121219/ippTasks/nightly_science.pro
===================================================================
--- /branches/eam_branches/ipp-20121219/ippTasks/nightly_science.pro	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippTasks/nightly_science.pro	(revision 34902)
@@ -370,5 +370,5 @@
   periods         -poll $LOADPOLL
   periods         -exec $LOADEXEC
-  periods         -timeout 120
+  periods         -timeout 480
   npending        1
 
Index: /branches/eam_branches/ipp-20121219/ippToPsps/config/IN/tables.vot
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/config/IN/tables.vot	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/config/IN/tables.vot	(revision 34902)
@@ -161,24 +161,4 @@
           <TR><TD>3</TD><TD>PS_MODEL_EXP</TD><TD>Exponential Fit</TD></TR>
           <TR><TD>4</TD><TD>PS_MODEL_SERSIC</TD><TD>Sersic Fit</TD></TR>
-        </TABLEDATA>
-      </DATA>
-    </TABLE>
-    <TABLE name="PhotozRecipe">
-      <DESCRIPTION>VOTable description of PSPS table PhotozRecipe</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="recipeID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>recipe index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="description" arraysize="100" datatype="char">
-        <DESCRIPTION>string describing the recipe</DESCRIPTION>
-      </FIELD>
-      <DATA>
-        <TABLEDATA>
-          <TR><TD>0</TD><TD>Spectroscopic Redshift</TD></TR>
-          <TR><TD>1</TD><TD>Le Phere photoz software</TD></TR>
-          <TR><TD>2</TD><TD>HyperZ photoz software</TD></TR>
-          <TR><TD>3</TD><TD>ANNz photoz software</TD></TR>
-          <TR><TD>4</TD><TD>EAZY software</TD></TR>
-          <TR><TD>5</TD><TD>Support vector machine (SVM) software</TD></TR>
         </TABLEDATA>
       </DATA>
@@ -102112,4 +102092,84 @@
       </DATA>
     </TABLE>
+    <TABLE name="StackDetectionFlags">
+      <DESCRIPTION>VOTable description of PSPS table DetectionFlags</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="name" arraysize="100" datatype="char">
+        <DESCRIPTION>Name of flag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="value" arraysize="1" datatype="long">
+        <DESCRIPTION>Flag value</DESCRIPTION>
+      </FIELD>
+      <FIELD name="description" arraysize="100" datatype="char">
+        <DESCRIPTION>Description of the flag</DESCRIPTION>
+      </FIELD>
+        <DATA>
+        <TABLEDATA>
+          <TR><TD>DEFAULT</TD><TD>0</TD><TD>Initial value: resets all bits</TD></TR>
+          <TR><TD>PSFMODEL</TD><TD>1</TD><TD>Source fitted with a psf model (linear or non-linear)</TD></TR>
+          <TR><TD>EXTMODEL</TD><TD>2</TD><TD>Source fitted with an extended-source model</TD></TR>
+	  <TR><TD>FITTED</TD><TD>4</TD><TD>Source fitted with non-linear model (PSF or EXT; good or bad)</TD></TR>
+	  <TR><TD>FAIL</TD><TD>8</TD><TD>Fit (non-linear) failed (non-converge, off-edge, run to zero)</TD></TR>
+	  <TR><TD>POOR</TD><TD>16</TD><TD>Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)</TD></TR>
+	  <TR><TD>PAIR</TD><TD>32</TD><TD>Source fitted with a double psf</TD></TR>
+	  <TR><TD>PSFSTAR</TD><TD>64</TD><TD>Source used to define PSF model</TD></TR>
+	  <TR><TD>SATSTAR</TD><TD>128</TD><TD>Source model peak is above saturation</TD></TR>
+	  <TR><TD>BLEND</TD><TD>256</TD><TD>Source is a blend with other sources</TD></TR>
+	  <TR><TD>EXTERNAL</TD><TD>512</TD><TD>Source based on supplied input position</TD></TR>
+	  <TR><TD>BADPSF</TD><TD>1024</TD><TD>Failed to get good estimate of object's PSF</TD></TR>
+	  <TR><TD>DEFECT</TD><TD>2048</TD><TD>Source is thought to be a defect</TD></TR>
+	  <TR><TD>SATURATED</TD><TD>4096</TD><TD>Source is thought to be saturated pixels (bleed trail)</TD></TR>
+	  <TR><TD>CR_LIMIT</TD><TD>8192</TD><TD>Source has crNsigma above limit</TD></TR>
+	  <TR><TD>EXT_LIMIT</TD><TD>16384</TD><TD>Source has extNsigma above limit</TD></TR>
+	  <TR><TD>MOMENTS_FAILURE</TD><TD>32768</TD><TD>could not measure the moments</TD></TR>
+	  <TR><TD>SKY_FAILURE</TD><TD>65536</TD><TD>could not measure the local sky</TD></TR>
+	  <TR><TD>SKYVAR_FAILURE</TD><TD>131072</TD><TD>could not measure the local sky variance</TD></TR>
+	  <TR><TD>BELOW_MOMENTS_SN</TD><TD>262144</TD><TD>moments not measured due to low S/N</TD></TR>
+	  <TR><TD>BIG_RADIUS</TD><TD>1048576</TD><TD>poor moments for small radius, try large radius</TD></TR>
+	  <TR><TD>AP_MAGS</TD><TD>2097152</TD><TD>source has an aperture magnitude</TD></TR>
+	  <TR><TD>BLEND_FIT</TD><TD>4194304</TD><TD>source was fitted as a blend</TD></TR>
+	  <TR><TD>EXTENDED_FIT</TD><TD>8388608</TD><TD>full extended fit was used</TD></TR>
+	  <TR><TD>EXTENDED_STATS</TD><TD>16777216</TD><TD>extended aperture stats calculated</TD></TR>
+	  <TR><TD>LINEAR_FIT</TD><TD>33554432</TD><TD>source fitted with the linear fit</TD></TR>
+	  <TR><TD>NONLINEAR_FIT</TD><TD>67108864</TD><TD>source fitted with the non-linear fit</TD></TR>
+	  <TR><TD>RADIAL_FLUX</TD><TD>134217728</TD><TD>radial flux measurements calculated</TD></TR>
+	  <TR><TD>SIZE_SKIPPED</TD><TD>268435456</TD><TD>size could not be determined</TD></TR>
+	  <TR><TD>ON_SPIKE</TD><TD>536870912</TD><TD>peak lands on diffraction spike</TD></TR>
+	  <TR><TD>ON_GHOST</TD><TD>1073741824</TD><TD>peak lands on ghost or glint</TD></TR>
+	  <TR><TD>OFF_CHIP</TD><TD>2147483648</TD><TD>peak lands off edge of chip</TD></TR>
+	  <TR><TD>DIFF_WITH_SINGLE</TD><TD>4294967296</TD><TD>diff source matched to a single positive detection</TD></TR>
+	  <TR><TD>DIFF_WITH_DOUBLE</TD><TD>8589934592</TD><TD>diff source matched to positive detections in both images</TD></TR>
+	  <TR><TD>MATCHED</TD><TD>17179869184</TD><TD>diff source matched to positive detections in both images</TD></TR>
+	  <TR><TD>ON_SPIKE</TD><TD>34359738368</TD><TD>>25% of (PSF-weighted) pixels land on diffraction spike</TD></TR>
+	  <TR><TD>ON_STARCORE</TD><TD>68719476736</TD><TD>>25% of (PSF-weighted) pixels land on starcore</TD></TR>
+	  <TR><TD>ON_BURNTOOL</TD><TD>137438953472</TD><TD>>25% of (PSF-weighted) pixels land on burntool</TD></TR>
+	  <TR><TD>ON_CONVPOOR</TD><TD>274877906944</TD><TD>>25% of (PSF-weighted) pixels land on convpoor</TD></TR>
+	  <TR><TD>PASS1_SRC</TD><TD>549755813888</TD><TD>source detected in first pass analysis</TD></TR>
+	  <TR><TD>HAS_BRIGHTER_NEIGHBOR</TD><TD>1099511627776</TD><TD>peak is not the brightest in its footprint</TD></TR>
+	  <TR><TD>BRIGHT_NEIGHBOR_1</TD><TD>2199023255552</TD><TD>flux_n / (r^2 flux_p) >1</TD></TR>
+	  <TR><TD>BRIGHT_NEIGHBOR_10</TD><TD>4398046511104</TD><TD>flux_n / (r^2 flux_p) >10</TD></TR>
+	  <TR><TD>DIFF_SELF_MATCH</TD><TD>8796093022208</TD><TD>positive detection match is probably this source</TD></TR>
+	  <TR><TD>SATSTAR_PROFILE</TD><TD>17592186044416</TD><TD>saturated source is modeled with a radial profile</TD></TR>
+	  <TR><TD>NOCAL</TD><TD>35184372088832</TD><TD>detection ignored for this analysis (photcode, time range) -- internal only</TD></TR>
+	  <TR><TD>POOR_PHOTOM</TD><TD>70368744177664</TD><TD>detection is photometry outlier</TD></TR>                              
+	  <TR><TD>SKIP_PHOTOM</TD><TD>140737488355328</TD><TD>detection was ignored for photometry measurement</TD></TR>                      
+	  <TR><TD>AREA</TD><TD>281474976710656</TD><TD>detection near image edge</TD></TR>                      
+	  <TR><TD>POOR_ASTROM</TD><TD>562949953421312</TD><TD>detection is astrometry outlier</TD></TR>                                  
+	  <TR><TD>SKIP_ASTROM</TD><TD>1125899906842624</TD><TD>detection was ignored for astrometry measurement</TD></TR>                          
+	  <TR><TD>USED_OBJ</TD><TD>2251799813685248</TD><TD>detection was used during update objects</TD></TR>
+	  <TR><TD>USED_CHIP</TD><TD>4503599627370496</TD><TD>detection was used during update chips (XXX this probably does not make it into the db)</TD></TR>
+	  <TR><TD>BLEND_MEAS</TD><TD>9007199254740992</TD><TD>detection is within radius of multiple objects</TD></TR>
+	  <TR><TD>BLEND_OBJ</TD><TD>18014398509481984</TD><TD>multiple detections within radius of object</TD></TR>
+	  <TR><TD>UNDEF_3</TD><TD>36028797018963968</TD><TD>unused</TD></TR>
+	  <TR><TD>UNDEF_4</TD><TD>72057594037927936</TD><TD>unused</TD></TR>
+	  <TR><TD>BLEND_MEAS_X</TD><TD>144115188075855872</TD><TD>detection is within radius of multiple objects across catalogs</TD></TR>               
+	  <TR><TD>ARTIFACT</TD><TD>288230376151711744</TD><TD>detection is thought to be non-astronomical</TD></TR>        
+	  <TR><TD>UNDEF_5</TD><TD>576460752303423488</TD><TD>unused</TD></TR>
+	  <TR><TD>PHOTOM_UBERCAL</TD><TD>1152921504606846976</TD><TD>externally-supplied zero point from ubercal analysis</TD></TR>
+	  <TR><TD>STACK_PRIMARY</TD><TD>2305843009213693952</TD><TD>externally-supplied zero point from ubercal analysis</TD></TR>            
+	  <TR><TD>STACK_PHOT_SRC</TD><TD>4611686018427387904</TD><TD>this measurement supplied the stack photometry</TD></TR>
+        </TABLEDATA>
+      </DATA>
+    </TABLE>
     <TABLE name="DetectionFlags">
       <DESCRIPTION>VOTable description of PSPS table DetectionFlags</DESCRIPTION>
@@ -102129,48 +102189,150 @@
           <TR><TD>PSFMODEL</TD><TD>1</TD><TD>Source fitted with a psf model (linear or non-linear)</TD></TR>
           <TR><TD>EXTMODEL</TD><TD>2</TD><TD>Source fitted with an extended-source model</TD></TR>
-          <TR><TD>FITTED</TD><TD>4</TD><TD>Source fitted with non-linear model (PSF or EXT; good or bad)</TD></TR>
-          <TR><TD>FITFAIL</TD><TD>8</TD><TD>Fit (non-linear) failed (non-converge, off-edge, run to zero)</TD></TR>
-          <TR><TD>POORFIT</TD><TD>16</TD><TD>Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)</TD></TR>
-          <TR><TD>PAIR</TD><TD>32</TD><TD>Source fitted with a double psf</TD></TR>
-          <TR><TD>PSFSTAR</TD><TD>64</TD><TD>Source used to define PSF model</TD></TR>
-          <TR><TD>SATSTAR</TD><TD>128</TD><TD>Source model peak is above saturation</TD></TR>
-          <TR><TD>BLEND</TD><TD>256</TD><TD>Source is a blend with other sourcers</TD></TR>
-          <TR><TD>EXTERNALPOS</TD><TD>512</TD><TD>Source based on supplied input position</TD></TR>
-          <TR><TD>BADPSF</TD><TD>1024</TD><TD>Failed to get good estimate of object's PSF</TD></TR>
-          <TR><TD>DEFECT</TD><TD>2048</TD><TD>Source is thought to be a defect</TD></TR>
-          <TR><TD>SATURATED</TD><TD>4096</TD><TD>Source is thought to be saturated pixels (bleed trail)</TD></TR>
-          <TR><TD>CR_LIMIT</TD><TD>8192</TD><TD>Source has crNsigma above limit</TD></TR>
-          <TR><TD>EXT_LIMIT</TD><TD>16384</TD><TD>Source has extNsigma above limit</TD></TR>
-          <TR><TD>MOMENTS_FAILURE</TD><TD>32768</TD><TD>could not measure the moments</TD></TR>
-          <TR><TD>SKY_FAILURE</TD><TD>65536</TD><TD>could not measure the local sky</TD></TR>
-          <TR><TD>SKYVAR_FAILURE</TD><TD>131072</TD><TD>could not measure the local sky variance</TD></TR>
-          <TR><TD>MOMENTS_SN</TD><TD>262144</TD><TD>moments not measured due to low S/N</TD></TR>
-          <TR><TD>BIG_RADIUS</TD><TD>1048576</TD><TD>poor moments for small radius, try large radius</TD></TR>
-          <TR><TD>AP_MAGS</TD><TD>2097152</TD><TD>source has an aperture magnitude</TD></TR>
-          <TR><TD>BLEND_FIT</TD><TD>4194304</TD><TD>source was fitted as a blend</TD></TR>
-          <TR><TD>EXTENDED_FIT</TD><TD>8388608</TD><TD>full extended fit was used</TD></TR>
-          <TR><TD>EXTENDED_STATS</TD><TD>16777216</TD><TD>extended aperture stats calculated</TD></TR>
-          <TR><TD>LINEAR_FIT</TD><TD>33554432</TD><TD>source fitted with the linear fit</TD></TR>
-          <TR><TD>NONLINEAR_FIT</TD><TD>67108864</TD><TD>source fitted with the non-linear fit</TD></TR>
-          <TR><TD>RADIAL_FLUX</TD><TD>134217728</TD><TD>radial flux measurements calculated</TD></TR>
-          <TR><TD>SIZE_SKIPPED</TD><TD>268435456</TD><TD>size could not be determined</TD></TR>
-          <TR><TD>ON_SPIKE</TD><TD>536870912</TD><TD>peak lands on diffraction spike</TD></TR>
-          <TR><TD>ON_GHOST</TD><TD>1073741824</TD><TD>peak lands on ghost or glint</TD></TR>
-          <TR><TD>OFF_CHIP</TD><TD>2147483648</TD><TD>peak lands off edge of chip</TD></TR>
-          <TR><TD>NOCAL</TD><TD>4294967296</TD><TD>detection ignored for this analysis (photcode, time range) -- internal only</TD></TR>
-          <TR><TD>POOR_PHOTOM</TD><TD>8589934592</TD><TD>detection is photometry outlier</TD></TR>
-          <TR><TD>SKIP_PHOTOM</TD><TD>17179869184</TD><TD>detection was ignored for photometry measurement</TD></TR>
-          <TR><TD>MEAS_AREA</TD><TD>34359738368</TD><TD>detection near image edge</TD></TR>
-          <TR><TD>POOR_ASTROM</TD><TD>68719476736</TD><TD>detection is astrometry outlier</TD></TR>
-          <TR><TD>SKIP_ASTROM</TD><TD>137438953472</TD><TD>detection was ignored for astrometry measurement</TD></TR>
-          <TR><TD>USED_OBJ</TD><TD>274877906944</TD><TD>detection was used during opdate objects</TD></TR>
-          <TR><TD>USED_CHIP</TD><TD>549755813888</TD><TD>detection was used during update chips</TD></TR>
-          <TR><TD>BLEND_MEAS</TD><TD>1099511627776</TD><TD>detection is within radius of multiple objects</TD></TR>
-          <TR><TD>BLEND_OBJ</TD><TD>2199023255552</TD><TD>multiple detections within radius of object</TD></TR>
-          <TR><TD>BLEND_MEAS_X</TD><TD>17592186044416</TD><TD>detection is within radius of multiple objects across catalogs</TD></TR>
-          <TR><TD>ARTIFACT</TD><TD>35184372088832</TD><TD>detection is thought to be non-astronomical</TD></TR>
+	  <TR><TD>FITTED</TD><TD>4</TD><TD>Source fitted with non-linear model (PSF or EXT; good or bad)</TD></TR>
+	  <TR><TD>FAIL</TD><TD>8</TD><TD>Fit (non-linear) failed (non-converge, off-edge, run to zero)</TD></TR>
+	  <TR><TD>POOR</TD><TD>16</TD><TD>Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)</TD></TR>
+	  <TR><TD>PAIR</TD><TD>32</TD><TD>Source fitted with a double psf</TD></TR>
+	  <TR><TD>PSFSTAR</TD><TD>64</TD><TD>Source used to define PSF model</TD></TR>
+	  <TR><TD>SATSTAR</TD><TD>128</TD><TD>Source model peak is above saturation</TD></TR>
+	  <TR><TD>BLEND</TD><TD>256</TD><TD>Source is a blend with other sources</TD></TR>
+	  <TR><TD>EXTERNAL</TD><TD>512</TD><TD>Source based on supplied input position</TD></TR>
+	  <TR><TD>BADPSF</TD><TD>1024</TD><TD>Failed to get good estimate of object's PSF</TD></TR>
+	  <TR><TD>DEFECT</TD><TD>2048</TD><TD>Source is thought to be a defect</TD></TR>
+	  <TR><TD>SATURATED</TD><TD>4096</TD><TD>Source is thought to be saturated pixels (bleed trail)</TD></TR>
+	  <TR><TD>CR_LIMIT</TD><TD>8192</TD><TD>Source has crNsigma above limit</TD></TR>
+	  <TR><TD>EXT_LIMIT</TD><TD>16384</TD><TD>Source has extNsigma above limit</TD></TR>
+	  <TR><TD>MOMENTS_FAILURE</TD><TD>32768</TD><TD>could not measure the moments</TD></TR>
+	  <TR><TD>SKY_FAILURE</TD><TD>65536</TD><TD>could not measure the local sky</TD></TR>
+	  <TR><TD>SKYVAR_FAILURE</TD><TD>131072</TD><TD>could not measure the local sky variance</TD></TR>
+	  <TR><TD>BELOW_MOMENTS_SN</TD><TD>262144</TD><TD>moments not measured due to low S/N</TD></TR>
+	  <TR><TD>BIG_RADIUS</TD><TD>1048576</TD><TD>poor moments for small radius, try large radius</TD></TR>
+	  <TR><TD>AP_MAGS</TD><TD>2097152</TD><TD>source has an aperture magnitude</TD></TR>
+	  <TR><TD>BLEND_FIT</TD><TD>4194304</TD><TD>source was fitted as a blend</TD></TR>
+	  <TR><TD>EXTENDED_FIT</TD><TD>8388608</TD><TD>full extended fit was used</TD></TR>
+	  <TR><TD>EXTENDED_STATS</TD><TD>16777216</TD><TD>extended aperture stats calculated</TD></TR>
+	  <TR><TD>LINEAR_FIT</TD><TD>33554432</TD><TD>source fitted with the linear fit</TD></TR>
+	  <TR><TD>NONLINEAR_FIT</TD><TD>67108864</TD><TD>source fitted with the non-linear fit</TD></TR>
+	  <TR><TD>RADIAL_FLUX</TD><TD>134217728</TD><TD>radial flux measurements calculated</TD></TR>
+	  <TR><TD>SIZE_SKIPPED</TD><TD>268435456</TD><TD>size could not be determined</TD></TR>
+	  <TR><TD>ON_SPIKE</TD><TD>536870912</TD><TD>peak lands on diffraction spike</TD></TR>
+	  <TR><TD>ON_GHOST</TD><TD>1073741824</TD><TD>peak lands on ghost or glint</TD></TR>
+	  <TR><TD>OFF_CHIP</TD><TD>2147483648</TD><TD>peak lands off edge of chip</TD></TR>
+	  <TR><TD>DIFF_WITH_SINGLE</TD><TD>4294967296</TD><TD>diff source matched to a single positive detection</TD></TR>
+	  <TR><TD>DIFF_WITH_DOUBLE</TD><TD>8589934592</TD><TD>diff source matched to positive detections in both images</TD></TR>
+	  <TR><TD>MATCHED</TD><TD>17179869184</TD><TD>diff source matched to positive detections in both images</TD></TR>
+	  <TR><TD>ON_SPIKE</TD><TD>34359738368</TD><TD>>25% of (PSF-weighted) pixels land on diffraction spike</TD></TR>
+	  <TR><TD>ON_STARCORE</TD><TD>68719476736</TD><TD>>25% of (PSF-weighted) pixels land on starcore</TD></TR>
+	  <TR><TD>ON_BURNTOOL</TD><TD>137438953472</TD><TD>>25% of (PSF-weighted) pixels land on burntool</TD></TR>
+	  <TR><TD>ON_CONVPOOR</TD><TD>274877906944</TD><TD>>25% of (PSF-weighted) pixels land on convpoor</TD></TR>
+	  <TR><TD>PASS1_SRC</TD><TD>549755813888</TD><TD>source detected in first pass analysis</TD></TR>
+	  <TR><TD>HAS_BRIGHTER_NEIGHBOR</TD><TD>1099511627776</TD><TD>peak is not the brightest in its footprint</TD></TR>
+	  <TR><TD>BRIGHT_NEIGHBOR_1</TD><TD>2199023255552</TD><TD>flux_n / (r^2 flux_p) >1</TD></TR>
+	  <TR><TD>BRIGHT_NEIGHBOR_10</TD><TD>4398046511104</TD><TD>flux_n / (r^2 flux_p) >10</TD></TR>
+	  <TR><TD>DIFF_SELF_MATCH</TD><TD>8796093022208</TD><TD>positive detection match is probably this source</TD></TR>
+	  <TR><TD>SATSTAR_PROFILE</TD><TD>17592186044416</TD><TD>saturated source is modeled with a radial profile</TD></TR>
+	  <TR><TD>NOCAL</TD><TD>35184372088832</TD><TD>detection ignored for this analysis (photcode, time range) -- internal only</TD></TR>
+	  <TR><TD>POOR_PHOTOM</TD><TD>70368744177664</TD><TD>detection is photometry outlier</TD></TR>                              
+	  <TR><TD>SKIP_PHOTOM</TD><TD>140737488355328</TD><TD>detection was ignored for photometry measurement</TD></TR>                      
+	  <TR><TD>AREA</TD><TD>281474976710656</TD><TD>detection near image edge</TD></TR>                      
+	  <TR><TD>POOR_ASTROM</TD><TD>562949953421312</TD><TD>detection is astrometry outlier</TD></TR>                                  
+	  <TR><TD>SKIP_ASTROM</TD><TD>1125899906842624</TD><TD>detection was ignored for astrometry measurement</TD></TR>                          
+	  <TR><TD>USED_OBJ</TD><TD>2251799813685248</TD><TD>detection was used during update objects</TD></TR>
+	  <TR><TD>USED_CHIP</TD><TD>4503599627370496</TD><TD>detection was used during update chips (XXX this probably does not make it into the db)</TD></TR>
+	  <TR><TD>BLEND_MEAS</TD><TD>9007199254740992</TD><TD>detection is within radius of multiple objects</TD></TR>
+	  <TR><TD>BLEND_OBJ</TD><TD>18014398509481984</TD><TD>multiple detections within radius of object</TD></TR>
+	  <TR><TD>UNDEF_3</TD><TD>36028797018963968</TD><TD>unused</TD></TR>
+	  <TR><TD>UNDEF_4</TD><TD>72057594037927936</TD><TD>unused</TD></TR>
+	  <TR><TD>BLEND_MEAS_X</TD><TD>144115188075855872</TD><TD>detection is within radius of multiple objects across catalogs</TD></TR>               
+	  <TR><TD>ARTIFACT</TD><TD>288230376151711744</TD><TD>detection is thought to be non-astronomical</TD></TR>        
+	  <TR><TD>UNDEF_5</TD><TD>576460752303423488</TD><TD>unused</TD></TR>
+	  <TR><TD>PHOTOM_UBERCAL</TD><TD>1152921504606846976</TD><TD>externally-supplied zero point from ubercal analysis</TD></TR>
+	  <TR><TD>STACK_PRIMARY</TD><TD>2305843009213693952</TD><TD>externally-supplied zero point from ubercal analysis</TD></TR>            
+	  <TR><TD>STACK_PHOT_SRC</TD><TD>4611686018427387904</TD><TD>this measurement supplied the stack photometry</TD></TR>
         </TABLEDATA>
       </DATA>
     </TABLE>
+    <TABLE name="ObjectInfoFlags">
+      <DESCRIPTION>VOTable description of PSPS table ObjectInfoFlags</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="name" arraysize="100" datatype="char">
+        <DESCRIPTION>Name of flag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="value" arraysize="1" datatype="long">
+        <DESCRIPTION>Flag value</DESCRIPTION>
+      </FIELD>
+      <FIELD name="description" arraysize="100" datatype="char">
+        <DESCRIPTION>Description of the flag</DESCRIPTION>
+      </FIELD>
+        <DATA>
+        <TABLEDATA>
+	  <TR><TD>FEW</TD><TD>1</TD><TD>used within relphot: skip star</TD></TR>
+	  <TR><TD>POOR</TD><TD>2</TD><TD>used within relphot: skip star</TD></TR>
+	  <TR><TD>FIT_AVE</TD><TD>65536</TD><TD>average position fitted</TD></TR>
+	  <TR><TD>FIT_PM</TD><TD>131072</TD><TD>proper motion fitted</TD></TR>
+	  <TR><TD>FIT_PAR</TD><TD>262144</TD><TD>parallax fitted</TD></TR>
+	  <TR><TD>USE_AVE</TD><TD>524288</TD><TD>average position used (not PM or PAR)</TD></TR>
+	  <TR><TD>USE_PM</TD><TD>1048576</TD><TD>proper motion used (not AVE or PAR)</TD></TR>
+	  <TR><TD>USE_PAR</TD><TD>2097152</TD><TD>parallax used (not AVE or PM)</TD></TR>
+	  <TR><TD>NO_ASTROM</TD><TD>4194304</TD><TD>mean astrometry could not be measured</TD></TR>
+	  <TR><TD>EXT</TD><TD>16777216</TD><TD>extended in our data (eg, PS)</TD></TR>
+	  <TR><TD>EXT_ALT</TD><TD>33554432</TD><TD>extended in external data (eg, 2MASS)</TD></TR>
+	  <TR><TD>GOOD</TD><TD>67108864</TD><TD>good-quality measurement in our data (eg,PS)</TD></TR>
+	  <TR><TD>GOOD_ALT</TD><TD>134217728</TD><TD>good-quality measurement in  external data (eg, 2MASS)</TD></TR>
+        </TABLEDATA>
+      </DATA>
+    </TABLE>
+     <TABLE name="ObjectFilterFlags">
+      <DESCRIPTION>VOTable description of PSPS table ObjectInfoFlags</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="name" arraysize="100" datatype="char">
+        <DESCRIPTION>Name of flag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="value" arraysize="1" datatype="long">
+        <DESCRIPTION>Flag value</DESCRIPTION>
+      </FIELD>
+      <FIELD name="description" arraysize="100" datatype="char">
+        <DESCRIPTION>Description of the flag</DESCRIPTION>
+      </FIELD>
+        <DATA>
+        <TABLEDATA>
+	  <TR><TD>SECF_STAR_FEW</TD><TD>1</TD><TD>used within relphot: skip star</TD></TR>
+	  <TR><TD>SECF_STAR_POOR</TD><TD>2</TD><TD>used within relphot: skip star</TD></TR>
+	  <TR><TD>SECF_USE_SYNTH</TD><TD>4</TD><TD>synthetic photometry used in average measurement</TD></TR>
+	  <TR><TD>SECF_USE_UBERCAL</TD><TD>8</TD><TD>synthetic photometry used in average measurement</TD></TR>
+	  <TR><TD>SECF_HAS_PS1</TD><TD>16</TD><TD>PS1 photometry used in average measurement</TD></TR>
+	  <TR><TD>SECF_HAS_STACK</TD><TD>32</TD><TD>PS1 stack photometry exists</TD></TR>
+	  <TR><TD>PHOTOM_PASS_0</TD><TD>256</TD><TD>average magnitude calculated in 0th pass</TD></TR>
+	  <TR><TD>PHOTOM_PASS_1</TD><TD>512</TD><TD>average magnitude calculated in 1th pass</TD></TR>
+	  <TR><TD>PHOTOM_PASS_2</TD><TD>1024</TD><TD>average magnitude calculated in 2th pass</TD></TR>
+	  <TR><TD>PHOTOM_PASS_3</TD><TD>2048</TD><TD>average magnitude calculated in 3th pass</TD></TR>
+	  <TR><TD>PHOTOM_PASS_4</TD><TD>4096</TD><TD>average magnitude calculated in 4th pass</TD></TR>
+	  <TR><TD>PSPS_OBJ_EXT</TD><TD>8192</TD><TD>extended in this band (PSPS only)</TD></TR>
+        </TABLEDATA>
+      </DATA>
+    </TABLE>
+     <TABLE name="ObjectQualityFlags">
+      <DESCRIPTION>VOTable description of PSPS table ObjectInfoFlags</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="name" arraysize="100" datatype="char">
+        <DESCRIPTION>Name of flag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="value" arraysize="1" datatype="long">
+        <DESCRIPTION>Flag value</DESCRIPTION>
+      </FIELD>
+      <FIELD name="description" arraysize="100" datatype="char">
+        <DESCRIPTION>Description of the flag</DESCRIPTION>
+      </FIELD>
+        <DATA>
+        <TABLEDATA>
+	  <TR><TD>QF_OBJ_EXT</TD><TD>1</TD><TD>extended in our data (eg, PS)</TD></TR>
+	  <TR><TD>QF_OBJ_EXT_ALT</TD><TD>2</TD><TD>extended in external data (eg, 2MASS)</TD></TR>
+	  <TR><TD>QF_OBJ_GOOD</TD><TD>4</TD><TD>good-quality measurement in our data (eg,PS)</TD></TR>
+	  <TR><TD>QF_OBJ_GOOD_ALT</TD><TD>8</TD><TD>good-quality measurement in  external data (eg, 2MASS)</TD></TR>
+	  <TR><TD>QF_OBJ_GOOD_STACK</TD><TD>16</TD><TD>good-quality object in the stack (> 1 good stack)</TD></TR>
+	  <TR><TD>QF_OBJ_SUSPECT_STACK</TD><TD>32</TD><TD>suspect object in the stack (> 1 good or suspect stack, less tham 2 good)</TD></TR>
+	  <TR><TD>QF_OBJ_BAD_STACK</TD><TD>64</TD><TD>good-quality object in the stack (> 1 good stack)</TD></TR>
+	</TABLEDATA>
+      </DATA>
+    </TABLE>   
   </RESOURCE>
 </VOTABLE>
Index: /branches/eam_branches/ipp-20121219/ippToPsps/config/P2/tables.vot
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/config/P2/tables.vot	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/config/P2/tables.vot	(revision 34902)
@@ -511,32 +511,4 @@
       </DATA>
     </TABLE>
-    <TABLE name="ObjectCalColor">
-      <DESCRIPTION>VOTable description of PSPS table ObjectCalColor</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM object identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ipp object identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calColor" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> color adopted for magnitude calculation</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calColorErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> error in calibrating color</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>calibration modification number</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>Data release when this color calibration was established</DESCRIPTION>
-      </FIELD>
-      <DATA>
-        <TABLEDATA></TABLEDATA>
-      </DATA>
-    </TABLE>
     <TABLE name="DetectionCalib">
       <DESCRIPTION>VOTable description of PSPS table DetectionCalib</DESCRIPTION>
Index: /branches/eam_branches/ipp-20121219/ippToPsps/config/ST/tables.vot
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/config/ST/tables.vot	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/config/ST/tables.vot	(revision 34902)
@@ -1212,33 +1212,5 @@
       </DATA>
     </TABLE>
-    <TABLE name="ObjectCalColor">
-      <DESCRIPTION>VOTable description of PSPS table ObjectCalColor</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long">
-        <DESCRIPTION>ODM object identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long">
-        <DESCRIPTION>ipp object identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calColor" arraysize="1" datatype="float">
-        <DESCRIPTION> color adopted for magnitude calculation (unit = mag)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calColorErr" arraysize="1" datatype="float">
-        <DESCRIPTION> error in calibrating color (unit = mag)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calibModNum" arraysize="1" datatype="short">
-        <DESCRIPTION>calibration modification number</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>Data release when this color calibration was established</DESCRIPTION>
-      </FIELD>
-      <DATA>
-        <TABLEDATA></TABLEDATA>
-      </DATA>
-    </TABLE>
-       <TABLE name="StackDetectionCalib">
+      <TABLE name="StackDetectionCalib">
       <DESCRIPTION>VOTable description of PSPS table StackDetectionCalib</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
Index: /branches/eam_branches/ipp-20121219/ippToPsps/jython/detectionbatch.py
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/jython/detectionbatch.py	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/jython/detectionbatch.py	(revision 34902)
@@ -766,5 +766,5 @@
                 self.populateSkinnyObjectTable(ota)
                 #self.logger.info("updated skinnyobject")
-                self.populateObjectCalColorTable(ota)
+                #self.populateObjectCalColorTable(ota)
                 #self.logger.info("updated objectcalcolor")
                 self.populateDetectionCalibTable(ota)
@@ -775,5 +775,5 @@
                 self.tablesToExport.append("Detection_" + ota)
                 self.tablesToExport.append("SkinnyObject_" + ota)
-                self.tablesToExport.append("ObjectCalColor_" + ota)
+                #self.tablesToExport.append("ObjectCalColor_" + ota)
                 self.tablesToExport.append("DetectionCalib_" + ota)
                 tables.append("Detection_" + ota)
Index: /branches/eam_branches/ipp-20121219/ippToPsps/jython/gpc1db.py
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/jython/gpc1db.py	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/jython/gpc1db.py	(revision 34902)
@@ -61,8 +61,10 @@
                    JOIN rawExp USING (exp_id) \
                    JOIN mergedvodbRun using (minidvodb_id) \
+                   JOIN mergedvodbProcessed using (merge_id) \
                    WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
                    AND minidvodbRun.state = 'merged' \
                    AND mergedvodbRun.state = 'full' \
                    AND minidvodbProcessed.fault = 0 \
+                   AND mergedvodbProcessed.fault = 0 \
                    AND addRun.stage = '" + stage + "' \
                    AND addRun.state = 'full' \
@@ -77,13 +79,17 @@
                    JOIN minidvodbRun USING(minidvodb_name) \
                    JOIN minidvodbProcessed USING(minidvodb_id) \
+                   JOIN mergedvodbRun USING(minidvodb_id) \
+                   JOIN mergedvodbProcessed USING (merge_id) \
                    JOIN  stackRun USING(stack_id) JOIN skycell USING(skycell_id) \
-                   WHERE minidvodbRun.minidvodb_group = '" + dvoDb + "' \
+                   WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
                    AND minidvodbRun.state = 'merged' \
                    AND minidvodbProcessed.fault = 0 \
+                   AND mergedvodbRun.state = 'full' \
+                   AND mergedvodbProcessed.fault = 0 \
                    AND addRun.stage = '" + stage + "' \
                    AND addRun.state = 'full' \
                    AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \
                    AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) 
-
+            
         try:
             rs = self.executeQuery(sql)
Index: /branches/eam_branches/ipp-20121219/ippToPsps/jython/stackbatch.py
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/jython/stackbatch.py	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/jython/stackbatch.py	(revision 34902)
@@ -93,5 +93,5 @@
        self.scratchDb.dropTable("StackToImage")
        self.scratchDb.dropTable("SkinnyObject")
-       self.scratchDb.dropTable("ObjectCalColor")
+       #self.scratchDb.dropTable("ObjectCalColor")
        self.scratchDb.dropTable("StackDetectionCalib")
 
@@ -828,5 +828,5 @@
         self.populateSkinnyObject()
         #self.logger.infoPair("populating","ObjectCalColor") 
-        self.populateObjectCalColor()
+        #self.populateObjectCalColor()
         #self.logger.infoPair("populating","StackDetectionCalib") 
         self.populateStackDetectionCalib()
Index: /branches/eam_branches/ipp-20121219/ippToPsps/perl/pspsSchema2xml.pl
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/perl/pspsSchema2xml.pl	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/perl/pspsSchema2xml.pl	(revision 34902)
@@ -118,5 +118,5 @@
     parseTable("Filter");
     parseTable("FitModel");
-    parseTable("PhotozRecipe");
+ #   parseTable("PhotozRecipe");
     parseTable("Survey");
     parseTable("CameraConfig");
@@ -141,5 +141,5 @@
     parseTable("Detection");
     parseTable("SkinnyObject");
-    parseTable("ObjectCalColor");
+  #  parseTable("ObjectCalColor");
 }
 
@@ -153,7 +153,7 @@
     parseTable("StackMeta");
     parseTable("StackToImage");
-    parseTable("StackLowSigDelta");
-    parseTable("StackHighSigDelta");
-    parseTable("ObjectCalColor");
+   # parseTable("StackLowSigDelta");
+   # parseTable("StackHighSigDelta");
+   # parseTable("ObjectCalColor");
 }
 
@@ -171,5 +171,5 @@
     parseTable("StackToImage");
     parseTable("SkinnyObject");
-    parseTable("ObjectCalColor");
+   # parseTable("ObjectCalColor");
 }
 
Index: /branches/eam_branches/ipp-20121219/ippTools/src/warptoolConfig.c
===================================================================
--- /branches/eam_branches/ipp-20121219/ippTools/src/warptoolConfig.c	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippTools/src/warptoolConfig.c	(revision 34902)
@@ -402,4 +402,5 @@
     psMetadataAddS64(tofullskyfileArgs, PS_LIST_TAIL, "-set_magicked",  0, "new value for magicked", 0);
     psMetadataAddS16(tofullskyfileArgs, PS_LIST_TAIL, "-set_quality", 0, "new value for quality", 0);
+    psMetadataAddS16(tofullskyfileArgs, PS_LIST_TAIL, "-set_background_model", 0, "new value for background_model", 0);
     
     // -updateskyfile
Index: /branches/eam_branches/ipp-20121219/ippconfig/recipes/ppStack.config
===================================================================
--- /branches/eam_branches/ipp-20121219/ippconfig/recipes/ppStack.config	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ippconfig/recipes/ppStack.config	(revision 34902)
@@ -32,4 +32,6 @@
 TARGET.FRAC	F32	0.1		# Minimum flux fraction for target PSF
 TARGET.MINMAG	F32	3.0		# Minimum magnitude difference to tolerate in stamp
+
+BACKGROUND.MODEL    BOOL   FALSE        # Construct a stacked version of the warp stage background
 
 RENORM		BOOL	TRUE		# Renormalise weight maps?
Index: /branches/eam_branches/ipp-20121219/ppStack/src/ppStackCombinePrepare.c
===================================================================
--- /branches/eam_branches/ipp-20121219/ppStack/src/ppStackCombinePrepare.c	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ppStack/src/ppStackCombinePrepare.c	(revision 34902)
@@ -34,10 +34,13 @@
 /*       options->expRO = NULL; */
 /*     } */
-    pmCell *bkgCell;
-    int bkg_r0,bkg_c0;
-    int bkg_nC,bkg_nR;
+    int bkg_r0 = 0,bkg_c0 = 0;
+    int bkg_nC = 0,bkg_nR = 0;
     if (bkgName) {
       ppStackFileActivationSingle(config, PPSTACK_FILES_BKG, true, 0);
       pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.BKGMODEL", 0);
+      if (!file)  {
+        psError(PPSTACK_ERR_ARGUMENTS, false, "Output background model selected but no inputs provided.");
+        return false;
+      }
       pmFPAview *view = ppStackFilesIterateDown(config);
       pmReadout *ro = pmFPAviewThisReadout(view,file->fpa);
@@ -47,5 +50,5 @@
       bkg_nC = ro->image->numCols;
       bkg_nR = ro->image->numRows;
-      bkgCell = pmFPAfileThisCell(config->files, view, bkgName); // Bkg cell
+      pmCell *bkgCell = pmFPAfileThisCell(config->files, view, bkgName); // Bkg cell
       
       options->bkgRO = pmReadoutAlloc(bkgCell); // BKG readout
Index: /branches/eam_branches/ipp-20121219/ppStack/src/ppStackLoop.c
===================================================================
--- /branches/eam_branches/ipp-20121219/ppStack/src/ppStackLoop.c	(revision 34901)
+++ /branches/eam_branches/ipp-20121219/ppStack/src/ppStackLoop.c	(revision 34902)
@@ -41,8 +41,9 @@
     if (options->quality) return true; // Can't do anything else
 
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
+
     // Ensure sufficient inputs
     {
         int numGood = stackSummary(options, "initial combination");
-        psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
         bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining
         if (safe && numGood <= 1) {
@@ -62,6 +63,8 @@
     }
 
+    bool doBackground = psMetadataLookupBool(NULL, recipe, "BACKGROUND.MODEL");
+
     // Prepare for combination
-    if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", "PPSTACK.OUTPUT.BKGMODEL", PPSTACK_FILES_STACK, stack, options, config)) {
+    if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", doBackground ? "PPSTACK.OUTPUT.BKGMODEL" : NULL, PPSTACK_FILES_STACK, stack, options, config)) {
         psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
         psFree(stack);
@@ -143,5 +146,5 @@
 
     // Generate median background stack here.
-    if (!ppStackCombineBackground(stack, options, config)) {
+    if (doBackground && !ppStackCombineBackground(stack, options, config)) {
       psError(psErrorCodeLast(), false, "Unable to generate median of background images.");
       psFree(stack);
Index: /branches/eam_branches/ipp-20121219/tools/queuessky.lap
===================================================================
--- /branches/eam_branches/ipp-20121219/tools/queuessky.lap	(revision 34902)
+++ /branches/eam_branches/ipp-20121219/tools/queuessky.lap	(revision 34902)
@@ -0,0 +1,183 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+use POSIX qw(strftime);
+
+# The rest of this is some subroutines for setting up the filter combinations
+my @filter = qw(
+g.00000
+r.00000
+i.00000
+z.00000
+y.00000
+);
+
+
+my ($ramin, $ramax, $decmin, $decmax, $absglatmin, $go);
+my $combos = 5;
+my $verbose = 0;
+
+GetOptions(
+    'ra_min=s'           =>  \$ramin,
+    'ra_max=s'           =>  \$ramax,
+    'dec_min=s'          =>  \$decmin,
+    'dec_max=s'          =>  \$decmax,
+#    'absglatmin=s'      =>  \$absglatmin,  # not yet
+    'nfilters=s'        =>  \$combos,
+    'go'                =>  \$go,
+    'verbose|v'         =>  \$verbose,
+) or pod2usage(2);
+
+unless (defined $ramin and defined $ramax) {
+    warn ("ramin and ramax are required\n");
+    pod2usage(2);
+};
+
+my $pretend = $go ? "" : " -pretend";
+
+my $filter_combos = setup_filter_combos($combos);
+
+# printcombos($filter_combos) if $verbose;
+
+my $label='LAP.ThreePi.20120706';
+
+my $datestr = strftime "%Y/%m/%d", gmtime;
+
+my $command="staticskytool -definebyquery -set_workdir neb://\@HOST\@.0/gpc1/$label/$datestr"
+    . " -set_label $label -select_label $label  -set_data_group $label -set_dist_group LAP.ThreePi"
+    . " -ra_min $ramin -ra_max $ramax"
+    . " -simple"
+    . $pretend;
+
+$command .= " -dec_min $decmin" if defined $decmin;
+$command .= " -dec_max $decmax" if defined $decmax;
+
+# XXX TODO: implement absglatmin
+
+foreach my $filter_combo (@$filter_combos) {
+    my $cmd = $command;
+    foreach my $f (@$filter_combo) {
+        $cmd .= " -select_filter $f";
+    }
+    print "$cmd\n" if $verbose;
+    my $rc = system $cmd ; #. " -glat_min 10";
+    if ($rc) {
+        my $status = $rc >> 8;
+        print STDERR "$cmd returned $rc $status\n";
+        exit $status;
+    }
+}
+
+
+
+exit 0;
+
+
+
+
+sub setup_filter_combos {
+    my $combos = shift;
+
+    die "invalid combos arg: $combos\n" unless defined $combos and ($combos eq "5" or $combos eq "4" or $combos eq "3" or $combos eq "2" or $combos eq "1");
+
+    if ($combos eq 5) {
+        my @ary;
+        push @ary, \@filter;
+        return \@ary;
+    } elsif ($combos eq 4) {
+        return makecombo4();
+    } elsif ($combos eq 3) {
+        return makecombo3();
+    } elsif ($combos eq 2) {
+        return makecombo2();
+    } elsif ($combos eq 1) {
+        my @ary;
+        foreach my $f (@filter) {
+            my @ary2 = ($f);
+            push @ary, \@ary2
+        }
+        return \@ary;
+    } else {
+        die "how did we get here?";
+    }
+}
+
+
+
+sub printcombos {
+    my $combos = shift;
+    foreach my $c (@$combos) {
+        my $str;
+        foreach my $f (@$c) {
+            $str .= " -select_filter $f";
+        }
+        print "$str\n";
+    }
+}
+
+
+sub makecombo4 {
+    my $numFilters = scalar @filter;
+    my @combos;
+
+    for (my $i = 0; $i < $numFilters; $i++) {
+        for (my $j = $i + 1; $j < $numFilters; $j++) {
+            for (my $k = $j + 1; $k < $numFilters; $k++) {
+                for (my $l = $k + 1; $l < $numFilters; $l++) {
+                    my @combo = ($filter[$i], $filter[$j], $filter[$k], $filter[$l]);
+                    push @combos, \@combo;
+                }
+            }
+        }
+    }
+    return \@combos;
+}
+
+sub makecombo3 {
+    my $numFilters = scalar @filter;
+    my @combos;
+
+    for (my $i = 0; $i < $numFilters; $i++) {
+        for (my $j = $i + 1; $j < $numFilters; $j++) {
+            for (my $k = $j + 1; $k < $numFilters; $k++) {
+                my @combo = ($filter[$i], $filter[$j], $filter[$k]);
+                push @combos, \@combo;
+            }
+        }
+    }
+    return \@combos;
+}
+
+sub makecombo2 {
+    my $numFilters = scalar @filter;
+    my @combos;
+
+    for (my $i = 0; $i < $numFilters; $i++) {
+        for (my $j = $i + 1; $j < $numFilters; $j++) {
+            my @combo = ($filter[$i], $filter[$j]);
+            push @combos, \@combo;
+        }
+    }
+    return \@combos;
+}
+
+
+__END__
+
+=pod
+
+=head1 NAME
+
+queuesskylap - queue LAP staticsky runs 
+
+=head1 SYNOPSIS
+    
+    XXX: pod TODO
+
+    queuesskylap --ra_min <ra_min> --ra_max <ra_max> --dec_min <dec_min> --dec_max <dec_max> [--go]
+
+
Index: /branches/eam_branches/ipp-20121219/tools/run.relastro
===================================================================
--- /branches/eam_branches/ipp-20121219/tools/run.relastro	(revision 34902)
+++ /branches/eam_branches/ipp-20121219/tools/run.relastro	(revision 34902)
@@ -0,0 +1,67 @@
+#!/bin/csh -f
+
+if ($#argv != 5) then 
+  echo "USAGE: run.relastro (catdir) (Rmin) (Rmax) (Dmin) (Dmax)"
+  exit 2
+endif
+
+set REALRUN = 0
+
+set  catdir = $argv[1]
+set  ra_min = $argv[2]
+set  ra_max = $argv[3]
+set dec_min = $argv[4]
+set dec_max = $argv[5]
+
+alias run.relastro \
+  'echo -n "--- starting relastro $catdir --- "; date; \
+   echo          relastro $options $region -D CATDIR $catdir; \
+   if ($REALRUN) relastro $options $region -D CATDIR $catdir'
+
+# -update-chips : determine improved astrometry calibrations
+# try 1000 meas per deg^2, but if memory if available, go to more
+if (1) then
+  set options = "-update-chips"
+  set options = "$options -D RELASTRO_SRC_MEAS_TOOFEW 1"
+  set options = "$options -D RELASTRO_SIGMA_LIM 0.1"
+  set options = "$options -nloop 6"
+  set options = "$options -basic-image-search"
+  set options = "$options -reset"
+  set options = "$options -update"
+  set options = "$options -max-density 3000"
+  set options = "$options -threads 4"
+  set options = "$options -v"
+
+  # enable parallel operations for parallel databases
+  # set options = "$options -parallel"
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relastro
+  if ($status) then
+    echo "ERROR : failure running relastro"
+    echo -n "--- done with relastro --- "; date
+    exit 1
+  endif
+endif
+
+# -update-objects : determine improved positions, including parallax and proper motions
+if (1) then
+  set options = "-update-objects -pmpar"
+  set options = "$options -D PM_DT_MIN 1.0"
+  set options = "$options -D PAR_FACTOR_MIN 0.25"
+  set options = "$options -update"
+  set options = "$options -v"
+
+  # enable parallel operations for parallel databases
+  # set options = "$options -parallel"
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relastro
+  if ($status) then
+    echo "ERROR : failure running relastro"
+    echo -n "--- done with relastro --- "; date
+    exit 1
+  endif
+endif
+
+echo -n "--- done with relastro --- "; date
Index: /branches/eam_branches/ipp-20121219/tools/run.relphot
===================================================================
--- /branches/eam_branches/ipp-20121219/tools/run.relphot	(revision 34902)
+++ /branches/eam_branches/ipp-20121219/tools/run.relphot	(revision 34902)
@@ -0,0 +1,57 @@
+#!/bin/csh -f
+
+if ($#argv != 5) then 
+  echo "USAGE: run.relphot (catdir) (Rmin) (Rmax) (Dmin) (Dmax)"
+  exit 2
+endif
+
+set REALRUN = 1
+
+set  catdir = $argv[1]
+set  ra_min = $argv[2]
+set  ra_max = $argv[3]
+set dec_min = $argv[4]
+set dec_max = $argv[5]
+
+alias run.relphot \
+  'echo -n "--- starting relphot $catdir --- "; date; \
+   echo          relphot $options $region -D CATDIR $catdir; \
+   if ($REALRUN) relphot $options $region -D CATDIR $catdir'
+
+# try 2000 meas per deg^2
+if (1) then
+  set filters = "g,r,i,z,y"
+
+  set options = "$filters -imfreeze -mosaic"
+  set options = "$options -D MAG_LIM 32.0"
+  set options = "$options -D SIGMA_LIM 0.1"
+  set options = "$options -D STAR_TOOFEW 1"
+  set options = "$options -D STAR_CHISQ 20.0"
+  set options = "$options -D IMAGE_OFFSET 2.0"
+
+  set options = "$options -nloop 25"
+
+  set options = "$options -D CAMERA gpc1"
+  set options = "$options -basic-image-search"
+  set options = "$options -update"
+  set options = "$options -threads 4"
+  set options = "$options -statmode WT_MEAN"
+  set options = "$options -max-density 2000"
+
+  # activate parallel mode when catdir is parallel
+  # set options = "$options -parallel"
+
+  # option to change the schema
+  # set options = "$options -update-catformat PS1_V3"
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relphot
+  if ($status) then
+    echo "ERROR : failure running relphot"
+    echo -n "--- done with relphot --- "; date
+    exit 1
+  endif
+endif
+
+echo -n "--- done with relphot --- "; date
+exit 0
Index: /branches/eam_branches/ipp-20121219/tools/run.setphot
===================================================================
--- /branches/eam_branches/ipp-20121219/tools/run.setphot	(revision 34902)
+++ /branches/eam_branches/ipp-20121219/tools/run.setphot	(revision 34902)
@@ -0,0 +1,40 @@
+#!/bin/csh -f
+
+if ($#argv != 1) then 
+  echo "USAGE: run.setphot (catdir)"
+  exit 2
+endif
+
+set REALRUN = 0
+
+set  catdir = $argv[1]
+set ubercal = ~ipp/ucalqw_noref.fits
+
+alias run.setphot \
+  'echo -n "--- starting setphot $catdir --- "; date; \
+   echo          setphot $options -D CATDIR $catdir $ubercal; \
+   if ($REALRUN) setphot $options -D CATDIR $catdir $ubercal'
+
+set options = ""
+set options = "$options -update"
+set options = "$options -ubercal"
+set options = "$options -no-metadata"
+
+# activate parallel mode when catdir is parallel
+# set options = "$options -parallel"
+
+# the new ubercal file includes Eddie's offsets relative to JT (so, no need to supply -zpt-offsets)
+run.setphot
+if ($status) then
+  echo "failed setphot"
+  echo -n "--- done with setphot ---"; date
+  exit 1
+endif
+echo -n "--- done with setphot ---"; date
+exit 0
+
+
+# old command lines with zpt offsets
+# setphot -parallel -reset -zpt-offsets g,r,i,z,y -0.013,+0.012,+0.001,-0.016,-0.021 -update -ubercal -no-metadata -D CATDIR $catdir_3pi $ubercal
+# setphot -images-only -parallel -reset -zpt-offsets g,r,i,z,y -0.013,+0.012,+0.001,-0.016,-0.021 -update -ubercal -no-metadata -D CATDIR $catdir_3pi $ubercal
+
