IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34134


Ignore:
Timestamp:
Jul 10, 2012, 2:34:42 PM (14 years ago)
Author:
eugene
Message:

a bit of cleanup on the galaxy creation; add TRAIL model for galaxies

Location:
branches/eam_branches/ipp-20120627/ppSim/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120627/ppSim/src/ppSimInsertGalaxies.c

    r34083 r34134  
    7676    if (type == -1) {
    7777        psError (PS_ERR_UNKNOWN, false, "invalid model name");
    78         return false;
     78        return false;
    7979    }
    8080
     
    136136        PAR[PM_PAR_YPOS] = yChip;
    137137
    138         psEllipseAxes axes;
    139         axes.major       = galaxy->Rmaj;
    140         axes.minor       = galaxy->Rmin;
    141         axes.theta       = galaxy->theta;
    142         pmPSF_AxesToModel (PAR, axes, type);
    143         psF64 Area = 2.0 * M_PI * axes.major * axes.minor;
     138        if (type == pmModelClassGetType ("PS_MODEL_TRAIL")) {
     139            PAR[PM_PAR_LENGTH] = galaxy->Rmaj;
     140            PAR[PM_PAR_SIGMA]  = galaxy->Rmin;
     141            PAR[PM_PAR_THETA]  = galaxy->theta;
     142        } else {
     143            psEllipseAxes axes;
     144            axes.major       = galaxy->Rmaj;
     145            axes.minor       = galaxy->Rmin;
     146            axes.theta       = galaxy->theta;
     147            pmPSF_AxesToModel (PAR, axes, type);
     148        }
     149        psF64 Area = 2.0 * M_PI * galaxy->Rmaj * galaxy->Rmin;
    144150
    145151        if (nParam == 8) {
     
    147153        }
    148154
    149         // set the normalization to get the desired flux
    150         // XXX for now, use peak: pmModelSetFlux (model, galaxy->flux);
    151 
    152155        // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
    153156        float radius = model->modelRadius (model->params, 0.1*roughNoise);
    154157        radius = PS_MAX (radius, 1.0);
     158
    155159        // XXX the exp(-r^0.25) models can go way out if allowed...
    156160        radius = PS_MIN (radius, 300.0);
     
    176180
    177181        float par8 = (model->params->n == 8) ? model->params->data.F32[7] : 0.0;
    178         fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", galaxy->x, galaxy->y, flux, 1, source->psfMag, source->psfMagErr, axes.major, axes.minor, axes.theta, par8);
     182        fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", galaxy->x, galaxy->y, flux, 1, source->psfMag, source->psfMagErr, galaxy->Rmaj, galaxy->Rmin, galaxy->theta, par8);
    179183
    180184        psArrayAdd (sources, 100,source);
  • branches/eam_branches/ipp-20120627/ppSim/src/ppSimMakeGalaxies.c

    r32350 r34134  
    11# include "ppSim.h"
     2
     3bool ppSimSetGalaxyPeak (ppSimGalaxy *galaxy, pmModelType type, float index, float seeing);
    24
    35bool ppSimMakeGalaxies(psArray *galaxies, pmFPA *fpa, pmConfig *config, const psRandom *rng) {
     
    1921    int galaxyGridDY      = psMetadataLookupS32 (&mdok, recipe, "GALAXY.GRID.DY"); // Density of fakes
    2022    bool galaxyGridRandom = psMetadataLookupBool(&mdok, recipe, "GALAXY.GRID.RANDOM"); // Density of fakes
    21     float galaxyGridPeak  = psMetadataLookupF32 (&mdok, recipe, "GALAXY.GRID.PEAK"); // peak flux of fakes
     23    // float galaxyGridPeak  = psMetadataLookupF32 (&mdok, recipe, "GALAXY.GRID.PEAK"); // peak flux of fakes
    2224    float galaxyGridMag   = psMetadataLookupF32 (&mdok, recipe, "GALAXY.GRID.MAG"); // peak flux of fakes
    2325   
     
    4244    float expTime         = psMetadataLookupF32(&mdok, recipe, "EXPTIME"); // Exposure time
    4345    float zp              = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); // Photometric zero point
    44     // float seeing       = psMetadataLookupF32(&mdok, recipe, "SEEING"); // Seeing sigma (pix)
     46    float seeing          = psMetadataLookupF32(&mdok, recipe, "SEEING"); // Seeing sigma (pix)
    4547    float scale           = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
    4648    float skyRate         = psMetadataLookupF32(&mdok, recipe, "SKY.RATE"); // Sky rate
     
    150152                galaxy->theta = (galaxyThetaMin  + rndValue * galaxyThetaSlope);
    151153               
    152                 bool sersicType = false;
    153                 sersicType |= (type == pmModelClassGetType ("PS_MODEL_SERSIC"));
    154                 sersicType |= (type == pmModelClassGetType ("PS_MODEL_EXP"));
    155                 sersicType |= (type == pmModelClassGetType ("PS_MODEL_DEV"));
    156                 if (sersicType) {
    157                     if (type == pmModelClassGetType ("PS_MODEL_DEV")) index = 4.0;
    158                     if (type == pmModelClassGetType ("PS_MODEL_EXP")) index = 1.0;
    159                        
    160                     // for a sersic model,
    161                     float bn = 1.9992*index - 0.3271;
    162                     float Io = exp(bn);
    163                    
    164                     // the integral of a Sersic has an analytical form as follows:
    165                     float logGamma = lgamma(2.0*index);
    166                     float bnFactor = pow(bn, 2.0*index);
    167                     float norm = 2.0 * M_PI * PS_SQR(galaxy->Rmaj) * index * Io * exp(logGamma) / bnFactor;
    168                    
    169                     // XXX probably should limit the allowed thinness of a galaxy
    170                     galaxy->peak = galaxyGridFlux / norm / (galaxy->Rmin / galaxy->Rmaj);
    171                 } else {
    172                     galaxy->peak = galaxyGridPeak;
    173                 }
     154                galaxy->flux = galaxyGridFlux;
     155                ppSimSetGalaxyPeak (galaxy, type, index, seeing);
    174156
    175157                // if (0) {
     
    206188            galaxy->theta = (psRandomUniform(rng) * galaxyThetaSlope  + galaxyThetaMin);
    207189
    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             }
     190            // XXX probably should limit the allowed thinness of a galaxy
     191            float galaxyMag =  PS_MIN (faintMag, PS_MAX (brightMag, (log10((i + 1.0) / normScale) / galaxyAlpha)));
     192           
     193            galaxy->flux = ppSimMagToFlux (galaxyMag, zp) * expTime;
     194            ppSimSetGalaxyPeak (galaxy, type, index, seeing);
    231195
    232196            if (1) {
     
    239203    return true;
    240204}
     205
     206bool ppSimSetGalaxyPeak (ppSimGalaxy *galaxy, pmModelType type, float index, float seeing) {
     207
     208    bool isSersicType = false;
     209    if (type == pmModelClassGetType ("PS_MODEL_DEV")) {
     210        index = 4.0;
     211        isSersicType = true;
     212    }
     213    if (type == pmModelClassGetType ("PS_MODEL_EXP")) {
     214        index = 1.0;
     215        isSersicType = true;
     216    }
     217    if (type == pmModelClassGetType ("PS_MODEL_SERSIC")) {
     218        isSersicType = true;
     219    }
     220
     221    if (isSersicType) {
     222        // for a sersic model,
     223        float bn = 1.9992*index - 0.3271;
     224        float Io = exp(bn);
     225                   
     226        // the integral of a Sersic has an analytical form as follows:
     227        float logGamma = lgamma(2.0*index);
     228        float bnFactor = pow(bn, 2.0*index);
     229        float norm = 2.0 * M_PI * PS_SQR(galaxy->Rmaj) * index * Io * exp(logGamma) / bnFactor;
     230                   
     231        // XXX probably should limit the allowed thinness of a galaxy
     232        galaxy->peak = galaxy->flux / norm / (galaxy->Rmin / galaxy->Rmaj);
     233        return true;
     234    }
     235
     236    if (type == pmModelClassGetType ("PS_MODEL_TRAIL")) {
     237        // galaxy->Rmaj -> PM_PAR_LENGTH
     238        // seeing -> PM_PAR_SIGMA
     239        galaxy->Rmin = seeing / 2.35; // Rmin is used for sigma
     240        galaxy->peak = galaxy->flux / (galaxy->Rmaj * galaxy->Rmin * 2.0 * sqrt(2.0 * M_PI));
     241        return true;
     242    }
     243
     244    galaxy->peak = galaxy->flux / (2 * M_PI * galaxy->Rmaj * galaxy->Rmin);
     245    return true;
     246}
Note: See TracChangeset for help on using the changeset viewer.