Changeset 41290 for trunk/psastro/src/psastroLoadGhosts.c
- Timestamp:
- Feb 25, 2020, 9:55:36 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroLoadGhosts.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroLoadGhosts.c
r40552 r41290 13 13 # include "psastroInternal.h" 14 14 15 // These are only used locally: 16 bool psastroLoadGhostsGPC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile); 17 bool psastroLoadGhostsHSC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile); 18 15 19 # define GET_2D_POLY(NAME,OUT) \ 16 20 md = psMetadataLookupMetadata (&status, ghostModel, NAME); \ … … 41 45 */ 42 46 43 44 45 47 bool psastroLoadGhosts (pmConfig *config) { 48 49 bool status; 50 51 psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions"); 52 53 // select the current recipe 54 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE); 55 if (!recipe) { 56 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe"); 57 return false; 58 } 59 60 // do we want to mask ghosts? 61 bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST"); 62 if (!REFSTAR_MASK_GHOST) return true; 63 64 // choose ghost model file 65 char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL"); 66 if (!strcasecmp(ghostFile, "NONE")) return true; 67 68 // load ghost model metadata structure 69 psMetadata *ghostModel = NULL; 70 if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) { 71 psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model"); 72 return false; 73 } 74 75 // test for items which are used by either the GPC or HSC ghost models: 76 psMetadataItem *item = NULL; 77 78 // test for required HSC ghost model elements 79 item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC"); 80 if (item) { 81 status = psastroLoadGhostsHSC (config, recipe, ghostModel, ghostFile); 82 if (!status) goto escape; 83 } 84 85 // test for required GPC ghost model elements 86 item = psMetadataLookup(ghostModel, "GHOST.CENTER.X"); 87 if (item) { 88 status = psastroLoadGhostsGPC (config, recipe, ghostModel, ghostFile); 89 if (!status) goto escape; 90 } 91 92 escape: 93 psFree (ghostModel); 94 return status; 95 } 96 97 bool psastroLoadGhostsGPC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile) { 46 98 47 99 bool status; … … 57 109 psPolynomial1D *innerMajor = NULL; 58 110 psPolynomial1D *innerMinor = NULL; 59 psMetadata *ghostModel = NULL;60 61 psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");62 63 // XXX this needs to be camera-dependent64 if (0) {65 psWarning("Doing the hard coded switch to HSC ghosts still.");66 return (psastroLoadGhostsHSC(config));67 }68 69 psWarning("hard coded switch to GPC ghosts.");70 71 // select the current recipe72 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);73 if (!recipe) {74 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");75 return false;76 }77 78 bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST");79 if (!REFSTAR_MASK_GHOST) return true;80 81 82 char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");83 if (!strcasecmp(ghostFile, "NONE")) return true;84 85 if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {86 psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");87 return false;88 }89 111 90 112 pmFPAview *view = pmFPAviewAlloc (0); 91 92 GET_2D_POLY ("GHOST.CENTER.X", centerX);93 GET_2D_POLY ("GHOST.CENTER.Y", centerY);94 95 GET_1D_POLY ("GHOST.OUTER.MAJOR", outerMajor);96 GET_1D_POLY ("GHOST.OUTER.MINOR", outerMinor);97 GET_1D_POLY ("GHOST.INNER.MAJOR", innerMajor);98 GET_1D_POLY ("GHOST.INNER.MINOR", innerMinor);99 113 100 114 // select the input astrometry data (also carries the refstars) … … 106 120 pmFPA *fpa = astrom->fpa; 107 121 108 // really error-out here? or just skip? 122 GET_2D_POLY ("GHOST.CENTER.X", centerX); 123 GET_2D_POLY ("GHOST.CENTER.Y", centerY); 124 125 GET_1D_POLY ("GHOST.OUTER.MAJOR", outerMajor); 126 GET_1D_POLY ("GHOST.OUTER.MINOR", outerMinor); 127 GET_1D_POLY ("GHOST.INNER.MAJOR", innerMajor); 128 GET_1D_POLY ("GHOST.INNER.MINOR", innerMinor); 129 130 // raise an error if the config is broken 109 131 if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) { 110 ps LogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");132 psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe"); 111 133 goto escape; 112 134 } … … 253 275 psFree (outerMajor); 254 276 psFree (outerMinor); 255 psFree (ghostModel);256 277 psFree (view); 257 278 return true; … … 264 285 psFree (outerMajor); 265 286 psFree (outerMinor); 266 psFree (ghostModel);267 287 psFree (view); 268 288 return false; 269 289 } 270 271 272 290 273 bool psastroLoadGhostsHSC (pmConfig *config) { 291 // This function adds the ghost mask elements to the ghostReadout->analysis structures. 292 // We return false and raise an error on a config problem. 293 bool psastroLoadGhostsHSC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile) { 294 274 295 bool status; 275 296 pmChip *chip = NULL; … … 277 298 pmReadout *readout = NULL; 278 299 float zeropt, exptime, MAX_MAG; 279 psMetadata *ghostModel = NULL;280 300 psVector *C_terms = NULL; 281 301 psVector *R_terms = NULL; 282 302 float glintPixelScale = 0.0; 283 303 284 psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");285 286 // select the current recipe287 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);288 if (!recipe) {289 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");290 return false;291 }292 293 bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST");294 if (!REFSTAR_MASK_GHOST) return true;295 296 // Load model from file297 char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");298 if (!strcasecmp(ghostFile, "NONE")) return true;299 psLogMsg("psastro", PS_LOG_INFO, "ghost file %s",ghostFile);300 if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {301 psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");302 return false;303 }304 305 304 // Allocate FPA and refstars 306 305 pmFPAview *view = pmFPAviewAlloc (0); 306 307 307 // select the input astrometry data (also carries the refstars) 308 308 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); … … 314 314 315 315 char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID"); 316 316 317 psMetadataItem *item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC"); 317 318 if (!item) { 318 psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC data missing");319 return false;319 psError(PSASTRO_ERR_CONFIG, true, "GHOST.MODEL.HSC data missing"); 320 goto escape; 320 321 } 321 322 if (item->type != PS_DATA_METADATA_MULTI) { 322 psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC not multi");323 return false;323 psError(PSASTRO_ERR_CONFIG, true, "GHOST.MODEL.HSC not multi"); 324 goto escape; 324 325 } 325 326 … … 328 329 while ((refItem = psListGetAndIncrement(iter))) { 329 330 if (refItem->type != PS_DATA_METADATA) { 330 psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC entry not metadata");331 return false;331 psError(PSASTRO_ERR_CONFIG, true, "GHOST.MODEL.HSC entry not metadata"); 332 goto escape; 332 333 } 333 334 char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER"); 334 335 if (!status) { 335 // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");336 336 continue; 337 337 } … … 343 343 } 344 344 345 // really error-out here? or just skip?345 // if a ghost model is not defined for a filter, skip HSC ghost model for that filter (no error) 346 346 if (!R_terms) { 347 347 psLogMsg ("psastro", PS_LOG_INFO, "failed to find HSC ghost model for filter %s", filter); 348 goto escape;349 } 350 351 // really error-out here? or just skip?348 goto giveup; 349 } 350 351 // if a filter is defined, but the recipe elements are missing, the config is broken. 352 352 if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) { 353 psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");354 goto escape;353 psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe"); 354 goto escape; 355 355 } 356 356 … … 430 430 431 431 if (ghostChip) { 432 psLogMsg("psastro",PS_LOG_INFO, 433 // psTrace("psastro.ghost",5, 432 psLogMsg("psastro", PS_LOG_INFO, 434 433 " in ghost: %d/%ld: ref: (%f,%f) or (%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)", 435 434 i,refstars->n, … … 441 440 ghost->inner.major,ghost->inner.minor,ghost->inner.theta, 442 441 ghost->outer.major,ghost->outer.minor,ghost->outer.theta); 443 } 444 else {445 psTrace("psastro.ghost",5," in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)",442 } else { 443 psTrace("psastro.ghost", 5, 444 " in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)", 446 445 i,refstars->n, 447 446 ref->FP->x,ref->FP->y, … … 451 450 ghost->outer.major,ghost->outer.minor,ghost->outer.theta); 452 451 } 453 454 455 452 456 453 if (!ghostChip) goto skip; … … 475 472 psFree (ghosts); 476 473 } 477 478 474 psArrayAdd (ghosts, 100, ghost); 479 475 480 476 skip: 481 482 477 psFree (ghost); 483 478 } … … 488 483 psastroExtractFreeChipBounds(); 489 484 485 giveup: 490 486 psFree (C_terms); 491 487 psFree (R_terms); 492 // psFree (ghostModel);493 488 psFree (view); 494 489 return true; … … 497 492 psFree (C_terms); 498 493 psFree (R_terms); 499 // psFree (ghostModel);500 494 psFree (view); 501 495 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
