Changeset 23836
- Timestamp:
- Apr 13, 2009, 2:16:23 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
ippconfig/recipes/ppSim.config (modified) (1 diff)
-
ppSim/src/ppSim.h (modified) (1 diff)
-
ppSim/src/ppSimCreate.c (modified) (8 diffs)
-
ppSim/src/ppSimUtils.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippconfig/recipes/ppSim.config
r23470 r23836 86 86 87 87 # filter-dependent parameters 88 ZEROPTS MULTI89 90 88 ZEROPTS METADATA 91 FILTER STR g 92 ZERO_PT F32 24.0 93 END 94 ZEROPTS METADATA 95 FILTER STR r 96 ZERO_PT F32 25.15 97 END 98 ZEROPTS METADATA 99 FILTER STR i 100 ZERO_PT F32 25.00 101 END 102 ZEROPTS METADATA 103 FILTER STR z 104 ZERO_PT F32 24.50 105 END 106 ZEROPTS METADATA 107 FILTER STR y 108 ZERO_PT F32 24.00 89 g F32 24.00 90 r F32 25.15 91 i F32 25.00 92 z F32 24.50 93 y F32 24.00 109 94 END 110 95 -
trunk/ppSim/src/ppSim.h
r23487 r23836 183 183 char *ppSimTypeToString (ppSimType type); 184 184 185 float ppSimGetZeroPoint (psMetadata *recipe,char *filter);185 float ppSimGetZeroPoint(psMetadata *recipe, const char *filter); 186 186 187 187 bool ppSimMergeReadouts (pmConfig *config, pmFPAview *view); -
trunk/ppSim/src/ppSimCreate.c
r18011 r23836 12 12 pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPSIM.INPUT", "INPUT"); 13 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 recipes15 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 } 19 19 } else { 20 // If an image is supplied, we still generate a fake image and merge them together downstream21 // (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 } 26 26 } 27 27 … … 30 30 fpa = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the observation 31 31 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; 34 34 } 35 35 … … 37 37 pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, "PPSIM.OUTPUT"); 38 38 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; 41 41 } 42 42 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; 46 46 } 47 47 // XXX we should not require the output image to be written … … 58 58 59 59 if (type == PPSIM_TYPE_OBJECT) { 60 // adjust the seeing by the scale61 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 values76 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 } 88 88 } 89 89 90 90 if ((type == PPSIM_TYPE_OBJECT) || (type == PPSIM_TYPE_FLAT)) { 91 // determine the zeropoint from the filter92 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 } 98 98 } 99 99 … … 103 103 if (doPhotom) { 104 104 105 // XXX at the moment, we can perform photometry on the fake sources and the forced106 // photometry positions, but not one or the other. Also, we only support photometry in107 // 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 just110 // 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 files147 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 } 152 152 } else { 153 // have we supplied a psf model? this happens in ppSimPhotomFiles if we request a photometry154 // analysis. however, even if we do not, a psf model may be used to generate the fake155 // 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 } 165 165 } 166 166 … … 169 169 pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES"); 170 170 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; 173 173 } 174 174 simSources->save = true; … … 176 176 // if we have loaded an input image, we derive certain values from the image, if possible 177 177 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); 188 193 } 189 194 … … 193 198 194 199 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 } 201 206 } 202 207 203 208 pmChip *chip; // Chip from FPA 204 209 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 chip215 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 } 225 230 } 226 231 -
trunk/ppSim/src/ppSimUtils.c
r20365 r23836 112 112 ppSimType ppSimTypeFromString (char *typeStr) { 113 113 114 if (!strcasecmp (typeStr, "BIAS")) return PPSIM_TYPE_BIAS;115 if (!strcasecmp (typeStr, "DARK")) return PPSIM_TYPE_DARK;116 if (!strcasecmp (typeStr, "FLAT")) return PPSIM_TYPE_FLAT;114 if (!strcasecmp (typeStr, "BIAS")) return PPSIM_TYPE_BIAS; 115 if (!strcasecmp (typeStr, "DARK")) return PPSIM_TYPE_DARK; 116 if (!strcasecmp (typeStr, "FLAT")) return PPSIM_TYPE_FLAT; 117 117 if (!strcasecmp (typeStr, "OBJECT")) return PPSIM_TYPE_OBJECT; 118 118 psAbort("Should never get here."); … … 174 174 if (binning <= 0) { 175 175 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Binning (%d) is non-positive.", binning); 176 exit(PS_EXIT_CONFIG_ERROR);176 exit(PS_EXIT_CONFIG_ERROR); 177 177 } 178 178 return true; … … 181 181 // Get a value from the command-line arguments and add it to recipe options 182 182 float ppSimArgToRecipeF32(bool *status, 183 psMetadata *options, // Target to which to add value184 const char *recipeName, // Name for value in the recipe185 psMetadata *arguments, // Command-line arguments186 const char *argName// Argument name in the command-line arguments183 psMetadata *options, // Target to which to add value 184 const char *recipeName, // Name for value in the recipe 185 psMetadata *arguments, // Command-line arguments 186 const char *argName // Argument name in the command-line arguments 187 187 ) 188 188 { … … 198 198 // Get a value from the command-line arguments and add it to recipe options 199 199 int ppSimArgToRecipeS32(bool *status, 200 psMetadata *options, // Target to which to add value201 const char *recipeName, // Name for value in the recipe202 psMetadata *arguments, // Command-line arguments203 const char *argName// Argument name in the command-line arguments200 psMetadata *options, // Target to which to add value 201 const char *recipeName, // Name for value in the recipe 202 psMetadata *arguments, // Command-line arguments 203 const char *argName // Argument name in the command-line arguments 204 204 ) 205 205 { … … 214 214 // Get a value from the command-line arguments and add it to recipe options 215 215 bool ppSimArgToRecipeBool(bool *status, 216 psMetadata *options, // Target to which to add value217 const char *recipeName, // Name for value in the recipe218 psMetadata *arguments, // Command-line arguments219 const char *argName// Argument name in the command-line arguments216 psMetadata *options, // Target to which to add value 217 const char *recipeName, // Name for value in the recipe 218 psMetadata *arguments, // Command-line arguments 219 const char *argName // Argument name in the command-line arguments 220 220 ) 221 221 { … … 231 231 // if it is not specified, do not override the existing recipe value 232 232 char *ppSimArgToRecipeStr(bool *status, 233 psMetadata *options, // Target to which to add value234 const char *recipeName, // Name for value in the recipe235 psMetadata *arguments, // Command-line arguments236 const char *argName// Argument name in the command-line arguments233 psMetadata *options, // Target to which to add value 234 const char *recipeName, // Name for value in the recipe 235 psMetadata *arguments, // Command-line arguments 236 const char *argName // Argument name in the command-line arguments 237 237 ) 238 238 { … … 241 241 char *value = psMetadataLookupStr(&myStatus, arguments, argName); // Value of interest 242 242 if (status) { 243 *status = myStatus;243 *status = myStatus; 244 244 } 245 245 if (!value) return NULL; … … 248 248 } 249 249 250 float ppSimGetZeroPoint (psMetadata *recipe, char *filter) {251 252 bool mdok;253 float zp;250 float ppSimGetZeroPoint(psMetadata *recipe, const char *filter) 251 { 252 PS_ASSERT_METADATA_NON_NULL(recipe, NAN); 253 PS_ASSERT_STRING_NON_EMPTY(filter, NAN); 254 254 255 255 // use the filter to get the zeropoint from the recipe 256 psMetadataItem *zpItem = psMetadataLookup (recipe, "ZEROPTS"); 257 // check that item is multi... 258 259 psArray *entries = psListToArray (zpItem->data.list); 260 261 // search for matching filter 262 for (int i = 0; i < entries->n; i++) { 263 psMetadataItem *item = entries->data[i]; 264 psMetadata *entry = item->data.V; 265 266 char *filterName = psMetadataLookupStr (&mdok, entry, "FILTER"); 267 assert (filterName); 268 269 if (strcmp(filterName, filter)) continue; 270 271 zp = psMetadataLookupF32 (&mdok, entry, "ZERO_PT"); 272 assert (mdok); 273 psFree (entries); 274 return zp; 275 } 276 psFree (entries); 277 return NAN; 256 psMetadata *zeropoints = psMetadataLookupMetadata(NULL, recipe, "ZEROPTS"); 257 if (!zeropoints) { 258 psError(PS_ERR_UNKNOWN, false, "Unable to find ZEROPTS in recipe"); 259 return NAN; 260 } 261 262 return psMetadataLookupF32(NULL, zeropoints, filter); 278 263 } 279 264 … … 295 280 296 281 for (int i = 0; i < sources->n; i++) { 297 pmSource *source = sources->data[i];282 pmSource *source = sources->data[i]; 298 283 299 284 // allocate image, weight, mask arrays for each peak (square of radius OUTER)
Note:
See TracChangeset
for help on using the changeset viewer.
