IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 13, 2008, 4:56:38 PM (18 years ago)
Author:
eugene
Message:

substantial work on argument handling to support externally supplied images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080511/ppSim/src/ppSimCreate.c

    r17630 r17672  
    11# include "ppSim.h"
    2 
    3 // XXX this function forces us to define the camera (on the command line) and format (via the
    4 // PPSIM.OUTPUT entry).  In this case, we need to set config->format,formatName based on these
    5 // values.  This will be a problem when we want to load an input image (in order to add fake
    6 // stars).  We will need to add some logic in ppSimArguments to distinguish the cases of 1)
    7 // input image and 2) specified camera
    82
    93pmFPAfile *ppSimCreate(pmConfig *config)
     
    3024            return NULL;
    3125        }
    32        
    3326    } else {
    3427        simImage = false;
     
    3730            return NULL;
    3831        }
    39         fpa = input->fpa;
     32        fpa = psMemIncrRefCounter (input->fpa);
    4033    }
    4134
    4235    // define the output image file -- this is the basis for the ppSimLoop
    43     pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);
    44     if (!file) {
     36    pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);
     37    if (!output) {
    4538        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s.  "
    4639                "Did you forget to specify the format?", OUTPUT_FILE);
    4740        return NULL;
    4841    }
    49     if (file->type != PM_FPA_FILE_IMAGE) {
     42    if (output->type != PM_FPA_FILE_IMAGE) {
    5043        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE);
    5144        psFree(fpa);
    52         psFree(file);
    5345        return NULL;
    5446    }
    5547    // XXX we should not require the output image to be written
    56     file->save = true;
     48    output->save = true;
    5749
    58     config->format = psMemIncrRefCounter (file->format);
    59     config->formatName = psStringCopy (file->formatName);
     50    config->format = psMemIncrRefCounter (output->format);
     51    config->formatName = psStringCopy (output->formatName);
     52
     53    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    6054
    6155    // For photometry, we operate on the chip-mosaicked image.  we create a copy of the mosaicked
    6256    // image for psphot so we can write out a clean image
    63     if (options->doPhotom) {
     57    bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes
     58    if (doPhotom) {
    6459
    6560        // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
     
    6762        if (!chipImage) {
    6863            psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.CHIP"));
    69             psFree(options);
     64            psFree(fpa);
    7065            return NULL;
    7166        }
    7267        if (chipImage->type != PM_FPA_FILE_IMAGE) {
    7368            psError(PS_ERR_IO, true, "PPSIM.CHIP is not of type IMAGE");
    74             psFree(options);
     69            psFree(fpa);
    7570            return NULL;
    7671        }
     
    8479        if (!psphotDefineFiles (config, psphotInput)) {
    8580            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
    86             return false;
     81            psFree(fpa);
     82            return NULL;
    8783        }
    8884    } else {
     
    9288        if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
    9389            // tie the psf file to the chipMosaic
    94             pmFPAfileBindFromArgs(&status, file, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
     90            pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
    9591            if (!status) {
    9692                psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
    9793                psFree(fpa);
    98                 psFree(file);
    9994                return NULL;
    10095            }
     
    10499    // PPSIM.SOURCES carries the constructed, fake sources with their true parameters
    105100    // XXX only invoke this code for OBJECT types of images
    106     pmFPAfile *simSources = pmFPAfileDefineOutput (config, file->fpa, "PPSIM.SOURCES");
     101    pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES");
    107102    if (!simSources) {
    108103        psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
     
    113108    // if we have loaded an input image, we do not need to populate the fpa
    114109    if (!simImage) {
    115         return file;
     110        // we need to extract certain metadata from the image and populate the recipe.
     111        // or else we need to set the fpa concepts based on the recipe options...
     112
     113        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     114
     115        ppSimArgToRecipeF32(&status, recipe, "EXPTIME", fpa->concepts, "FPA.EXPOSURE");
     116        char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", fpa->concepts, "FPA.FILTER");
     117
     118        float zp = ppSimGetZeroPoint (recipe, filter);
     119        psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     120
     121        return output;
    116122    }
    117123
    118     pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level at which PHU goes
     124    pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes
    119125
    120126    pmFPAview *view = pmFPAviewAlloc(0);// View for current level
    121127
    122128    if (phuLevel == PM_FPA_LEVEL_FPA) {
    123         if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {
     129        if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    124130            psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    125131            psFree(fpa);
    126132            psFree(view);
    127             psFree(file);
    128133            return NULL;
    129134        }
     
    133138    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    134139        if (phuLevel == PM_FPA_LEVEL_CHIP) {
    135             if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {
     140            if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    136141                psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    137142                psFree(fpa);
    138143                psFree(view);
    139                 psFree(file);
    140144                return NULL;
    141145            }
     
    145149        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    146150            if (phuLevel == PM_FPA_LEVEL_CELL) {
    147                 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {
     151                if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    148152                    psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    149153                    psFree(fpa);
    150154                    psFree(view);
    151                     psFree(file);
    152155                    return NULL;
    153156                }
     
    159162    psFree(view);
    160163
    161     return file;
     164    return output;
    162165}
Note: See TracChangeset for help on using the changeset viewer.