IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14667


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

added galaxies, some tweaks

Location:
trunk/ppSim/src
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/Makefile.am

    r14657 r14667  
    99        ppSimLoadStars.c        \
    1010        ppSimMakeStars.c        \
     11        ppSimMakeGalaxies.c     \
    1112        ppSimMakeBiassec.c      \
    1213        ppSimMakeBias.c         \
     
    1415        ppSimMakeSky.c          \
    1516        ppSimInsertSources.c    \
     17        ppSimInsertGalaxies.c   \
    1618        ppSimAddOverscan.c      \
    1719        ppSimAddNoise.c         \
  • trunk/ppSim/src/ppSim.h

    r14657 r14667  
    4848} ppSimStar;
    4949
     50typedef struct {
     51    double ra;
     52    double dec;
     53    float mag;
     54    float x;
     55    float y;
     56    float flux;
     57
     58    float peak;
     59    float Rmaj;
     60    float Rmin;
     61    float theta;
     62    float index;
     63} ppSimGalaxy;
    5064
    5165ppSimStar *ppSimStarAlloc ();
     66ppSimGalaxy *ppSimGalaxyAlloc ();
    5267
    5368/// Parse command-line arguments
     
    85100                     );
    86101
    87 psArray *ppSimLoadStars (pmFPA *fpa, pmConfig *config);
     102bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config);
    88103bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng);
    89104
     
    117132bool ppSimSetPSF (pmChip *chip, pmConfig *config);
    118133
     134bool ppSimMakeGalaxies(psArray *galaxies, pmFPA *fpa, pmConfig *config, const psRandom *rng);
     135bool ppSimInsertGalaxies (pmReadout *readout, psImage *expCorr, psArray *galaxies, pmConfig *config);
     136
    119137#endif
  • trunk/ppSim/src/ppSimArguments.c

    r14657 r14667  
    7171    pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf", "-psflist");
    7272
    73     if (!config->camera) {
    74         psErrorStackPrint(stderr, "A camera name must be specified using the -camera option.");
     73    // only one of -camera and -file is needed
     74    bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
     75    if (!config->camera && !status) {
     76        psErrorStackPrint(stderr, "A camera name (-camera NAME) or an image (-file NAME) must be specified");
    7577        usage(argv[0], arguments, config);
    7678    }
     
    8284    psString formatName = psMetadataLookupStr(NULL, arguments, "-format"); // Name of format
    8385    if (formatName) {
     86        // XXX delay the config below until ppSimCreate?
    8487        config->formatName = psMemIncrRefCounter(formatName);
    8588
  • trunk/ppSim/src/ppSimCreate.c

    r14657 r14667  
    99pmFPAfile *ppSimCreate(pmConfig *config)
    1010{
     11    bool status;
     12    bool simImage = false;
    1113    PS_ASSERT_PTR_NON_NULL(config, NULL);
     14    pmFPA *fpa = NULL;
    1215
    13     pmFPA *fpa = pmFPAConstruct(config->camera); // FPA to contain the observation
    14     if (!fpa) {
    15         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
    16         return NULL;
     16    // the input image defines the camera.  if it is not supplied, the user must have
     17    // supplied a camera and other metadata on the command line
     18    pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT");
     19    if (!input) {
     20        simImage = true;
     21        fpa = pmFPAConstruct(config->camera); // FPA to contain the observation
     22        if (!fpa) {
     23            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
     24            return NULL;
     25        }
     26    } else {
     27        simImage = false;
     28        if (input->type != PM_FPA_FILE_IMAGE) {
     29            psError(PS_ERR_IO, true, "PPIMAGE.INPUT is not of type IMAGE");
     30            return NULL;
     31        }
     32        fpa = input->fpa;
    1733    }
    1834
     
    5672    }
    5773    simSources->save = true;
     74
     75    // if we have loaded an input image, we do not need to populate the fpa
     76    if (!simImage) {
     77        return file;
     78    }
    5879
    5980    pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level at which PHU goes
  • trunk/ppSim/src/ppSimInsertSources.c

    r14657 r14667  
    55    bool mdok;
    66
     7    assert (readout);
    78    assert (stars);
    8     assert (readout);
    9    
     9
     10    if (!stars->n) { return true; }
     11
    1012    // XXX is this needed?
    1113    // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources
     
    8890        pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR);
    8991
     92        // XXX set the mag & err values (should this be done in pmSourceFromModel?)
     93        // XXX i should be applying the gain and the correct effective area
     94        psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0);
     95        psF64 Area = 2.0 * M_PI * axes.major * axes.minor;
     96
     97        source->psfMag = -2.5*log10(star->flux);
     98        source->errMag = sqrt(Area*PS_SQR(roughNoise) + star->flux) / star->flux;       
     99       
    90100        // XXX add the sources to a source array
    91101
  • trunk/ppSim/src/ppSimLoadStars.c

    r14531 r14667  
    11#include "ppSim.h"
    22
    3 psArray *ppSimLoadStars (pmFPA *fpa, pmConfig *config) {
     3bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config) {
     4
     5    bool mdok;
     6    assert (stars);
     7
     8    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
     9
     10    bool starsReal = psMetadataLookupBool(&mdok, recipe, "STARS.REAL"); // Density of fakes
     11    if (!starsReal) return true;
    412
    513    // Read catalogue stars using psastro
     
    3846    psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", refStars->n);
    3947
    40     psArray *stars = psArrayAlloc (refStars->n);
     48    long oldSize = stars->n;
     49    stars = psArrayRealloc (stars, refStars->n);
    4150
    4251    // Conversion loop
     
    6170        star->flux = powf(10.0, -0.4 * (star->mag - zp)) * expTime;
    6271        star->peak = star->flux / sqrt(2.0*M_PI) / seeing;
    63         stars->data[i] = star;
     72        stars->data[oldSize + i] = star;
    6473    }
    6574    psFree(refStars);
  • trunk/ppSim/src/ppSimLoop.c

    r14657 r14667  
    1717
    1818    // Load catalogue stars
    19     psArray *stars = NULL;
     19    psArray *stars = psArrayAllocEmpty (1);
    2020    if (type == PPSIM_TYPE_OBJECT) {
    21         stars = ppSimLoadStars (fpa, config);
     21        ppSimLoadStars (stars, fpa, config);
    2222    }
    2323
     
    2525    if (type == PPSIM_TYPE_OBJECT) {
    2626        ppSimMakeStars (stars, fpa, config, rng);
     27    }
     28
     29    // Add random galaxies
     30    psArray *galaxies = psArrayAllocEmpty (1);
     31    if (type == PPSIM_TYPE_OBJECT) {
     32        ppSimMakeGalaxies (galaxies, fpa, config, rng);
    2733    }
    2834
     
    6268        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    6369
    64             // Size, position and orientation of cell
    65             int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning;
    66             int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning;
    67 
     70            // check that we are able to work with this cell (readdir must be 1)
    6871            int readdir = psMetadataLookupS32(NULL, cell->concepts, "CELL.READDIR"); // Read direction
    6972            if (readdir != 1) {
     
    7376            }
    7477
    75             psVector *biasCols = ppSimMakeBiassec (cell, config);
     78            // if no readout exists, generate a single readout (upgrade to allow multiple
     79            // readouts?)
     80            if (cell->readouts->n == 0) {
     81                // Size, position and orientation of cell
     82                int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning;
     83                int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning;
    7684
    77             int numReadouts = 1;
    78             for (int i = 0; i < numReadouts; i++) {
     85                // generate a new readout for this cell
    7986                pmReadout *readout = pmReadoutAlloc(cell); // Readout within cell
    8087
     
    8390                readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels
    8491
     92                psImageInit (readout->image, 0.0);
     93                psImageInit (readout->weight, 0.0);
     94            }
     95
     96            psVector *biasCols = ppSimMakeBiassec (cell, config);
     97
     98            for (int i = 0; i < cell->readouts->n; i++) {
     99
     100                pmReadout *readout = cell->readouts->data[i];
     101                assert (readout);
     102
     103                // if we have not read in a weight or generated a fake image above, we need to
     104                // build one here
     105                if (!readout->weight) {
     106                    if (!pmReadoutGenerateWeight(readout, true)) {
     107                        psError (PS_ERR_UNKNOWN, false, "trouble creating weight");
     108                        return false;
     109                    }
     110                }
     111
    85112                psImage *expCorr = NULL; // Exposure correction per pixel, for adding objects
    86113                if (type == PPSIM_TYPE_OBJECT) {
    87                     expCorr = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     114                    expCorr = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_F32);
    88115                }
    89116
    90117                psVector *biasRows = ppSimMakeBias (readout, config, rng);
    91118                if (type == PPSIM_TYPE_BIAS) goto done;
    92                
     119       
    93120                ppSimMakeDark (readout, config);
    94121                if (type == PPSIM_TYPE_DARK) goto done;
     
    99126                if (type == PPSIM_TYPE_OBJECT) {
    100127                    ppSimInsertSources (readout, expCorr, stars, config);
     128                }
     129
     130                if (type == PPSIM_TYPE_OBJECT) {
     131                    ppSimInsertGalaxies (readout, expCorr, galaxies, config);
    101132                }
    102133
     
    111142                readout->parent->data_exists = true;
    112143                readout->parent->parent->data_exists = true;
    113                 psFree(readout);        // Drop reference
    114144            }
    115145            psFree(biasCols);
  • trunk/ppSim/src/ppSimMakeBias.c

    r14657 r14667  
    4646
    4747            // Bias level
    48             signal->data.F32[y][x] = biasRows->data.F32[y];
    49             variance->data.F32[y][x] = PS_SQR(readnoise);
     48            signal->data.F32[y][x] += biasRows->data.F32[y];
     49            variance->data.F32[y][x] += PS_SQR(readnoise);
    5050
    5151        }
  • trunk/ppSim/src/ppSimMakeStars.c

    r14531 r14667  
    33bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng) {
    44
     5    bool mdok;
    56    assert (stars);
    67
    7     bool mdok;
     8    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
    89
    9     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
     10    bool starsFake = psMetadataLookupBool(&mdok, recipe, "STARS.FAKE"); // Density of fakes
     11    if (!starsFake) return true;
    1012
    1113    float starsLum = psMetadataLookupF32(NULL, config->arguments, "STARS.LUM"); // Star luminosity func slope
     
    4547        psLogMsg("ppSim", PS_LOG_INFO,
    4648                 "Image noise is above brightest random star --- no random stars added.");
    47     } else {
     49        return true;
     50    }
    4851
    49         // Normalisation, set by the specified stellar density at the specified bright magnitude
    50         float norm = starsDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI) /
    51             powf(bright, starsLum);
     52    // Normalisation, set by the specified stellar density at the specified bright magnitude
     53    float norm = starsDensity * xSize * ySize * PS_SQR(scale * 180.0 / M_PI) /
     54        powf(bright, starsLum);
    5255
    53         // Total number of stars down to the faint flux end
    54         long num = expf(logf(norm) + starsLum * logf(faint)) + 0.5;
     56    // Total number of stars down to the faint flux end
     57    long num = expf(logf(norm) + starsLum * logf(faint)) + 0.5;
    5558
    56         psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld stars down to %f mag\n", num,
    57                 -2.5 * log10(faint * sqrt(2.0*M_PI) * seeing / expTime) + zp);
     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);
    5861
    59         long oldSize = stars->n;
    60         psArrayRealloc (stars, stars->n + num);
     62    long oldSize = stars->n;
     63    psArrayRealloc (stars, stars->n + num);
    6164
    62         for (long i = 0; i < num; i++) {
    63             ppSimStar *star = ppSimStarAlloc ();
     65    for (long i = 0; i < num; i++) {
     66        ppSimStar *star = ppSimStarAlloc ();
    6467
    65             // make fpa center of distribution
    66             star->x    = psRandomUniform(rng) * xSize; // x position
    67             star->y    = psRandomUniform(rng) * ySize; // y position
    68             star->peak = expf((logf(i + 1) - logf(norm)) / starsLum); // Peak flux
    69             star->flux = star->peak * sqrt(2.0*M_PI)*seeing;
    70             stars->data[oldSize + i] = star;
    71         }
    72         stars->n = stars->nalloc;
     68        // make fpa center of distribution
     69        star->x    = psRandomUniform(rng) * xSize; // x position
     70        star->y    = psRandomUniform(rng) * ySize; // y position
     71
     72        star->flux = expf((logf(i + 1) - logf(norm)) / starsLum); // Peak flux
     73        star->peak = star->flux / (2.0*M_PI*PS_SQR(seeing));
     74
     75        stars->data[oldSize + i] = star;
    7376    }
     77    stars->n = stars->nalloc;
     78
    7479    return true;
    7580}
  • 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.