IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 13, 2011, 11:59:42 AM (15 years ago)
Author:
eugene
Message:

do not cull peaks with only one entry; skip the section that culls duplicate peaks -- this was dropping many valid peaks and seems unneeded; save radial apertures in their own extension; fixed logic on culling of faint peaks

Location:
trunk/psModules/src/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects

    • Property svn:mergeinfo deleted
  • trunk/psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c

    r29019 r30621  
    2020
    2121#include "pmConfig.h"
     22#include "pmErrorCodes.h"
    2223#include "pmDetrendDB.h"
    2324
     
    7172    psF32 errMag, chisq, apRadius;
    7273    psS32 nPix, nDOF;
    73     char keyword1[80], keyword2[80];
    7474
    7575    pmChip *chip = readout->parent->parent;
     
    103103    table = psArrayAllocEmpty (sources->n);
    104104
     105# if (0)
    105106    // we use this just to define the output vectors (which must be present for all objects)
    106107    bool status = false;
     
    118119      psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]);
    119120    }
    120 
     121# endif
    121122
    122123    // we write out PSF-fits for all sources, regardless of quality.  the source flags tell us the state
     
    258259        psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2",           PS_DATA_U32, "psphot analysis flags",                     source->mode2);
    259260
     261# if (0)
     262        // XXX if we have raw radial apertures, write them out here
    260263        psVector *radFlux    = psVectorAlloc(radMax->n, PS_TYPE_F32);
    261264        psVector *radFluxErr = psVectorAlloc(radMax->n, PS_TYPE_F32);
     
    284287        psFree (radFluxErr);
    285288        psFree (radFill);
     289# endif
    286290
    287291        // XXX not sure how to get this : need to load Nimages with weight?
     
    781785    return true;
    782786}
     787
     788// **** write out the radial flux values for the sources for a given matched-PSF image
     789// **** how do we distinguish the matched-PSF images from the non-matched version
     790bool pmSourcesWrite_CMF_PS1_SV1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe)
     791{
     792
     793    psArray *table;
     794    psMetadata *row;
     795    psF32 xPos, yPos;
     796    char keyword1[80], keyword2[80];
     797
     798    // create a header to hold the output data
     799    psMetadata *outhead = psMetadataAlloc ();
     800
     801    // write the links to the image header
     802    psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "radial flux table extension", extname);
     803
     804    // we use this just to define the output vectors (which must be present for all objects)
     805    bool status = false;
     806    psVector *radMin = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.LOWER");
     807    psVector *radMax = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER");
     808    psAssert (radMax, "this must have been defined and tested earlier!");
     809    psAssert (radMax->n, "this must have been defined and tested earlier!");
     810    psAssert (radMin->n == radMax->n, "inconsistent annular bins");
     811
     812    // write the radial profile apertures to header
     813    for (int i = 0; i < radMax->n; i++) {
     814      sprintf (keyword1, "RMIN_%02d", i);
     815      sprintf (keyword2, "RMAX_%02d", i);
     816      psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword1, PS_META_REPLACE, "min radius for SB profile", radMin->data.F32[i]);
     817      psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]);
     818    }
     819
     820    psVector *fwhmValues = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES");
     821    if (!fwhmValues) {
     822        psError (PM_ERR_CONFIG, true, "convolved or measured FWHM is not defined for this readout");
     823        return false;
     824    }
     825
     826    // let's write these out in S/N order
     827    sources = psArraySort (sources, pmSourceSortBySN);
     828
     829    table = psArrayAllocEmpty (sources->n);
     830
     831    // we write out all sources, regardless of quality.  the source flags tell us the state
     832    for (int i = 0; i < sources->n; i++) {
     833
     834        pmSource *source = sources->data[i];
     835
     836        // skip sources without radial aper measurements (or insufficient)
     837        if (source->radialAper == NULL) continue;
     838        psAssert (source->radialAper->n == fwhmValues->n, "inconsistent radial aperture set");
     839
     840        for (int entry = 0; entry < fwhmValues->n; entry++) {
     841
     842            // choose the convolved EXT model, if available, otherwise the simple one
     843            pmSourceRadialApertures *radialAper = source->radialAper->data[entry];
     844            assert (radialAper);
     845
     846            bool useMoments = true;
     847            useMoments = (useMoments && source->moments);          // can't if there are no moments
     848            useMoments = (useMoments && source->moments->nPixels); // can't if the moments were not measured
     849            useMoments = (useMoments && !(source->mode && PM_SOURCE_MODE_MOMENTS_FAILURE)); // can't if the moments failed...
     850
     851            if (useMoments) {
     852                xPos = source->moments->Mx;
     853                yPos = source->moments->My;
     854            } else {
     855                xPos = source->peak->xf;
     856                yPos = source->peak->yf;
     857            }
     858
     859            row = psMetadataAlloc ();
     860
     861            // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
     862            psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
     863            psMetadataAddF32 (row, PS_LIST_TAIL, "X_APER",           0, "Center of aperture measurements",            xPos);
     864            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_APER",           0, "Center of aperture measurements",            yPos);
     865            psMetadataAddF32 (row, PS_LIST_TAIL, "PSF_FWHM",         0, "FWHM of matched PSF",                        fwhmValues->data.F32[entry]);
     866
     867            // XXX if we have raw radial apertures, write them out here
     868            psVector *radFlux    = psVectorAlloc(radMax->n, PS_TYPE_F32);
     869            psVector *radFluxErr = psVectorAlloc(radMax->n, PS_TYPE_F32);
     870            psVector *radFill    = psVectorAlloc(radMax->n, PS_TYPE_F32);
     871            psVectorInit (radFlux,    NAN);
     872            psVectorInit (radFluxErr, NAN);
     873            psVectorInit (radFill,    NAN);
     874            if (!radialAper->flux) goto write_annuli;
     875            if (!radialAper->fill) goto write_annuli;
     876            psAssert (radialAper->flux->n <= radFlux->n, "inconsistent vector lengths");
     877            psAssert (radialAper->fill->n <= radFlux->n, "inconsistent vector lengths");
     878
     879            // copy the data from fluxVal (which is not guaranteed to be the full length) to radFlux
     880            for (int j = 0; j < radialAper->flux->n; j++) {
     881                radFlux->data.F32[j]    = radialAper->flux->data.F32[j];
     882                radFluxErr->data.F32[j] = radialAper->fluxErr->data.F32[j];
     883                radFill->data.F32[j]    = radialAper->fill->data.F32[j];
     884            }
     885
     886        write_annuli:
     887            psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX",     PS_DATA_VECTOR, "flux within annuli",    radFlux);
     888            psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX_ERR", PS_DATA_VECTOR, "flux error in annuli",  radFluxErr);
     889            psMetadataAdd (row, PS_LIST_TAIL, "APER_FILL",     PS_DATA_VECTOR, "fill factor of annuli", radFill);
     890            psFree (radFlux);
     891            psFree (radFluxErr);
     892            psFree (radFill);
     893
     894            psArrayAdd (table, 100, row);
     895            psFree (row);
     896        }
     897    }
     898
     899    if (table->n == 0) {
     900        if (!psFitsWriteBlank (fits, outhead, extname)) {
     901            psError(psErrorCodeLast(), false, "Unable to write empty sources file.");
     902            psFree(outhead);
     903            psFree(table);
     904            return false;
     905        }
     906        psFree (outhead);
     907        psFree (table);
     908        return true;
     909    }
     910
     911    psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
     912    if (!psFitsWriteTable (fits, outhead, table, extname)) {
     913        psError(psErrorCodeLast(), false, "writing ext data %s\n", extname);
     914        psFree (outhead);
     915        psFree(table);
     916        return false;
     917    }
     918    psFree (outhead);
     919    psFree (table);
     920    return true;
     921}
Note: See TracChangeset for help on using the changeset viewer.