IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 1, 2009, 4:50:46 PM (17 years ago)
Author:
Paul Price
Message:

Merging work on detection efficiency measurement. pmReadoutFakeFromSources has changed, but it shouldn't be visible to anything else. psphotFake is not active yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmReadoutFake.c

    r23960 r25230  
    5050}
    5151
    52 bool pmReadoutFakeFromSources(pmReadout *readout, int numCols, int numRows, const psArray *sources,
    53                               const psVector *xOffset, const psVector *yOffset, const pmPSF *psf,
    54                               float minFlux, int radius, bool circularise, bool normalisePeak)
     52
     53bool pmReadoutFakeFromVectors(pmReadout *readout, int numCols, int numRows,
     54                              const psVector *x, const psVector *y, const psVector *mag,
     55                              const psVector *xOffset, const psVector *yOffset,
     56                              const pmPSF *psf, float minFlux, int radius,
     57                              bool circularise, bool normalisePeak)
    5558{
    5659    PS_ASSERT_PTR_NON_NULL(readout, false);
    5760    PS_ASSERT_INT_LARGER_THAN(numCols, 0, false);
    5861    PS_ASSERT_INT_LARGER_THAN(numRows, 0, false);
    59     PS_ASSERT_ARRAY_NON_NULL(sources, false);
    60 
     62    PS_ASSERT_VECTOR_NON_NULL(x, false);
     63    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, false);
     64    PS_ASSERT_VECTOR_NON_NULL(y, false);
     65    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false);
     66    PS_ASSERT_VECTORS_SIZE_EQUAL(y, x, false);
     67    PS_ASSERT_VECTOR_NON_NULL(mag, false);
     68    PS_ASSERT_VECTOR_TYPE(mag, PS_TYPE_F32, false);
     69    PS_ASSERT_VECTORS_SIZE_EQUAL(mag, x, false);
     70    long numSources = x->n;              // Number of sources
    6171    if (xOffset || yOffset) {
    6272        PS_ASSERT_VECTOR_NON_NULL(xOffset, false);
     
    6474        PS_ASSERT_VECTORS_SIZE_EQUAL(xOffset, yOffset, false);
    6575        PS_ASSERT_VECTOR_TYPE(xOffset, PS_TYPE_S32, false);
    66         PS_ASSERT_VECTOR_TYPE_EQUAL(xOffset, yOffset, false);
    67         if (xOffset->n != sources->n) {
     76        PS_ASSERT_VECTOR_TYPE(yOffset, PS_TYPE_S32, false);
     77        if (xOffset->n != numSources) {
    6878            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
    6979                    "Number of offset vectors (%ld) and sources (%ld) doesn't match",
    70                     xOffset->n, sources->n);
     80                    xOffset->n, numSources);
    7181            return false;
    7282        }
     
    8191    psImageInit(readout->image, 0);
    8292
    83     int numSources = sources->n;          // Number of stars
    84     for (int i = 0; i < numSources; i++) {
    85         pmSource *source = sources->data[i]; // Source of interest
    86         if (!source) {
    87             continue;
    88         }
    89         if (source->mode & SOURCE_MASK) {
    90             continue;
    91         }
    92         if (!isfinite(source->psfMag)) {
    93             continue;
    94         }
    95         float x, y;                     // Coordinates of source
    96         if (source->modelPSF) {
    97             x = source->modelPSF->params->data.F32[PM_PAR_XPOS];
    98             y = source->modelPSF->params->data.F32[PM_PAR_YPOS];
    99         } else {
    100             x = source->peak->xf;
    101             y = source->peak->yf;
    102         }
    103 
    104         float flux = powf(10.0, -0.4 * source->psfMag); // Flux of source
     93    for (long i = 0; i < numSources; i++) {
     94        float flux = powf(10.0, -0.4 * mag->data.F32[i]); // Flux of source
     95        float xSrc = x->data.F32[i], ySrc = y->data.F32[i]; // Coordinates of source
    10596
    10697        if (normalisePeak) {
     
    137128
    138129        pmSource *fakeSource = pmSourceAlloc(); // Fake source to generate
    139         fakeSource->peak = pmPeakAlloc(x, y, fakeModel->params->data.F32[PM_PAR_I0], PM_PEAK_LONE);
     130        fakeSource->peak = pmPeakAlloc(xSrc, ySrc, fakeModel->params->data.F32[PM_PAR_I0], PM_PEAK_LONE);
    140131        float fakeRadius = radius > 0 ? radius :
    141132            PS_MAX(1.0, fakeModel->modelRadius(fakeModel->params, minFlux)); // Radius of fake source
    142133
    143134        if (xOffset) {
    144             if (!pmSourceDefinePixels(fakeSource, readout, x + xOffset->data.S32[i],
    145                                       y + yOffset->data.S32[i], fakeRadius)) {
     135            if (!pmSourceDefinePixels(fakeSource, readout, xSrc + xOffset->data.S32[i],
     136                                      ySrc + yOffset->data.S32[i], fakeRadius)) {
    146137                psErrorClear();
    147138                continue;
     
    153144            }
    154145        } else {
    155             if (!pmSourceDefinePixels(fakeSource, readout, x, y, fakeRadius)) {
     146            if (!pmSourceDefinePixels(fakeSource, readout, xSrc, ySrc, fakeRadius)) {
    156147                psErrorClear();
    157148                continue;
     
    168159    return true;
    169160}
     161
     162
     163bool pmReadoutFakeFromSources(pmReadout *readout, int numCols, int numRows, const psArray *sources,
     164                              const psVector *xOffset, const psVector *yOffset, const pmPSF *psf,
     165                              float minFlux, int radius, bool circularise, bool normalisePeak)
     166{
     167    PS_ASSERT_ARRAY_NON_NULL(sources, false);
     168
     169    int numSources = sources->n;          // Number of stars
     170    psVector *x = psVectorAllocEmpty(numSources, PS_TYPE_F32);
     171    psVector *y = psVectorAllocEmpty(numSources, PS_TYPE_F32);
     172    psVector *mag = psVectorAllocEmpty(numSources, PS_TYPE_F32);
     173
     174    int numGood = 0;                    // Number of good sources
     175    for (int i = 0; i < numSources; i++) {
     176        pmSource *source = sources->data[i]; // Source of interest
     177        if (!source) {
     178            continue;
     179        }
     180        if (source->mode & SOURCE_MASK) {
     181            continue;
     182        }
     183        if (!isfinite(source->psfMag)) {
     184            continue;
     185        }
     186        float xSrc, ySrc;                     // Coordinates of source
     187        if (source->modelPSF) {
     188            xSrc = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     189            ySrc = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     190        } else {
     191            xSrc = source->peak->xf;
     192            ySrc = source->peak->yf;
     193        }
     194
     195        x->data.F32[numGood] = xSrc;
     196        y->data.F32[numGood] = ySrc;
     197        mag->data.F32[numGood] = source->psfMag;
     198        numGood++;
     199    }
     200    x->n = numGood;
     201    y->n = numGood;
     202    mag->n = numGood;
     203
     204    bool status = pmReadoutFakeFromVectors(readout, numCols, numRows, x, y, mag, xOffset, yOffset, psf,
     205                                           minFlux, radius, circularise, normalisePeak);
     206    psFree(x);
     207    psFree(y);
     208    psFree(mag);
     209
     210    return status;
     211}
Note: See TracChangeset for help on using the changeset viewer.