IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:35:14 PM (17 years ago)
Author:
Paul Price
Message:

Adding pmReadoutFakeFromVectors, and altering pmReadoutFakeFromSources to use it.

Location:
branches/pap/psModules/src/camera
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap/psModules/src/camera/pmReadoutFake.c

    r25027 r25028  
    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) {
     
    126117            continue;
    127118        }
     119
    128120        if (circularise && !circulariseModel(fakeModel)) {
    129121            psError(PS_ERR_UNKNOWN, false, "Unable to circularise PSF model.");
     
    137129
    138130        pmSource *fakeSource = pmSourceAlloc(); // Fake source to generate
    139         fakeSource->peak = pmPeakAlloc(x, y, fakeModel->params->data.F32[PM_PAR_I0], PM_PEAK_LONE);
     131        fakeSource->peak = pmPeakAlloc(xSrc, ySrc, fakeModel->params->data.F32[PM_PAR_I0], PM_PEAK_LONE);
    140132        float fakeRadius = radius > 0 ? radius :
    141133            PS_MAX(1.0, fakeModel->modelRadius(fakeModel->params, minFlux)); // Radius of fake source
    142134
    143135        if (xOffset) {
    144             if (!pmSourceDefinePixels(fakeSource, readout, x + xOffset->data.S32[i],
    145                                       y + yOffset->data.S32[i], fakeRadius)) {
     136            if (!pmSourceDefinePixels(fakeSource, readout, xSrc + xOffset->data.S32[i],
     137                                      ySrc + yOffset->data.S32[i], fakeRadius)) {
    146138                psErrorClear();
    147139                continue;
     
    153145            }
    154146        } else {
    155             if (!pmSourceDefinePixels(fakeSource, readout, x, y, fakeRadius)) {
     147            if (!pmSourceDefinePixels(fakeSource, readout, xSrc, ySrc, fakeRadius)) {
    156148                psErrorClear();
    157149                continue;
     
    168160    return true;
    169161}
     162
     163
     164
     165
     166
     167
     168
     169
     170bool pmReadoutFakeFromSources(pmReadout *readout, int numCols, int numRows, const psArray *sources,
     171                              const psVector *xOffset, const psVector *yOffset, const pmPSF *psf,
     172                              float minFlux, int radius, bool circularise, bool normalisePeak)
     173{
     174    PS_ASSERT_ARRAY_NON_NULL(sources, false);
     175
     176    int numSources = sources->n;          // Number of stars
     177    psVector *x = psVectorAllocEmpty(numSources, PS_TYPE_F32);
     178    psVector *y = psVectorAllocEmpty(numSources, PS_TYPE_F32);
     179    psVector *mag = psVectorAllocEmpty(numSources, PS_TYPE_F32);
     180
     181    int numGood = 0;                    // Number of good sources
     182    for (int i = 0; i < numSources; i++) {
     183        pmSource *source = sources->data[i]; // Source of interest
     184        if (!source) {
     185            continue;
     186        }
     187        if (source->mode & SOURCE_MASK) {
     188            continue;
     189        }
     190        if (!isfinite(source->psfMag)) {
     191            continue;
     192        }
     193        float xSrc, ySrc;                     // Coordinates of source
     194        if (source->modelPSF) {
     195            xSrc = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     196            ySrc = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     197        } else {
     198            xSrc = source->peak->xf;
     199            ySrc = source->peak->yf;
     200        }
     201
     202        x->data.F32[numGood] = xSrc;
     203        y->data.F32[numGood] = ySrc;
     204        mag->data.F32[numGood] = source->psfMag;
     205        numGood++;
     206    }
     207    x->n = numGood;
     208    y->n = numGood;
     209    mag->n = numGood;
     210
     211    bool status = pmReadoutFakeFromVectors(readout, numCols, numRows, x, y, mag, xOffset, yOffset, psf,
     212                                           minFlux, radius, circularise, normalisePeak);
     213    psFree(x);
     214    psFree(y);
     215    psFree(mag);
     216
     217    return status;
     218}
  • branches/pap/psModules/src/camera/pmReadoutFake.h

    r20999 r25028  
    1212#include <pmPSF.h>
    1313
     14/// Generate a fake readout from vectors of position and magnitude
     15bool pmReadoutFakeFromVectors(
     16    pmReadout *readout,                   ///< Output readout, or NULL
     17    int numCols, int numRows,             ///< Dimension of image
     18    const psVector *x, const psVector *y, ///< Coordinates of sources
     19    const psVector *mag,                  ///< Magnitudes of sources
     20    const psVector *xOffset,              ///< x offsets for sources (source -> img), or NULL
     21    const psVector *yOffset,              ///< y offsets for sources (source -> img), or NULL
     22    const pmPSF *psf,                     ///< PSF for sources
     23    float minFlux,                        ///< Minimum flux to bother about; for setting source radius
     24    int radius,                           ///< Fixed radius for sources
     25    bool circularise,                     ///< Circularise PSF model?
     26    bool normalise                        ///< Normalise the peak value?
     27    );
     28
     29
    1430/// Generate a fake readout from an array of sources
    15 bool pmReadoutFakeFromSources(pmReadout *readout, ///< Output readout, or NULL
    16                               int numCols, int numRows, ///< Dimension of image
    17                               const psArray *sources, ///< Array of pmSource
    18                               const psVector *xOffset, ///< x offsets for sources (source -> img), or NULL
    19                               const psVector *yOffset, ///< y offsets for sources (source -> img), or NULL
    20                               const pmPSF *psf, ///< PSF for sources
    21                               float minFlux, ///< Minimum flux to bother about; for setting source radius
    22                               int radius, ///< Fixed radius for sources
    23                               bool circularise, ///< Circularise PSF model?
    24                               bool normalise ///< Normalise the peak value?
     31bool pmReadoutFakeFromSources(
     32    pmReadout *readout,                 ///< Output readout, or NULL
     33    int numCols, int numRows,           ///< Dimension of image
     34    const psArray *sources,             ///< Array of pmSource
     35    const psVector *xOffset,            ///< x offsets for sources (source -> img), or NULL
     36    const psVector *yOffset,            ///< y offsets for sources (source -> img), or NULL
     37    const pmPSF *psf,                   ///< PSF for sources
     38    float minFlux,                      ///< Minimum flux to bother about; for setting source radius
     39    int radius,                         ///< Fixed radius for sources
     40    bool circularise,                   ///< Circularise PSF model?
     41    bool normalise                      ///< Normalise the peak value?
    2542    );
    2643
Note: See TracChangeset for help on using the changeset viewer.