IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 11, 2011, 4:31:07 PM (15 years ago)
Author:
bills
Message:

Oops. Thought this has been chedked in

File:
1 edited

Legend:

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

    r30656 r32396  
    9595        psFree(header);
    9696
     97#ifndef USE_OLD_READ_TABLE
     98        // use new fits table functions
     99
     100        psFitsTable *table = psFitsReadTableNew(fits); // Table of interest
     101        if (!table) {
     102            psError(PS_ERR_IO, false, "Unable to read table %d", i);
     103            return false;
     104        }
     105        psFitsClose(fits);
     106
     107        double plateScale = 0.0;        // Plate scale
     108        long numGood = 0;               // Number of good rows
     109        for (long row = 0; row < size; row++) {
     110
     111            psU32 flags = psFitsTableGetU32(NULL, table, row, "FLAGS");
     112            if (flags & SOURCE_MASK) {
     113                psTrace("ppMops.read", 10, "Discarding row %ld from input %d because of flags: %ud", row, i, flags);
     114                continue;
     115            }
     116
     117            det->x->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "X_PSF");
     118            det->y->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "Y_PSF");
     119            det->ra->data.F64[numGood] = DEG_TO_RAD(psFitsTableGetF64(NULL, table, row, "RA_PSF"));
     120            det->dec->data.F64[numGood] = DEG_TO_RAD(psFitsTableGetF64(NULL, table, row, "DEC_PSF"));
     121            det->mag->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_INST_MAG");
     122            det->magErr->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_INST_MAG_SIG");
     123            det->chi2->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_CHISQ");
     124            det->dof->data.S32[numGood] = psFitsTableGetS32(NULL, table, row, "PSF_NDOF");
     125            det->cr->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "CR_NSIGMA");
     126            det->extended->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "EXT_NSIGMA");
     127            det->psfMajor->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_MAJOR");
     128            det->psfMinor->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_MINOR");
     129            det->psfTheta->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_THETA");
     130            det->quality->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_QF");
     131            det->numPix->data.S32[numGood] = psFitsTableGetS32(NULL, table, row, "PSF_NPIX");
     132            det->xxMoment->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "MOMENTS_XX");
     133            det->xyMoment->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "MOMENTS_XY");
     134            det->yyMoment->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "MOMENTS_YY");
     135            det->flags->data.U32[numGood] = psFitsTableGetU32(NULL, table, row, "FLAGS");
     136            det->diffSkyfileId->data.S64[numGood] = diffSkyfileId;
     137            det->naxis1->data.S32[numGood] = naxis1;
     138            det->naxis2->data.S32[numGood] = naxis2;
     139            det->nPos->data.S32[numGood] = psFitsTableGetS32(NULL, table, row, "DIFF_NPOS");
     140            det->fPos->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_FRATIO");
     141            det->nRatioBad->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_NRATIO_BAD");
     142            det->nRatioMask->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_NRATIO_MASK");
     143            det->nRatioAll->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_NRATIO_ALL");
     144
     145            //Additions of 2010-10-25
     146            if (args->version == 2) {
     147              //Values are set only if the version is 2
     148              if (skyChipPsfVersion == 2) {
     149                det->psfInstFlux->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_INST_FLUX");
     150                det->psfInstFluxSig->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_INST_FLUX_SIG");
     151                det->apMag->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "AP_MAG");
     152                det->apMagRaw->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "AP_MAG_RAW");
     153                det->apMagRadius->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "AP_MAG_RADIUS");
     154                det->apFlux->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "AP_FLUX");
     155                det->apFluxSig->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "AP_FLUX_SIG");
     156                det->peakFluxAsMag->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PEAK_FLUX_AS_MAG");
     157                det->calPsfMag->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "CAL_PSF_MAG");
     158                det->calPsfMagSig->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "CAL_PSF_MAG_SIG");
     159                det->sky->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "SKY");
     160                det->skySig->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "SKY_SIGMA");
     161                det->qualityPerfect->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "PSF_QF_PERFECT");
     162                det->momentsR1->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "MOMENTS_R1");
     163                det->momentsRH->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "MOMENTS_RH");
     164                det->kronFlux->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "KRON_FLUX");
     165                det->kronFluxErr->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "KRON_FLUX_ERR");
     166                det->kronFluxInner->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "KRON_FLUX_INNER");
     167                det->kronFluxOuter->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "KRON_FLUX_OUTER");
     168                det->diffRP->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_R_P");
     169                det->diffSnP->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_SN_P");
     170                det->diffRM->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_R_M");
     171                det->diffSnM->data.F32[numGood] = psFitsTableGetF32(NULL, table, row, "DIFF_SN_M");
     172                det->flags2->data.U32[numGood] = psFitsTableGetU32(NULL, table, row, "FLAGS2");
     173                det->ippIdet->data.U32[numGood] = psFitsTableGetU32(NULL, table, row, "IPP_IDET");
     174                det->nFrames->data.U16[numGood] = psFitsTableGetU16(NULL, table, row, "N_FRAMES");
     175                det->padding->data.S16[numGood] = psFitsTableGetS16(NULL, table, row, "PADDING");
     176              } else {
     177                det->psfInstFlux->data.F32[numGood] = NAN;
     178                det->psfInstFluxSig->data.F32[numGood] = NAN;
     179                det->apMag->data.F32[numGood] = NAN;
     180                det->apMagRaw->data.F32[numGood] = NAN;
     181                det->apMagRadius->data.F32[numGood] = NAN;
     182                det->apFlux->data.F32[numGood] = NAN;
     183                det->apFluxSig->data.F32[numGood] = NAN;
     184                det->peakFluxAsMag->data.F32[numGood] = NAN;
     185                det->calPsfMag->data.F32[numGood] = NAN;
     186                det->calPsfMagSig->data.F32[numGood] = NAN;
     187                det->sky->data.F32[numGood] = NAN;
     188                det->skySig->data.F32[numGood] = NAN;
     189                det->qualityPerfect->data.F32[numGood] = NAN;
     190                det->momentsR1->data.F32[numGood] = NAN;
     191                det->momentsRH->data.F32[numGood] = NAN;
     192                det->kronFlux->data.F32[numGood] = NAN;
     193                det->kronFluxErr->data.F32[numGood] = NAN;
     194                det->kronFluxInner->data.F32[numGood] = NAN;
     195                det->kronFluxOuter->data.F32[numGood] = NAN;
     196                det->diffRP->data.F32[numGood] = NAN;
     197                det->diffSnP->data.F32[numGood] = NAN;
     198                det->diffRM->data.F32[numGood] = NAN;
     199                det->diffSnM->data.F32[numGood] = NAN;
     200                det->flags2->data.U32[numGood] = 0;
     201                det->ippIdet->data.U32[numGood] = 0;
     202                det->nFrames->data.U16[numGood] = 0;
     203                det->padding->data.S16[numGood] = 0;
     204              }
     205            }
     206
     207            // Calculate error in RA, Dec
     208            double xErr = psFitsTableGetF64(NULL, table, row, "X_PSF_SIG"); //SC: Warning! Promotion of F32
     209            double yErr = psFitsTableGetF64(NULL, table, row, "Y_PSF_SIG"); //SC: Warning! Promotion of F32
     210            double scale = psFitsTableGetF64(NULL, table, row, "PLTSCALE"); //SC: Warning! Promotion of F32
     211            double angle = psFitsTableGetF64(NULL, table, row, "POSANGLE"); //SC: Warning! Promotion of F32
     212
     213            if (!isfinite(det->x->data.F32[numGood]) || !isfinite(det->y->data.F32[numGood]) ||
     214                !isfinite(det->ra->data.F64[numGood]) || !isfinite(det->dec->data.F64[numGood]) ||
     215                !isfinite(det->mag->data.F32[numGood]) || !isfinite(det->magErr->data.F32[numGood]) ||
     216                !isfinite(xErr) || !isfinite(yErr) || !isfinite(scale) || !isfinite(angle)) {
     217                psTrace("ppMops.read", 10,
     218                        "Discarding row %ld from input %d because of non-finite values: "
     219                        "%f %f %lf %lf %f %f %f %f %f %f",
     220                        row, i,
     221                        det->x->data.F32[numGood], det->y->data.F32[numGood],
     222                        det->ra->data.F64[numGood], det->dec->data.F64[numGood],
     223                        det->mag->data.F32[numGood], det->magErr->data.F32[numGood],
     224                        xErr, yErr, scale, angle);
     225                continue;
     226            }
     227
     228            // XXX Not at all sure I've got the angles around the right way here...
     229            double cosAngle = cos(angle), sinAngle = sin(angle);
     230            double cosAngle2 = PS_SQR(cosAngle), sinAngle2 = PS_SQR(sinAngle);
     231            double xErr2 = PS_SQR(xErr), yErr2 = PS_SQR(yErr);
     232            double errScale = scale / 3600.0;
     233            det->raErr->data.F64[numGood] = errScale * sqrt(cosAngle2 * xErr2 + sinAngle2 * yErr2);
     234            det->decErr->data.F64[numGood] = errScale * sqrt(sinAngle2 * xErr2 + cosAngle2 * yErr2);
     235
     236            det->mask->data.U8[numGood] = 0;
     237            plateScale += scale;
     238            numGood++;
     239        }
     240#else
     241    // OLD way of reading fits tables read it into an array of metadata objects, one for each row. Uses lots and lots
     242    // and lots of memory.
    97243        psArray *table = psFitsReadTable(fits); // Table of interest
    98244        if (!table) {
     
    236382            numGood++;
    237383        }
     384#endif
    238385        det->seeing *= ((float) plateScale) / ((float) numGood);
    239386
Note: See TracChangeset for help on using the changeset viewer.