IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29002 for trunk/ppSim


Ignore:
Timestamp:
Aug 20, 2010, 12:09:48 PM (16 years ago)
Author:
eugene
Message:

save galaxy params in output file; fix convolved image construction; fix galaxy shapes; add galaxy grid option

Location:
trunk/ppSim/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimInsertGalaxies.c

    r27657 r29002  
    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 
  • trunk/ppSim/src/ppSimInsertStars.c

    r28127 r29002  
    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;
     124       
     125        // set the expected model errors
     126        model->dparams->data.F32[PM_PAR_I0] = source->errMag * model->params->data.F32[PM_PAR_I0];
    132127
    133         fprintf (outfile, "%8.3f %8.3f  %10.2f  %7.3f %5.3f\n", star->x, star->y, star->flux, source->psfMag, source->errMag);
     128        float par8 = (model->params->n == 8) ? model->params->data.F32[7] : 0.0;
     129        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);
    134130
    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);
     131        // if psfConvolve is TRUE, we will (elsewhere) convolve the image we a PSF
     132        // in this case, simply place delta functions in the image
     133        if (psfConvolve) {
     134            readout->image->data.F32[(int)(yCell)][(int)(xCell)] += flux;
     135        } else {
     136            // insert the source flux in the image
     137            pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
     138           
     139            // insert the source flux in the noise image
     140            pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, dX, dY);
     141           
     142            // Blow away the image parts of the source, which makes the memory explode
     143            RESET(source->pixels);
     144            RESET(source->variance);
     145            RESET(source->maskObj);
     146            RESET(source->maskView);
     147            RESET(source->modelFlux);
     148            RESET(source->psfImage);
     149            RESET(source->blends);
     150        }
    149151
    150152        // add the sources to the source array
  • trunk/ppSim/src/ppSimMakeGalaxies.c

    r18011 r29002  
    1818    int galaxyGridDX      = psMetadataLookupS32(&mdok, recipe, "GALAXY.GRID.DX"); // Density of fakes
    1919    int galaxyGridDY      = psMetadataLookupS32(&mdok, recipe, "GALAXY.GRID.DY"); // Density of fakes
     20    bool galaxyGridRandom = psMetadataLookupBool(&mdok, recipe, "GALAXY.GRID.RANDOM"); // Density of fakes
    2021   
    2122    float galaxyRmajorMax = psMetadataLookupF32(&mdok, recipe, "GALAXY.RMAJOR.MAX"); // Density of fakes
     
    4344
    4445    if (galaxyDensity <= 0) return true;
     46
     47    if (galaxyGridRandom) {
     48        long A, B;
     49        A = time(NULL);
     50        for (B = 0; A == time(NULL); B++);
     51        srand48(B);
     52    }
    4553
    4654    // Size of FPA
     
    8189        psLogMsg("ppSim", PS_LOG_INFO, "Adding grid of %ld galaxies\n", num);
    8290
    83         float galaxyIndexSlope = (galaxyIndexMax - galaxyIndexMin) / num;
    84         float galaxyThetaSlope = (galaxyThetaMax - galaxyThetaMin) / num;
    85         float galaxyARatioSlope = (galaxyARatioMax - galaxyARatioMin) / num;
    86         float galaxyRmajorSlope = (galaxyRmajorMax - galaxyRmajorMin) / num;
     91        float galaxyIndexSlope = (galaxyIndexMax - galaxyIndexMin);
     92        float galaxyThetaSlope = (galaxyThetaMax - galaxyThetaMin);
     93        float galaxyARatioSlope = (galaxyARatioMax - galaxyARatioMin);
     94        float galaxyRmajorSlope = (galaxyRmajorMax - galaxyRmajorMin);
    8795
    8896        int i = 0;
     
    96104                galaxy->y    = iy;
    97105
    98                 galaxy->peak = 20000;
     106                galaxy->peak = 1000;
    99107
    100                 galaxy->index = (galaxyIndexMin  + i * galaxyIndexSlope);
    101                 galaxy->Rmaj  = (galaxyRmajorMin + i * galaxyRmajorSlope);
    102                 galaxy->Rmin  = (galaxyARatioMin + i * galaxyARatioSlope) * galaxy->Rmaj;
    103                 galaxy->theta = (galaxyThetaMin  + i * galaxyThetaSlope);
     108                // galaxyIndex from user should be for function of this form: exp(-r^(1/n))
     109                // galaxy->index = (1/2n)
     110
     111                float factor = galaxyGridRandom ? drand48() : i / num;
     112                float index = (galaxyIndexMin  + factor * galaxyIndexSlope); // factor of 0.5 because the Sersic model creates exp(-z^n), not exp(-r^n)
     113                galaxy->index = 0.5/index;
     114
     115                factor = galaxyGridRandom ? drand48() : i / num;
     116                float scale = (galaxyRmajorMin + factor * galaxyRmajorSlope);
     117
     118                // for a sersic model,
     119                float bn = 1.9992*index - 0.3271;
     120                float fR = 1.0 / (sqrt(2.0) * pow (bn, index));
     121                float Io = exp(bn);
     122
     123                // galaxy->Rmaj  = scale * fR;
     124
     125                galaxy->Rmaj  = scale;
     126
     127                factor = galaxyGridRandom ? drand48() : i / num;
     128                galaxy->Rmin  = (galaxyARatioMin + factor * galaxyARatioSlope) * galaxy->Rmaj;
     129
     130                factor = galaxyGridRandom ? drand48() : i / num;
     131                galaxy->theta = (galaxyThetaMin  + factor * galaxyThetaSlope);
     132
     133                // galaxy->peak *= Io;
     134
     135                if (0) {
     136                    fprintf (stderr, "Rmaj: %f, scale: %f, index: %f, bn: %f, Ro: %f, Io: %f\n", galaxy->Rmaj, scale, index, bn, fR, Io);
     137                }
    104138
    105139                psArrayAdd (galaxies, 100, galaxy);
     
    124158            galaxy->y    = psRandomUniform(rng) * ySize; // y position
    125159
    126             galaxy->flux = pow ((double)((i + 1) / norm), (double) (1.0 / galaxyLum));
     160            // galaxy->flux = pow ((double)((i + 1) / norm), (double) (1.0 / galaxyLum));
    127161
    128             galaxy->index = (psRandomUniform(rng) * galaxyIndexSlope  + galaxyIndexMin);
     162            galaxy->index = (sqrt(psRandomUniform(rng)) * galaxyIndexSlope  + galaxyIndexMin);
    129163            galaxy->theta = (psRandomUniform(rng) * galaxyThetaSlope  + galaxyThetaMin);
    130164            galaxy->Rmaj  = (psRandomUniform(rng) * galaxyRmajorSlope + galaxyRmajorMin);
    131             galaxy->Rmin  = (psRandomUniform(rng) * galaxyARatioSlope + galaxyARatioMin) * galaxy->Rmaj;
     165            galaxy->Rmin  = (PS_SQR(psRandomUniform(rng)) * galaxyARatioSlope + galaxyARatioMin) * galaxy->Rmaj;
    132166
     167            // the flux is only approximately correct (scaling of the peak is wrong)
     168            // elsewhere (ppSimInsertGalaxies.c) we calculate the true galaxy flux
    133169            galaxy->flux = expf((logf(i + 1) - logf(norm)) / galaxyLum); // Peak flux
    134170            galaxy->peak = galaxy->flux / (2.0*M_PI*PS_SQR(seeing));
    135             // galaxy->peak = 5000;
    136171
    137172            psArrayAdd (galaxies, 100, galaxy);
  • trunk/ppSim/src/ppSimPhotomReadout.c

    r27657 r29002  
    6969    psArray *fakeSources = psArrayAlloc (injectedSources->n);
    7070    for (int i = 0; i < injectedSources->n; i++) {
    71       fakeSources->data[i] = pmSourceCopy (injectedSources->data[i]);
     71      fakeSources->data[i] = pmSourceCopyData (injectedSources->data[i]);
    7272    }
    7373
  • trunk/ppSim/src/ppSimPhotomReadoutFake.c

    r27657 r29002  
    4040    psArray *fakeSources = psArrayAlloc (injectedSources->n);
    4141    for (int i = 0; i < injectedSources->n; i++) {
    42       fakeSources->data[i] = pmSourceCopy (injectedSources->data[i]);
     42      fakeSources->data[i] = pmSourceCopyData (injectedSources->data[i]);
    4343    }
    4444
     
    4747    psArray *realSources = psArrayAlloc (realMeasuredSources->n);
    4848    for (int i = 0; i < realMeasuredSources->n; i++) {
    49         realSources->data[i] = pmSourceCopy (realMeasuredSources->data[i]);
     49        realSources->data[i] = pmSourceCopyData (realMeasuredSources->data[i]);
    5050    }
    5151
  • trunk/ppSim/src/ppSimPhotomReadoutForce.c

    r27657 r29002  
    4646    psArray *realSources = psArrayAlloc (realMeasuredSources->n);
    4747    for (int i = 0; i < realMeasuredSources->n; i++) {
    48         realSources->data[i] = pmSourceCopy (realMeasuredSources->data[i]);
     48        realSources->data[i] = pmSourceCopyData (realMeasuredSources->data[i]);
    4949    }
    5050
  • trunk/ppSim/src/ppSimSmoothReadout.c

    r28125 r29002  
    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.