IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32633


Ignore:
Timestamp:
Nov 8, 2011, 2:56:56 PM (15 years ago)
Author:
eugene
Message:

add unofficial PS1_V4 output format (not yet standard); add clean radial profile to find sky limit; use sky limit to control kron analysis window; fix thread / memory problem for radial photometry; fix object matching for forced psf photometry; fix object matching to get the right matches

Location:
trunk
Files:
23 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/Makefile.am

    r32347 r32633  
    4545        pmSourceIO_CMF_PS1_V2.c \
    4646        pmSourceIO_CMF_PS1_V3.c \
     47        pmSourceIO_CMF_PS1_V4.c \
    4748        pmSourceIO_CMF_PS1_SV1.c \
    4849        pmSourceIO_CMF_PS1_DV1.c \
     
    130131
    131132# pmSourceID_CMF_* functions use a common framework
    132 BUILT_SOURCES = pmSourceIO_CMF_PS1_V1.c pmSourceIO_CMF_PS1_V2.c pmSourceIO_CMF_PS1_V3.c
     133BUILT_SOURCES = pmSourceIO_CMF_PS1_V1.c pmSourceIO_CMF_PS1_V2.c pmSourceIO_CMF_PS1_V3.c pmSourceIO_CMF_PS1_V4.c
    133134
    134135pmSourceIO_CMF_PS1_V1.c : pmSourceIO_CMF.c.in mksource.pl
     
    141142        mksource.pl pmSourceIO_CMF.c.in PS1_V3 pmSourceIO_CMF_PS1_V3.c
    142143
     144pmSourceIO_CMF_PS1_V4.c : pmSourceIO_CMF.c.in mksource.pl
     145        mksource.pl pmSourceIO_CMF.c.in PS1_V4 pmSourceIO_CMF_PS1_V4.c
     146
    143147# EXTRA_DIST = pmErrorCodes.h.in pmErrorCodes.dat pmErrorCodes.c.in
  • trunk/psModules/src/objects/mksource.pl

    r32347 r32633  
    1616%cmfmodes = ("PS1_V1", 1,
    1717             "PS1_V2", 2,
    18              "PS1_V3", 3);
     18             "PS1_V3", 3,
     19             "PS1_V4", 4);
    1920
    2021print "1: $cmfmodes{1}\n";
  • trunk/psModules/src/objects/pmSource.c

    r32347 r32633  
    137137    source->apFlux           = NAN;
    138138    source->apFluxErr        = NAN;
     139
     140    source->skyRadius        = NAN;
     141    source->skyFlux          = NAN;
     142    source->skySlope         = NAN;
    139143
    140144    source->pixWeightNotBad  = NAN;
  • trunk/psModules/src/objects/pmSource.h

    r32347 r32633  
    3636    PM_SOURCE_TMPF_MOMENTS_MEASURED  = 0x0010,
    3737    PM_SOURCE_TMPF_CANDIDATE_PSFSTAR = 0x0020,
    38     PM_SOURCE_TMPF_STACK_KEEP        = 0x0040,
    39     PM_SOURCE_TMPF_STACK_SKIP        = 0x0080,
     38    PM_SOURCE_TMPF_RADIAL_KEEP       = 0x0040,
     39    PM_SOURCE_TMPF_RADIAL_SKIP       = 0x0080,
     40    PM_SOURCE_TMPF_PETRO_KEEP        = 0x0100,
     41    PM_SOURCE_TMPF_PETRO_SKIP        = 0x0200,
    4042} pmSourceTmpF;
    4143
     
    9597    float apFluxErr;                    ///< apFluxErr corresponding to psfMag or extMag (depending on type)
    9698
     99    float skyRadius;                    ///< radius at which profile hits local sky (or goes flat)
     100    float skyFlux;                      ///< mean flux per pixel in aperture at which profile hits local sky (or goes flat)
     101    float skySlope;                     ///< mean flux slope at which profile hits local sky (or goes flat)
     102
    97103    float pixWeightNotBad;              ///< PSF-weighted coverage of unmasked (not BAD) pixels
    98104    float pixWeightNotPoor;             ///< PSF-weighted coverage of unmasked (not POOR) pixels
  • trunk/psModules/src/objects/pmSourceIO.c

    r31670 r32633  
    569569            PM_SOURCES_WRITE("PS1_V2",    CMF_PS1_V2);
    570570            PM_SOURCES_WRITE("PS1_V3",    CMF_PS1_V3);
     571            PM_SOURCES_WRITE("PS1_V4",    CMF_PS1_V4);
    571572            PM_SOURCES_WRITE("PS1_SV1",   CMF_PS1_SV1);
    572573            PM_SOURCES_WRITE("PS1_DV1",   CMF_PS1_DV1);
     
    10251026                sources = pmSourcesRead_CMF_PS1_V3 (file->fits, hdu->header);
    10261027            }
     1028            if (!strcmp (exttype, "PS1_V4")) {
     1029                sources = pmSourcesRead_CMF_PS1_V4 (file->fits, hdu->header);
     1030            }
    10271031            if (!strcmp (exttype, "PS1_SV1")) {
    10281032                sources = pmSourcesRead_CMF_PS1_SV1 (file->fits, hdu->header);
  • trunk/psModules/src/objects/pmSourceIO.h

    r30621 r32633  
    6262bool pmSourcesWrite_CMF_PS1_V3_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);
    6363
     64bool pmSourcesWrite_CMF_PS1_V4(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe);
     65bool pmSourcesWrite_CMF_PS1_V4_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);
     66bool pmSourcesWrite_CMF_PS1_V4_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname);
     67bool pmSourcesWrite_CMF_PS1_V4_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);
     68
    6469bool pmSourcesWrite_CMF_PS1_SV1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe);
    6570bool pmSourcesWrite_CMF_PS1_SV1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);
     
    8691psArray *pmSourcesRead_CMF_PS1_V2 (psFits *fits, psMetadata *header);
    8792psArray *pmSourcesRead_CMF_PS1_V3 (psFits *fits, psMetadata *header);
     93psArray *pmSourcesRead_CMF_PS1_V4 (psFits *fits, psMetadata *header);
    8894psArray *pmSourcesRead_CMF_PS1_SV1 (psFits *fits, psMetadata *header);
    8995psArray *pmSourcesRead_CMF_PS1_DV1 (psFits *fits, psMetadata *header);
  • trunk/psModules/src/objects/pmSourceIO_CMF.c.in

    r32347 r32633  
    127127
    128128        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",             source->apMag);
    129         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW",       PS_DATA_F32, "magnitude in reported aperture",             source->apMagRaw);
     129        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW",       PS_DATA_F32, "magnitude in reported aperture",             source->apMagRaw);
    130130        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              outputs.apRadius);
    131131        @<PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           outputs.peakMag);
     
    138138        @>PS1_V1@ psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF",          PS_DATA_F64, "PSF DEC coordinate (degrees)",               outputs.dec);
    139139
    140         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           outputs.peakMag);
     140        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           outputs.peakMag);
    141141        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",                                  source->sky);
    142142        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA",        PS_DATA_F32, "Sigma of sky level",                         source->skyErr);
     
    150150        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA",        PS_DATA_F32, "PSF orientation angle",                      outputs.psfTheta);
    151151        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF",           PS_DATA_F32, "PSF coverage/quality factor (bad)",          source->pixWeightNotBad);
    152         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT",   PS_DATA_F32, "PSF coverage/quality factor (poor)",         source->pixWeightNotPoor);
     152        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT",   PS_DATA_F32, "PSF coverage/quality factor (poor)",         source->pixWeightNotPoor);
    153153        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF",         PS_DATA_S32, "degrees of freedom",                         outputs.nDOF);
    154154        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX",         PS_DATA_S32, "number of pixels in fit",                    outputs.nPix);
     
    158158        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY",       PS_DATA_F32, "second moments (Y*Y)",                       moments.Myy);
    159159
    160         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M3C",      PS_DATA_F32, "third momemt cos theta",                     moments.M_c3);
    161         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M3S",      PS_DATA_F32, "third momemt sin theta",                     moments.M_s3);
    162         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4C",      PS_DATA_F32, "fourth momemt cos theta",                    moments.M_c4);
    163         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4S",      PS_DATA_F32, "fourth momemt sin theta",                    moments.M_s4);
    164 
    165         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1",       PS_DATA_F32, "first radial moment",                        moments.Mrf);
    166         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH",       PS_DATA_F32, "half radial moment",                         moments.Mrh);
    167         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX",        PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Krf);
    168         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR",    PS_DATA_F32, "Kron Flux Error",                            moments.dKrf);
    169         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER",  PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Kinner);
    170         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER",  PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Kouter);
    171 
    172         // XXX do not keep this long term, just a TEST:
    173         // @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_PSF",    PS_DATA_F32, "Kron Flux",                                  moments.KronPSF);
    174         // @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_PSF_SIG",PS_DATA_F32, "Kron Flux",                                  moments.KronPSFErr);
    175         // Do NOT write these : not consistent with the definition of PS1_V3 in Ohana/src/libautocode/dev/cmf-ps1-v3.d
    176         // psMetadataAdd (row, PS_LIST_TAIL, "KRON_CORE_FLUX",   PS_DATA_F32, "Kron Flux (in 1.0 R1)",                      moments.KronCore);
    177         // psMetadataAdd (row, PS_LIST_TAIL, "KRON_CORE_ERROR",  PS_DATA_F32, "Kron Error (in 1.0 R1)",                     moments.KronCoreErr);
     160        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M3C",      PS_DATA_F32, "third momemt cos theta",                     moments.M_c3);
     161        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M3S",      PS_DATA_F32, "third momemt sin theta",                     moments.M_s3);
     162        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4C",      PS_DATA_F32, "fourth momemt cos theta",                    moments.M_c4);
     163        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4S",      PS_DATA_F32, "fourth momemt sin theta",                    moments.M_s4);
     164
     165        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1",       PS_DATA_F32, "first radial moment",                        moments.Mrf);
     166        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH",       PS_DATA_F32, "half radial moment",                         moments.Mrh);
     167        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX",        PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Krf);
     168        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR",    PS_DATA_F32, "Kron Flux Error",                            moments.dKrf);
     169        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER",  PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Kinner);
     170        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER",  PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Kouter);
     171
     172        @>PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "SKY_LIMIT_RAD",    PS_DATA_F32, "Radius where object hits sky",               source->skyRadius);
     173        @>PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "SKY_LIMIT_FLUX",   PS_DATA_F32, "Flux / pix where object hits sky",           source->skyFlux);
     174        @>PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "SKY_LIMIT_SLOPE",  PS_DATA_F32, "d(Flux/pix)/dRadius where object hits sky",  source->skySlope);
    178175
    179176        @ALL@     psMetadataAdd (row, PS_LIST_TAIL, "FLAGS",            PS_DATA_U32, "psphot analysis flags",                      source->mode);
    180         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2",           PS_DATA_U32, "psphot analysis flags",                      source->mode2);
    181         @=PS1_V3@ psMetadataAdd (row, PS_LIST_TAIL, "PADDING2",         PS_DATA_S32, "more padding", 0);
     177        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2",           PS_DATA_U32, "psphot analysis flags",                      source->mode2);
     178        @>PS1_V2@ psMetadataAdd (row, PS_LIST_TAIL, "PADDING2",         PS_DATA_S32, "more padding", 0);
    182179
    183180        // XXX not sure how to get this : need to load Nimages with weight?
     
    286283        @ALL@     source->psfMagErr = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    287284        @ALL@     source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
    288         @=PS1_V3@ source->apMagRaw  = psMetadataLookupF32 (&status, row, "AP_MAG_RAW");
     285        @>PS1_V2@ source->apMagRaw  = psMetadataLookupF32 (&status, row, "AP_MAG_RAW");
    289286
    290287        // XXX use these to determine PAR[PM_PAR_I0] if they exist?
    291         @=PS1_V3@ source->psfFlux   = psMetadataLookupF32 (&status, row, "PSF_INST_FLUX");
    292         @=PS1_V3@ source->psfFluxErr= psMetadataLookupF32 (&status, row, "PSF_INST_FLUX_SIG");
     288        @>PS1_V2@ source->psfFlux   = psMetadataLookupF32 (&status, row, "PSF_INST_FLUX");
     289        @>PS1_V2@ source->psfFluxErr= psMetadataLookupF32 (&status, row, "PSF_INST_FLUX_SIG");
    293290
    294291        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
     
    311308
    312309        @ALL@     source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF");
    313         @=PS1_V3@ source->pixWeightNotPoor = psMetadataLookupF32 (&status, row, "PSF_QF_PERFECT");
     310        @>PS1_V2@ source->pixWeightNotPoor = psMetadataLookupF32 (&status, row, "PSF_QF_PERFECT");
    314311        @ALL@     source->crNsigma  = psMetadataLookupF32 (&status, row, "CR_NSIGMA");
    315312        @ALL@     source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA");
     
    329326        @ALL@     source->moments->Myy = psMetadataLookupF32 (&status, row, "MOMENTS_YY");
    330327
    331         @=PS1_V3@ source->moments->Mrf         = psMetadataLookupF32 (&status, row, "MOMENTS_R1");
    332         @=PS1_V3@ source->moments->Mrh         = psMetadataLookupF32 (&status, row, "MOMENTS_RH");
    333         @=PS1_V3@ source->moments->KronFlux    = psMetadataLookupF32 (&status, row, "KRON_FLUX");
    334         @=PS1_V3@ source->moments->KronFluxErr = psMetadataLookupF32 (&status, row, "KRON_FLUX_ERR");
    335 
    336         @=PS1_V3@ source->moments->KronFinner  = psMetadataLookupF32 (&status, row, "KRON_FLUX_INNER");
    337         @=PS1_V3@ source->moments->KronFouter  = psMetadataLookupF32 (&status, row, "KRON_FLUX_OUTER");
     328        @>PS1_V2@ source->moments->Mrf         = psMetadataLookupF32 (&status, row, "MOMENTS_R1");
     329        @>PS1_V2@ source->moments->Mrh         = psMetadataLookupF32 (&status, row, "MOMENTS_RH");
     330        @>PS1_V2@ source->moments->KronFlux    = psMetadataLookupF32 (&status, row, "KRON_FLUX");
     331        @>PS1_V2@ source->moments->KronFluxErr = psMetadataLookupF32 (&status, row, "KRON_FLUX_ERR");
     332
     333        @>PS1_V2@ source->moments->KronFinner  = psMetadataLookupF32 (&status, row, "KRON_FLUX_INNER");
     334        @>PS1_V2@ source->moments->KronFouter  = psMetadataLookupF32 (&status, row, "KRON_FLUX_OUTER");
     335
     336        @>PS1_V3@ source->skyRadius            = psMetadataLookupF32 (&status, row, "SKY_LIMIT_RAD");
     337        @>PS1_V3@ source->skyFlux              = psMetadataLookupF32 (&status, row, "SKY_LIMIT_FLUX");
     338        @>PS1_V3@ source->skySlope             = psMetadataLookupF32 (&status, row, "SKY_LIMIT_SLOPE");
    338339
    339340        // XXX we do not save all of the 3rd and 4th moment parameters. when we load in data,
    340341        // we are storing enough information so the output will be consistent with the input
    341         @=PS1_V3@ source->moments->Mxxx = +1.0 * psMetadataLookupF32 (&status, row, "MOMENTS_M3C");
    342         @=PS1_V3@ source->moments->Mxxy = 0.0;
    343         @=PS1_V3@ source->moments->Mxyy = 0.0;
    344         @=PS1_V3@ source->moments->Myyy = -1.0 * psMetadataLookupF32 (&status, row, "MOMENTS_M3S");
    345 
    346         @=PS1_V3@ source->moments->Mxxxx = +1.00 * psMetadataLookupF32 (&status, row, "MOMENTS_M4C");
    347         @=PS1_V3@ source->moments->Mxxxy = 0.0;
    348         @=PS1_V3@ source->moments->Mxxyy = 0.0;
    349         @=PS1_V3@ source->moments->Mxyyy = -0.25 * psMetadataLookupF32 (&status, row, "MOMENTS_M4S");
    350         @=PS1_V3@ source->moments->Myyyy = 0.0;
     342        @>PS1_V2@ source->moments->Mxxx = +1.0 * psMetadataLookupF32 (&status, row, "MOMENTS_M3C");
     343        @>PS1_V2@ source->moments->Mxxy = 0.0;
     344        @>PS1_V2@ source->moments->Mxyy = 0.0;
     345        @>PS1_V2@ source->moments->Myyy = -1.0 * psMetadataLookupF32 (&status, row, "MOMENTS_M3S");
     346
     347        @>PS1_V2@ source->moments->Mxxxx = +1.00 * psMetadataLookupF32 (&status, row, "MOMENTS_M4C");
     348        @>PS1_V2@ source->moments->Mxxxy = 0.0;
     349        @>PS1_V2@ source->moments->Mxxyy = 0.0;
     350        @>PS1_V2@ source->moments->Mxyyy = -0.25 * psMetadataLookupF32 (&status, row, "MOMENTS_M4S");
     351        @>PS1_V2@ source->moments->Myyyy = 0.0;
    351352
    352353        @ALL@     source->mode = psMetadataLookupU32 (&status, row, "FLAGS");
    353         @=PS1_V3@ source->mode2 = psMetadataLookupU32 (&status, row, "FLAGS2");
     354        @>PS1_V2@ source->mode2 = psMetadataLookupU32 (&status, row, "FLAGS2");
    354355        assert (status);
    355356
  • trunk/psphot

  • trunk/psphot/src/Makefile.am

    r32348 r32633  
    185185        psphotKronMasked.c             \
    186186        psphotKronIterate.c            \
     187        psphotRadialProfileWings.c     \
    187188        psphotDeblendSatstars.c        \
    188189        psphotMosaicSubimage.c         \
     
    201202        psphotRadialBins.c             \
    202203        psphotRadialApertures.c        \
    203         psphotRadialAperturesByObject.c \
    204204        psphotPetrosian.c              \
    205205        psphotPetrosianRadialBins.c    \
  • trunk/psphot/src/psphot.h

    r32348 r32633  
    428428bool psphotRadialAperturesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, int entry);
    429429bool psphotRadialApertures_Threaded (psThreadJob *job);
    430 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, psImageMaskType maskVal, const psVector *radMax, int entry);
     430bool psphotRadialApertureSource (pmSource *source, pmReadout *readout, int entry, psVector *pixRadius2, psVector *pixFlux, psVector *pixVer);
     431// bool psphotRadialApertureSource (pmSource *source, int entry);
    431432
    432433bool psphotExtendedSourceAnalysisByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule);
     
    466467bool psphotKronIterate_Threaded (psThreadJob *job);
    467468
     469bool psphotRadialProfileWings (pmConfig *config, const pmFPAview *view, const char *filerule);
     470bool psphotRadialProfileWingsReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources);
     471bool psphotRadialProfileWings_Threaded (psThreadJob *job);
     472
    468473bool psphotStackObjectsSelectForAnalysis (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);
    469474
  • trunk/psphot/src/psphotExtendedSourceAnalysis.c

    r32348 r32633  
    209209        // if we have checked the source validity on the basis of the object set, then
    210210        // we either skip these tests below or we skip the source completely
    211         if (source->tmpFlags & PM_SOURCE_TMPF_STACK_SKIP) continue;
    212         if (source->tmpFlags & PM_SOURCE_TMPF_STACK_KEEP) goto keepSource;
     211        if (source->tmpFlags & PM_SOURCE_TMPF_PETRO_SKIP) continue;
     212        if (source->tmpFlags & PM_SOURCE_TMPF_PETRO_KEEP) goto keepSource;
    213213
    214214        // skip PSF-like and non-astronomical objects
  • trunk/psphot/src/psphotFitSourcesLinear.c

    r32348 r32633  
    134134    for (int i = 0; i < sources->n; i++) {
    135135        pmSource *source = sources->data[i];
     136
     137        // psAssert (source->peak, "source without peak??");
     138        // psAssert (source->peak->footprint, "peak without footprint??");
    136139
    137140        // turn this bit off and turn it on again if we pass this test
  • trunk/psphot/src/psphotGuessModels.c

    r32348 r32633  
    170170        if (!source->peak) continue;
    171171
     172        // psAssert (source->peak->footprint, "peak without footprint??");
     173
    172174        nSrc ++;
    173175
  • trunk/psphot/src/psphotKronIterate.c

    r32348 r32633  
    151151            }
    152152# else
    153             if (!psphotExtendedSourceFits_Threaded(job)) {
     153            if (!psphotKronIterate_Threaded(job)) {
    154154                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    155155                psFree(AnalysisRegion);
     
    192192    float MIN_KRON_RADIUS           = PS_SCALAR_VALUE(job->args->data[6],F32);
    193193
    194     for (int j = 0; j < 5; j++) {
     194    // XXX TEST : set iteration to 1
     195    for (int j = 0; j < 1; j++) {
    195196        for (int i = 0; i < sources->n; i++) {
    196197
     
    209210
    210211            // use S/N to control max window size
    211             float kronSN = source->moments->KronFlux / source->moments->KronFluxErr;
     212            // float kronSN = source->moments->KronFlux / source->moments->KronFluxErr;
    212213
    213214            // maxWindow -> 1.5*RADIUS for kronSN = 5.0, keeping S.B. constant (kronSN ~ flux)
    214215            // (kronSN / maxWindow^2) = (5.0 / (1.5 RADIUS)^2)
    215216            // maxWindow = 1.5 * RADIUS * sqrt(kronSN / 5.0)
    216             float maxWindow = (isfinite(kronSN) && (kronSN > 5.0)) ? 1.5 * RADIUS * sqrt(kronSN / 5.0) : 1.5*RADIUS;
     217            // XXX float maxWindow = (isfinite(kronSN) && (kronSN > 5.0)) ? 1.5 * RADIUS * sqrt(kronSN / 5.0) : 1.5*RADIUS;
    217218
    218219            // iterate to the window radius
    219             float windowRadius = PS_MIN(PS_MAX(RADIUS, 4.0*source->moments->Mrf), maxWindow);
     220            // XXX float windowRadius = PS_MIN(PS_MAX(RADIUS, 4.0*source->moments->Mrf), maxWindow);
     221
     222            // XXX TEST : use a window based on the radial profile numbers: max is skyRadius, min is RADIUS
     223            float maxWindow = source->skyRadius;
     224            float windowRadius = PS_MAX(RADIUS, maxWindow);
    220225
    221226            // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS
  • trunk/psphot/src/psphotRadialApertures.c

    r32348 r32633  
    2626    int num = psphotFileruleCount(config, filerule);
    2727
     28    // skip the chisq image (optionally?)
     29    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     30    if (!status) chisqNum = -1;
     31
    2832    // loop over the available readouts
    2933    for (int i = 0; i < num; i++) {
     34        if (i == chisqNum) continue; // skip chisq image
     35
    3036        if (!psphotRadialAperturesReadout (config, view, filerule, i, recipe, entry)) {
    3137            psError (PSPHOT_ERR_CONFIG, false, "failed on measure extended source aperture-like parameters for %s entry %d", filerule, i);
     
    3541    return true;
    3642}
     43
     44// these values are used by all threads repeatedly (and are not modified)
     45static psVector *aperRadii = NULL;
     46static psVector *aperRadii2 = NULL;
     47static float outerRadius = NAN;
     48static float SN_LIM = NAN;
     49static psImageMaskType maskVal = 0;
    3750
    3851// aperture-like measurements for extended sources
     
    7588        nThreads = 0;
    7689    }
     90
     91    // aperRadii stores the upper bounds of the annuli
     92    // XXX keep the same name here as for the petrosian / elliptical apertures?
     93    aperRadii = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER");
     94    psAssert (aperRadii, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe");
     95    psAssert (aperRadii->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define");
     96
     97    outerRadius = aperRadii->data.F32[aperRadii->n - 1];
     98
     99    // save the R^2 values as well for quicker comparison
     100    aperRadii2 = psVectorAlloc(aperRadii->n, PS_TYPE_F32);
     101    for (int i = 0; i < aperRadii->n; i++) {
     102        aperRadii2->data.F32[i] = PS_SQR(aperRadii->data.F32[i]);
     103    }
     104
     105    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     106    maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     107    assert (maskVal);
     108
     109    // S/N limit to perform full non-linear fits
     110    SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM");
    77111
    78112    // source analysis is done in S/N order (brightest first)
     
    117151            psArrayAdd(job->args, 1, cells->data[j]); // sources
    118152            psArrayAdd(job->args, 1, AnalysisRegion);
    119             psArrayAdd(job->args, 1, recipe);
    120 
    121153            PS_ARRAY_ADD_SCALAR(job->args, entry,  PS_TYPE_S32);
    122154            PS_ARRAY_ADD_SCALAR(job->args, nEntry, PS_TYPE_S32);
    123 
    124155            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nradial
    125156
    126 // set this to 0 to run without threading
     157            // set this to 0 to run without threading
    127158# if (1)           
    128159            if (!psThreadJobAddPending(job)) {
     
    138169            }
    139170            psScalar *scalar = NULL;
    140             scalar = job->args->data[6];
     171            scalar = job->args->data[5];
    141172            Nradial += scalar->data.S32;
    142173            psFree(job);
     
    158189            } else {
    159190                psScalar *scalar = NULL;
    160                 scalar = job->args->data[6];
     191                scalar = job->args->data[5];
    161192                Nradial += scalar->data.S32;
    162193            }
     
    166197    psFree (cellGroups);
    167198    psFree(AnalysisRegion);
     199    psFree (aperRadii2);
    168200
    169201    psLogMsg ("psphot", PS_LOG_WARN, "radial source apertures: %f sec for %d objects\n", psTimerMark ("psphot.radial"), Nradial);
     
    173205bool psphotRadialApertures_Threaded (psThreadJob *job) {
    174206
    175     bool status;
    176207    int Nradial = 0;
    177208
     
    180211    psArray *sources        = job->args->data[1];
    181212    psRegion *region        = job->args->data[2];
    182     psMetadata *recipe      = job->args->data[3];
    183 
    184     int entry               = PS_SCALAR_VALUE(job->args->data[4],S32); // which psf-matched image are we working on? (0 == unmatched)
    185     int nEntry              = PS_SCALAR_VALUE(job->args->data[5],S32); // total number of psf-matched images + 1 unmatched
    186 
    187     // radMax stores the upper bounds of the annuli
    188     // XXX keep the same name here as for the petrosian / elliptical apertures?
    189     psVector *radMax = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER");
    190     psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe");
    191     psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define");
    192 
    193     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
    194     psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
    195     assert (maskVal);
    196 
    197     // S/N limit to perform full non-linear fits
    198     float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM");
    199 
    200     float outerRadius = radMax->data.F32[radMax->n - 1];
     213    int entry               = PS_SCALAR_VALUE(job->args->data[3],S32); // which psf-matched image are we working on? (0 == unmatched)
     214    int nEntry              = PS_SCALAR_VALUE(job->args->data[4],S32); // total number of psf-matched images + 1 unmatched
     215
     216    // storage for the derived pixel values (these are passed into psphotRadialApertureSource)
     217    psVector *pixRadius2 = psVectorAllocEmpty(100, PS_TYPE_F32);
     218    psVector *pixFlux    = psVectorAllocEmpty(100, PS_TYPE_F32);
     219    psVector *pixVar     = psVectorAllocEmpty(100, PS_TYPE_F32);
    201220
    202221    // choose the sources of interest
     
    204223
    205224        pmSource *source = sources->data[i];
     225
     226        // if we have checked the source validity on the basis of the object set, then
     227        // we either skip these tests below or we skip the source completely
     228        if (source->tmpFlags & PM_SOURCE_TMPF_RADIAL_SKIP) continue;
     229        if (source->tmpFlags & PM_SOURCE_TMPF_RADIAL_KEEP) goto keepSource;
    206230
    207231        // skip PSF-like and non-astronomical objects
     
    222246        if (source->peak->x > region->x1) continue;
    223247        if (source->peak->y > region->y1) continue;
     248
     249    keepSource:
    224250
    225251        // allocate pmSourceExtendedParameters, if not already defined
     
    240266        }
    241267
    242         // we need to change the view for the radial aperture analysis, but we want to recover exactly
    243         // the original view; the following elements get destroyed by pmSourceRedefinePixels so save them:
    244         psImage *oldMaskObj   = psMemIncrRefCounter(source->maskObj);
    245         psImage *oldModelFlux = psMemIncrRefCounter(source->modelFlux);
    246         psImage *oldPSFimage  = psMemIncrRefCounter(source->psfImage);
    247         psRegion oldRegion    = source->region;
    248 
    249268        Nradial ++;
    250269
    251         // force source image to be a bit larger...
    252         pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, outerRadius + 2);
    253 
    254         if (!psphotRadialApertureSource (source, recipe, maskVal, radMax, entry)) {
     270        if (!psphotRadialApertureSource (source, readout, entry, pixRadius2, pixFlux, pixVar)) {
    255271            psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    256272        } else {
     
    258274        }
    259275
    260         pmSourceRedefinePixelsByRegion (source, readout, oldRegion);
    261         psFree(source->maskObj);   source->maskObj   = oldMaskObj;
    262         psFree(source->modelFlux); source->modelFlux = oldModelFlux;
    263         psFree(source->psfImage);  source->psfImage  = oldPSFimage;
    264        
    265276        // re-subtract the object, leave local sky
    266277        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    267278    }
    268     psScalar *scalar = job->args->data[6];
     279    psScalar *scalar = job->args->data[5];
    269280    scalar->data.S32 = Nradial;
     281
     282    psFree (pixRadius2);
     283    psFree (pixFlux);
     284    psFree (pixVar);
    270285
    271286    return true;
    272287}
    273288
    274 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, psImageMaskType maskVal, const psVector *aperRadii, int entry) {
    275 
     289bool psphotRadialApertureSource (pmSource *source, pmReadout *readout, int entry, psVector *pixRadius2, psVector *pixFlux, psVector *pixVar) {
     290                                           
    276291    // if we are a child source, save the results to the parent source radial aperture array
    277292    psArray *radialAperSet = source->radialAper;
     
    285300    radialAperSet->data[entry] = radialAper;
    286301
    287     // storage for the derived pixel values
    288     psVector *pixRadius2 = psVectorAllocEmpty(100, PS_TYPE_F32);
    289     psVector *pixFlux    = psVectorAllocEmpty(100, PS_TYPE_F32);
    290     psVector *pixVar     = psVectorAllocEmpty(100, PS_TYPE_F32);
     302    // find the largest aperture of interest (use only apertures with inner radii <=
     303    // source->skyRadius)
     304    int lastAp = aperRadii->n;
     305    for (int i = 0; i < aperRadii->n; i++) {
     306        if (aperRadii->data.F32[i] < source->skyRadius) continue;
     307        lastAp = i + 1;
     308        break;
     309    }
    291310
    292311    // outer-most radius for initial truncation
    293     float Rmax  = aperRadii->data.F32[aperRadii->n - 1];
     312    float Rmax  = aperRadii->data.F32[lastAp - 1];
    294313    float Rmax2 = PS_SQR(Rmax);
    295314
    296     // store the R^2 values for the apertures
    297     psVector *aperRadii2 = psVectorAlloc(aperRadii->n, PS_TYPE_F32);
    298     for (int i = 0; i < aperRadii->n; i++) {
    299         aperRadii2->data.F32[i] = PS_SQR(aperRadii->data.F32[i]);
    300     }
     315    // in this function, the operatins are relative to the full image (readout->image, etc)
    301316
    302317    float xCM = NAN, yCM = NAN;
    303318    if (pmSourcePositionUseMoments(source)) {
    304         xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage
    305         yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage
     319        xCM = source->moments->Mx; // index coord of peak in readout
     320        yCM = source->moments->My; // index coord of peak in readout
    306321    } else {
    307         xCM = source->peak->xf - 0.5 - source->pixels->col0; // coord of peak in subimage
    308         yCM = source->peak->yf - 0.5 - source->pixels->row0; // coord of peak in subimage
    309     }
     322        xCM = source->peak->xf; // index coord of peak in readout
     323        yCM = source->peak->yf; // index coord of peak in readout
     324    }
     325
     326    int Nx = readout->image->numCols;
     327    int Ny = readout->image->numRows;
     328
     329    pixRadius2->n = 0;
     330    pixFlux->n = 0;
     331    pixVar->n = 0;
    310332
    311333    // one pass through the pixels to select the valid pixels and calculate R^2
    312     for (int iy = 0; iy < source->pixels->numRows; iy++) {
    313 
    314         float yDiff = iy - yCM;
    315         if (fabs(yDiff) > Rmax) continue;
    316 
    317         float *vPix = source->pixels->data.F32[iy];
    318         float *vWgt = source->variance->data.F32[iy];
    319         psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy];
    320 
    321         for (int ix = 0; ix < source->pixels->numCols; ix++, vPix++, vWgt++) {
    322 
    323             if (vMsk) {
    324                 if (*vMsk & maskVal) {
    325                     vMsk++;
    326                     continue;
    327                 }
    328                 vMsk++;
    329             }
    330             if (isnan(*vPix)) continue;
    331 
    332             float xDiff = ix - xCM;
    333             if (fabs(xDiff) > Rmax) continue;
     334    for (int iy = -Rmax; iy < Rmax + 1; iy++) {
     335
     336        float yDiff = iy + 0.5 + yCM;  // y-coordinate at this offse
     337        int yPix = (int) yDiff;
     338
     339        if (yPix < 0) continue;
     340        if (yPix > Ny - 1) continue;
     341        if (fabs(iy) > Rmax) continue;
     342
     343        float *vPix = readout->image->data.F32[yPix];
     344        float *vWgt = readout->variance->data.F32[yPix];
     345        psImageMaskType  *vMsk = readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix];
     346
     347        for (int ix = -Rmax; ix < Rmax + 1; ix++) {
     348
     349            float xDiff = ix + 0.5 + xCM;  // x-coordinate at this offse
     350            int xPix = (int) xDiff;
     351           
     352            if (xPix < 0) continue;
     353            if (xPix > Nx - 1) continue;
     354            if (fabs(ix) > Rmax) continue;
     355           
     356            if (vMsk[xPix] & maskVal) continue;
     357            if (isnan(vPix[xPix])) continue;
    334358
    335359            // radius is just a function of (xDiff, yDiff)
    336             float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     360            float r2  = PS_SQR(ix) + PS_SQR(iy);
    337361            if (r2 > Rmax2) continue;
    338362
    339363            psVectorAppend(pixRadius2, r2);
    340             psVectorAppend(pixFlux, *vPix);
    341             psVectorAppend(pixVar, *vWgt);
     364            psVectorAppend(pixFlux, vPix[xPix]);
     365            psVectorAppend(pixVar, vWgt[xPix]);
    342366        }
    343367    }
     
    348372    psVector *fill    = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
    349373
     374    // init the apertures of interest to 0.0, the rest go to NAN
    350375    psVectorInit (flux,    0.0);
    351376    psVectorInit (fluxStd, 0.0);
    352377    psVectorInit (fluxErr, 0.0);
    353378    psVectorInit (fill,    0.0);
     379    for (int i = lastAp; i < flux->n; i++) {
     380        flux->data.F32[i] = NAN;
     381        fluxStd->data.F32[i] = NAN;
     382        fluxErr->data.F32[i] = NAN;
     383        fill->data.F32[i] = NAN;
     384    }
    354385
    355386    float *rPix2 = pixRadius2->data.F32;
     
    358389        int j = 0;
    359390        float *aRad2 = aperRadii2->data.F32;
    360         for (; (*aRad2 < *rPix2) && (j < aperRadii2->n); j++, aRad2++);
    361         for (; j < aperRadii2->n; j++, aRad2++) {
     391        for (; (*aRad2 < *rPix2) && (j < lastAp); j++, aRad2++);
     392
     393        // XXX I can speed this up by only saving this single aperture
     394        for (; j < lastAp; j++, aRad2++) {
    362395            flux->data.F32[j]    += pixFlux->data.F32[i];
    363396            fluxStd->data.F32[j] += PS_SQR(pixFlux->data.F32[i]);
     
    371404       2) the fractional fill factor (count of valid pixels / effective area of the aperture
    372405       3) the error on the flux within that aperture
    373      */
    374 
    375     for (int i = 0; i < flux->n; i++) {
     406    */
     407
     408    for (int i = 0; i < lastAp; i++) {
    376409        // calculate the total flux for bin 'nOut'
    377410        float Area = M_PI*aperRadii2->data.F32[i];
     
    383416        // XXX report the total flux or the mask-corrected flux?
    384417        // flux->data.F32[i]    = SBmean * Area;
    385         // fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / nPix;
     418        // fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / Pinx;
    386419
    387420        fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]);
     
    393426    }
    394427   
     428# if (1)
    395429    radialAper->flux = flux;
    396430    radialAper->fluxStdev = fluxStd;
    397431    radialAper->fluxErr = fluxErr;
    398432    radialAper->fill = fill;
    399 
    400     psFree (aperRadii2);
    401     psFree (pixRadius2);
    402     psFree (pixFlux);
    403     psFree (pixVar);
     433# else
     434    // XXX TEST
     435    psFree(flux);
     436    psFree(fluxStd);
     437    psFree(fluxErr);
     438    psFree(fill);
     439# endif
    404440
    405441    return true;
    406442}
     443
     444/*** below is a test to use a sort to speed this up, not very successfully ***/
    407445
    408446static int nCalls = 0;
     
    495533// *** pmSourceRadialProfileSortPair is a utility function for sorting a pair of vectors
    496534# define COMPARE_VECT(A,B) (radius->data.F32[A] < radius->data.F32[B])
    497 # define SWAP_VECT(TYPE,A,B) { \
    498   float tmp; \
    499   if (A != B) { \
    500     tmp = radius->data.F32[A]; \
    501     radius->data.F32[A] = radius->data.F32[B];  \
    502     radius->data.F32[B] = tmp; \
    503     tmp = pixFlux->data.F32[A]; \
    504     pixFlux->data.F32[A] = pixFlux->data.F32[B]; \
    505     pixFlux->data.F32[B] = tmp; \
    506     tmp = pixVar->data.F32[A]; \
    507     pixVar->data.F32[A] = pixVar->data.F32[B]; \
    508     pixVar->data.F32[B] = tmp; \
    509   } \
    510 }
     535# define SWAP_VECT(TYPE,A,B) {                                  \
     536        float tmp;                                              \
     537        if (A != B) {                                           \
     538            tmp = radius->data.F32[A];                          \
     539            radius->data.F32[A] = radius->data.F32[B];          \
     540            radius->data.F32[B] = tmp;                          \
     541            tmp = pixFlux->data.F32[A];                         \
     542            pixFlux->data.F32[A] = pixFlux->data.F32[B];        \
     543            pixFlux->data.F32[B] = tmp;                         \
     544            tmp = pixVar->data.F32[A];                          \
     545            pixVar->data.F32[A] = pixVar->data.F32[B];          \
     546            pixVar->data.F32[B] = tmp;                          \
     547        }                                                       \
     548    }
    511549
    512550bool psphotRadialAperturesSortFlux (psVector *radius, psVector *pixFlux, psVector *pixVar) {
  • trunk/psphot/src/psphotReadout.c

    r32348 r32633  
    190190    psphotDumpChisqs (config, view, filerule);
    191191
     192    // measure the radial profiles to the sky
     193    psphotRadialProfileWings (config, view, filerule);
     194
    192195    // re-measure the kron mags with models subtracted.  this pass uses a circular window of size PSF_MOMENTS_RADIUS (same window used to measure the psf-scale moments)
    193196   
     
    305308pass1finish:
    306309
     310    // measure the radial profiles to the sky (only measures new objects)
     311    psphotRadialProfileWings (config, view, filerule);
     312
    307313    // re-measure the kron mags with models subtracted
    308314    // psphotKronMasked(config, view, filerule);
  • trunk/psphot/src/psphotSetThreads.c

    r32348 r32633  
    5050    psFree(task);
    5151
    52     task = psThreadTaskAlloc("PSPHOT_RADIAL_APERTURES", 7);
     52    task = psThreadTaskAlloc("PSPHOT_RADIAL_APERTURES", 6);
    5353    task->function = &psphotRadialApertures_Threaded;
     54    psThreadTaskAdd(task);
     55    psFree(task);
     56
     57    task = psThreadTaskAlloc("PSPHOT_RADIAL_PROFILE_WINGS", 3);
     58    task->function = &psphotRadialProfileWings_Threaded;
    5459    psThreadTaskAdd(task);
    5560    psFree(task);
  • trunk/psphot/src/psphotSourceFits.c

    r32348 r32633  
    357357    pmSource *newSrc = pmSourceCopy (source);
    358358    newSrc->modelPSF = psMemIncrRefCounter (DBL->data[1]);
     359    newSrc->peak->footprint = source->peak->footprint; // just a reference; the peak does not own the footprint
     360    psArrayAdd(newSrc->peak->footprint->peaks, 1, newSrc->peak); // the footprint owns the peak
    359361
    360362    // build cached models and subtract
  • trunk/psphot/src/psphotSourceMatch.c

    r32348 r32633  
    6767    objects = psArraySort (objects, pmPhotObjSortByX);
    6868 
    69     psVector *found = psVectorAlloc(sources->n, PS_TYPE_U8);
    70     psVectorInit (found, 0);
     69    psVector *foundSrc = psVectorAlloc(sources->n, PS_TYPE_U8);
     70    psVectorInit (foundSrc, 0);
     71
     72    psVector *foundObj = psVectorAlloc(sources->n, PS_TYPE_U8);
     73    psVectorInit (foundObj, 0);
    7174
    7275    // match sources to existing objects
     
    9396        if (dx > +1.02*RADIUS) NEXT2;
    9497 
     98        /* this block will match a given detection to the closest object within range of that detection.
     99           XXX note that this matches ALL detections within range of the single object to that same object
     100           this is bad, but I cannot just go in linear order (ie, mark off each object as they are
     101           used).  I should make a list of all Nobj * Ndet pairs in range and choose the matches
     102           based on their separations.  UGH
     103        */
     104   
    95105        // we are within match range, look for matches:
    96106        int Jmin = -1;
     
    98108        for (int J = j; (dx > -1.02*RADIUS) && (J < objects->n); J++) {
    99109 
     110            // skip objects that are already assigned:
     111            if (foundObj->data.U8[J]) continue;
    100112            obj = objects->data[J];
    101113           
     
    117129        }
    118130        obj = objects->data[Jmin];
     131        foundObj->data.U8[Jmin] = 1;
    119132
    120133        // add to object
    121134        pmPhotObjAddSource (obj, src);
    122         found->data.U8[i] = 1;
     135        foundSrc->data.U8[i] = 1;
    123136        i++;
    124137    }
     
    128141    for (i = 0; i < sources->n; i++) {
    129142
    130         if (found->data.U8[i]) continue;
     143        if (foundSrc->data.U8[i]) continue;
    131144
    132145        pmSource *src = sources->data[i];
     
    139152    psLogMsg ("psphot", PS_LOG_DETAIL, "matched sources (%ld vs %ld)", sources->n, objects->n);
    140153
    141     psFree (found);
     154    psFree (foundSrc);
     155    psFree (foundObj);
    142156    return true;
    143157}
     
    234248           
    235249            // assign to a footprint on this readout->image
    236             peak->footprint = pmFootprintCopyData(footprint, readout->image);
    237 
    238             // the peak does not claim ownership of the footprint (it does not free it). save a copy of this
    239             // footprint on detections->footprints so we can free it later
    240             psArrayAdd(detections->footprints, 100, peak->footprint);
    241             psFree (peak->footprint);
     250            if (footprint) {
     251                peak->footprint = pmFootprintCopyData(footprint, readout->image);
     252
     253                // the peak does not claim ownership of the footprint (it does not free it). save a copy of this
     254                // footprint on detections->footprints so we can free it later
     255                psArrayAdd(detections->footprints, 100, peak->footprint);
     256                psFree (peak->footprint);
     257            }
    242258           
    243259            // create a new source
     
    268284        pmPhotObj *obj = objects->data[i];
    269285        nSources += obj->sources->n;
     286        psAssert (obj->sources->n == nImages, "failed to match sources?");
    270287    }
    271288    psLogMsg ("psphot", PS_LOG_DETAIL, "total of %d sources for %d images", nSources, nImages);
  • trunk/psphot/src/psphotSourceSize.c

    r32348 r32633  
    156156
    157157    // XXX fix this (was source->n  - first)
    158     psLogMsg ("psphot.size", PS_LOG_INFO, "measure source sizes for %ld sources: %f sec\n", sources->n, psTimerMark ("psphot.size"));
     158    psLogMsg ("psphot.size", PS_LOG_WARN, "measure source sizes for %ld sources: %f sec\n", sources->n, psTimerMark ("psphot.size"));
    159159
    160160    psphotVisualPlotSourceSize (recipe, readout->analysis, sources);
  • trunk/psphot/src/psphotSourceStats.c

    r32348 r32633  
    124124        // add the peak
    125125        source->peak = psMemIncrRefCounter(peak);
     126
     127        // psAssert (source->peak->footprint, "peak without footprint??");
    126128
    127129        // allocate space for moments
  • trunk/psphot/src/psphotStackObjects.c

    r32348 r32633  
    7070
    7171    // S/N limit to perform full non-linear fits
    72     float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");
     72    float SN_LIM_PETRO  = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");
     73    float SN_LIM_RADIAL = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM");
    7374
    7475    bool doPetroStars   = psMetadataLookupBool (&status, recipe, "PETROSIAN_FOR_STARS");
     
    8182        // we check each source for an object and keep the object if any source is valid
    8283
    83         bool keepObject = false;
     84        bool keepObjectRadial = false;
     85        bool keepObjectPetro = false;
    8486        for (int j = 0; j < object->sources->n; j++) {
    8587
     
    9496            if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
    9597           
    96         // optionally allow non-extended objects to get petrosians as well
    97         if (!doPetroStars) {
    98             if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) continue;
    99             if (source->type == PM_SOURCE_TYPE_STAR) continue;
    100         }
    101 
    102             // limit selection to some SN limit
    103             // assert (source->peak); // how can a source not have a peak?
    104             // limit selection to some SN limit
    105             bool skipSource = false;
    106             if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    107                 skipSource = (source->moments->KronFlux < SN_LIM * source->moments->KronFluxErr);
    108             } else {
    109                 skipSource = (sqrt(source->peak->detValue) < SN_LIM);
    110             }
    111             if (skipSource) continue;
    112 
    11398            // limit selection by analysis region (this automatically apply
    11499            if (source->peak->x < AnalysisRegion.x0) continue;
     
    117102            if (source->peak->y > AnalysisRegion.y1) continue;
    118103           
    119             keepObject = true;
     104            // SN limit tests for RADIAL APERTURES:
     105            bool skipSourceRadial = false;
     106            if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
     107                skipSourceRadial = (source->moments->KronFlux < SN_LIM_RADIAL * source->moments->KronFluxErr);
     108            } else {
     109                skipSourceRadial = (sqrt(source->peak->detValue) < SN_LIM_RADIAL);
     110            }
     111            if (!skipSourceRadial) keepObjectRadial = true;
     112
     113            // SN limit tests for PETRO
     114            bool skipSourcePetro = false;
     115            if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
     116                skipSourcePetro = (source->moments->KronFlux < SN_LIM_PETRO * source->moments->KronFluxErr);
     117            } else {
     118                skipSourcePetro = doPetroStars ? (sqrt(source->peak->detValue) < SN_LIM_PETRO) : true;
     119            }
     120            if (!skipSourcePetro) keepObjectPetro = true;
     121
     122            keepObjectPetro = true;
    120123        }
    121124
     
    128131            // avoid the single-detection tests
    129132
    130             if (keepObject) {
    131                 source->tmpFlags |=  PM_SOURCE_TMPF_STACK_KEEP;
    132                 source->tmpFlags &= ~PM_SOURCE_TMPF_STACK_SKIP;
     133            if (keepObjectPetro) {
     134                source->tmpFlags |=  PM_SOURCE_TMPF_PETRO_KEEP;
     135                source->tmpFlags &= ~PM_SOURCE_TMPF_PETRO_SKIP;
    133136            } else {
    134                 source->tmpFlags |=  PM_SOURCE_TMPF_STACK_SKIP;
    135                 source->tmpFlags &= ~PM_SOURCE_TMPF_STACK_KEEP;
     137                source->tmpFlags |=  PM_SOURCE_TMPF_PETRO_SKIP;
     138                source->tmpFlags &= ~PM_SOURCE_TMPF_PETRO_KEEP;
     139            }       
     140
     141            if (keepObjectRadial) {
     142                source->tmpFlags |=  PM_SOURCE_TMPF_RADIAL_KEEP;
     143                source->tmpFlags &= ~PM_SOURCE_TMPF_RADIAL_SKIP;
     144            } else {
     145                source->tmpFlags |=  PM_SOURCE_TMPF_RADIAL_SKIP;
     146                source->tmpFlags &= ~PM_SOURCE_TMPF_RADIAL_KEEP;
    136147            }       
    137148        }
  • trunk/psphot/src/psphotStackReadout.c

    r32348 r32633  
    4343
    4444bool psphotStackReadout (pmConfig *config, const pmFPAview *view) {
     45
     46    psArray *objects = NULL; // used below after 'pass1finish' label
    4547
    4648    // measure the total elapsed time in psphotReadout.  dtime is the elapsed time used jointly
     
    169171    psphotStackVisualFilerule(config, view, STACK_SRC);
    170172
     173    // measure the radial profiles to the sky
     174    psphotRadialProfileWings (config, view, STACK_SRC);
     175
    171176    // re-measure the kron mags with models subtracted.  this pass starts with a circular
    172177    // window of size PSF_MOMENTS_RADIUS (same window used to measure the psf-scale moments)
     
    184189    psphotReplaceAllSources (config, view, STACK_SRC); // pass 1 (detections->allSources)
    185190
     191    // if we only do one pass, skip to extended source analysis
     192    if (!strcasecmp (breakPt, "PASS1")) goto pass1finish;
     193
    186194    // linear fit to include all sources (subtract again)
    187195    // NOTE : apply to ALL sources (extended + psf)
    188196    psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 2 (detections->allSources)
    189 
    190     // if we only do one pass, skip to extended source analysis
    191     if (!strcasecmp (breakPt, "PASS1")) goto pass1finish;
    192197
    193198    // NOTE: possibly re-measure background model here with objects subtracted / or masked
     
    238243        // XXX check on free of sources...
    239244        psphotMergeSources (config, view, STACK_SRC); // (detections->newSources + detections->allSources -> detections->allSources)
    240 
    241         // NOTE: apply to ALL sources
    242         psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 3 (detections->allSources)
    243245    }
    244246
    245247pass1finish:
     248
     249    // generate the objects (objects unify the sources from the different images) NOTE: could
     250    // this just match the detections for the chisq image, and not bother measuring the source
     251    // stats in that case...?
     252    objects = psphotMatchSources (config, view, STACK_SRC);
     253    psMemDump("matchsources");
     254
     255    psphotStackObjectsUnifyPosition (objects);
     256
     257    psphotStackObjectsSelectForAnalysis (config, view, STACK_SRC, objects);
     258
     259    // NOTE: apply to ALL sources
     260    psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 3 (detections->allSources)
     261
     262    // measure the radial profiles to the sky (only measures new objects)
     263    psphotRadialProfileWings (config, view, STACK_SRC);
    246264
    247265    // re-measure the kron mags with models subtracted
     
    254272
    255273    psMemDump("psfstats");
    256 
    257     // generate the objects (objects unify the sources from the different images)
    258     // XXX this could just match the detections for the chisq image, and not bother measuring the
    259     // source stats in that case...
    260     psArray *objects = psphotMatchSources (config, view, STACK_SRC);
    261     psMemDump("matchsources");
    262 
    263     psphotStackObjectsUnifyPosition (objects);
    264 
    265     psphotStackObjectsSelectForAnalysis (config, view, STACK_SRC, objects);
    266274
    267275    // measure elliptical apertures, petrosians (objects sorted by S/N)
     
    281289
    282290    // measure circular, radial apertures (objects sorted by S/N)
    283     // XXX can we just use psphotRadialApertures
    284     // XXX make sure the headers are consistent with this (which PSF convolutions, ie mark 'none')
    285     // psphotRadialAperturesByObject (config, objectsRadial, view, STACK_SRC, nMatchedPSF);
     291    // this forces photometry on the undetected sources from other images
    286292    psphotRadialApertures (config, view, STACK_SRC, 0); // XXX entry 0 == unmatched?
    287293    psMemDump("extmeas");
     
    323329    psphotMagnitudes(config, view, STACK_SRC);
    324330
    325     if (0 && !psphotEfficiency(config, view, STACK_DET)) {
     331    // XXX NOTE: this function wants to have the PSF of the image, but we (so far) only measure the
     332    // PSF of the SRC image.  can we fake it by generating the PSF for DET as well (up above)?
     333    if (false && !psphotEfficiency(config, view, STACK_DET)) {
    326334        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
    327335        psErrorClear();
Note: See TracChangeset for help on using the changeset viewer.