IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 8, 2008, 4:03:31 PM (18 years ago)
Author:
eugene
Message:

update from changes on eam_branch_20080511 : adding photometry of fake sources, force photometry; major cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimMakeSky.c

    r17557 r18011  
    11# include "ppSim.h"
    22
    3 // XXX add bounds to the inputs?
     3// this function sets the skyRate to a value for the night sky (SKY.RATE or SKY.MAGS) or for a
     4// flat-field image (FLAT.RATE).  Include a shutter correction and a scattered light source
     5
    46bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config) {
    57
     
    1517    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    1618
    17     float expTime     = psMetadataLookupF32(&status, recipe, "EXPTIME"); // Exposure time
    18     float flatSigma   = psMetadataLookupF32(&status, recipe, "FLAT.SIGMA"); // Flat-field coefficient
    19     float flatRate    = psMetadataLookupF32(&status, recipe, "FLAT.RATE"); // Flat-field rate
    20     float shutterTime = psMetadataLookupF32(&status, recipe, "SHUTTER.TIME"); // Shutter time
    21     float skyRate     = psMetadataLookupF32(&status, recipe, "SKY.RATE"); // Sky rate
    22     if (isnan(skyRate)) {
    23         float zp      = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); assert (status);
    24         float scale   = psMetadataLookupF32(&status, recipe, "SCALE");     assert (status);
    25         float skyMags = psMetadataLookupF32(&status, recipe, "SKY.MAGS");  assert (status);
     19    bool sky  = psMetadataLookupBool(&status, recipe, "SKY"); // Generate a SKY flux?
     20    bool flat = psMetadataLookupBool(&status, recipe, "FLAT"); // Apply flat-field term?
     21 
     22    float expTime      = psMetadataLookupF32(&status, recipe, "EXPTIME"); // Exposure time
     23
     24    float flatSigma    = psMetadataLookupF32(&status, recipe, "FLAT.SIGMA"); // Flat-field coefficient
     25    float flatRate     = psMetadataLookupF32(&status, recipe, "FLAT.RATE"); // Flat-field rate
     26    float shutterTime  = psMetadataLookupF32(&status, recipe, "SHUTTER.TIME"); // Shutter time
     27    float scatterFrac  = psMetadataLookupF32(&status, recipe, "SCATTER.FRAC"); // scattered light fraction (max)
     28    float skyRate      = psMetadataLookupF32(&status, recipe, "SKY.RATE"); // Sky rate
     29    float skyMags      = psMetadataLookupF32(&status, recipe, "SKY.MAGS");  assert (status);
     30    if (!isnan(skyMags)) {
     31        float zp       = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); assert (status);
     32        float scale    = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE"); assert (status);
    2633        skyRate = scale * scale * ppSimMagToFlux (skyMags, zp);
     34    }
     35    if (type == PPSIM_TYPE_FLAT) {
     36      skyRate = flatRate;
    2737    }
    2838
     
    3747    int yParityCell   = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY");
    3848
    39     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
     49    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
    4050
    4151    // Size of FPA
    4252    psRegion *bounds = ppSimFPABounds (fpa);
     53    int dXfpa = bounds->x1 - bounds->x0;
     54    int dYfpa = bounds->y1 - bounds->y0;
    4355
    4456    // Correct chip offsets so that boresight is in the middle of the FPA
    45     x0Chip -= 0.5 * (bounds->x1 - bounds->x0);
    46     y0Chip -= 0.5 * (bounds->y1 - bounds->y0);
     57    x0Chip -= 0.5 * dXfpa;
     58    y0Chip -= 0.5 * dYfpa;
    4759
    4860    for (int y = 0; y < signal->numRows; y++) {
     
    5870            float realExpTime = expTime + shutterTime * (xFPA + yFPA + 2.0) / 4.0;
    5971
    60             // Gaussian flat-field over the FPA
    61             float flatValue = expf(-0.5 / PS_SQR(flatSigma) * (PS_SQR(yFPA) + PS_SQR(xFPA))) /
    62                 flatSigma / sqrtf(2.0 * M_PI);
     72            // Gaussian flat-field over the FPA with flatValue = 1.0 at the field center
     73            float flatValue = 1.0;
     74            if (flat) {
     75                // we make the flat-field have a response of 1.0 at the field center (like a vignetting)
     76                flatValue = expf(-0.5 / PS_SQR(flatSigma) * (PS_SQR(yFPA) + PS_SQR(xFPA)));
     77            }
    6378
    64             if (type == PPSIM_TYPE_FLAT) {
    65                 float flatFlux = flatRate * flatValue * realExpTime; // Flux from flat-field
    66                 signal->data.F32[y][x] += flatFlux;
    67                 variance->data.F32[y][x] += flatFlux;
    68                 continue;
    69             }
     79            float scatterRate = 0.0;
    7080
    71             expCorr->data.F32[y][x] = realExpTime / expTime;
     81            if (sky) {
     82              // add a scattered light term to the flat-field images (no
     83              if (type == PPSIM_TYPE_FLAT) {
     84                float xF = 2.0*(xFPA / dXfpa) - 1.0;
     85                scatterRate = scatterFrac * PS_SQR(xF);
     86              }
    7287
    73             // Sky background
    74             float skyFlux = skyRate * flatValue * realExpTime; // Flux from sky
    75             signal->data.F32[y][x] += skyFlux;
    76             variance->data.F32[y][x] += skyFlux;
     88              // Sky background
     89              float skyFlux = (skyRate * (flatValue + scatterRate)) * realExpTime; // Flux from sky
     90              signal->data.F32[y][x] += skyFlux;
     91              variance->data.F32[y][x] += skyFlux;
     92            }
     93
     94            // used later to modify the star and galaxy photometry
     95            if (expCorr) {
     96              expCorr->data.F32[y][x] = realExpTime / expTime;
     97            }
    7798
    7899            // TO DO: Add fringes
Note: See TracChangeset for help on using the changeset viewer.