IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10096


Ignore:
Timestamp:
Nov 19, 2006, 7:26:08 PM (20 years ago)
Author:
eugene
Message:

working on global linear fit with sky level

Location:
trunk/psphot/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotChoosePSF.c

    r10076 r10096  
    2626    }
    2727
     28    // supply the measured sky variance for optional constant errors (non-poissonian)
     29    float SKY_STDEV = psMetadataLookupF32 (&status, recipe, "SKY_STDEV");
     30    if (!status) {
     31        SKY_STDEV = 1.0;
     32        psWarning("SKY_STDEV is not set --- defaulting to %f\n", SKY_STDEV);
     33    }
    2834    // use poissonian errors or local-sky errors
    2935    bool POISSON_ERRORS = psMetadataLookupBool (&status, recipe, "POISSON_ERRORS");
     
    3238        psWarning("POISSON_ERRORS is not set in the recipe --- defaulting to true.\n");
    3339    }
     40    pmSourceFitModelInit (15, 0.01, PS_SQR(SKY_STDEV), POISSON_ERRORS);
    3441
    3542    // how to model the PSF variations across the field
     
    4855    }
    4956
    50     pmSourceFitModelInit (15, 0.1, POISSON_ERRORS);
    51 
    5257    stars = psArrayAllocEmpty (sources->n);
    5358
     
    9499        modelName = item->data.V;
    95100        models->data[i] = pmPSFtryModel (stars, modelName, RADIUS, POISSON_ERRORS, psfTrendMask);
    96     }
    97 
    98     // XXX test dump of psf stars and model
    99     if (1) {
    100         psphotSaveImage (NULL, readout->image,  "testsub.fits");
    101         pmSourcesWritePSFs (stars, "psfstars.dat");
    102         try = models->data[0];
    103         psf = try->psf;
    104         psMetadata *psfData = pmPSFtoMetadata (NULL, psf);
    105         psMetadataConfigWrite (psfData, "psfmodel.dat");
    106         psFree (psfData);
    107101    }
    108102
     
    138132    try = models->data[bestN];
    139133
     134    // XXX test dump of psf star data and psf-subtracted image
     135    if (0) {
     136        for (int i = 0; i < try->sources->n; i++) {
     137            // masked for: bad model fit, outlier in parameters
     138            if (try->mask->data.U8[i] & PSFTRY_MASK_ALL)
     139                continue;
     140
     141            pmSource *source = try->sources->data[i];
     142            float x = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     143            float y = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     144
     145            // set the mask and subtract the PSF model
     146            psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PM_MASK_MARK);
     147            pmModelSub (source->pixels, source->mask, source->modelPSF, false, false);
     148            psImageKeepCircle (source->mask, x, y, RADIUS, "AND", PS_NOT_U8(PM_MASK_MARK));
     149        }
     150
     151        psphotSaveImage (NULL, readout->image,  "psfstars.fits");
     152        pmSourcesWritePSFs (try->sources, "psfstars.dat");
     153        psMetadata *psfData = pmPSFtoMetadata (NULL, try->psf);
     154        psMetadataConfigWrite (psfData, "psfmodel.dat");
     155        psFree (psfData);
     156        psLogMsg ("psphot.choosePSF", 3, "wrote out psf-subtracted image, psf data, exiting\n");
     157        exit (0);
     158    }
     159
    140160    // unset the PSFSTAR flag for stars not used for PSF model
    141161    for (int i = 0; i < try->sources->n; i++) {
  • trunk/psphot/src/psphotEnsemblePSF.c

    r10076 r10096  
    1010// the analysis is performed wrt the simulated pixel values
    1111
    12 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope);
     12static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope, bool constant_weights);
    1313
    1414bool psphotEnsemblePSF (pmReadout *readout, psArray *refSources, psMetadata *recipe, pmPSF *psf, bool final) {
     
    162162    // set the sky, sky_x, sky_y components of border matrix
    163163    // XXX ignore sky slope terms for now
    164     SetBorderT (border, readout, refSources, fitSources, index, false);
     164    SetBorderT (border, readout, refSources, fitSources, index, false, CONSTANT_PHOTOMETRIC_WEIGHTS);
    165165
    166166    psSparseConstraint constraint;
     
    170170
    171171    // solve for normalization terms (need include local sky?)
    172     # if (0)
     172    # if (1)
    173173    psVector *norm = NULL;
    174174    psVector *skyfit = NULL;
    175175    psSparseBorderSolve (&norm, &skyfit, constraint, border, 3);
     176    fprintf (stderr, "skyfit: %f\n", skyfit->data.F32[0]);
    176177    # else
    177178    psVector *norm = psSparseSolve (NULL, constraint, sparse, 3);
     
    226227
    227228// calculate the weight terms for the sky fit component of the matrix
    228 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope) {
     229static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope, bool constant_weights) {
    229230
    230231    // generate the image-wide weight terms
     
    251252    psU8 **mask = readout->mask->data.U8;
    252253
    253     double w, x, y, x2, xy, y2, xc, yc;
    254     w = x = y = x2 = xy = y2 = 0;
     254    double w, x, y, x2, xy, y2, xc, yc, wt, f, fo, fx, fy;
     255    w = x = y = x2 = xy = y2 = fo = fx = fy = 0;
    255256   
    256257    int col0 = readout->image->col0;
     
    260261        for (int i = 0; i < readout->image->numCols; i++) {
    261262            if (mask[j][i]) continue;
    262             w  +=       image[j][i]/weight[j][i];
     263            if (constant_weights) {
     264                wt = 1.0;
     265            } else {
     266                wt = weight[j][i];
     267            }
     268            f = image[j][i];
     269            w   += 1/wt;
     270            fo  += f/wt;
     271
    263272            if (!fitSlope) continue;
    264273            xc = i + col0;
    265274            yc = j + row0;
    266             x  +=    xc*image[j][i]/weight[j][i];
    267             y  +=    yc*image[j][i]/weight[j][i];
    268             x2 += xc*xc*image[j][i]/weight[j][i];
    269             xy += xc*yc*image[j][i]/weight[j][i];
    270             y2 += yc*yc*image[j][i]/weight[j][i];
     275            x  +=    xc/wt;
     276            y  +=    yc/wt;
     277            x2 += xc*xc/wt;
     278            xy += xc*yc/wt;
     279            y2 += yc*yc/wt;
     280            fx +=  f*xc/wt;
     281            fy +=  f*yc/wt;
    271282        }
    272283    }
     
    276287
    277288    // set the Border T elements
     289    psSparseBorderElementG (border, 0, fo);
    278290    psSparseBorderElementT (border, 0, 0, w);
    279291    if (fitSlope) {
     292        psSparseBorderElementG (border, 0, fx);
     293        psSparseBorderElementG (border, 0, fy);
    280294        psSparseBorderElementT (border, 1, 0, x);
    281295        psSparseBorderElementT (border, 2, 0, y);
  • trunk/psphot/src/psphotImageMedian.c

    r9270 r10096  
    124124    stats = psImageStats (stats, model->image, NULL, 0);
    125125    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MEAN", PS_DATA_F32 | PS_META_REPLACE, "sky model mean",          stats->sampleMean);
    126     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_STDV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev",         stats->sampleStdev);
     126    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_STDEV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev",         stats->sampleStdev);
    127127    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MAX",  PS_DATA_F32 | PS_META_REPLACE, "sky model maximum value", stats->max);
    128128    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MIN",  PS_DATA_F32 | PS_META_REPLACE, "sky model minimum value", stats->min);
  • trunk/psphot/src/psphotModelTest.c

    r9539 r10096  
    1717    bool POISSON_ERRORS = psMetadataLookupBool (&status, recipe, "POISSON_ERRORS");
    1818    if (!status) POISSON_ERRORS = true;
    19     pmSourceFitModelInit (15, 0.1, POISSON_ERRORS);
     19    pmSourceFitModelInit (15, 0.1, 1.0, POISSON_ERRORS);
    2020
    2121    // run model fitting tests on a single source
  • trunk/psphot/src/psphotOutput.c

    r9270 r10096  
    8080    // sky background model statistics
    8181    psMetadataItemTransfer (header, recipe, "SKY_MEAN");
    82     psMetadataItemTransfer (header, recipe, "SKY_STDV");
     82    psMetadataItemTransfer (header, recipe, "SKY_STDEV");
    8383    psMetadataItemTransfer (header, recipe, "SKY_MIN");
    8484    psMetadataItemTransfer (header, recipe, "SKY_MAX");
  • trunk/psphot/src/psphotTestPSF.c

    r9771 r10096  
    3232        psWarning("POISSON_ERRORS is not set in the recipe --- defaulting to true.\n");
    3333    }
     34    pmSourceFitModelInit (15, 0.1, 1.0, POISSON_ERRORS);
    3435
    3536    // how to model the PSF variations across the field
     
    4748        }
    4849    }
    49 
    50     pmSourceFitModelInit (15, 0.1, POISSON_ERRORS);
    5150
    5251    stars = psArrayAllocEmpty (sources->n);
  • trunk/psphot/src/psphotWeightBias.c

    r9813 r10096  
    1818
    1919    // set fitting method to use non-poisson errors (local sky error)
    20     pmSourceFitModelInit (15, 0.1, false);
     20    float SKY_STDEV = psMetadataLookupF32 (&status, recipe, "SKY_STDEV");
     21    if (!status) {
     22      SKY_STDEV = 1.0;
     23        psWarning("SKY_STDEV is not set --- defaulting to %f\n", SKY_STDEV);
     24    }
     25    // use poissonian errors or local-sky errors
     26    bool POISSON_ERRORS = psMetadataLookupBool (&status, recipe, "POISSON_ERRORS");
     27    if (!status) {
     28        POISSON_ERRORS = true;
     29        psWarning("POISSON_ERRORS is not set in the recipe --- defaulting to true.\n");
     30    }
     31    pmSourceFitModelInit (15, 0.1, PS_SQR(SKY_STDEV), POISSON_ERRORS);
    2132
    2233    // option to limit analysis to a specific region
Note: See TracChangeset for help on using the changeset viewer.