IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17818


Ignore:
Timestamp:
May 27, 2008, 7:12:46 PM (18 years ago)
Author:
eugene
Message:

working on the photometry of fake sources

Location:
branches/eam_branch_20080511/ppSim
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080511/ppSim/notes.txt

    r17709 r17818  
     1
     2
     32008.05.17
     4
     5  pmFPAfiles used in ppSim:
     6
     7  PPSIM.INPUT : an input image loaded by ppSim; the simulated features
     8                may be added to this image.  In fact, the features are
     9                generated in the output image, and the two images are
     10                added (as images) together.
     11
     12  PPSIM.OUTPUT  : the output image.  this file is used for the main
     13                  ppSimLoop function
     14
     15  PPSIM.CHIP    : chip-mosaiced version of the output image.  only
     16                  generated if photometry is requested.  Is this
     17                  actually used as an output image?
     18
     19  PPSIM.REAL.SOURCES : real sources loaded by PPSIM.  these sources
     20                       are subtracted from the image before testing
     21                       for the detectability of the fake sources and
     22                       before measuring the flux of fake or forced
     23                       soures.  They should be the sources measured in
     24                       a previous psphot run, though any input list
     25                       could be used.  Results are very ill-defined if
     26                       the sources do not correspond to actual image
     27                       sources!
     28
     29  PSPHOT.PSF.LOAD : input PSF model used to measure the input sources
     30
     31  PPSIM.SOURCES : output fake sources (injected fake sources with real values)
     32  PPSIM.FAKE.SOURCES : output fake photometry (measured photometry for all fake sources)
     33  PPSIM.FORCE.SOURCES : output force photometry
     34 
     35  ** used within psphot functions:
     36  PSPHOT.BACKMDL : model background generated by psphotModelBackground
     37  PSPHOT.BACKMDL.STDEV : model background error generated by psphotModelBackground
     38  PSPHOT.BACKGND : full-scale model background generated by psphotSubtractBackground
     39  PSPHOT.BACKSUB : background-subtracted image
    140
    2412008.05.15
  • branches/eam_branch_20080511/ppSim/src/Makefile.am

    r17705 r17818  
    2626        ppSimLoadSpots.c        \
    2727        ppSimPhotom.c           \
     28        ppSimPhotomReadout.c    \
     29        ppSimPhotomFiles.c      \
     30        ppSimLoadForceSources.c \
    2831        ppSimMergeReadouts.c    \
     32        ppSimDetections.c       \
     33        ppSimMergeSources.c     \
    2934        ppSimMosaicChip.c       \
    3035        ppSimRandomGaussian.c   \
  • branches/eam_branch_20080511/ppSim/src/ppSim.h

    r17705 r17818  
    1616
    1717#define PPSIM_RECIPE "PPSIM"
    18 #define OUTPUT_FILE "PPSIM.OUTPUT"
     18// #define OUTPUT_FILE "PPSIM.OUTPUT"
    1919
    2020// Compare a value with minimum and maximum values, replacing where required.
     
    174174float ppSimGetZeroPoint (psMetadata *recipe, char *filter);
    175175
    176 bool ppSimMergeReadouts (pmReadout *outReadout, pmReadout *inReadout);
     176bool ppSimMergeReadouts (pmConfig *config, pmFPAview *view);
    177177
    178178double ppSimRandomGaussian (const psRandom *rnd, double mean, double sigma);
     
    180180void ppSimRandomGaussianFree();
    181181
     182bool ppSimPhotomFiles (pmConfig *config, pmFPAfile *input);
     183bool ppSimPhotomReadout(pmConfig *config, const pmFPAview *view);
     184psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view);
     185bool ppSimDetections (psImage *significance, psMetadata *recipe, psArray *sources);
     186psArray *ppSimMergeSources (psArray *in1, psArray *in2);
     187
    182188#endif
  • branches/eam_branch_20080511/ppSim/src/ppSimCreate.c

    r17706 r17818  
    33pmFPAfile *ppSimCreate(pmConfig *config)
    44{
    5     bool status;
    6     bool simImage = false;
    7     PS_ASSERT_PTR_NON_NULL(config, NULL);
    8     pmFPA *fpa = NULL;
     5  bool status;
     6  bool simImage = false;
     7  PS_ASSERT_PTR_NON_NULL(config, NULL);
     8  pmFPA *fpa = NULL;
    99
    10     // the input image defines the camera.  if it is not supplied, the user must have
    11     // supplied a camera and other metadata on the command line
    12     pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT");
    13     if (!input) {
    14         // if we have not specified the camera already, we need to interpolate the recipes associated with this camera, and read other command-line recipes
    15         if (!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) {
    16             psError(PS_ERR_IO, false, "Error merging recipes from camera config for %s", config->cameraName);
    17             return NULL;
    18         }
    19     } else {
    20       // If an image is supplied, we still generate a fake image and merge them together downstream
    21       // (otherwise, we get the variance wrong).
    22         simImage = false;
    23         if (input->type != PM_FPA_FILE_IMAGE) {
    24             psError(PS_ERR_IO, true, "PPIMAGE.INPUT is not of type IMAGE");
    25             return NULL;
    26         }
     10  // the input image defines the camera.  if it is not supplied, the user must have
     11  // supplied a camera and other metadata on the command line
     12  pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPSIM.INPUT", "INPUT");
     13  if (!input) {
     14    // if we have not specified the camera already, we need to interpolate the recipes associated with this camera, and read other command-line recipes
     15    if (!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) {
     16      psError(PS_ERR_IO, false, "Error merging recipes from camera config for %s", config->cameraName);
     17      return NULL;
    2718    }
     19  } else {
     20    // If an image is supplied, we still generate a fake image and merge them together downstream
     21    // (otherwise, we get the variance wrong).
     22    simImage = false;
     23    if (input->type != PM_FPA_FILE_IMAGE) {
     24      psError(PS_ERR_IO, true, "PPSIM.INPUT is not of type IMAGE");
     25      return NULL;
     26    }
     27  }
    2828
    29     // generate the fpa structure used by the output camera (determined from INPUT or specified)
    30     assert (config->camera);
    31     fpa = pmFPAConstruct(config->camera); // FPA to contain the observation
    32     if (!fpa) {
    33       psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
     29  // generate the fpa structure used by the output camera (determined from INPUT or specified)
     30  assert (config->camera);
     31  fpa = pmFPAConstruct(config->camera); // FPA to contain the observation
     32  if (!fpa) {
     33    psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
     34    return NULL;
     35  }
     36
     37  // define the output image file -- this is the basis for the ppSimLoop
     38  pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, "PPSIM.OUTPUT");
     39  if (!output) {
     40    psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from PPSIM.OUTPUT. Did you forget to specify the format?");
     41    return NULL;
     42  }
     43  if (output->type != PM_FPA_FILE_IMAGE) {
     44    psError(PS_ERR_BAD_PARAMETER_TYPE, true, "PPSIM.OUTPUT type is not IMAGE");
     45    psFree(fpa);
     46    return NULL;
     47  }
     48  // XXX we should not require the output image to be written
     49  output->save = true;
     50
     51  config->format = psMemIncrRefCounter (output->format);
     52  config->formatName = psStringCopy (output->formatName);
     53
     54  // the recipe is now fully realized for the desired camera
     55  psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     56
     57  char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate
     58  ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate
     59
     60  if (type == PPSIM_TYPE_OBJECT) {
     61    // adjust the seeing by the scale
     62    float seeing = psMetadataLookupF32(&status, recipe, "SEEING");
     63    if (isnan(seeing)) {
     64      psError(PS_ERR_BAD_PARAMETER_TYPE, true, "seeing is not defined");
     65      psFree(fpa);
     66      return NULL;
     67    }
     68    float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE");
     69    if (isnan(scale)) {
     70      psError(PS_ERR_BAD_PARAMETER_TYPE, true, "pixel scale is not defined");
     71      psFree(fpa);
     72      return NULL;
     73    }
     74    psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
     75  }
     76
     77  if ((type == PPSIM_TYPE_OBJECT) || (type == PPSIM_TYPE_FLAT)) {
     78    // determine the zeropoint from the filter
     79    float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT");
     80    if (isnan(zp)) {
     81      char *filter = psMetadataLookupStr(&status, recipe, "FILTER");
     82      float zp = ppSimGetZeroPoint (recipe, filter);
     83      psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     84    }
     85  }
     86
     87  // For photometry, we operate on the chip-mosaicked image.  we create a copy of the mosaicked
     88  // image for psphot so we can write out a clean image
     89  bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes
     90  if (doPhotom) {
     91
     92    // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
     93    pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.CHIP");
     94    if (!chipImage) {
     95      psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.CHIP"));
     96      psFree(fpa);
     97      return NULL;
     98    }
     99    if (chipImage->type != PM_FPA_FILE_IMAGE) {
     100      psError(PS_ERR_IO, true, "PPSIM.CHIP is not of type IMAGE");
     101      psFree(fpa);
    34102      return NULL;
    35103    }
    36104
    37     // define the output image file -- this is the basis for the ppSimLoop
    38     pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);
    39     if (!output) {
    40         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s.  "
    41                 "Did you forget to specify the format?", OUTPUT_FILE);
    42         return NULL;
     105    // define associated psphot input/output files
     106    if (!ppSimPhotomFiles (config, chipImage)) {
     107      psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
     108      psFree(fpa);
     109      return NULL;
    43110    }
    44     if (output->type != PM_FPA_FILE_IMAGE) {
    45         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE);
     111  } else {
     112    // have we supplied a psf model?  this happens in ppSimPhotomFiles if we request a photometry
     113    // analysis.  however, even if we do not, a psf model may be used to generate the fake
     114    // sources.
     115    if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
     116      // tie the psf file to the chipMosaic
     117      pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
     118      if (!status) {
     119        psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
    46120        psFree(fpa);
    47         return NULL;
     121        return NULL;
     122      }
    48123    }
    49     // XXX we should not require the output image to be written
    50     output->save = true;
     124  }
    51125
    52     config->format = psMemIncrRefCounter (output->format);
    53     config->formatName = psStringCopy (output->formatName);
     126  // PPSIM.SOURCES carries the constructed, fake sources with their true parameters
     127  // XXX only invoke this code for OBJECT types of images?
     128  pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES");
     129  if (!simSources) {
     130    psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
     131    return false;
     132  }
     133  simSources->save = true;
    54134
    55     // the recipe is now fully realized for the desired camera
     135  // if we have loaded an input image, we derive certain values from the image, if possible
     136  if (input) {
     137    // we need to extract certain metadata from the image and populate the recipe.
     138    // or else we need to set the fpa concepts based on the recipe options...
     139
    56140    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    57141
    58     char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate
    59     ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate
     142    ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE");
     143    char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTER");
    60144
    61     if (type == PPSIM_TYPE_OBJECT) {
    62         // adjust the seeing by the scale
    63         float seeing = psMetadataLookupF32(&status, recipe, "SEEING");
    64         if (isnan(seeing)) {
    65             psError(PS_ERR_BAD_PARAMETER_TYPE, true, "seeing is not defined");
    66             psFree(fpa);
    67             return NULL;
    68         }
    69         float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE");
    70         if (isnan(scale)) {
    71             psError(PS_ERR_BAD_PARAMETER_TYPE, true, "pixel scale is not defined");
    72             psFree(fpa);
    73             return NULL;
    74         }
    75         psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
     145    float zp = ppSimGetZeroPoint (recipe, filter);
     146    psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     147  }
     148
     149  pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes
     150
     151  pmFPAview *view = pmFPAviewAlloc(0);// View for current level
     152
     153  if (phuLevel == PM_FPA_LEVEL_FPA) {
     154    if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     155      psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     156      psFree(fpa);
     157      psFree(view);
     158      return NULL;
     159    }
     160  }
     161
     162  pmChip *chip;                       // Chip from FPA
     163  while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
     164    if (phuLevel == PM_FPA_LEVEL_CHIP) {
     165      if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     166        psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     167        psFree(fpa);
     168        psFree(view);
     169        return NULL;
     170      }
    76171    }
    77172
    78     if ((type == PPSIM_TYPE_OBJECT) || (type == PPSIM_TYPE_FLAT)) {
    79         // determine the zeropoint from the filter
    80         float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT");
    81         if (isnan(zp)) {
    82             char *filter = psMetadataLookupStr(&status, recipe, "FILTER");
    83             float zp = ppSimGetZeroPoint (recipe, filter);
    84             psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     173    pmCell *cell;                   // Cell from chip
     174    while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
     175      if (phuLevel == PM_FPA_LEVEL_CELL) {
     176        if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     177          psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     178          psFree(fpa);
     179          psFree(view);
     180          return NULL;
    85181        }
     182      }
    86183    }
     184  }
    87185
    88     // For photometry, we operate on the chip-mosaicked image.  we create a copy of the mosaicked
    89     // image for psphot so we can write out a clean image
    90     bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes
    91     if (doPhotom) {
     186  psFree(fpa);
     187  psFree(view);
    92188
    93         // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
    94         pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.CHIP");
    95         if (!chipImage) {
    96             psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.CHIP"));
    97             psFree(fpa);
    98             return NULL;
    99         }
    100         if (chipImage->type != PM_FPA_FILE_IMAGE) {
    101             psError(PS_ERR_IO, true, "PPSIM.CHIP is not of type IMAGE");
    102             psFree(fpa);
    103             return NULL;
    104         }
    105 
    106         // *** Define two input files:
    107         // PPSIM.REAL.SOURCES
    108 
    109         // the input image(s) are required arguments; they define the camera
    110         pmFPAfile *realSources = pmFPAfileDefineFromArgs (&status, config, "PPSIM.REAL.SOURCES", "REAL.SOURCES");
    111         if (!status) {
    112           psError(PS_ERR_UNKNOWN, false, "Failed to build FPA from PPSIM.REAL.SOURCES");
    113           return false;
    114         }
    115 
    116         // this file is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by
    117         // psphotDefineFiles
    118         pmFPAfile *psphotInput = pmFPAfileDefineFromFile (config, chipImage, 1, 1, "PSPHOT.INPUT");
    119         PS_ASSERT (psphotInput, false);
    120 
    121         // define associated psphot input/output files
    122         if (!psphotDefineFiles (config, psphotInput)) {
    123             psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
    124             psFree(fpa);
    125             return NULL;
    126         }
    127     } else {
    128         // have we supplied a psf model?  this happens in psphotDefineFiles if we request a photometry
    129         // analysis.  however, even if we do not, a psf model may be used to generate the fake
    130         // sources.
    131         if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
    132             // tie the psf file to the chipMosaic
    133             pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
    134             if (!status) {
    135                 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
    136                 psFree(fpa);
    137                 return NULL;
    138             }
    139         }
    140     }
    141 
    142     // PPSIM.SOURCES carries the constructed, fake sources with their true parameters
    143     // XXX only invoke this code for OBJECT types of images?
    144     pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES");
    145     if (!simSources) {
    146         psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
    147         return false;
    148     }
    149     simSources->save = true;
    150 
    151     // if we have loaded an input image, we derive certain values from the image, if possible
    152     if (input) {
    153         // we need to extract certain metadata from the image and populate the recipe.
    154         // or else we need to set the fpa concepts based on the recipe options...
    155 
    156         psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    157 
    158         ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE");
    159         char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTER");
    160 
    161         float zp = ppSimGetZeroPoint (recipe, filter);
    162         psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
    163     }
    164 
    165     pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes
    166 
    167     pmFPAview *view = pmFPAviewAlloc(0);// View for current level
    168 
    169     if (phuLevel == PM_FPA_LEVEL_FPA) {
    170         if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    171             psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    172             psFree(fpa);
    173             psFree(view);
    174             return NULL;
    175         }
    176     }
    177 
    178     pmChip *chip;                       // Chip from FPA
    179     while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    180         if (phuLevel == PM_FPA_LEVEL_CHIP) {
    181             if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    182                 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    183                 psFree(fpa);
    184                 psFree(view);
    185                 return NULL;
    186             }
    187         }
    188 
    189         pmCell *cell;                   // Cell from chip
    190         while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    191             if (phuLevel == PM_FPA_LEVEL_CELL) {
    192                 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    193                     psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    194                     psFree(fpa);
    195                     psFree(view);
    196                     return NULL;
    197                 }
    198             }
    199         }
    200     }
    201 
    202     psFree(fpa);
    203     psFree(view);
    204 
    205     return output;
     189  return output;
    206190}
  • branches/eam_branch_20080511/ppSim/src/ppSimInsertStars.c

    r17705 r17818  
    1515
    1616    if (!stars->n) { return true; }
    17 
    18     // XXX is this needed?
    19     // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources
    2017
    2118    pmCell *cell = readout->parent;
     
    136133
    137134    // NOTE: readout must be part of the pmFPAfile named "PPSIM.OUTPUT"
    138     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources);
     135    // XXX PPSIM.SOURCES are the fake sources with their *input* values
     136    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.SOURCES", PS_DATA_ARRAY, "fake sources", sources);
    139137    psFree(sources);
    140138
  • branches/eam_branch_20080511/ppSim/src/ppSimLoadForceSources.c

    r17709 r17818  
     1# include "ppSim.h"
     2
     3psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view) {
     4
     5# if (0)
     6
    17    // de-activate all files except PSASTRO.REFSTARS
    28    pmFPAfileActivate (config->files, false, NULL);
     
    7783    pmFPAfileActivate (config->files, true, NULL);
    7884    pmFPAfileActivate (config->files, false, "PSASTRO.OUT.REFSTARS");
     85# endif
     86
     87    return NULL;
     88}
  • branches/eam_branch_20080511/ppSim/src/ppSimLoop.c

    r17705 r17818  
    1313
    1414    // in this program, we are looping over the output image, rather than the input as in ppImage
    15     pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, OUTPUT_FILE); // Output file
     15    pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); // Output file
    1616    assert(file);
    17 
    18     // if we have an input image, we need to add the synthetic data on top of it below
    19     // XXX we may potentially use this input file to skip missing elements
    20     pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.INPUT");
    2117
    2218    pmFPA *fpa = file->fpa;             // FPA for file
     
    111107
    112108            psVector *biasCols = ppSimMakeBiassec (cell, config);
    113 
    114             pmCell *inputCell = NULL;
    115             if (input) {
    116                 inputCell = pmFPAviewThisCell (view, input->fpa);
    117             }
    118109
    119110            for (int i = 0; i < cell->readouts->n; i++) {
     
    169160                readout->parent->parent->data_exists = true;
    170161
    171                 if (inputCell && inputCell->readouts->data[i]) {
    172                     pmReadout *inReadout = inputCell->readouts->data[i];
    173                     if (!inReadout->weight) {
    174                         if (!pmReadoutGenerateWeight(inReadout, true)) {
    175                             psError (PS_ERR_UNKNOWN, false, "trouble creating weight");
    176                             return false;
    177                         }
    178                     }
    179                     if (!ppSimMergeReadouts (readout, inReadout)) ESCAPE (PS_ERR_UNKNOWN, "problem merging input image with simulated image");
    180                 }
     162                // if there is an input image, merge it with the simulated image
     163                if (!ppSimMergeReadouts (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem merging input image with simulated image");
    181164            }
    182165            psFree(biasCols);
  • branches/eam_branch_20080511/ppSim/src/ppSimMergeReadouts.c

    r17703 r17818  
    22
    33// XXX add bounds to the inputs?
    4 bool ppSimMergeReadouts (pmReadout *outReadout, pmReadout *inReadout) {
     4bool ppSimMergeReadouts (pmConfig *config, pmFPAview *view) {
    55
    66    // bool mdok;
     7
     8    // if we have an input image, we need to add the synthetic data on top of it below
     9    // XXX we may potentially use this input file to skip missing elements
     10    pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSIM.INPUT");
     11    if (!input) return true;
     12
     13    pmReadout *inReadout = pmFPAviewThisReadout (view, input->fpa);
     14    if (!inReadout) return true;
     15
     16    if (!inReadout->weight) {
     17      if (!pmReadoutGenerateWeight(inReadout, true)) {
     18        psError (PS_ERR_UNKNOWN, false, "trouble creating weight");
     19        return false;
     20      }
     21    }
     22
     23    // output must exist or we made a programming error
     24    pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); // Output file
     25    assert(output);
     26
     27    // XXX require outReadout?
     28    pmReadout *outReadout = pmFPAviewThisReadout (view, output->fpa);
     29    if (!outReadout) return true;
    730
    831    psImage *inSignal = inReadout->image;
     
    1235    psImage *outVariance = outReadout->weight;
    1336
    14     // psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
    1537    assert (inSignal->numRows == outSignal->numRows);
    1638    assert (inSignal->numCols == outSignal->numCols);
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotom.c

    r17708 r17818  
    1818    ppSimMosaicChip(config, blankMask, view, "PPSIM.CHIP", "PPSIM.OUTPUT");
    1919
    20     // find or define a pmFPAfile PSPHOT.INPUT
    21     pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
     20    // XXX have ppSimMosaicChip return the pointer?
     21    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPSIM.CHIP");
    2222    if (!status) {
    23         psError(PSPHOT_ERR_CONFIG, false, "PSPHOT.INPUT I/O file is not defined");
     23        psError(PSPHOT_ERR_CONFIG, false, "PPSIM.CHIP I/O file is not defined");
    2424        return false;
    2525    }
    2626
    2727    // we make a new copy of the output chip to keep psphot from modifying the output image
    28     // XXX is this needed for ppSim? (yes, unless we do not do photometry and make a simulated image)
     28    // XXX is this needed for ppSim? only if we want to write out the image with and without subtracted sources
    2929    pmChip *oldChip = pmFPAviewThisChip (view, input->src);
    3030    pmChip *newChip = pmFPAviewThisChip (view, input->fpa);
     
    4545                return false;
    4646            }
    47 
    4847            ppSimDetectionLimits (config, view);
    4948        }
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotomReadout.c

    r17709 r17818  
    1 # include "psphotInternal.h"
     1# include "ppSim.h"
    22
    3 bool psphotReadout(pmConfig *config, const pmFPAview *view) {
     3bool ppSimPhotomReadout(pmConfig *config, const pmFPAview *view) {
    44
    55    psTimerStart ("psphotReadout");
     
    1818    }
    1919
    20     // find the currently selected readout
    21     // XXX keep this name or go with something like PPSIM.PHOT.INPUT?
    22     pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");
     20    // find the currently selected readout.
     21    // we always perform photometry on the mosaiced chip
     22    pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PPSIM.CHIP");
    2323    PS_ASSERT_PTR_NON_NULL (readout, false);
    2424
     
    2727
    2828    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
     29    // this function uses PSPHOT.PSF.LOAD as the pmFPAfile
    2930    pmPSF *psf = psphotLoadPSF (config, view, recipe);
    3031    assert (psf);
     
    3334    // PPSIM.REAL.SOURCES carries the pmSource objects (from psphot analysis or loaded externally)
    3435    psArray *realSources = psMetadataLookupPtr (NULL, readout->analysis, "PPSIM.REAL.SOURCES");
    35     psArray *fakeSources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES");
    36     forceSources = ppSimLoadForceSources (config, view);
     36    psArray *forceSources = ppSimLoadForceSources (config, view);
    3737
    38     // replace all sources
    39     psphotRemoveSources (realSources, recipe);
     38    // XXX make a copy of the fake-source parameters so these can be saved independently
     39    // from the measured fake-source parameters
     40    psArray *injectedSources = psMetadataLookupPtr (NULL, readout->analysis, "PPSIM.SOURCES");
     41    psArray *fakeSources = psArrayAlloc (injectedSources->n);
     42    for (int i = 0; i < injectedSources->n; i++) {
     43      fakeSources->data[i] = pmSourceCopy (injectedSources->data[i]);
     44    }
     45
     46    // remove all sources
     47    psphotRemoveAllSources (realSources, recipe);
    4048
    4149    // generate a background model (median, smoothed image)
    42     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
     50    if (!psphotModelBackground (config, view, "PPSIM.CHIP")) {
    4351        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    4452    }
    45     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
     53    if (!psphotSubtractBackground (config, view, "PPSIM.CHIP")) {
    4654        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    4755    }
     
    5159
    5260    // XXX fake sources should measure peak->x,y, force sources should not
     61    psMaskType maskVal = 0xff;
    5362    psImage *significance = psphotSignificanceImage (readout, recipe, 1, maskVal);
    5463    ppSimDetections (significance, recipe, fakeSources);
     
    6069
    6170    // replace all sources
    62     psphotReplaceAll (realSources, recipe);
     71    psphotReplaceAllSources (realSources, recipe);
    6372
    6473    // construct an initial model for each object
     
    6776    psphotGuessModels (readout, forceSources, recipe, psf);
    6877   
     78    psArray *sources = NULL;
     79
    6980    // linear fit to real + fake sources
    70     psArray *sources = ppSimMergeSources (realSources, fakeSources);
     81    sources = ppSimMergeSources (realSources, fakeSources);
    7182    psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract
    72     psphotReplaceAll (sources, recipe);
     83    psphotReplaceAllSources (sources, recipe);
    7384    psFree (sources); // only frees the merged references
    7485
    7586    // linear fit to real + forced sources
    76     psArray *sources = ppSimMergeSources (realSources, forceSources);
     87    sources = ppSimMergeSources (realSources, forceSources);
    7788    psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract
    78     psphotReplaceAll (sources, recipe);
     89    psphotReplaceAllSources (sources, recipe);
    7990    psFree (sources); // only frees the merged references
    8091
     
    8596    if (!psphotApResid (readout, forceSources, recipe, psf)) {
    8697        psLogMsg ("psphot", 3, "failed on psphotApResid");
    87         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     98        return psphotReadoutCleanup (config, readout, recipe, NULL, psf, NULL);
    8899    }
    89100
    90     // calculate source magnitudes
     101    // calculate source magnitudes (for which set??)
    91102    pmReadout *background = psphotSelectBackground (config, view, false);
    92     psphotMagnitudes(sources, recipe, psf, background);
     103    psphotMagnitudes(fakeSources, recipe, psf, background);
     104    psphotMagnitudes(forceSources, recipe, psf, background);
    93105
    94106    // drop the references to the image pixels held by each source
    95     psphotSourceFreePixels (sources);
     107    psphotSourceFreePixels (realSources);
     108    psphotSourceFreePixels (fakeSources);
     109    psphotSourceFreePixels (forceSources);
    96110
    97111    // create the exported-metadata and free local data
    98     return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     112    // XXX this places the sources on readout->analysis as PSPHOT.SOURCES.  modify?
     113    // (or don't supply the sources, and do this with a different function)
     114    psphotReadoutCleanup(config, readout, recipe, NULL, psf, NULL);
     115
     116    // add forceSources to the readout (real and fake already there)
     117    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FAKE.SOURCES", PS_DATA_ARRAY, "fake photometry ", fakeSources);
     118    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources);
     119    psFree (forceSources);
     120    return true;
    99121}
Note: See TracChangeset for help on using the changeset viewer.