IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 9, 2008, 5:48:15 PM (17 years ago)
Author:
Paul Price
Message:

Adding iteration on relative photometry. Still need to add rejection and test for photometric conditions.

File:
1 edited

Legend:

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

    r20948 r20949  
    282282
    283283
    284 
    285 
    286 
    287 psVector *pmSourceMatchRelphot(const psArray *matches, // Array of matches
    288                                const psVector *zp, // Zero points for each image (including airmass term)
    289                                float cloudClip // Clipping for clouds
    290                                )
    291 {
    292     PS_ASSERT_ARRAY_NON_NULL(matches, NULL);
    293     PS_ASSERT_VECTOR_NON_NULL(zp, NULL);
    294     PS_ASSERT_VECTOR_TYPE(zp, PS_TYPE_F32, NULL);
    295     PS_ASSERT_FLOAT_LARGER_THAN(cloudClip, 0.0, NULL);
    296 
     284// Iterate on the star magnitudes and image transparencies
     285// Returns the solution chi^2
     286float sourceMatchRelphotIterate(psVector *trans, // Transparencies
     287                                psVector *stars, // Star magnitudes
     288                                const psArray *matches, // Array of matches
     289                                const psVector *zp // Zero points for each image (including airmass term)
     290                                )
     291{
    297292    int numImages = zp->n;              // Number of images
    298293    int numStars = matches->n;          // Number of stars
    299     psVector *trans = psVectorAlloc(numImages, PS_TYPE_F32); // Transparencies for each image, magnitudes
     294
     295    psAssert(trans && trans->type.type == PS_TYPE_F32, "Need transparencies");
     296    psAssert(trans->n == numImages, "Not enough transparencies: %ld\n", trans->n);
     297    psAssert(stars && stars->type.type == PS_TYPE_F32, "Need star magnitudes");
     298    psAssert(stars->n == numStars, "Not enough stars: %ld\n", stars->n);
     299    psAssert(matches, "Need list of matches");
     300    psAssert(zp && zp->type.type == PS_TYPE_F32, "Need zero points");
     301    psAssert(zp->n == numImages, "Not enough ZPs: %ld", zp->n);
     302
    300303    psVector *transErr = psVectorAlloc(numImages, PS_TYPE_F32); // Errors in the transparency
    301     psVector *stars = psVectorAlloc(numStars, PS_TYPE_F32); // Magnitudes for each star
    302304    psVector *starsErr = psVectorAlloc(numStars, PS_TYPE_F32); // Errors in the star magnitudes
    303 
    304 
    305     // XXX Need to apply provided ZPs
    306 
    307     psVectorInit(trans, 0.0);
    308     psVectorInit(transErr, 0.0);
    309305
    310306    // Solve the star magnitudes
     
    318314            float magErr = match->magErr->data.F32[j]; // Error in measured magnitude
    319315            float invErr2 = 1.0 / PS_SQR(magErr); // Inverse square error
    320             stars->data.F32[i] += (mag - trans->data.F32[index]) * invErr2;
     316            stars->data.F32[i] += (mag + zp->data.F32[index] - trans->data.F32[index]) * invErr2;
    321317            starsErr->data.F32[i] += invErr2;
    322318        }
     
    347343        transErr->data.F32[i] = sqrtf(inverse);
    348344
    349         psTrace("psModules.objects", 1, "Transparency for image %d: %f +/- %f\n",
     345        psTrace("psModules.objects", 3, "Transparency for image %d: %f +/- %f\n",
    350346                i, trans->data.F32[i], transErr->data.F32[i]);
    351347    }
    352348
     349    // Once more through to evaluate chi^2
     350    float chi2 = 0.0;                   // chi^2 for iteration
     351    for (int i = 0; i < numStars; i++) {
     352        pmSourceMatch *match = matches->data[i]; // Matched stars
     353        for (int j = 0; j < match->num; j++) {
     354            int index = match->image->data.U32[j]; // Image index
     355            float mag = match->mag->data.F32[j]; // Measured magnitude
     356            float magErr = match->magErr->data.F32[j]; // Error in measured magnitude
     357            chi2 += PS_SQR(mag - stars->data.F32[index] - trans->data.F32[index] + zp->data.F32[index]) /
     358                PS_SQR(magErr);
     359        }
     360    }
     361    chi2 /= numStars + numImages;
     362
    353363    psFree(transErr);
    354     psFree(stars);
    355364    psFree(starsErr);
    356365
     366    return chi2;
     367}
     368
     369
     370psVector *pmSourceMatchRelphot(const psArray *matches, // Array of matches
     371                               const psVector *zp, // Zero points for each image (including airmass term)
     372                               int maxIter, // Maximum number of iterations
     373                               float tol, // Relative tolerance for convergence
     374                               float cloudClip, // Clipping for clouds
     375                               float starClip // Clipping for stars
     376                               )
     377{
     378    PS_ASSERT_ARRAY_NON_NULL(matches, NULL);
     379    PS_ASSERT_VECTOR_NON_NULL(zp, NULL);
     380    PS_ASSERT_VECTOR_TYPE(zp, PS_TYPE_F32, NULL);
     381    PS_ASSERT_FLOAT_LARGER_THAN(cloudClip, 0.0, NULL);
     382
     383    int numImages = zp->n;              // Number of images
     384    int numStars = matches->n;          // Number of stars
     385    psVector *trans = psVectorAlloc(numImages, PS_TYPE_F32); // Transparencies for each image, magnitudes
     386    psVectorInit(trans, 0.0);
     387    psVector *stars = psVectorAlloc(numStars, PS_TYPE_F32); // Magnitudes for each star
     388
     389    float chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp); // chi^2 for solution
     390    psTrace("psModules.objects", 1, "Initial: chi^2 = %f\n", chi2);
     391    float lastChi2 = INFINITY;          // chi^2 on last iteration
     392    for (int i = 0; i < maxIter && (lastChi2 - chi2) / chi2 > tol; i++) {
     393        lastChi2 = chi2;
     394        chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp); // chi^2 for solution
     395        psTrace("psModules.objects", 1, "iter = %d: chi^2 = %f\n", i, chi2);
     396    }
     397
    357398    return trans;
    358399}
Note: See TracChangeset for help on using the changeset viewer.