IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17958


Ignore:
Timestamp:
Jun 5, 2008, 5:16:44 PM (18 years ago)
Author:
eugene
Message:

split fake and force photometry into separate functions and separate mosaicked images

Location:
branches/eam_branch_20080511/ppSim/src
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080511/ppSim/src/Makefile.am

    r17818 r17958  
    44ppSim_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSPHOT_LIBS) $(PSASTRO_LIBS)
    55ppSim_SOURCES = \
    6         ppSim.c                 \
    7         ppSimArguments.c        \
    8         ppSimCreate.c           \
    9         ppSimLoadStars.c        \
    10         ppSimMakeStars.c        \
    11         ppSimMakeGalaxies.c     \
    12         ppSimMakeBiassec.c      \
    13         ppSimMakeBias.c         \
    14         ppSimMakeDark.c         \
    15         ppSimMakeSky.c          \
    16         ppSimInsertStars.c      \
    17         ppSimInsertGalaxies.c   \
    18         ppSimAddOverscan.c      \
    19         ppSimAddNoise.c         \
    20         ppSimSaturate.c         \
    21         ppSimBounds.c           \
    22         ppSimStars.c            \
    23         ppSimSetPSF.c           \
    24         ppSimUtils.c            \
    25         ppSimLoop.c             \
    26         ppSimLoadSpots.c        \
    27         ppSimPhotom.c           \
    28         ppSimPhotomReadout.c    \
    29         ppSimPhotomFiles.c      \
    30         ppSimLoadForceSources.c \
    31         ppSimMergeReadouts.c    \
    32         ppSimDetections.c       \
    33         ppSimMergeSources.c     \
    34         ppSimMosaicChip.c       \
    35         ppSimRandomGaussian.c   \
     6        ppSim.c                   \
     7        ppSimArguments.c          \
     8        ppSimCreate.c             \
     9        ppSimLoadStars.c          \
     10        ppSimMakeStars.c          \
     11        ppSimMakeGalaxies.c       \
     12        ppSimMakeBiassec.c        \
     13        ppSimMakeBias.c           \
     14        ppSimMakeDark.c           \
     15        ppSimMakeSky.c            \
     16        ppSimInsertStars.c        \
     17        ppSimInsertGalaxies.c     \
     18        ppSimAddOverscan.c        \
     19        ppSimAddNoise.c           \
     20        ppSimSaturate.c           \
     21        ppSimBounds.c             \
     22        ppSimStars.c              \
     23        ppSimSetPSF.c             \
     24        ppSimUtils.c              \
     25        ppSimLoop.c               \
     26        ppSimLoadSpots.c          \
     27        ppSimPhotom.c             \
     28        ppSimPhotomReadoutFake.c  \
     29        ppSimPhotomReadoutForce.c \
     30        ppSimPhotomFiles.c        \
     31        ppSimLoadForceSources.c   \
     32        ppSimMergeReadouts.c      \
     33        ppSimDetections.c         \
     34        ppSimMergeSources.c       \
     35        ppSimMosaicChip.c         \
     36        ppSimRandomGaussian.c     \
    3637        ppSimBadPixels.c
    3738
  • branches/eam_branch_20080511/ppSim/src/ppSim.h

    r17901 r17958  
    187187void ppSimRandomGaussianFree();
    188188
    189 bool ppSimPhotomFiles (pmConfig *config, pmFPAfile *input);
    190 bool ppSimPhotomReadout(pmConfig *config, const pmFPAview *view);
     189bool ppSimPhotomFiles (pmConfig *config, pmFPAfile *fakeFile, pmFPAfile *forceFile);
     190
     191bool ppSimPhotomReadoutFake(pmConfig *config, const pmFPAview *view);
     192bool ppSimPhotomReadoutForce(pmConfig *config, const pmFPAview *view);
     193
    191194psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view);
    192195bool ppSimDetections (psImage *significance, psMetadata *recipe, psArray *sources);
    193196psArray *ppSimMergeSources (psArray *in1, psArray *in2);
    194197
     198psArray *ppSimSelectSources (pmConfig *config, const pmFPAview *view, const char *filename);
     199bool ppSimDefinePixels (psArray *sources, pmReadout *readout, psMetadata *recipe);
     200
    195201#endif
  • branches/eam_branch_20080511/ppSim/src/ppSimArguments.c

    r17901 r17958  
    125125        ppSimArgToRecipeF32(&status, options, "PIXEL.SCALE", arguments, "-scale"); // Plate scale
    126126
     127        // XXX we need to be more flexible: get this from the input image header or WCS
     128        float ra0     = psMetadataLookupF32(NULL, arguments, "-ra"); // Right Ascension of boresight
     129        float dec0    = psMetadataLookupF32(NULL, arguments, "-dec"); // Declination of boresight
     130        psMetadataAddF32(options, PS_LIST_TAIL, "RA", 0, "Boresight RA (radians)", ra0 * M_PI / 180.0);
     131        psMetadataAddF32(options, PS_LIST_TAIL, "DEC", 0, "Boresight Declination (radians)", dec0 * M_PI / 180.0);
     132
    127133        psFree (arguments);
    128134        return true;
  • branches/eam_branch_20080511/ppSim/src/ppSimCreate.c

    r17935 r17958  
    33pmFPAfile *ppSimCreate(pmConfig *config)
    44{
    5   bool status;
    6   bool simImage = false;
    7   PS_ASSERT_PTR_NON_NULL(config, NULL);
    8   pmFPA *fpa = NULL;
    9 
    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;
    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, "PPSIM.INPUT is not of type IMAGE");
    25       return NULL;
    26     }
    27   }
    28 
    29   // generate the fpa structure used by the output camera (determined from INPUT or specified)
    30   assert (config->camera);
    31   fpa = pmFPAConstruct(config->camera, config->cameraName); // 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);
    102       return NULL;
    103     }
    104 
    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;
    110     }
    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");
     5    bool status;
     6    bool simImage = false;
     7    PS_ASSERT_PTR_NON_NULL(config, NULL);
     8    pmFPA *fpa = NULL;
     9
     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;
     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, "PPSIM.INPUT is not of type IMAGE");
     25            return NULL;
     26        }
     27    }
     28
     29    // generate the fpa structure used by the output camera (determined from INPUT or specified)
     30    assert (config->camera);
     31    fpa = pmFPAConstruct(config->camera, config->cameraName); // 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");
    12045        psFree(fpa);
    12146        return NULL;
    122       }
    123     }
    124   }
    125 
    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;
    134 
    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 
     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
    14055    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    14156
    142     ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE");
    143     char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTER");
    144 
    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       }
    171     }
    172 
    173     pmCell *cell;                   // Cell from chip
    174     while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    175       if (phuLevel == PM_FPA_LEVEL_CELL) {
     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        // XXX optionally select fake and/or force
     93
     94        // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
     95        pmFPAfile *fakeImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.FAKE.CHIP");
     96        if (!fakeImage) {
     97            psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FAKE.CHIP"));
     98            psFree(fpa);
     99            return NULL;
     100        }
     101        if (fakeImage->type != PM_FPA_FILE_IMAGE) {
     102            psError(PS_ERR_IO, true, "PPSIM.FAKE.CHIP is not of type IMAGE");
     103            psFree(fpa);
     104            return NULL;
     105        }
     106
     107        // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
     108        pmFPAfile *forceImage = NULL;
     109        if (input) {
     110            forceImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSIM.FORCE.CHIP");
     111            if (!forceImage) {
     112                psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FORCE.CHIP"));
     113                psFree(fpa);
     114                return NULL;
     115            }
     116            if (forceImage->type != PM_FPA_FILE_IMAGE) {
     117                psError(PS_ERR_IO, true, "PPSIM.FORCE.CHIP is not of type IMAGE");
     118                psFree(fpa);
     119                return NULL;
     120            }
     121        }
     122
     123        // define associated psphot input/output files
     124        if (!ppSimPhotomFiles (config, fakeImage, forceImage)) {
     125            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
     126            psFree(fpa);
     127            return NULL;
     128        }
     129    } else {
     130        // have we supplied a psf model?  this happens in ppSimPhotomFiles if we request a photometry
     131        // analysis.  however, even if we do not, a psf model may be used to generate the fake
     132        // sources.
     133        if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
     134            // tie the psf file to the chipMosaic
     135            pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
     136            if (!status) {
     137                psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
     138                psFree(fpa);
     139                return NULL;
     140            }
     141        }
     142    }
     143
     144    // PPSIM.SOURCES carries the constructed, fake sources with their true parameters
     145    // XXX only invoke this code for OBJECT types of images?
     146    pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES");
     147    if (!simSources) {
     148        psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
     149        return false;
     150    }
     151    simSources->save = true;
     152
     153    // if we have loaded an input image, we derive certain values from the image, if possible
     154    if (input) {
     155        // we need to extract certain metadata from the image and populate the recipe.
     156        // or else we need to set the fpa concepts based on the recipe options...
     157
     158        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     159
     160        ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE");
     161        char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTER");
     162
     163        float zp = ppSimGetZeroPoint (recipe, filter);
     164        psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     165    }
     166
     167    pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes
     168
     169    pmFPAview *view = pmFPAviewAlloc(0);// View for current level
     170
     171    if (phuLevel == PM_FPA_LEVEL_FPA) {
    176172        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;
    181         }
    182       }
    183     }
    184   }
    185 
    186   psFree(fpa);
    187   psFree(view);
    188 
    189   return output;
     173            psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     174            psFree(fpa);
     175            psFree(view);
     176            return NULL;
     177        }
     178    }
     179
     180    pmChip *chip;                       // Chip from FPA
     181    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
     182        if (phuLevel == PM_FPA_LEVEL_CHIP) {
     183            if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     184                psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     185                psFree(fpa);
     186                psFree(view);
     187                return NULL;
     188            }
     189        }
     190
     191        pmCell *cell;                   // Cell from chip
     192        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
     193            if (phuLevel == PM_FPA_LEVEL_CELL) {
     194                if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     195                    psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     196                    psFree(fpa);
     197                    psFree(view);
     198                    return NULL;
     199                }
     200            }
     201        }
     202    }
     203
     204    psFree(fpa);
     205    psFree(view);
     206
     207    return output;
    190208}
  • branches/eam_branch_20080511/ppSim/src/ppSimDetectionLimits.c

    r17818 r17958  
    1717    // find the currently selected readout.
    1818    // we always perform photometry on the mosaiced chip
    19     pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PPSIM.CHIP");
     19    pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PPSIM.FAKE.CHIP");
    2020    PS_ASSERT_PTR_NON_NULL (readout, false);
    2121
  • branches/eam_branch_20080511/ppSim/src/ppSimLoadForceSources.c

    r17935 r17958  
    2525    psAssert(srcFile, "missing PPSIM.REAL.SOURCES");
    2626
     27    // select the fpa and chip from PPSIM.REAL.SOURCES, which carries the astrometry in the headers
    2728    pmFPA     *fpa     = srcFile->fpa;
    2829    pmChip    *chip    = pmFPAviewThisChip (view, fpa);
    29     // pmCell    *cell    = pmFPAviewThisCell (view, fpa);
    30     pmReadout *readout = pmFPAviewThisReadout (view, fpa);
     30
     31    // we use the readout for the PPSIM.FORCE.CHIP, which contains the chip-mosaicked image(s)
     32    pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PPSIM.FORCE.CHIP");
    3133
    3234    // XXX we should have only one cell and readout per chip, right?
    3335
    3436    // read WCS from existing output from psphot & psastro
    35     // XXX can we be more flexible?  ie, use the header of PPSIM.CHIP?
     37    // XXX can we be more flexible?  ie, use the header of PPSIM.FORCE.CHIP?
    3638    bool bilevelAstrometry = false;
    3739    status = psastroAstromGuessSetFPA (fpa, &bilevelAstrometry);
  • branches/eam_branch_20080511/ppSim/src/ppSimLoadSpots.c

    r17935 r17958  
    99    bool status;
    1010
    11     psArray *spots = psArrayAllocEmpty (1);
    12     psMetadataAddPtr (fpa->analysis, PS_LIST_TAIL, "FORCED.SPOTS", PS_META_REPLACE, "forced photometry positions", spots);
    13     psFree (spots); // free the extra (local) reference; a copy remains on fpa->analysis
    1411
    1512    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    1613
    1714    bool forcedPhot = psMetadataLookupBool(&status, recipe, "FORCED.PHOT"); // Density of fakes
    18     if (!forcedPhot) return true;
     15    if (!forcedPhot) {
     16        psArray *spots = psArrayAllocEmpty (1);
     17        psMetadataAddArray (fpa->analysis, PS_LIST_TAIL, "FORCED.SPOTS", PS_META_REPLACE, "forced photometry positions", spots);
     18        psFree (spots); // free the extra (local) reference; a copy remains on fpa->analysis
     19        return true;
     20    }
    1921
    2022    // We read the catalogue stars using psastroLoadRefstars
     
    3032
    3133    char *catdir = psMetadataLookupStr(NULL, recipe, "FORCED.CATDIR");
    32     char *photcode = psMetadataLookupStr(NULL, recipe, "FORCED.PHOTCODE");
    33     float MAGmax = 100.0;
    3434
    3535    // Size of FPA
     
    4747    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_META_REPLACE, "", dec0 + radius);
    4848   
    49     // XXX these two values are somewhat bogus: can we have psastroLoadRefstars optionally ignore photcode and MAGmax?
    50     psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.PHOTCODE",  PS_META_REPLACE, "", photcode);
    51     psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.MAG.MAX",  PS_META_REPLACE, "", MAGmax);
     49    // tell psastroLoadRefstars to ignore photcode and maglim
     50    psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.PHOTCODE",  PS_META_REPLACE, "", "NONE");
     51    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.MAG.MAX",  PS_META_REPLACE, "", NAN);
    5252
    53     psArray *refStars = psastroLoadRefstars(config);
    54     if (!refStars || refStars->n == 0) {
     53    // load refstars from the catalog
     54    psArray *spots = psastroLoadRefstars(config);
     55    if (!spots || spots->n == 0) {
    5556        psError(PS_ERR_UNKNOWN, false, "Unable to find reference stars.");
    56         psFree(refStars);
     57        psFree(spots);
    5758        return false;
    5859    }
    59     psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", refStars->n);
     60    psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", spots->n);
    6061
    61     // convert the pmAstromObj sources to the storage format used by the CMF files
    62     psArrayRealloc (spots, refStars->n);
    63     for (long i = 0; i < refStars->n; i++) {
    64         ppSimStar *spot = ppSimStarAlloc ();
    65 
    66         pmAstromObj *ref = refStars->data[i]; // Reference star
    67         spot->ra  = ref->sky->r; // RA of star
    68         spot->dec = ref->sky->d; // Dec of star
    69         spot->mag = ref->Mag;       // Magnitude of star
    70 
    71         // Apply rotation, make FPA center of boresite
    72         // convert the ra,dec to x,y using examples in psastro.
    73         // spot->x = cos(pa) * xi - sin(pa) * eta + x0fpa;
    74         // spot->y = sin(pa) * xi + cos(pa) * eta + y0fpa;
    75 
    76         spots->data[i] = spot;
    77 
    78         psTrace("ppSim", 10, "Adding catalogue star: %.1f,%.1f --> %.2f\n", spot->x, spot->y, ref->Mag);
    79     }
     62    psMetadataAddArray (fpa->analysis, PS_LIST_TAIL, "FORCED.SPOTS", PS_META_REPLACE, "forced photometry positions", spots);
     63    psFree (spots); // free the extra (local) reference; a copy remains on fpa->analysis
    8064
    8165    return true;
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotom.c

    r17901 r17958  
    1616
    1717    int blankMask = 0;          // XXX not sure what this should be set to...
    18     ppSimMosaicChip(config, blankMask, view, "PPSIM.CHIP", "PPSIM.OUTPUT");
     18    ppSimMosaicChip(config, blankMask, view, "PPSIM.FORCE.CHIP", "PPSIM.INPUT");
     19    ppSimMosaicChip(config, blankMask, view, "PPSIM.FAKE.CHIP", "PPSIM.OUTPUT");
    1920
    20     // XXX have ppSimMosaicChip return the pointer?
    21     pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPSIM.CHIP");
     21    // use PPSIM.FAKE.CHIP as the base since it is guaranteed to exist (derived from PPSIM.OUTPUT)
     22    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPSIM.FAKE.CHIP");
    2223    if (!status) {
    23         psError(PSPHOT_ERR_CONFIG, false, "PPSIM.CHIP I/O file is not defined");
     24        psError(PSPHOT_ERR_CONFIG, false, "PPSIM.FAKE.CHIP I/O file is not defined");
    2425        return false;
    2526    }
     
    4647
    4748            // run the actual photometry analysis
    48             if (!ppSimPhotomReadout (config, view)) {
     49            if (!ppSimPhotomReadoutFake (config, view)) {
     50                psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
     51                return false;
     52            }
     53            if (!ppSimPhotomReadoutForce (config, view)) {
    4954                psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
    5055                return false;
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotomFiles.c

    r17901 r17958  
    22
    33// define the needed / desired I/O files
    4 bool ppSimPhotomFiles (pmConfig *config, pmFPAfile *input) {
     4bool ppSimPhotomFiles (pmConfig *config, pmFPAfile *fakeFile, pmFPAfile *forceFile) {
    55
    66    bool status = false;
     
    1313        int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
    1414        int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
    15         pmFPAfile *output = pmFPAfileDefineFromFile (config, input, DX, DY, "PSPHOT.BACKMDL");
     15        pmFPAfile *output = pmFPAfileDefineFromFile (config, fakeFile, DX, DY, "PSPHOT.BACKMDL");
    1616        if (!output) {
    1717            psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.BACKMDL");
     
    2424        int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
    2525        int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
    26         pmFPAfile *output = pmFPAfileDefineFromFile (config, input, DX, DY, "PSPHOT.BACKMDL.STDEV");
     26        pmFPAfile *output = pmFPAfileDefineFromFile (config, fakeFile, DX, DY, "PSPHOT.BACKMDL.STDEV");
    2727        if (!output) {
    2828            psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.BACKMDL.STDEV");
     
    3333    // optionally save the full background image
    3434    if (psMetadataLookupBool(NULL, recipe, "SAVE.BACKGND")) {
    35         pmFPAfile *output = pmFPAfileDefineFromFile (config, input,  1,  1, "PSPHOT.BACKGND");
     35        pmFPAfile *output = pmFPAfileDefineFromFile (config, fakeFile,  1,  1, "PSPHOT.BACKGND");
    3636        if (!output) {
    3737            psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.BACKGND");
     
    4242    // optionally save the background-subtracted image
    4343    if (psMetadataLookupBool(NULL, recipe, "SAVE.BACKSUB")) {
    44         pmFPAfile *output = pmFPAfileDefineFromFile (config, input,  1,  1, "PSPHOT.BACKSUB");
     44        pmFPAfile *output = pmFPAfileDefineFromFile (config, fakeFile,  1,  1, "PSPHOT.BACKSUB");
    4545        if (!output) {
    4646            psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.BACKSUB");
     
    5757    }
    5858
    59     // the fake sources are carried on the input->fpa structures
    60     pmFPAfile *outsources = pmFPAfileDefineOutputFromFile (config, input, "PPSIM.FAKE.SOURCES");
     59    // the fake sources are carried on the fakeFile->fpa structures (PPSIM.FAKE.CHIP)
     60    pmFPAfile *outsources = pmFPAfileDefineOutput (config, fakeFile->fpa, "PPSIM.FAKE.SOURCES");
    6161    if (!outsources) {
    6262        psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PPSIM.FAKE.SOURCES");
     
    6565    outsources->save = true;
    6666
     67    // the forced sources are carried on the forceFile->fpa structures (PPSIM.FORCE.CHIP)
     68    pmFPAfile *outforced = pmFPAfileDefineOutput (config, forceFile->fpa, "PPSIM.FORCE.SOURCES");
     69    if (!outforced) {
     70        psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PPSIM.FORCE.SOURCES");
     71        return false;
     72    }
     73    outforced->save = true;
     74
    6775    // we bind the psffile to the chip-mosaicked image so we have a reference to the image
    68     pmFPAfile *psffile = pmFPAfileBindFromArgs(&status, input, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
     76    pmFPAfile *psffile = pmFPAfileBindFromArgs(&status, fakeFile, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
    6977    if (!psffile) {
    7078      psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.PSF.LOAD");
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotomReadout.c

    r17935 r17958  
    158158    // these are outputs: we need to generate the fpa structure
    159159   
     160    pmCell    *forceCell    = pmFPAfileThisCell (config->files, view, "PPSIM.FORCE.SOURCES"); psAssert (forceCell, "no cell?");
     161    pmChip    *forceChip    = pmFPAfileThisChip (config->files, view, "PPSIM.FORCE.SOURCES"); psAssert (forceChip, "no chip?");
     162    pmReadout *forceReadout = pmFPAfileThisReadout (config->files, view, "PPSIM.FORCE.SOURCES");
     163    if (!forceReadout) {
     164        forceReadout = pmReadoutAlloc (forceCell);
     165        psFree (forceReadout); // there is a copy on 'cell' as well
     166    }
     167    psAssert (forceReadout, "no forceReadout?");
     168    pmChipSetDataStatus (forceChip, true);
     169    psMetadataAddArray (forceReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "forced photometry ", forceSources);
     170    psFree (forceSources);
     171
     172    pmCell    *fakeCell    = pmFPAfileThisCell (config->files, view, "PPSIM.FAKE.SOURCES"); psAssert (fakeCell, "no cell?");
     173    pmChip    *fakeChip    = pmFPAfileThisChip (config->files, view, "PPSIM.FAKE.SOURCES"); psAssert (fakeChip, "no chip?");
    160174    pmReadout *fakeReadout = pmFPAfileThisReadout (config->files, view, "PPSIM.FAKE.SOURCES");
    161     psMetadataAdd (fakeReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "fake photometry ", fakeSources);
     175    if (!fakeReadout) {
     176        fakeReadout = pmReadoutAlloc (fakeCell);
     177        psFree (fakeReadout); // there is a copy on 'cell' as well
     178    }
     179    psAssert (fakeReadout, "no fakeReadout?");
     180    pmChipSetDataStatus (fakeChip, true);
     181    psMetadataAddArray (fakeReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "fake photometry ", fakeSources);
    162182
    163     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources);
    164     psFree (forceSources);
    165183    return true;
    166184}
  • branches/eam_branch_20080511/ppSim/src/ppSimUtils.c

    r17901 r17958  
    274274    return NAN;
    275275}
     276
     277psArray *ppSimSelectSources (pmConfig *config, const pmFPAview *view, const char *filename) {
     278
     279    pmReadout *readout = pmFPAfileThisReadout (config->files, view, filename);
     280    PS_ASSERT_PTR_NON_NULL (readout, NULL);
     281
     282    psArray *sources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES");
     283    return sources;
     284}
     285
     286bool ppSimDefinePixels (psArray *sources, pmReadout *readout, psMetadata *recipe) {
     287
     288    bool status;
     289
     290    float OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS");
     291    if (!status) return NULL;
     292
     293    for (int i = 0; i < sources->n; i++) {
     294        pmSource *source = sources->data[i];
     295
     296        // allocate image, weight, mask arrays for each peak (square of radius OUTER)
     297        pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
     298    }
     299    return true;
     300}
     301
Note: See TracChangeset for help on using the changeset viewer.