IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 11, 2010, 3:24:33 PM (16 years ago)
Author:
eugene
Message:

sersic model consistency

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/ppSim/src/ppSimInsertGalaxies.c

    r27657 r28659  
    11# include "ppSim.h"
    22static char *defaultModel = "PS_MODEL_SERSIC";
     3
     4float imageSum (psImage *image) {
     5    float sum = 0.0;
     6    for (int iy = 0; iy < image->numRows; iy++) {
     7        for (int ix = 0; ix < image->numCols; ix++) {
     8            sum += image->data.F32[iy][ix];
     9        }
     10    }
     11    return sum;
     12}
    313
    414bool ppSimInsertGalaxies (pmReadout *readout, psImage *expCorr, psArray *galaxies, pmConfig *config) {
     
    8494    psArray *sources = sources = detections->allSources;
    8595
     96    // output filename
     97    char outname[1024];
     98    char *outroot = psMetadataLookupStr(&mdok, config->arguments, "OUTPUT");
     99    sprintf (outname, "%s.dat", outroot);
     100
     101    FILE *outfile = fopen (outname, "a");
     102
    86103    // add sources to the readout image & weight
    87104    for (long i = 0; i < galaxies->n; i++) {
     
    131148
    132149        // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
    133         float radius = model->modelRadius (model->params, roughNoise);
     150        float radius = model->modelRadius (model->params, 0.1*roughNoise);
    134151        radius = PS_MAX (radius, 1.0);
    135152        // XXX the exp(-r^0.25) models can go way out if allowed...
    136         radius = PS_MIN (radius, 150.0);
     153        radius = PS_MIN (radius, 300.0);
    137154
    138155        // construct a source, with model flux pixels set, based on the model
    139156        pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_EXTENDED);
     157
     158        galaxy->flux = model->modelFlux (model->params);
    140159
    141160        // XXX set the mag & err values (should this be done in pmSourceFromModel?)
     
    145164        source->errMag = sqrt(Area*PS_SQR(roughNoise) + galaxy->flux) / galaxy->flux;   
    146165       
    147         // XXX add the sources to a source array
     166        // insert the source flux in the image
     167        float sum1 = imageSum(source->pixels);
     168        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
     169        float sum2 = imageSum(source->pixels);
     170        float flux = sum2 - sum1;
    148171
    149 # if (0)       
    150         if (CONVOLVED_FIT) {
     172        // fprintf (stderr, "flux: %f, sum1: %f, sum2: %f, flux2: %f, dflux: %f\n", galaxy->flux, sum1, sum2, sum2 - sum1, galaxy->flux - sum2 + sum1);
    151173
    152             // select the PSF (XXX : move out of loop)
    153             pmPSF *psfModel = psMetadataLookupPtr (&mdok, chip->analysis, "PSPHOT.PSF");
    154             assert (psf);
    155            
    156             // supply the psf to the source (normalized?)
    157             source->modelPSF = pmModelFromPSFforXY (psfModel, xChip, yChip, 1.0);
     174        float par8 = (model->params->n == 8) ? model->params->data.F32[7] : 0.0;
     175        fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", galaxy->x, galaxy->y, flux, 1, source->psfMag, source->errMag, axes.major, axes.minor, axes.theta, par8);
    158176
    159             // instantiate the psf flux
    160             pmSourceCachePSF (source, maskVal);
    161 
    162             // convert the cached cached psf model for this source to a psKernel
    163             // XXX for the moment, hard-wire the kernel to be 5x5 (2 pix radius)
    164             // XXX for the moment, hard-wire the kernel to be 9x9 (4 pix radius)
    165             psKernel *psf = psphotKernelFromPSF (source, psfSize);
    166 
    167             // instantiate the source model flux
    168             // XXX this may need to handle the offset?
    169             pmSourceCacheModel (source, maskVal);
    170 
    171             // make a storage buffer for the output image
    172             psImage *buffer = psImageCopy (source->modelFlux, PS_TYPE_F32);
    173 
    174             // convolve the psf image with the model image
    175             psImageConvolveDirect (buffer, source->modelFlux, psf);
    176 
    177             // save the result back in the source
    178             psFree (source->modelFlux);
    179             source->modelFlux = buffer;
    180         }
    181 # endif
    182 
    183         // insert the source flux in the image
    184         pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
    185177        psArrayAdd (sources, 100,source);
    186178    }
     179    fclose (outfile);
    187180
    188181    // XXX many leaks in here, i think
     
    191184    return true;
    192185}
    193 
Note: See TracChangeset for help on using the changeset viewer.