IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 9, 2009, 9:29:40 AM (17 years ago)
Author:
Paul Price
Message:

Don't allow orderMin to be greater than orderMax.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmPSFtryModel.c

    r25754 r25818  
    7070        psFree(psfTry);
    7171        return NULL;
    72     }     
     72    }
    7373
    7474    int orderMin = (options->psfTrendMode == PM_TREND_MAP) ? 1 : 0;
     
    8080    if ((sources->n <  8) && (orderMax >= 1)) orderMax = 0;
    8181    if ((sources->n <  3)) {
    82         psError (PS_ERR_UNKNOWN, true, "failed to determine PSF parameters");
    83         return NULL;
    84     }
     82        psError (PS_ERR_UNKNOWN, true, "failed to determine PSF parameters");
     83        return NULL;
     84    }
     85    orderMin = PS_MIN(orderMin, orderMax);
    8586
    8687    // save the raw source mask (generated by pmPSFtryFitEXT)
    8788    psVector *srcMask = psVectorCopy (NULL, psfTry->mask, PS_TYPE_VECTOR_MASK);
    8889
    89     // we will save the PSF with the best fit (min systematic error) 
     90    // we will save the PSF with the best fit (min systematic error)
    9091    pmPSF *minPSF = NULL;
    9192    psVector *minMask = NULL;
     
    9697    int Ny = options->psfTrendNy;
    9798    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         }
     99
     100        if (Nx > Ny) {
     101            options->psfTrendNx = i;
     102            options->psfTrendNy = PS_MAX (orderMin, (int)(i * (Ny / Nx) + 0.5));
     103        } else {
     104            options->psfTrendNy = i;
     105            options->psfTrendNx = PS_MAX (orderMin, (int)(i * (Nx / Ny) + 0.5));
     106        }
     107
     108        // free existing data, if any
     109        psFree(psfTry->psf);
     110        psFree(psfTry->mask);
     111
     112        // allocate a mask and a psf model using the current Nx,Ny order values;
     113        psfTry->psf = pmPSFAlloc (options);
     114        psfTry->mask = psVectorCopy (NULL, srcMask, PS_TYPE_VECTOR_MASK);
     115
     116        // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
     117        if (!pmPSFtryMakePSF (psfTry)) {
     118            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
     119            psFree(psfTry);
     120            return NULL;
     121        }
     122
     123        // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
     124        if (!pmPSFtryFitPSF (psfTry, options, maskVal, markVal)) {
     125            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
     126            psFree(psfTry);
     127            return NULL;
     128        }
     129
     130        // stage 4: measure systematic error in pmPSFtry->metric
     131        if (!pmPSFtryMetric (psfTry)) {
     132            psError(PS_ERR_UNKNOWN, false, "failed to measure systematic error of metric");
     133            psFree(psfTry);
     134            return NULL;
     135        }
     136
     137        if (!minPSF) {
     138            minPSF = psMemIncrRefCounter(psfTry->psf);
     139            minMask = psMemIncrRefCounter(psfTry->mask);
     140        }
     141
     142        if (psfTry->psf->dApResid < minPSF->dApResid) {
     143            psFree (minPSF);
     144            psFree (minMask);
     145            minPSF = psMemIncrRefCounter(psfTry->psf);
     146            minMask = psMemIncrRefCounter(psfTry->mask);
     147        }
    147148    }
    148149    psFree (srcMask);
     
    153154    psfTry->psf = minPSF;
    154155    psfTry->mask = minMask;
    155    
     156
    156157    // XXXXX this is probably not used any more.  Are the chisq of the fits so bad? can we
    157158    // fix them by softening the errors on the brightest pixels?
Note: See TracChangeset for help on using the changeset viewer.