IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 3, 2010, 5:38:55 PM (16 years ago)
Author:
Paul Price
Message:

In the process of reworking ppMops to conform to new interface format, which is SMF-like.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppTranslate/src/ppMopsRead.c

    r28027 r28209  
    2727        }
    2828
    29         psS64 diffSkyfileId = psMetadataLookupS64(NULL, header, "IMAGEID"); // Identifier for image
    30         if (diffSkyfileId == 0) {
    31             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find identifier for image %d", i);
    32             return false;
    33         }
    34 
    3529        if (!psFitsMoveExtName(fits, "SkyChip.psf")) {
    3630            psError(PS_ERR_IO, false, "Unable to move to HDU with detections");
     
    4842        }
    4943        ppMopsDetections *det = ppMopsDetectionsAlloc(size);
    50 
    51         psTrace("ppMops.read", 3, "Reading %ld rows from %s\n", size, (const char*)inNames->data[i]);
     44        det->header = header;
    5245
    5346        det->raBoresight = psMemIncrRefCounter(psMetadataLookupStr(NULL, header, "FPA.RA"));
     
    6457                             psMetadataLookupF32(NULL, header, "FWHM_MIN"));
    6558
    66         int naxis1 = psMetadataLookupS32(NULL, header, "IMNAXIS1"); // Number of columns
    67         int naxis2 = psMetadataLookupS32(NULL, header, "IMNAXIS2"); // Number of rows
     59        det->naxis1 = psMetadataLookupS32(NULL, header, "IMNAXIS1");
     60        det->naxis2 = psMetadataLookupS32(NULL, header, "IMNAXIS2");
    6861
    69         psFree(header);
    70 
    71         psArray *table = psFitsReadTable(fits); // Table of interest
     62        det->table = psFitsReadTableAllColumns(fits); // Table of interest
    7263        if (!table) {
    73             psError(PS_ERR_IO, false, "Unable to read table %d", i);
     64            psError(psErrorCodeLast(), false, "Unable to read table %d", i);
    7465            return false;
    7566        }
    7667        psFitsClose(fits);
    7768
    78         double plateScale = 0.0;        // Plate scale
    79         long numGood = 0;               // Number of good rows
    80         for (long j = 0; j < size; j++) {
    81             psMetadata *row = table->data[j]; // Row of interest
     69        psTrace("ppMops.read", 2, "Read %ld rows from %s\n", numGood, (const char*)inNames->data[i]);
    8270
    83             psU32 flags = psMetadataLookupU32(NULL, row, "FLAGS");
    84             if (flags & SOURCE_MASK) {
    85                 psTrace("ppMops.read", 10, "Discarding row %ld from input %d because of flags: %ud", j, i, flags);
    86                 continue;
    87             }
    88 
    89             det->x->data.F32[numGood] = psMetadataLookupF32(NULL, row, "X_PSF");
    90             det->y->data.F32[numGood] = psMetadataLookupF32(NULL, row, "Y_PSF");
    91             det->ra->data.F64[numGood] = DEG_TO_RAD(psMetadataLookupF64(NULL, row, "RA_PSF"));
    92             det->dec->data.F64[numGood] = DEG_TO_RAD(psMetadataLookupF64(NULL, row, "DEC_PSF"));
    93             det->mag->data.F32[numGood] = psMetadataLookupF32(NULL, row, "PSF_INST_MAG");
    94             det->magErr->data.F32[numGood] = psMetadataLookupF32(NULL, row, "PSF_INST_MAG_SIG");
    95             det->chi2->data.F32[numGood] = psMetadataLookupF32(NULL, row, "PSF_CHISQ");
    96             det->dof->data.S32[numGood] = psMetadataLookupS32(NULL, row, "PSF_NDOF");
    97             det->cr->data.F32[numGood] = psMetadataLookupF32(NULL, row, "CR_NSIGMA");
    98             det->extended->data.F32[numGood] = psMetadataLookupF32(NULL, row, "EXT_NSIGMA");
    99             det->psfMajor->data.F32[numGood] = psMetadataLookupF32(NULL, row, "PSF_MAJOR");
    100             det->psfMinor->data.F32[numGood] = psMetadataLookupF32(NULL, row, "PSF_MINOR");
    101             det->psfTheta->data.F32[numGood] = psMetadataLookupF32(NULL, row, "PSF_THETA");
    102             det->quality->data.F32[numGood] = psMetadataLookupF32(NULL, row, "PSF_QF");
    103             det->numPix->data.S32[numGood] = psMetadataLookupS32(NULL, row, "PSF_NPIX");
    104             det->xxMoment->data.F32[numGood] = psMetadataLookupF32(NULL, row, "MOMENTS_XX");
    105             det->xyMoment->data.F32[numGood] = psMetadataLookupF32(NULL, row, "MOMENTS_XY");
    106             det->yyMoment->data.F32[numGood] = psMetadataLookupF32(NULL, row, "MOMENTS_YY");
    107             det->flags->data.U32[numGood] = psMetadataLookupU32(NULL, row, "FLAGS");
    108             det->diffSkyfileId->data.S64[numGood] = diffSkyfileId;
    109             det->naxis1->data.S32[numGood] = naxis1;
    110             det->naxis2->data.S32[numGood] = naxis2;
    111 
    112             det->nPos->data.S32[numGood] = psMetadataLookupS32(NULL, row, "DIFF_NPOS");
    113             det->fPos->data.F32[numGood] = psMetadataLookupF32(NULL, row, "DIFF_FRATIO");
    114             det->nRatioBad->data.F32[numGood] = psMetadataLookupF32(NULL, row, "DIFF_NRATIO_BAD");
    115             det->nRatioMask->data.F32[numGood] = psMetadataLookupF32(NULL, row, "DIFF_NRATIO_MASK");
    116             det->nRatioAll->data.F32[numGood] = psMetadataLookupF32(NULL, row, "DIFF_NRATIO_ALL");
    117 
    118             // Calculate error in RA, Dec
    119             double xErr = psMetadataLookupF64(NULL, row, "X_PSF_SIG");
    120             double yErr = psMetadataLookupF64(NULL, row, "Y_PSF_SIG");
    121             double scale = psMetadataLookupF64(NULL, row, "PLTSCALE");
    122             double angle = psMetadataLookupF64(NULL, row, "POSANGLE");
    123 
    124             if (!isfinite(det->x->data.F32[numGood]) || !isfinite(det->y->data.F32[numGood]) ||
    125                 !isfinite(det->ra->data.F64[numGood]) || !isfinite(det->dec->data.F64[numGood]) ||
    126                 !isfinite(det->mag->data.F32[numGood]) || !isfinite(det->magErr->data.F32[numGood]) ||
    127                 !isfinite(xErr) || !isfinite(yErr) || !isfinite(scale) || !isfinite(angle)) {
    128                 psTrace("ppMops.read", 10,
    129                         "Discarding row %ld from input %d because of non-finite values: "
    130                         "%f %f %lf %lf %f %f %f %f %f %f",
    131                         j, i,
    132                         det->x->data.F32[numGood], det->y->data.F32[numGood],
    133                         det->ra->data.F64[numGood], det->dec->data.F64[numGood],
    134                         det->mag->data.F32[numGood], det->magErr->data.F32[numGood],
    135                         xErr, yErr, scale, angle);
    136                 continue;
    137             }
    138 
    139             // XXX Not at all sure I've got the angles around the right way here...
    140             double cosAngle = cos(angle), sinAngle = sin(angle);
    141             double cosAngle2 = PS_SQR(cosAngle), sinAngle2 = PS_SQR(sinAngle);
    142             double xErr2 = PS_SQR(xErr), yErr2 = PS_SQR(yErr);
    143             double errScale = scale / 3600.0;
    144             det->raErr->data.F64[numGood] = errScale * sqrt(cosAngle2 * xErr2 + sinAngle2 * yErr2);
    145             det->decErr->data.F64[numGood] = errScale * sqrt(sinAngle2 * xErr2 + cosAngle2 * yErr2);
    146 
    147             det->mask->data.U8[numGood] = 0;
    148             plateScale += scale;
    149             numGood++;
    150         }
    151         det->seeing *= plateScale / numGood;
    152 
    153         det->x->n = numGood;
    154         det->y->n = numGood;
    155         det->ra->n = numGood;
    156         det->dec->n = numGood;
    157         det->raErr->n = numGood;
    158         det->decErr->n = numGood;
    159         det->mag->n = numGood;
    160         det->magErr->n = numGood;
    161         det->chi2->n = numGood;
    162         det->dof->n = numGood;
    163         det->cr->n = numGood;
    164         det->extended->n = numGood;
    165         det->psfMajor->n = numGood;
    166         det->psfMinor->n = numGood;
    167         det->psfTheta->n = numGood;
    168         det->quality->n = numGood;
    169         det->numPix->n = numGood;
    170         det->xxMoment->n = numGood;
    171         det->xyMoment->n = numGood;
    172         det->yyMoment->n = numGood;
    173         det->flags->n = numGood;
    174         det->diffSkyfileId->n = numGood;
    175         det->naxis1->n = numGood;
    176         det->naxis2->n = numGood;
    177         det->mask->n = numGood;
    178         det->nPos->n = numGood;
    179         det->fPos->n = numGood;
    180         det->nRatioBad->n = numGood;
    181         det->nRatioMask->n = numGood;
    182         det->nRatioAll->n = numGood;
    183 
    184         det->num = numGood;
    185 
    186         if (isfinite(args->zp) && numGood > 0) {
    187             psBinaryOp(det->mag, det->mag, "+", psScalarAlloc(args->zp, PS_TYPE_F32));
     71        det->ra = psMemIncrRefCounter(psMetadataLookupVector(NULL, table, "RA_PSF"));
     72        det->dec = psMemIncrRefCounter(psMetadataLookupVector(NULL, table, "DEC_PSF"));
     73        det->x = psMemIncrRefCounter(psMetadataLookupVector(NULL, table, "X_PSF"));
     74        det->y = psMemIncrRefCounter(psMetadataLookupVector(NULL, table, "Y_PSF"));
     75        if (!det->ra || !det->dec || !det->x || !det->y) {
     76            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find all of RA, Dec, X and Y columns");
     77            return false;
    18878        }
    18979
    190         psTrace("ppMops.read", 2, "Read %ld good rows from %s\n", numGood, (const char*)inNames->data[i]);
    191 
    192         psFree(table);
    19380        detections->data[i] = det;
    19481    }
Note: See TracChangeset for help on using the changeset viewer.