IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23189


Ignore:
Timestamp:
Mar 5, 2009, 9:18:09 AM (17 years ago)
Author:
Paul Price
Message:

Flag an image as bad if its transparency comes out as NAN (e.g., if no
stars matched). This allows the process to finish, and bad images to
be identified.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceMatch.c

    r21266 r23189  
    6363        pmSource *source = sources->data[i]; // Source of interest
    6464        if (!source) continue;
    65         if (source->mode & SOURCE_MASK) continue;
    66         if (!isfinite(source->psfMag)) continue;
    67         if (!isfinite(source->errMag)) continue;
    68         if (source->psfMag > SOURCE_FAINTEST) continue;
     65        if (source->mode & SOURCE_MASK) continue;
     66        if (!isfinite(source->psfMag)) continue;
     67        if (!isfinite(source->errMag)) continue;
     68        if (source->psfMag > SOURCE_FAINTEST) continue;
    6969
    7070        float xSrc, ySrc;               // Coordinates of source
     
    290290static float sourceMatchRelphotIterate(psVector *trans, // Transparencies
    291291                                       psVector *stars, // Star magnitudes
     292                                       psVector *badImage, // Bad image mask
    292293                                       const psArray *matches, // Array of matches
    293294                                       const psVector *zp, // Zero points for each image (incl. airmass term)
     
    363364    for (int i = 0; i < numImages; i++) {
    364365        trans->data.F32[i] = accum->data.F64[i] / accumErr->data.F64[i];
    365 
     366        if (!isfinite(trans->data.F32[i])) {
     367            badImage->data.U8[i] = 0xFF;
     368        }
    366369        psTrace("psModules.objects", 3, "Transparency for image %d: %f\n", i, trans->data.F32[i]);
    367370    }
     
    379382            }
    380383            int index = match->image->data.U32[j]; // Image index
     384            if (badImage->data.U8[index]) {
     385                continue;
     386            }
    381387            float mag = match->mag->data.F32[j]; // Measured magnitude
    382388            float magErr2 = PS_SQR(match->magErr->data.F32[j]) + sysErr2; // Error in measured magnitude
     
    402408static int sourceMatchRelphotPhotometric(psVector *photo, // Photometric determination
    403409                                         const psVector *trans, // Estimated transparencies
     410                                         const psVector *badImage, // Bad image?
    404411                                         int transIter, // Iterations for transparency
    405412                                         float transClip, // Clipping level for transparency
     
    409416    psAssert(photo && photo->type.type == PS_TYPE_U8, "Need photometric determination");
    410417    psAssert(trans && trans->type.type == PS_TYPE_F32, "Need transparencies");
     418    psAssert(badImage && badImage->type.type == PS_TYPE_U8, "Need bad image determination");
    411419
    412420    int numImages = photo->n;              // Number of images
    413421
    414422    psAssert(trans->n == numImages, "Not enough transparencies: %ld", trans->n);
     423    psAssert(badImage->n == numImages, "Not enough bad image determinations: %ld", badImage->n);
    415424    psAssert(transIter >= 0, "Iterations for transparency must be non-negative: %d", transIter);
    416425    psAssert(transClip > 0, "Clipping level for transparency must be positive: %f", transClip);
     
    421430    stats->clipSigma = transClip;
    422431
    423     if (!psVectorStats(stats, trans, NULL, NULL, 0)) {
     432    if (!psVectorStats(stats, trans, NULL, badImage, 0xFF)) {
    424433        psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on transparencies.");
    425434        psFree(stats);
     
    432441    int numPhoto = 0;                   // Number of photometric images
    433442    for (int i = 0; i < numImages; i++) {
     443        if (badImage->data.U8[i]) {
     444            continue;
     445        }
    434446        if (trans->data.F32[i] < thresh) {
    435447            photo->data.U8[i] = 0xFF;
     
    451463                                      const psVector *zp, // Zero points for each image
    452464                                      const psVector *photo, // Photometric image?
     465                                      const psVector *badImage, // Bad image?
    453466                                      float starClip, // Clipping for stars
    454467                                      float sysErr2 // Systematic error squared
     
    468481    psAssert(!photo || photo->type.type == PS_TYPE_U8, "Photometric determination is wrong type");
    469482    psAssert(!photo || photo->n == numImages, "Not enough photometric determinations: %ld", photo->n);
     483    psAssert(!badImage || badImage->type.type == PS_TYPE_U8, "Photometric determination is wrong type");
     484    psAssert(!badImage || badImage->n == numImages, "Not enough bad determinations: %ld", badImage->n);
    470485
    471486    starClip = PS_SQR(starClip);
     
    481496            numMeasurements++;
    482497            int index = match->image->data.U32[j]; // Image index
     498            if (badImage->data.U8[index]) {
     499                continue;
     500            }
    483501            float mag = match->mag->data.F32[j]; // Measured magnitude
    484502            float magErr = match->magErr->data.F32[j]; // Error in measured magnitude
     
    489507            float dev = mag + cal - stars->data.F32[i]; // Deviation
    490508
    491             // only reject detections from photometric images (non-photometric images can
    492             // have large errors.  XXX Or: allow a much higher rejection threshold
    493             if (photo->data.U8[index]) {
    494               if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {
    495                 numRejected++;
    496                 match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF;
    497               }
    498             }
     509            // only reject detections from photometric images (non-photometric images can
     510            // have large errors.  XXX Or: allow a much higher rejection threshold
     511            if (photo->data.U8[index]) {
     512                if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {
     513                    numRejected++;
     514                    match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF;
     515                }
     516            }
    499517        }
    500518    }
     
    529547    psVector *photo = psVectorAlloc(numImages, PS_TYPE_U8); // Photometric determination for each image
    530548    psVectorInit(photo, 0);
     549    psVector *badImage = psVectorAlloc(numImages, PS_TYPE_U8); // Bad image?
     550    psVectorInit(badImage, 0);
    531551    psVector *stars = psVectorAlloc(numStars, PS_TYPE_F32); // Magnitudes for each star
    532552
    533     float chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, sysErr); // chi^2 for solution
     553    float chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp,
     554                                           photo, sysErr); // chi^2 for solution
    534555    psTrace("psModules.objects", 1, "Initial: chi^2 = %f\n", chi2);
    535556    float lastChi2 = INFINITY;          // chi^2 on last iteration
     
    540561
    541562        // Identify photometric nights
    542         int numPhoto = sourceMatchRelphotPhotometric(photo, trans, transIter, transClip, photoLevel); // Number of photometric images
    543         if (numPhoto < 0) {
    544             psError(PS_ERR_UNKNOWN, false, "Unable to perform photometric determination");
    545             psFree(trans);
    546             psFree(photo);
    547             psFree(stars);
    548             return NULL;
    549         }
    550         psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages);
    551 
    552         // XXX use 20 sigma rejection and 0.1 mag systematic error (move these to the recipe)
    553         fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, 20.0, PS_SQR(0.1));
    554         psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100);
    555 
    556         // XXX use 0.05 mag systematic error (move these to the recipe)
    557         chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, PS_SQR(0.1)); // chi^2 for solution
    558         psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
    559     }
    560 
    561     for (int i = 0; i < maxIter && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) {
    562         lastChi2 = chi2;
    563 
    564         // Identify photometric nights
    565         int numPhoto = sourceMatchRelphotPhotometric(photo, trans, transIter, transClip,
     563        int numPhoto = sourceMatchRelphotPhotometric(photo, trans, badImage, transIter, transClip,
    566564                                                     photoLevel); // Number of photometric images
    567565        if (numPhoto < 0) {
     
    572570            return NULL;
    573571        }
     572        psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages);
     573
     574        // XXX use 20 sigma rejection and 0.1 mag systematic error (move these to the recipe)
     575        fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, 20.0, PS_SQR(0.1));
     576        psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100);
     577
     578        // XXX use 0.05 mag systematic error (move these to the recipe)
     579        chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, PS_SQR(0.1));
     580        psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
     581    }
     582
     583    for (int i = 0; i < maxIter && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) {
     584        lastChi2 = chi2;
     585
     586        // Identify photometric nights
     587        int numPhoto = sourceMatchRelphotPhotometric(photo, trans, badImage, transIter, transClip,
     588                                                     photoLevel); // Number of photometric images
     589        if (numPhoto < 0) {
     590            psError(PS_ERR_UNKNOWN, false, "Unable to perform photometric determination");
     591            psFree(trans);
     592            psFree(photo);
     593            psFree(stars);
     594            return NULL;
     595        }
    574596        psTrace("psModules.objects", 3, "Determined %d/%d are photometric", numPhoto, numImages);
    575597
    576         fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, starClip, sysErr);
     598        fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, starClip, sysErr);
    577599        psTrace("psModules.objects", 3, "%f%% of measurements rejected", fracRej * 100);
    578600
    579         chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, sysErr); // chi^2 for solution
     601        chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, sysErr);
    580602        psTrace("psModules.objects", 1, "iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
    581603    }
    582604
    583605    psFree(photo);
     606    psFree(badImage);
    584607    psFree(stars);
    585608
Note: See TracChangeset for help on using the changeset viewer.