Changeset 14816 for trunk/ppSim/src/ppSimInsertStars.c
- Timestamp:
- Sep 11, 2007, 1:01:03 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimInsertStars.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 }
Note:
See TracChangeset
for help on using the changeset viewer.
