IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 11, 2007, 1:01:03 PM (19 years ago)
Author:
Paul Price
Message:

Ensuring consistency between flux scales (peak vs integrated) --- stars now appear on the output image! Some memory fixing too.

File:
1 edited

Legend:

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

    r14667 r14816  
    11# include "ppSim.h"
     2
     3#define FAINT_FUDGE_FACTOR   1.0        // Fraction of the noise in a (boxcar) PSF for the faint limit
     4
    25
    36bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng) {
     
    3639    float readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE"); // Default read noise
    3740    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;
    4144    }
    4245
    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);
    4652    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;
    5056    }
    5157
    5258    // Normalisation, set by the specified stellar density at the specified bright magnitude
    5359    float norm = starsDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI) /
    54         powf(bright, starsLum);
     60        powf(bright, starsLum);
    5561
    5662    // Total number of stars down to the faint flux end
    5763    long num = expf(logf(norm) + starsLum * logf(faint)) + 0.5;
    5864
    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);
    6167
    6268    long oldSize = stars->n;
     
    6470
    6571    for (long i = 0; i < num; i++) {
    66         ppSimStar *star = ppSimStarAlloc ();
     72        ppSimStar *star = ppSimStarAlloc ();
    6773
    68         // make fpa center of distribution
    69         star->x    = psRandomUniform(rng) * xSize; // x position
    70         star->y    = psRandomUniform(rng) * ySize; // y position
     74        // make fpa center of distribution
     75        star->x    = psRandomUniform(rng) * xSize; // x position
     76        star->y    = psRandomUniform(rng) * ySize; // y position
    7177
    72         star->flux = expf((logf(i + 1) - logf(norm)) / starsLum); // Peak flux
    73         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));
    7480
    75         stars->data[oldSize + i] = star;
     81        stars->data[oldSize + i] = star;
    7682    }
    77     stars->n = stars->nalloc;
     83    stars->n = oldSize + num;
    7884
    7985    return true;
Note: See TracChangeset for help on using the changeset viewer.