Changeset 41625
- Timestamp:
- May 31, 2021, 11:45:18 AM (5 years ago)
- Location:
- branches/eam_branches/relphot.20210521
- Files:
-
- 15 edited
-
include/relphot.h (modified) (3 diffs)
-
src/GridOps.c (modified) (1 diff)
-
src/ImageOps.c (modified) (9 diffs)
-
src/MagResidSave.c (modified) (1 diff)
-
src/MosaicOps.c (modified) (7 diffs)
-
src/ResetOps.c (modified) (4 diffs)
-
src/StarOps.c (modified) (13 diffs)
-
src/TGroupOps.c (modified) (4 diffs)
-
src/ZeroPointModes.c (modified) (3 diffs)
-
src/initialize.c (modified) (1 diff)
-
src/plot_scatter.c (modified) (1 diff)
-
src/relphot_images.c (modified) (2 diffs)
-
src/relphot_parallel_images.c (modified) (5 diffs)
-
src/setMrelCatalog.c (modified) (5 diffs)
-
src/setMrelFinal.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/relphot.20210521/include/relphot.h
r41624 r41625 8 8 9 9 # define NBOOTSTRAP 100 10 11 // MEAS_BAD is used in ImageOps.c, MosaicOps.c, TGroupOps.c to skip specific measurements. 12 // ID_MEAS_AREA is raised for measurements outside the user-specified region of the chips 13 // ID_MEAS_NOCAL is raised for measurements outside the valid time range or for inactive photcodes 14 // Note: these bits are only raised on the temporary MeasureTiny elements and are not saved 15 // to the database files. 16 # define MEAS_BAD (ID_MEAS_AREA | ID_MEAS_NOCAL) 10 17 11 18 # ifndef MAX_INT … … 453 460 char MOSAICNAME[256]; 454 461 char STATMODE[32]; 455 int STAR_BAD;456 int MEAS_BAD;457 462 int STAR_TOOFEW; 458 463 int GRID_TOOFEW; 459 464 int IMAGE_TOOFEW; 460 465 double IMAGE_GOOD_FRACTION; 461 int IMAGE_BAD;462 466 int CALIBRATE_STACKS_AND_WARPS; 463 467 … … 848 852 int GetZptIteration (void); 849 853 850 void SetZeroPointModes ( void);854 void SetZeroPointModes (Catalog *catalog, int Ncatalog); 851 855 int UseStandardOLS (ZptFitModeType mode); 852 856 int GetActivePhotcodeIndex (int photcode); -
branches/eam_branches/relphot.20210521/src/GridOps.c
r41620 r41625 192 192 for (int k = 0; k < catalog[nc].averageT[na].Nmeasure; k++, nm++) { 193 193 194 // XXX I need to skip bad measurements, but I am not certain this 195 // flag is set correctly. see note below 194 // skip measurements marked by AREA or TIME 196 195 if (catalog[nc].measureT[nm].dbFlags & MEAS_BAD) continue; 197 196 -
branches/eam_branches/relphot.20210521/src/ImageOps.c
r41608 r41625 385 385 if (i == -1) return NAN; 386 386 387 if (image[i].flags & IMAGE_BAD) return NAN; 387 // allow context dependence?: in relphot_images, we want to exclude detections from poor images 388 // but in the final pass, we want to allow even bad detections 389 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) return NAN; 388 390 389 391 switch (class) { … … 409 411 if (i == -1) return (1000); 410 412 411 if (image[i].flags & IMAGE_BAD) return (1000);412 413 distance = image[i].ubercalDist; // was dummy3 in structure 413 414 return (distance); … … 689 690 if (mark) { 690 691 image[i].flags |= ID_IMAGE_PHOTOM_FEW; 692 image[i].McalPSF = 0.0; 693 image[i].McalAPER = 0.0; 694 image[i].McalChiSq = NAN; 691 695 image[i].dMcal = NAN; 692 image[i]. McalChiSq= NAN;696 image[i].dMagSys = NAN; 693 697 image[i].nFitPhotom = 0; 694 698 Nfew ++; … … 894 898 // measure stats for Mcal and dMcal 895 899 for (i = N = 0; i < Nimage; i++) { 896 if (image[i].flags & IMAGE_BAD) continue;900 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 897 901 898 902 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 922 926 923 927 mark = FALSE; 924 image[i].flags &= ~ID_IMAGE_PHOTOM_POOR; 925 mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].McalPSF - MedOffset) > MaxOffset); 928 929 if (image[i].flags & ID_IMAGE_PHOTOM_FEW) { 930 mark = TRUE; 931 } 932 if (image[i].dMcal > MaxScatter) { 933 mark = TRUE; 934 } 935 if (fabs(image[i].McalPSF - MedOffset) > MaxOffset) { 936 mark = TRUE; 937 } 938 926 939 if (mark) { 927 940 Nmark ++; … … 1089 1102 n = 0; 1090 1103 for (i = 0; i < Nimage; i++) { 1091 if (image[i].flags & IMAGE_BAD)continue;1104 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1092 1105 1093 1106 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 1138 1151 for (i = 0; i < Nimage; i++) { 1139 1152 1140 if (image[i].flags & IMAGE_BAD)continue;1153 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1141 1154 1142 1155 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 1171 1184 for (i = 0; i < Nimage; i++) { 1172 1185 1173 if (image[i].flags & IMAGE_BAD)continue;1186 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1174 1187 1175 1188 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 1204 1217 for (i = 0; i < Nimage; i++) { 1205 1218 1206 if (image[i].flags & IMAGE_BAD)continue;1219 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1207 1220 1208 1221 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; -
branches/eam_branches/relphot.20210521/src/MagResidSave.c
r41608 r41625 215 215 off_t c = ImageToCatalog[j]; 216 216 217 // XXX drop this?218 217 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) continue; 219 218 -
branches/eam_branches/relphot.20210521/src/MosaicOps.c
r41608 r41625 780 780 if (i == -1) return (0.0); 781 781 782 if (mosaic[i].flags & IMAGE_BAD) return (NAN); 782 // if the mosaic cannot be calibrated (too few measurements, skip it) 783 // XXX: if the mosaic is bad (few) but the chips are OK, I can used them. 784 // XXX: if (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW) return (NAN); 783 785 value = mosaic[i].McalPSF; 784 786 return (value); … … 1330 1332 } 1331 1333 1332 // When we rationalize the images/mosaics, we are driving the negative cloud images back1333 // to 0.0. At the same time, we make a guess to the effective impact on all other images,1334 // driven by the coupling of common stars.1335 // XXX this function is no longer used because we force significantly negative clouds to 0.01336 int rationalize_mosaics (Catalog *catalog, int Ncatalog) {1337 1338 double *imageOffset, **starOffset;1339 int **starNcount, *seclist;1340 int **Slist, *NSlist, *NSLIST;1341 int i, j, k, m, nMos, Ns, found;1342 1343 off_t Nimage;1344 Image *image;1345 1346 // set a test value for now1347 float CLOUD_TOLERANCE = 0.025;1348 1349 if (!MOSAIC_ZEROPT) return (FALSE);1350 if (FREEZE_MOSAICS) return (FALSE);1351 1352 image = getimages (&Nimage, NULL);1353 1354 ALLOCATE (imageOffset, double, Nmosaic);1355 ALLOCATE ( Slist, int *, Nmosaic); // array of calibrated star indexes on this mosaic1356 ALLOCATE (NSlist, int, Nmosaic); // number of stars on mosaic1357 ALLOCATE (NSLIST, int, Nmosaic); // number of Slist entries allocated1358 memset (Slist, 0, Nmosaic*sizeof(int *));1359 1360 // find the images / mosaics with negative clouds and save their offset1361 for (i = 0; i < Nmosaic; i++) {1362 1363 NSlist[i] = 0;1364 NSLIST[i] = 100;1365 ALLOCATE (Slist[i], int, NSLIST[i]);1366 1367 imageOffset[i] = 0.0;1368 1369 if (VERBOSE2 && (fabs(mosaic[i].McalPSF) < CLOUD_TOLERANCE)) {1370 fprintf (stderr, "cloud-free: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);1371 }1372 if (VERBOSE2 && (mosaic[i].McalPSF < -CLOUD_TOLERANCE)) {1373 imageOffset[i] = -mosaic[i].McalPSF;1374 // NOTE the negative sign: down below, we are going to add in the negative of McalPSF1375 // to this image, and the propagated mean values for other images1376 fprintf (stderr, "anti-clouds: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);1377 }1378 if (VERBOSE2 && (mosaic[i].McalPSF > CLOUD_TOLERANCE)) {1379 fprintf (stderr, "cloudy : %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);1380 }1381 }1382 1383 int Nsecfilt = GetPhotcodeNsecfilt ();1384 ALLOCATE (seclist, int, Nphotcodes);1385 for (Ns = 0; Ns < Nphotcodes; Ns ++) {1386 int thisCode = photcodes[Ns][0].code;1387 seclist[Ns] = GetPhotcodeNsec(thisCode);1388 }1389 1390 // allocate an array for star offsets1391 int Nstars = 0;1392 int NSTARS = 1000;1393 ALLOCATE (starOffset, double *, NSTARS);1394 ALLOCATE (starNcount, int *, NSTARS);1395 memset (starOffset, 0, NSTARS*sizeof(double *));1396 memset (starNcount, 0, NSTARS*sizeof(int *));1397 1398 // find the mean offset for each star1399 for (i = 0; i < Ncatalog; i++) {1400 for (j = 0; j < catalog[i].Naverage; j++) {1401 ALLOCATE (starOffset[Nstars], double, Nphotcodes);1402 ALLOCATE (starNcount[Nstars], int, Nphotcodes);1403 memset (starOffset[Nstars], 0, Nphotcodes*sizeof(double));1404 memset (starNcount[Nstars], 0, Nphotcodes*sizeof(int));1405 1406 m = catalog[i].averageT[j].measureOffset;1407 1408 // determine the mosaic for each measurement1409 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {1410 1411 // skip unused measurements1412 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;1413 1414 // skip unused measurements1415 1416 // XXX replace with:1417 // Ns = GetActivePhotcodeIndex (photcode);1418 // if (Ns < 0) continue;1419 1420 int Nsec;1421 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);1422 found = FALSE;1423 for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) {1424 if (ecode == photcodes[Ns][0].code) {1425 found = TRUE;1426 break;1427 }1428 }1429 if (!found) continue;1430 Nsec = seclist[Ns];1431 1432 // bad stars for this secfilt1433 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;1434 1435 // skip REF measurements (not tied to an image)1436 if (getImageEntry (m, i) < 0) continue;1437 1438 // find the source of this measurement (skip unassigned measurements)1439 nMos = MeasureToMosaic[i][m];1440 if (nMos == -1) continue;1441 1442 // XXX how can this not be true?1443 if (mosaic[nMos].photcode != ecode) {1444 fprintf (stderr, "*");1445 }1446 1447 assert (Ns >= 0);1448 assert (Ns < Nphotcodes);1449 1450 // accumulate the offsets from the negative cloud images (others have 0.0 value)1451 starOffset[Nstars][Ns] += imageOffset[nMos];1452 starNcount[Nstars][Ns] ++;1453 1454 // record the mosaic->star reference1455 Slist[nMos][NSlist[nMos]] = Nstars;1456 NSlist[nMos] ++;1457 if (NSlist[nMos] == NSLIST[nMos]) {1458 NSLIST[nMos] += 100;1459 REALLOCATE (Slist[nMos], int, NSLIST[nMos]);1460 }1461 }1462 Nstars ++;1463 if (Nstars == NSTARS) {1464 NSTARS += 1000;1465 REALLOCATE (starOffset, double *, NSTARS);1466 REALLOCATE (starNcount, int *, NSTARS);1467 memset (&starOffset[NSTARS-1000], 0, 1000*sizeof(double *));1468 memset (&starNcount[NSTARS-1000], 0, 1000*sizeof(int *));1469 }1470 }1471 }1472 1473 // find the mean offset of the images without negative clouds1474 for (i = 0; i < Nmosaic; i++) {1475 1476 found = FALSE;1477 for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) {1478 if (mosaic[i].photcode == photcodes[Ns][0].code) {1479 found = TRUE;1480 break;1481 }1482 }1483 if (!found) {1484 fprintf (stderr, "invalid photcode for mosaic?\n");1485 abort();1486 }1487 1488 // a negative cloud image (cloud: McalPSF > 0; anti-clouds: McalPSF < 0; imageOffset = -McalPSF)1489 if (imageOffset[i] > 0.0) continue;1490 1491 // we need to actually have cross-references to count1492 if (NSlist[i] < 2) continue;1493 1494 float dM = 0.0;1495 for (j = 0; j < NSlist[i]; j++) {1496 k = Slist[i][j];1497 if (starNcount[k][Ns] > 1) {1498 dM += (starOffset[k][Ns] / starNcount[k][Ns]);1499 }1500 }1501 imageOffset[i] = dM / NSlist[i];1502 // fprintf (stderr, "adjust image: %s : (%f %d) : %f\n", image[MosaicToImage[i][0]].name, dM, NSlist[i], imageOffset[i]);1503 }1504 1505 // for (i = 0; i < Nmosaic; i++) {1506 // fprintf (stderr, "correction: %s : %f\n", image[MosaicToImage[i][0]].name, imageOffset[i]);1507 // }1508 1509 // apply all offset values to the mosaics1510 // find the images / mosaics with negative clouds and save their offset1511 for (i = 0; i < Nmosaic; i++) {1512 mosaic[i].McalPSF += imageOffset[i];1513 }1514 1515 for (i = 0; i < Nstars; i++) {1516 free (starOffset[i]);1517 free (starNcount[i]);1518 }1519 free (starOffset);1520 free (starNcount);1521 1522 free (seclist);1523 free (NSlist);1524 free (NSLIST);1525 for (i = 0; i < Nmosaic; i++){1526 free (Slist[i]);1527 }1528 free (Slist);1529 free (imageOffset);1530 return (TRUE);1531 }1532 1533 1334 StatType statsMosaicM (Catalog *catalog) { 1534 1335 OHANA_UNUSED_PARAM(catalog); … … 1547 1348 n = 0; 1548 1349 for (i = 0; i < Nmosaic; i++) { 1549 if (mosaic[i].flags & IMAGE_BAD) continue;1350 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1550 1351 if (mosaic[i].skipCal) continue; 1551 1352 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1580 1381 n = 0; 1581 1382 for (i = 0; i < Nmosaic; i++) { 1582 if (mosaic[i].flags & IMAGE_BAD) continue;1383 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1583 1384 if (mosaic[i].skipCal) continue; 1584 1385 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1613 1414 n = 0; 1614 1415 for (i = 0; i < Nmosaic; i++) { 1615 if (mosaic[i].flags & IMAGE_BAD) continue;1416 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1616 1417 if (mosaic[i].skipCal) continue; 1617 1418 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1663 1464 n = 0; 1664 1465 for (i = 0; i < Nmosaic; i++) { 1665 if (mosaic[i].flags & IMAGE_BAD) continue;1466 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1666 1467 if (mosaic[i].skipCal) continue; 1667 1468 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1795 1596 c = MosaicToCatalog[i][j]; 1796 1597 1797 if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;1598 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) continue; 1798 1599 1799 1600 // ave = catalog[c].measureT[m].averef; -
branches/eam_branches/relphot.20210521/src/ResetOps.c
r41624 r41625 75 75 } 76 76 } 77 if (RESET_FLATCORR) { 78 measure->Mflat = 0.0; 79 } 77 80 measure->dbFlags &= ~photomBitsMeasure; 78 81 } … … 88 91 for (off_t i = 0; i < Nsubset; i++) { 89 92 // reset these bits regardless (we will re-determine) 90 subset[i].flags &= ~(ID_IMAGE_PHOTOM_ NOCAL | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP| ID_IMAGE_PHOTOM_FEW);93 subset[i].flags &= ~(ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW); 91 94 if (RESET) { 92 95 if (RESET_ZEROPTS) { … … 117 120 118 121 for (off_t i = 0; i < catalog->Naverage; i++) { 119 catalog[0].average[i].psfQF = NAN; // force recalculation in setMrelCatalog 120 catalog[0].average[i].psfQFperf = NAN; // force recalculation in setMrelCatalog 121 catalog[0].average[i].stargal = NAN; // force recalculation in setMrelCatalog 122 catalog[0].average[i].photFlagsUpper = 0; // reset (will be re-calculated) 123 catalog[0].average[i].photFlagsLower = 0; // reset (will be re-calculated) 124 catalog[0].average[i].NwarpOK = 0; // reset (will be re-calculated) 122 catalog->average[i].psfQF = NAN; // force recalculation in setMrelCatalog 123 catalog->average[i].psfQFperf = NAN; // force recalculation in setMrelCatalog 124 catalog->average[i].stargal = NAN; // force recalculation in setMrelCatalog 125 catalog->average[i].photFlagsUpper = 0; // reset (will be re-calculated) 126 catalog->average[i].photFlagsLower = 0; // reset (will be re-calculated) 127 catalog->average[i].NwarpOK = 0; // reset (will be re-calculated) 128 129 // RESET_FLATCORR independent of RESET? 125 130 126 131 if (!RESET) continue; … … 128 133 catalog->average[i].flags &= ~photomBitsAverage; // reset all photometry bits (but not astrom) 129 134 130 for (int Ns = 0; Ns < Nsecfilt; Ns++) { 135 // Reset secfilt values only for the active photcodes 136 for (int Ns = 0; Ns < Nphotcodes; Ns++) { 137 138 int thisCode = photcodes[Ns][0].code; 139 int Nsec = GetPhotcodeNsec(thisCode); 140 off_t N = Nsecfilt*i+Nsec; 141 142 dvo_secfilt_init (&catalog->secfilt[N], SECFILT_RESET_ALL); 143 } 144 145 // Reset measure values only for the active photcodes 146 147 off_t m = catalog->average[i].measureOffset; 148 149 for (off_t j = 0; j < catalog->average[i].Nmeasure; j++, m++) { 150 151 /* select measurements for active photcodes */ 152 PhotCode *code = GetPhotcodebyCode (catalog->measure[m].photcode); 153 if (!code) continue; 154 // photcode exists, but is it one of the active ones? 155 int found = FALSE; 156 for (int Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 157 if (code->equiv != photcodes[Ns][0].code) continue; 158 found = TRUE; 159 } 160 if (!found) continue; 161 162 // reset the Mflat value if requested 163 if (RESET_FLATCORR) { 164 catalog->measure[m].Mflat = 0.0; 165 } 166 167 /* select measurements by time */ 168 if (TimeSelect) { 169 if (catalog->measure[m].t < TSTART) continue; 170 if (catalog->measure[m].t > TSTOP) continue; 171 } 131 172 132 off_t N = Nsecfilt*i+Ns;133 dvo_secfilt_init (&catalog->secfilt[N], SECFILT_RESET_ALL);173 // only reset Mcal for measures with a matching image 174 // do not reset Mcal for ubercal images unless explicitly requested 134 175 135 off_t m = catalog->average[i].measureOffset; 136 137 for (off_t j = 0; j < catalog->average[i].Nmeasure; j++, m++) { 138 139 /* select measurements by time */ 140 if (TimeSelect) { 141 if (catalog->measure[m].t < TSTART) continue; 142 if (catalog->measure[m].t > TSTOP) continue; 176 if (catalog->measure[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { 177 if (!KEEP_UBERCAL) { 178 catalog->measure[m].McalPSF = 0.0; 179 catalog->measure[m].McalAPER = 0.0; 180 catalog->measure[m].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL; 181 } 182 } else { 183 if (RESET_ZEROPTS && (getImageEntry (m, 0) >= 0)) { 184 catalog->measure[m].McalPSF = 0.0; 185 catalog->measure[m].McalAPER = 0.0; 143 186 } 144 145 // only reset Mcal for measures with a matching image146 // do not reset Mcal for ubercal images unless explicitly requested147 148 if (catalog->measure[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {149 if (!KEEP_UBERCAL) {150 catalog->measure[m].McalPSF = 0.0;151 catalog->measure[m].McalAPER = 0.0;152 catalog->measure[m].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL;153 }154 } else {155 if (RESET_ZEROPTS && (getImageEntry (m, 0) >= 0)) {156 catalog->measure[m].McalPSF = 0.0;157 catalog->measure[m].McalAPER = 0.0;158 }159 }160 catalog->measure[m].dbFlags &= ~photomBitsMeasure;161 187 } 188 catalog->measure[m].dbFlags &= ~photomBitsMeasure; 162 189 } 163 190 } 164 191 } 165 192 193 -
branches/eam_branches/relphot.20210521/src/StarOps.c
r41624 r41625 1 1 # include "relphot.h" 2 3 # define STAR_BAD (ID_SECF_STAR_FEW | ID_SECF_STAR_POOR) 2 4 3 5 enum {THREAD_RUN, THREAD_DONE}; … … 290 292 291 293 // setMrel and setMrelOutput are extremely similar, but have slightly different implications: 294 // * both call setMrelCatalog, but setMrel set isSetMrelFinal to FALSE 292 295 // * setMrel only uses the internal Tiny structures 293 // * setMrel skips stars for which there are too few good measurements (setMrelOutput assigns an average mag with only 1) 296 // * setMrel skips stars for which there are too few good measurements 297 // -> (setMrelOutput assigns an average mag for all objects, even those with only 1 measurement) 294 298 // * setMrelOutput sets psfQF, psfQFperf, extNsigma, rank info, etc 295 299 // * setMrelOutput sets average Map 296 300 // * setMrelOutput updates 2MASS average flags 297 301 // * setMrelOutput updates average EXT flags (PS1 and 2MASS) 298 // * setMrelOutput sets average stack & warp photometry (if requested) 302 // * setMrelOutput sets average stack & warp photometry (if requested), setMrel always skips those 303 // * setMrelOutput is NOT threaded it reads/writes catalogs one at a time 299 304 300 305 int setMrel (Catalog *catalog, int Ncatalog) { … … 325 330 } 326 331 327 // setMrelOutput is NOT threaded because we read/write catalogs one at a time (for now)328 332 int setMrelOutput (Catalog *catalog, int Ncatalog) { 329 333 … … 443 447 } 444 448 445 # define SKIP_THIS_MEAS(REASON) { \446 catalog[Nc].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM; \447 if (catalog[Nc].measure) { \448 catalog[Nc].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM; \449 } \450 results->REASON ++; \451 continue; }452 453 454 449 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure) { 455 450 … … 471 466 } 472 467 473 /* set measure.Mcal for all measures except ID_MEAS_NOCAL and ID_IMAGE_PHOTOM_NOCAL*/468 /* set measure.Mcal for all measures except ID_MEAS_NOCAL */ 474 469 int setMcalOutput (Catalog *catalog, int Ncatalog) { 475 470 … … 477 472 off_t j, k, m; 478 473 479 MEAS_BAD = ID_MEAS_NOCAL;480 IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;481 482 474 for (i = 0; i < Ncatalog; i++) { 483 475 for (j = 0; j < catalog[i].Naverage; j++) { … … 485 477 m = catalog[i].averageT[j].measureOffset; 486 478 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 487 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;479 if (catalog[i].measureT[m].dbFlags & ID_MEAS_NOCAL) continue; 488 480 float McalPSF = getMcal (m, i, MAG_CLASS_PSF); 489 481 float McalAPER = getMcal (m, i, MAG_CLASS_APER); 490 482 if (isnan(McalPSF)) continue; 491 float Mmos = getMmos (m, i); 492 if (isnan(Mmos)) continue; 493 float Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL); 494 if (isnan(Mgrp)) continue; 495 float Mgrid = getMgridTiny (&catalog[i].measureT[m]); 496 if (isnan(Mgrid)) continue; 483 484 // Mmos, Mgrp have already been transfered to Mcal and should be zero here 485 // float Mmos = getMmos (m, i); 486 // if (isnan(Mmos)) continue; 487 // float Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL); 488 // if (isnan(Mgrp)) continue; 489 490 // Mgrid is applied to Mflat and should be ignored here 491 // float Mgrid = getMgridTiny (&catalog[i].measureT[m]); 492 // if (isnan(Mgrid)) continue; 497 493 498 494 // Note that this operation is setting measure->McalAPER to image->McalAPER only … … 507 503 508 504 // set the output calibration 509 // float Moff = Mmos + Mgrp + Mgrid; 510 float Moff = Mmos + Mgrid; // Mgrp has already been applied to the image.Mcal 511 catalog[i].measure[m].McalPSF = McalPSF + Moff; 512 catalog[i].measure[m].McalAPER = useStackAper ? McalAPER + Moff : McalPSF + Moff; 505 catalog[i].measure[m].McalPSF = McalPSF; 506 catalog[i].measure[m].McalAPER = useStackAper ? McalAPER : McalPSF; 513 507 514 508 if (catalog[i].measureT[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { … … 612 606 for (i = Ntot = 0; i < Ncatalog; i++) { 613 607 for (j = 0; j < catalog[i].Naverage; j++) { 614 if ( catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;608 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 615 609 float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq; 616 610 if (isnan(Mchisq)) continue; … … 621 615 } 622 616 } 623 617 618 // XXX the limits for MaxChisq and MaxScatter should be 619 // user-defined. This uses 624 620 liststats (xlist, dlist, NULL, Ntot, &stats); 625 MaxChisq = MAX (STAR_CHISQ, 2*stats.median); 621 float ChiSqUpper90 = stats.Upper90; 622 MaxChisq = MAX (STAR_CHISQ, ChiSqUpper90); 626 623 627 624 liststats (slist, dlist, NULL, Ntot, &stats); 628 MaxScatter = MAX (STAR_SCATTER, 2*stats.median); 625 float ScatterUpper90 = stats.Upper90; 626 MaxScatter = MAX (STAR_SCATTER, ScatterUpper90); 629 627 fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq); 630 628 … … 636 634 mark = (dM > MaxScatter) || (isnan(Mchisq)) || (Mchisq > MaxChisq); 637 635 if (mark) { 638 catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_ OBJ_POOR;636 catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_SECF_STAR_POOR; 639 637 Ndel ++; 640 638 if (dM > MaxScatter) { Nscat ++; } … … 642 640 if (Mchisq > MaxChisq) { Nchi ++; } 643 641 } else { 644 catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_ OBJ_POOR;642 catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_SECF_STAR_POOR; 645 643 } 646 644 Nave ++; … … 652 650 free (slist); 653 651 free (dlist); 654 }655 656 // clean_measures examines the stats for a single star. It measures the INNER 50% mean657 // and sigma, it then re-measures the mean and sigma using all stars with NSIGMA_CLIP (3)658 // sigma of the INNER 50% mean. it then flags any measurements which are more than659 // NSIGMA_REJECT (5) sigma of the mean660 661 // this function only operations on the PSF magnitudes662 663 // XXX EAM clean_measures is no longer used -- we rely on IRLS to down-weight outliers664 665 # define NSIGMA_CLIP 3.0666 # define NSIGMA_REJECT 5.0667 void clean_measures (Catalog *catalog, int Ncatalog, int final) {668 669 off_t j, k, m, Nmax, Ndel, Nave;670 int i, N, image_bad, TOOFEW;671 off_t *ilist;672 double *tlist, *list, *dlist;673 float Msys, Mcal, Mmos, Mgrp, Mgrid;674 int Ncal, Nmos, Ngrp, Ngrid, Nfew;675 676 int Nsecfilt = GetPhotcodeNsecfilt ();677 678 if (VERBOSE) fprintf (stderr, "marking poor measures\n");679 /* Nmeasure is now different, need to reallocate */680 Nmax = 0;681 for (i = 0; i < Ncatalog; i++) {682 for (j = 0; j < catalog[i].Naverage; j++) {683 Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure);684 }685 }686 ALLOCATE (list, double, MAX (1, Nmax));687 ALLOCATE (dlist, double, MAX (1, Nmax));688 ALLOCATE (ilist, off_t, Nmax);689 ALLOCATE (tlist, double, Nmax);690 691 /* it makes no sense to mark 3-sigma outliers with <5 measurements */692 TOOFEW = MAX (5, STAR_TOOFEW);693 694 // stats structures for inner and full stats695 StatType instats, stats;696 liststats_setmode (&instats, "INNER_MEAN");697 liststats_setmode (&stats, "MEAN");698 699 Ndel = Nave = 0;700 Ncal = Nmos = Ngrp = Ngrid = Nfew = 0;701 for (i = 0; i < Ncatalog; i++) {702 for (j = 0; j < catalog[i].Naverage; j++) {703 704 int Ns;705 for (Ns = 0; Ns < Nphotcodes; Ns++) {706 707 int thisCode = photcodes[Ns][0].code;708 int Nsec = GetPhotcodeNsec(thisCode);709 710 /* on final processing, skip stars already measured */711 if (final && catalog[i].found_t[Nsecfilt*j + Nsec]) continue;712 713 /* skip bad stars to prevent them from becoming good (on inner sample) */714 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;715 716 /* accumulate list of valid measurements */717 m = catalog[i].averageT[j].measureOffset;718 N = 0;719 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {720 // skip measurements that do not match the current photcode721 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);722 if (ecode != thisCode) { continue; }723 724 // SKIP gpc1 stack data725 if (isGPC1stack(catalog[i].measureT[m].photcode)) continue;726 727 // SKIP gpc1 forced-warp data728 if (isGPC1warp(catalog[i].measureT[m].photcode)) continue;729 730 // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers731 Mcal = getMcal (m, i, MAG_CLASS_PSF);732 if (isnan(Mcal)) { Ncal ++; continue; }733 Mmos = getMmos (m, i);734 if (isnan(Mmos)) { Nmos ++; continue; }735 Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL);736 if (isnan(Mgrp)) { Ngrp ++; continue; }737 Mgrid = getMgridTiny (&catalog[i].measureT[m]);738 if (isnan(Mgrid)) { Ngrid ++; continue; }739 740 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF);741 list[N] = Msys - Mcal - Mmos - Mgrp - Mgrid;742 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);743 N++;744 }745 if (N <= TOOFEW) {746 Nfew ++;747 continue;748 }749 750 /* 3-sigma clip based on stats of inner 50% */751 752 // calculated mean of inner 50%753 liststats (list, dlist, NULL, N, &instats);754 instats.sigma = MAX (MIN_ERROR, instats.sigma); /* if measurements agree too well, sigma -> 0.0 */755 756 // ignore entries > 3sigma from inner mean757 for (k = m = 0; k < N; k++) {758 if (fabs (list[k] - instats.median) < NSIGMA_CLIP*instats.sigma) {759 list[m] = list[k];760 m++;761 }762 }763 // recalculate the mean & sigma of the accepted measurements764 liststats (list, dlist, NULL, m, &stats);765 stats.sigma = MAX (MIN_ERROR, stats.sigma);766 767 /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */768 image_bad = IMAGE_BAD;769 IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;770 m = catalog[i].averageT[j].measureOffset;771 N = 0;772 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {773 // skip measurements that do not match the current photcode774 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);775 if (ecode != thisCode) { continue; }776 777 // SKIP gpc1 stack data778 if (isGPC1stack(catalog[i].measureT[m].photcode)) continue;779 780 // SKIP gpc1 forced-warp data781 if (isGPC1warp(catalog[i].measureT[m].photcode)) continue;782 783 // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers784 Mcal = getMcal (m, i, MAG_CLASS_PSF);785 if (isnan(Mcal)) continue;786 Mmos = getMmos (m, i);787 if (isnan(Mmos)) continue;788 Mgrid = getMgridTiny (&catalog[i].measureT[m]);789 if (isnan(Mgrid)) continue;790 791 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF);792 list[N] = Msys - Mcal - Mmos - Mgrid;793 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);794 ilist[N] = m;795 N++;796 Nave ++;797 }798 if (N < TOOFEW) continue;799 800 /* mark bad measures (> 5 sigma deviant) */801 for (k = 0; k < N; k++) {802 // treat the scatter of the star as a systematic term. this is a bit of an803 // over-estimage (a perfect Gauss distribution with perfect errors would have804 // mySigma = sqrt(2) too large)805 float mySigma = hypot (stats.sigma, dlist[k]);806 if (fabs (list[k] - stats.median) > NSIGMA_REJECT*mySigma) {807 catalog[i].measureT[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;808 if (final) {809 // for the final pass, we have a duplicate set of values in measure and measureT810 catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;811 }812 Ndel ++;813 } else {814 catalog[i].measureT[ilist[k]].dbFlags &= ~ID_MEAS_POOR_PHOTOM;815 if (final) {816 // for the final pass, we have a duplicate set of values in measure and measureT817 catalog[i].measure[ilist[k]].dbFlags &= ~ID_MEAS_POOR_PHOTOM;818 }819 }820 }821 IMAGE_BAD = image_bad;822 }823 }824 }825 if (VERBOSE) fprintf (stderr, OFF_T_FMT" measures marked poor, "OFF_T_FMT" total\n", Ndel, Nave);826 827 free (list);828 free (dlist);829 free (ilist);830 free (tlist);831 652 } 832 653 -
branches/eam_branches/relphot.20210521/src/TGroupOps.c
r41608 r41625 1172 1172 ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes); 1173 1173 1174 int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW;1175 1176 1174 int n = 0; 1177 1175 for (int i = 0; i < NtgroupTimes; i++) { 1178 1176 TGroup *tgroup = tgroupTimes[i][0].byCode; 1179 1177 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1180 if (tgroup[j].flags & NIGHT_BAD) continue;1178 if (tgroup[j].flags & (ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1181 1179 list[n] = tgroup[j].McalPSF; 1182 1180 dlist[n] = 1; … … 1209 1207 TGroup *tgroup = tgroupTimes[i][0].byCode; 1210 1208 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1211 if (tgroup[j].flags & IMAGE_BAD) continue;1209 if (tgroup[j].flags & (ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1212 1210 list[n] = tgroup[j].dMcal; 1213 1211 dlist[n] = 1; … … 1240 1238 TGroup *tgroup = tgroupTimes[i][0].byCode; 1241 1239 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1242 if (tgroup[j].flags & IMAGE_BAD) continue;1240 if (tgroup[j].flags & (ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1243 1241 list[n] = tgroup[j].McalChiSq; 1244 1242 dlist[n] = 1; … … 1396 1394 c = tgroup[i].catalog[j]; 1397 1395 1398 if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;1396 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) continue; 1399 1397 1400 1398 // ave = catalog[c].measureT[m].averef; -
branches/eam_branches/relphot.20210521/src/ZeroPointModes.c
r41603 r41625 22 22 } 23 23 24 void SetZeroPointModes ( void) {24 void SetZeroPointModes (Catalog *catalog, int Ncatalog) { 25 25 26 26 if (TGROUP_ZEROPT && MOSAIC_ZEROPT) { … … 59 59 clean_mosaics(); // do this on every pass 60 60 clean_images(); // do this on every pass 61 clean_stars(catalog, Ncatalog); // do this on every pass 61 62 } 62 63 if ((CurrentLoop >= 21) && (CurrentLoop <= 999)) { … … 71 72 clean_mosaics(); // do this on every pass 72 73 clean_images(); // do this on every pass 74 clean_stars(catalog, Ncatalog); // do this on every pass 73 75 } 74 76 } -
branches/eam_branches/relphot.20210521/src/initialize.c
r41603 r41625 27 27 } 28 28 29 IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;30 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;31 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;32 33 29 if (SHOW_PARAMS) { 34 30 int Ns; -
branches/eam_branches/relphot.20210521/src/plot_scatter.c
r41606 r41625 28 28 N = 0; 29 29 for (i = 0; i < Ncatalog; i++) { 30 for (j = 0; j < catalog[i].Naverage; j++) {30 for (j = 0; j < catalog[i].Naverage; j++) { 31 31 32 /* calculate the average value for a single star */33 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;34 m = catalog[i].averageT[j].measureOffset;32 /* calculate the average value for a single star */ 33 // if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 34 m = catalog[i].averageT[j].measureOffset; 35 35 36 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {37 // skip measurements that do not match the current photcode38 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);39 if (ecode != thisCode) { continue; }36 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 37 // skip measurements that do not match the current photcode 38 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 39 if (ecode != thisCode) { continue; } 40 40 41 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;42 Mcal = getMcal (m, i, MAG_CLASS_PSF);43 if (isnan(Mcal)) continue;44 Mmos = getMmos (m, i);45 if (isnan(Mmos)) continue;46 Mgrid = getMgridTiny (&catalog[i].measureT[m]);47 if (isnan(Mgrid)) continue;41 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 42 Mcal = getMcal (m, i, MAG_CLASS_PSF); 43 if (isnan(Mcal)) continue; 44 Mmos = getMmos (m, i); 45 if (isnan(Mmos)) continue; 46 Mgrid = getMgridTiny (&catalog[i].measureT[m]); 47 if (isnan(Mgrid)) continue; 48 48 49 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp;50 if (isnan(Mrel)) continue;49 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp; 50 if (isnan(Mrel)) continue; 51 51 52 xlist[N] = Mrel; 53 ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF) - Mcal - Mmos - Mgrid - Mrel; 54 ilist[N] = PhotInstTiny (&catalog[i].measureT[m], MAG_CLASS_PSF); 55 N++; 56 } 52 xlist[N] = Mrel; 53 ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF) - Mcal - Mmos - Mgrid - Mrel; 54 ilist[N] = PhotInstTiny (&catalog[i].measureT[m], MAG_CLASS_PSF); 55 N++; 57 56 } 57 } 58 58 } 59 59 -
branches/eam_branches/relphot.20210521/src/relphot_images.c
r41624 r41625 83 83 SAVEPLOT = FALSE; 84 84 85 // mark ID_MEAS_AREA (user-selected chip region) and ID_MEAS_NOCAL (time range & active photcode) 85 86 setExclusions (catalog, Ncatalog, TRUE); 86 87 … … 114 115 115 116 global_stats (catalog, Ncatalog, i); 116 SetZeroPointModes ( );117 SetZeroPointModes (catalog, Ncatalog); 117 118 118 119 MARKTIME("-- finished loop %d: %f sec\n", i, dtime); -
branches/eam_branches/relphot.20210521/src/relphot_parallel_images.c
r41606 r41625 8 8 * update the unowned detections for owned objects from neighbor regions 9 9 * update the unowned objects for owned detections 10 11 * TGROUP and GRID corrections are not calculated. 10 12 */ 11 13 … … 105 107 setMcal (catalog); 106 108 setMmos (catalog); 107 // setMgrp (catalog, FALSE); XXX think this through: this may not make sense for tgroups108 109 MARKTIME("-- set Mrel, Mcal, Mmos, Mgrid : %f sec\n", dtime); 109 110 … … 117 118 global_stats (catalog, Ncatalog, i); 118 119 119 SetZeroPointModes ( );120 SetZeroPointModes (catalog, Ncatalog); 120 121 MARKTIME("-- finished loop %d: %f sec\n", i, dtime); 121 122 } … … 138 139 139 140 setMcalFromMosaics (); // copy per-mosaic calibrations to the images 140 // XXX keep? setMcalFromTGroups (); // copy per-tgroup calibrations to the images141 141 142 142 share_image_mags (regionHosts, -1); … … 152 152 freeImageBins(Ncatalog, TRUE); 153 153 freeMosaicBins (Ncatalog, TRUE); 154 freeGridBins ();155 154 freeImages((char *)image); 156 155 free (image); -
branches/eam_branches/relphot.20210521/src/setMrelCatalog.c
r41624 r41625 225 225 } 226 226 227 /* some things to note here: 228 229 Mcal, Mmos, Mgrid are only relevant (non-zero) during the relphot_images and 230 relphot_parallel_images analysis steps. For the final output steps (setMrelFinal), 231 these are turned off 232 233 During the image analysis, Mflat is the prior stored value while Mgrid is the new 234 measurement. In the final output step, Mgrid is transferred to Mflat and zero 235 236 On the final calculation of Mrel, the value of Mgrid has been applied to Mflat, but 237 it has not been removed from the GridOps.c structures. In order to avoid 238 double-counting, we need to skip Mgrid on the final calculation. 239 */ 240 227 241 // ** Choose the calibration (depends on the mode : do I have an image reference or not?) 228 242 float Mcal = 0.0, Mmos = 0.0, Mgrid = 0.0, Mflat = 0.0, Mgrp = 0.0; … … 235 249 Mcal = measureT[k].McalPSF; // check that this is zero for loaded REF value 236 250 } else { 237 // getMcal returns image[].Mcal ; note the flat-field correction is stored in measure.Mflat251 // getMcal returns image[].Mcal 238 252 Mcal = getMcal (meas, cat, MAG_CLASS_PSF); 239 253 if (isnan(Mcal)) SKIP_THIS_MEAS(Ncal); 240 Mmos = getMmos (meas, cat); 241 if (isnan(Mmos)) SKIP_THIS_MEAS(Nmos); 242 Mgrp = getMgrp (meas, cat, measureT[k].airmass, &dMgrp); 243 if (isnan(Mgrp)) SKIP_THIS_MEAS(Ngrp); 244 Mgrid = isSetMrelFinal ? 0.0 : getMgridTiny (&measureT[k]); 245 if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid); 254 255 // the flat-field correction is stored in measure.Mflat 246 256 Mflat = isnan (measureT[k].Mflat) ? 0.0 : measureT[k].Mflat; 247 } 248 // on the final calculation of Mrel the value of Mgrid has been applied to Mflat, but 249 // it has not been removed from the GridOps.c structures. In order to avoid double-counting, 250 // we need to skip Mgrid on the final calculation. 257 258 // see note above re: final output vs image analysis 259 if (!isSetMrelFinal) { 260 Mmos = getMmos (meas, cat); 261 if (isnan(Mmos)) SKIP_THIS_MEAS(Nmos); 262 Mgrp = getMgrp (meas, cat, measureT[k].airmass, &dMgrp); 263 if (isnan(Mgrp)) SKIP_THIS_MEAS(Ngrp); 264 Mgrid = getMgridTiny (&measureT[k]); 265 if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid); 266 } 267 } 251 268 252 269 int myUbercalDist = getUbercalDist(meas, cat); … … 367 384 } 368 385 386 // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps: 387 // NOTE: This test only applies if this bit was set by an earlier analysis 369 388 if (PRESERVE_PS1 && (secfilt[Nsec].flags & ID_SECF_HAS_PS1)) continue; 370 // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps:371 389 372 390 // XXX hardwired grizy = (01234) JHK = (567) w = (8) … … 419 437 int NrankingPSF = useOLS ? magStatsByRanking (&results->psfData[Nsec], psfstats) : magStatsByRankingIRLS (&results->psfData[Nsec], psfstats); 420 438 if (NrankingPSF < Nminmeas) { 421 secfilt[Nsec].flags |= ID_ OBJ_FEW;439 secfilt[Nsec].flags |= ID_SECF_STAR_FEW; 422 440 } else { 423 441 secfilt[Nsec].MpsfChp = psfstats->mean; 424 442 secfilt[Nsec].dMpsfChp = psfstats->error; 425 443 secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN; 444 secfilt[Nsec].flags &= ~ID_SECF_STAR_FEW; 426 445 } 427 446 … … 629 648 haveStackObject = TRUE; 630 649 631 // if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);632 633 650 int isPrimary = FALSE; 634 651 -
branches/eam_branches/relphot.20210521/src/setMrelFinal.c
r41624 r41625 13 13 ResetAverageAndMeasure (catalog); 14 14 15 // this sets flags in the measureT element, not the measure element 15 // This sets ID_MEAS flags in the measureT element, not the measure element 16 // These bits are thus ephemeral and not saved. 16 17 setExclusions (catalog, 1, VERBOSE); /* mark by area */ 17 // XXXXX THis probably does not make sense18 18 19 19 /* set catalog[0].found[i] = FALSE */ … … 31 31 setMrelOutput (catalog, 1); // sets the values secfilt.MpsfChp = <measure.M - image.Mcal - measure.Mflat> 32 32 setMcalOutput (catalog, 1); // sets measure.Mcal = image.Mcal 33 34 // clear ID_OBJ_POOR, ID_OBJ_FEW, ID_MEAS_NOCAL values before writing35 // These are internal bits, so they should be cleared36 // XXX are these still used?37 // XXX eventually: move these internal flags to an internal-only catalog->FOO element (like found)38 for (i = 0; i < catalog[0].Naverage; i++) {39 catalog[0].average[i].flags &= ~ID_OBJ_FEW;40 catalog[0].average[i].flags &= ~ID_OBJ_POOR;41 off_t j;42 for (j = 0; j < Nsecfilt; j++) {43 catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_OBJ_FEW;44 catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_OBJ_POOR;45 }46 off_t m = catalog[0].average[i].measureOffset;47 for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {48 catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;49 }50 }51 33 } 52 53 /* ID_MEAS_SKIP marks measurements which were not used to calculate Mrel */54 // For each star & photcode, we are selecting the measurements to use in the average55 // photometry value. This function is called several times, lowering the bar to56 // acceptance on each pass. The rejections at the different passes are:57 58 // 0 : only use measurements thought to be GOOD (photflags not POOR or BAD)59 // 1 : accept measurements thought to be POOR based on photflags60 // 2 : accept the measurements marked as outliers; accept images marked as outliers61 // 3 : accept measurements thought to be BAD based on photflags62 // 4 : accept the measurements outside of the instrumental magnitude limits (eg, SAT)63 64 // XXX if I'm reading this correctly, passes 0, 1, 2 are identical & accept all65 // non-outliers with Imag range66 34 67 35 // int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure) { … … 84 52 // } 85 53 86 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure); 87 88 // XXX this function is no longer used: 89 void skip_measurements (Catalog *catalog, int pass) { 90 91 off_t i, k, m; 92 off_t Ntot, Ntry, Nkeep, Nskip; 93 float mag; 94 95 int Nsecfilt = GetPhotcodeNsecfilt (); 96 97 Ntot = Ntry = Nskip = Nkeep = 0; 98 99 /* allow measures from images marked POOR and FEW */ 100 if (pass >= 3) IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL; 101 102 /* allow measures marked as outliers (POOR) and off image region (AREA) */ 103 if (pass >= 3) { 104 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_SKIP_PHOTOM; 105 } else { 106 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA; 107 } 108 109 /* mark measures which should be ignored on this pass */ 110 for (i = 0; i < catalog[0].Naverage; i++) { 111 Ntot += catalog[0].average[i].Nmeasure; 112 113 if (FALSE && (catalog[0].average[i].objID == 0x46a4) && (catalog[0].average[i].catID == 0xf40e)) { 114 fprintf (stderr, "test obj\n"); 115 print_measure_set (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], catalog[0].measure); 116 } 117 118 // mark measurements for each secfilt separately 119 int Ns; 120 for (Ns = 0; Ns < Nphotcodes; Ns++) { 121 122 int thisCode = photcodes[Ns][0].code; 123 int Nsec = GetPhotcodeNsec(thisCode); 124 125 /* star/photcodes already calibrated */ 126 if (catalog[0].found_t[Nsecfilt*i+Nsec]) continue; 127 128 m = catalog[0].average[i].measureOffset; 129 for (k = 0; k < catalog[0].average[i].Nmeasure; k++, m++) { 130 Ntry++; 131 132 // skip measurements not related to this photcode 133 PhotCode *code = GetPhotcodebyCode (catalog[0].measure[m].photcode); 134 if (!code) continue; 135 if (code->equiv != thisCode) continue; 136 137 // skip measurements by time range (mark as skipped for this secfilt) 138 // XXX note that this is a bit dangerous : some objects may never get calibrated 139 if (TimeSelect) { 140 if (catalog[0].measure[m].t < TSTART) goto skip; 141 if (catalog[0].measure[m].t > TSTOP) goto skip; 142 } 143 144 // we now have a measurement relavant to this photcode (and time range) 145 146 // clear SKIP for all measures at first 147 catalog[0].measureT[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 148 catalog[0].measure [m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 149 150 // skip measurements from BAD images and mosaics (not REF mags) 151 // do NOT skip measurements without a matching image (REF mags) 152 off_t Nim = getImageEntry (m, 0); 153 if (Nim > -1) { 154 if (isnan(getMcal (m, 0, MAG_CLASS_PSF))) goto skip; 155 if (isnan(getMmos (m, 0))) goto skip; 156 } 157 158 // PASS 4 : skip measurements by inst mag limit (not REF mags) 159 if ((pass < 4) && ImagSelect) { 160 if (Nim > -1) { 161 mag = PhotInst (&catalog[0].measure[m], MAG_CLASS_PSF); 162 if (mag < ImagMin) goto skip; 163 if (mag > ImagMax) goto skip; 164 } 165 } 166 167 // PASS 3 : accept bad measurements (eg, SAT, CR), internal outliers 168 if (pass < 3) { 169 if (catalog[0].measure[m].photFlags & code->photomBadMask) goto skip; 170 if ((catalog[0].measure[m].photcode > 10000) && (catalog[0].measure[m].photcode < 10500)) { 171 if (catalog[0].measure[m].psfQF < 0.85) goto skip; 172 } 173 } 174 175 // PASS 2 : (no additional cut) 176 177 // PASS 1 : accept poor measurements as well (eg, POOR FIT, etc) 178 if ((pass < 1) && (catalog[0].measure[m].photFlags & code->photomPoorMask)) goto skip; 179 180 // PASS 0 : skip poor, outlier, bad measurements as well (eg, POOR FIT, etc) 181 182 Nkeep ++; 183 184 continue; 185 186 skip: 187 catalog[0].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM; 188 catalog[0].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM; 189 Nskip ++; 190 } 191 } 192 } 193 if (VERBOSE) fprintf (stderr, "pass %d, Ntot: "OFF_T_FMT", Ntry: "OFF_T_FMT", Nskip: "OFF_T_FMT", Nkeep: "OFF_T_FMT"\n", 194 pass, Ntot, Ntry, Nskip, Nkeep); 195 } 196 197 // XXX review this, especially the good/bad images 198 // by this point, we have propagated the mosaic and tgroup flags to each image 54 // This function is only called for the final output step. By this point, we have 55 // propagated the mosaic and tgroup flags to each image. 199 56 void setMeasureRank (Catalog *catalog) { 200 57 201 58 int i; 202 59 203 // make these global204 int IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;205 int IMAGE_POOR = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;206 int MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_SKIP_PHOTOM;207 int MEAS_POOR = ID_MEAS_POOR_PHOTOM | ID_MEAS_AREA;208 209 60 Measure *measure = catalog[0].measure; 210 MeasureTiny *measureT = catalog[0].measureT;211 61 char *measureRank = catalog[0].measureRank; 212 62 … … 215 65 measureRank[i] = 11; // start at a low rank 216 66 217 // clear SKIP for all measures at first 218 measureT[i].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 219 measure [i].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 220 221 // skip measurements without a valid photcode 67 // measurements without a valid photcode have lowest rank (should not be used anyway) 222 68 PhotCode *code = GetPhotcodebyCode (measure[i].photcode); 223 69 if (!code) continue; … … 225 71 // measurements outside time range have poor rank 226 72 if (TimeSelect) { 227 if (measure[i].t < TSTART) { measureRank[i] = 10; continue; }228 if (measure[i].t > TSTOP) { measureRank[i] = 10; continue; }73 if (measure[i].t < TSTART) { measureRank[i] = 10; continue; } 74 if (measure[i].t > TSTOP) { measureRank[i] = 10; continue; } 229 75 } 230 76 231 // measurements from BAD images and mosaics (not REF mags)232 off_t Nim = getImageEntry (i, 0);77 // Nim < 0 for REF mags, imageFlags have bits for IMAGE, MOSAIC, NIGHT 78 off_t Nim = getImageEntry (i, 0); 233 79 int imageFlags = getImageFlags (i, 0); 234 int mosaicFlags = getMosaicFlags (i, 0);235 80 236 81 if (Nim > -1) { 237 if (imageFlags & IMAGE_BAD) { measureRank[i] = 9; continue; }238 239 if (mosaicFlags & IMAGE_BAD) { measureRank[i] = 9; continue; }240 241 82 // measurements ranked by inst mag limit (not REF mags) 242 83 if (ImagSelect) { 243 84 float mag = PhotInst (&measure[i], MAG_CLASS_PSF); 244 if (mag < ImagMin) { measureRank[i] = 8; continue; }245 if (mag > ImagMax) { measureRank[i] = 8; continue; }85 if (mag < ImagMin) { measureRank[i] = 9; continue; } 86 if (mag > ImagMax) { measureRank[i] = 9; continue; } 246 87 } 247 88 } 248 89 249 // RANK 1 : BAD photFlags 250 if (measure[i].dbFlags & MEAS_BAD) { measureRank[i] = 7; continue; } 251 252 // RANK 3 : BAD photFlags (eg, SAT, CR), internal outliers 253 if (measure[i].photFlags & code->photomBadMask) { measureRank[i] = 6; continue; } 254 90 // RANK 8 : Poor image 255 91 if (Nim > -1) { 256 if (imageFlags & IMAGE_POOR) { measureRank[i] = 5; continue; } 257 if (mosaicFlags & IMAGE_POOR) { measureRank[i] = 5; continue; } 92 if (imageFlags & ID_IMAGE_PHOTOM_POOR) { measureRank[i] = 8; continue; } 258 93 } 259 94 260 // RANK 2 : psfQF value 261 if (!isfinite(measure[i].psfQF) || measure[i].psfQF < 0.85) { measureRank[i] = 4; continue; } 95 // RANK 7 : BAD photFlags (eg, SAT, CR), internal outliers 96 if (measure[i].photFlags & code->photomBadMask) { measureRank[i] = 7; continue; } 97 98 // RANK 6 : bad psfQF value 99 if (!isfinite(measure[i].psfQF) || measure[i].psfQF < 0.85) { measureRank[i] = 6; continue; } 262 100 263 // RANK 1 : POOR photFlags264 if (measure[i].dbFlags & MEAS_POOR) { measureRank[i] = 3; continue; }101 // RANK 5 : not in valid chip region 102 if (measure[i].dbFlags & ID_MEAS_AREA) { measureRank[i] = 5; continue; } 265 103 266 // RANK 1: POOR photFlags267 if (measure[i].photFlags & code->photomPoorMask) { measureRank[i] = 2; continue; }104 // RANK 4 : POOR photFlags 105 if (measure[i].photFlags & code->photomPoorMask) { measureRank[i] = 4; continue; } 268 106 269 // RANK 1 :psfQFperfect value270 if (!isfinite(measure[i].psfQFperf) || measure[i].psfQFperf < 0.85) { measureRank[i] = 1; continue; }107 // RANK 3 : bad psfQFperfect value 108 if (!isfinite(measure[i].psfQFperf) || measure[i].psfQFperf < 0.85) { measureRank[i] = 3; continue; } 271 109 110 // RANK 2 : Poor mosaic 111 if (Nim > -1) { 112 if (imageFlags & ID_IMAGE_MOSAIC_POOR) { measureRank[i] = 2; continue; } 113 } 114 115 // RANK 1 : Poor night 116 if (Nim > -1) { 117 if (imageFlags & ID_IMAGE_NIGHT_POOR) { measureRank[i] = 1; continue; } 118 } 272 119 // RANK 0 : perfect measurement: 273 120 measureRank[i] = 0;
Note:
See TracChangeset
for help on using the changeset viewer.
