IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28659


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

sersic model consistency

Location:
branches/eam_branches/ipp-20100621/ppSim/src
Files:
4 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 
  • branches/eam_branches/ipp-20100621/ppSim/src/ppSimInsertStars.c

    r28127 r28659  
    105105        float flux = star->flux * expCorr->data.F32[(int)yCell][(int)xCell];
    106106
    107         // if psfConvolve is TRUE, we will (elsewhere) convolve the image we a PSF
    108         // in this case, simply place delta functions in the image
    109         if (psfConvolve) {
    110             readout->image->data.F32[(int)(yCell)][(int)(xCell)] += flux;
    111             continue;
    112         }
    113 
    114107        // instantiate a model for the PSF at this location, set desired flux
    115108        pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0);
     
    125118        // XXX i should be applying the gain and the correct effective area
    126119        psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0);
    127         psF64 Area = 2.0 * M_PI * axes.major * axes.minor;
     120        float Area = 2.0 * M_PI * axes.major * axes.minor;
    128121
    129         // this value is the pure (input) flux, and is saved in the output source cmf files
    130122        source->psfMag = -2.5*log10(star->flux);
    131123        source->errMag = sqrt(Area*PS_SQR(roughNoise) + flux) / flux;
    132124
    133         fprintf (outfile, "%8.3f %8.3f  %10.2f  %7.3f %5.3f\n", star->x, star->y, star->flux, source->psfMag, source->errMag);
     125        float par8 = (model->params->n == 8) ? model->params->data.F32[7] : 0.0;
     126        fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", star->x, star->y, star->flux, 0, source->psfMag, source->errMag, axes.major, axes.minor, axes.theta, par8);
    134127
    135         // insert the source flux in the image
    136         pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
    137 
    138         // insert the source flux in the noise image
    139         pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, dX, dY);
    140 
    141         // Blow away the image parts of the source, which makes the memory explode
    142         RESET(source->pixels);
    143         RESET(source->variance);
    144         RESET(source->maskObj);
    145         RESET(source->maskView);
    146         RESET(source->modelFlux);
    147         RESET(source->psfImage);
    148         RESET(source->blends);
     128        // if psfConvolve is TRUE, we will (elsewhere) convolve the image we a PSF
     129        // in this case, simply place delta functions in the image
     130        if (psfConvolve) {
     131            readout->image->data.F32[(int)(yCell)][(int)(xCell)] += flux;
     132        } else {
     133            // insert the source flux in the image
     134            pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
     135           
     136            // insert the source flux in the noise image
     137            pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, dX, dY);
     138           
     139            // Blow away the image parts of the source, which makes the memory explode
     140            RESET(source->pixels);
     141            RESET(source->variance);
     142            RESET(source->maskObj);
     143            RESET(source->maskView);
     144            RESET(source->modelFlux);
     145            RESET(source->psfImage);
     146            RESET(source->blends);
     147        }
    149148
    150149        // add the sources to the source array
  • branches/eam_branches/ipp-20100621/ppSim/src/ppSimMakeGalaxies.c

    r18011 r28659  
    9696                galaxy->y    = iy;
    9797
    98                 galaxy->peak = 20000;
     98                galaxy->peak = 1000;
    9999
    100                 galaxy->index = (galaxyIndexMin  + i * galaxyIndexSlope);
    101                 galaxy->Rmaj  = (galaxyRmajorMin + i * galaxyRmajorSlope);
     100                // galaxyIndex from user should be for function of this form: exp(-r^(1/n))
     101                // galaxy->index = (1/2n)
     102
     103                float index = (galaxyIndexMin  + i * galaxyIndexSlope); // factor of 0.5 because the Sersic model creates exp(-z^n), not exp(-r^n)
     104                galaxy->index = 0.5/index;
     105
     106                float scale = (galaxyRmajorMin + i * galaxyRmajorSlope);
     107
     108                // for a sersic model,
     109                float bn = 1.9992*index - 0.3271;
     110                float fR = 1.0 / (sqrt(2.0) * pow (bn, index));
     111                float Io = exp(bn);
     112
     113                // galaxy->Rmaj  = scale * fR;
     114
     115                galaxy->Rmaj  = scale;
    102116                galaxy->Rmin  = (galaxyARatioMin + i * galaxyARatioSlope) * galaxy->Rmaj;
    103117                galaxy->theta = (galaxyThetaMin  + i * galaxyThetaSlope);
     118
     119                // galaxy->peak *= Io;
     120
     121                fprintf (stderr, "Rmaj: %f, scale: %f, index: %f, bn: %f, Ro: %f, Io: %f\n",
     122                         galaxy->Rmaj, scale, index, bn, fR, Io);
    104123
    105124                psArrayAdd (galaxies, 100, galaxy);
     
    124143            galaxy->y    = psRandomUniform(rng) * ySize; // y position
    125144
    126             galaxy->flux = pow ((double)((i + 1) / norm), (double) (1.0 / galaxyLum));
     145            // galaxy->flux = pow ((double)((i + 1) / norm), (double) (1.0 / galaxyLum));
    127146
    128             galaxy->index = (psRandomUniform(rng) * galaxyIndexSlope  + galaxyIndexMin);
     147            galaxy->index = (sqrt(psRandomUniform(rng)) * galaxyIndexSlope  + galaxyIndexMin);
    129148            galaxy->theta = (psRandomUniform(rng) * galaxyThetaSlope  + galaxyThetaMin);
    130149            galaxy->Rmaj  = (psRandomUniform(rng) * galaxyRmajorSlope + galaxyRmajorMin);
    131             galaxy->Rmin  = (psRandomUniform(rng) * galaxyARatioSlope + galaxyARatioMin) * galaxy->Rmaj;
     150            galaxy->Rmin  = (PS_SQR(psRandomUniform(rng)) * galaxyARatioSlope + galaxyARatioMin) * galaxy->Rmaj;
    132151
     152            // the flux is only approximately correct (scaling of the peak is wrong)
     153            // elsewhere (ppSimInsertGalaxies.c) we calculate the true galaxy flux
    133154            galaxy->flux = expf((logf(i + 1) - logf(norm)) / galaxyLum); // Peak flux
    134155            galaxy->peak = galaxy->flux / (2.0*M_PI*PS_SQR(seeing));
    135             // galaxy->peak = 5000;
    136156
    137157            psArrayAdd (galaxies, 100, galaxy);
  • branches/eam_branches/ipp-20100621/ppSim/src/ppSimSmoothReadout.c

    r28125 r28659  
    77    // XXX use these defaults?
    88    // float minGauss = 0.1;
    9     float nSigma = 3.0;
     9    float nSigma = 4.0;
    1010    float sigma = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels)
    1111
     
    2828// 4*pi*SIGMA_SMTH^2, but for measurements based on apertures comparable to or larger than the
    2929// smoothing kernel, the effective per-pixel variance is maintained.
     30
     31
     32// XXX this only allows for Gaussian PSFs.  To extend this, we need to convolve with an image
     33// of the PSF model
Note: See TracChangeset for help on using the changeset viewer.