IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36441 for trunk/psphot


Ignore:
Timestamp:
Jan 14, 2014, 2:28:47 PM (13 years ago)
Author:
bills
Message:

Iniital implementation of the full force stages to the pipeline.
Maginitude and galactic coordinate limits on extended source fits

Location:
trunk
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/psphot

  • trunk/psphot/src

  • trunk/psphot/src/Makefile.am

    r36375 r36441  
    2525libpsphot_la_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
    2626
    27 bin_PROGRAMS = psphot psphotForced psphotFullForce psphotMinimal psphotMakePSF psphotStack psphotModelTest psmakecff
     27bin_PROGRAMS = psphot psphotForced psphotFullForce psphotFullForceSummary psphotMinimal psphotMakePSF psphotStack psphotModelTest psmakecff
    2828# bin_PROGRAMS = psphotPetrosianStudy psphotTest psphotMomentsStudy
    2929
     
    3939psphotFullForce_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
    4040psphotFullForce_LDADD = libpsphot.la
     41
     42psphotFullForceSummary_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     43psphotFullForceSummary_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
     44psphotFullForceSummary_LDADD = libpsphot.la
    4145
    4246psphotMinimal_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     
    99103        psphotMosaicChip.c         \
    100104        psphotCleanup.c
     105
     106# combine full force results from several inputs
     107psphotFullForceSummary_SOURCES = \
     108        psphotFullForceSummary.c \
     109        psphotFullForceSummaryReadout.c
    101110
    102111# forced photometry of specified positions given a specified psf
  • trunk/psphot/src/psmakecff.c

    r36375 r36441  
    22# include <config.h>
    33# endif
     4
     5// psmakecff : A program to make read a cmf file and write a cff file
     6// The real work is done in psModules.
    47
    58#include <stdio.h>
     
    811#include "psphot.h"
    912
     13// For simplicilty, this program's (simple) functions are all contained in this file.
    1014static pmConfig* psmakecffArguments(int, char**);
    1115static bool psmakecffParseCamera(pmConfig *);
     
    2529//    psphotVersionPrint();
    2630
    27     // load input data (config and images (signal, noise, mask)
    2831    if (!psmakecffParseCamera (config)) {
    2932        psErrorStackPrint(stderr, "Error setting up the camera\n");
     
    3134    }
    3235
    33     // call psphot for each readout
    3436    if (!psmakecffImageLoop (config)) {
    3537        psErrorStackPrint(stderr, "Error in the psphot image loop\n");
     
    3739    }
    3840
    39 //    psLogMsg ("psphot", PS_LOG_WARN, "complete psphot run: %f sec\n", psTimerMark ("complete"));
    40 
    41 //    psErrorCode exit_status = psphotGetExitStatus();
    42 //    psphotCleanup (config);
    4341    exit (0);
    4442}
     
    7371    return config;
    7472}
     73
    7574static bool psmakecffParseCamera(pmConfig *config) {
    7675    bool status = false;
     
    127126    psAssert (recipe, "missing recipe?");
    128127
    129 //    psImageMaskType maskTest = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
    130128
    131129    // for psphot, we force data to be read at the chip level
    132130    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
    133         psLogMsg ("psmakecmf", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     131        psLogMsg ("psmakecff", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
    134132        if (! chip->process || ! chip->file_exists) { continue; }
    135133
    136 #ifdef notdef
    137         pmFPAfileActivate (config->files, false, NULL);
    138         pmFPAfileActivate (config->files, true, "PSPHOT.LOAD");
    139 #endif
    140134        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psmakecff.");
    141135
    142136        // there is now only a single chip (multiple readouts?). loop over it and process
    143137        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
    144             psLogMsg ("psmakecmf", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     138            psLogMsg ("psmakecff", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    145139
    146140            // process each of the readouts
    147141            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
    148                 psLogMsg ("psmakecmf", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     142                psLogMsg ("psmakecff", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    149143                if (! readout->data_exists) { continue; }
    150144
    151145                pmHDU *hdu = pmHDUGetHighest(input->fpa, chip, cell);
    152146                if (hdu && hdu != lastHDU) {
     147                    // XXX: probably should do this
    153148                    // psphotVersionHeaderFull(hdu->header);
    154149                    lastHDU = hdu;
     
    157152
    158153        }
    159         // Defer output and closing of files until we've (possibly) done the NFrames analysis below
    160 //        pmFPAfileActivate (config->files, false, NULL);
    161 
    162154        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed pmFPAfileIOChecks for Chip in psmakecff.");
    163155    }
    164156    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed pmFPAfileIOChecks for FPA in psphot.");
    165157
    166     // fail if we failed to handle an error
     158    // fail if we encountered an unhandled error
    167159    if (psErrorCodeLast() != PS_ERR_NONE) psAbort ("failed to handle an error!");
    168160
  • trunk/psphot/src/psphot.h

    r36375 r36441  
    361361bool psphotModelTestReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
    362362
     363bool psphotFullForceSummaryReadout (pmConfig * config, const pmFPAview *view);
     364
    363365int psphotFileruleCount(const pmConfig *config, const char *filerule);
    364366bool psphotFileruleCountSet(const pmConfig *config, const char *filerule, int num);
  • trunk/psphot/src/psphotChooseAnalysisOptions.c

    r36375 r36441  
    6060}
    6161
    62 bool GetGalacticCoords (psSphere *ptGal, psSphere *ptSky, psSphereRot *toGal, pmChip *chip, float xPos, float yPos);
     62static bool GetGalacticCoords (psSphere *ptGal, psSphere *ptSky, psSphereRot *toGal, pmChip *chip, float xPos, float yPos);
    6363
    6464// this function use an internal flag to mark sources which have already been measured
     
    121121    psSphereRot *toGal = NULL;
    122122    float GAL_LIMIT = 0.0;
     123    float GAL_LIMIT_BULGE = 0.0;
     124    float GAL_LIMIT_SIGMA2 = 0.0;
    123125    bool useGAL_LIMIT = psMetadataLookupBool(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.USE");
    124126    assert (status);
    125127    if (useGAL_LIMIT) {
     128        toGal = psSphereRotICRSToGalactic();
    126129        GAL_LIMIT = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT");
    127         toGal = psSphereRotICRSToGalactic();
     130        assert (status);
     131        GAL_LIMIT = DEG_TO_RAD(GAL_LIMIT);
     132        GAL_LIMIT_BULGE = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE");
     133        assert (status);
     134        GAL_LIMIT_BULGE = DEG_TO_RAD(GAL_LIMIT_BULGE);
     135        float GAL_LIMIT_SIGMA = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE.SIGMA");
     136        assert (status);
     137        assert(GAL_LIMIT_SIGMA > 0);
     138        GAL_LIMIT_SIGMA = DEG_TO_RAD(GAL_LIMIT_SIGMA);
     139        GAL_LIMIT_SIGMA2 = GAL_LIMIT_SIGMA * GAL_LIMIT_SIGMA;
    128140    }
    129141
     
    135147    }
    136148
     149    float petroFluxLim = NAN;
    137150    float extFitFluxLim = NAN;
    138151
     
    140153        float extFitMagLimDefault = NAN;
    141154        float extFitMagLim = NAN;
     155        float petroMagLimDefault = NAN;
     156        float petroMagLim = NAN;
    142157
    143158        // match to the given filter
     
    156171            // find a matching filter or default to 'any'
    157172            if (!strcasecmp (thisFilter, "any")) {
    158                 psString extFitMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT");
    159                 psAssert(extFitMagLimStr, "missing MAG.LIMIT");
     173                psString petroMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
     174                psAssert(petroMagLimStr, "missing MAG.LIMIT.PETRO");
     175                petroMagLimDefault = atof (petroMagLimStr);
     176
     177                psString extFitMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
     178                psAssert(extFitMagLimStr, "missing MAG.LIMIT.EXTFIT");
    160179                extFitMagLimDefault = atof (extFitMagLimStr);
    161180            }
    162181
    163             // find a matching filter or default to 'any'
    164182            if (!strcasecmp (thisFilter, filterID)) {
    165                 psString extFitMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT");
    166                 psAssert(extFitMagLimStr, "missing MAG.LIMIT");
     183                psString petroMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
     184                psAssert(petroMagLimStr, "missing MAG.LIMIT.PETRO");
     185                petroMagLim = atof (petroMagLimStr);
     186
     187                psString extFitMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
     188                psAssert(extFitMagLimStr, "missing MAG.LIMIT.EXTFIT");
    167189                extFitMagLim = atof (extFitMagLimStr);
    168190                break;
    169191            }
    170192        }
     193        psFree(iter);
     194        if (!isfinite (petroMagLim)) petroMagLim = petroMagLimDefault;
    171195        if (!isfinite (extFitMagLim)) extFitMagLim = extFitMagLimDefault;
    172196
     
    185209        psAssert (status, "missing FPA.ZP?");
    186210
     211        petroFluxLim = exptime * pow (10.0, 0.4*(zeropt - petroMagLim));
    187212        extFitFluxLim = exptime * pow (10.0, 0.4*(zeropt - extFitMagLim));
    188213    }
     
    225250            psSphere ptGal, ptSky;
    226251            GetGalacticCoords (&ptGal, &ptSky, toGal, chip, source->peak->xf, source->peak->yf);
    227             if (fabs(ptGal.d) < GAL_LIMIT) continue;
     252            float b = ptGal.r;
     253            float limit = GAL_LIMIT + GAL_LIMIT_BULGE * exp(-0.5*(b*b/GAL_LIMIT_SIGMA2));
     254            if (fabs(ptGal.d) < limit) continue;
    228255            // include an exception for low density skycells below the limit?
    229256        }
    230257
    231258        // for petro and extFit, we will either use the mag limits or the S/N
     259        if (doPetrosian) {
     260            if (isfinite(petroFluxLim)) {
     261                if (source->moments->KronFlux > petroFluxLim) {
     262                    source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
     263                }
     264            } else if (source->moments->KronFlux > SN_LIM * source->moments->KronFluxErr) {
     265                source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
     266            }
     267        }
    232268        if (isfinite(extFitFluxLim)) {
    233269            if (source->moments->KronFlux > extFitFluxLim) {
    234270                source->tmpFlags |= PM_SOURCE_TMPF_EXT_FIT;
    235                 if (doPetrosian) source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
    236271            }
    237272        } else {
    238273            if (source->moments->KronFlux > SN_LIM * source->moments->KronFluxErr) {
    239274                source->tmpFlags |= PM_SOURCE_TMPF_EXT_FIT;
    240                 if (doPetrosian) source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
    241275            }
    242276        }
     
    244278
    245279    psLogMsg ("psphot.options", PS_LOG_WARN, "choose analysis options for %ld sources: %f sec\n", sources->n, psTimerMark ("psphot.options"));
     280
     281    psFree(toGal);
    246282
    247283    return true;
     
    287323    psSphereRot *toGal = NULL;
    288324    float GAL_LIMIT = 0.0;
     325    float GAL_LIMIT_BULGE = 0.0;
     326    float GAL_LIMIT_SIGMA2 = 0.0;
    289327    bool useGAL_LIMIT = psMetadataLookupBool(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.USE");
    290328    assert (status);
    291329    if (useGAL_LIMIT) {
     330        toGal = psSphereRotICRSToGalactic();
    292331        GAL_LIMIT = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT");
    293         toGal = psSphereRotICRSToGalactic();
     332        assert (status);
     333        GAL_LIMIT = DEG_TO_RAD(GAL_LIMIT);
     334        GAL_LIMIT_BULGE = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE");
     335        assert (status);
     336        GAL_LIMIT_BULGE = DEG_TO_RAD(GAL_LIMIT_BULGE);
     337        float GAL_LIMIT_SIGMA = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE.SIGMA");
     338        assert (status);
     339        assert(GAL_LIMIT_SIGMA > 0);
     340        GAL_LIMIT_SIGMA = DEG_TO_RAD(GAL_LIMIT_SIGMA);
     341        GAL_LIMIT_SIGMA2 = GAL_LIMIT_SIGMA * GAL_LIMIT_SIGMA;
    294342    }
    295343
     
    365413    // find extFitFluxLim->data.F32[i] for i == image number
    366414    psVector *extFitFluxLim = NULL;
     415    psVector *petroFluxLim = NULL;
    367416    if (magLimits) {
    368417        extFitFluxLim = psVectorAlloc (inputFilters->n, PS_TYPE_F32);
     418        petroFluxLim = psVectorAlloc (inputFilters->n, PS_TYPE_F32);
    369419        psVectorInit (extFitFluxLim, NAN);
     420        psVectorInit (petroFluxLim, NAN);
    370421
    371422        float extFitMagLimDefault = NAN;
     423        float petroMagLimDefault = NAN;
    372424
    373425        // match mag limits (flux limits) to the filters
     
    383435            // save the default value to assign to unset filters
    384436            if (!strcasecmp (thisFilter, "any")) {
    385                 psString magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT");
    386                 psAssert(magString, "missing MAG.LIMIT");
     437                psString magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
     438                psAssert(magString, "missing MAG.LIMIT.EXTFIT");
    387439                extFitMagLimDefault = atof (magString);
     440
     441                magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
     442                psAssert(magString, "missing MAG.LIMIT.PETRO");
     443                petroMagLimDefault = atof (magString);
    388444                continue;
    389445            }
     
    393449                if (i == chisqNum) continue;
    394450                if (!strcasecmp (thisFilter, inputFilters->data[i])) {
    395                     psString magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT");
    396                     psAssert(magString, "missing MAG.LIMIT");
     451                    psString magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
     452                    psAssert(magString, "missing MAG.LIMIT.PETRO");
    397453                    float magvalue = atof (magString);
     454                    petroFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - magvalue));
     455
     456                    magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
     457                    psAssert(magString, "missing MAG.LIMIT.EXTFIT");
     458                    magvalue = atof (magString);
    398459                    extFitFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - magvalue));
    399460                    break;
     
    401462            }
    402463        }
     464        psFree(iter);
    403465
    404466        for (int i = 0; i < num; i++) {
    405467            if (i == chisqNum) continue;
    406             if (isfinite(extFitFluxLim->data.F32[i])) continue;
    407             extFitFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - extFitMagLimDefault));
     468            if (!isfinite(petroFluxLim->data.F32[i])) {
     469                petroFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - petroMagLimDefault));
     470            }
     471            if (!isfinite(extFitFluxLim->data.F32[i])) {
     472                extFitFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - extFitMagLimDefault));
     473            }
    408474        }
    409475    }
     
    420486        bool doObjectRadial = false;
    421487        bool doObjectExtFit = false;
    422         for (int j = 0; !doObjectExtFit && !doObjectRadial && (j < object->sources->n); j++) {
     488        bool doObjectPetrosian = false;
     489        for (int j = 0; !doObjectExtFit && !doObjectRadial && !doObjectPetrosian && (j < object->sources->n); j++) {
    423490
    424491            pmSource *source = object->sources->data[j];
     
    451518            if (extFitAll) {
    452519                doObjectExtFit = true;
     520                doObjectPetrosian = doPetrosian;
    453521                continue;
    454522            }
     
    465533                psSphere ptGal, ptSky;
    466534                GetGalacticCoords (&ptGal, &ptSky, toGal, chips->data[imageID], source->peak->xf, source->peak->yf);
    467                 if (fabs(ptGal.d) < GAL_LIMIT) continue;
    468                 // include an exception for low density skycells below the limit?
    469             }
    470 
    471             float fluxLim = extFitFluxLim ? extFitFluxLim->data.F32[imageID] : NAN;
     535                float b = ptGal.r;
     536                float limit = GAL_LIMIT + GAL_LIMIT_BULGE * exp(-0.5*(b*b/GAL_LIMIT_SIGMA2));
     537                if (fabs(ptGal.d) < limit) continue;
     538            }
     539
     540            float fluxLim = NAN;
     541            // for petro and extFit, we will either use the mag limits or the S/N
     542            if (doPetrosian) {
     543                fluxLim = petroFluxLim ? petroFluxLim->data.F32[imageID] : NAN;
     544                if (isfinite(fluxLim)) {
     545                    if (source->moments->KronFlux > extFitFluxLim->data.F32[imageID]) {
     546                        doObjectPetrosian = true;
     547                    }
     548                } else {
     549                    if (source->moments->KronFlux > SN_LIM * source->moments->KronFluxErr) {
     550                        doObjectPetrosian = true;
     551                    }
     552                }
     553            }
     554            fluxLim = extFitFluxLim ? extFitFluxLim->data.F32[imageID] : NAN;
    472555            // for petro and extFit, we will either use the mag limits or the S/N
    473556            if (isfinite(fluxLim)) {
     
    503586            if (source->modelPSF == NULL) continue;
    504587               
    505             // Do the fits if the recipe requests we do extended source fits to everything
    506588            if (doObjectExtFit) {
    507589                source->tmpFlags |= PM_SOURCE_TMPF_EXT_FIT;
    508                 if (doPetrosian) source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
    509             }
     590            }
     591            if (doObjectPetrosian) {
     592                source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
     593            }
    510594
    511595            // Do the fits if the recipe requests we do extended source fits to everything
     
    522606    psLogMsg ("psphot.options", PS_LOG_WARN, "choose analysis options for %ld objects: %f sec\n", objects->n, psTimerMark ("psphot.options"));
    523607
     608    psFree(toGal);
     609
    524610    return true;
    525611}
    526612
    527 bool GetGalacticCoords (psSphere *ptGal, psSphere *ptSky, psSphereRot *toGal, pmChip *chip, float xPos, float yPos) {
     613static bool GetGalacticCoords (psSphere *ptGal, psSphere *ptSky, psSphereRot *toGal, pmChip *chip, float xPos, float yPos) {
    528614
    529615    pmFPA *fpa = chip->parent;
     
    543629    psSphereRotApply (ptGal, toGal, ptSky);
    544630
     631    // psSphereRotApply insures that 0 < r < 2PI. We want -PI < b <= PI
     632    if (ptGal->r > M_PI) {
     633        ptGal->r -= 2.0 * M_PI;
     634    }
     635
    545636    return true;
    546637
  • trunk/psphot/src/psphotGalaxyShape.c

    r36375 r36441  
    283283    }
    284284
     285#ifdef SAVE_BEST_MODEL
     286    // Save model with smallest chisq
    285287    if (isfinite(chisqBest)) {
     288#else
     289    // Save model with nominal parameters
     290    {
     291        fRmajorBest = 1;
     292        fRminorBest = 1;
     293#endif
    286294        // now save the best fitting model as the source's extended model
    287295        psEllipseAxes testAxes = guessAxes;
     
    293301        psphotGalaxyShapeSource (pcm, source, maskVal, psfSize, false);
    294302
     303        // Replace modelEXT with this model
     304        // XXX: only do this if the model is good
    295305        psFree (source->modelEXT);
    296306
     
    299309        source->mode |= PM_SOURCE_MODE_EXTMODEL;
    300310        source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    301 
    302         // adjust the window so the subtraction covers the faint wings
    303         // psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal);
    304311
    305312        // cache the model flux
  • trunk/psphot/src/psphotStackImageLoop.c

Note: See TracChangeset for help on using the changeset viewer.