IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 25, 2007, 11:57:36 AM (19 years ago)
Author:
eugene
Message:

added galaxies, some tweaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimStars.c

    r14463 r14667  
    11# include "ppSim.h"
    2 
    3 #define STAR_RANGE_MIN 4.5              // Minimum pixel range for adding stars, sigma
    4 #define STAR_BG_FRAC 0.1                // Fraction of background error to go out to when adding stars
    5 
    6 // Return star flux at a position
    7 static inline float starFlux(float x, float y, // Position of interest
    8                              float x0, float y0, // Centre of star
    9                              float seeing // Seeing FWHM (pixels)
    10     )
    11 {
    12 #ifdef STAR_GAUSSIAN
    13     // Gaussian star
    14     return exp(-0.5 * (PS_SQR(x - x0) + PS_SQR(y - y0)) / PS_SQR(seeing));
    15 #else
    16     // Waussian star
    17     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 #endif
    20 }
    21 
    22 // Return size of star in pixels
    23 static inline int starSize(float noise, float peak, float seeing)
    24 {
    25 #ifdef STAR_GAUSSIAN
    26     // 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 #else
    30     // 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 #endif
    34 }
    35 
    36 // Add a star into the signal and variance images
    37 bool ppSimInsertStar(psImage *signal,       // Signal image, to which to add star
    38                      psImage *variance,     // Variance image, to which to add star
    39                      float x0, float y0,    // Position of star
    40                      float peak,            // Peak flux of star
    41                      float noise,           // Rough noise estimate
    42                      float seeing,          // Seeing for star
    43                      const psImage *correction // Exposure correction as a function of position
    44     )
    45 {
    46     int size = starSize(noise, peak, seeing); // Size of star
    47 
    48     // Range in image pixels on which to add star
    49     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 flux
    57             signal->data.F32[y][x] += star;
    58             variance->data.F32[y][x] += star;
    59         }
    60     }
    61     return true;
    62 }
    632
    643void ppSimStarFree(ppSimStar *star)
     
    7413    return star;
    7514}
     15
     16void ppSimGalaxyFree(ppSimGalaxy *galaxy)
     17{
     18    return;
     19}
     20
     21ppSimGalaxy *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.