IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 18, 2009, 10:23:28 AM (17 years ago)
Author:
eugene
Message:

updated vysos branch from trunk

Location:
branches/eam_branches/20090820
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090820

  • branches/eam_branches/20090820/psModules/src/objects/pmPSFtryModel.c

    r25766 r25870  
    7070        psFree(psfTry);
    7171        return NULL;
    72     }     
    73 
    74     int orderMin = (options->psfTrendMode == PM_TREND_MAP) ? 1 : 0;
     72    }
     73
     74    // XXX set the min number of needed source more carefully (depends on psfTrendMode?)
    7575    int orderMax = PS_MAX (options->psfTrendNx, options->psfTrendNy);
    76 
    77     // XXX set the min number of needed source more carefully (depends on psfTrendMode?)
    7876    if ((sources->n < 15) && (orderMax >= 3)) orderMax = 2;
    7977    if ((sources->n < 11) && (orderMax >= 2)) orderMax = 1;
    8078    if ((sources->n <  8) && (orderMax >= 1)) orderMax = 0;
    8179    if ((sources->n <  3)) {
    82         psError (PS_ERR_UNKNOWN, true, "failed to determine PSF parameters");
    83         return NULL;
     80        psError (PS_ERR_UNKNOWN, true, "failed to determine PSF parameters");
     81        return NULL;
     82    }
     83
     84    int orderMin;
     85    if (options->psfTrendMode == PM_TREND_MAP) {
     86        orderMin = 1;
     87        orderMax = PS_MAX(orderMax, 1);
     88    } else {
     89        orderMin = 0;
    8490    }
    8591
     
    8793    psVector *srcMask = psVectorCopy (NULL, psfTry->mask, PS_TYPE_VECTOR_MASK);
    8894
    89     // we will save the PSF with the best fit (min systematic error) 
     95    // we will save the PSF with the best fit (min systematic error)
    9096    pmPSF *minPSF = NULL;
    9197    psVector *minMask = NULL;
     
    96102    int Ny = options->psfTrendNy;
    97103    for (int i = orderMin; i <= orderMax; i++) {
    98        
    99         if (Nx > Ny) {
    100             options->psfTrendNx = i;
    101             options->psfTrendNy = PS_MAX (orderMin, (int)(i * (Ny / Nx) + 0.5));
    102         } else {
    103             options->psfTrendNy = i;
    104             options->psfTrendNx = PS_MAX (orderMin, (int)(i * (Nx / Ny) + 0.5));
    105         }
    106 
    107         // free existing data, if any
    108         psFree(psfTry->psf);
    109         psFree(psfTry->mask);
    110 
    111         // allocate a mask and a psf model using the current Nx,Ny order values;
    112         psfTry->psf = pmPSFAlloc (options);
    113         psfTry->mask = psVectorCopy (NULL, srcMask, PS_TYPE_VECTOR_MASK);
    114 
    115         // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
    116         if (!pmPSFtryMakePSF (psfTry)) {
    117             psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
    118             psFree(psfTry);
    119             return NULL;
    120         }
    121 
    122         // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
    123         if (!pmPSFtryFitPSF (psfTry, options, maskVal, markVal)) {
    124             psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
    125             psFree(psfTry);
    126             return NULL;
    127         }
    128 
    129         // stage 4: measure systematic error in pmPSFtry->metric
    130         if (!pmPSFtryMetric (psfTry)) {
    131             psError(PS_ERR_UNKNOWN, false, "failed to measure systematic error of metric");
    132             psFree(psfTry);
    133             return NULL;
    134         }
    135 
    136         if (!minPSF) {
    137             minPSF = psMemIncrRefCounter(psfTry->psf);
    138             minMask = psMemIncrRefCounter(psfTry->mask);
    139         }
    140 
    141         if (psfTry->psf->dApResid < minPSF->dApResid) {
    142             psFree (minPSF);
    143             psFree (minMask);
    144             minPSF = psMemIncrRefCounter(psfTry->psf);
    145             minMask = psMemIncrRefCounter(psfTry->mask);
    146         }
     104
     105        if (Nx > Ny) {
     106            options->psfTrendNx = i;
     107            options->psfTrendNy = PS_MAX (orderMin, (int)(i * (Ny / Nx) + 0.5));
     108        } else {
     109            options->psfTrendNy = i;
     110            options->psfTrendNx = PS_MAX (orderMin, (int)(i * (Nx / Ny) + 0.5));
     111        }
     112
     113        // free existing data, if any
     114        psFree(psfTry->psf);
     115        psFree(psfTry->mask);
     116
     117        // allocate a mask and a psf model using the current Nx,Ny order values;
     118        psfTry->psf = pmPSFAlloc (options);
     119        psfTry->mask = psVectorCopy (NULL, srcMask, PS_TYPE_VECTOR_MASK);
     120
     121        // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
     122        if (!pmPSFtryMakePSF (psfTry)) {
     123            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
     124            psFree(psfTry);
     125            return NULL;
     126        }
     127
     128        // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
     129        if (!pmPSFtryFitPSF (psfTry, options, maskVal, markVal)) {
     130            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
     131            psFree(psfTry);
     132            return NULL;
     133        }
     134
     135        // stage 4: measure systematic error in pmPSFtry->metric
     136        if (!pmPSFtryMetric (psfTry)) {
     137            psError(PS_ERR_UNKNOWN, false, "failed to measure systematic error of metric");
     138            psFree(psfTry);
     139            return NULL;
     140        }
     141
     142        if (!minPSF) {
     143            minPSF = psMemIncrRefCounter(psfTry->psf);
     144            minMask = psMemIncrRefCounter(psfTry->mask);
     145        }
     146
     147        if (psfTry->psf->dApResid < minPSF->dApResid) {
     148            psFree (minPSF);
     149            psFree (minMask);
     150            minPSF = psMemIncrRefCounter(psfTry->psf);
     151            minMask = psMemIncrRefCounter(psfTry->mask);
     152        }
    147153    }
    148154    psFree (srcMask);
     
    153159    psfTry->psf = minPSF;
    154160    psfTry->mask = minMask;
    155    
     161
    156162    // XXXXX this is probably not used any more.  Are the chisq of the fits so bad? can we
    157163    // fix them by softening the errors on the brightest pixels?
Note: See TracChangeset for help on using the changeset viewer.