IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 13, 2009, 2:16:23 PM (17 years ago)
Author:
Paul Price
Message:

Zero point when loading input image was being derived from FPA.FILTER (e.g., r.00000) instead of FPA.FILTERID (e.g., r). Reworked how this is defined from a MULTI to a menu.

File:
1 edited

Legend:

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

    r18011 r23836  
    1212    pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPSIM.INPUT", "INPUT");
    1313    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         }
     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        }
    1919    } 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         if (input->type != PM_FPA_FILE_IMAGE) {
    23             psError(PS_ERR_IO, true, "PPSIM.INPUT is not of type IMAGE");
    24             return NULL;
    25         }
     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        if (input->type != PM_FPA_FILE_IMAGE) {
     23            psError(PS_ERR_IO, true, "PPSIM.INPUT is not of type IMAGE");
     24            return NULL;
     25        }
    2626    }
    2727
     
    3030    fpa = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the observation
    3131    if (!fpa) {
    32         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
    33         return NULL;
     32        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
     33        return NULL;
    3434    }
    3535
     
    3737    pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, "PPSIM.OUTPUT");
    3838    if (!output) {
    39         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from PPSIM.OUTPUT. Did you forget to specify the format?");
    40         return NULL;
     39        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from PPSIM.OUTPUT. Did you forget to specify the format?");
     40        return NULL;
    4141    }
    4242    if (output->type != PM_FPA_FILE_IMAGE) {
    43         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "PPSIM.OUTPUT type is not IMAGE");
    44         psFree(fpa);
    45         return NULL;
     43        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "PPSIM.OUTPUT type is not IMAGE");
     44        psFree(fpa);
     45        return NULL;
    4646    }
    4747    // XXX we should not require the output image to be written
     
    5858
    5959    if (type == PPSIM_TYPE_OBJECT) {
    60         // adjust the seeing by the scale
    61         float seeing = psMetadataLookupF32(&status, recipe, "SEEING");
    62         if (isnan(seeing)) {
    63             psError(PS_ERR_BAD_PARAMETER_TYPE, true, "seeing is not defined");
    64             psFree(fpa);
    65             return NULL;
    66         }
    67         float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE");
    68         if (isnan(scale)) {
    69             psError(PS_ERR_BAD_PARAMETER_TYPE, true, "pixel scale is not defined");
    70             psFree(fpa);
    71             return NULL;
    72         }
    73         psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
    74 
    75         // if we have been supplied an input image, but no ra & dec, use the input image values
    76         if (input) {
    77             float ra = psMetadataLookupF32(&status, recipe, "RA");
    78             if (isnan(ra)) {
    79                 ra = psMetadataLookupF64(&status, input->fpa->concepts, "FPA.RA");
    80                 psMetadataAddF32(recipe, PS_LIST_TAIL, "RA", PS_META_REPLACE, "ra (radians)", ra);
    81             }
    82             float dec = psMetadataLookupF32(&status, recipe, "DEC");
    83             if (isnan(dec)) {
    84                 dec = psMetadataLookupF64(&status, input->fpa->concepts, "FPA.DEC");
    85                 psMetadataAddF32(recipe, PS_LIST_TAIL, "DEC", PS_META_REPLACE, "dec (radians)", dec);
    86             }
    87         }
     60        // adjust the seeing by the scale
     61        float seeing = psMetadataLookupF32(&status, recipe, "SEEING");
     62        if (isnan(seeing)) {
     63            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "seeing is not defined");
     64            psFree(fpa);
     65            return NULL;
     66        }
     67        float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE");
     68        if (isnan(scale)) {
     69            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "pixel scale is not defined");
     70            psFree(fpa);
     71            return NULL;
     72        }
     73        psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
     74
     75        // if we have been supplied an input image, but no ra & dec, use the input image values
     76        if (input) {
     77            float ra = psMetadataLookupF32(&status, recipe, "RA");
     78            if (isnan(ra)) {
     79                ra = psMetadataLookupF64(&status, input->fpa->concepts, "FPA.RA");
     80                psMetadataAddF32(recipe, PS_LIST_TAIL, "RA", PS_META_REPLACE, "ra (radians)", ra);
     81            }
     82            float dec = psMetadataLookupF32(&status, recipe, "DEC");
     83            if (isnan(dec)) {
     84                dec = psMetadataLookupF64(&status, input->fpa->concepts, "FPA.DEC");
     85                psMetadataAddF32(recipe, PS_LIST_TAIL, "DEC", PS_META_REPLACE, "dec (radians)", dec);
     86            }
     87        }
    8888    }
    8989
    9090    if ((type == PPSIM_TYPE_OBJECT) || (type == PPSIM_TYPE_FLAT)) {
    91         // determine the zeropoint from the filter
    92         float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT");
    93         if (isnan(zp)) {
    94             char *filter = psMetadataLookupStr(&status, recipe, "FILTER");
    95             float zp = ppSimGetZeroPoint (recipe, filter);
    96             psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
    97         }
     91        // determine the zeropoint from the filter
     92        float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT");
     93        if (isnan(zp)) {
     94            char *filter = psMetadataLookupStr(&status, recipe, "FILTER");
     95            float zp = ppSimGetZeroPoint (recipe, filter);
     96            psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     97        }
    9898    }
    9999
     
    103103    if (doPhotom) {
    104104
    105         // XXX at the moment, we can perform photometry on the fake sources and the forced
    106         // photometry positions, but not one or the other.  Also, we only support photometry in
    107         // the context of an image previously analysed by psphot.  Add support for:
    108         // * photometry of a pure fake image (requires peak detection and psf creation)
    109         // * photometry of forced source positions without fake image (this might work, it just
    110         // requires not generating any fake features).
    111 
    112         if (!input) {
    113             psError(PS_ERR_UNKNOWN, false, "input image not found; currently required for photometry");
    114             return NULL;
    115         }
    116 
    117         // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
    118         pmFPAfile *fakeImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.FAKE.CHIP");
    119         if (!fakeImage) {
    120             psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FAKE.CHIP"));
    121             psFree(fpa);
    122             return NULL;
    123         }
    124         if (fakeImage->type != PM_FPA_FILE_IMAGE) {
    125             psError(PS_ERR_IO, true, "PPSIM.FAKE.CHIP is not of type IMAGE");
    126             psFree(fpa);
    127             return NULL;
    128         }
    129 
    130         // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
    131         pmFPAfile *forceImage = NULL;
    132         if (input) {
    133             forceImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSIM.FORCE.CHIP");
    134             if (!forceImage) {
    135                 psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FORCE.CHIP"));
    136                 psFree(fpa);
    137                 return NULL;
    138             }
    139             if (forceImage->type != PM_FPA_FILE_IMAGE) {
    140                 psError(PS_ERR_IO, true, "PPSIM.FORCE.CHIP is not of type IMAGE");
    141                 psFree(fpa);
    142                 return NULL;
    143             }
    144         }
    145 
    146         // define associated psphot input/output files
    147         if (!ppSimPhotomFiles (config, fakeImage, forceImage)) {
    148             psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
    149             psFree(fpa);
    150             return NULL;
    151         }
     105        // XXX at the moment, we can perform photometry on the fake sources and the forced
     106        // photometry positions, but not one or the other.  Also, we only support photometry in
     107        // the context of an image previously analysed by psphot.  Add support for:
     108        // * photometry of a pure fake image (requires peak detection and psf creation)
     109        // * photometry of forced source positions without fake image (this might work, it just
     110        // requires not generating any fake features).
     111
     112        if (!input) {
     113            psError(PS_ERR_UNKNOWN, false, "input image not found; currently required for photometry");
     114            return NULL;
     115        }
     116
     117        // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
     118        pmFPAfile *fakeImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.FAKE.CHIP");
     119        if (!fakeImage) {
     120            psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FAKE.CHIP"));
     121            psFree(fpa);
     122            return NULL;
     123        }
     124        if (fakeImage->type != PM_FPA_FILE_IMAGE) {
     125            psError(PS_ERR_IO, true, "PPSIM.FAKE.CHIP is not of type IMAGE");
     126            psFree(fpa);
     127            return NULL;
     128        }
     129
     130        // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
     131        pmFPAfile *forceImage = NULL;
     132        if (input) {
     133            forceImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSIM.FORCE.CHIP");
     134            if (!forceImage) {
     135                psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FORCE.CHIP"));
     136                psFree(fpa);
     137                return NULL;
     138            }
     139            if (forceImage->type != PM_FPA_FILE_IMAGE) {
     140                psError(PS_ERR_IO, true, "PPSIM.FORCE.CHIP is not of type IMAGE");
     141                psFree(fpa);
     142                return NULL;
     143            }
     144        }
     145
     146        // define associated psphot input/output files
     147        if (!ppSimPhotomFiles (config, fakeImage, forceImage)) {
     148            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
     149            psFree(fpa);
     150            return NULL;
     151        }
    152152    } else {
    153         // have we supplied a psf model?  this happens in ppSimPhotomFiles if we request a photometry
    154         // analysis.  however, even if we do not, a psf model may be used to generate the fake
    155         // sources.
    156         if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
    157             // tie the psf file to the chipMosaic
    158             pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
    159             if (!status) {
    160                 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
    161                 psFree(fpa);
    162                 return NULL;
    163             }
    164         }
     153        // have we supplied a psf model?  this happens in ppSimPhotomFiles if we request a photometry
     154        // analysis.  however, even if we do not, a psf model may be used to generate the fake
     155        // sources.
     156        if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
     157            // tie the psf file to the chipMosaic
     158            pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
     159            if (!status) {
     160                psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
     161                psFree(fpa);
     162                return NULL;
     163            }
     164        }
    165165    }
    166166
     
    169169    pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES");
    170170    if (!simSources) {
    171         psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
    172         return false;
     171        psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
     172        return false;
    173173    }
    174174    simSources->save = true;
     
    176176    // if we have loaded an input image, we derive certain values from the image, if possible
    177177    if (input) {
    178         // we need to extract certain metadata from the image and populate the recipe.
    179         // or else we need to set the fpa concepts based on the recipe options...
    180 
    181         psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    182 
    183         ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE");
    184         char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTER");
    185 
    186         float zp = ppSimGetZeroPoint (recipe, filter);
    187         psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     178        // we need to extract certain metadata from the image and populate the recipe.
     179        // or else we need to set the fpa concepts based on the recipe options...
     180
     181        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     182
     183        ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE");
     184        char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTERID");
     185
     186        float zp = ppSimGetZeroPoint(recipe, filter);
     187        if (!isfinite(zp)) {
     188            psError(PS_ERR_UNKNOWN, false, "Unable to find zero point for filter %s", filter);
     189            psFree(fpa);
     190            return NULL;
     191        }
     192        psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
    188193    }
    189194
     
    193198
    194199    if (phuLevel == PM_FPA_LEVEL_FPA) {
    195         if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    196             psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    197             psFree(fpa);
    198             psFree(view);
    199             return NULL;
    200         }
     200        if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     201            psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     202            psFree(fpa);
     203            psFree(view);
     204            return NULL;
     205        }
    201206    }
    202207
    203208    pmChip *chip;                       // Chip from FPA
    204209    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    205         if (phuLevel == PM_FPA_LEVEL_CHIP) {
    206             if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    207                 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    208                 psFree(fpa);
    209                 psFree(view);
    210                 return NULL;
    211             }
    212         }
    213 
    214         pmCell *cell;                   // Cell from chip
    215         while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    216             if (phuLevel == PM_FPA_LEVEL_CELL) {
    217                 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    218                     psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    219                     psFree(fpa);
    220                     psFree(view);
    221                     return NULL;
    222                 }
    223             }
    224         }
     210        if (phuLevel == PM_FPA_LEVEL_CHIP) {
     211            if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     212                psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     213                psFree(fpa);
     214                psFree(view);
     215                return NULL;
     216            }
     217        }
     218
     219        pmCell *cell;                   // Cell from chip
     220        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
     221            if (phuLevel == PM_FPA_LEVEL_CELL) {
     222                if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
     223                    psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
     224                    psFree(fpa);
     225                    psFree(view);
     226                    return NULL;
     227                }
     228            }
     229        }
    225230    }
    226231
Note: See TracChangeset for help on using the changeset viewer.