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/ppSimLoop.c

    r15482 r18011  
    11#include "ppSim.h"
     2
     3# define ESCAPE(CODE,MSG) { \
     4  psError(CODE, false, MSG); \
     5  psFree (rng); \
     6  return false; }
    27
    38bool ppSimLoop(pmConfig *config)
    49{
     10    bool status;
     11
     12    // XXX if we are supplying a PSF, then we should use that to specify the seeing.
     13    // we will need to force the psf to be loaded here (deactivate everyone, activate psf, load
     14    // it, then calculate seeing as appropriate).
     15
    516    PS_ASSERT_PTR_NON_NULL(config, PS_EXIT_PROG_ERROR);
    617
    7     pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, OUTPUT_FILE); // Output file
     18    // in this program, we are looping over the output image, rather than the input as in ppImage
     19    pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); // Output file
    820    assert(file);
     21
    922    pmFPA *fpa = file->fpa;             // FPA for file
    1023    assert(fpa);
    1124
    12     ppSimType type = psMetadataLookupS32(NULL, config->arguments, "TYPE"); // Type of image to simulate
     25    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
    1326
    1427    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
    1528
    16     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
    17 
    18     // Load catalogue stars
     29    char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate
     30    ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate
     31    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
     32
    1933    psArray *stars = psArrayAllocEmpty (1);
    20     if (type == PPSIM_TYPE_OBJECT) {
    21         ppSimLoadStars (stars, fpa, config);
    22     }
    23 
    24     // Add random stars
    25     if (type == PPSIM_TYPE_OBJECT) {
    26         ppSimMakeStars (stars, fpa, config, rng);
    27     }
    28 
    29     // Add random galaxies
    3034    psArray *galaxies = psArrayAllocEmpty (1);
    3135    if (type == PPSIM_TYPE_OBJECT) {
    32         ppSimMakeGalaxies (galaxies, fpa, config, rng);
     36        // Load forced-photometry positions (these are placed on fpa->analysis for use in ppSimPhotomReadout)
     37        if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots");
     38
     39        // Load catalogue stars
     40        if (!ppSimLoadStars (stars, fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load catalog stars");
     41
     42        // Add random stars
     43        if (!ppSimMakeStars (stars, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random stars");
     44
     45        // Add random galaxies
     46        if (!ppSimMakeGalaxies (galaxies, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random galaxies");
    3347    }
    3448
     
    4660
    4761    ppSimUpdateConceptsFPA (fpa, config);
     62    if (fpa->hdu) { // XXX only do this if there is no INPUT image
     63        if (!ppSimInitHeader(config, fpa, NULL, NULL)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header");
     64    }
    4865
    4966    pmChip *chip;                       // Chip from FPA
     
    98115            psVector *biasCols = ppSimMakeBiassec (cell, config);
    99116
    100             for (int i = 0; i < cell->readouts->n; i++) {
    101 
    102                 pmReadout *readout = cell->readouts->data[i];
    103                 assert (readout);
     117            pmReadout *readout;
     118            while ((readout = pmFPAviewNextReadout (view, fpa, 1))) {
    104119
    105120                // if we have not read in a weight or generated a fake image above, we need to
     
    117132                }
    118133
    119                 psVector *biasRows = ppSimMakeBias (readout, config, rng);
     134                psVector *biasRows = ppSimMakeBias (&status, readout, config, rng);
     135                if (!status) ESCAPE (PS_ERR_UNKNOWN, "problem generating dark structure");
    120136                if (type == PPSIM_TYPE_BIAS) goto done;
    121137
    122                 ppSimMakeDark (readout, config);
     138                if (!ppSimMakeDark (readout, config)) ESCAPE (PS_ERR_UNKNOWN, "problem generating dark structure");
    123139                if (type == PPSIM_TYPE_DARK) goto done;
    124140
    125                 ppSimMakeSky (readout, expCorr, type, config);
     141                if (!ppSimMakeSky (readout, expCorr, type, config)) ESCAPE (PS_ERR_UNKNOWN, "problem generating sky background");
    126142                if (type == PPSIM_TYPE_FLAT) goto done;
    127143
    128144                if (type == PPSIM_TYPE_OBJECT) {
    129                     ppSimInsertStars (readout, expCorr, stars, config);
     145                    if (!ppSimInsertStars (readout, expCorr, stars, config)) ESCAPE (PS_ERR_UNKNOWN, "problem inserting stars");
    130146                }
    131147
    132148                if (type == PPSIM_TYPE_OBJECT) {
    133                     ppSimInsertGalaxies (readout, expCorr, galaxies, config);
     149                    if (!ppSimInsertGalaxies (readout, expCorr, galaxies, config)) ESCAPE (PS_ERR_UNKNOWN, "problem inserting galaxies");
    134150                }
    135151
     
    137153
    138154            done:
    139                 ppSimAddNoise(readout->image, readout->weight, cell, config, rng);
    140                 ppSimSaturate(readout, config);
    141 
    142                 ppSimBadPixels(readout, config, rng);
    143 
    144                 ppSimAddOverscan (readout, config, biasCols, biasRows, rng);
     155                if (!ppSimAddNoise(readout->image, readout->weight, cell, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding noise");
     156                if (!ppSimSaturate(readout, config)) ESCAPE (PS_ERR_UNKNOWN, "problem setting saturation levels");
     157
     158                if (!ppSimBadPixels(readout, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding bad pixels");
     159
     160                if (!ppSimAddOverscan (readout, config, biasCols, biasRows, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding overscan region");
    145161                psFree(biasRows);
    146162
     
    148164                readout->parent->data_exists = true;
    149165                readout->parent->parent->data_exists = true;
     166
     167                // if there is an input image, merge it with the simulated image
     168                if (!ppSimMergeReadouts (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem merging input image with simulated image");
    150169            }
    151170            psFree(biasCols);
    152171
    153             ppSimUpdateConceptsCell (cell, config);
     172            if (!ppSimUpdateConceptsCell (cell, config)) ESCAPE (PS_ERR_UNKNOWN, "problem updating cell concepts");
    154173
    155174            if (cell->hdu) {
    156                 ppSimInitHeader(config, NULL, NULL, cell);
     175                // XXX only do this if there is no INPUT image?
     176                if (!ppSimInitHeader(config, NULL, NULL, cell)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header");
    157177            }
    158178
     
    166186        }
    167187
     188        // XXX why no UpdateConceptsChip??
     189
    168190        if (chip->hdu) {
    169             ppSimInitHeader(config, NULL, chip, NULL);
    170         }
     191            // XXX only do this if there is no INPUT image
     192            if (!ppSimInitHeader(config, NULL, chip, NULL)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header");
     193        }
     194
     195        // we perform photometry on the readouts of this chip in the output
     196        if (!ppSimPhotom (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem performing photometry");
    171197
    172198        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     
    174200            psFree(rng);
    175201            psFree(view);
    176             // return PS_EXIT_SYS_ERROR;
    177202            return false;
    178203        }
    179 
    180204    }
    181205
    182206    psFree(stars);
    183207    psFree(galaxies);
    184 
    185     if (fpa->hdu) {
    186         ppSimInitHeader(config, fpa, NULL, NULL);
    187     }
    188208
    189209    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     
    191211        psFree(rng);
    192212        psFree(view);
    193         // return PS_EXIT_SYS_ERROR;
    194213        return false;
    195214    }
Note: See TracChangeset for help on using the changeset viewer.