IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 13, 2009, 1:23:29 PM (17 years ago)
Author:
Paul Price
Message:

Working on fake sources in psphot. Still not done. Being put on back burner for now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap/psphot/src/psphotFake.c

    r25025 r25062  
    99
    1010
    11 // Calculate the limiting flux for an image
     11// Calculate the limiting magnitude for an image
    1212//
    1313// We limit ourselves to calculating the peak flux in the smoothed image, which should be close (modulo
     
    6262    }
    6363
    64     return thresh * sqrtf(meanVar * factor); // Limiting peak flux in smoothed image
     64    return -2.5 * log10(thresh * sqrtf(meanVar * factor));
    6565}
     66
     67static bool fakeGenerate(psImage **xSrc, psImage **ySrc, // Positions of sources
     68                         const pmReadout *ro,            // Readout of interest
     69                         const psMetadata *recipe, // psphot recipe
     70                         float refMag              // Reference magnitude
     71                         )
     72{
     73    PM_ASSERT_READOUT_NON_NULL(ro, NULL);
     74    PM_ASSERT_READOUT_IMAGE(ro, NULL);
     75    PS_ASSERT_METADATA_NON_NULL(recipe, NULL);
     76
     77    psMetadata *fake = psMetadataLookupMetadata(NULL, recipe, "FAKE"); // Fake information
     78    if (!fake) {
     79        psError(PSPHOT_ERR_CONFIG, false, "Unable to find FAKE information in recipe");
     80        return NULL;
     81    }
     82
     83    psVector *magOffsets = psMetadataLookupVector(NULL, recipe, "FAKE.MAG"); // Magnitude offsets
     84    if (!magOffset || magOffset->type.type != PS_TYPE_F32) {
     85        psError(PSPHOT_ERR_CONFIG, false, "Unable to find FAKE.MAG F32 vector in recipe");
     86        return NULL;
     87    }
     88    int numBins = magOffset->n;                                     // Number of bins
     89    int numSources = psMetadataLookupS32(NULL, recipe, "FAKE.NUM"); // Number of sources for each bin
     90
     91    int numCols = ro->image->numCols, numRows = ro->image->numRows; // Size of image
     92
     93
     94
     95    *xSrc = psImageRecycle(*xSrc, numSources, numBins, PS_TYPE_F32);
     96    *ySrc = psImageRecycle(*ySrc, numSources, numBins, PS_TYPE_F32);
     97
     98    // Master list, for image creation
     99    psVector *xAll = psVectorAlloc(numBins * numSources, PS_TYPE_F32);
     100    psVector *yAll = psVectorAlloc(numBins * numSources, PS_TYPE_F32);
     101    psVector *magAll = psVectorAlloc(numBins * numSources, PS_TYPE_F32);
     102
     103    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
     104    for (int i = 0; i <= numBins; i++) {
     105        psArray *data = psArrayAlloc(3); // Sources for bin
     106
     107        psVector *x = psVectorAlloc(numSources, PS_TYPE_F32);
     108        psVector *y = psVectorAlloc(numSources, PS_TYPE_F32);
     109
     110        float mag = refMag + magOffset->data.F32[i]; // Instrumental magnitude of sources
     111
     112        for (int j = 0; j <= numSources; j++) {
     113            x->data.F32[j] = psRandomUniform(rng) * numCols;
     114            y->data.F32[j] = psRandomUniform(rng) * numRows;
     115            magAll->data.F32[i * numSources + j] = mag;
     116        }
     117        memcpy(xSrc->data.F32[i], x->data.F32, numSources * PSELEMTYPE_SIZEOF(PS_TYPE_F32));
     118        memcpy(ySrc->data.F32[i], y->data.F32, numSources * PSELEMTYPE_SIZEOF(PS_TYPE_F32));
     119        memcpy(&xAll->data.F32[i * numSources], x->data.F32, numSources * PSELEMTYPE_SIZEOF(PS_TYPE_F32));
     120        memcpy(&yAll->data.F32[i * numSources], y->data.F32, numSources * PSELEMTYPE_SIZEOF(PS_TYPE_F32));
     121    }
     122    psFree(rng);
     123
     124    pmReadout *fakeRO = pmReadoutAlloc(); // Fake readout
     125    pmReadoutFakeFromVectors(fakeRO, xAll, yAll, mag,
     126
    66127
    67128
     
    80141
    81142    // Generate array of fake sources and define the pixels with pmSourceDefinePixels
    82     psArray *fakeOrig = psphotFakeGenerate(config, readout, recipe);
     143    psArray *fakeOrig = fakeGenerate(config, readout, recipe);
    83144
    84145    psArray *fakeMeasured = psArrayAlloc(fakeOrig->n); // Measured values for the sources in fakeOrig
Note: See TracChangeset for help on using the changeset viewer.