Changeset 14816
- Timestamp:
- Sep 11, 2007, 1:01:03 PM (19 years ago)
- Location:
- trunk/ppSim/src
- Files:
-
- 3 edited
-
ppSimInsertStars.c (modified) (3 diffs)
-
ppSimMakeSky.c (modified) (2 diffs)
-
ppSimMakeStars.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimInsertStars.c
r14668 r14816 1 1 # include "ppSim.h" 2 3 // Reset a pointer: free and set to NULL 4 #define RESET(PTR) \ 5 psFree(PTR); \ 6 PTR = NULL; 7 2 8 3 9 bool ppSimInsertStars (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config) { … … 26 32 float readnoise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE");// CCD read noise, e 27 33 if (isnan(readnoise)) { 28 psWarning("CELL.READNOISE is not set; reverting to recipe value READNOISE.");29 readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE");30 if (!mdok) {31 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe.");32 return false;33 }34 psWarning("CELL.READNOISE is not set; reverting to recipe value READNOISE."); 35 readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE"); 36 if (!mdok) { 37 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe."); 38 return false; 39 } 34 40 } 35 41 … … 58 64 59 65 // add sources to the readout image & weight 66 psTrace("ppSim", 1, "Inserting %ld stars...\n", stars->n); 60 67 for (long i = 0; i < stars->n; i++) { 61 ppSimStar *star = stars->data[i]; 68 ppSimStar *star = stars->data[i]; 69 psTrace("ppSim", 10, "Inserting star at %.1f,%.1f --> %.2f\n", star->x, star->y, star->flux); 62 70 63 // star->x,y are in fpa coordinates71 // star->x,y are in fpa coordinates 64 72 65 // Position on the cell and peak flux66 float xChip = PM_FPA_TO_CHIP(star->x, x0Chip, xParityChip);67 float yChip = PM_FPA_TO_CHIP(star->y, y0Chip, yParityChip);73 // Position on the cell and peak flux 74 float xChip = PM_FPA_TO_CHIP(star->x, x0Chip, xParityChip); 75 float yChip = PM_FPA_TO_CHIP(star->y, y0Chip, yParityChip); 68 76 69 // Position on the cell and peak flux70 float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, binning);71 float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, binning);77 // Position on the cell and peak flux 78 float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, binning); 79 float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, binning); 72 80 73 if (xCell < 0) continue; 74 if (yCell < 0) continue; 75 if (xCell > readout->image->numCols) continue; 76 if (yCell > readout->image->numRows) continue; 77 // XXX need to apply col0, row0 if readout is a subarray 81 // XXX Note, the below does not put the edges of stars on the readout if they fall slightly off 82 // This will be visible as cut-off stars at amplifier boundaries (e.g., Megacam) 83 if (xCell < 0) continue; 84 if (yCell < 0) continue; 85 if (xCell > readout->image->numCols) continue; 86 if (yCell > readout->image->numRows) continue; 87 // XXX need to apply col0, row0 if readout is a subarray 78 88 79 // XXX apply the expCorr to the star->flux before setting the model flux 89 // Apply the expCorr to the star->flux before setting the model flux 90 float flux = star->flux * expCorr->data.F32[(int)yCell][(int)xCell]; 80 91 81 // instantiate a model for the PSF at this location, set desired flux82 pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0);83 pmModelSetFlux (model, star->flux);92 // instantiate a model for the PSF at this location, set desired flux 93 pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0); 94 pmModelSetFlux (model, flux); 84 95 85 // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)86 float radius = model->modelRadius (model->params, roughNoise);87 radius = PS_MAX (radius, 1.0);96 // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0) 97 float radius = model->modelRadius (model->params, roughNoise); 98 radius = PS_MAX (radius, 1.0); 88 99 89 // construct a source, with model flux pixels set, based on the model90 pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR);100 // construct a source, with model flux pixels set, based on the model 101 pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR); 91 102 92 // XXX set the mag & err values (should this be done in pmSourceFromModel?)93 // XXX i should be applying the gain and the correct effective area94 psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0);95 psF64 Area = 2.0 * M_PI * axes.major * axes.minor;103 // XXX set the mag & err values (should this be done in pmSourceFromModel?) 104 // XXX i should be applying the gain and the correct effective area 105 psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0); 106 psF64 Area = 2.0 * M_PI * axes.major * axes.minor; 96 107 97 source->psfMag = -2.5*log10(star->flux); 98 source->errMag = sqrt(Area*PS_SQR(roughNoise) + star->flux) / star->flux; 99 100 // XXX add the sources to a source array 108 source->psfMag = -2.5*log10(flux); 109 source->errMag = sqrt(Area*PS_SQR(roughNoise) + flux) / flux; 101 110 102 // insert the source flux in the image 103 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY); 104 psArrayAdd (sources, 100,source); 111 // XXX add the sources to a source array 112 113 // insert the source flux in the image 114 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY); 115 psArrayAdd (sources, 100,source); 116 psFree(source); // Drop reference 117 118 // Blow away the image parts of the source, which makes the memory explode 119 RESET(source->pixels); 120 RESET(source->weight); 121 RESET(source->maskObj); 122 RESET(source->maskView); 123 RESET(source->modelFlux); 124 RESET(source->psfFlux); 125 RESET(source->blends); 105 126 } 106 127 107 128 // NOTE: readout must be part of the pmFPAfile named "PPSIM.OUTPUT" 108 129 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources); 130 psFree(sources); 109 131 110 // XXX many leaks in here, i think 132 // XXX many leaks in here, i think 111 133 return true; 112 134 } -
trunk/ppSim/src/ppSimMakeSky.c
r14657 r14816 8 8 9 9 pmCell *cell = readout->parent; 10 pmChip *chip = cell->parent; 10 pmChip *chip = cell->parent; 11 11 pmFPA *fpa = chip->parent; 12 12 … … 38 38 for (int y = 0; y < signal->numRows; y++) { 39 39 40 float yFPA = PPSIM_CELL_TO_FPA(y, y0Cell, yParityCell, binning, y0Chip, yParityChip) * 2.0 /41 (bounds->y1 - bounds->y0); // Relative y position in FPA40 float yFPA = PPSIM_CELL_TO_FPA(y, y0Cell, yParityCell, binning, y0Chip, yParityChip) * 2.0 / 41 (bounds->y1 - bounds->y0); // Relative y position in FPA 42 42 43 for (int x = 0; x < signal->numCols; x++) {44 float xFPA = PPSIM_CELL_TO_FPA(x, x0Cell, xParityCell, binning, x0Chip, xParityChip) * 2.0 /45 (bounds->x1 - bounds->x0); // Relative x position in FPA43 for (int x = 0; x < signal->numCols; x++) { 44 float xFPA = PPSIM_CELL_TO_FPA(x, x0Cell, xParityCell, binning, x0Chip, xParityChip) * 2.0 / 45 (bounds->x1 - bounds->x0); // Relative x position in FPA 46 46 47 // Shutter: adjust exposure time48 float realExpTime = expTime + shutterTime * (xFPA + yFPA + 2.0) / 4.0;47 // Shutter: adjust exposure time 48 float realExpTime = expTime + shutterTime * (xFPA + yFPA + 2.0) / 4.0; 49 49 50 // Gaussian flat-field over the FPA51 float flatValue = exp(-0.5 / PS_SQR(flatSigma) * 52 (PS_SQR(yFPA) + PS_SQR(xFPA))) / flatSigma / sqrt(M_PI);50 // Gaussian flat-field over the FPA 51 float flatValue = expf(-0.5 / PS_SQR(flatSigma) * (PS_SQR(yFPA) + PS_SQR(xFPA))) / 52 flatSigma / sqrtf(2.0 * M_PI); 53 53 54 if (type == PPSIM_TYPE_FLAT) {55 float flatFlux = flatRate * flatValue * realExpTime; // Flux from flat-field56 signal->data.F32[y][x] += flatFlux;57 variance->data.F32[y][x] += flatFlux;58 continue;59 }54 if (type == PPSIM_TYPE_FLAT) { 55 float flatFlux = flatRate * flatValue * realExpTime; // Flux from flat-field 56 signal->data.F32[y][x] += flatFlux; 57 variance->data.F32[y][x] += flatFlux; 58 continue; 59 } 60 60 61 expCorr->data.F32[y][x] = flatValue *realExpTime / expTime;61 expCorr->data.F32[y][x] = realExpTime / expTime; 62 62 63 // Sky background64 float skyFlux = skyRate * flatValue * realExpTime; // Flux from sky65 signal->data.F32[y][x] += skyFlux;66 variance->data.F32[y][x] += skyFlux;63 // Sky background 64 float skyFlux = skyRate * flatValue * realExpTime; // Flux from sky 65 signal->data.F32[y][x] += skyFlux; 66 variance->data.F32[y][x] += skyFlux; 67 67 68 // TO DO: Add fringes68 // TO DO: Add fringes 69 69 70 }70 } 71 71 } 72 72 psFree(bounds); -
trunk/ppSim/src/ppSimMakeStars.c
r14667 r14816 1 1 # include "ppSim.h" 2 3 #define FAINT_FUDGE_FACTOR 1.0 // Fraction of the noise in a (boxcar) PSF for the faint limit 4 2 5 3 6 bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng) { … … 36 39 float readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE"); // Default read noise 37 40 if (!mdok) { 38 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe.");39 psFree(bounds);40 return false;41 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe."); 42 psFree(bounds); 43 return false; 41 44 } 42 45 43 // Peak fluxes: faintest and brightest levels for random stars 44 float faint = 0.1 * 10.0 * sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime); 45 float bright = powf(10.0, -0.4 * (starsMag - zp)) / sqrt(2.0*M_PI) / seeing * expTime; 46 // Faintest and brightest (integrated) fluxes (actually fluence, since integrated) for random stars 47 float faint = FAINT_FUDGE_FACTOR * sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime) * 48 seeing; // Faint limit is related to the noise in a (boxcar) PSF 49 float bright = powf(10.0, -0.4 * (starsMag - zp)) * expTime; // Bright limit is specified by user as mag 50 psTrace("ppSim", 6, "Faint limit: %f\n", faint); 51 psTrace("ppSim", 6, "Bright limit: %f\n", bright); 46 52 if (bright < faint) { 47 psLogMsg("ppSim", PS_LOG_INFO,48 "Image noise is above brightest random star --- no random stars added.");49 return true;53 psLogMsg("ppSim", PS_LOG_INFO, 54 "Image noise is above brightest random star --- no random stars added."); 55 return true; 50 56 } 51 57 52 58 // Normalisation, set by the specified stellar density at the specified bright magnitude 53 59 float norm = starsDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI) / 54 powf(bright, starsLum);60 powf(bright, starsLum); 55 61 56 62 // Total number of stars down to the faint flux end 57 63 long num = expf(logf(norm) + starsLum * logf(faint)) + 0.5; 58 64 59 psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld stars down to %f mag\n", num,60 -2.5 * log10(faint * sqrt(2.0*M_PI) * seeing/ expTime) + zp);65 psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld stars down to %f mag\n", 66 num, -2.5 * log10(faint / expTime) + zp); 61 67 62 68 long oldSize = stars->n; … … 64 70 65 71 for (long i = 0; i < num; i++) { 66 ppSimStar *star = ppSimStarAlloc ();72 ppSimStar *star = ppSimStarAlloc (); 67 73 68 // make fpa center of distribution69 star->x = psRandomUniform(rng) * xSize; // x position70 star->y = psRandomUniform(rng) * ySize; // y position74 // make fpa center of distribution 75 star->x = psRandomUniform(rng) * xSize; // x position 76 star->y = psRandomUniform(rng) * ySize; // y position 71 77 72 star->flux = expf((logf(i + 1) - logf(norm)) / starsLum); // Peak flux73 star->peak = star->flux / (2.0*M_PI*PS_SQR(seeing));78 star->flux = expf((logf(i + 1) - logf(norm)) / starsLum); // Peak flux 79 star->peak = star->flux / (2.0*M_PI*PS_SQR(seeing)); 74 80 75 stars->data[oldSize + i] = star;81 stars->data[oldSize + i] = star; 76 82 } 77 stars->n = stars->nalloc;83 stars->n = oldSize + num; 78 84 79 85 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
