IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34418 for trunk


Ignore:
Timestamp:
Sep 7, 2012, 10:51:18 AM (14 years ago)
Author:
eugene
Message:

merge changes from eam_branch/ipp-20120905: add satstar profile to psphotStackReadout; skip negative fluxes in standard psphotReadout; replace mask pixel values when growing the CR mask; mask cores of 1st pass sources to avoid excessively close detections; add SUBTRACT_SATSTAR_PROFILE to psphot recipe

Location:
trunk
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Ohana

    • Property svn:mergeinfo deleted
  • trunk/Ohana/src/opihi

    • Property svn:mergeinfo deleted
  • trunk/Ohana/src/opihi/cmd.astro

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippMonitor

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippScripts/scripts/destreak_restore_camera.pl

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippScripts/scripts/ipp_apply_burntool_single.pl

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippScripts/scripts/magic_destreak.pl

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippToPsps

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippTools/share/camtool_find_pendingimfile.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippTools/share/chiptool_setimfiletoupdate.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippTools/share/pxadmin_create_tables.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippTools/share/warptool_towarped.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippTools/src

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippTools/src/magictool.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ippconfig

  • trunk/ippconfig/recipes/psphot.config

    r34354 r34418  
    7575DEBLEND_SKY_NSIGMA                  F32   10.0
    7676DEBLEND_MIN_SATURATION              F32   40000.0
     77
     78# subtract radial profiles for extremely bright stars?
     79SUBTRACT_SATSTAR_PROFILE            BOOL  F
    7780
    7881# parameters to control the selection of the peak in the Sx,Sy plane
     
    414417  PETROSIAN_FOR_STARS                 BOOL  FALSE
    415418
     419  # subtract radial profiles for extremely bright stars?
     420  SUBTRACT_SATSTAR_PROFILE            BOOL  T
     421 
    416422  CONSTANT_PHOTOMETRIC_WEIGHTS        BOOL  TRUE
    417423  POISSON.ERRORS.PHOT.LMM             BOOL  TRUE
  • trunk/ippconfig/recipes/reductionClasses.mdc

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/ppImage/src

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/psModules

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/psphot

  • trunk/psphot/src

  • trunk/psphot/src/psphot.h

    r34404 r34418  
    8181
    8282bool            psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule);
    83 bool            psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
     83bool            psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
    8484
    8585bool            psphotBasicDeblend (pmConfig *config, const pmFPAview *view, const char *filerule);
  • trunk/psphot/src/psphotAddNoise.c

    r34404 r34418  
    11# include "psphotInternal.h"
     2
     3bool psphotMaskSource(pmSource *source, bool add, psImageMaskType maskVal);
    24
    35bool psphotAddNoise (pmConfig *config, const pmFPAview *view, const char *filerule) {
     
    3032}
    3133
     34static int Nmasked = 0;
     35
    3236bool psphotAddOrSubNoiseReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool add) {
    3337
     
    5660    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
    5761    psAssert (maskVal, "missing mask value?");
     62
     63    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels
     64    psAssert (markVal, "missing mask value?");
    5865
    5966    // increase variance by factor*(object noise):
     
    94101
    95102        pmSourceNoiseOp (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, FACTOR, SIZE, add, maskVal, 0, 0);
     103
     104        psphotMaskSource (source, add, markVal);
    96105    }
    97106    if (add) {
     
    100109        psLogMsg ("psphot.noise", PS_LOG_WARN, "sub noise for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.noise"));
    101110    }
     111    fprintf (stderr, "masked %d objects\n", Nmasked);
    102112
    103113    psphotVisualShowImage (readout);
     
    105115    return true;
    106116}
     117
     118bool psphotMaskSource(pmSource *source, bool add, psImageMaskType maskVal) {
     119
     120    if (!source) return false;
     121    if (!source->peak) return false; // XXX how can we have a peak-less source?
     122    if (source->type == PM_SOURCE_TYPE_DEFECT) return false;
     123    if (source->type == PM_SOURCE_TYPE_SATURATED) return false;
     124
     125    float Xc = source->peak->xf - source->pixels->col0 - 0.5;
     126    float Yc = source->peak->yf - source->pixels->row0 - 0.5;
     127
     128    psImageMaskType notMaskVal = ~maskVal;
     129
     130    for (int iy = 0; iy < source->pixels->numRows; iy++) {
     131        for (int ix = 0; ix < source->pixels->numCols; ix++) {
     132
     133            float radius = hypot (ix - Xc, iy - Yc) ;
     134
     135            if (radius > 4) continue;
     136
     137            if (add) {
     138              source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= maskVal;
     139            } else {
     140              source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] &= notMaskVal;
     141            }
     142        }
     143    }
     144    Nmasked ++;
     145
     146    return true;
     147}
     148
  • trunk/psphot/src/psphotBlendFit.c

    r34404 r34418  
    11# include "psphotInternal.h"
    22bool psphotBlendFitSetSource(pmSource *source, psImage *IDimage, float sigSigma);
     3bool psphotBlendSetSourceSatstar (psImage *image, pmSource *source);
     4float InterpolateValues (float X0, float Y0, float X1, float Y1, float X);
    35
    46// for now, let's store the detections on the readout->analysis for each readout
     
    256258
    257259        int TEST_ON = false;
    258 # if (1)
     260# if (0)
    259261# define TEST_X 653
    260262# define TEST_Y 466
    261263        if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) {
    262264            fprintf (stderr, "test object\n");
    263             //  psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
     265            psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
    264266            TEST_ON = true;
    265267        }
     
    377379    if (!source) return false;
    378380    if (!source->peak) return false; // XXX how can we have a peak-less source?
     381
     382# if (0)
     383# define TEST_X 653
     384# define TEST_Y 466
     385        if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) {
     386            fprintf (stderr, "test object\n");
     387        }
     388# undef TEST_X
     389# undef TEST_Y
     390# endif
     391
    379392    if (!source->moments) return false;
    380393    if (source->type == PM_SOURCE_TYPE_DEFECT) return false;
     
    385398    if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) {
    386399        // find the radius at which we hit something like 0.1*SATURATION
    387         return false;
     400        psphotBlendSetSourceSatstar (IDimage, source);
     401        return true;
    388402    }
    389403
     
    431445    float rMxx = 0.5 / PS_SQR(shape.sx);
    432446    float rMyy = 0.5 / PS_SQR(shape.sy);
    433     float Sxy = -1. * shape.sxy;    // factor of -1 is included to match the previous window function
    434                                     // implementation. XXX: Is this correct?
     447    float Sxy = shape.sxy;    // factor of -1 is included to match the previous window function
     448    // implementation. XXX: Is this correct?
    435449
    436450    int ID = source->id;
     
    443457
    444458            float z = rMxx * PS_SQR(dX) + rMyy * PS_SQR(dY) + Sxy*dX*dY;
     459            if (z > 2.311) continue;
    445460
    446461            float f = Io*exp(-z);
     
    453468    return true;
    454469}
     470
     471bool psphotBlendSetSourceSatstar (psImage *IDimage, pmSource *source) {
     472
     473    float Xo = source->satstar->Xo;
     474    float Yo = source->satstar->Yo;
     475    psVector *logRmodel = source->satstar->logRmodel;
     476    psVector *logFmodel = source->satstar->logFmodel;
     477
     478    float lPeak = logFmodel->data.F32[0];
     479    float fPeak = pow(10.0, lPeak);
     480    float threshold = 0.1*fPeak;
     481    float logThresh = log10(threshold);
     482
     483    float radius = NAN;
     484
     485    // what is the radius for a specific peak fraction?
     486    for (int i = 1; i < logFmodel->n; i++) {
     487        float logF = logFmodel->data.F32[i];
     488        if (!isfinite(logF)) continue;
     489
     490        float flux = pow(10.0, logF);
     491        if (flux > threshold) continue;
     492       
     493        float logF0 = logFmodel->data.F32[i - 1];
     494        float logR0 = logRmodel->data.F32[i - 1];
     495
     496        float logF1 = logFmodel->data.F32[i];
     497        float logR1 = logRmodel->data.F32[i];
     498
     499        float logR = InterpolateValues (logF0, logR0, logF1, logR1, logThresh);
     500        radius = pow(10.0, logR);
     501        break;
     502    }
     503
     504    if (!isfinite(radius)) {
     505        for (int i = logFmodel->n - 1; i >= 0; i--) {
     506            if (!isfinite(logFmodel->data.F32[i])) continue;
     507            float logR = logRmodel->data.F32[i];
     508            radius = pow(10.0, logR);
     509            break;
     510        }
     511    }
     512
     513    if (!isfinite(radius)) return false;
     514
     515    int Nx = IDimage->numCols;
     516    int Ny = IDimage->numRows;
     517
     518    // region to mask
     519    int minX = PS_MIN(PS_MAX(Xo - radius, 0), Nx - 1);
     520    int maxX = PS_MIN(PS_MAX(Xo + radius, 0), Nx - 1);
     521    int minY = PS_MIN(PS_MAX(Yo - radius, 0), Ny - 1);
     522    int maxY = PS_MIN(PS_MAX(Yo + radius, 0), Ny - 1);
     523
     524    int ID = source->id;
     525
     526    fprintf (stderr, "Xo,Yo: %f,%f; radius: %f\n", Xo, Yo, radius);
     527
     528    for (int iy = minY; iy < maxY; iy++) {
     529        for (int ix = minX; ix < maxX; ix++) {
     530
     531            float dX = (ix - Xo);
     532            float dY = (iy - Yo);
     533            float R = hypot (dX, dY) ;
     534            if (R > radius) continue;
     535
     536            IDimage->data.S32[iy][ix] = ID;
     537        }
     538    }
     539    return true;
     540}
     541
  • trunk/psphot/src/psphotDeblendSatstars.c

    r34404 r34418  
    1616bool psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule)
    1717{
     18    bool status = false;
     19
    1820    int num = psphotFileruleCount(config, filerule);
     21
     22    // select the appropriate recipe information
     23    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     24    psAssert (recipe, "missing recipe?");
     25
     26    // perform full extended source non-linear fits?
     27    if (!psMetadataLookupBool (&status, recipe, "SUBTRACT_SATSTAR_PROFILE")) {
     28        psLogMsg ("psphot", PS_LOG_INFO, "skipping extended source fits\n");
     29        return true;
     30    }
    1931
    2032    // loop over the available readouts
    2133    for (int i = 0; i < num; i++) {
    22         if (!psphotDeblendSatstarsReadout (config, view, filerule, i)) {
     34        if (!psphotDeblendSatstarsReadout (config, view, filerule, i, recipe)) {
    2335            psError (PSPHOT_ERR_CONFIG, false, "failed on saturated star deblend analysis for %s entry %d", filerule, i);
    2436            return false;
     
    4052    4) subtract the radial profile
    4153   
     54    There is also support code for calculation of magnitudes and add/subtract the profile (a la pmSourceOp)
     55
    4256    TBD:
    4357
    44     * function to replace the radial profile for a source
    4558    * recenter the profile (based on cross-correlation / convolution with 1D profile)
    46 
    47     * raise a bit somewhere for these super saturated stars (if they were so modeled)
    48     * consider the subtraction bit : when to raise it?
    49 
    5059 **/
    5160
    52 bool psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int fileIndex) {
     61bool psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int fileIndex, psMetadata *recipe) {
    5362
    5463    int N;
     
    5665    bool status;
    5766
    58     // XXX disable this function for now
    59     return true;
    60 
    6167    psTimerStart ("psphot.deblend.sat");
    6268
     
    7884        return true;
    7985    }
    80 
    81     // select the appropriate recipe information
    82     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
    83     psAssert (recipe, "missing recipe?");
    8486
    8587    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     
    124126    int BIG_SIGMA = BIG_RADIUS / 4.0;
    125127
    126     int display = psphotKapaChannel (1);
    127     psphotVisualScaleImage (display, (psImage *) source->pixels->parent, NULL, "image", 1.0, 0);
     128    // int display = psphotKapaChannel (1);
     129    // psphotVisualScaleImage (display, (psImage *) source->pixels->parent, NULL, "image", 1.0, 0);
    128130
    129131    // examine sources in decreasing SN order
     
    185187    }
    186188    // show the image after object have been subtracted
    187     psphotVisualScaleImage (display, (psImage *) source->pixels->parent, NULL, "image", 1.0, 1);
     189    // psphotVisualScaleImage (display, (psImage *) source->pixels->parent, NULL, "image", 1.0, 1);
    188190
    189191    psFree (SN);
     
    451453    // XXX do something sensible here if the profile is crap
    452454
     455    // replace an existing profile
     456    psFree (source->satstar);
    453457    source->satstar = pmSourceSatstarAlloc();
    454458    source->satstar->Xo = Xo;
  • trunk/psphot/src/psphotFindDetections.c

    r34404 r34418  
    4545    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
    4646    psAssert (maskVal, "missing mask value?");
     47
     48    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     49    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels
     50    psAssert (markVal, "missing mark value?");
     51
     52    maskVal |= markVal;
    4753
    4854    // Use the new pmFootprints approach?
  • trunk/psphot/src/psphotFitSourcesLinear.c

    r34404 r34418  
    439439        model->params->data.F32[PM_PAR_I0] = norm->data.F32[i];
    440440        model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i];
     441
     442        if (norm->data.F32[i] < MIN_VALID_FLUX) {
     443          fprintf (stderr, "fit out of bounds for %f,%f : %f\n", source->peak->xf, source->peak->yf, norm->data.F32[i]);
     444          model->params->data.F32[PM_PAR_I0] = MIN_VALID_FLUX;
     445        }
    441446
    442447        // clear the 'mark' pixels so the subtraction covers the full window
  • trunk/psphot/src/psphotKronIterate.c

    r34404 r34418  
    321321            if (!source->peak) continue; // XXX how can we have a peak-less source?
    322322
     323# if (0)
     324# define TEST_X 653
     325# define TEST_Y 466
     326        if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) {
     327            fprintf (stderr, "test object\n");
     328        }
     329# undef TEST_X
     330# undef TEST_Y
     331# endif
     332
    323333            // check status of this source's moments
    324334            if (!source->moments) continue;
     
    541551    if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) {
    542552        // We did not get a good measurement
    543         source->moments->Mrf = NAN;
     553        source->moments->Mrf = NAN;
    544554        source->moments->KronFlux  = NAN;
    545555        source->moments->KronFluxErr  = NAN;
  • trunk/psphot/src/psphotReadout.c

    r34404 r34418  
    185185
    186186    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    187     psphotFitSourcesLinear (config, view, filerule, false, false); // pass 1 (detections->allSources)
     187    psphotFitSourcesLinear (config, view, filerule, false, true); // pass 1 (detections->allSources)
    188188
    189189    // measure the radial profiles to the sky
     
    212212    // linear fit to include all sources (subtract again)
    213213    // NOTE : apply to ALL sources (extended + psf)
    214     psphotFitSourcesLinear (config, view, filerule, true, false); // pass 2 (detections->allSources)
     214    psphotFitSourcesLinear (config, view, filerule, true, true); // pass 2 (detections->allSources)
    215215
    216216    // if we only do one pass, skip to extended source analysis
     
    260260
    261261        // NOTE: apply to ALL sources
    262         psphotFitSourcesLinear (config, view, filerule, true, false); // pass 3 (detections->allSources)
     262        psphotFitSourcesLinear (config, view, filerule, true, true); // pass 3 (detections->allSources)
    263263    }
    264264
     
    300300
    301301        // NOTE: apply to ALL sources
    302         psphotFitSourcesLinear (config, view, filerule, true, false); // pass 3 (detections->allSources)
     302        psphotFitSourcesLinear (config, view, filerule, true, true); // pass 3 (detections->allSources)
    303303    }
    304304
  • trunk/psphot/src/psphotSourceSize.c

    r34404 r34418  
    675675            return false;
    676676        }
    677         psFree(readout->mask);
    678         readout->mask = newMask;
     677        // Copy the new mask pixel values to the old mask array.  NOTE: we cannot replace
     678        // the mask pointer because the source->maskView objects point to the old data
     679        // area
     680        psImage *oldMask = readout->mask;
     681        readout->mask = psImageCopy (readout->mask, newMask, PS_TYPE_IMAGE_MASK);
     682        psAssert (oldMask == readout->mask, "should have copied the values in-situ");
     683        psFree(newMask);
    679684    }
    680685
  • trunk/psphot/src/psphotStackImageLoop.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/psphot/src/psphotStackReadout.c

    r34354 r34418  
    169169    }
    170170
     171    // If DET and SRC are different images, subtract radial profiles for the convolved
     172    // image first.  The profiles found on the convolved image will be replaced by those
     173    // found for the unconvolved image.  Downstream, in psphotFindDetections, we will
     174    // replace the the profiles (and re-subtract them) for the detection image, so we want
     175    // to keep those versions of the profiles on the sources.
     176    if (strcmp(STACK_SRC, STACK_DET)) {
     177      // find and subtract radial profile models for saturated stars (XXX change name eventually)
     178      if (!psphotDeblendSatstars (config, view, STACK_SRC)) {
     179        psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     180        return psphotReadoutCleanup (config, view, STACK_SRC);
     181      }
     182    }
     183    // find and subtract radial profile models for saturated stars (XXX change name eventually)
     184    if (!psphotDeblendSatstars (config, view, STACK_DET)) {
     185        psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     186        return psphotReadoutCleanup (config, view, STACK_SRC);
     187    }
     188
    171189    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
    172190    // only run this on detections from the input images, not chisq image
     
    206224    // window of size PSF_MOMENTS_RADIUS (same window used to measure the psf-scale moments)
    207225    // but iterates to an appropriately larger size
    208         logMemStats("before.kron.1");
     226    logMemStats("before.kron.1");
    209227    psphotKronIterate(config, view, STACK_SRC, 1);
    210         logMemStats("after.kron.1");
    211 
     228    logMemStats("after.kron.1");
     229       
    212230    // identify CRs and extended sources
    213231    psphotSourceSize (config, view, STACK_SRC, true);
     
    332350    psphotStackObjectsSelectForAnalysis (config, view, STACK_SRC, objects);
    333351
    334     if (splitLinearFit) {
    335         // NOTE: apply to Matched sources. Since the sources that we fit above are subtracted, they will
    336         // not be included in this fit.
    337         psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 4 (detections->allSources)
    338     } else {
    339         // Fit all sources together
    340         psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 3 (detections->allSources)
    341     }
     352    // final linear fit. NOTE: if splitLinearFit is true above, this pass will only fit
     353    // the unsubtracted (matched) sources (the sources that we fit above are subtracted)
     354    psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 4 (detections->allSources)
    342355
    343356    // measure the radial profiles to the sky (only measures new objects)
  • trunk/pstamp/scripts

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/psvideophot

    • Property svn:mergeinfo changed (with no actual effect on merging)
Note: See TracChangeset for help on using the changeset viewer.