IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27649


Ignore:
Timestamp:
Apr 9, 2010, 4:41:16 PM (16 years ago)
Author:
eugene
Message:

working on psphotStack (nearly done)

Location:
branches/eam_branches/stackphot.20100406/psphot/src
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/stackphot.20100406/psphot/src/Makefile.am

    r27625 r27649  
    8787# a psphot-variant for stack photometry
    8888psphotStack_SOURCES = \
    89         psphotStack.c              \
    90         psphotStackArguments.c     \
    91         psphotStackParseCamera.c   \
    92         psphotStackImageLoop.c     \
    93         psphotStackReadout.c       \
    94         psphotStackChisqImage.c    \
    95         psphotCleanup.c
    96 
    97 # psphotFitSourceLinearStack.c   
     89        psphotStack.c                 \
     90        psphotStackArguments.c        \
     91        psphotStackParseCamera.c      \
     92        psphotStackImageLoop.c        \
     93        psphotStackReadout.c          \
     94        psphotStackChisqImage.c       \
     95        psphotFitSourcesLinearStack.c \
     96        psphotSourceMatch.c           \
     97        psphotCleanup.c
     98
    9899
    99100
  • branches/eam_branches/stackphot.20100406/psphot/src/psphot.h

    r27625 r27649  
    350350bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration
    351351                                     const pmFPAview *view,
    352                                      pmReadout *chiReadout,
     352                                     pmReadout **chiReadout,
    353353                                     char *filename,
    354354                                     int index);
    355355
     356bool psphotStackRemoveChisqFromInputs (pmConfig *config);
     357bool pmFPAfileRemoveSingle(psMetadata *files, const char *name, int num);
     358
     359psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view);
     360bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index);
     361bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS);
     362
     363bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final);
     364int pmPhotObjSortBySN (const void **a, const void **b);
     365int pmPhotObjSortByX (const void **a, const void **b);
    356366
    357367#endif
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotApResid.c

    r26894 r27649  
    1616    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    1717
     18    // skip the chisq image (optionally?)
     19    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     20    if (!status) chisqNum = -1;
     21
    1822    // loop over the available readouts
    1923    for (int i = 0; i < num; i++) {
     24        if (i == chisqNum) continue; // skip chisq image
    2025        if (!psphotApResidReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
    2126            psError (PSPHOT_ERR_CONFIG, false, "failed to measure aperture residual for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotChoosePSF.c

    r27568 r27649  
    1313    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    1414
     15    // skip the chisq image (optionally?)
     16    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     17    if (!status) chisqNum = -1;
     18
    1519    // loop over the available readouts
    1620    for (int i = 0; i < num; i++) {
     21        if (i == chisqNum) continue; // skip chisq image
    1722        if (!psphotChoosePSFReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
    1823            psError (PSPHOT_ERR_CONFIG, false, "failed to choose a psf model for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotEfficiency.c

    r27532 r27649  
    160160    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    161161
     162    // skip the chisq image (optionally?)
     163    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     164    if (!status) chisqNum = -1;
     165
    162166    // loop over the available readouts
    163167    for (int i = 0; i < num; i++) {
     168        if (i == chisqNum) continue; // skip chisq image
    164169        if (!psphotEfficiencyReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
    165170            psError (PSPHOT_ERR_CONFIG, false, "failed to measure detection efficiency for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotFitSourcesLinearStack.c

    r27625 r27649  
    33// XXX define the 'good' / 'bad' flags?
    44
     5# define COVAR_FACTOR 1.0
     6
    57bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final) {
    68
    79    bool status;
    8     float x;
    9     float y;
    1010    float f;
    1111
     
    2929    // analysis is done in spatial order (to speed up overlap search)
    3030    // sort by first element in each source list
    31     objects = psArraySort (objects, pmPhotObjSortByY);
     31    objects = psArraySort (objects, pmPhotObjSortByX);
    3232
    3333    // storage array for fitSources
     
    6666        }
    6767    }
    68     psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), sources->n);
     68    psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), objects->n);
    6969
    7070    if (fitSources->n == 0) {
     
    8686
    8787        // diagonal elements of the sparse matrix (auto-cross-product)
    88         f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     88        f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR);
    8989        psSparseMatrixElement (sparse, i, i, f);
    9090
    9191        // the formal error depends on the weighting scheme
    9292        if (CONSTANT_PHOTOMETRIC_WEIGHTS) {
    93             float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor);
     93            float var = pmSourceModelDotModel (SRCi, SRCi, false, COVAR_FACTOR);
    9494            errors->data.F32[i] = 1.0 / sqrt(var);
    9595        } else {
     
    9898
    9999        // find the image x model value
    100         f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     100        f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR);
    101101        psSparseVectorElement (sparse, i, f);
    102102
     
    109109
    110110            // skip over disjoint source images, break after last possible overlap
    111             if (SRCi->pixels->row0 + SRCi->pixels->numRows < SRCj->pixels->row0) break;
    112             if (SRCj->pixels->row0 + SRCj->pixels->numRows < SRCi->pixels->row0) continue;
    113             if (SRCi->pixels->col0 + SRCi->pixels->numCols < SRCj->pixels->col0) continue;
    114             if (SRCj->pixels->col0 + SRCj->pixels->numCols < SRCi->pixels->col0) continue;
     111            if (SRCj->pixels->row0 + SRCj->pixels->numRows < SRCi->pixels->row0) continue;  // source(i) is above source(j)
     112            if (SRCi->pixels->row0 + SRCi->pixels->numRows < SRCj->pixels->row0) continue;  // source(i) is below source(j)
     113            if (SRCj->pixels->col0 + SRCj->pixels->numCols < SRCi->pixels->col0) continue;  // source(i) is right of source(j)
     114            if (SRCi->pixels->col0 + SRCi->pixels->numCols < SRCj->pixels->col0) break;     // source(i) is left of source(j) [no other source(j) can overlap source(i)]
    115115
    116116            // got an overlap; calculate cross-product and add to output array
    117             f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);
     117            f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR);
    118118            psSparseMatrixElement (sparse, j, i, f);
    119119        }
     
    157157        if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) continue;
    158158        pmModel *model = pmSourceGetModel (NULL, source);
    159         pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, covarFactor);
     159        pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, COVAR_FACTOR);
    160160    }
    161161    psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "get chisqs: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem);
     
    172172}
    173173
    174 // sort by Y (ascending)
    175 int pmPhotObjSortBySN (const void **a, const void **b)
     174// sort by X (ascending)
     175int pmPhotObjSortByX (const void **a, const void **b)
    176176{
    177177    pmPhotObj *objA = *(pmPhotObj **)a;
    178178    pmPhotObj *objB = *(pmPhotObj **)b;
    179179
    180     psAssert (objA->sources, "missing sources?");
    181     psAssert (objB->sources, "missing sources?");
    182 
    183     psAssert (objA->sources->n, "missing sources");
    184     psAssert (objB->sources->n, "missing sources");
    185 
    186     psAssert (objA->sources->data[0], "missing sources");
    187     psAssert (objB->sources->data[0], "missing sources");
    188 
    189     pmSource *A = objA->sources->data[0];
    190     pmSource *B = objB->sources->data[0];
    191 
    192     psF32 fA = (A->peak == NULL) ? 0 : A->peak->y;
    193     psF32 fB = (B->peak == NULL) ? 0 : B->peak->y;
     180    psF32 fA = objA->x;
     181    psF32 fB = objB->x;
    194182
    195183    psF32 diff = fA - fB;
     
    198186    return (0);
    199187}
    200 
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotGuessModels.c

    r26894 r27649  
    1515    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    1616
     17    // skip the chisq image (optionally?)
     18    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     19    if (!status) chisqNum = -1;
     20
    1721    // loop over the available readouts
    1822    for (int i = 0; i < num; i++) {
     23        if (i == chisqNum) continue; // skip chisq image
    1924        if (!psphotGuessModelsReadout (config, view, "PSPHOT.INPUT", i)) {
    2025            psError (PSPHOT_ERR_CONFIG, false, "failed on to guess models for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotImageLoop.c

    r25755 r27649  
    9191            }
    9292
    93             status = true;
    94             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
    95             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
    96             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");
    97             if (!status) {
    98                 psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files");
    99                 psFree (view);
    100                 return false;
    101             }
     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            }
    102103        }
    103 
    104104        // save output which is saved at the chip level
    105105        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot.");
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotImageQuality.c

    r26894 r27649  
    1616    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    1717
     18    // skip the chisq image (optionally?)
     19    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     20    if (!status) chisqNum = -1;
     21
    1822    // loop over the available readouts
    1923    for (int i = 0; i < num; i++) {
     24        if (i == chisqNum) continue; // skip chisq image
    2025        if (!psphotImageQualityReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
    2126            psError (PSPHOT_ERR_CONFIG, false, "failed on to measure image quality for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotMagnitudes.c

    r27532 r27649  
    1212    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    1313
     14    // skip the chisq image (optionally?)
     15    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     16    if (!status) chisqNum = -1;
     17
    1418    // loop over the available readouts
    1519    for (int i = 0; i < num; i++) {
     20        if (i == chisqNum) continue; // skip chisq image
    1621
    1722        // find the currently selected readout
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotModelBackground.c

    r26894 r27649  
    371371
    372372    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
    373     pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning);
    374     pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
     373    pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning, index);
     374    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning, index);
    375375
    376376    if (!psphotModelBackgroundReadout(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotReadoutCleanup.c

    r26894 r27649  
    5353    pmPSF        *psf        = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    5454    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    55     psArray      *sources    = detections->allSources;
     55    psArray      *sources    = detections ? detections->allSources : NULL;
    5656    // XXX where do we free these, in here (psMetadataRemove?)
    5757
     
    7373    // Check to see if the image quality was measured
    7474    // XXX not sure we want / need this test
    75     if (!psf) {
     75    if (0 && !psf) {
    7676        bool mdok;                      // Status of MD lookup
    7777        int nIQ = psMetadataLookupS32(&mdok, recipe, "IQ_NSTAR"); // Number of stars for IQ measurement
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotRoughClass.c

    r26894 r27649  
    1919    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    2020
     21    // skip the chisq image (optionally?)
     22    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     23    if (!status) chisqNum = -1;
     24
    2125    // loop over the available readouts
    2226    for (int i = 0; i < num; i++) {
     27        if (i == chisqNum) continue; // skip chisq image
    2328        if (!psphotRoughClassReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
    2429            psError (PSPHOT_ERR_CONFIG, false, "failed on rough classification for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotSkyReplace.c

    r26894 r27649  
    88    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    99
     10    // skip the chisq image (optionally?)
     11    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     12    if (!status) chisqNum = -1;
     13
    1014    // loop over the available readouts
    1115    for (int i = 0; i < num; i++) {
     16        if (i == chisqNum) continue; // skip chisq image
    1217        if (!psphotSkyReplaceReadout (config, view, "PSPHOT.INPUT", i)) {
    1318            psError (PSPHOT_ERR_CONFIG, false, "failed to replace sky for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceMatch.c

    r27628 r27649  
    1414        if (!psphotMatchSourcesReadout (objects, config, view, "PSPHOT.INPUT", i)) {
    1515            psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i);
    16             return false;
     16            psFree (objects);
     17            return NULL;
    1718        }
    1819    }
     20
     21    // psphotMatchSourcesGenerate (objects, config, view, "PSPHOT.INPUT", i);
     22
     23    return objects;
     24}
     25
     26bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) {
     27 
     28    bool status = false;
     29
     30    // select the appropriate recipe information
     31    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     32    psAssert (recipe, "missing recipe?");
     33
     34    int RADIUS = psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.MATCH.RADIUS");
     35    psAssert (status, "programming error: must define PSPHOT.STACK.MATCH.RADIUS");
     36
     37    // find the currently selected readout
     38    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     39    psAssert (file, "missing file?");
     40
     41    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     42    psAssert (readout, "missing readout?");
     43
     44    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     45    psAssert (detections, "missing detections?");
     46    psAssert (detections->newSources, "new sources not defined?");
     47    psAssert (!detections->allSources, "all sources already defined?");
     48
     49    // XXX TEST:
     50    if (detections->newSources) {
     51        psphotMatchSourcesToObjects(objects, detections->newSources, RADIUS);
     52    }
     53
    1954    return true;
    2055}
    2156
    22 // we need a couple of functions to distinguish coincident sources:
    23 // XXX these are similar (identical?) to the goals of pmSourceMatch.c
    24  
    2557# define NEXT1 { i++; continue; }
    2658# define NEXT2 { j++; continue; }
    27  
    28 bool psphotSourceMerge (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) {
     59bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS) {
    2960 
    3061    float dx, dy;
    3162 
     63    float RADIUS2 = RADIUS*RADIUS;
     64
    3265    // sort the source list by X
    33     pmSourceSortByX (sources1);
    34     pmSourceSortByX (sources2);
     66    sources = psArraySort (sources, pmSourceSortByX);
     67    objects = psArraySort (objects, pmPhotObjSortByX);
    3568 
     69    psVector *found = psVectorAlloc(sources->n, PS_TYPE_U8);
     70    psVectorInit (found, 0);
     71
     72    // match sources to existing objects
     73
     74    psLogMsg ("psphot", PS_LOG_DETAIL, "attempt to match sources (%ld vs %ld)", sources->n, objects->n);
     75
    3676    int i, j;
    37     for (i = j = 0; (i < sources1->n) && (j < sources2->n); ) {
     77    for (i = j = 0; (i < sources->n) && (j < objects->n); ) {
    3878 
    39         pmSource *src1 = sources1->data[i];
    40         pmSource *src2 = sources2->data[j];
     79        pmSource  *src = sources->data[i];
     80        pmPhotObj *obj = objects->data[j];
    4181 
    42         if (!src1) NEXT1;
    43         if (!src1->peak) NEXT1;
    44         if (!finite(src1->peak->xf)) NEXT1;
    45         if (!finite(src1->peak->yf)) NEXT1;
     82        if (!src) NEXT1;
     83        if (!src->peak) NEXT1;
     84        if (!finite(src->peak->xf)) NEXT1;
     85        if (!finite(src->peak->yf)) NEXT1;
    4686 
    47         if (!src2) NEXT2;
    48         if (!src2->peak) NEXT2;
    49         if (!finite(src2->peak->xf)) NEXT2;
    50         if (!finite(src2->peak->yf)) NEXT2;
     87        if (!obj) NEXT2;
     88        if (!finite(obj->x)) NEXT2;
     89        if (!finite(obj->y)) NEXT2;
    5190 
    52         dx = src1->peak->xf - src2->peak->xf;
     91        dx = src->peak->xf - obj->x;
    5392        if (dx < -1.02*RADIUS) NEXT1;
    5493        if (dx > +1.02*RADIUS) NEXT2;
    5594 
    5695        // we are within match range, look for matches:
    57         for (int J = j; (dx > -1.02*radius) && (J < sources2->n); J++) {
     96        int Jmin = -1;
     97        float Rmin = RADIUS2;
     98        for (int J = j; (dx > -1.02*RADIUS) && (J < objects->n); J++) {
    5899 
    59             dx = src1->peak->xf - src2->peak->xf;
    60             dy = src1->peak->yf - src2->peak->yf;
     100            obj = objects->data[J];
     101           
     102            dx = src->peak->xf - obj->x;
     103            dy = src->peak->yf - obj->y;
    61104 
    62             dr = dx*dx + dy*dy;
     105            float dr = dx*dx + dy*dy;
    63106            if (dr > RADIUS2) continue;
    64  
    65             // add to group?
    66         }
     107            if (dr < Rmin) {
     108                Rmin = dr;
     109                Jmin  = J;
     110            }
     111        }
     112
     113        // no match, try next source
     114        if (Jmin == -1) {
     115            i++;
     116            continue;
     117        }
     118        obj = objects->data[Jmin];
     119
     120        // add to object
     121        pmPhotObjAddSource (obj, src);
     122        found->data.U8[i] = 1;
    67123        i++;
    68124    }
     125
     126    // add missed sources to new objects
     127
     128    for (i = 0; i < sources->n; i++) {
     129
     130        if (found->data.U8[i]) continue;
     131
     132        pmSource *src = sources->data[i];
     133
     134        pmPhotObj *obj = pmPhotObjAlloc();
     135        pmPhotObjAddSource(obj, src);
     136        psArrayAdd (objects, 100, obj);
     137    }
     138    psLogMsg ("psphot", PS_LOG_DETAIL, "matched sources (%ld vs %ld)", sources->n, objects->n);
     139
     140    return true;
    69141}
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceSize.c

    r27532 r27649  
    4444    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    4545
     46    // skip the chisq image (optionally?)
     47    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     48    if (!status) chisqNum = -1;
     49
    4650    // loop over the available readouts
    4751    for (int i = 0; i < num; i++) {
     52        if (i == chisqNum) continue; // skip chisq image
    4853        if (!psphotSourceSizeReadout (config, view, "PSPHOT.INPUT", i, recipe, getPSFsize)) {
    4954            psError (PSPHOT_ERR_CONFIG, false, "failed on source size analysis for PSPHOT.INPUT entry %d", i);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotStackChisqImage.c

    r27625 r27649  
    1212    psTimerStart ("psphot.chisq.image");
    1313
    14     pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.OUTPUT", 0);
     14    pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.IMAGE", 0);
    1515    psAssert (chisqFile, "missing chisq image FPA?");
    1616
    17     pmCell *chisqCell = pmFPAviewThisCell(view, chisqFile->fpa);
    18 
    19     // create a holder for the image
    20     pmReadout *chiReadout = pmFPAviewThisReadout(view, chisqFile->fpa);
    21     if (!chiReadout) {
    22       chiReadout = pmReadoutAlloc(chisqCell);
    23     } else {
    24       psMemIncrRefCounter(chiReadout);
    25     }
     17    pmReadout *chiReadout = NULL;
    2618
    2719    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     
    3022    // loop over the available readouts
    3123    for (int i = 0; i < num; i++) {
    32         if (!psphotStackChisqImageAddReadout(config, view, chiReadout, "PSPHOT.INPUT", i)) {
     24        if (!psphotStackChisqImageAddReadout(config, view, &chiReadout, "PSPHOT.INPUT", i)) {
    3325            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
    3426            return false;
     
    5143    psLogMsg ("psphot", PS_LOG_INFO, "built chisq image: %f sec\n", psTimerMark ("psphot.chisq.image"));
    5244
    53     psFree (chiReadout);
    5445    return true;
    5546}
     
    5748bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration
    5849                                     const pmFPAview *view,
    59                                      pmReadout *chiReadout,
     50                                     pmReadout **chiReadout,
    6051                                     char *filename,
    6152                                     int index)
     
    7162
    7263    psImage *inImage     = inReadout->image;
     64    psAssert (inImage, "missing image?");
     65
    7366    psImage *inVariance  = inReadout->variance;
     67    psAssert (inVariance, "missing variance?");
     68
    7469    psImage *inMask      = inReadout->mask;
     70    psAssert (inMask, "missing mask?");
    7571
    76     psImage *chiImage    = chiReadout->image;
    77     psImage *chiVariance = chiReadout->variance;
    78     psImage *chiMask     = chiReadout->mask;
     72    if (*chiReadout == NULL) {
     73        *chiReadout = pmFPAGenerateReadout(config, view, "PSPHOT.CHISQ.IMAGE", input->fpa, NULL, 0);
     74    }
     75
     76    psImage *chiImage = (*chiReadout)->image;
     77    psAssert (chiImage, "missing chi image");
     78
     79    psImage *chiVariance = (*chiReadout)->variance;
     80    psAssert (chiVariance, "missing chi variance");
     81
     82    psImage *chiMask = (*chiReadout)->mask;
     83    psAssert (chiMask, "missing chi mask");
    7984
    8085    // select the appropriate recipe information
     
    105110    return true;
    106111}
     112
     113bool psphotStackRemoveChisqFromInputs (pmConfig *config) {
     114
     115    bool status = false;
     116
     117    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     118    psAssert (status, "programming error: must define PSPHOT.CHISQ.NUM");
     119
     120    int inputNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     121    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     122
     123    pmFPAfileRemoveSingle (config->files, "PSPHOT.INPUT", chisqNum);
     124
     125    inputNum --;
     126    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", inputNum);
     127
     128    return true;
     129}
     130
     131bool pmFPAfileRemoveSingle(psMetadata *files, const char *name, int num)
     132{
     133    PS_ASSERT_PTR_NON_NULL(files, NULL);
     134    PS_ASSERT_INT_NONNEGATIVE(num, NULL);
     135
     136    psList* mdList = files->list;
     137    psHash* mdHash = files->hash;
     138
     139    // Generate a REGEX to select only items that match 'name'
     140    psString regex = NULL;              // Regular expression
     141    if (name) {
     142        if (!psMetadataLookup(files, name)) {
     143            // No files match the requested name
     144            return false;
     145        }
     146        psStringAppend(&regex, "^%s$", name);
     147    }
     148
     149    psMetadataIterator *iter = psMetadataIteratorAlloc(files, PS_LIST_HEAD, regex); // Iterator
     150    psFree(regex);
     151    psMetadataItem *item;               // Item from iteration
     152
     153    bool found = false;
     154    int i = 0;                          // Counter
     155    for (i = 0; !found && (item = psMetadataGetAndIncrement(iter)); i++) {
     156        if (i == num) found = true;
     157    }
     158    psFree(iter);
     159    if (!found) {
     160        return false;
     161    }
     162
     163    char *key = item->name;
     164
     165    // look up the name via hash to see if we have a multi or not
     166    psMetadataItem* hashItem = psHashLookup(mdHash, name);
     167    if (hashItem == NULL) {
     168        psError(PS_ERR_UNKNOWN, false, _("Failed to remove metadata item, %s, from metadata table."), key);
     169        return false;
     170    }
     171
     172    if (hashItem->type == PS_DATA_METADATA_MULTI) {
     173        // multiple entries with same key, remove just the specified one
     174        psListRemoveData(hashItem->data.list, item);
     175    } else {
     176        psHashRemove(mdHash, key);
     177    }
     178    psListRemoveData(mdList, item);
     179
     180    return true;
     181}
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotStackImageLoop.c

    r27625 r27649  
    99bool psphotStackImageLoop (pmConfig *config) {
    1010
     11    bool status;
     12    pmChip *chip;
     13    pmCell *cell;
     14    pmReadout *readout;
     15
     16    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
     17    if (!status) {
     18        psError(PSPHOT_ERR_PROG, false, "Can't find input data!");
     19        return false;
     20    }
     21
    1122    pmFPAview *view = pmFPAviewAlloc (0);
    1223
     
    1425    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
    1526
    16     // XXX for now, we assume there is only a single chip in the PHU:
    17     psphotStackReadout (config, view);
     27    // for psphot, we force data to be read at the chip level
     28    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     29        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     30        if (! chip->process || ! chip->file_exists) { continue; }
     31        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphotStack.");
     32
     33        // there is now only a single chip (multiple readouts?). loop over it and process
     34        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     35            psLogMsg ("psphot", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     36            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Cell in psphotStack.");
     37
     38            // process each of the readouts
     39            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
     40                psLogMsg ("psphot", 6, "Readout %d: %x %x\n", view->readout, cell->file_exists, cell->process);
     41                if (! readout->data_exists) { continue; }
     42
     43                // XXX for now, we assume there is only a single chip in the PHU:
     44                if (!psphotStackReadout (config, view)) {
     45                    psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
     46                    psFree (view);
     47                    return false;
     48                }
     49
     50            }
     51            // drop all versions of the internal files
     52            status = true;
     53            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
     54            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
     55            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");
     56            if (!status) {
     57                psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files");
     58                psFree (view);
     59                return false;
     60            }
     61        }
     62        // save output which is saved at the chip level
     63        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot.");
     64    }
     65    // save output which is saved at the fpa level
     66    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed ouput for FPA in psphot.");
    1867
    1968    // fail if we failed to handle an error
     
    2776   the easiest way to implement this is to assume we can pre-load the full set of images up front.
    2877   with 5 filters and 6000^2 (image, mask, var = 10 byte per pixel), we need 1.8GB, which is not too bad.
    29  */
     78*/
    3079
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotStackParseCamera.c

    r27625 r27649  
    1515    }
    1616
    17     psMetadataItem *item = NULL;
    18     int nInputs = 0;
    19     while ((item = psMetadataGet(inputs, nInputs)) != NULL) {
     17    int nInputs = inputs->list->n;
     18    for (int i = 0; i < nInputs; i++) {
     19        psMetadataItem *item = psMetadataGet(inputs, i);
    2020        if (item->type != PS_DATA_METADATA) {
    2121            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Component %s of the input metadata is not of type METADATA", item->name);
     
    3434        pmFPAfile *imageFile = defineFile(config, NULL, "PSPHOT.INPUT", image, PM_FPA_FILE_IMAGE); // File for image
    3535        if (!imageFile) {
    36             psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", nInputs, image);
     36            psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image);
    3737            return false;
    3838        }
     
    4040        psString mask = psMetadataLookupStr(&status, input, "MASK"); // Name of mask
    4141        if (mask && strlen(mask) > 0) {
    42             if (!defineFile(config, imageFile, "PSPHOT.INPUT.MASK", mask, PM_FPA_FILE_MASK)) {
    43                 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", nInputs, mask);
     42            if (!defineFile(config, imageFile, "PSPHOT.MASK", mask, PM_FPA_FILE_MASK)) {
     43                psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);
    4444                return false;
    4545            }
     
    4848        psString variance = psMetadataLookupStr(&status, input, "VARIANCE"); // Name of variance map
    4949        if (variance && strlen(variance) > 0) {
    50             if (!defineFile(config, imageFile, "PSPHOT.INPUT.VARIANCE", variance, PM_FPA_FILE_VARIANCE)) {
    51                 psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", nInputs, variance);
     50            if (!defineFile(config, imageFile, "PSPHOT.VARIANCE", variance, PM_FPA_FILE_VARIANCE)) {
     51                psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance);
    5252                return false;
    5353            }
    5454        }
    55         nInputs ++;
     55        // the output sources are carried on the input->fpa structures
     56        pmFPAfile *outsources = pmFPAfileDefineOutputFromFile (config, imageFile, "PSPHOT.STACK.OUTPUT");
     57        if (!outsources) {
     58            psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.OUTPUT");
     59            return false;
     60        }
     61        outsources->save = true;
     62        outsources->fileID = i;         // this is used to generate output names
    5663    }
    5764    psMetadataRemoveKey(config->arguments, "FILENAMES");
    5865    psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", nInputs);
     66
     67    if (!psphotSetMaskBits (config)) {
     68        psError (PS_ERR_UNKNOWN, false, "failed to set mask bit values");
     69        return NULL;
     70    }
    5971
    6072    // generate an pmFPAimage for the chisqImage
     
    6476        return false;
    6577    }
    66     pmFPAfile *chisqMask = pmFPAfileDefineOutput(config, chisqImage->fpa, "PPIMAGE.CHISQ.MASK");
     78    chisqImage->save = true;
     79
     80    pmFPAfile *chisqMask = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.MASK");
    6781    if (!chisqMask) {
    68         psError(PS_ERR_IO, false, _("Unable to generate output file from PPIMAGE.CHISQ.MASK"));
     82        psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.MASK"));
    6983        return NULL;
    7084    }
    7185    if (chisqMask->type != PM_FPA_FILE_MASK) {
    72         psError(PS_ERR_IO, true, "PPIMAGE.CHISQ.MASK is not of type MASK");
     86        psError(PS_ERR_IO, true, "PSPHOT.CHISQ.MASK is not of type MASK");
    7387        return NULL;
    7488    }
    75     pmFPAfile *chisqVariance = pmFPAfileDefineOutput(config, chisqImage->fpa, "PPIMAGE.CHISQ.VARIANCE");
     89    chisqMask->save = true;
     90
     91    pmFPAfile *chisqVariance = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.VARIANCE");
    7692    if (!chisqVariance) {
    77         psError(PS_ERR_IO, false, _("Unable to generate output file from PPIMAGE.CHISQ.VARIANCE"));
     93        psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.VARIANCE"));
    7894        return NULL;
    7995    }
    8096    if (chisqVariance->type != PM_FPA_FILE_VARIANCE) {
    81         psError(PS_ERR_IO, true, "PPIMAGE.CHISQ.VARIANCE is not of type VARIANCE");
     97        psError(PS_ERR_IO, true, "PSPHOT.CHISQ.VARIANCE is not of type VARIANCE");
    8298        return NULL;
    8399    }
     100    chisqVariance->save = true;
    84101
    85102# if (0)   
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotStackReadout.c

    r27625 r27649  
    5959
    6060    // find the detections (by peak and/or footprint) in the image.
     61    // This finds the detections on Chisq image as well as the individuals
    6162    if (!psphotFindDetections (config, view, true)) { // pass 1
    6263        // this only happens if we had an error in psphotFindDetections
     
    6667
    6768    // construct sources and measure basic stats (saved on detections->newSources)
     69    // only run this on detections from the input images, not chisq image
    6870    if (!psphotSourceStats (config, view, true)) { // pass 1
    6971        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
    7072        return psphotReadoutCleanup (config, view);
    7173    }
    72     if (!strcasecmp (breakPt, "PEAKS")) {
    73         return psphotReadoutCleanup(config, view);
     74
     75    // *** generate the objects (which unify the sources from the different images)
     76    psArray *objects = psphotMatchSources (config, view);
     77
     78    // construct sources for the newly-generated sources (from other images)
     79    if (!psphotSourceStats (config, view, false)) { // pass 1
     80        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     81        return psphotReadoutCleanup (config, view);
    7482    }
    7583
    7684    // find blended neighbors of very saturated stars (detections->newSources)
    77     if (!psphotDeblendSatstars (config, view)) {
    78         psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
    79         return psphotReadoutCleanup (config, view);
    80     }
     85    // if (!psphotDeblendSatstars (config, view)) {
     86    //     psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     87    //     return psphotReadoutCleanup (config, view);
     88    // }
    8189
    8290    // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
    83     if (!psphotBasicDeblend (config, view)) {
    84         psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
    85         return psphotReadoutCleanup (config, view);
    86     }
     91    // if (!psphotBasicDeblend (config, view)) {
     92    //     psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
     93    //     return psphotReadoutCleanup (config, view);
     94    // }
    8795
    8896    // classify sources based on moments, brightness
     97    // only run this on detections from the input images, not chisq image
    8998    if (!psphotRoughClass (config, view)) {
    9099        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
     
    92101    }
    93102    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     103    // only run this on detections from the input images, not chisq image
    94104    if (!psphotImageQuality (config, view)) { // pass 1
    95105        psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
     
    121131    psphotMergeSources (config, view);
    122132
    123     // *** generate the objects (which unify the sources from the different images)
    124     // pmArray *objects = psphotMatchSources (config, view);
    125    
    126133    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    127     // psphotFitSourcesLinearStack (config, objects, FALSE);
     134    psphotFitSourcesLinearStack (config, objects, FALSE);
     135    psFree (objects);
    128136
    129137    // identify CRs and extended sources
     
    153161    psphotSourceFreePixels (config, view);
    154162
     163    // remove chisq image from config->file:PSPHOT.INPUT (why?)
     164    psphotStackRemoveChisqFromInputs(config);
     165
    155166    // create the exported-metadata and free local data
    156167    return psphotReadoutCleanup (config, view);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotSubtractBackground.c

    r26894 r27649  
    2323    pmFPAfile *modelFile = pmFPAfileSelectSingle(config->files, "PSPHOT.BACKMDL", index); // File of interest
    2424    assert (modelFile);
    25     pmReadout *model = pmFPAviewThisReadout (view, modelFile->fpa);
     25
     26    pmReadout *model = NULL;
     27    if (modelFile->mode == PM_FPA_MODE_INTERNAL) {
     28        model = modelFile->readout;
     29    } else {
     30        model = pmFPAviewThisReadout (view, modelFile->fpa);
     31    }
    2632    assert (model);
    2733
Note: See TracChangeset for help on using the changeset viewer.