Changeset 18011 for trunk/ppSim/src/ppSimUtils.c
- Timestamp:
- Jun 8, 2008, 4:03:31 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimUtils.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimUtils.c
r17557 r18011 15 15 float dec0 = psMetadataLookupF32(NULL, recipe, "DEC"); // Boresight Dec (radians) 16 16 float pa = psMetadataLookupF32(NULL, recipe, "PA"); // Position angle (radians) 17 float scale = psMetadataLookupF32(NULL, recipe, " SCALE"); // plate scale in arcsec / pixel17 float scale = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE"); // plate scale in arcsec / pixel 18 18 scale *= M_PI / 3600.0 / 180.0; // convert plate scale to radians/pixel 19 19 20 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y20 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 21 21 22 22 float x0 = 0.0, y0 = 0.0; … … 95 95 } 96 96 97 char *ppSimTypeToString (ppSimType type) { 98 99 char *typeStr; 100 101 switch (type) { 102 case PPSIM_TYPE_BIAS: typeStr = psStringCopy ("BIAS"); break; 103 case PPSIM_TYPE_DARK: typeStr = psStringCopy ("DARK"); break; 104 case PPSIM_TYPE_FLAT: typeStr = psStringCopy ("FLAT"); break; 105 case PPSIM_TYPE_OBJECT: typeStr = psStringCopy ("OBJECT"); break; 106 default: 107 psAbort("Should never get here."); 108 } 109 return (typeStr); 110 } 111 112 ppSimType ppSimTypeFromString (char *typeStr) { 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; 117 if (!strcasecmp (typeStr, "OBJECT")) return PPSIM_TYPE_OBJECT; 118 psAbort("Should never get here."); 119 } 120 97 121 bool ppSimUpdateConceptsFPA (pmFPA *fpa, pmConfig *config) { 98 122 … … 103 127 float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time 104 128 105 const char *filter = psMetadataLookupStr(NULL, config->arguments, "FILTER"); // Filter name129 const char *filter = psMetadataLookupStr(NULL, recipe, "FILTER"); // Filter name 106 130 if (!filter) { 107 131 filter = "NONE"; 108 132 } 109 133 110 ppSimType type = psMetadataLookupS32(NULL, config->arguments, "TYPE"); // Type of image to simulate 111 112 // Update FPA concepts 113 const char *typeStr; // Exposure type String 114 switch (type) { 115 case PPSIM_TYPE_BIAS: typeStr = "BIAS"; break; 116 case PPSIM_TYPE_DARK: typeStr = "DARK"; break; 117 case PPSIM_TYPE_FLAT: typeStr = "FLAT"; break; 118 case PPSIM_TYPE_OBJECT: typeStr = "OBJECT"; break; 119 default: 120 psAbort("Should never get here."); 121 } 122 123 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBSTYPE", PS_META_REPLACE, 124 "Observation type", typeStr); 125 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBJECT", PS_META_REPLACE, 126 "Observation name", typeStr); 127 psMetadataAddF32(fpa->concepts, PS_LIST_TAIL, "FPA.EXPTIME", PS_META_REPLACE, 128 "Exposure time (sec)", expTime); 134 char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate 135 136 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBSTYPE", PS_META_REPLACE, "Observation type", typeStr); 137 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBJECT", PS_META_REPLACE, "Observation name", typeStr); 138 psMetadataAddF32(fpa->concepts, PS_LIST_TAIL, "FPA.EXPOSURE", PS_META_REPLACE, "Exposure time (sec)", expTime); 129 139 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.FILTERID", PS_META_REPLACE, "Filter name", filter); 130 140 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.FILTER", PS_META_REPLACE, "Filter name", filter); … … 139 149 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 140 150 141 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y151 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 142 152 float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time 143 153 … … 153 163 return true; 154 164 } 165 166 bool ppSimRecipeValidation (pmConfig *config) { 167 168 bool status; 169 170 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 171 172 int binning = psMetadataLookupS32(&status, recipe, "BINNING"); // Binning in x and y 173 if (binning <= 0) { 174 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Binning (%d) is non-positive.", binning); 175 exit(PS_EXIT_CONFIG_ERROR); 176 } 177 return true; 178 } 179 180 // Get a value from the command-line arguments and add it to recipe options 181 float ppSimArgToRecipeF32(bool *status, 182 psMetadata *options, // Target to which to add value 183 const char *recipeName, // Name for value in the recipe 184 psMetadata *arguments, // Command-line arguments 185 const char *argName // Argument name in the command-line arguments 186 ) 187 { 188 bool myStatus; 189 float value = psMetadataLookupF32(&myStatus, arguments, argName); // Value of interest 190 if (status) { *status = myStatus; } 191 if (isnan(value)) return value; 192 193 psMetadataAddF32(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value); 194 return value; 195 } 196 197 // Get a value from the command-line arguments and add it to recipe options 198 int ppSimArgToRecipeS32(bool *status, 199 psMetadata *options, // Target to which to add value 200 const char *recipeName, // Name for value in the recipe 201 psMetadata *arguments, // Command-line arguments 202 const char *argName // Argument name in the command-line arguments 203 ) 204 { 205 bool myStatus; 206 int value = psMetadataLookupS32(&myStatus, arguments, argName); // Value of interest 207 if (status) { *status = myStatus; } 208 209 psMetadataAddS32(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value); 210 return value; 211 } 212 213 // Get a value from the command-line arguments and add it to recipe options 214 bool ppSimArgToRecipeBool(bool *status, 215 psMetadata *options, // Target to which to add value 216 const char *recipeName, // Name for value in the recipe 217 psMetadata *arguments, // Command-line arguments 218 const char *argName // Argument name in the command-line arguments 219 ) 220 { 221 bool myStatus; 222 bool value = psMetadataLookupS32(&myStatus, arguments, argName); // Value of interest 223 if (status) { *status = myStatus; } 224 225 psMetadataAddBool(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value); 226 return value; 227 } 228 229 // Get a value from the command-line arguments and add it to recipe options 230 char *ppSimArgToRecipeStr(bool *status, 231 psMetadata *options, // Target to which to add value 232 const char *recipeName, // Name for value in the recipe 233 psMetadata *arguments, // Command-line arguments 234 const char *argName // Argument name in the command-line arguments 235 ) 236 { 237 bool myStatus; 238 239 char *value = psMetadataLookupStr(&myStatus, arguments, argName); // Value of interest 240 if (status) { 241 *status = myStatus; 242 } 243 psMetadataAddStr(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value); 244 return value; 245 } 246 247 float ppSimGetZeroPoint (psMetadata *recipe, char *filter) { 248 249 bool mdok; 250 float zp; 251 252 // use the filter to get the zeropoint from the recipe 253 psMetadataItem *zpItem = psMetadataLookup (recipe, "ZEROPTS"); 254 // check that item is multi... 255 256 psArray *entries = psListToArray (zpItem->data.list); 257 258 // search for matching filter 259 for (int i = 0; i < entries->n; i++) { 260 psMetadataItem *item = entries->data[i]; 261 psMetadata *entry = item->data.V; 262 263 char *filterName = psMetadataLookupStr (&mdok, entry, "FILTER"); 264 assert (filterName); 265 266 if (strcmp(filterName, filter)) continue; 267 268 zp = psMetadataLookupF32 (&mdok, entry, "ZERO_PT"); 269 assert (mdok); 270 psFree (entries); 271 return zp; 272 } 273 psFree (entries); 274 return NAN; 275 } 276 277 psArray *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 286 bool 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.
