LSST Science Pipelines-specific TODOs:
* Add copyright preambles
* Switch from using std::list to std::vector in general
* Change Point.x from std::vector<double> to std::array<double, 2> in WCSFoFRoutine.h
* Do a memory overhaul of FoF.h (change raw pointers to smart pointers)
* Do a memory overhaul of PhotoMatch.h (raw pointers to smart pointers)


* Check on int/long/LONGLONG for id's

* "bad conversion" happening during/after Final MapCollection in WCSFit - some multithreading bug.  Check protection of YAMLCollector against threads.
* Document CFITSIO_NEEDS_CURL
* Document: syserrmmag for per-exposure syserrs. 
* Update documentation: PixelMap.tex and the fitting classes.
* Document PhotoFit, MagColor and all their parameters.

* Implement proper motion and parallax, Gaia DR2 (or other) references
  * WEIGHT, MAGWEIGHT required?
  * AIRMASS, EXPOSURE coming in properly in config.py?
  * get real ra, dec into coords for the python notebook making fake data

* Pass initial guess xypix into dPixdWorld

* It's possible that passing fieldProjections into readObjects and fillDetection is superfluous because it is already the projection in use by the WCS.

* Include parallax when slicing PMDetection down to single-epoch detection??

* Allow photmetric reference catalog

* Derive asymmetric errors and excess variance from turbulence
  
* Go through test programs (AUDIT file)

* Occasional segfault in ReadExtensions, something to do with multithreading??
  (Looked through this and all of the places needing critical() segments seem to have them.
  Rarer crashes now?)

* Read data (and reject short-count exposures) before degeneracy checks

* Why is final mapCollection slow?

* Hex values read for Expressions.

* New nightwise priors using time structure functions
* Atmospheric parameters for nightly priors?

* Roll back alpha while clipping instead of recalculating full matrix

* Check for underfit exposure after sigma clipping

* is minMatch being used consistently for #matches total vs in fitted detections?

* Investigate color term degeneracy breaking

-------------DONE
* Fix allfit.py script
* option for DrawAstro to not draw, just make TPVs
* Parallelize Photo2DESDM loops
* Change priors to YAML format
* Write auto-prior script
* clean up gmbpy dependence
* Bring in setup directory
* Bring in python analysis scripts

For py3 branch, upgrading all Python to work with Python 3.x:
    * from __future__ import division,print_function
    * Check all /, change to // where integer floor is desired
    * change print statements
    * switch "if/for x in dict.keys()" to "if/for x in dict"
    * iteritems()->items() (slow now in Python2 since it makes a list? from future.utils import iteritems)
    * range(),zip(),dict.keys(),values(),items() are now iterables, not lists.  Check these...  Note that iterators in dicts won't work if objects are popped out of dict during iteration (or added).
    * xrange -> range
    * __builtin__ module now builtins.  Don't see a __future__ for this.

