IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26405


Ignore:
Timestamp:
Dec 15, 2009, 1:45:56 AM (16 years ago)
Author:
Paul Price
Message:

Add fake sources at random positions and constant nominated magnitude.

Location:
trunk/ppViz/src/ppVizPSF
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppViz/src/ppVizPSF/ppVizPSF.h

    r26367 r26405  
    1111    psString psfName;                   // Filename with PSF
    1212    psString sourcesName;               // Filename with sources
     13    int fakeNum;                        // Number of fake sources
     14    float fakeMag;                      // Magnitude of fake sources
    1315    psString outRoot;                   // Output root name
    1416    float minFlux;                      // Minimum flux for sources
  • trunk/ppViz/src/ppVizPSF/ppVizPSFArguments.c

    r26367 r26405  
    4949    psMetadata *arguments = psMetadataAlloc(); // Command-line arguments
    5050    psMetadataAddStr(arguments, PS_LIST_TAIL, "-psf", 0, "Filename of PSF", NULL);
    51     psMetadataAddStr(arguments, PS_LIST_TAIL, "-sources", 0, "Filename of sources", NULL);
     51    psMetadataAddStr(arguments, PS_LIST_TAIL, "-sources", 0, "Filename of CMF sources", NULL);
     52    psMetadataAddS32(arguments, PS_LIST_TAIL, "-fake-num", 0, "Number of fake sources", 0);
     53    psMetadataAddF32(arguments, PS_LIST_TAIL, "-fake-mag", 0, "Magnitude of fake sources", NAN);
    5254    psMetadataAddF32(arguments, PS_LIST_TAIL, "-x", 0, "x position of fake source [0..1]", NAN);
    5355    psMetadataAddF32(arguments, PS_LIST_TAIL, "-y", 0, "y position of fake source [0..1]", NAN);
     
    5961    data->psfName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-psf"));
    6062    data->sourcesName = psMemIncrRefCounter(psMetadataLookupStr(&mdok, arguments, "-sources"));
     63    data->fakeNum = psMetadataLookupS32(NULL, arguments, "-fake-num");
     64    data->fakeMag = psMetadataLookupF32(NULL, arguments, "-fake-mag");
    6165    data->outRoot = psStringCopy(argv[1]);
    6266    data->x = psMetadataLookupF32(NULL, arguments, "-x");
  • trunk/ppViz/src/ppVizPSF/ppVizPSFData.c

    r26367 r26405  
    2828    data->psfName = NULL;
    2929    data->sourcesName = NULL;
     30    data->fakeNum = 0;
     31    data->fakeMag = NAN;
    3032    data->outRoot = NULL;
    3133    data->config = NULL;
  • trunk/ppViz/src/ppVizPSF/ppVizPSFLoop.c

    r26367 r26405  
    7474                int numCols = 0, numRows = 0;              // Size of image
    7575                psVector *xOffset = NULL, *yOffset = NULL; // Offset from source to true position
     76
     77                if (sources || (data->fakeNum > 0 && isfinite(data->fakeMag))) {
     78                  numCols = psf->fieldNx;
     79                  numRows = psf->fieldNy;
     80                  psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image", numCols, numRows);
     81                }
    7682                if (sources) {
    7783                    psMemIncrRefCounter(sources);
    78                     numCols = psf->fieldNx;
    79                     numRows = psf->fieldNy;
    80                     psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image from %ld input sources",
    81                              numCols, numRows, sources->n);
    82                 } else {
     84                    psLogMsg("ppVizPSF", PS_LOG_INFO, "Using %ld input sources", sources->n);
     85                }
     86                if (data->fakeNum > 0 && isfinite(data->fakeMag)) {
     87                  long numOld = 0; // Old number of sources
     88                  long numNew = -1; // New number of sources
     89                  psLogMsg("ppVizPSF", PS_LOG_INFO, "Adding %d fake sources", data->fakeNum);
     90                  if (sources) {
     91                    numOld = sources->n;
     92                    numNew = numOld + data->fakeNum;
     93                    sources = psArrayRealloc(sources, numNew);
     94                    sources->n = numNew;
     95                  } else {
     96                    numNew = data->fakeNum;
     97                    sources = psArrayAlloc(numNew);
     98                  }
     99
     100                  psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
     101
     102                  for (int i = numOld; i < numNew; i++) {
     103                    pmSource *source = pmSourceAlloc(); // Fake source
     104                    sources->data[i] = source;
     105                    float xSrc = psRandomUniform(rng) * numCols, ySrc = psRandomUniform(rng) * numRows; // Position of source
     106
     107                    pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation
     108                    float fluxNorm = model->modelFlux(model->params);               // Flux for peak=1
     109                    float fluxPeak = powf(10.0, -0.4 * data->fakeMag) / fluxNorm; // Peak flux
     110                    source->peak = pmPeakAlloc(xSrc, ySrc, fluxPeak, PM_PEAK_LONE);
     111                    source->psfMag = data->fakeMag;
     112                    psFree(model);
     113                  }
     114                }                 
     115                if (!sources) {
     116                  // Generate fake image with only a single realisation of the PSF
    83117                    sources = psArrayAlloc(1);
    84118                    pmSource *source = pmSourceAlloc(); // Fake source
Note: See TracChangeset for help on using the changeset viewer.