IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2011, 1:16:41 PM (15 years ago)
Author:
eugene
Message:

improvements to the output headers; some code organization; plug leaks; user-specified limits to input seeing ranges

Location:
trunk/ppStack
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack

    • Property svn:ignore
      •  

        old new  
        1717autom4te.cache
        1818Doxyfile
         19a.out.dSYM
    • Property svn:mergeinfo deleted
  • trunk/ppStack/src/ppStackSources.c

    r30685 r31158  
    115115    float fracMatch = psMetadataLookupF32(NULL, recipe, "ZP.MATCH"); // Fraction of images to match for star
    116116
    117     psMetadata *airmassZP = psMetadataLookupMetadata(NULL, recipe, "ZP.AIRMASS"); // Airmass terms
     117    bool mdok = false;
     118    float airmassTarget = psMetadataLookupF32(&mdok, recipe, "ZP.AIRMASS.TARGET"); // output airmass value
     119    if (!mdok) {
     120        airmassTarget = 1.0;
     121    }
     122
     123    psMetadata *airmassZP = psMetadataLookupMetadata(NULL, recipe, "ZP.AIRMASS"); // Airmass terms (slopes) by filter
    118124    if (!airmassZP) {
    119125        psError(PPSTACK_ERR_CONFIG, false, "Unable to find ZP.AIRMASS in recipe.");
     
    128134    int num = options->num;             // Number of inputs
    129135    psAssert(num == sourceLists->n, "Wrong number of source lists: %ld\n", sourceLists->n);
     136
     137    // vectors to store these inputs so they may be recorded in the output headers
     138    options->zpInput      = psVectorAlloc(num, PS_TYPE_F32);
     139    options->expTimeInput = psVectorAlloc(num, PS_TYPE_F32);
     140    options->airmassInput = psVectorAlloc(num, PS_TYPE_F32);
    130141
    131142    psVector *zp = psVectorAlloc(num, PS_TYPE_F32); // Relative zero points for each image
     
    167178        const char *expFilter = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.FILTER"); // Filter name
    168179        zpExp->data.F32[i] = psMetadataLookupF32(NULL, file->fpa->concepts, "FPA.ZP"); // Exposure zero point
     180        // XXX need to get the zero point error values and propagate to get the FPA.ZP.ERR value
     181
     182        options->zpInput->data.F32[i] = zpExp->data.F32[i]; // NOTE zpExp may be re-assigned below using relative photometry
     183        options->expTimeInput->data.F32[i] = exptime;
     184        options->airmassInput->data.F32[i] = airmass;
     185
    169186        psLogMsg("ppStack", PS_LOG_INFO,
    170187                 "Image %d: %.2f sec exposure in %s at airmass %.2f with zero point %.2f",
     
    185202        if (!filter) {
    186203            filter = expFilter;
    187             bool mdok;
    188204            airmassTerm = psMetadataLookupF32(&mdok, airmassZP, filter);
    189205            if (!mdok || !isfinite(airmassTerm)) {
     
    206222        }
    207223
     224        // XXX this is wrong, or at least inconsistent with the above: this needs to include
     225        // a value for the nominal system zero point to be consistent with zpExp
    208226        zp->data.F32[i] = airmassTerm * airmass + 2.5 * log10(exptime);
    209227    }
     
    236254
    237255    if (zpExpNum == numGoodImages) {
     256        psLogMsg ("ppStack", PS_LOG_INFO, "all zero points are finite; using reported zero points listed above");
    238257        for (int i = 0; i < num; i++) {
    239258            zp->data.F32[i] = zpExp->data.F32[i];
     259        }
     260    } else {
     261        psLogMsg ("ppStack", PS_LOG_INFO, "missing some zero points; using guess values:");
     262        for (int i = 0; i < num; i++) {
     263            psLogMsg("ppStack", PS_LOG_INFO, "Image %d: %.2f sec exposure with zero point %.2f", i, options->exposures->data.F32[i], zp->data.F32[i]);
    240264        }
    241265    }
     
    265289            }
    266290        }
    267         // M = m + c0 + c1 * airmass - 2.5log(t) + transparency
    268         // Want sources to have m corresponding to airmass = 1 and t = sumExpTime and transparency = 0
    269         // m_0 + c1 * airmass_0 + 2.5log(t_0) - trans_0 = m_1 + c1 * airmass_1 + 2.5log(t_1) - trans_1
    270         // m_0 = m_1 + zp_1 + trans_1 - c1 * airmass_0 - 2.5log(t_0)
    271         // We don't need to know the magnitude zero point for the filter, since it cancels out
     291
     292        // EAM : the discussion here was not quite right (or at least sloppy).  Here is a replacement explanation:
     293
     294        // For any star, the observed instrumental magnitude on an image and the apparent magnitude are related by:
     295        // M_app = m_inst + zp + c1 * airmass + 2.5log(t) - transparency
     296        // NOTE the sign of 'transparency'  this must agree with the definition in pmSourceMatch.c. see, eg, line 457 where
     297        // transparency = m_inst + zp + c1 * airmass + 2.5log(t) - M_app
     298
     299        // we want to adjust the input images to be in a consistent flux system so that the
     300        // final stack can be generated with a specific target zero point.  Any adjustment to
     301        // the flux scale of the image must be made in coordination with the resulting
     302        // zeropoint, exposure time, and airmass such that the above relationship yields the
     303        // same apparent magnitude for a given star:
     304
     305        // m_inst_i : instrumental mags on input image (in)
     306        // m_inst_o : instrumental mags on re-normalized image (out)
     307
     308        // m_inst_o + zp_o + c1 * airmass_o + 2.5log(t_o) - trans_o = m_inst_i + zp_i + c1 * airmass_i + 2.5log(t_i) - trans_i
     309
     310        // m_inst_o = m_inst_i + (zp_i - zp_o) + c1 * (airmass_i - airmass_o) + 2.5log(t_i) - 2.5log(t_o) - trans_i + trans_o
     311
     312        // zp_i, airmass_i, t_i, trans_i : reported or measured for input image
     313
     314        // zp_o      = zpTarget      (from recipe)
     315        // airmass_o = airmassTarget (from recipe)
     316        // t_o       = sumExpTime    [sum of input exposure times: once images are scale to this time, they can be avereaged]
     317        // trans_o   = 0.0           [obviously!]
     318
     319        // we have 2 cases: (a) all reported ZPs are good or (b) some are bad:
     320        // (a) FPA.ZP = zp_i + c1 * airmass_i
     321        //  --> zp[i] = zp_i + c1 * airmass_i + 2.5log(exptime_i)
     322        // (b)  zp[i] = c1 * airmass_i + 2.5log(exptime_i)
     323        // NOTE: in case (b), the current code is equating the TARGET zp with the NOMINAL zp, which is wrong.
     324
     325        // m_inst_o - m_inst_i = zp[i] - zpTarget - c1 * airmassTarget - 2.5log(sumExpTime) - trans_i
     326
    272327        if (options->matchZPs) {
    273328            options->norm = psVectorAlloc(num, PS_TYPE_F32);
     
    277332                }
    278333                psArray *sources = sourceLists->data[i]; // Sources of interest
    279                 float magCorr = zp->data.F32[i] - trans->data.F32[i] - 2.5*log10(options->sumExposure);
    280                 if (zpExpNum == numGoodImages) {
     334                float magCorr = zp->data.F32[i] - trans->data.F32[i] - 2.5*log10(options->sumExposure) - airmassTerm * airmassTarget;
     335                if (zpExpNum == numGoodImages) { // case (a)
    281336                    // Using measured zero points, so attempt to set target zero point
     337                    // XXX see NOTE above regarding case (b) : this is wrong.  the code should load a nominal zero point and supply it above
     338                    //
    282339                    magCorr -= zpTarget;
    283340                }
     
    302359            // Producing image with target zero point
    303360            options->zp = zpTarget;
     361            options->airmass = airmassTarget;
     362            options->airmassSlope = airmassTerm;
    304363        } else {
    305364            options->zp = NAN;
Note: See TracChangeset for help on using the changeset viewer.