Changeset 28659
- Timestamp:
- Jul 11, 2010, 3:24:33 PM (16 years ago)
- Location:
- branches/eam_branches/ipp-20100621/ppSim/src
- Files:
-
- 4 edited
-
ppSimInsertGalaxies.c (modified) (5 diffs)
-
ppSimInsertStars.c (modified) (2 diffs)
-
ppSimMakeGalaxies.c (modified) (2 diffs)
-
ppSimSmoothReadout.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/ppSim/src/ppSimInsertGalaxies.c
r27657 r28659 1 1 # include "ppSim.h" 2 2 static char *defaultModel = "PS_MODEL_SERSIC"; 3 4 float 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 } 3 13 4 14 bool ppSimInsertGalaxies (pmReadout *readout, psImage *expCorr, psArray *galaxies, pmConfig *config) { … … 84 94 psArray *sources = sources = detections->allSources; 85 95 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 86 103 // add sources to the readout image & weight 87 104 for (long i = 0; i < galaxies->n; i++) { … … 131 148 132 149 // 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); 134 151 radius = PS_MAX (radius, 1.0); 135 152 // 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); 137 154 138 155 // construct a source, with model flux pixels set, based on the model 139 156 pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_EXTENDED); 157 158 galaxy->flux = model->modelFlux (model->params); 140 159 141 160 // XXX set the mag & err values (should this be done in pmSourceFromModel?) … … 145 164 source->errMag = sqrt(Area*PS_SQR(roughNoise) + galaxy->flux) / galaxy->flux; 146 165 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; 148 171 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); 151 173 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); 158 176 159 // instantiate the psf flux160 pmSourceCachePSF (source, maskVal);161 162 // convert the cached cached psf model for this source to a psKernel163 // 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 flux168 // XXX this may need to handle the offset?169 pmSourceCacheModel (source, maskVal);170 171 // make a storage buffer for the output image172 psImage *buffer = psImageCopy (source->modelFlux, PS_TYPE_F32);173 174 // convolve the psf image with the model image175 psImageConvolveDirect (buffer, source->modelFlux, psf);176 177 // save the result back in the source178 psFree (source->modelFlux);179 source->modelFlux = buffer;180 }181 # endif182 183 // insert the source flux in the image184 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);185 177 psArrayAdd (sources, 100,source); 186 178 } 179 fclose (outfile); 187 180 188 181 // XXX many leaks in here, i think … … 191 184 return true; 192 185 } 193 -
branches/eam_branches/ipp-20100621/ppSim/src/ppSimInsertStars.c
r28127 r28659 105 105 float flux = star->flux * expCorr->data.F32[(int)yCell][(int)xCell]; 106 106 107 // if psfConvolve is TRUE, we will (elsewhere) convolve the image we a PSF108 // in this case, simply place delta functions in the image109 if (psfConvolve) {110 readout->image->data.F32[(int)(yCell)][(int)(xCell)] += flux;111 continue;112 }113 114 107 // instantiate a model for the PSF at this location, set desired flux 115 108 pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0); … … 125 118 // XXX i should be applying the gain and the correct effective area 126 119 psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0); 127 psF64Area = 2.0 * M_PI * axes.major * axes.minor;120 float Area = 2.0 * M_PI * axes.major * axes.minor; 128 121 129 // this value is the pure (input) flux, and is saved in the output source cmf files130 122 source->psfMag = -2.5*log10(star->flux); 131 123 source->errMag = sqrt(Area*PS_SQR(roughNoise) + flux) / flux; 132 124 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); 134 127 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 } 149 148 150 149 // add the sources to the source array -
branches/eam_branches/ipp-20100621/ppSim/src/ppSimMakeGalaxies.c
r18011 r28659 96 96 galaxy->y = iy; 97 97 98 galaxy->peak = 20000;98 galaxy->peak = 1000; 99 99 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; 102 116 galaxy->Rmin = (galaxyARatioMin + i * galaxyARatioSlope) * galaxy->Rmaj; 103 117 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); 104 123 105 124 psArrayAdd (galaxies, 100, galaxy); … … 124 143 galaxy->y = psRandomUniform(rng) * ySize; // y position 125 144 126 galaxy->flux = pow ((double)((i + 1) / norm), (double) (1.0 / galaxyLum));145 // galaxy->flux = pow ((double)((i + 1) / norm), (double) (1.0 / galaxyLum)); 127 146 128 galaxy->index = ( psRandomUniform(rng) * galaxyIndexSlope + galaxyIndexMin);147 galaxy->index = (sqrt(psRandomUniform(rng)) * galaxyIndexSlope + galaxyIndexMin); 129 148 galaxy->theta = (psRandomUniform(rng) * galaxyThetaSlope + galaxyThetaMin); 130 149 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; 132 151 152 // the flux is only approximately correct (scaling of the peak is wrong) 153 // elsewhere (ppSimInsertGalaxies.c) we calculate the true galaxy flux 133 154 galaxy->flux = expf((logf(i + 1) - logf(norm)) / galaxyLum); // Peak flux 134 155 galaxy->peak = galaxy->flux / (2.0*M_PI*PS_SQR(seeing)); 135 // galaxy->peak = 5000;136 156 137 157 psArrayAdd (galaxies, 100, galaxy); -
branches/eam_branches/ipp-20100621/ppSim/src/ppSimSmoothReadout.c
r28125 r28659 7 7 // XXX use these defaults? 8 8 // float minGauss = 0.1; 9 float nSigma = 3.0;9 float nSigma = 4.0; 10 10 float sigma = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels) 11 11 … … 28 28 // 4*pi*SIGMA_SMTH^2, but for measurements based on apertures comparable to or larger than the 29 29 // 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.
