IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2011, 1:05:28 PM (15 years ago)
Author:
watersc1
Message:

Merge of trunk back into branch.

Location:
branches/czw_branch/20101203
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/psphot

  • branches/czw_branch/20101203/psphot/src/psphotRadialAperturesByObject.c

    r30118 r30631  
    33// aperture-like measurements for extended sources
    44// flux in simple, circular apertures
    5 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule) {
     5
     6// **** it looks like this function will re-point the source pixels at the specified FILERULE
     7// **** I need to distinguish PSF-matched images from raw
     8// **** save (somewhere) the PSF-matched PSF values
     9
     10// this function measures the radial aperture fluxes for the set of readouts.  this function
     11// may be called multiple times (presumably with different matched PSF sizes).  we must have
     12// already added an entry to the readout->analysis identifying the FWHM of this version.
     13
     14bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule, int nMatchedPSF) {
    615
    716    bool status;
     
    2837    psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe");
    2938    psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define");
     39    float outerRadius = radMax->data.F32[radMax->n - 1];
    3040
    3141    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     
    3949    float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM");
    4050
     51    // how many target PSFs do we want?
     52    int nPSFsizes = 0;
     53    {
     54        psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM");
     55        if (status) {
     56            nPSFsizes = 1;
     57        } else {
     58            psVector *fwhmValues = psMetadataLookupVector(&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); // Magnitude offsets
     59            psAssert (status, "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM");
     60            nPSFsizes = fwhmValues->n;
     61        }
     62    }
     63   
    4164    // source analysis is done in S/N order (brightest first)
    4265    objects = psArraySort (objects, pmPhotObjSortBySN);
     
    5275        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    5376        psAssert (readout, "missing readout?");
     77
     78        psVector *fwhmValues = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES");
     79        if (!fwhmValues) {
     80            psError (PSPHOT_ERR_CONFIG, true, "convolved or measured FWHM is not defined for this readout");
     81            return false;
     82        }
     83        if (fwhmValues->n != nMatchedPSF + 1) {
     84            psError (PSPHOT_ERR_CONFIG, true, "convolved or measured FWHM sequence is inconsistent this readout");
     85            return false;
     86        }
     87        psLogMsg ("psphot", PS_LOG_DETAIL, "PSF FWHM of %s : %f pixels\n", file->name, fwhmValues->data.F32[nMatchedPSF]);
    5488
    5589        readouts->data[i] = psMemIncrRefCounter(readout);
     
    77111            if (source->peak->SN < SN_LIM) continue;
    78112
     113            int index = source->imageID;
     114            if (index >= readouts->n) continue; // skip the sources generated by the chisq image
     115            pmReadout *readout = readouts->data[index];
     116
     117            // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index);
     118            // psphotVisualShowImage(readout);
     119
     120            // allocate pmSourceExtendedParameters, if not already defined
     121            if (source->parent) {
     122                if (!source->parent->radialAper) {
     123                    source->parent->radialAper = psArrayAlloc(nPSFsizes);
     124                }
     125            } else {
     126                if (!source->radialAper) {
     127                    source->radialAper = psArrayAlloc(nPSFsizes);
     128                }
     129            }
     130
    79131            // replace object in image
    80132            if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
    81133                pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    82134            }
     135
     136            // we need to change the view for the radial aperture analysis, but we want to recover exactly
     137            // the original view; the following elements get destroyed by pmSourceRedefinePixels so save them:
     138            psImage *oldMaskObj   = psMemIncrRefCounter(source->maskObj);
     139            psImage *oldModelFlux = psMemIncrRefCounter(source->modelFlux);
     140            psImage *oldPSFimage  = psMemIncrRefCounter(source->psfImage);
     141            psRegion oldRegion    = source->region;
     142
    83143            Nradial ++;
    84144
    85             int index = source->imageID;
    86             pmReadout *readout = readouts->data[index];
     145            // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index);
     146            // psphotVisualShowImage(readout);
    87147
    88148            // force source image to be a bit larger...
    89             float radius = source->peak->xf - source->pixels->col0;
    90             radius = PS_MAX (radius, source->peak->yf - source->pixels->row0);
    91             radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0);
    92             radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0);
    93             pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius);
     149            // float radius = source->peak->xf - source->pixels->col0;
     150            // radius = PS_MAX (radius, source->peak->yf - source->pixels->row0);
     151            // radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0);
     152            // radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0);
     153            pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, outerRadius + 2);
    94154
    95             if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax)) {
     155            if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, nMatchedPSF)) {
    96156                psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    97157            } else {
     
    99159            }
    100160
     161            pmSourceRedefinePixelsByRegion (source, readout, oldRegion);
     162            psFree(source->maskObj);   source->maskObj   = oldMaskObj;
     163            psFree(source->modelFlux); source->modelFlux = oldModelFlux;
     164            psFree(source->psfImage);  source->psfImage  = oldPSFimage;
     165
    101166            // re-subtract the object, leave local sky
    102167            pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     168
     169            // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index);
     170            // psphotVisualShowImage(readout);
    103171        }
    104172    }
Note: See TracChangeset for help on using the changeset viewer.