IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32300


Ignore:
Timestamp:
Sep 3, 2011, 11:40:00 AM (15 years ago)
Author:
eugene
Message:

generate a somewhat realistic luminosity function of galaxies (consistent with the star lum function parameters)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110710/ppSim/src/ppSimMakeGalaxies.c

    r32159 r32300  
    1111    if (!galaxyFake) return true;
    1212
    13     float galaxyLum       = psMetadataLookupF32(&mdok, recipe, "GALAXY.LUM"); // Galaxy luminosity func slope
    14     float galaxyMag       = psMetadataLookupF32(&mdok, recipe, "GALAXY.MAG"); // Galaxy brightest magnitude
     13    float galaxyAlpha     = psMetadataLookupF32(&mdok, recipe, "GALAXY.LUM"); // Galaxy luminosity func slope
     14    float brightMag       = psMetadataLookupF32(&mdok, recipe, "GALAXY.MAG"); // Galaxy brightest magnitude
    1515    float galaxyDensity   = psMetadataLookupF32(&mdok, recipe, "GALAXY.DENSITY"); // Density of fakes
    1616
     
    3939    float galaxyIndexMax  = psMetadataLookupF32(&mdok, recipe, "GALAXY.INDEX.MAX"); // Density of fakes
    4040
    41     float darkRate        = psMetadataLookupF32(&mdok, recipe, "DARK.RATE"); // Dark rate
     41    // float darkRate     = psMetadataLookupF32(&mdok, recipe, "DARK.RATE"); // Dark rate
    4242    float expTime         = psMetadataLookupF32(&mdok, recipe, "EXPTIME"); // Exposure time
    4343    float zp              = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); // Photometric zero point
    44     float seeing          = psMetadataLookupF32(&mdok, recipe, "SEEING"); // Seeing sigma (pix)
     44    // float seeing       = psMetadataLookupF32(&mdok, recipe, "SEEING"); // Seeing sigma (pix)
    4545    float scale           = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
    4646    float skyRate         = psMetadataLookupF32(&mdok, recipe, "SKY.RATE"); // Sky rate
     
    7676    // Grabbing read noise from the recipe rather than the cell, which is a potential danger, but it
    7777    // shouldn't be too bad.
    78     float readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE"); // Default read noise
    79     if (!mdok) {
    80         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe.");
    81         psFree(bounds);
    82         return false;
    83     }
    84 
    85     // Peak fluxes: faintest and brightest levels for random galaxy
    86     float faint = 0.1 * 10.0 * sqrt(2.0*M_PI) * seeing * sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime);
    87     float bright = powf(10.0, -0.4 * (galaxyMag - zp)) / sqrt(2.0*M_PI) / seeing * expTime;
    88     if (bright < faint) {
    89         psLogMsg("ppSim", PS_LOG_INFO,
    90                  "Image noise is above brightest random galaxy --- no random galaxy added.");
     78    // float readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE"); // Default read noise
     79    // if (!mdok) {
     80    //  psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe.");
     81    //  psFree(bounds);
     82    //  return false;
     83    // }
     84
     85    // faintest and brightest magnitudes for random galaxies
     86    // float brightFlux = ppSimMagToFlux (brightMag, zp) * expTime;
     87    float faintMag = brightMag + 5.0;
     88    if (brightMag > faintMag) {
     89        psLogMsg("ppSim", PS_LOG_INFO, "Image noise is above brightest random galaxy --- no random galaxy added.");
    9190        return true;
    9291    }
    9392
    9493    // Normalisation, set by the specified stellar density at the specified bright magnitude
    95     float norm = galaxyDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI) /
    96         powf(bright, galaxyLum);
     94    float refSum = galaxyDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI);
     95    float normLum =  refSum / (galaxyAlpha * logf(10.0) * powf(10.0, (galaxyAlpha * brightMag)));
     96    float normScale = normLum * galaxyAlpha * logf(10.0);
    9797
    9898    // Total number of galaxy down to the faint flux end
    99     long num = expf(logf(norm) + galaxyLum * logf(faint)) + 0.5;
    100 
    101     fprintf (stderr, "galaxy grid inst mag: %f\n", galaxyGridMag - zp - 2.5*log10(expTime));
     99    long nTotal = 0;
     100    if (galaxyAlpha < 0.1) {
     101        nTotal = 100;
     102    } else {
     103        nTotal = normScale * powf (10.0, (galaxyAlpha * faintMag));
     104    }
    102105
    103106    if (galaxyGrid) {
    104         num = (int)(xSize / galaxyGridDX) * (int)(ySize / galaxyGridDY);
     107        fprintf (stderr, "galaxy grid inst mag: %f\n", galaxyGridMag - zp - 2.5*log10(expTime));
     108        nTotal = (int)(xSize / galaxyGridDX) * (int)(ySize / galaxyGridDY);
    105109   
    106         psLogMsg("ppSim", PS_LOG_INFO, "Adding grid of %ld galaxies\n", num);
     110        psLogMsg("ppSim", PS_LOG_INFO, "Adding grid of %ld galaxies\n", nTotal);
    107111
    108112        float galaxyIndexSlope = (galaxyIndexMax - galaxyIndexMin);
     
    131135                float rndValue;
    132136
    133                 rndValue = galaxyGridRandom ? drand48() : i / (float) num;
     137                rndValue = galaxyGridRandom ? drand48() : i / (float) nTotal;
    134138                float index = (galaxyIndexMin  + rndValue * galaxyIndexSlope);
    135139                galaxy->index = 0.5/index; // factor of 0.5 because the Sersic model creates exp(-z^n), not exp(-r^n)
    136140
    137                 rndValue = galaxyGridRandom ? drand48() : i / (float) num;
     141                rndValue = galaxyGridRandom ? drand48() : i / (float) nTotal;
    138142                float scale = (galaxyRmajorMin + rndValue * galaxyRmajorSlope);
    139143
    140144                galaxy->Rmaj  = scale;
    141145
    142                 rndValue = galaxyGridRandom ? drand48() : i / (float) num;
     146                rndValue = galaxyGridRandom ? drand48() : i / (float) nTotal;
    143147                galaxy->Rmin  = (galaxyARatioMin + rndValue * galaxyARatioSlope) * galaxy->Rmaj;
    144148
    145                 rndValue = galaxyGridRandom ? drand48() : i / (float) num;
     149                rndValue = galaxyGridRandom ? drand48() : i / (float) nTotal;
    146150                galaxy->theta = (galaxyThetaMin  + rndValue * galaxyThetaSlope);
    147151               
     
    179183    } else {   
    180184
     185        fprintf (stderr, "galaxy ref inst mag: %f\n", brightMag - zp - 2.5*log10(expTime));
    181186        float galaxyIndexSlope = (galaxyIndexMax - galaxyIndexMin);
    182187        float galaxyThetaSlope = (galaxyThetaMax - galaxyThetaMin);
     
    184189        float galaxyRmajorSlope = (galaxyRmajorMax - galaxyRmajorMin);
    185190
    186         psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld galaxies down to %f mag\n", num,
    187                  -2.5 * log10(faint * sqrt(2.0*M_PI) * seeing / expTime) + zp);
    188 
    189         for (long i = 0; i < num; i++) {
     191        psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld galaxies down to %f mag\n", nTotal, faintMag);
     192
     193        for (long i = 0; i < nTotal; i++) {
    190194            ppSimGalaxy *galaxy = ppSimGalaxyAlloc ();
    191195
     
    198202
    199203            float scale = (psRandomUniform(rng) * galaxyRmajorSlope + galaxyRmajorMin);
    200 
    201             // for a sersic model,
    202             float bn = 1.9992*index - 0.3271;
    203             float fR = 1.0 / (sqrt(2.0) * pow (bn, index));
    204             float Io = exp(bn);
    205 
    206204            galaxy->Rmaj  = scale;
    207 
    208205            galaxy->Rmin  = (PS_SQR(psRandomUniform(rng)) * galaxyARatioSlope + galaxyARatioMin) * galaxy->Rmaj;
    209 
    210206            galaxy->theta = (psRandomUniform(rng) * galaxyThetaSlope  + galaxyThetaMin);
    211207
    212             // the flux is only approximately correct (scaling of the peak is wrong)
    213             // elsewhere (ppSimInsertGalaxies.c) we calculate the true galaxy flux
    214             galaxy->flux = expf((logf(i + 1) - logf(norm)) / galaxyLum); // Peak flux
    215             galaxy->peak = galaxy->flux / (2.0*M_PI*PS_SQR(seeing));
    216 
    217             if (0) {
    218               fprintf (stderr, "Rmaj: %f, scale: %f, index: %f, bn: %f, Ro: %f, Io: %f\n", galaxy->Rmaj, scale, index, bn, fR, Io);
     208            bool sersicType = false;
     209            sersicType |= (type == pmModelClassGetType ("PS_MODEL_SERSIC"));
     210            sersicType |= (type == pmModelClassGetType ("PS_MODEL_EXP"));
     211            sersicType |= (type == pmModelClassGetType ("PS_MODEL_DEV"));
     212            if (sersicType) {
     213                if (type == pmModelClassGetType ("PS_MODEL_DEV")) index = 4.0;
     214                if (type == pmModelClassGetType ("PS_MODEL_EXP")) index = 1.0;
     215               
     216                // for a sersic model,
     217                float bn = 1.9992*index - 0.3271;
     218                float Io = exp(bn);
     219               
     220                // the integral of a Sersic has an analytical form as follows:
     221                float logGamma = lgamma(2.0*index);
     222                float bnFactor = pow(bn, 2.0*index);
     223                float norm = 2.0 * M_PI * PS_SQR(galaxy->Rmaj) * index * Io * exp(logGamma) / bnFactor;
     224                   
     225                // XXX probably should limit the allowed thinness of a galaxy
     226                float galaxyMag =  PS_MIN (faintMag, PS_MAX (brightMag, (log10((i + 1.0) / normScale) / galaxyAlpha)));
     227
     228                galaxy->flux = ppSimMagToFlux (galaxyMag, zp) * expTime;
     229                galaxy->peak = galaxy->flux / norm / (galaxy->Rmin / galaxy->Rmaj);
     230            }
     231
     232            if (1) {
     233                fprintf (stderr, "Rmaj: %f, Rmin: %f, theta: %f, scale: %f, index: %f, peak: %f, mag: %f\n", galaxy->Rmaj, galaxy->Rmin, galaxy->theta*180.0/M_PI, scale, index, galaxy->peak, -2.5*log10(galaxy->flux));
    219234            }
    220235
Note: See TracChangeset for help on using the changeset viewer.