Changeset 36588
- Timestamp:
- Mar 14, 2014, 1:59:13 PM (12 years ago)
- Location:
- tags/ipp-20140114/psphot/src
- Files:
-
- 3 edited
-
psphotFullForceSummary.c (modified) (2 diffs)
-
psphotFullForceSummaryReadout.c (modified) (3 diffs)
-
psphotGalaxyShape.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-20140114/psphot/src/psphotFullForceSummary.c
r36441 r36588 78 78 usage(); 79 79 } 80 if ((N = psArgumentGet(argc, argv, "-cff"))) { 81 if (argc <= N+1) { 82 psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1); 83 usage(); 84 } 85 psArgumentRemove(N, &argc, argv); 86 87 // We read CFF file as table not as sources. All we want are the nominal parameters input to psphotFullForce 88 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "CFF_FILE", 0, "CFF file with nominal parameters", argv[N]); 89 psArgumentRemove(N, &argc, argv); 90 } else { 91 psErrorStackPrint(stderr, "-cff must be supplied."); 92 usage(); 93 } 80 94 81 95 if (argc < 2) { … … 148 162 } 149 163 output->save = true; 164 165 // We read cff file as a table not as sources 166 psString cffName = psMetadataLookupStr(NULL, config->arguments, "CFF_FILE"); 167 if (!cffName) { 168 psError(PSPHOT_ERR_CONFIG, true, "CFF_FILE is missing from arguments"); 169 return false; 170 } 171 psString resolvedName = pmConfigConvertFilename(cffName, config, false, false); 172 if (!resolvedName) { 173 psError(PSPHOT_ERR_CONFIG, false, "failed to resolve CFF_FILE %s", cffName); 174 return false; 175 } 176 psFits *fits = psFitsOpen(resolvedName, "r"); 177 if (!fits) { 178 psError(PSPHOT_ERR_CONFIG, false, "failed to open fits CFF_FILE %s", resolvedName); 179 return false; 180 } 181 psArray *inTable = psFitsReadTable(fits); 182 if (!inTable) { 183 psError(PSPHOT_ERR_CONFIG, false, "failed to read cff fits table from CFF_FILE %s", resolvedName); 184 return false; 185 } 186 psFitsClose(fits); 187 188 // Convert to an array indexed by ID 189 psArray *sortedTable = psArrayAlloc(4*inTable->n); 190 for (int i=0; i<inTable->n; i++) { 191 psMetadata *row = inTable->data[i]; 192 psS32 ID = psMetadataLookupS32(&status, row, "ID"); 193 if (ID >= sortedTable->n) { 194 sortedTable = psArrayRealloc(sortedTable, 2*ID); 195 } 196 if (sortedTable->data[ID]) { 197 psError(PSPHOT_ERR_CONFIG, true, "Duplicate row with ID %d", ID); 198 return false; 199 } 200 sortedTable->data[ID] = psMemIncrRefCounter(row); 201 } 202 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "CFF_TABLE", PS_META_REPLACE, "cff table", sortedTable); 203 psFree(inTable); 204 psFree(sortedTable); 150 205 151 206 return true; -
tags/ipp-20140114/psphot/src/psphotFullForceSummaryReadout.c
r36441 r36588 14 14 psArray *zeroPt; 15 15 psArray *exptime; 16 psArray *cffTable; 16 17 } galaxyShapeOptions; 17 18 … … 69 70 if (!setOptions(&options, readout, recipe, true)) { 70 71 psError (PS_ERR_UNKNOWN, false, "problem determining galaxy shape options."); 72 return false; 73 } 74 options.cffTable = psMetadataLookupPtr(NULL, config->arguments, "CFF_TABLE"); 75 if (!options.cffTable) { 76 psError (PS_ERR_UNKNOWN, true, "Cannot find cff table in arguments."); 71 77 return false; 72 78 } … … 309 315 // copy the best fit params to the model 310 316 psEllipseAxes axes = pmPSF_ModelToAxes(outSrc->modelEXT->params->data.F32, outSrc->modelEXT->type); 311 axes.major *= options->rMajor->data.F32[min_j]; 312 axes.minor *= options->rMinor->data.F32[min_j]; 317 if (outSrc->seq >= options->cffTable->n) { 318 psError(PS_ERR_PROGRAMMING, true, "object sequence number %d is larger than cff table length %ld", 319 outSrc->seq, options->cffTable->n); 320 return NULL; 321 } 322 psMetadata *row = options->cffTable->data[outSrc->seq]; 323 if (!row) { 324 psError (PS_ERR_PROGRAMMING, true, "NO cff data for object %d", outSrc->seq); 325 psFree(outSrc); 326 return NULL; 327 } 328 bool mdok; 329 psF32 rMajor = psMetadataLookupF32(&mdok, row, "R_MAJOR"); 330 if (!mdok) { 331 psError (PS_ERR_PROGRAMMING, true, "can't find R_MAJOR for object %d", outSrc->seq); 332 psFree(outSrc); 333 return NULL; 334 } 335 psF32 rMinor = psMetadataLookupF32(&mdok, row, "R_MINOR"); 336 if (!mdok) { 337 psError (PS_ERR_PROGRAMMING, true, "can't find R_MINOR for object %d", outSrc->seq); 338 psFree(outSrc); 339 return NULL; 340 } 341 axes.major = rMajor * options->rMajor->data.F32[min_j]; 342 axes.minor = rMinor * options->rMinor->data.F32[min_j]; 313 343 pmPSF_AxesToModel (outSrc->modelEXT->params->data.F32, axes, outSrc->modelEXT->type); 314 344 outSrc->modelEXT->chisq = minChisq; -
tags/ipp-20140114/psphot/src/psphotGalaxyShape.c
r36441 r36588 274 274 275 275 int i = source->galaxyFits->chisq->n - 1; 276 float thisChisq = source->galaxyFits->chisq->data.F32[i]; 277 if (isfinite(thisChisq) && (!isfinite(chisqBest) || thisChisq < chisqBest)) { 278 chisqBest = thisChisq; 279 fRmajorBest = fRmajor; 280 fRminorBest = fRminor; 276 float flux = source->galaxyFits->Flux->data.F32[i]; 277 if (isfinite(flux)) { 278 float thisChisq = source->galaxyFits->chisq->data.F32[i]; 279 if (isfinite(thisChisq) && isfinite(flux) && (!isfinite(chisqBest) || thisChisq < chisqBest)) { 280 chisqBest = thisChisq; 281 fRmajorBest = fRmajor; 282 fRminorBest = fRminor; 283 } 281 284 } 285 // reset I0 to avoid potential problems on the next iteration 286 PAR[PM_PAR_I0] = 1.0; 282 287 } 283 288 } 284 289 290 #define SAVE_BEST_MODEL 285 291 #ifdef SAVE_BEST_MODEL 286 292 // Save model with smallest chisq … … 301 307 psphotGalaxyShapeSource (pcm, source, maskVal, psfSize, false); 302 308 303 // Replace modelEXT with this model 304 // XXX: only do this if the model is good 305 psFree (source->modelEXT); 306 307 source->modelEXT = psMemIncrRefCounter (pcm->modelConv); 308 source->type = PM_SOURCE_TYPE_EXTENDED; 309 source->mode |= PM_SOURCE_MODE_EXTMODEL; 310 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 311 312 // cache the model flux 313 pmPCMCacheModel (source, maskVal, psfSize, fitOptions->nsigma); 309 // Replace modelEXT with this model, if the model is good 310 if (isfinite(PAR[PM_PAR_I0])) { 311 psFree (source->modelEXT); 312 313 source->modelEXT = psMemIncrRefCounter (pcm->modelConv); 314 source->type = PM_SOURCE_TYPE_EXTENDED; 315 source->mode |= PM_SOURCE_MODE_EXTMODEL; 316 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 317 318 // cache the model flux 319 pmPCMCacheModel (source, maskVal, psfSize, fitOptions->nsigma); 320 } 314 321 } 315 322
Note:
See TracChangeset
for help on using the changeset viewer.
