IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28484 for branches/pap/psphot


Ignore:
Timestamp:
Jun 24, 2010, 2:59:09 PM (16 years ago)
Author:
Paul Price
Message:

Merging trunk in advance of reintegrating into trunk.

Location:
branches/pap
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/psphot

  • branches/pap/psphot/src/psphotApResid.c

    r28013 r28484  
    2222    // loop over the available readouts
    2323    for (int i = 0; i < num; i++) {
    24         if (i == chisqNum) continue; // skip chisq image
    25         if (!psphotApResidReadout (config, view, filerule, i, recipe)) {
     24        if (i == chisqNum) continue; // skip chisq image
     25        if (!psphotApResidReadout (config, view, filerule, i, recipe)) {
    2626            psError (PSPHOT_ERR_CONFIG, false, "failed to measure aperture residual for %s entry %d", filerule, i);
    27             return false;
    28         }
     27            return false;
     28        }
    2929    }
    3030    return true;
     
    5656
    5757    if (!sources->n) {
    58         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping ap resid");
    59         return true;
     58        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping ap resid");
     59        return true;
    6060    }
    6161
     
    6666    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
    6767    if (!status) {
    68         nThreads = 0;
     68        nThreads = 0;
    6969    }
    7070
     
    128128    for (int i = 0; i < cellGroups->n; i++) {
    129129
    130         psArray *cells = cellGroups->data[i];
    131 
    132         for (int j = 0; j < cells->n; j++) {
    133 
    134             // allocate a job -- if threads are not defined, this just runs the job
    135             psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS");
    136 
    137             psArrayAdd(job->args, 1, cells->data[j]); // sources
    138             psArrayAdd(job->args, 1, psf);
    139             PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
    140             PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    141             PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
    142 
    143             PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nskip
    144             PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nfail
    145 
    146             if (!psThreadJobAddPending(job)) {
    147                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    148                 psFree (job);
    149                 return false;
    150             }
    151             psFree(job);
    152         }
    153 
    154         // wait for the threads to finish and manage results
    155         if (!psThreadPoolWait (false)) {
    156             psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    157             return false;
    158         }
    159 
    160         // we have only supplied one type of job, so we can assume the types here
    161         psThreadJob *job = NULL;
    162         while ((job = psThreadJobGetDone()) != NULL) {
    163             if (job->args->n < 1) {
    164                 fprintf (stderr, "error with job\n");
    165             } else {
    166                 psScalar *scalar = NULL;
    167                 scalar = job->args->data[5];
    168                 Nskip += scalar->data.S32;
    169                 scalar = job->args->data[6];
    170                 Nfail += scalar->data.S32;
    171             }
    172             psFree(job);
    173         }
     130        psArray *cells = cellGroups->data[i];
     131
     132        for (int j = 0; j < cells->n; j++) {
     133
     134            // allocate a job -- if threads are not defined, this just runs the job
     135            psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS");
     136
     137            psArrayAdd(job->args, 1, cells->data[j]); // sources
     138            psArrayAdd(job->args, 1, psf);
     139            PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
     140            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     141            PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
     142
     143            PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nskip
     144            PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nfail
     145
     146            if (!psThreadJobAddPending(job)) {
     147                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     148                return false;
     149            }
     150        }
     151
     152        // wait for the threads to finish and manage results
     153        if (!psThreadPoolWait (false)) {
     154            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     155            return false;
     156        }
     157
     158        // we have only supplied one type of job, so we can assume the types here
     159        psThreadJob *job = NULL;
     160        while ((job = psThreadJobGetDone()) != NULL) {
     161            if (job->args->n < 1) {
     162                fprintf (stderr, "error with job\n");
     163            } else {
     164                psScalar *scalar = NULL;
     165                scalar = job->args->data[5];
     166                Nskip += scalar->data.S32;
     167                scalar = job->args->data[6];
     168                Nfail += scalar->data.S32;
     169            }
     170            psFree(job);
     171        }
    174172    }
    175173
     
    184182    Npsf = 0;
    185183
    186 # ifdef DEBUG   
     184# ifdef DEBUG
    187185    FILE *f = fopen ("apresid.dat", "w");
    188186    psAssert (f, "failed open");
     
    199197        if (source->mode &  PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR");
    200198
    201         if (source->mode &  PM_SOURCE_MODE_EXT_LIMIT) SKIPSTAR ("EXTENDED");
    202         if (source->mode &  PM_SOURCE_MODE_CR_LIMIT) SKIPSTAR ("COSMIC RAY");
    203         if (source->mode &  PM_SOURCE_MODE_DEFECT) SKIPSTAR ("DEFECT");
    204            
     199        if (source->mode &  PM_SOURCE_MODE_EXT_LIMIT) SKIPSTAR ("EXTENDED");
     200        if (source->mode &  PM_SOURCE_MODE_CR_LIMIT) SKIPSTAR ("COSMIC RAY");
     201        if (source->mode &  PM_SOURCE_MODE_DEFECT) SKIPSTAR ("DEFECT");
     202
    205203        if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {
    206204            continue;
    207205        }
    208206
    209         // XXX make this user-configurable?
    210         if (source->errMag > 0.01) continue;
     207        // XXX make this user-configurable?
     208        if (source->errMag > 0.01) continue;
    211209
    212210        // aperture residual for this source
     
    221219
    222220# ifdef DEBUG
    223         fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f\n",
    224                  source->peak->xf, source->peak->yf,
    225                  source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS],
    226                 source->psfMag, source->apMag, source->errMag,
    227                  source->modelPSF->params->data.F32[PM_PAR_I0],
    228                  source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], source->modelPSF->params->data.F32[PM_PAR_SYY],
    229                 source->modelPSF->params->data.F32[PM_PAR_7]);
     221        fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f\n",
     222                 source->peak->xf, source->peak->yf,
     223                 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS],
     224                source->psfMag, source->apMag, source->errMag,
     225                 source->modelPSF->params->data.F32[PM_PAR_I0],
     226                 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], source->modelPSF->params->data.F32[PM_PAR_SYY],
     227                source->modelPSF->params->data.F32[PM_PAR_7]);
    230228# endif
    231         if (!isfinite(source->psfMag)) psAbort ("nan in psfMag");
    232         if (!isfinite(source->errMag)) psAbort ("nan in errMag");
    233         if (!isfinite(source->apMag)) psAbort ("nan in apMag");
    234         if (!isfinite(model->params->data.F32[PM_PAR_XPOS])) psAbort ("nan in xPos");
    235         if (!isfinite(model->params->data.F32[PM_PAR_YPOS])) psAbort ("nan in yPos");
     229        if (!isfinite(source->psfMag)) psAbort ("nan in psfMag");
     230        if (!isfinite(source->errMag)) psAbort ("nan in errMag");
     231        if (!isfinite(source->apMag)) psAbort ("nan in apMag");
     232        if (!isfinite(model->params->data.F32[PM_PAR_XPOS])) psAbort ("nan in xPos");
     233        if (!isfinite(model->params->data.F32[PM_PAR_YPOS])) psAbort ("nan in yPos");
    236234
    237235        psVectorAppend (mag, source->psfMag);
     
    253251    if (Npsf < APTREND_NSTAR_MIN) {
    254252        psWarning("Only %d valid aperture residual sources (need %d), giving up", Npsf, APTREND_NSTAR_MIN);
    255         goto escape;
    256     }
    257 
    258     // this is a bit tricky, because we have two cases (MAP vs POLY), and they have a different 
    259     // definition for 'order' (order_MAP = order_POLY + 1).  in addition, we have a 
     253        goto escape;
     254    }
     255
     256    // this is a bit tricky, because we have two cases (MAP vs POLY), and they have a different
     257    // definition for 'order' (order_MAP = order_POLY + 1).  in addition, we have a
    260258    // user-specified MAX order, which we should respect, regardless of the mode
    261259
     
    270268    pmTrend2DMode mode = PM_TREND_MAP;
    271269    if (mode == PM_TREND_MAP) {
    272         MaxOrderForStars ++;
    273     } 
     270        MaxOrderForStars ++;
     271    }
    274272    APTREND_ORDER_MAX = PS_MIN (APTREND_ORDER_MAX, MaxOrderForStars);
    275273
     
    283281    int NY = readout->image->numRows;
    284282    for (int i = 1; i <= APTREND_ORDER_MAX; i++) {
    285        
    286         int Nx, Ny;
    287         if (NX > NY) {
    288             Nx = i;
    289             Ny = PS_MAX (1, (int)(i * (NY / (float)(NX)) + 0.5));
    290         } else {
    291             Ny = i;
    292             Nx = PS_MAX (1, (int)(i * (NX / (float)(NY)) + 0.5));
    293         }
    294 
    295         float errorFloor;
     283
     284        int Nx, Ny;
     285        if (NX > NY) {
     286            Nx = i;
     287            Ny = PS_MAX (1, (int)(i * (NY / (float)(NX)) + 0.5));
     288        } else {
     289            Ny = i;
     290            Nx = PS_MAX (1, (int)(i * (NX / (float)(NY)) + 0.5));
     291        }
     292
     293        float errorFloor;
    296294        pmTrend2D *apTrend = psphotApResidTrend (&errorFloor, readout, Nx, Ny, xPos, yPos, apResid, dMag);
    297         if (!apTrend) {
    298             continue;
    299         }
    300 
    301         // apply ApTrend results
    302         // float xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5;
    303         // float yc = 0.5*readout->image->numRows + readout->image->row0 + 0.5;
    304         // float ApResid = pmTrend2DEval (psf->ApTrend, xc, yc); // ap-fit at chip center
    305         // if (!isfinite(ApResid)) psAbort("nan apresid @ center");
     295        if (!apTrend) {
     296            continue;
     297        }
     298
     299        // apply ApTrend results
     300        // float xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5;
     301        // float yc = 0.5*readout->image->numRows + readout->image->row0 + 0.5;
     302        // float ApResid = pmTrend2DEval (psf->ApTrend, xc, yc); // ap-fit at chip center
     303        // if (!isfinite(ApResid)) psAbort("nan apresid @ center");
    306304
    307305        // store the minimum errorFloor and best ApTrend to keep
    308306        if (errorFloor < errorFloorMin) {
    309307            errorFloorMin = errorFloor;
    310             psFree (psf->ApTrend);
    311             psf->ApTrend = psMemIncrRefCounter(apTrend);
    312         }
    313         psFree (apTrend);
     308            psFree (psf->ApTrend);
     309            psf->ApTrend = psMemIncrRefCounter(apTrend);
     310        }
     311        psFree (apTrend);
    314312    }
    315313    if (psf->ApTrend == NULL) {
    316314        psWarning("Failed to find a valid aperture residual value");
    317         goto escape;
     315        goto escape;
    318316    }
    319317
     
    383381    if (!pmTrend2DFit (apTrend, mask, 0xff, xPos, yPos, apResid, dMagSoft)) {
    384382        psWarning("Failed to fit trend for %d x %d map", Nx, Ny);
    385         psFree (apTrend);
    386         return NULL;
     383        psFree (apTrend);
     384        return NULL;
    387385    }
    388386    if (apTrend->mode == PM_TREND_MAP) {
    389         // p_psImagePrint (2, apTrend->map->map, "ApTrend Before"); // XXX TEST:
    390         psImageMapRepair (apTrend->map->map);
    391         // p_psImagePrint (2, apTrend->map->map, "ApTrend After"); // XXX TEST:
     387        // p_psImagePrint (2, apTrend->map->map, "ApTrend Before"); // XXX TEST:
     388        psImageMapRepair (apTrend->map->map);
     389        // p_psImagePrint (2, apTrend->map->map, "ApTrend After"); // XXX TEST:
    392390    }
    393391
     
    400398    if (!isfinite(*apResidSysErr)) {
    401399        psWarning("Failed to find systematic error for %d x %d map", Nx, Ny);
    402         psFree (apTrend);
    403         return NULL;
     400        psFree (apTrend);
     401        return NULL;
    404402    }
    405403
     
    408406
    409407    if (psTraceGetLevel("psphot") >= 4) {
    410         char filename[64];
    411         snprintf (filename, 64, "apresid.%dx%d.dat", Nx, Ny);
     408        char filename[64];
     409        snprintf (filename, 64, "apresid.%dx%d.dat", Nx, Ny);
    412410        FILE *dumpFile = fopen (filename, "w");
    413411        for (int i = 0; i < xPos->n; i++) {
     
    457455        }
    458456
    459         // clear the mask bit and set the circular mask pixels
    460         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    461         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
    462 
    463         bool status = pmSourceMagnitudes (source, psf, photMode, maskVal);
    464 
    465         // clear the mask bit
    466         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
     457        // clear the mask bit and set the circular mask pixels
     458        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
     459        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
     460
     461        bool status = pmSourceMagnitudes (source, psf, photMode, maskVal);
     462
     463        // clear the mask bit
     464        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    467465
    468466        // re-subtract the object, leave local sky
    469467        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    470468
    471         if (!status) {
    472             Nskip ++;
    473             psTrace ("psphot", 3, "skip : bad source mag");
    474             continue;
    475         }
    476    
    477         if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {
    478             Nfail ++;
    479             psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);
    480             continue;
    481         }
    482         source->mode |= PM_SOURCE_MODE_AP_MAGS;
     469        if (!status) {
     470            Nskip ++;
     471            psTrace ("psphot", 3, "skip : bad source mag");
     472            continue;
     473        }
     474
     475        if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {
     476            Nfail ++;
     477            psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);
     478            continue;
     479        }
     480        source->mode |= PM_SOURCE_MODE_AP_MAGS;
    483481    }
    484482
  • branches/pap/psphot/src/psphotBlendFit.c

    r28013 r28484  
    1515    // loop over the available readouts
    1616    for (int i = 0; i < num; i++) {
    17         if (!psphotBlendFitReadout (config, view, filerule, i, recipe)) {
     17        if (!psphotBlendFitReadout (config, view, filerule, i, recipe)) {
    1818            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (non-linear) for %s entry %d", filerule, i);
    19             return false;
    20         }
     19            return false;
     20        }
    2121    }
    2222    return true;
     
    4848
    4949    if (!sources->n) {
    50         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend fit");
    51         return true;
     50        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend fit");
     51        return true;
    5252    }
    5353
     
    8787    sources = psArraySort (sources, pmSourceSortBySN);
    8888    if (!sources->n) {
    89         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
    90         return true;
     89        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
     90        return true;
    9191    }
    9292
     
    103103        for (int j = 0; j < cells->n; j++) {
    104104
    105             // allocate a job -- if threads are not defined, this just runs the job
    106             psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT");
    107             psArray *newSources = psArrayAllocEmpty(16);
    108 
    109             psArrayAdd(job->args, 1, readout);
    110             psArrayAdd(job->args, 1, recipe);
    111             psArrayAdd(job->args, 1, cells->data[j]); // sources
    112             psArrayAdd(job->args, 1, psf);
    113             psArrayAdd(job->args, 1, newSources); // return for new sources
    114             psFree (newSources);
    115 
    116             PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit
    117             PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf
    118             PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next
    119             PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
    120 
    121             if (!psThreadJobAddPending(job)) {
    122                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    123                 psFree (job);
    124                 return NULL;
    125             }
    126             psFree(job);
     105            // allocate a job -- if threads are not defined, this just runs the job
     106            psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT");
     107            psArray *newSources = psArrayAllocEmpty(16);
     108
     109            psArrayAdd(job->args, 1, readout);
     110            psArrayAdd(job->args, 1, recipe);
     111            psArrayAdd(job->args, 1, cells->data[j]); // sources
     112            psArrayAdd(job->args, 1, psf);
     113            psArrayAdd(job->args, 1, newSources); // return for new sources
     114            psFree (newSources);
     115
     116            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit
     117            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf
     118            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next
     119            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
     120
     121            if (!psThreadJobAddPending(job)) {
     122                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     123                return NULL;
     124            }
    127125
    128126# if (0)
     
    152150        }
    153151
    154         // wait for the threads to finish and manage results
    155         if (!psThreadPoolWait (false)) {
    156             psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    157             return NULL;
    158         }
    159 
    160         // we have only supplied one type of job, so we can assume the types here
    161         psThreadJob *job = NULL;
    162         while ((job = psThreadJobGetDone()) != NULL) {
    163             if (job->args->n < 1) {
    164                 fprintf (stderr, "error with job\n");
    165             } else {
    166                 psScalar *scalar = NULL;
    167                 scalar = job->args->data[5];
    168                 Nfit += scalar->data.S32;
    169                 scalar = job->args->data[6];
    170                 Npsf += scalar->data.S32;
    171                 scalar = job->args->data[7];
    172                 Next += scalar->data.S32;
    173                 scalar = job->args->data[8];
    174                 Nfail += scalar->data.S32;
    175 
    176                 // add these back onto sources
    177                 psArray *newSources = job->args->data[4];
    178                 for (int j = 0; j < newSources->n; j++) {
    179                     psArrayAdd (sources, 16, newSources->data[j]);
    180                 }
    181             }
    182             psFree(job);
     152        // wait for the threads to finish and manage results
     153        if (!psThreadPoolWait (false)) {
     154            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     155            return NULL;
     156        }
     157
     158        // we have only supplied one type of job, so we can assume the types here
     159        psThreadJob *job = NULL;
     160        while ((job = psThreadJobGetDone()) != NULL) {
     161            if (job->args->n < 1) {
     162                fprintf (stderr, "error with job\n");
     163            } else {
     164                psScalar *scalar = NULL;
     165                scalar = job->args->data[5];
     166                Nfit += scalar->data.S32;
     167                scalar = job->args->data[6];
     168                Npsf += scalar->data.S32;
     169                scalar = job->args->data[7];
     170                Next += scalar->data.S32;
     171                scalar = job->args->data[8];
     172                Nfail += scalar->data.S32;
     173
     174                // add these back onto sources
     175                psArray *newSources = job->args->data[4];
     176                for (int j = 0; j < newSources->n; j++) {
     177                    psArrayAdd (sources, 16, newSources->data[j]);
     178                }
     179            }
     180            psFree(job);
    183181            }
    184182    }
     
    278276                psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
    279277                Next ++;
    280                 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     278                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    281279                continue;
    282280            }
     
    286284                psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
    287285                Npsf ++;
    288                 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     286                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    289287                continue;
    290288            }
  • branches/pap/psphot/src/psphotFitSourcesLinear.c

    r28013 r28484  
    2727    for (int i = 0; i < num; i++) {
    2828
    29         // find the currently selected readout
    30         pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
    31         psAssert (file, "missing file?");
    32 
    33         pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    34         psAssert (readout, "missing readout?");
    35 
    36         pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    37         psAssert (detections, "missing detections?");
    38 
    39         psArray *sources = detections->allSources;
    40         psAssert (sources, "missing sources?");
    41 
    42         pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    43         psAssert (psf, "missing psf?");
    44 
    45         if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final)) {
     29        // find the currently selected readout
     30        pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
     31        psAssert (file, "missing file?");
     32
     33        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     34        psAssert (readout, "missing readout?");
     35
     36        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     37        psAssert (detections, "missing detections?");
     38
     39        psArray *sources = detections->allSources;
     40        psAssert (sources, "missing sources?");
     41
     42        pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     43        psAssert (psf, "missing psf?");
     44
     45        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final)) {
    4646            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i);
    47             return false;
    48         }
     47            return false;
     48        }
    4949    }
    5050    return true;
     
    5959
    6060    if (!sources->n) {
    61         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping linear fit");
    62         return true;
     61        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping linear fit");
     62        return true;
    6363    }
    6464
     
    150150
    151151    if (fitSources->n == 0) {
     152        psFree(fitSources);
    152153        return true;
    153154    }
     
    170171
    171172        // diagonal elements of the sparse matrix (auto-cross-product)
    172         f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     173        f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
    173174        psSparseMatrixElement (sparse, i, i, f);
    174175
    175176        // the formal error depends on the weighting scheme
    176177        if (CONSTANT_PHOTOMETRIC_WEIGHTS) {
    177             float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor);
     178            float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor, maskVal);
    178179            errors->data.F32[i] = 1.0 / sqrt(var);
    179180        } else {
     
    183184
    184185        // find the image x model value
    185         f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     186        f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
    186187        psSparseVectorElement (sparse, i, f);
    187188
     
    189190        switch (SKY_FIT_ORDER) {
    190191          case 1:
    191             f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     192            f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
    192193            psSparseBorderElementB (border, i, 1, f);
    193             f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     194            f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
    194195            psSparseBorderElementB (border, i, 2, f);
    195196
    196197          case 0:
    197             f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     198            f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
    198199            psSparseBorderElementB (border, i, 0, f);
    199200            break;
     
    215216
    216217            // got an overlap; calculate cross-product and add to output array
    217             f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     218            f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
    218219            psSparseMatrixElement (sparse, j, i, f);
    219220        }
  • branches/pap/psphot/src/psphotFitSourcesLinearStack.c

    r28013 r28484  
    4343    for (int i = 0; i < objects->n; i++) {
    4444        pmPhotObj *object = objects->data[i];
    45         if (!object) continue;
    46         if (!object->sources) continue;
     45        if (!object) continue;
     46        if (!object->sources) continue;
    4747
    48         // XXX check an element of the group to see if we should use it
    49         // if (!object->flags & PM_PHOT_OBJ_BAD) continue;
     48        // XXX check an element of the group to see if we should use it
     49        // if (!object->flags & PM_PHOT_OBJ_BAD) continue;
    5050
    51         for (int j = 0; j < object->sources->n; j++) {
    52           pmSource *source = object->sources->data[j];
    53           if (!source) continue;
     51        for (int j = 0; j < object->sources->n; j++) {
     52          pmSource *source = object->sources->data[j];
     53          if (!source) continue;
    5454
    55           // turn this bit off and turn it on again if we keep this source
    56           source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT;
     55          // turn this bit off and turn it on again if we keep this source
     56          source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT;
    5757
    58           // generate model for sources without, or skip if we can't
    59           if (!source->modelFlux) {
     58          // generate model for sources without, or skip if we can't
     59          if (!source->modelFlux) {
    6060            if (!pmSourceCacheModel (source, maskVal)) continue;
    61           }
     61          }
    6262
    63           source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
    64           psArrayAdd (fitSources, 100, source);
    65         }
     63          source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
     64          psArrayAdd (fitSources, 100, source);
     65        }
    6666    }
    6767    psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), objects->n);
     
    8585
    8686        // diagonal elements of the sparse matrix (auto-cross-product)
    87         f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR);
     87        f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR, maskVal);
    8888        psSparseMatrixElement (sparse, i, i, f);
    8989
    9090        // the formal error depends on the weighting scheme
    9191        if (CONSTANT_PHOTOMETRIC_WEIGHTS) {
    92             float var = pmSourceModelDotModel (SRCi, SRCi, false, COVAR_FACTOR);
     92            float var = pmSourceModelDotModel (SRCi, SRCi, false, COVAR_FACTOR, maskVal);
    9393            errors->data.F32[i] = 1.0 / sqrt(var);
    9494        } else {
     
    9797
    9898        // find the image x model value
    99         f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR);
     99        f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR, maskVal);
    100100        psSparseVectorElement (sparse, i, f);
    101101
     
    104104            pmSource *SRCj = fitSources->data[j];
    105105
    106             // we only need to generate dot terms for source on the same image
    107             if (SRCj->imageID != SRCi->imageID) { continue; }
     106            // we only need to generate dot terms for source on the same image
     107            if (SRCj->imageID != SRCi->imageID) { continue; }
    108108
    109109            // skip over disjoint source images, break after last possible overlap
     
    114114
    115115            // got an overlap; calculate cross-product and add to output array
    116             f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR);
     116            f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR, maskVal);
    117117            psSparseMatrixElement (sparse, j, i, f);
    118118        }
  • branches/pap/psphot/src/psphotGuessModels.c

    r28013 r28484  
    2121    // loop over the available readouts
    2222    for (int i = 0; i < num; i++) {
    23         if (i == chisqNum) continue; // skip chisq image
     23        if (i == chisqNum) continue; // skip chisq image
    2424        if (!psphotGuessModelsReadout (config, view, filerule, i)) {
    2525            psError (PSPHOT_ERR_CONFIG, false, "failed on to guess models for %s entry %d", filerule, i);
     
    106106            if (!psThreadJobAddPending(job)) {
    107107                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    108                 psFree (job);
    109108                return false;
    110109            }
    111             psFree(job);
    112110        }
    113111
  • branches/pap/psphot/src/psphotImageLoop.c

    r27657 r28484  
    4646        if (!psphotMosaicChip(config, view, "PSPHOT.INPUT", "PSPHOT.LOAD")) ESCAPE ("Unable to mosaic chip.");
    4747
     48        // Read WCS if easy.
     49        // XXX Since we're mosaicking cells, we ignore the case where the WCS is defined for a cell.
     50        {
     51            pmChip *inChip = pmFPAviewThisChip(view, input->fpa); // Mosaicked chip
     52            pmHDU *hduLow = pmHDUGetLowest(input->fpa, inChip, NULL);
     53            if (hduLow && !pmAstromReadWCS(input->fpa, inChip, hduLow->header, 1.0)) {
     54                psWarning("Unable to read WCS astrometry from header.");
     55                psErrorClear();
     56                pmHDU *hduHigh = pmHDUGetHighest(input->fpa, inChip, NULL);
     57                if (hduHigh && hduHigh != hduLow &&
     58                    !pmAstromReadWCS(input->fpa, chip, hduHigh->header, 1.0)) {
     59                    psWarning("Unable to read WCS astrometry from primary header.");
     60                    psErrorClear();
     61                }
     62            }
     63        }
     64
    4865        // try to load other supporting data (PSF, SRC, etc).
    4966        // do not re-load the following three files
     
    6784
    6885                // Update the header
    69                 pmHDU *hdu = pmHDUGetHighest(input->fpa, chip, cell);
    70                 if (hdu && hdu != lastHDU) {
    71                     psphotVersionHeaderFull(hdu->header);
    72                     lastHDU = hdu;
     86                {
     87                    pmHDU *hdu = pmHDUGetHighest(input->fpa, chip, cell);
     88                    if (hdu && hdu != lastHDU) {
     89                        psphotVersionHeaderFull(hdu->header);
     90                        lastHDU = hdu;
     91                    }
    7392                }
    7493
    75                 // if an external mask is supplied, ensure that NAN pixels are also masked
    76                 if (readout->mask) {
    77                     psImageMaskType maskSat = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
    78                     if (!pmReadoutMaskNonfinite(readout, maskSat)) {
    79                         psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels.");
    80                         psFree(view);
    81                         return false;
    82                     }
    83                 }
     94                // if an external mask is supplied, ensure that NAN pixels are also masked
     95                if (readout->mask) {
     96                    psImageMaskType maskSat = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
     97                    if (!pmReadoutMaskNonfinite(readout, maskSat)) {
     98                        psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels.");
     99                        psFree(view);
     100                        return false;
     101                    }
     102                }
    84103
    85104                // run the actual photometry analysis on this chip/cell/readout
     
    91110            }
    92111
    93             // drop all versions of the internal files
    94             status = true;
    95             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
    96             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
    97             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");
    98             if (!status) {
    99                 psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files");
    100                 psFree (view);
    101                 return false;
    102             }
     112            // drop all versions of the internal files
     113            status = true;
     114            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
     115            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
     116            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");
     117            if (!status) {
     118                psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files");
     119                psFree (view);
     120                return false;
     121            }
    103122        }
    104123        // save output which is saved at the chip level
  • branches/pap/psphot/src/psphotMagnitudes.c

    r28098 r28484  
    1818    // loop over the available readouts
    1919    for (int i = 0; i < num; i++) {
    20         if (i == chisqNum) continue; // skip chisq image
    21 
    22         // find the currently selected readout
    23         pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
    24         psAssert (file, "missing file?");
    25 
    26         pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    27         psAssert (readout, "missing readout?");
    28 
    29         pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    30         psAssert (detections, "missing detections?");
    31 
    32         psArray *sources = detections->allSources;
    33         psAssert (sources, "missing sources?");
    34 
    35         pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    36         psAssert (psf, "missing psf?");
    37 
    38         if (!psphotMagnitudesReadout (config, recipe, view, readout, sources, psf)) {
     20        if (i == chisqNum) continue; // skip chisq image
     21
     22        // find the currently selected readout
     23        pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
     24        psAssert (file, "missing file?");
     25
     26        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     27        psAssert (readout, "missing readout?");
     28
     29        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     30        psAssert (detections, "missing detections?");
     31
     32        psArray *sources = detections->allSources;
     33        psAssert (sources, "missing sources?");
     34
     35        pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     36        psAssert (psf, "missing psf?");
     37
     38        if (!psphotMagnitudesReadout (config, recipe, view, readout, sources, psf)) {
    3939            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i);
    40             return false;
    41         }
     40            return false;
     41        }
    4242    }
    4343    return true;
     
    5050
    5151    if (!sources->n) {
    52         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source magnitudes");
    53         return true;
    54     }
    55        
     52        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source magnitudes");
     53        return true;
     54    }
     55
    5656    psTimerStart ("psphot.mags");
    5757
     
    122122            if (!psThreadJobAddPending(job)) {
    123123                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    124                 psFree (job);
    125124                return false;
    126125            }
    127             psFree(job);
    128126
    129127# if (0)
     
    184182        }
    185183
    186         // clear the mask bit and set the circular mask pixels
    187         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    188         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
     184        // clear the mask bit and set the circular mask pixels
     185        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
     186        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
    189187
    190188        status = pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal
    191189        if (status && isfinite(source->apMag)) Nap ++;
    192190
    193         // clear the mask bit
    194         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
     191        // clear the mask bit
     192        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    195193
    196194        // re-subtract the object, leave local sky
     
    273271            if (!psThreadJobAddPending(job)) {
    274272                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    275                 psFree (job);
    276273                return false;
    277274            }
    278             psFree(job);
    279 
    280275        }
    281276
  • branches/pap/psphot/src/psphotRadiusChecks.c

    r26894 r28484  
    44static float PSF_FIT_NSIGMA;
    55static float PSF_FIT_PADDING;
    6 static float PSF_APERTURE = 0;  // radius to use in PSF aperture mags
    7 static float PSF_FIT_RADIUS = 0;        // radius to use in fitting (ignored if <= 0,
    8                                         // and a per-object radius is calculated)
     6static float PSF_APERTURE = 0;  // radius to use in PSF aperture mags
     7static float PSF_FIT_RADIUS = 0;        // radius to use in fitting (ignored if <= 0,
     8                                        // and a per-object radius is calculated)
    99
    1010bool psphotInitRadiusPSF(const psMetadata *recipe, const psMetadata *analysis, const pmModelType type) {
     
    1717    PSF_FIT_RADIUS =  psMetadataLookupF32(&status, analysis, "PSF_FIT_RADIUS");
    1818    if (!status) {
    19         PSF_FIT_RADIUS = psMetadataLookupF32(&status, recipe, "PSF_FIT_RADIUS");
     19        PSF_FIT_RADIUS = psMetadataLookupF32(&status, recipe, "PSF_FIT_RADIUS");
    2020    }
    2121
    2222    PSF_APERTURE =  psMetadataLookupF32(&status, analysis, "PSF_APERTURE");
    2323    if (!status) {
    24         PSF_APERTURE =  psMetadataLookupF32(&status, recipe, "PSF_APERTURE");
     24        PSF_APERTURE =  psMetadataLookupF32(&status, recipe, "PSF_APERTURE");
     25    }
     26
     27    // The PSF_FIT_RADIUS and PSF_APERTURE may not be set if the PSF was loaded and not chosen
     28
     29    if (PSF_FIT_RADIUS == 0.0) {
     30        float gaussSigma = psMetadataLookupF32(&status, analysis, "MOMENTS_GAUSS_SIGMA");
     31        if (!status) {
     32            gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA");
     33        }
     34        float fitScale = psMetadataLookupF32(&status, recipe, "PSF_FIT_RADIUS_SCALE");
     35        PSF_FIT_RADIUS = (int)(fitScale*gaussSigma);
     36    }
     37
     38    if (PSF_APERTURE == 0.0) {
     39        float gaussSigma = psMetadataLookupF32(&status, analysis, "MOMENTS_GAUSS_SIGMA");
     40        if (!status) {
     41            gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA");
     42        }
     43        float apScale = psMetadataLookupF32(&status, recipe, "PSF_APERTURE_SCALE");
     44        PSF_APERTURE = (int)(apScale*gaussSigma);
    2545    }
    2646
     
    3858    // set the fit radius based on the object flux limit and the model
    3959    float radiusFit = PSF_FIT_RADIUS;
    40     if (radiusFit <= 0) {               // use fixed radius
    41         if (moments == NULL) {
    42             radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
    43         } else {
    44             radiusFit = model->modelRadius(model->params, 1.0);
    45         }
    46         model->fitRadius = (RADIUS_TYPE)(radiusFit + PSF_FIT_PADDING);
     60    if (radiusFit <= 0) {               // use fixed radius
     61        if (moments == NULL) {
     62            radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
     63        } else {
     64            radiusFit = model->modelRadius(model->params, 1.0);
     65        }
     66        model->fitRadius = (RADIUS_TYPE)(radiusFit + PSF_FIT_PADDING);
    4767    } else {
    48         model->fitRadius = radiusFit;
     68        model->fitRadius = radiusFit;
    4969    }
    5070    if (isnan(model->fitRadius)) psAbort("error in radius");
    51        
     71
    5272    if (source->mode & PM_SOURCE_MODE_SATSTAR) {
    53         model->fitRadius *= 2;
     73        model->fitRadius *= 2;
    5474    }
    5575
     
    7393    // set the fit radius based on the object flux limit and the model
    7494    float radiusFit = PSF_FIT_RADIUS;
    75     if (radiusFit <= 0) {               // use fixed radius
    76         if (moments == NULL) {
    77             radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
    78         } else {
    79             radiusFit = model->modelRadius(model->params, 1.0);
    80         }
    81         model->fitRadius = (RADIUS_TYPE)(radiusFit + PSF_FIT_PADDING);
     95    if (radiusFit <= 0) {               // use fixed radius
     96        if (moments == NULL) {
     97            radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
     98        } else {
     99            radiusFit = model->modelRadius(model->params, 1.0);
     100        }
     101        model->fitRadius = (RADIUS_TYPE)(radiusFit + PSF_FIT_PADDING);
    82102    } else {
    83         model->fitRadius = radiusFit;
     103        model->fitRadius = radiusFit;
    84104    }
    85105    if (isnan(model->fitRadius)) psAbort("error in radius");
     
    89109
    90110    if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
    91         model->fitRadius *= 2;
     111        model->fitRadius *= 2;
    92112    }
    93113
     
    134154    float radius = 0.0;
    135155    for (int j = 0; j < footprint->spans->n; j++) {
    136         pmSpan *span = footprint->spans->data[j];
    137 
    138         float dY  = span->y  - peak->yf;
    139         float dX0 = span->x0 - peak->xf;
    140         float dX1 = span->x1 - peak->xf;
    141 
    142         radius = PS_MAX (radius, hypot(dY, dX0));
    143         radius = PS_MAX (radius, hypot(dY, dX1));
     156        pmSpan *span = footprint->spans->data[j];
     157
     158        float dY  = span->y  - peak->yf;
     159        float dX0 = span->x0 - peak->xf;
     160        float dX1 = span->x1 - peak->xf;
     161
     162        radius = PS_MAX (radius, hypot(dY, dX0));
     163        radius = PS_MAX (radius, hypot(dY, dX1));
    144164    }
    145165
  • branches/pap/psphot/src/psphotReadout.c

    r28013 r28484  
    4545        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
    4646    }
     47
    4748    if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
    4849        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     
    9394        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
    9495    }
     96
    9597    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
    9698    if (!psphotImageQuality (config, view, "PSPHOT.INPUT")) { // pass 1
     
    208210
    209211    // calculate source magnitudes
    210     psphotMagnitudes(config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
    211 
     212    if (!psphotMagnitudes(config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)
     213      psErrorStackPrint(stderr, "Unable to do magnitudes.");
     214        psErrorClear();
     215    }
    212216    if (!psphotEfficiency(config, view, "PSPHOT.INPUT")) { // pass 1
    213217        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
     
    219223
    220224    // replace background in residual image
    221     psphotSkyReplace (config, view, "PSPHOT.INPUT"); // pass 1
    222 
     225    if (!psphotSkyReplace (config, view, "PSPHOT.INPUT")) { // pass 1
     226      psErrorStackPrint(stderr, "Unable to replace sky");
     227      psErrorClear();
     228
     229/*       psLogMsg("psphot", 3, "failed on psphotSkyReplace"); */
     230/*       return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */
     231    }
    223232    // drop the references to the image pixels held by each source
    224     psphotSourceFreePixels (config, view, "PSPHOT.INPUT"); // pass 1
    225 
     233    if (!psphotSourceFreePixels (config, view, "PSPHOT.INPUT")) { // pass 1
     234      psErrorStackPrint(stderr, "Unable to free source pixels");
     235      psErrorClear();
     236
     237/*       psLogMsg ("psphot", 3, "failed on psphotSourceFreePixels"); */
     238/*       return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */
     239    }
    226240    // create the exported-metadata and free local data
    227241    return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");
  • branches/pap/psphot/src/psphotRoughClass.c

    r28013 r28484  
    2525    // loop over the available readouts
    2626    for (int i = 0; i < num; i++) {
    27         if (i == chisqNum) continue; // skip chisq image
    28         if (!psphotRoughClassReadout (config, view, filerule, i, recipe)) {
     27        if (i == chisqNum) continue; // skip chisq image
     28        if (!psphotRoughClassReadout (config, view, filerule, i, recipe)) {
    2929            psError (PSPHOT_ERR_CONFIG, false, "failed on rough classification for %s entry %d", filerule, i);
    30             return false;
    31         }
     30            return false;
     31        }
    3232    }
    3333    return true;
     
    5050    bool havePSF = false;
    5151    if (psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF")) {
    52         havePSF = true;
     52        havePSF = true;
    5353    }
    5454
     
    6060
    6161    if (!sources->n) {
    62         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping rough classification");
    63         return true;
     62        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping rough classification");
     63        return true;
    6464    }
    6565
     
    7878                psLogMsg ("psphot", 4, "Failed to determine rough classification for region %f,%f - %f,%f\n",
    7979                         region->x0, region->y0, region->x1, region->y1);
     80
     81                // If in doubt, it's a PSF
     82                for (int i = 0; i < sources->n; i++) {
     83                    pmSource *source = sources->data[i]; // Source of interest
     84                    if (!source || !source->peak) {
     85                        continue;
     86                    }
     87                    if (source->peak->x <  region->x0) continue;
     88                    if (source->peak->x >= region->x1) continue;
     89                    if (source->peak->y <  region->y0) continue;
     90                    if (source->peak->y >= region->y1) continue;
     91                    source->type = PM_SOURCE_TYPE_STAR;
     92                }
    8093                psFree (region);
    8194                continue;
     
    124137        // XXX why not save the psfClump as a PTR?
    125138
    126         float PSF_SN_LIM = psMetadataLookupF32(&status, recipe, "PSF_SN_LIM"); psAssert (status, "missing PSF_SN_LIM");
    127         float MOMENTS_AR_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_AR_MAX"); psAssert (status, "missing MOMENTS_AR_MAX");
     139        float PSF_SN_LIM = psMetadataLookupF32(&status, recipe, "PSF_SN_LIM"); psAssert (status, "missing PSF_SN_LIM");
     140        float MOMENTS_AR_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_AR_MAX"); psAssert (status, "missing MOMENTS_AR_MAX");
    128141
    129         float PSF_CLUMP_GRID_SCALE = psMetadataLookupF32(&status, analysis, "PSF_CLUMP_GRID_SCALE");
    130         if (!status) {
    131             PSF_CLUMP_GRID_SCALE = psMetadataLookupF32(&status, recipe, "PSF_CLUMP_GRID_SCALE");
    132             psAssert (status, "missing PSF_CLUMP_GRID_SCALE");
    133         }
    134         float MOMENTS_SX_MAX = psMetadataLookupF32(&status, analysis, "MOMENTS_SX_MAX");
    135         if (!status) {
    136             MOMENTS_SX_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SX_MAX");
    137             psAssert (status, "missing MOMENTS_SX_MAX");
    138         }
    139         float MOMENTS_SY_MAX = psMetadataLookupF32(&status, analysis, "MOMENTS_SY_MAX");
    140         if (!status) {
    141             MOMENTS_SY_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SY_MAX");
    142             psAssert (status, "missing MOMENTS_SY_MAX");
    143         }
     142        float PSF_CLUMP_GRID_SCALE = psMetadataLookupF32(&status, analysis, "PSF_CLUMP_GRID_SCALE");
     143        if (!status) {
     144            PSF_CLUMP_GRID_SCALE = psMetadataLookupF32(&status, recipe, "PSF_CLUMP_GRID_SCALE");
     145            psAssert (status, "missing PSF_CLUMP_GRID_SCALE");
     146        }
     147        float MOMENTS_SX_MAX = psMetadataLookupF32(&status, analysis, "MOMENTS_SX_MAX");
     148        if (!status) {
     149            MOMENTS_SX_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SX_MAX");
     150            psAssert (status, "missing MOMENTS_SX_MAX");
     151        }
     152        float MOMENTS_SY_MAX = psMetadataLookupF32(&status, analysis, "MOMENTS_SY_MAX");
     153        if (!status) {
     154            MOMENTS_SY_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SY_MAX");
     155            psAssert (status, "missing MOMENTS_SY_MAX");
     156        }
    144157
    145158        psfClump = pmSourcePSFClump (NULL, region, sources, PSF_SN_LIM, PSF_CLUMP_GRID_SCALE, MOMENTS_SX_MAX, MOMENTS_SY_MAX, MOMENTS_AR_MAX);
  • branches/pap/psphot/src/psphotSourceStats.c

    r28013 r28484  
    33// convert detections to sources and measure their basic properties (moments, local sky, sky
    44// variance) Note: this function only generates sources for the new peaks (peak->assigned).
    5 // The new sources are added to any existing sources on detections->newSources.  The sources 
     5// The new sources are added to any existing sources on detections->newSources.  The sources
    66// on detections->allSources are ignored.
    77bool psphotSourceStats (pmConfig *config, const pmFPAview *view, const char *filerule, bool setWindow)
     
    2222    // loop over the available readouts
    2323    for (int i = 0; i < num; i++) {
    24         // if (i == chisqNum) continue; // skip chisq image
     24        // if (i == chisqNum) continue; // skip chisq image
    2525        if (!psphotSourceStatsReadout (config, view, filerule, i, recipe, setWindow)) {
    2626            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for %s entry %d", filerule, i);
     
    9191    // generate the array of sources, define the associated pixel
    9292    if (!detections->newSources) {
    93         detections->newSources = psArrayAllocEmpty (peaks->n);
     93        detections->newSources = psArrayAllocEmpty (peaks->n);
    9494    }
    9595    sources = detections->newSources;
     
    107107        // create a new source
    108108        pmSource *source = pmSourceAlloc();
    109         source->imageID = index;
     109        source->imageID = index;
    110110
    111111        // add the peak
     
    184184            if (!psThreadJobAddPending(job)) {
    185185                psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS");
    186                 psFree (job);
    187186                psFree(detections->newSources);
    188187                return false;
    189188            }
    190             psFree(job);
    191189        }
    192190
     
    194192        if (!psThreadPoolWait (false)) {
    195193            psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS");
    196             psFree(detections->newSources);
     194            psFree(detections->newSources);
    197195            return false;
    198196        }
     
    315313            if (!psThreadJobAddPending(job)) {
    316314                psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS");
    317                 psFree (job);
    318315                return NULL;
    319316            }
    320             psFree(job);
    321317        }
    322318
     
    380376        pmSource *source = sources->data[i];
    381377
    382         if (source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue;
    383         source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
     378        if (source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue;
     379        source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
    384380
    385381        // skip faint sources for moments measurement
     
    493489        psLogMsg ("psphot", 3, "radius %.1f, nStars: %d, nSigma: %5.2f, X,  Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]);
    494490
     491#if 0
     492        // Modifying clump parameters without restoring!
    495493        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
    496494        psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, "PSF.CLUMP.REGION.000");
     
    504502        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    505503        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    506 
    507504        psphotVisualPlotMoments (recipe, analysis, sources);
     505#endif
    508506
    509507        Sout[i] = sqrt(0.5*(psfClump.X + psfClump.Y)) / sigma[i];
  • branches/pap/psphot/src/psphotTest.c

    r24187 r28484  
    2525
    2626bool FillImage_Threaded (psThreadJob *job) {
    27    
     27
    2828    psImage *image = job->args->data[0];
    2929    int xs = PS_SCALAR_VALUE(job->args->data[1],S32);
     
    3636    psRegion region = psRegionSet (xs, xs + dx, ys, ys + dy);
    3737    for (int i = 0; i < 100; i++) {
    38         psImage *subset = psImageSubset (image, region);
    39         psImageInit (subset, value + i);
    40         psFree (subset);
     38        psImage *subset = psImageSubset (image, region);
     39        psImageInit (subset, value + i);
     40        psFree (subset);
    4141    }
    4242    return true;
     
    4646
    4747    if (argc != 3) {
    48         fprintf (stderr, "USAGE: psphotTest (output.fits) (nThreads)\n");
    49         exit (2);
     48        fprintf (stderr, "USAGE: psphotTest (output.fits) (nThreads)\n");
     49        exit (2);
    5050    }
    5151
     
    6262
    6363    for (int ix = 0; ix < 1000; ix += 100) {
    64         for (int iy = 0; iy < 1000; iy += 100) {
     64        for (int iy = 0; iy < 1000; iy += 100) {
    6565
    66             // allocate a job -- if threads are not defined, this just runs the job
    67             psThreadJob *job = psThreadJobAlloc ("FILL_IMAGE");
     66            // allocate a job -- if threads are not defined, this just runs the job
     67            psThreadJob *job = psThreadJobAlloc ("FILL_IMAGE");
    6868
    69             psArrayAdd(job->args, 1, image);
    70             PS_ARRAY_ADD_SCALAR(job->args, ix, PS_TYPE_S32);
    71             PS_ARRAY_ADD_SCALAR(job->args, iy, PS_TYPE_S32);
    72             PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);
    73             PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);
    74             PS_ARRAY_ADD_SCALAR(job->args, ix + iy, PS_TYPE_S32);
     69            psArrayAdd(job->args, 1, image);
     70            PS_ARRAY_ADD_SCALAR(job->args, ix, PS_TYPE_S32);
     71            PS_ARRAY_ADD_SCALAR(job->args, iy, PS_TYPE_S32);
     72            PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);
     73            PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);
     74            PS_ARRAY_ADD_SCALAR(job->args, ix + iy, PS_TYPE_S32);
    7575
    76             // FillImage (image, ix, iy, 100, 100, ix + iy);
     76            // FillImage (image, ix, iy, 100, 100, ix + iy);
    7777
    78             if (!psThreadJobAddPending(job)) {
    79                 fprintf (stderr, "failure to run FillImage(1)");
    80                 psFree (job);
    81                 exit (1);
    82             }
    83             psFree(job);
    84         }
     78            if (!psThreadJobAddPending(job)) {
     79                fprintf (stderr, "failure to run FillImage(1)");
     80                exit (1);
     81            }
     82        }
    8583    }
    8684
     
    8886    // wait for the threads to finish and manage results
    8987    if (!psThreadPoolWait (true)) {
    90         fprintf (stderr, "failure to run FillImage (2)");
    91         exit (1);
     88        fprintf (stderr, "failure to run FillImage (2)");
     89        exit (1);
    9290    }
    9391
Note: See TracChangeset for help on using the changeset viewer.