Changeset 36375 for trunk/psModules/src/objects/pmSourceIO_CMF.c.in
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
trunk/psModules
- Property svn:mergeinfo changed
-
trunk/psModules/src/objects/pmSourceIO_CMF.c.in
r35768 r36375 789 789 char name[64]; 790 790 791 pmModelType modelTypeTrail = pmModelClassGetType("PS_MODEL_TRAIL"); 792 791 793 // create a header to hold the output data 792 794 psMetadata *outhead = psMetadataAlloc (); … … 798 800 sources = psArraySort (sources, pmSourceSortByFlux); 799 801 800 @>PS1_DV2@float magOffset;801 @>PS1_DV2@float zeroptErr;802 @>PS1_DV2@float fwhmMajor;803 @>PS1_DV2@float fwhmMinor;804 @>PS1_DV2@pmSourceOutputsCommonValues (&magOffset, &zeroptErr, &fwhmMajor, &fwhmMinor, readout, imageHeader);802 float magOffset; 803 float zeroptErr; 804 float fwhmMajor; 805 float fwhmMinor; 806 pmSourceOutputsCommonValues (&magOffset, &zeroptErr, &fwhmMajor, &fwhmMinor, readout, imageHeader); 805 807 806 808 // we are writing one row per model; we need to write out same number of columns for each row: find the max Nparams … … 823 825 @>PS1_DV2@ pmChip *chip = readout->parent->parent; 824 826 827 pmModelStatus badModel = PM_MODEL_STATUS_NONE; 828 badModel |= PM_MODEL_STATUS_BADARGS; 829 badModel |= PM_MODEL_STATUS_OFFIMAGE; 830 badModel |= PM_MODEL_STATUS_NAN_CHISQ; 831 badModel |= PM_MODEL_SERSIC_PCM_FAIL_GUESS; 832 badModel |= PM_MODEL_SERSIC_PCM_FAIL_GRID; 833 badModel |= PM_MODEL_PCM_FAIL_GUESS; 834 825 835 table = psArrayAllocEmpty (sources->n); 826 836 … … 847 857 848 858 // skip models which were not actually fitted 849 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 859 // XXX 860 if (model->flags & badModel) continue; 850 861 851 862 PAR = model->params->data.F32; … … 853 864 xPos = PAR[PM_PAR_XPOS]; 854 865 yPos = PAR[PM_PAR_YPOS]; 855 xErr = dPAR[PM_PAR_XPOS]; 856 yErr = dPAR[PM_PAR_YPOS]; 866 867 // for the extended source models, we do not always fit the centroid in the non-linear fitting process 868 // current situation (hard-wired into psphotSourceFits.c:psphotFitPCM, 869 // SERSIC, DEV, EXP : X,Y not fitted (PCM and not PCM) 870 // TRAIL : X,Y are fitted 871 // 872 873 // XXX this should be based on what happened, not on the model type 874 if (model->type == modelTypeTrail) { 875 xErr = dPAR[PM_PAR_XPOS]; 876 yErr = dPAR[PM_PAR_YPOS]; 877 } else { 878 // this is definitely an underestimate since it does not 879 // account for the extent of the source 880 xErr = fwhmMajor * model->magErr / 2.35; 881 yErr = fwhmMinor * model->magErr / 2.35; 882 } 857 883 858 884 @>PS1_DV2@ psSphere ptSky = {0.0, 0.0, 0.0, 0.0}; … … 870 896 row = psMetadataAlloc (); 871 897 872 // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)873 898 // the psMetadataAdd entry and the double quotes are used by grep to select the output fields for automatic documentation 874 899 // This set of psMetadataAdd Entries marks the "----" "Start of the XFIT segment" … … 888 913 @>PS1_DV2@ float calMag = isfinite(magOffset) ? model->mag + magOffset : NAN; 889 914 @>PS1_DV2@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_CAL_MAG", PS_DATA_F32, "EXT Magnitude using supplied calibration", calMag); 890 @>PS1_DV2@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_CHISQ", PS_DATA_F32, "EXT Magnitude using supplied calibration", model->chisq); 891 @>PS1_DV2@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_NDOF", PS_DATA_S32, "EXT Magnitude using supplied calibration", model->nDOF); 915 @>PS1_DV2,PS1_SV?@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_CHISQ", PS_DATA_F32, "EXT Model Chisq", model->chisq); 916 @>PS1_DV2,PS1_SV?@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_NDOF", PS_DATA_S32, "EXT Model num degrees of freedom", model->nDOF); 917 @>PS1_SV1,PS1_SV?@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_MODEL_TYPE", PS_DATA_S32, "type for chosen EXT_MODEL", source->modelEXT ? source->modelEXT->type : -1); 918 919 // EAM : adding for PV2 outputs: 920 @>PS1_SV1@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_FLAGS", PS_DATA_S16, "model fit flags (pmModelStatus)", source->modelEXT ? source->modelEXT->flags : 0); 892 921 893 922 @>PS1_DV2@ psMetadataAddF32 (row, PS_LIST_TAIL, "POSANGLE", 0, "position angle at source (degrees)", posAngle); … … 946 975 947 976 snprintf (name, 64, "EXT_PAR_%02d", k); 948 977 949 978 if (k < model->params->n) { 950 979 psMetadataAddF32 (row, PS_LIST_TAIL, name, 0, "", model->params->data.F32[k]); … … 956 985 // optionally, write out the covariance matrix values 957 986 // XXX do I need to pad this to match the biggest covar matrix? 958 if ( model->covar) {987 if (false && model->covar) { 959 988 for (int iy = 0; iy < model->covar->numCols; iy++) { 960 989 for (int ix = iy; ix < model->covar->numCols; ix++) { … … 1058 1087 model->magErr = psMetadataLookupF32(&status, row, "EXT_INST_MAG_SIG"); 1059 1088 1089 model->chisq = psMetadataLookupF32(&status, row, "EXT_CHISQ"); 1090 model->nDOF = psMetadataLookupF32(&status, row, "EXT_NDOF"); 1091 1092 // EXT_MODEL_TYPE gives the model chosen by psphot as the best. 1093 // Putting this into the XFIT table makes 3 copies of it (one for each model) 1094 // but since we have many fewer XFIT rows than psf rows that is cheaper than putting it 1095 // in the psf table. 1096 psS32 extModelType = psMetadataLookupS32(&status, row, "EXT_MODEL_TYPE"); 1097 if (!status) { 1098 // older cmfs don't have this column 1099 extModelType = -1; 1100 } 1101 1060 1102 psEllipseAxes axes; 1061 1103 axes.major = psMetadataLookupF32(&status, row, "EXT_WIDTH_MAJ"); … … 1072 1114 if (model->params->n > 7) { 1073 1115 PAR[7] = psMetadataLookupF32(&status, row, "EXT_PAR_07"); 1074 } 1075 // read the covariance matrix 1076 int nparams = model->params->n; 1077 psImage *covar = psImageAlloc(nparams, nparams, PS_TYPE_F32); 1078 for (int y = 0; y < nparams; y++) { 1079 for (int x = 0; x < nparams; x++) { 1080 char name[64]; 1081 snprintf(name, 64, "EXT_COVAR_%02d_%02d", y, x); 1082 covar->data.F32[y][x] = psMetadataLookupF32(&status, row, name); 1116 // XXX add an error: 1117 // dPAR[7] = psMetadataLookupF32(&status, row, "EXT_PAR_07_"); 1118 } 1119 1120 // XXX : make this depend on what is in the cmf 1121 if (0) { 1122 // read the covariance matrix 1123 int nparams = model->params->n; 1124 psImage *covar = psImageAlloc(nparams, nparams, PS_TYPE_F32); 1125 for (int y = 0; y < nparams; y++) { 1126 for (int x = 0; x < nparams; x++) { 1127 char name[64]; 1128 snprintf(name, 64, "EXT_COVAR_%02d_%02d", y, x); 1129 covar->data.F32[y][x] = psMetadataLookupF32(&status, row, name); 1130 } 1131 } 1132 model->covar = covar; 1133 } 1134 1135 if (modelType == extModelType) { 1136 // The software that created this source picked this model as the best of the fits. 1137 // Set the extModel to point to it. 1138 // This is important for programs like psastro (skycal) so that its output cmfs 1139 // will have valid EXT_MODEL_TYPE 1140 psFree(source->modelEXT); 1141 source->modelEXT = psMemIncrRefCounter(model); 1142 source->type = PM_SOURCE_TYPE_EXTENDED; 1143 if (0) { 1144 // since FLAGS were read we don't need to do this 1145 source->mode |= PM_SOURCE_MODE_EXTMODEL; 1146 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 1083 1147 } 1084 1148 } 1085 model->covar = covar;1086 1149 1087 1150 psArrayAdd(source->modelFits, 1, model); 1088 1151 psFree(model); 1089 1090 1152 psFree(row); 1091 1153 } … … 1209 1271 1210 1272 write_annuli: 1211 psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX", PS_DATA_VECTOR, "flux within annuli", radFlux);1212 psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX_ERR", PS_DATA_VECTOR, "flux error in annuli", radFluxErr);1213 psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX_STDEV", PS_DATA_VECTOR, "flux standard deviation", radFluxStdev);1214 psMetadataAdd (row, PS_LIST_TAIL, "APER_FILL", PS_DATA_VECTOR, "fill factor of annuli", radFill);1273 psMetadataAddVector (row, PS_LIST_TAIL, "APER_FLUX", PS_META_REPLACE, "flux within annuli", radFlux); 1274 psMetadataAddVector (row, PS_LIST_TAIL, "APER_FLUX_ERR", PS_META_REPLACE, "flux error in annuli", radFluxErr); 1275 psMetadataAddVector (row, PS_LIST_TAIL, "APER_FLUX_STDEV", PS_META_REPLACE, "flux standard deviation", radFluxStdev); 1276 psMetadataAddVector (row, PS_LIST_TAIL, "APER_FILL", PS_META_REPLACE, "fill factor of annuli", radFill); 1215 1277 psFree (radFlux); 1216 1278 psFree (radFluxErr); … … 1343 1405 return true; 1344 1406 } 1407 1408 // XXX where should I record the number of columns?? 1409 bool pmSourcesWrite_CMF_@CMFMODE@_XGAL (psFits *fits, psArray *sources, char *extname, psMetadata *recipe) 1410 { 1411 bool status = false; 1412 1413 // perform full non-linear fits / extended source analysis? 1414 if (!psMetadataLookupBool (&status, recipe, "GALAXY_SHAPES")) { 1415 psLogMsg ("psphot", PS_LOG_INFO, "galaxy shapes were not measured, skipping\n"); 1416 return true; 1417 } 1418 1419 // create a header to hold the output data 1420 psMetadata *outhead = psMetadataAlloc (); 1421 1422 // write the links to the image header 1423 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "galaxy table extension", extname); 1424 1425 // let's write these out in S/N order 1426 sources = psArraySort (sources, pmSourceSortByFlux); 1427 1428 psArray *table = psArrayAllocEmpty (sources->n); 1429 1430 for (int i = 0; i < sources->n; i++) { 1431 1432 pmSource *thisSource = sources->data[i]; 1433 1434 // this is the "real" version of this source 1435 pmSource *source = thisSource->parent ? thisSource->parent : thisSource; 1436 1437 // if we did not fit the galaxy model, modelFits will be NULL 1438 if (source->modelFits == NULL) continue; 1439 1440 // if we did not fit the galaxy model, galaxyFits will also be NULL 1441 if (source->galaxyFits == NULL) continue; 1442 1443 pmModel *model = source->modelFits->data[0]; 1444 if (!model) return false; 1445 1446 // X,Y coordinates are stored with the model parameters 1447 psF32 *PAR = model->params->data.F32; 1448 1449 psMetadata *row = psMetadataAlloc (); 1450 1451 // we write out the x,y positions so people can link to the psf either way (position or ID) 1452 psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET", 0, "IPP detection identifier index", source->seq); 1453 psMetadataAddF32 (row, PS_LIST_TAIL, "X_FIT", 0, "model x coordinate", PAR[PM_PAR_XPOS]); 1454 psMetadataAddF32 (row, PS_LIST_TAIL, "Y_FIT", 0, "model y coordinate", PAR[PM_PAR_YPOS]); 1455 psMetadataAddF32 (row, PS_LIST_TAIL, "NPIX", 0, "number of pixels for fits", source->galaxyFits->nPix); 1456 1457 psVector *Flux = source->galaxyFits->Flux; 1458 psVector *dFlux = source->galaxyFits->dFlux; 1459 psVector *chisq = source->galaxyFits->chisq; 1460 1461 psMetadataAddVector (row, PS_LIST_TAIL, "GAL_FLUX", PS_META_REPLACE, "normalization for galaxy flux", Flux); 1462 psMetadataAddVector (row, PS_LIST_TAIL, "GAL_FLUX_ERR", PS_META_REPLACE, "error on normalization", dFlux); 1463 psMetadataAddVector (row, PS_LIST_TAIL, "GAL_CHISQ", PS_META_REPLACE, "galaxy fit chisq", chisq); 1464 1465 psArrayAdd (table, 100, row); 1466 psFree (row); 1467 } 1468 1469 if (table->n == 0) { 1470 if (!psFitsWriteBlank (fits, outhead, extname)) { 1471 psError(psErrorCodeLast(), false, "Unable to write empty sources file."); 1472 psFree(outhead); 1473 psFree(table); 1474 return false; 1475 } 1476 psFree (outhead); 1477 psFree (table); 1478 return true; 1479 } 1480 1481 psTrace ("pmFPAfile", 5, "writing galaxy data %s\n", extname); 1482 if (!psFitsWriteTable (fits, outhead, table, extname)) { 1483 psError(psErrorCodeLast(), false, "writing galaxy data %s\n", extname); 1484 psFree (outhead); 1485 psFree(table); 1486 return false; 1487 } 1488 psFree (outhead); 1489 psFree (table); 1490 return true; 1491 } 1492
Note:
See TracChangeset
for help on using the changeset viewer.