* Parallax / PM update:
  * chisq and DOF counting
  * Augment Detection with time, earth position 2d, allow 2d error ellipses?
  * Derive PMDetection having priors on 5d
  * Derive PMMatch for objects with PM freedom
  * MaxDeviateSq is different for PMDetection with 5 DOF.  Make it per DOF.
  * readExposure should look for systematic errors (or install them)
  * wtx/y to invCov.
  * Have parallax prior
  * Convert Gaia position to reference epoch
  * Free parallax, PM are options.
  * Make weights per exposure (readExposure, config files)
  * Make a new output file for stellar PM's.
  * get a color for each Match in astro output.
  * Match maintains state telling when to remap coordinates.
  * Check coordalign methods for proper state updating of Matches.
  * Does sigmaClip routine efficiently use remap()?
  * are solve(), predict(), etc. ok when no valid fit for Match (always check dof<0)
  * Insure that positions are calculated even for clipped / non-fit points before output and stats for astrometry
  * WCSFit now uses max error in world coordinates, not pixels
  * ReadObjects must produce new Detection members.
  * Change output data to include PM's
  * Check that PMMatch will appropriately skip when too few DOF, no prior
  * Treat PMDetection as single epoch properly if not using PMMatch
  * Change WCSFit summary output
  * Are sigmas stored as arcsec or radians?
  * Program-level systematic errors need to work with any already in config files.
  * Make new Units.h for single-source convention about angular units.  Replace discrete
    uses of units throughout code with these, also checking covariance specs.  Done for:
    Match.h,cpp FitSubroutines MagColor WCSFit Accum WcsSubs WCSFoF
  * readObjects makes xyErrKeys array
  * WCSFoF needs to get Gaia coords with PM (actually just uses xkey, ykey)
  * prepare() should get expected chisq even for clipped detections
  * Work out expectedChisq considering non-unity weights.
  * Get rid of invCovMeas and take weight factor out of invCovFit->invCov.  clean up where weight
    factors are needed (sigma clip without them, compare to expectedChisq).  Set up trueChisq at
    match level.  (check for nFit, invCovFit, pmCov and the like)
  * Signal no fitting with weight->0. - check initialization of fitWeight.
  * document that all PM catalogs are ICRS degrees for RA/Dec, mas for PM/Par    
  * check syserr, obs keywords in the cpp programs match those in configure.py
  * Config files need:
    * Field: PM_EPOCH (actually only need this if want to override Gaia default) DONE
    * Exposure: observatory position, systematic errors for astrometry
    * Extension: ERRXX,YY,XYKeys
    * Need mjd to be Gaia epoch for Gaia files.
  * Shift all internal PM, PAR, covariance data to WCS_UNIT (degrees) to
    make matrices combining positions and PM/PAR better conditioned.
  * Alter getGaiaDR2 to use mas in position covariances.
  * WCSFit puts parallaxPrior into WCS_UNIT from mas.
  * move parallax/PM priors into static variables of PMDetection
  * output RA, Dec for stars / output in degrees, not mas for [xy]W
* DOF changing during Newton iterations (needed dof,chisq reductions in chisqDOF)
* Some Eigen alignment error - needed EIGEN_NEW in Exposure, Match, PMMatch
* Remove duplicate parallactic in decamDCR.py, dup EpochFinder stuff in compresscat -
  get from gbutil.decam now.
* Residual calculation should be multiprocessed, and reduce FITS I/O, separate files for 2 other cats
* Fix conflict between AstronomicalConstants SECOND and an MKL routine of same name.
* Add in-place Cholesky to photometric solver for Eigen
* Change photometric fit / clip to use fitWeight, other parallel state maintenance to Astro.
  * change weight / invVar usage DONE
  * self-maintenance of state DONE
  * write getTrueChisq(), expectedChisq DONE
  * get rid of countFit() usages DONE
  * logging in sigmaClip 
  * get rid of remap() calls for photoprior, photo/coordAlign, in favor of states. DONE
  
* Use individual systematic errors per extension in MagColor

----
Some notes about inputs and errors for 5d:
FitSubroutines makePMDetection() takes column names for
xKey, yKey, for RA/Dec (in WCS_UNIT=DEGREE) [pmRa,pmDec,parallax,pmCov]Key.
It calls shiftReferenceEpoch, which has the job of filling in xw,yw and 2d sigmas
in case we are going to slice it.
readObjects() looks in extension table for attributes named
  xKey, yKey
  err[XX,YY,XY]Key -or- errKey for non-PM, giving ellipse or circlular error,
    which will be in pixel units.  1 or 3 go into xyErrKeys array, in the order XX,YY,XY.
    Then add the astrometricCovariance from the exposure. invCov->0 for tags.
  pm[Ra,Dec,Cov]Key,parallaxKey for PM catalogs.  No additional covariance from exposure.

readExposures() is looking for sysAstCov column which is vector<double> type.  Defaults
  to zero matrix if there are not 3 elements in the exposure's row.
  WCSFit.h will *add* command-line-specified systematic errors to the ones in table.
  sysError gets added to all real instruments.  referenceSysError gets added to REFERENCE
  exposures, but *not* to PM exposures.

Note PM_INSTRUMENTs are always considered references (no free parameters).

Choice of degrees for WCS for reference exposures is made in readExtensions()
Others are spec'ed in the Astro file.
