IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26674


Ignore:
Timestamp:
Jan 22, 2010, 5:32:32 PM (16 years ago)
Author:
Paul Price
Message:

Get running with scaling of kernel parameters.

Location:
branches/eam_branches/20091201/ppStack/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/ppStack/src/ppStackMatch.c

    r26671 r26674  
    317317            float poorFrac = psMetadataLookupF32(&mdok, ppsub, "POOR.FRACTION"); // Fraction for "poor"
    318318
    319             bool scale = psMetadataLookupBool(NULL, recipe, "SCALE");        // Scale kernel parameters?
    320             float scaleRef = psMetadataLookupF32(NULL, recipe, "SCALE.REF"); // Reference for scaling
    321             float scaleMin = psMetadataLookupF32(NULL, recipe, "SCALE.MIN"); // Minimum for scaling
    322             float scaleMax = psMetadataLookupF32(NULL, recipe, "SCALE.MAX"); // Maximum for scaling
     319            bool scale = psMetadataLookupBool(NULL, ppsub, "SCALE");        // Scale kernel parameters?
     320            float scaleRef = psMetadataLookupF32(NULL, ppsub, "SCALE.REF"); // Reference for scaling
     321            float scaleMin = psMetadataLookupF32(NULL, ppsub, "SCALE.MIN"); // Minimum for scaling
     322            float scaleMax = psMetadataLookupF32(NULL, ppsub, "SCALE.MAX"); // Maximum for scaling
    323323            if (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax)) {
    324324                psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    325                         "Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in recipe.",
     325                        "Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in PPSUB recipe.",
    326326                        scaleRef, scaleMin, scaleMax);
    327327                return false;
  • branches/eam_branches/20091201/ppStack/src/ppStackOptions.c

    r26671 r26674  
    2424    psFree(options->sourceLists);
    2525    psFree(options->norm);
     26    psFree(options->sources);
    2627    psFree(options->cells);
    2728    psFree(options->kernels);
     
    4445    options->convolve = true;
    4546    options->matchZPs = true;
     47    options->photometry = false;
    4648    options->stats = NULL;
    4749    options->statsFile = NULL;
     
    6062    options->sourceLists = NULL;
    6163    options->norm = NULL;
     64    options->sources = NULL;
    6265    options->cells = NULL;
    6366    options->kernels = NULL;
  • branches/eam_branches/20091201/ppStack/src/ppStackOptions.h

    r26671 r26674  
    1010    bool convolve;                      // Convolve images?
    1111    bool matchZPs;                      // Adjust relative fluxes based on transparency analysis?
     12    bool photometry;                    // Perform photometry?
    1213    psMetadata *stats;                  // Statistics for output
    1314    FILE *statsFile;                    // File to which to write statistics
     
    2425    psArray *sourceLists;               // Individual lists of sources for matching
    2526    psVector *norm;                     // Normalisation for each image
     27    psArray *sources;                   // Matched sources
    2628    // Convolve
    2729    psArray *cells;                     // Cells for convolved images --- a handle for reading again
  • branches/eam_branches/20091201/ppStack/src/ppStackPhotometry.c

    r24216 r26674  
    1919    psAssert(recipe, "We've thrown an error on this before.");
    2020
    21     bool mdok;                          // Status of MD lookup
    22     if (!psMetadataLookupBool(&mdok, recipe, "PHOTOMETRY")) {
     21    if (!options->photometry) {
    2322        // Nothing to do
    2423        return true;
     
    6059                           "Bits to use for mark", markValue);
    6160
    62     pmCell *sourcesCell = pmFPAfileThisCell(config->files, photView, "PPSTACK.OUTPUT");
    63     psArray *inSources = psMetadataLookupPtr(NULL, sourcesCell->analysis, "PSPHOT.SOURCES");
     61    psArray *inSources = options->sources;
    6462    if (!inSources) {
    6563        psError(PS_ERR_UNKNOWN, false, "Unable to find input sources");
  • branches/eam_branches/20091201/ppStack/src/ppStackReadout.c

    r26475 r26674  
    126126    int kernelSize = psMetadataLookupS32(NULL, ppsub, "KERNEL.SIZE"); // Kernel half-size
    127127
    128     psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.IN"); // Name of bits to mask going in
     128    psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in
    129129    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
    130130    psString maskSuspectStr = psMetadataLookupStr(NULL, recipe, "MASK.SUSPECT"); // Name of suspect mask bits
     
    219219    bool safe = psMetadataLookupBool(&mdok, recipe, "SAFE"); // Be safe when combining small numbers of pixels
    220220
    221     psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.IN"); // Name of bits to mask going in
     221    psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in
    222222    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
    223223    psString maskSuspectStr = psMetadataLookupStr(NULL, recipe, "MASK.SUSPECT"); // Name of suspect mask bits
  • branches/eam_branches/20091201/ppStack/src/ppStackSetup.c

    r26475 r26674  
    2222    psAssert(recipe, "We've thrown an error on this before.");
    2323
    24     options->matchZPs = psMetadataLookupBool(NULL, recipe, "MATCH.ZERO.POINTS"); // Adjust zero points based on tranparency analysis?
     24    options->matchZPs = psMetadataLookupBool(NULL, recipe, "ZP"); // Adjust zero points?
     25
     26    options->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY"); // Perform photometry?
    2527
    2628    options->convolve = psMetadataLookupBool(NULL, recipe, "CONVOLVE"); // Convolve images?
  • branches/eam_branches/20091201/ppStack/src/ppStackSources.c

    r26475 r26674  
    6161    PS_ASSERT_PTR_NON_NULL(config, false);
    6262
    63     if (!options->matchZPs) {
    64         int num = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs
    65         options->norm = psVectorAlloc(num, PS_TYPE_F32);
    66         psVectorInit (options->norm, 0.0);
    67 
    68         // XXX do I need to set this?
    69         // options->sumExposure = sumExpTime;
    70 
    71         return true;
     63    if (!options->matchZPs && !options->photometry) {
     64        int num = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs
     65        options->norm = psVectorAlloc(num, PS_TYPE_F32);
     66        psVectorInit (options->norm, 0.0);
     67
     68        // XXX do I need to set this?
     69        // options->sumExposure = sumExpTime;
     70
     71        return true;
    7272    }
    7373
     
    191191#endif
    192192
    193     psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1,
    194                                            iter2, starRej2, starSys2, starLimit,
    195                                            transIter, transRej, transThresh); // Transparencies for each image
    196     if (!trans) {
    197         psError(PS_ERR_UNKNOWN, false, "Unable to measure transparencies");
    198         return false;
    199     }
     193    if (options->matchZPs) {
     194        psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1,
     195                                               iter2, starRej2, starSys2, starLimit,
     196                                               transIter, transRej, transThresh); // Transparencies per image
     197        if (!trans) {
     198            psError(PS_ERR_UNKNOWN, false, "Unable to measure transparencies");
     199            return false;
     200        }
     201        for (int i = 0; i < trans->n; i++) {
     202            if (!isfinite(trans->data.F32[i])) {
     203                inputMask->data.U8[i] |= PPSTACK_MASK_CAL;
     204            }
     205        }
     206        // M = m + c0 + c1 * airmass - 2.5log(t) + transparency
     207        // Want sources to have m corresponding to airmass = 1 and t = sumExpTime and transparency = 0
     208        // m_0 + c1 * airmass_0 + 2.5log(t_0) - trans_0 = m_1 + c1 * airmass_1 + 2.5log(t_1) - trans_1
     209        // m_0 = m_1 + zp_1 + trans_1 - c1 * airmass_0 - 2.5log(t_0)
     210        // We don't need to know the magnitude zero point for the filter, since it cancels out
     211        if (options->matchZPs) {
     212            options->norm = psVectorAlloc(num, PS_TYPE_F32);
     213            for (int i = 0; i < num; i++) {
     214                if (!isfinite(trans->data.F32[i])) {
     215                    continue;
     216                }
     217                psArray *sources = sourceLists->data[i]; // Sources of interest
     218                float magCorr = airmassTerm - 2.5*log10(sumExpTime) - zp->data.F32[i] - trans->data.F32[i];
     219                options->norm->data.F32[i] = magCorr;
     220                psLogMsg("ppStack", PS_LOG_INFO, "Applying magnitude correction to image %d: %f\n",
     221                         i, magCorr);
     222
     223                for (int j = 0; j < sources->n; j++) {
     224                    pmSource *source = sources->data[j]; // Source of interest
     225                    if (!source) {
     226                        continue;
     227                    }
     228                    source->psfMag += magCorr;
     229                }
     230            }
     231        }
     232
     233#ifdef TESTING
     234        dumpMatches("source_mags.dat", num, matches, zp, trans);
     235#endif
     236        psFree(trans);
     237
     238#ifdef TESTING
     239        // Double check: all transparencies should be zero
     240        {
     241            psArray *matches = pmSourceMatchSources(sourceLists, radius); // List of matches
     242            if (!matches) {
     243                psError(PS_ERR_UNKNOWN, false, "Unable to match sources");
     244                psFree(zp);
     245                return false;
     246            }
     247            psVector *trans = pmSourceMatchRelphot(matches, zp, iter, tol, starLimit, transIter, transRej,
     248                                                   transThresh, starRej, starSys);
     249            for (int i = 0; i < num; i++) {
     250                fprintf(stderr, "Transparency of image %d: %f\n", i, trans->data.F32[i]);
     251            }
     252            psFree(trans);
     253        }
     254#endif
     255    }
     256
    200257
    201258#if 0
     
    216273#endif
    217274
    218 #ifdef TESTING
    219     dumpMatches("source_mags.dat", num, matches, zp, trans);
    220 #endif
    221 
    222     for (int i = 0; i < trans->n; i++) {
    223         if (!isfinite(trans->data.F32[i])) {
    224             inputMask->data.U8[i] |= PPSTACK_MASK_CAL;
    225         }
    226     }
    227 
    228     // Save best matches SOMEWHERE for future photometry
    229     // XXX this is a really poor output location; clean up the pmFPAfiles used in ppStack
    230     pmCell *sourcesCell = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT");
    231     psArray *sourcesBest = psArrayAllocEmpty(matches->n);
    232 
    233     // XXX something of a hack: require at least 2 detections or the nominated fraction of the max possible
    234     int minMatches = PS_MAX(2, fracMatch * num);// Minimum number of matches required
    235     for (int i = 0; i < matches->n; i++) {
    236         pmSourceMatch *match = matches->data[i]; // Match of interest
    237         if (match->num < minMatches) {
    238             continue;
    239         }
    240 
    241         // We need to grab a single instance of this source: just take the first available
    242         int image = match->image->data.S32[0]; // Index of image
    243         int index = match->index->data.S32[0]; // Index of source within image
    244         psArray *sources = sourceLists->data[image]; // Sources for image
    245         pmSource *source = sources->data[index]; // Source of interest
    246 
    247         psArrayAdd(sourcesBest, sourcesBest->n, source);
    248     }
    249     psMetadataAdd(sourcesCell->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY | PS_META_REPLACE,
    250                   "psphot sources", sourcesBest);
    251     psLogMsg("ppStack", PS_LOG_INFO, "Selected %ld sources for photometry analysis", sourcesBest->n);
    252     psFree(sourcesBest);
     275    if (options->photometry) {
     276        // Save best matches for future photometry
     277        psArray *sourcesBest = options->sources = psArrayAllocEmpty(matches->n);
     278
     279        // XXX something of a hack: require at least 2 detections or the nominated fraction of the max possible
     280        int minMatches = PS_MAX(2, fracMatch * num);// Minimum number of matches required
     281        for (int i = 0; i < matches->n; i++) {
     282            pmSourceMatch *match = matches->data[i]; // Match of interest
     283            if (match->num < minMatches) {
     284                continue;
     285            }
     286
     287            // We need to grab a single instance of this source: just take the first available
     288            int image = match->image->data.S32[0]; // Index of image
     289            int index = match->index->data.S32[0]; // Index of source within image
     290            psArray *sources = sourceLists->data[image]; // Sources for image
     291            pmSource *source = sources->data[index]; // Source of interest
     292
     293            psArrayAdd(sourcesBest, sourcesBest->n, source);
     294        }
     295        psLogMsg("ppStack", PS_LOG_INFO, "Selected %ld sources for photometry analysis", sourcesBest->n);
     296    }
    253297
    254298    psFree(matches);
    255 
    256     // M = m + c0 + c1 * airmass - 2.5log(t) + transparency
    257     // Want sources to have m corresponding to airmass = 1 and t = sumExpTime and transparency = 0
    258     // m_0 + c1 * airmass_0 + 2.5log(t_0) - trans_0 = m_1 + c1 * airmass_1 + 2.5log(t_1) - trans_1
    259     // m_0 = m_1 + zp_1 + trans_1 - c1 * airmass_0 - 2.5log(t_0)
    260     // We don't need to know the magnitude zero point for the filter, since it cancels out
    261     options->norm = psVectorAlloc(num, PS_TYPE_F32);
    262     for (int i = 0; i < num; i++) {
    263         if (!isfinite(trans->data.F32[i])) {
    264             continue;
    265         }
    266         psArray *sources = sourceLists->data[i]; // Sources of interest
    267         float magCorr = airmassTerm - 2.5*log10(sumExpTime) - zp->data.F32[i] - trans->data.F32[i];
    268         options->norm->data.F32[i] = magCorr;
    269         psLogMsg("ppStack", PS_LOG_INFO, "Applying magnitude correction to image %d: %f\n", i, magCorr);
    270 
    271         for (int j = 0; j < sources->n; j++) {
    272             pmSource *source = sources->data[j]; // Source of interest
    273             if (!source) {
    274                 continue;
    275             }
    276             source->psfMag += magCorr;
    277         }
    278     }
    279     psFree(trans);
    280 
    281 #ifdef TESTING
    282     // Double check: all transparencies should be zero
    283     {
    284         psArray *matches = pmSourceMatchSources(sourceLists, radius); // List of matches
    285         if (!matches) {
    286             psError(PS_ERR_UNKNOWN, false, "Unable to match sources");
    287             psFree(zp);
    288             return false;
    289         }
    290         psVector *trans = pmSourceMatchRelphot(matches, zp, iter, tol, starLimit, transIter, transRej,
    291                                                transThresh, starRej, starSys);
    292         for (int i = 0; i < num; i++) {
    293             fprintf(stderr, "Transparency of image %d: %f\n", i, trans->data.F32[i]);
    294         }
    295         psFree(trans);
    296     }
    297 #endif
    298299
    299300    return true;
Note: See TracChangeset for help on using the changeset viewer.