Changeset 14667
- Timestamp:
- Aug 25, 2007, 11:57:36 AM (19 years ago)
- Location:
- trunk/ppSim/src
- Files:
-
- 2 added
- 10 edited
-
Makefile.am (modified) (2 diffs)
-
ppSim.h (modified) (3 diffs)
-
ppSimArguments.c (modified) (2 diffs)
-
ppSimCreate.c (modified) (2 diffs)
-
ppSimInsertGalaxies.c (added)
-
ppSimInsertSources.c (modified) (2 diffs)
-
ppSimLoadStars.c (modified) (3 diffs)
-
ppSimLoop.c (modified) (7 diffs)
-
ppSimMakeBias.c (modified) (1 diff)
-
ppSimMakeGalaxies.c (added)
-
ppSimMakeStars.c (modified) (2 diffs)
-
ppSimStars.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/Makefile.am
r14657 r14667 9 9 ppSimLoadStars.c \ 10 10 ppSimMakeStars.c \ 11 ppSimMakeGalaxies.c \ 11 12 ppSimMakeBiassec.c \ 12 13 ppSimMakeBias.c \ … … 14 15 ppSimMakeSky.c \ 15 16 ppSimInsertSources.c \ 17 ppSimInsertGalaxies.c \ 16 18 ppSimAddOverscan.c \ 17 19 ppSimAddNoise.c \ -
trunk/ppSim/src/ppSim.h
r14657 r14667 48 48 } ppSimStar; 49 49 50 typedef struct { 51 double ra; 52 double dec; 53 float mag; 54 float x; 55 float y; 56 float flux; 57 58 float peak; 59 float Rmaj; 60 float Rmin; 61 float theta; 62 float index; 63 } ppSimGalaxy; 50 64 51 65 ppSimStar *ppSimStarAlloc (); 66 ppSimGalaxy *ppSimGalaxyAlloc (); 52 67 53 68 /// Parse command-line arguments … … 85 100 ); 86 101 87 psArray *ppSimLoadStars (pmFPA *fpa, pmConfig *config);102 bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config); 88 103 bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng); 89 104 … … 117 132 bool ppSimSetPSF (pmChip *chip, pmConfig *config); 118 133 134 bool ppSimMakeGalaxies(psArray *galaxies, pmFPA *fpa, pmConfig *config, const psRandom *rng); 135 bool ppSimInsertGalaxies (pmReadout *readout, psImage *expCorr, psArray *galaxies, pmConfig *config); 136 119 137 #endif -
trunk/ppSim/src/ppSimArguments.c
r14657 r14667 71 71 pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf", "-psflist"); 72 72 73 if (!config->camera) { 74 psErrorStackPrint(stderr, "A camera name must be specified using the -camera option."); 73 // only one of -camera and -file is needed 74 bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); 75 if (!config->camera && !status) { 76 psErrorStackPrint(stderr, "A camera name (-camera NAME) or an image (-file NAME) must be specified"); 75 77 usage(argv[0], arguments, config); 76 78 } … … 82 84 psString formatName = psMetadataLookupStr(NULL, arguments, "-format"); // Name of format 83 85 if (formatName) { 86 // XXX delay the config below until ppSimCreate? 84 87 config->formatName = psMemIncrRefCounter(formatName); 85 88 -
trunk/ppSim/src/ppSimCreate.c
r14657 r14667 9 9 pmFPAfile *ppSimCreate(pmConfig *config) 10 10 { 11 bool status; 12 bool simImage = false; 11 13 PS_ASSERT_PTR_NON_NULL(config, NULL); 14 pmFPA *fpa = NULL; 12 15 13 pmFPA *fpa = pmFPAConstruct(config->camera); // FPA to contain the observation 14 if (!fpa) { 15 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); 16 return NULL; 16 // the input image defines the camera. if it is not supplied, the user must have 17 // supplied a camera and other metadata on the command line 18 pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT"); 19 if (!input) { 20 simImage = true; 21 fpa = pmFPAConstruct(config->camera); // FPA to contain the observation 22 if (!fpa) { 23 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); 24 return NULL; 25 } 26 } else { 27 simImage = false; 28 if (input->type != PM_FPA_FILE_IMAGE) { 29 psError(PS_ERR_IO, true, "PPIMAGE.INPUT is not of type IMAGE"); 30 return NULL; 31 } 32 fpa = input->fpa; 17 33 } 18 34 … … 56 72 } 57 73 simSources->save = true; 74 75 // if we have loaded an input image, we do not need to populate the fpa 76 if (!simImage) { 77 return file; 78 } 58 79 59 80 pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level at which PHU goes -
trunk/ppSim/src/ppSimInsertSources.c
r14657 r14667 5 5 bool mdok; 6 6 7 assert (readout); 7 8 assert (stars); 8 assert (readout); 9 9 10 if (!stars->n) { return true; } 11 10 12 // XXX is this needed? 11 13 // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources … … 88 90 pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR); 89 91 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 area 94 psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0); 95 psF64 Area = 2.0 * M_PI * axes.major * axes.minor; 96 97 source->psfMag = -2.5*log10(star->flux); 98 source->errMag = sqrt(Area*PS_SQR(roughNoise) + star->flux) / star->flux; 99 90 100 // XXX add the sources to a source array 91 101 -
trunk/ppSim/src/ppSimLoadStars.c
r14531 r14667 1 1 #include "ppSim.h" 2 2 3 psArray *ppSimLoadStars (pmFPA *fpa, pmConfig *config) { 3 bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config) { 4 5 bool mdok; 6 assert (stars); 7 8 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 9 10 bool starsReal = psMetadataLookupBool(&mdok, recipe, "STARS.REAL"); // Density of fakes 11 if (!starsReal) return true; 4 12 5 13 // Read catalogue stars using psastro … … 38 46 psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", refStars->n); 39 47 40 psArray *stars = psArrayAlloc (refStars->n); 48 long oldSize = stars->n; 49 stars = psArrayRealloc (stars, refStars->n); 41 50 42 51 // Conversion loop … … 61 70 star->flux = powf(10.0, -0.4 * (star->mag - zp)) * expTime; 62 71 star->peak = star->flux / sqrt(2.0*M_PI) / seeing; 63 stars->data[ i] = star;72 stars->data[oldSize + i] = star; 64 73 } 65 74 psFree(refStars); -
trunk/ppSim/src/ppSimLoop.c
r14657 r14667 17 17 18 18 // Load catalogue stars 19 psArray *stars = NULL;19 psArray *stars = psArrayAllocEmpty (1); 20 20 if (type == PPSIM_TYPE_OBJECT) { 21 stars = ppSimLoadStars (fpa, config);21 ppSimLoadStars (stars, fpa, config); 22 22 } 23 23 … … 25 25 if (type == PPSIM_TYPE_OBJECT) { 26 26 ppSimMakeStars (stars, fpa, config, rng); 27 } 28 29 // Add random galaxies 30 psArray *galaxies = psArrayAllocEmpty (1); 31 if (type == PPSIM_TYPE_OBJECT) { 32 ppSimMakeGalaxies (galaxies, fpa, config, rng); 27 33 } 28 34 … … 62 68 while ((cell = pmFPAviewNextCell(view, fpa, 1))) { 63 69 64 // Size, position and orientation of cell 65 int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning; 66 int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning; 67 70 // check that we are able to work with this cell (readdir must be 1) 68 71 int readdir = psMetadataLookupS32(NULL, cell->concepts, "CELL.READDIR"); // Read direction 69 72 if (readdir != 1) { … … 73 76 } 74 77 75 psVector *biasCols = ppSimMakeBiassec (cell, config); 78 // if no readout exists, generate a single readout (upgrade to allow multiple 79 // readouts?) 80 if (cell->readouts->n == 0) { 81 // Size, position and orientation of cell 82 int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning; 83 int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning; 76 84 77 int numReadouts = 1; 78 for (int i = 0; i < numReadouts; i++) { 85 // generate a new readout for this cell 79 86 pmReadout *readout = pmReadoutAlloc(cell); // Readout within cell 80 87 … … 83 90 readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels 84 91 92 psImageInit (readout->image, 0.0); 93 psImageInit (readout->weight, 0.0); 94 } 95 96 psVector *biasCols = ppSimMakeBiassec (cell, config); 97 98 for (int i = 0; i < cell->readouts->n; i++) { 99 100 pmReadout *readout = cell->readouts->data[i]; 101 assert (readout); 102 103 // if we have not read in a weight or generated a fake image above, we need to 104 // build one here 105 if (!readout->weight) { 106 if (!pmReadoutGenerateWeight(readout, true)) { 107 psError (PS_ERR_UNKNOWN, false, "trouble creating weight"); 108 return false; 109 } 110 } 111 85 112 psImage *expCorr = NULL; // Exposure correction per pixel, for adding objects 86 113 if (type == PPSIM_TYPE_OBJECT) { 87 expCorr = psImageAlloc( numCols,numRows, PS_TYPE_F32);114 expCorr = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_F32); 88 115 } 89 116 90 117 psVector *biasRows = ppSimMakeBias (readout, config, rng); 91 118 if (type == PPSIM_TYPE_BIAS) goto done; 92 119 93 120 ppSimMakeDark (readout, config); 94 121 if (type == PPSIM_TYPE_DARK) goto done; … … 99 126 if (type == PPSIM_TYPE_OBJECT) { 100 127 ppSimInsertSources (readout, expCorr, stars, config); 128 } 129 130 if (type == PPSIM_TYPE_OBJECT) { 131 ppSimInsertGalaxies (readout, expCorr, galaxies, config); 101 132 } 102 133 … … 111 142 readout->parent->data_exists = true; 112 143 readout->parent->parent->data_exists = true; 113 psFree(readout); // Drop reference114 144 } 115 145 psFree(biasCols); -
trunk/ppSim/src/ppSimMakeBias.c
r14657 r14667 46 46 47 47 // Bias level 48 signal->data.F32[y][x] = biasRows->data.F32[y];49 variance->data.F32[y][x] = PS_SQR(readnoise);48 signal->data.F32[y][x] += biasRows->data.F32[y]; 49 variance->data.F32[y][x] += PS_SQR(readnoise); 50 50 51 51 } -
trunk/ppSim/src/ppSimMakeStars.c
r14531 r14667 3 3 bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng) { 4 4 5 bool mdok; 5 6 assert (stars); 6 7 7 bool mdok;8 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 8 9 9 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe 10 bool starsFake = psMetadataLookupBool(&mdok, recipe, "STARS.FAKE"); // Density of fakes 11 if (!starsFake) return true; 10 12 11 13 float starsLum = psMetadataLookupF32(NULL, config->arguments, "STARS.LUM"); // Star luminosity func slope … … 45 47 psLogMsg("ppSim", PS_LOG_INFO, 46 48 "Image noise is above brightest random star --- no random stars added."); 47 } else { 49 return true; 50 } 48 51 49 // Normalisation, set by the specified stellar density at the specified bright magnitude50 float norm = starsDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI) /51 powf(bright, starsLum);52 // Normalisation, set by the specified stellar density at the specified bright magnitude 53 float norm = starsDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI) / 54 powf(bright, starsLum); 52 55 53 // Total number of stars down to the faint flux end54 long num = expf(logf(norm) + starsLum * logf(faint)) + 0.5;56 // Total number of stars down to the faint flux end 57 long num = expf(logf(norm) + starsLum * logf(faint)) + 0.5; 55 58 56 psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld stars down to %f mag\n", num,57 -2.5 * log10(faint * sqrt(2.0*M_PI) * seeing / expTime) + zp);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); 58 61 59 long oldSize = stars->n;60 psArrayRealloc (stars, stars->n + num);62 long oldSize = stars->n; 63 psArrayRealloc (stars, stars->n + num); 61 64 62 for (long i = 0; i < num; i++) {63 ppSimStar *star = ppSimStarAlloc ();65 for (long i = 0; i < num; i++) { 66 ppSimStar *star = ppSimStarAlloc (); 64 67 65 // make fpa center of distribution66 star->x = psRandomUniform(rng) * xSize; // x position67 star->y = psRandomUniform(rng) * ySize; // y position68 star->peak = expf((logf(i + 1) - logf(norm)) / starsLum); // Peak flux 69 star->flux = star->peak * sqrt(2.0*M_PI)*seeing;70 stars->data[oldSize + i] = star;71 } 72 stars-> n = stars->nalloc;68 // make fpa center of distribution 69 star->x = psRandomUniform(rng) * xSize; // x position 70 star->y = psRandomUniform(rng) * ySize; // y position 71 72 star->flux = expf((logf(i + 1) - logf(norm)) / starsLum); // Peak flux 73 star->peak = star->flux / (2.0*M_PI*PS_SQR(seeing)); 74 75 stars->data[oldSize + i] = star; 73 76 } 77 stars->n = stars->nalloc; 78 74 79 return true; 75 80 } -
trunk/ppSim/src/ppSimStars.c
r14463 r14667 1 1 # include "ppSim.h" 2 3 #define STAR_RANGE_MIN 4.5 // Minimum pixel range for adding stars, sigma4 #define STAR_BG_FRAC 0.1 // Fraction of background error to go out to when adding stars5 6 // Return star flux at a position7 static inline float starFlux(float x, float y, // Position of interest8 float x0, float y0, // Centre of star9 float seeing // Seeing FWHM (pixels)10 )11 {12 #ifdef STAR_GAUSSIAN13 // Gaussian star14 return exp(-0.5 * (PS_SQR(x - x0) + PS_SQR(y - y0)) / PS_SQR(seeing));15 #else16 // Waussian star17 float z = (PS_SQR(x - x0) + PS_SQR(y - y0)) / (2.0 * PS_SQR(seeing));18 return 1.0 / (1.0 + z + PS_SQR(z));19 #endif20 }21 22 // Return size of star in pixels23 static inline int starSize(float noise, float peak, float seeing)24 {25 #ifdef STAR_GAUSSIAN26 // Gaussian star (solving Gaussian)27 float target = STAR_BG_FRAC * seeing * sqrt(M_2_PI) * noise / peak;28 return target < 1.0 ? 2.0 * seeing * sqrtf(-logf(target)) + 0.5 : seeing * STAR_RANGE_MIN;29 #else30 // Waussian star (solving Waussian where z >> 1 and peak/sqrt(bg) >> 1)31 float target = STAR_BG_FRAC * noise / peak;32 return PS_MAX(sqrtf(1.0 / target) + 0.5, seeing * STAR_RANGE_MIN);33 #endif34 }35 36 // Add a star into the signal and variance images37 bool ppSimInsertStar(psImage *signal, // Signal image, to which to add star38 psImage *variance, // Variance image, to which to add star39 float x0, float y0, // Position of star40 float peak, // Peak flux of star41 float noise, // Rough noise estimate42 float seeing, // Seeing for star43 const psImage *correction // Exposure correction as a function of position44 )45 {46 int size = starSize(noise, peak, seeing); // Size of star47 48 // Range in image pixels on which to add star49 int xMin = PS_MAX(0, x0 - size);50 int xMax = PS_MIN(signal->numCols - 1, x0 + size);51 int yMin = PS_MAX(0, y0 - size);52 int yMax = PS_MIN(signal->numRows - 1, y0 + size);53 54 for (int y = yMin; y <= yMax; y++) {55 for (int x = xMin; x <= xMax; x++) {56 float star = peak * correction->data.F32[y][x] * starFlux(x, y, x0, y0, seeing); // Star flux57 signal->data.F32[y][x] += star;58 variance->data.F32[y][x] += star;59 }60 }61 return true;62 }63 2 64 3 void ppSimStarFree(ppSimStar *star) … … 74 13 return star; 75 14 } 15 16 void ppSimGalaxyFree(ppSimGalaxy *galaxy) 17 { 18 return; 19 } 20 21 ppSimGalaxy *ppSimGalaxyAlloc () { 22 23 ppSimGalaxy *galaxy = (ppSimGalaxy *) psAlloc(sizeof(ppSimGalaxy)); 24 psMemSetDeallocator(galaxy, (psFreeFunc) ppSimGalaxyFree); 25 26 return galaxy; 27 }
Note:
See TracChangeset
for help on using the changeset viewer.
