- Timestamp:
- Jul 17, 2014, 12:30:45 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-ops-20130712/psModules
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
src/objects (modified) (1 prop)
-
src/objects/pmSourceIO.c (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-ops-20130712/psModules
- Property svn:mergeinfo deleted
-
branches/eam_branches/ipp-ops-20130712/psModules/src/objects
- Property svn:ignore
-
old new 12 12 pmSourceIO_CMF_PS1_V1.v1.c 13 13 pmSourceIO_CMF_PS1_V4.c 14 pmSourceIO_CMF_PS1_V5.c 14 15 pmSourceIO_CMF_PS1_SV1.c 15 16 pmSourceIO_CMF_PS1_SV2.c 17 pmSourceIO_CMF_PS1_SV3.c 16 18 pmSourceIO_CMF_PS1_DV1.c 17 19 pmSourceIO_CMF_PS1_DV2.c 18 20 pmSourceIO_CMF_PS1_DV3.c 19 21 pmSourceIO_CMF_PS1_DV4.c
-
- Property svn:ignore
-
branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.c
r35610 r37066 40 40 #include "pmMoments.h" 41 41 #include "pmModelFuncs.h" 42 #include "pmModelClass.h" 42 43 #include "pmModel.h" 43 44 #include "pmModelUtils.h" 44 #include "pmModelClass.h"45 45 #include "pmSourceMasks.h" 46 46 #include "pmSourceExtendedPars.h" 47 47 #include "pmSourceDiffStats.h" 48 48 #include "pmSourceSatstar.h" 49 #include "pmSourceLensing.h" 49 50 #include "pmSource.h" 50 51 #include "pmSourceFitModel.h" … … 61 62 static bool pmReadoutReadXFIT(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 62 63 static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 64 static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 63 65 64 66 // lookup the EXTNAME values used for table data and image header segments … … 69 71 psString *xfitname, // Extension name for extended fitted measurements 70 72 psString *xradname, // Extension name for radial apertures 73 psString *xgalname, // Extension name for galaxy shapes 71 74 const pmFPAfile *file, // File of interest 72 75 const pmFPAview *view // View to level of interest … … 140 143 } 141 144 *xradname = pmFPAfileNameFromRule (rule, file, view); 145 } 146 147 // EXTNAME for radial apertures 148 if (xgalname) { 149 const char *rule = psMetadataLookupStr(&status, menu, "CMF.XGAL"); 150 if (!rule) { 151 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XGAL in EXTNAME.RULES in camera.config"); 152 return false; 153 } 154 *xgalname = pmFPAfileNameFromRule (rule, file, view); 142 155 } 143 156 … … 352 365 # define PM_SOURCES_WRITE(NAME,TYPE) \ 353 366 if (!strcmp (exttype, NAME)) { \ 354 status &= pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \367 status = pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \ 355 368 if (xsrcname) { \ 356 369 status &= pmSourcesWrite_##TYPE##_XSRC(file->fits, readout, sources, file->header, xsrcname, recipe); \ … … 362 375 status &= pmSourcesWrite_##TYPE##_XRAD (file->fits, readout, sources, file->header, xradname, recipe); \ 363 376 } \ 377 if (xgalname) { \ 378 status &= pmSourcesWrite_##TYPE##_XGAL (file->fits, readout, sources, xgalname, recipe); \ 379 } \ 364 380 } 365 381 … … 464 480 } 465 481 466 // if this is not TRUE, the output files only contain the psf measurements. 467 bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS"); 482 // if none of these are TRUE, the output files only contain the psf measurements. 483 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 484 bool doAnnuli = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI"); 485 bool XSRC_OUTPUT = doPetrosian || doAnnuli; 468 486 bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS"); 469 487 bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES"); 488 bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES"); 470 489 471 490 // define the EXTNAME values for the different data segments: … … 476 495 psString xfitname = NULL; 477 496 psString xradname = NULL; 497 psString xgalname = NULL; 478 498 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, 479 499 XSRC_OUTPUT ? &xsrcname : NULL, 480 500 XFIT_OUTPUT ? &xfitname : NULL, 481 501 XRAD_OUTPUT ? &xradname : NULL, 502 XGAL_OUTPUT ? &xgalname : NULL, 482 503 file, view)) { 483 504 return false; … … 563 584 psMetadataAddStr (outhead, PS_LIST_TAIL, "XRADNAME", PS_META_REPLACE, "name of XRAD table extension", xradname); 564 585 } 586 if (xgalname) { 587 psMetadataAddStr (outhead, PS_LIST_TAIL, "XGALNAME", PS_META_REPLACE, "name of XGAL table extension", xgalname); 588 } 565 589 566 590 // these are case-sensitive since the EXTYPE is case-sensitive 567 status = true;591 status = false; 568 592 PM_SOURCES_WRITE("SMPDATA", SMPDATA); 569 593 PM_SOURCES_WRITE("PS1_DEV_0", PS1_DEV_0); … … 574 598 PM_SOURCES_WRITE("PS1_V3", CMF_PS1_V3); 575 599 PM_SOURCES_WRITE("PS1_V4", CMF_PS1_V4); 600 PM_SOURCES_WRITE("PS1_V5", CMF_PS1_V5); 576 601 PM_SOURCES_WRITE("PS1_SV1", CMF_PS1_SV1); 577 602 PM_SOURCES_WRITE("PS1_SV2", CMF_PS1_SV2); 603 PM_SOURCES_WRITE("PS1_SV3", CMF_PS1_SV3); 578 604 PM_SOURCES_WRITE("PS1_DV1", CMF_PS1_DV1); 579 605 PM_SOURCES_WRITE("PS1_DV2", CMF_PS1_DV2); 580 606 PM_SOURCES_WRITE("PS1_DV3", CMF_PS1_DV3); 607 PM_SOURCES_WRITE("PS1_DV4", CMF_PS1_DV4); 581 608 582 609 psFree (outhead); … … 609 636 psFree (xfitname); 610 637 psFree (xradname); 638 psFree (xgalname); 611 639 psFree (deteffname); 612 640 … … 620 648 psFree (xfitname); 621 649 psFree (xradname); 650 psFree (xgalname); 622 651 psFree (deteffname); 623 652 return false; 624 653 654 case PM_FPA_FILE_CFF: { 655 // determine the output table format 656 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT"); 657 if (!status) { 658 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data"); 659 return false; 660 } 661 662 hdu = pmFPAviewThisHDU (view, fpa); 663 pmConfigConformHeader(hdu->header, file->format); 664 psFitsWriteBlank (file->fits, hdu->header, NULL); 665 file->header = hdu->header; 666 file->wrote_phu = true; 667 if (!pmSourcesWrite_CFF(readout, file->fits, sources, hdu->header, recipe)) { 668 psError(PS_ERR_UNKNOWN, false, "failed to write CFF"); 669 return false; 670 } 671 break; 672 } 673 625 674 default: 626 675 fprintf (stderr, "warning: type mismatch\n"); … … 914 963 psArray *sources = NULL; 915 964 pmHDU *hdu; 965 966 // define the EXTNAME values for the different data segments: 967 psString headname = NULL; 968 psString dataname = NULL; 969 psString deteffname = NULL; 970 psString xsrcname = NULL; 971 psString xfitname = NULL; 972 psString xradname = NULL; 973 psString xgalname = NULL; 974 975 psMetadata *tableHeader = NULL; 976 char *xtension = NULL; 916 977 917 978 switch (file->type) { … … 963 1024 hdu = pmFPAviewThisHDU (view, file->fpa); 964 1025 965 // define the EXTNAME values for the different data segments:966 psString headname = NULL;967 psString dataname = NULL;968 psString deteffname = NULL;969 psString xsrcname = NULL;970 psString xfitname = NULL;971 psString xradname = NULL;972 973 1026 // determine the output table format. Assume if we need to output extendend source 974 1027 // parameters that they may exist in the input. … … 981 1034 } 982 1035 983 // if this is not TRUE, the output files only contain the psf measurements. 984 bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS"); 1036 // if none of these are TRUE, we only read the psf measurements 1037 // XXX: shouldn't we look for these extensions and read the regardless of the recipe values? 1038 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 1039 bool doAnnuli = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI"); 1040 bool XSRC_OUTPUT = doPetrosian || doAnnuli; 985 1041 bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS"); 986 1042 bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES"); 1043 bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES"); 987 1044 988 1045 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, … … 990 1047 XFIT_OUTPUT ? &xfitname : NULL, 991 1048 XRAD_OUTPUT ? &xradname : NULL, 1049 XGAL_OUTPUT ? &xgalname : NULL, 992 1050 file, view)) { 993 1051 return false; … … 1033 1091 } 1034 1092 1035 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header1093 tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1036 1094 if (!tableHeader) psAbort("cannot read table header"); 1037 1095 1038 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");1096 xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1039 1097 if (!xtension) psAbort("cannot read table type"); 1040 1098 if (strcmp (xtension, "BINTABLE")) { … … 1062 1120 PM_SOURCES_READ_PSF("PS1_V3", CMF_PS1_V3); 1063 1121 PM_SOURCES_READ_PSF("PS1_V4", CMF_PS1_V4); 1122 PM_SOURCES_READ_PSF("PS1_V5", CMF_PS1_V5); 1064 1123 PM_SOURCES_READ_PSF("PS1_SV1", CMF_PS1_SV1); 1065 1124 PM_SOURCES_READ_PSF("PS1_SV2", CMF_PS1_SV2); 1125 PM_SOURCES_READ_PSF("PS1_SV3", CMF_PS1_SV3); 1066 1126 PM_SOURCES_READ_PSF("PS1_DV1", CMF_PS1_DV1); 1067 1127 PM_SOURCES_READ_PSF("PS1_DV2", CMF_PS1_DV2); 1068 1128 PM_SOURCES_READ_PSF("PS1_DV3", CMF_PS1_DV3); 1129 PM_SOURCES_READ_PSF("PS1_DV4", CMF_PS1_DV4); 1130 1131 if (!sources) { 1132 psError(PS_ERR_IO, false, "reading CMF data from %s with format %s\n", file->filename, exttype); 1133 return false; 1134 } 1069 1135 1070 1136 long *sourceIndex = NULL; 1071 if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT) { 1137 if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT || XGAL_OUTPUT) { 1138 // Build sourceIndex. Lookup table from source->seq to index in sources array. 1139 // Consists of an array of length max(source->seq) + 1. 1140 1141 // find maximum sequence number 1072 1142 long seq_max = -1; 1073 1143 for (long i = sources->n -1; i >= 0; i--) { … … 1082 1152 } 1083 1153 } 1154 // allocate and initialize the index 1084 1155 sourceIndex = psAlloc((seq_max + 1) * sizeof(long)); 1085 1156 for (long i = 0; i < seq_max; i++) { 1086 1157 sourceIndex[i] = -1; 1087 1158 } 1159 // populate the index 1088 1160 for (long i = 0; i < sources->n; i++) { 1089 1161 pmSource *source = sources->data[i]; … … 1111 1183 } 1112 1184 psFree(xradname); 1185 } 1186 if (XGAL_OUTPUT && xgalname) { 1187 // a cmf file may have an XGAL extension, but it is not required 1188 if (!pmReadoutReadXGAL(file, readout, exttype, hdu->header, xgalname, sources, sourceIndex)) { 1189 // do anything? 1190 } 1191 psFree(xgalname); 1113 1192 } 1114 1193 psFree(sourceIndex); … … 1132 1211 break; 1133 1212 1213 case PM_FPA_FILE_CFF: { 1214 // determine the output table format 1215 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT"); 1216 if (!status) { 1217 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data"); 1218 return false; 1219 } 1220 // read in header, if not yet loaded 1221 hdu = pmFPAviewThisHDU (view, file->fpa); 1222 1223 // look these up in the camera config? 1224 // headrule = {CHIP.NAME}.hdr 1225 // datarule = {CHIP.NAME}.cff 1226 1227 // define the EXTNAME values for the different data segments: 1228 headname = pmFPAfileNameFromRule("{CHIP.NAME}.hdr", file, view); 1229 dataname = pmFPAfileNameFromRule("{CHIP.NAME}.cff", file, view); 1230 1231 // advance to the IMAGE HEADER extension 1232 if (hdu->header == NULL) { 1233 // if the IMAGE header does not exist, we have no data for this view 1234 if (!psFitsMoveExtNameClean (file->fits, headname)) { 1235 readout->data_exists = false; 1236 psFree (headname); 1237 psFree (dataname); 1238 return true; 1239 } 1240 hdu->header = psFitsReadHeader (NULL, file->fits); 1241 } 1242 1243 // advance to the table data extension 1244 // since we have read the IMAGE header, the TABLE header should exist 1245 if (!psFitsMoveExtName (file->fits, dataname)) { 1246 psAbort("cannot find data extension %s in %s", dataname, file->filename); 1247 } 1248 1249 tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1250 if (!tableHeader) psAbort("cannot read table header"); 1251 1252 // verify this is a binary table 1253 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1254 if (!xtension) psAbort("cannot read table type"); 1255 if (strcmp (xtension, "BINTABLE")) { 1256 psWarning ("no binary table in extension %s, skipping\n", dataname); 1257 psFree(tableHeader); 1258 return false; 1259 } 1260 1261 sources = pmSourcesRead_CFF(file->fits, hdu->header, recipe); 1262 1263 psTrace("psModules.objects", 6, "read CMF table from %s : %s : %s", file->filename, headname, dataname); 1264 psFree (headname); 1265 psFree (dataname); 1266 psFree (tableHeader); 1267 } 1268 break; 1269 1134 1270 default: 1135 1271 fprintf (stderr, "warning: type mismatch\n"); … … 1272 1408 PM_SOURCES_READ_XSRC("PS1_V3", CMF_PS1_V3); 1273 1409 PM_SOURCES_READ_XSRC("PS1_V4", CMF_PS1_V4); 1410 PM_SOURCES_READ_XSRC("PS1_V5", CMF_PS1_V5); 1274 1411 PM_SOURCES_READ_XSRC("PS1_SV1", CMF_PS1_SV1); 1275 1412 PM_SOURCES_READ_XSRC("PS1_SV2", CMF_PS1_SV2); 1413 PM_SOURCES_READ_XSRC("PS1_SV3", CMF_PS1_SV3); 1276 1414 PM_SOURCES_READ_XSRC("PS1_DV1", CMF_PS1_DV1); 1277 1415 PM_SOURCES_READ_XSRC("PS1_DV2", CMF_PS1_DV2); 1278 1416 PM_SOURCES_READ_XSRC("PS1_DV3", CMF_PS1_DV3); 1417 PM_SOURCES_READ_XSRC("PS1_DV4", CMF_PS1_DV4); 1279 1418 } 1280 1419 psFree(tableHeader); … … 1311 1450 PM_SOURCES_READ_XFIT("PS1_V3", CMF_PS1_V3); 1312 1451 PM_SOURCES_READ_XFIT("PS1_V4", CMF_PS1_V4); 1452 PM_SOURCES_READ_XFIT("PS1_V5", CMF_PS1_V5); 1313 1453 PM_SOURCES_READ_XFIT("PS1_SV1", CMF_PS1_SV1); 1314 1454 PM_SOURCES_READ_XFIT("PS1_SV2", CMF_PS1_SV2); 1455 PM_SOURCES_READ_XFIT("PS1_SV3", CMF_PS1_SV3); 1315 1456 PM_SOURCES_READ_XFIT("PS1_DV1", CMF_PS1_DV1); 1316 1457 PM_SOURCES_READ_XFIT("PS1_DV2", CMF_PS1_DV2); 1317 1458 PM_SOURCES_READ_XFIT("PS1_DV3", CMF_PS1_DV3); 1459 PM_SOURCES_READ_XFIT("PS1_DV4", CMF_PS1_DV4); 1318 1460 } 1319 1461 psFree(tableHeader); … … 1349 1491 PM_SOURCES_READ_XRAD("PS1_V3", CMF_PS1_V3); 1350 1492 PM_SOURCES_READ_XRAD("PS1_V4", CMF_PS1_V4); 1493 PM_SOURCES_READ_XRAD("PS1_V5", CMF_PS1_V5); 1351 1494 PM_SOURCES_READ_XRAD("PS1_SV1", CMF_PS1_SV1); 1352 1495 PM_SOURCES_READ_XRAD("PS1_SV2", CMF_PS1_SV2); 1496 PM_SOURCES_READ_XRAD("PS1_SV3", CMF_PS1_SV3); 1353 1497 PM_SOURCES_READ_XRAD("PS1_DV1", CMF_PS1_DV1); 1354 1498 PM_SOURCES_READ_XRAD("PS1_DV2", CMF_PS1_DV2); 1355 1499 PM_SOURCES_READ_XRAD("PS1_DV3", CMF_PS1_DV3); 1500 PM_SOURCES_READ_XRAD("PS1_DV4", CMF_PS1_DV4); 1356 1501 } 1357 1502 psFree(tableHeader); 1358 1503 return status; 1359 1504 } 1505 static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char *exttype, psMetadata *hduHeader, psString xgalname, psArray *sources, long *sourceIndex) 1506 { 1507 if (!psFitsMoveExtNameClean (file->fits, xgalname)) { 1508 psTrace ("pmFPAfile", 1, "cannot find xgal extension %s in %s, skipping", xgalname, file->filename); 1509 return false; 1510 } 1511 1512 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1513 if (!tableHeader) psAbort("cannot read table header"); 1514 1515 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1516 if (!xtension) psAbort("cannot read table type"); 1517 if (strcmp (xtension, "BINTABLE")) { 1518 psFree(tableHeader); 1519 psWarning ("no binary table in extension %s, skipping\n", xgalname); 1520 return false; 1521 } 1522 1523 # define PM_SOURCES_READ_XGAL(NAME,TYPE) \ 1524 if (!strcmp (exttype, NAME)) { \ 1525 status = pmSourcesRead_##TYPE##_XGAL(file->fits, readout, hduHeader, tableHeader, sources, sourceIndex); \ 1526 } 1527 1528 bool status = false; 1529 if (file->type == PM_FPA_FILE_CMF) { 1530 PM_SOURCES_READ_XGAL("PS1_V1", CMF_PS1_V1); 1531 PM_SOURCES_READ_XGAL("PS1_V2", CMF_PS1_V2); 1532 PM_SOURCES_READ_XGAL("PS1_V3", CMF_PS1_V3); 1533 PM_SOURCES_READ_XGAL("PS1_V4", CMF_PS1_V4); 1534 PM_SOURCES_READ_XGAL("PS1_V5", CMF_PS1_V5); 1535 PM_SOURCES_READ_XGAL("PS1_SV1", CMF_PS1_SV1); 1536 PM_SOURCES_READ_XGAL("PS1_SV2", CMF_PS1_SV2); 1537 PM_SOURCES_READ_XGAL("PS1_SV3", CMF_PS1_SV3); 1538 PM_SOURCES_READ_XGAL("PS1_DV1", CMF_PS1_DV1); 1539 PM_SOURCES_READ_XGAL("PS1_DV2", CMF_PS1_DV2); 1540 PM_SOURCES_READ_XGAL("PS1_DV3", CMF_PS1_DV3); 1541 PM_SOURCES_READ_XGAL("PS1_DV4", CMF_PS1_DV4); 1542 } 1543 psFree(tableHeader); 1544 return status; 1545 }
Note:
See TracChangeset
for help on using the changeset viewer.
