
2005.12.23

  Improvements in psphot as of psphot_dev_07

  - updated to work with psModule release 9.0
  - moved model test functions into psphot as optional mode
  - added pmSourceFitSet : simultaneous model group fitting
  - added bicubic interpolation to tweak up the peak coordinates
  - added aperture residual analysis after complete object model & subtraction
  - added 3D (x,y,rflux) aperture residual fitting
  - added blend vs blob fitting (BlendFit)
  - added ensemble PSF fitting, with sparse matrix inversion
  - improved the flagging / marking of model results
  - better abstraction for setting fit parameters
  - various low-level fixes
  - added PSF output option
  - added break points
  - added more optional output formats
  - fixed FITS table output

  Things still to be added to psphot:

  - better initial background model (NxM median grid?)
  - include local background model in EnsemblePSF Fit (use sparse matrix)
  - 2nd pass (after object subtraction) to smooth and detect faint objects
  - re-add background to object-subtracted image
  - cleanup function names
  - push more functions into psLib / psModule
  - fix extended / galaxy models to improve stability
  - add mode with input PSF
  - add mode with input fixed sources (PS_SOURCE_FIXED)
  - cleanup memory leaks

2005.11.25

  I've updated psphot to work with the current psLib v8, though a
  number of psLib fixes were needed.  These are pushed under
  psLib:eam_rel8_b2.  The psphot code which works with that version of
  psLib is tagged psphot_dev_04.

  I'm working on converting psphot to work with the current release of
  psModules, which basically includes all of the object functions. 

  - change comments are relative to psModules (vs psphot versions)

  psEllipse.c : OK
  psEllipse.h : OK
  pmModelGroup.c : OK (missing TGAUSS entry)
  pmModelGroup.h : OK (adds many comments)

  pmPSFtry.c : a bunch of formatting weirdness (try-> got line breaks
	       added pmPSFtryMetric_Alt
	       fixed up usage of psVectorClipFitPolynomial1D  
	       fixed up usage of psPolynomial..Alloc  

  pmPSFtry.h : OK (Added extensive comments)

  pmPSF.c : fixed up usage of psPolynomial..Alloc

  pmPSF.h : OK (Added extensive comments)

  pmObjects.c : cleaned up some formatting,
		fixed usage of psImageCountPixelMask

  pmObjects.h : added apMag and fitMag to pmSource
		dropped PS_MODEL_name defines

  psLibUtils.[ch] should be dropped from psModules
  psModulesUtils.[ch] should be dropped from psModules

  Makefile.am : dropped psModulesUtils.[ch], psLibUtils.[ch]

  - I have successfully tested psphot with the psModules.v8 code
    (eam_rel8_b1 tag).  I only needed to make a few modes in the
    psModules code.  

2005.11.16

  I have made some fixes to make psphot work with pslib rel8_0.  I
  need to merge psphot with the rel8_0 version of the psMinimize and
  pmObjects code.  

2005.09.06

  I have built a working version of PSPhot using my own copy of the
  pmObjects.[ch] files.  I need to minimize the difference between the
  v0.7.0, v0.5.0, and my own version of pmObjects.c

  additions to psLib based on the new version:
  - extended the minimization to include parameter limits

  changes v0.5.0 / v0.7.0 / EAM
  - changed all ps* to pm*
  - fixed naming for local static functions (eg modelFree not p_psModelFree)
  - dropped all hard-coded model names (vs v0.7.0)
  - using current psMemSetDellocator name
  - added noise image to pmSource
  - converted old asserts to new asserts (PS_.._CHECK..)
  - add return from error in pmFindImagePeaks
  - allow isItInThisRegion to have NULL region (true)
  - fixed subImages to correspond to region definition (end is
    exclusive) in LocalSky and SetPixelCircle
  - dropped old, redundant code in pmSourceLocalSky
  - fixed pmSourceMoments use of mask (0 is valid, not 1)
  - added pmSourceMoments validity tests (numPixels, Sum, centroid shift)
  - added correction for Sxy (XY/Sum - x*y)
  - added pmSourcePSFClump function (and pmPSFClump structure)
  - allow missing sources in pmSourcePSFClump (not all peaks yield
    sources)
  - moved pmSourceRoughClass metadata lookups out of inner loop
  - added saturated pixel test using pmImageCountPixelMask
  - various redefinitions of initial classes
  - dropped old, redundant code in pmSourceSetPixelsCircle
  - mask image set to type psU8 (was psF32)
  - abstract object model functions for pmSourceModelGuess
  - converted evalModel to a public function psModelEval, modified params
  - pmSourceFitModel operates on a specified model
  - pmSourceFitModel had option to apply/ignore PSF information
  - pmSourceFitModel calculates yErr
  - pmSourceFitModel calculates the covariance matrix
  - added paramMask to pmSourceFitModel 
  - pmSourceFitModel_EAM uses covar to carry in beta and param
    limits...
  - pmSourceFitModel requires solution to stay within image
  - pmSourceFitModel calculates and saves chisq, nIter, nDOF
  - pmSourceFitModel uses GaussNewtonDelta for frozen params
  - added mask to pmSourceAdd, pmSourceSub
  - model abstractions in pmSourceAdd, pmSourceSub
  - fixed 'center' option in pmSourceAdd/Sub

  - pmPSF params should be F64

  lingering concerns:
  - Polynomials and related functions are STILL messed up.  this is a
    major priority!!!
  - pmSourceFitModel calculates sqrt(var), psMinimize calculates sq(sqrt(var))
  - does psImageAlloc zero the image?  if so, drop init routine
    from pmSourcePSFClump
  - pmSourceRoughClass uses RDNOISE, GAIN to calculate SN: should use
    the source->noise image? part of pmSourceMoments?
  - pmSourceMoments_EAM uses macro for checkRegion
  - pmObjects_EAM.c uses some hardcoded mask values (LocalSky)
  - why does LocalSky_EAM not need subImageMask->col0 = subImage->col0??
  - psGetRowVectorFromImage should be in psLib (in psLibUtils)
  - pmSourceSetPixelsCircle and pmSourceLocalSky probably could use
    the psImageMaskRegion, etc functions.
  - pmSourceSetPixelsCircle uses a hard-coded mask value
  - define a mask registration process??
  - pmSourceContour is using the model flux, not the image flux

2005.09.05

  I have a working version of PSPhot which handles PSF and galaxy
  models.  I am tagging the module with an alpha version number. this
  version compiles with psLib-0.5.0, at least my version of it.  My
  current goal is to make it work with the current psLib head (nearly
  0.7.0) with a mimimum of _EAM versions of functions.

  the tag for the working version is dev_01

2005.06.04

  progress on psphot has moved along well.  At this point, the process
  loads the image, finds the peaks, determines a best PSF model,
  identifies objects which are consistent with that model, and
  attempts to fit a galaxy model to the objects which are not
  consistent with the model. 

  a variety of minor issues remain, as well as some major issues. 

  - use a proper noise image to keep the fits honest after other
    objects have been subtracted.  

  - define the masks in terms of a single mask image.  this image
    could be provided initially by the user.   

  - add noise enhancement (couple with mask marking subtraction)

  - 

2005.04.12

- psPeak, psSource, etc: should be pmPeak, pmSource, etc
- pmCullPeaks: should be pmCullImagePeaks

- does pmSourceMoments need an image argument?

- psLibInit / p_psTimeInit

  we should not have to know about astronomy time concepts (ie, have a
  timeConfig file) in order to use the time functions for basic work.
  This means having a PS_TIME_UNIX which just works with the UNIX
  clock and avoids all initialization issues.

- psImageStats is much too slow for basic median
  - this function does a complete sort on all pixel values.  we need
  to use the histogram method (spec a different type of median)

- psImageStats, ROBUST_MEDIAN fails
- there are errors in psVectorStats for ROBUST MEAN, STDEV (& median?)
  * this is ill-defined.  revise the ADD: too sensitive to the
  binning, smoothing scales 

- pmFindImagePeaks is not finding any peaks:
  typo in interior row section: see bug 359
  after this fix: PASS

* p_psGetRowVectorFromImage : PASS
* psGetRowVectorFromImage : PASS 
- both have about the same time (~15 us +/- 5us) for 2048 pix on alala

* pmFindVectorPeaks : PASS (returned row data in data.U32)

- # include <string.h> : needed in psMetadata.c

* MyListAddPeak / pmPeakAlloc are inconsistent wrt col,row vs x,y

- why does psMetadataItemAllocV allocate a string of length
  MAX_STRING_LENGTH for the comment, then use strncpy?

  should be:

    // set metadata item comment
    if (comment == NULL) {
        // Per SDRS, null isn't allowed, must use "" instead
        metadataItem->comment = psStringCopy ("");
    } else {
        metadataItem->comment = psStringCopy (comment);
    }

psMetadataAdd -> psMetadataAddItem is all confused:
 - we end up with two psMetadataItemAlloc calls, when only one should
   be used
 - psMetadataItemAlloc was doing the wrong thing if the incoming data
   was NULL
 - I think the logic in this block is wrong as well.  

 * I fixed this in psMetadata.c

2005.04.14 : 

 - psImageStats is still much too slow

 - pmObjects : changed to using psArray to carry peaks / sources,
   rather than psList

 - added function pmPeaksSubset to replace pmCullPeaks

 - pmSourceLocalSky: added min/max fncs to force subimage to stay in
   image

 - Sx, Sy can go negative: have forced limit to 0,0

 - pmSourceRoughClass: implemented sigmaX, sigmaY search for stellar
   clump (uses pmComparePeakDescend)

   - the search ignores the 0,0 pixel

   - pmSourceRoughClass uses all detected peaks.  allow an exclusion
     for peak > max, peak < min?

   - need to push clump stats on the metadata

   - the source classes are assigned so they are mutually exclusive 

   - change PS_SOURCE_OTHER to STAR? 

 - pmSourceSetPixelCircle:

   - name should be pmSourceSetPixelsCircle (geometry could be an
     option...)

   - I cleaned the defined region to match the convensions of
     pmSourceLocalSky

   - truncate and force subimage to lie on image

   - CheckRadius2 seems like an inefficient coding

   - valid pixels have mask value of 1 (inverse of other funcs)

 - pmSourceFitModel:

   - num iterations is much too large

   - 

mrq:

 - allocate alpha, beta arrays
 - mrq2dcof (pars, alpha, beta)
 - make guess pars', alpha', beta'
 - mrq2dcof (pars', alpha', beta')
 - if (chisq < old chisq), keep new guess


2005.04.19:

- psMinimizeLMChi2 has some serious problems.  I re-wrote it starting
  from the mrqmin example in ohana.   after a variety little bugs, it
  seems to work quite well.  the program 'modeltest.c' runs two
  different gaussians through psMinimizeLMChi2, and gets the right
  answer quite quickly.  The first pass at the implementation had a
  variety of problems.  to avoid any worry about errors in the
  psMatrix code, I implemented psGaussJordan, basing the code on the
  elixir gaussj.c code.  this worked fine, and let me find the errors
  elsewhere in the code. the LUD version now works just the same as
  the GaussJ version.


2005.04.21

- psMinimizeLMChi2 does an excellent job now in most cases.  I am able
  to run pmSourceFitModel on the PSF stars quite well.  I added in the
  (nearly) correct errors (actually, just using sqrt(N), limiting to
  N>=1).  I see one problem object, which is quite faint, and does not
  converge well: I get very large values for x,y, Sx, Sy, etc.  I need
  to think about constraining these fits from running way off scale.

  fit:   0.123879 sec for 277 stars (gauss)
  fit:   0.155940 sec for 277 stars (pgauss) (!)
  fit:   0.153292 sec for 277 stars
  (0.5 msec per star)
