Changeset 14667 for trunk/ppSim/src/ppSimStars.c
- Timestamp:
- Aug 25, 2007, 11:57:36 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimStars.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
