IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2012, 2:49:37 PM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20111122/psModules/src/objects
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/psModules/src/objects/models/pmModel_QGAUSS.c

    r32347 r33638  
    402402    assert (psf->params->n > PM_PAR_YPOS);
    403403    assert (psf->params->n > PM_PAR_XPOS);
     404
     405    if (! isfinite(Io)) {
     406        fprintf(stderr, "non-finite Io passed to PM_MODEL_PARAMS_FROM_PSF\n");
     407        return false;
     408    }
    404409
    405410    PAR[PM_PAR_SKY]  = 0.0;
  • branches/eam_branches/ipp-20111122/psModules/src/objects/models/pmModel_SERSIC.c

    r32347 r33638  
    192192    psF32 z0 = PAR[PM_PAR_I0]*f1;
    193193    psF32 f0 = PAR[PM_PAR_SKY] + z0;
     194
     195    if (!isfinite(z0)) {
     196        fprintf(stderr, "z0 is not finite for %f %f %f %f %f.  Parameters: \n", X, Y, radius, z, f1);
     197        fprintf(stderr, "%f %f %f %f %f %f %f %f\n", PAR[0], PAR[1], PAR[2], PAR[3], PAR[4],
     198            PAR[5], PAR[6], PAR[7]);
     199    }
    194200
    195201    assert (isfinite(f2));
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmFootprintCullPeaks.c

    r32827 r33638  
    178178            psArray *myFP = pmFootprintsFind(subImg, threshold, 5);
    179179            if (!myFP) {
    180                 psWarning ("missing footprint?");
     180                psWarning ("missing footprint? threshold: %.f", threshold);
    181181                continue;
    182182            }
    183183            if (!myFP->n) {
    184                 psWarning ("empty footprint?");
     184                psWarning ("empty footprint? threshold: %.f", threshold);
    185185                psFree (myFP);
    186186                continue;
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmModelUtils.c

    r32347 r33638  
    144144
    145145    *Io = source->peak->rawFlux;
     146
     147#ifndef ALLOW_NONFINITE_PEAK
     148    // Gene says fail of peak !finite
     149    if (!isfinite(*Io)) return false;
     150#else
     151    // This is the way it used to be. Somtimes an infinite value Io made it's way down the pipeline
     152    // causing assertion failures
    146153    if (!isfinite(*Io) && !source->moments) return false;
    147154
    148155    *Io = source->moments->Peak;
    149156    if (!isfinite(*Io)) return false;
     157#endif
    150158
    151159    return true;
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmPCMdata.c

    r32725 r33638  
    136136            sum += value;
    137137        }
     138    }
     139
     140    if (!(sum > 0.0)) {
     141        // Crazy PSF image print out some debugging information ...
     142        fprintf(stderr, "invalid kernel sum %f found by pmPCMkernelFromPSF\n", sum);    for (int j = psf->yMin; j <= psf->yMax; j++) {
     143            fprintf(stderr, "Row %d\n", j);
     144            for (int i = psf->xMin; i <= psf->xMax; i++) {
     145                double value = source->psfImage->data.F32[y0 + j][x0 + i];
     146                fprintf(stderr, "  %d %f\n", i, value);
     147            }
     148        }
     149        fflush(stderr);
     150        // ... but avoid the asssertion two lines down by escaping
     151        goto escape;
    138152    }
    139153    assert (sum > 0.0);
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmPSFtryFitEXT.c

    r30621 r33638  
    7373            continue;
    7474        }
     75        // If mask object does not exist, mark the source as bad.
     76        // We cannot proceed with it because psImageMaskPixels leaves an uncleared error code last which causes
     77        // psphot to exit with a fault.
     78        if (source->maskObj == NULL) {
     79            psTrace ("psModules.objects", 4, "source %d (%d,%d) : null maskObj\n", i, source->peak->x, source->peak->y);
     80            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL;
     81            continue;
     82        }
    7583
    7684        source->modelEXT = pmSourceModelGuess (source, options->type);
     
    8997
    9098        // clear object mask to define valid pixels
    91         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); // clear the circular mask
     99        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); // clear the circular mask
    92100
    93101        // exclude the poor fits
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourceIO.c

    r32633 r33638  
    5757#define BLANK_HEADERS "BLANK.HEADERS"   // Name of metadata in camera configuration containing header names
    5858                                        // for putting values into a blank PHU
     59static bool pmReadoutReadXSRC(pmFPAfile *file, char * exttype, psMetadata *hduHeader, psString xsrcname, psArray *sources, long *sourceIndex);
     60static bool pmReadoutReadXFIT(pmFPAfile *file, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
     61static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
    5962
    6063// lookup the EXTNAME values used for table data and image header segments
     
    961964        psString dataname = NULL;
    962965        psString deteffname = NULL;
    963         if (!pmSourceIOextnames(&headname, &dataname, &deteffname, NULL, NULL, NULL, file, view)) {
     966        psString xsrcname = NULL;
     967        psString xfitname = NULL;
     968        psString xradname = NULL;
     969
     970        // determine the output table format. Assume if we need to output extendend source
     971        // parameters that they may exist in the input.
     972        // XXX: Perhaps we should use different recipe values.
     973        // I.E. EXTENDED_SOURCE_ANALYSIS_READ or something like that
     974        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
     975        if (!status) {
     976            psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
     977            return false;
     978        }
     979        // if this is not TRUE, the output files only contain the psf measurements.
     980        bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS");
     981        bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS");
     982        bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES");
     983
     984        if (!pmSourceIOextnames(&headname, &dataname, &deteffname,
     985                XSRC_OUTPUT ? &xsrcname : NULL,
     986                XFIT_OUTPUT ? &xfitname : NULL,
     987                XRAD_OUTPUT ? &xradname : NULL,
     988                file, view)) {
    964989            return false;
    965990        }
     
    10391064            }
    10401065
     1066            long *sourceIndex = NULL;
     1067            if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT) {
     1068                long seq_max = -1;
     1069                for (long i = sources->n -1; i >= 0; i--) {
     1070                    pmSource *source = sources->data[i];
     1071                    if (source->seq < 0) {
     1072                        // This can happen cmf files that have been corrupted
     1073                        psError(PS_ERR_IO, true, "seq < 0 for source %ld: Suspect %s is corrupt", i, file->origname);
     1074                        return false;
     1075                    }
     1076                    if (source->seq > seq_max) {
     1077                        seq_max = source->seq;
     1078                    }
     1079                }
     1080                sourceIndex = psAlloc((seq_max + 1) * sizeof(long));
     1081                for (long i = 0; i < seq_max; i++) {
     1082                    sourceIndex[i] = -1;
     1083                }
     1084                for (long i = 0; i < sources->n; i++) {
     1085                    pmSource *source = sources->data[i];
     1086                    sourceIndex[source->seq] = i;
     1087                }
     1088            }
     1089            if (XSRC_OUTPUT && xsrcname) {
     1090                if (!pmReadoutReadXSRC(file, exttype, hdu->header, xsrcname, sources, sourceIndex)) {
     1091                    // XXX: is this an error?
     1092                    psErrorClear();
     1093                }
     1094                psFree(xsrcname);
     1095            }
     1096            if (XFIT_OUTPUT && xfitname) {
     1097                if (!pmReadoutReadXFIT(file, exttype, hdu->header, xfitname, sources, sourceIndex)) {
     1098                    // XXX: is this an error?
     1099                    psErrorClear();
     1100                }
     1101                psFree(xfitname);
     1102            }
     1103            if (XRAD_OUTPUT && xradname) {
     1104                if (!pmReadoutReadXRAD(file, readout, exttype, hdu->header, xradname, sources, sourceIndex)) {
     1105                    // XXX: is this an error?
     1106                    psErrorClear();
     1107                }
     1108                psFree(xradname);
     1109            }
     1110            psFree(sourceIndex);
     1111
    10411112            if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) {
    10421113#if 0
     
    11651236}
    11661237
    1167 
     1238// XXX: We might be able to macroize this and reuse for the other types
     1239
     1240static bool pmReadoutReadXSRC(pmFPAfile *file, char *exttype, psMetadata *hduHeader, psString xsrcname, psArray *sources, long *sourceIndex)
     1241{
     1242    if (!psFitsMoveExtName (file->fits, xsrcname)) {
     1243        psError(PS_ERR_UNKNOWN, false, "cannot find xsrc extension %s in %s", xsrcname, file->filename);
     1244        return false;
     1245    }
     1246
     1247    psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1248    if (!tableHeader) psAbort("cannot read table header");
     1249
     1250    char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1251    if (!xtension) psAbort("cannot read table type");
     1252    if (strcmp (xtension, "BINTABLE")) {
     1253        psWarning ("no binary table in extension %s, skipping\n", xsrcname);
     1254        return false;
     1255    }
     1256
     1257    // XXX these are case-sensitive since the EXTYPE is case-sensitive
     1258    bool status = false;
     1259    if (file->type == PM_FPA_FILE_CMF) {
     1260        if (!strcmp (exttype, "PS1_SV1")) {
     1261            status  = pmSourcesRead_CMF_PS1_SV1_XSRC (file->fits, hduHeader, sources, sourceIndex);
     1262        }
     1263    }
     1264    psFree(tableHeader);
     1265    return status;
     1266}
     1267
     1268static bool pmReadoutReadXFIT(pmFPAfile *file, char *exttype, psMetadata *hduHeader, psString extname, psArray *sources, long *sourceIndex)
     1269{
     1270    if (!psFitsMoveExtName (file->fits, extname)) {
     1271        psError(PS_ERR_UNKNOWN, false, "cannot find extension %s in %s", extname, file->filename);
     1272        return false;
     1273    }
     1274
     1275    psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1276    if (!tableHeader) psAbort("cannot read table header");
     1277
     1278    char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1279    if (!xtension) psAbort("cannot read table type");
     1280    if (strcmp (xtension, "BINTABLE")) {
     1281        psWarning ("no binary table in extension %s, skipping\n", extname);
     1282        return false;
     1283    }
     1284
     1285    // XXX these are case-sensitive since the EXTYPE is case-sensitive
     1286    bool status = false;
     1287    if (file->type == PM_FPA_FILE_CMF) {
     1288        if (!strcmp (exttype, "PS1_SV1")) {
     1289            status  = pmSourcesRead_CMF_PS1_SV1_XFIT (file->fits, hduHeader, sources, sourceIndex);
     1290        }
     1291    }
     1292    psFree(tableHeader);
     1293    return status;
     1294}
     1295static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char *exttype, psMetadata *hduHeader, psString extname, psArray *sources, long *sourceIndex)
     1296{
     1297    if (!psFitsMoveExtName (file->fits, extname)) {
     1298        psError(PS_ERR_UNKNOWN, false, "cannot find extension %s in %s", extname, file->filename);
     1299        return false;
     1300    }
     1301
     1302    psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1303    if (!tableHeader) psAbort("cannot read table header");
     1304
     1305    char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1306    if (!xtension) psAbort("cannot read table type");
     1307    if (strcmp (xtension, "BINTABLE")) {
     1308        psWarning ("no binary table in extension %s, skipping\n", extname);
     1309        return false;
     1310    }
     1311
     1312    // XXX these are case-sensitive since the EXTYPE is case-sensitive
     1313    bool status = false;
     1314    if (file->type == PM_FPA_FILE_CMF) {
     1315        if (!strcmp (exttype, "PS1_SV1")) {
     1316            status  = pmSourcesRead_CMF_PS1_SV1_XRAD (file->fits, readout, hduHeader, sources, sourceIndex);
     1317        }
     1318    }
     1319    psFree(tableHeader);
     1320    return status;
     1321}
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourceIO.h

    r32633 r33638  
    9393psArray *pmSourcesRead_CMF_PS1_V4 (psFits *fits, psMetadata *header);
    9494psArray *pmSourcesRead_CMF_PS1_SV1 (psFits *fits, psMetadata *header);
     95bool pmSourcesRead_CMF_PS1_SV1_XSRC (psFits *fits, psMetadata *header, psArray *sources, long *);
     96bool pmSourcesRead_CMF_PS1_SV1_XFIT (psFits *fits, psMetadata *header, psArray *sources, long *);
     97bool pmSourcesRead_CMF_PS1_SV1_XRAD (psFits *fits, pmReadout *readout, psMetadata *header, psArray *sources, long *);
    9598psArray *pmSourcesRead_CMF_PS1_DV1 (psFits *fits, psMetadata *header);
    9699psArray *pmSourcesRead_CMF_PS1_DV2 (psFits *fits, psMetadata *header);
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c

    r32347 r33638  
    539539}
    540540
     541bool pmSourcesRead_CMF_PS1_SV1_XSRC(psFits *fits, psMetadata *hduHeader, psArray *sources, long *sourceIndex)
     542{
     543    PS_ASSERT_PTR_NON_NULL(fits, false);
     544    PS_ASSERT_PTR_NON_NULL(sources, false);
     545
     546    bool status;
     547    long numSources = psFitsTableSize(fits); // Number of sources in table
     548    if (numSources == 0) {
     549        psError(psErrorCodeLast(), false, "XSRC Table contains no entries\n");
     550        return false;
     551    }
     552
     553    // petrosian mags are not saved, we need to calculate fluxes. For this we need exptime and zero point
     554    float zeropt = psMetadataLookupF32(&status, hduHeader, "FPA.ZP");
     555    float exptime = psMetadataLookupF32(&status, hduHeader, "EXPTIME");
     556    float magOffset = zeropt + 2.5*log10(exptime);
     557
     558    for (long i = 0; i < numSources; i++) {
     559        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
     560        if (!row) {
     561            psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i);
     562            psFree(row);
     563            return false;
     564        }
     565        // Find the source with this sequence number.
     566        // XXX: I am assuming that sources is sorted in order of seq
     567        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
     568        pmSource *source = NULL;
     569#ifndef ASSUME_SORTED
     570        long j = seq < sources->n ? seq : sources->n - 1;
     571        for (; j >= 0; j--) {
     572            source = sources->data[j];
     573            if (source->seq == seq) {
     574                break;
     575            }
     576        }
     577#else
     578        long j = sourceIndex[seq];
     579        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
     580        source = sources->data[j];
     581#endif
     582        if (!source) {
     583            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
     584            psFree(row);
     585            return false;
     586        }
     587
     588        if (!source->extpars) {
     589            source->extpars = pmSourceExtendedParsAlloc ();
     590        }
     591        pmSourceExtendedPars *extpars = source->extpars;
     592
     593        // Assume that X_EXT Y_EXT and sigmas match the psf src so skip
     594
     595        // We don't have enough information to calculate the major and minor axis. Set major to 1. Should we scale this by
     596        // psf size or something?
     597        extpars->axes.major = 1.0;
     598        extpars->axes.minor = extpars->axes.major * psMetadataLookupF32(&status, row, "F25_ARATIO");
     599        extpars->axes.theta = psMetadataLookupF32(&status, row, "F25_THETA");
     600
     601        float mag = psMetadataLookupF32(&status, row, "PETRO_MAG");
     602        float magErr = psMetadataLookupF32(&status, row, "PETRO_MAG_ERR");
     603        if (isfinite(mag)) {
     604            extpars->petrosianFlux    = pow(10., (magOffset - mag) / 2.5);
     605            if (isfinite(magErr)) {
     606                extpars->petrosianFluxErr = extpars->petrosianFlux / magErr;
     607            }
     608        }
     609
     610        extpars->petrosianRadius   = psMetadataLookupF32(&status, row, "PETRO_RADIUS");
     611        extpars->petrosianRadiusErr= psMetadataLookupF32(&status, row, "PETRO_RADIUS_ERR");
     612        extpars->petrosianR50      = psMetadataLookupF32(&status, row, "PETRO_RADIUS_50");
     613        extpars->petrosianR50Err   = psMetadataLookupF32(&status, row, "PETRO_RADIUS_50_ERR");
     614        extpars->petrosianR90      = psMetadataLookupF32(&status, row, "PETRO_RADIUS_90");
     615        extpars->petrosianR90Err   = psMetadataLookupF32(&status, row, "PETRO_RADIUS_90_ERR");
     616        extpars->petrosianFill     = psMetadataLookupF32(&status, row, "PETRO_FILL");
     617
     618        psVector *radSB   = psMetadataLookupVector(&status, row, "PROF_SB");
     619        psVector *radFlux = psMetadataLookupVector(&status, row, "PROF_FLUX");
     620        psVector *radFill = psMetadataLookupVector(&status, row, "PROF_FILL");
     621
     622        if (radSB && radSB->n > 0) {
     623            extpars->radProfile = pmSourceRadialProfileAlloc();
     624            extpars->radProfile->binSB   = psMemIncrRefCounter(radSB);
     625            extpars->radProfile->binSum   = psMemIncrRefCounter(radFlux);
     626            extpars->radProfile->binFill = psMemIncrRefCounter(radFill);
     627        }
     628
     629        psFree(row);
     630    }
     631
     632    return true;
     633}
     634
    541635// XXX this layout is still the same as PS1_DEV_1
    542636bool pmSourcesWrite_CMF_PS1_SV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname)
     
    684778    psFree (outhead);
    685779    psFree (table);
     780    return true;
     781}
     782
     783bool pmSourcesRead_CMF_PS1_SV1_XFIT(psFits *fits, psMetadata *hduHeader, psArray *sources, long *sourceIndex)
     784{
     785    PS_ASSERT_PTR_NON_NULL(fits, false);
     786    PS_ASSERT_PTR_NON_NULL(sources, false);
     787
     788    bool status;
     789    long numSources = psFitsTableSize(fits); // Number of sources in table
     790    if (numSources == 0) {
     791        psError(psErrorCodeLast(), false, "XFIT Table contains no entries\n");
     792        return false;
     793    }
     794
     795    for (long i = 0; i < numSources; i++) {
     796        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
     797        if (!row) {
     798            psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i);
     799            psFree(row);
     800            return false;
     801        }
     802        // Find the source with this sequence number.
     803        // XXX: I am assuming that sources is sorted in order of seq.
     804        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
     805        long j = seq < sources->n ? seq : sources->n - 1;
     806        pmSource *source = NULL;
     807        for (; j >= 0; j--) {
     808            source = sources->data[j];
     809            if (source->seq == seq) {
     810                break;
     811            }
     812        }
     813        if (!source) {
     814            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
     815            psFree(row);
     816            return false;
     817        }
     818        if (!source->modelFits) {
     819            // XXX: where to find the number of models to expect?
     820            source->modelFits = psArrayAllocEmpty(5);
     821        }
     822        psString modelName = psMetadataLookupStr(&status, row, "MODEL_TYPE");
     823        if (!modelName) {
     824            psError(PS_ERR_UNKNOWN, true, "Failed to find model name for row %ld\n", i);
     825            psFree(row);
     826            return false;
     827        }
     828        pmModelType modelType = pmModelClassGetType(modelName);
     829        if (modelType < 0) {
     830            psError(PS_ERR_UNKNOWN, true, "Failed to find model type for %s\n", modelName);
     831            psFree(row);
     832            return false;
     833        }
     834        pmModel *model = pmModelAlloc(modelType);
     835
     836        psF32 *PAR = model->params->data.F32;
     837        psF32 *dPAR = model->dparams->data.F32;
     838
     839        PAR[PM_PAR_XPOS] = psMetadataLookupF32(&status, row, "X_EXT");
     840        PAR[PM_PAR_YPOS] = psMetadataLookupF32(&status, row, "Y_EXT");
     841        dPAR[PM_PAR_XPOS] = psMetadataLookupF32(&status, row, "X_EXT_SIG");
     842        dPAR[PM_PAR_YPOS] = psMetadataLookupF32(&status, row, "Y_EXT_SIG");
     843
     844        model->mag = psMetadataLookupF32(&status, row, "EXT_INST_MAG");
     845        model->magErr = psMetadataLookupF32(&status, row, "EXT_INST_MAG_SIG");
     846
     847        psEllipseAxes axes;
     848        axes.major = psMetadataLookupF32(&status, row, "EXT_WIDTH_MAJ");
     849        axes.minor = psMetadataLookupF32(&status, row, "EXT_WIDTH_MIN");
     850        axes.theta = psMetadataLookupF32(&status, row, "EXT_THETA");
     851        if (!pmPSF_AxesToModel(PAR, axes, modelType)) {
     852            // Do we need to fail here or can this happen?
     853            psError(PS_ERR_UNKNOWN, false, "Failed to convert psf axes to model");
     854            psFree(model);
     855            psFree(row);
     856            return false;
     857        }
     858        // XXX: clean this up
     859        if (model->params->n > 7) {
     860            PAR[7] = psMetadataLookupF32(&status, row, "EXT_PAR_07");
     861        }
     862        // read the covariance matrix
     863        int nparams = model->params->n;
     864        psImage *covar = psImageAlloc(nparams, nparams, PS_TYPE_F32);
     865        for (int y = 0; y < nparams; y++) {
     866            for (int x = 0; x < nparams; x++) {
     867                char name[64];
     868                snprintf(name, 64, "EXT_COVAR_%02d_%02d", y, x);
     869                covar->data.F32[y][x] = psMetadataLookupF32(&status, row, name);
     870            }
     871        }
     872        model->covar = covar;
     873
     874        psArrayAdd(source->modelFits, 1, model);
     875        psFree(model);
     876
     877        psFree(row);
     878    }
     879
    686880    return true;
    687881}
     
    8311025    return true;
    8321026}
     1027
     1028bool pmSourcesRead_CMF_PS1_SV1_XRAD(psFits *fits, pmReadout *readout, psMetadata *hduHeader, psArray *sources, long *sourceIndex)
     1029{
     1030    PS_ASSERT_PTR_NON_NULL(fits, false);
     1031    PS_ASSERT_PTR_NON_NULL(sources, false);
     1032
     1033    bool status;
     1034    long numSources = psFitsTableSize(fits); // Number of sources in table
     1035    if (numSources == 0) {
     1036        psError(psErrorCodeLast(), false, "XRAD Table contains no entries\n");
     1037        return false;
     1038    }
     1039
     1040    long       seq_first = -1;
     1041    long       seq_last = -1;
     1042    psVector   *fwhmValues = psVectorAllocEmpty(10, PS_TYPE_F32);
     1043    long       max_entries = -1;
     1044    long       num_entries = -1;
     1045
     1046    for (long i = 0; i < numSources; i++) {
     1047        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
     1048        if (!row) {
     1049            psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i);
     1050            psFree(row);
     1051            return false;
     1052        }
     1053        // Find the source with this sequence number.
     1054        // XXX: I am assuming that sources is sorted in order of seq.
     1055        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
     1056        long j = seq < sources->n ? seq : sources->n - 1;
     1057        pmSource *source = NULL;
     1058        for (; j >= 0; j--) {
     1059            source = sources->data[j];
     1060            if (source->seq == seq) {
     1061                break;
     1062            }
     1063        }
     1064        if (!source) {
     1065            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
     1066            psFree(row);
     1067            return false;
     1068        }
     1069        if (seq_first == -1) {
     1070            seq_first = seq;
     1071        }
     1072        if (seq == seq_first) {
     1073            psF32 value = psMetadataLookupF32(&status, row, "PSF_FWHM");
     1074            psVectorAppend(fwhmValues, value);
     1075        }
     1076        if (seq == seq_last) {
     1077            num_entries++;
     1078        } else {
     1079            num_entries = 1;
     1080            seq_last = seq;
     1081        }
     1082        if (num_entries > max_entries) {
     1083            max_entries = num_entries;
     1084        }
     1085
     1086        if (!source->radialAper) {
     1087            // XXX: where to find the number of models to expect?
     1088            source->radialAper = psArrayAllocEmpty(5);
     1089        }
     1090        pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc();
     1091
     1092        radialAper->flux = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FLUX"));
     1093        radialAper->fluxStdev = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FLUX_STDEV"));
     1094        radialAper->fluxErr = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FLUX_ERR"));
     1095        radialAper->fill = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FILL"));
     1096
     1097        psArrayAdd(source->radialAper, 1, radialAper);
     1098
     1099        psFree(radialAper);
     1100        psFree(row);
     1101    }
     1102
     1103    // check for consistency between the length of fwhmValues and the maximum number of entries for each row
     1104    if (fwhmValues->n != max_entries) {
     1105        psError(PS_ERR_PROGRAMMING, true, "number of PSF_FWHM values found %ld does not match expected number: %ld\n",
     1106            fwhmValues->n, max_entries);
     1107        psAssert(0, "fixme");
     1108    }
     1109
     1110    if (!readout->analysis) {
     1111        readout->analysis = psMetadataAlloc();
     1112    }
     1113
     1114    psMetadataAddVector(readout->analysis, PS_LIST_TAIL, "STACK.PSF.FWHM.VALUES", PS_META_REPLACE, "PSF sizes", fwhmValues);
     1115    psFree(fwhmValues);
     1116
     1117    return true;
     1118}
  • branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c

    r33085 r33638  
    569569        }
    570570    }
    571 
    572571    return (true);
    573572}
Note: See TracChangeset for help on using the changeset viewer.