- Timestamp:
- Jan 4, 2021, 4:33:51 PM (6 years ago)
- Location:
- trunk/Ohana/src/relphot
- Files:
-
- 1 added
- 17 edited
-
Makefile (modified) (3 diffs)
-
include/relphot.h (modified) (11 diffs)
-
src/GridOps.c (modified) (3 diffs)
-
src/ImageOps.c (modified) (5 diffs)
-
src/MosaicOps.c (modified) (22 diffs)
-
src/StarOps.c (modified) (3 diffs)
-
src/TGroupOps.c (modified) (42 diffs)
-
src/ZeroPointModes.c (added)
-
src/args.c (modified) (3 diffs)
-
src/extra.c (modified) (1 diff)
-
src/fit1d_irls.c (modified) (3 diffs)
-
src/global_stats.c (modified) (5 diffs)
-
src/liststats.c (modified) (1 diff)
-
src/relphot_images.c (modified) (3 diffs)
-
src/relphot_parallel_images.c (modified) (2 diffs)
-
src/setMrelCatalog.c (modified) (12 diffs)
-
src/test_fitirls.c (modified) (3 diffs)
-
test/relphot.tgroups.dvo (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/relphot/Makefile
r41453 r41462 77 77 $(SRC)/indexCatalog.$(ARCH).o \ 78 78 $(SRC)/client_logger.$(ARCH).o \ 79 $(SRC)/ZeroPointModes.$(ARCH).o \ 79 80 $(SRC)/setExclusions.$(ARCH).o \ 80 81 $(SRC)/setMrelFinal.$(ARCH).o \ … … 124 125 $(SRC)/synthetic_zpts.$(ARCH).o \ 125 126 $(SRC)/client_logger.$(ARCH).o \ 127 $(SRC)/ZeroPointModes.$(ARCH).o \ 126 128 $(SRC)/setExclusions.$(ARCH).o \ 127 129 $(SRC)/setMrelFinal.$(ARCH).o \ … … 143 145 TEST_FITIRLS = \ 144 146 $(SRC)/fit1d_irls.$(ARCH).o \ 147 $(SRC)/extra.$(ARCH).o \ 145 148 $(SRC)/test_fitirls.$(ARCH).o 146 149 -
trunk/Ohana/src/relphot/include/relphot.h
r41453 r41462 84 84 float secz; 85 85 float ubercalDist; 86 unsigned short nFitPhotom; 86 unsigned int nFitPhotom; 87 unsigned int nValPhotom; 87 88 unsigned int flags; 88 89 char skipCal; // if TRUE, this mosaic is incomplete and should not be calibrated 90 char inTGroup; 89 91 Coords coords; 90 92 } Mosaic; … … 97 99 float dMcal; 98 100 float dMsys; 101 float stdev; 99 102 float McalChiSq; 100 unsigned short nFitPhotom; 103 unsigned int nFitPhotom; 104 unsigned int nValPhotom; 101 105 unsigned int flags; 102 106 … … 109 113 off_t *measure; 110 114 off_t *catalog; 115 116 off_t Nmosaic; 117 off_t NMOSAIC; 118 Mosaic **mosaic; // pointer to the mosaic structures 111 119 112 120 void *parent; … … 185 193 int Nlist; // total number of measurements in list (may be more than the number to use) 186 194 int Nbootstrap; // number of bootstrap iterations 195 int MaxIterations; // number of IRLS iterations 187 196 188 197 // input data & parameters: … … 387 396 int VERBOSE2; 388 397 int VERBOSE_IMAGE; 398 389 399 int MOSAIC_ZEROPT; 390 400 int TGROUP_ZEROPT; 401 402 int FREEZE_IMAGES; 403 int FREEZE_MOSAICS; 404 391 405 int TGROUP_FIT_AIRMASS; 392 406 … … 414 428 double IMAGE_GOOD_FRACTION; 415 429 int IMAGE_BAD; 416 int FREEZE_IMAGES;417 int FREEZE_MOSAICS;418 430 int CALIBRATE_STACKS_AND_WARPS; 419 431 int USE_GRID; … … 461 473 SkyRegion UserPatch; 462 474 char *UserCatalog; 475 476 enum {TGROUP_ZPT_MODE_NONE, TGROUP_ZPT_MODE_GOOD_NIGHT, TGROUP_ZPT_MODE_ALL, }; 477 int TGROUP_ZPT_MODE; 478 479 enum {MOSAIC_ZPT_MODE_NONE, MOSAIC_ZPT_MODE_BAD_NIGHT, MOSAIC_ZPT_MODE_GOOD_MOSAIC, MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC, MOSAIC_ZPT_MODE_ALL, }; 480 int MOSAIC_ZPT_MODE; 481 482 enum {IMAGE_ZPT_MODE_NONE, IMAGE_ZPT_MODE_BAD_NIGHT, IMAGE_ZPT_MODE_BAD_MOSAIC, IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC, IMAGE_ZPT_MODE_ALL, }; 483 int IMAGE_ZPT_MODE; 463 484 464 485 int USE_ALL_IMAGES; … … 526 547 float getMgrid PROTO((off_t meas, int cat)); 527 548 float getMmos PROTO((off_t meas, int cat)); 528 float getMgrp PROTO((off_t meas, int cat, float airmass ));549 float getMgrp PROTO((off_t meas, int cat, float airmass, float *dZpt)); 529 550 float getMrel PROTO((Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source)); 530 551 short getUbercalDist PROTO((off_t meas, int cat)); … … 601 622 int reload_images PROTO((FITS_DB *db)); 602 623 int setExclusions PROTO((Catalog *catalog, int Ncatalog, int verbose)); 603 void setM cal PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));624 void setMgrid PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr)); 604 625 void setMcalFromMosaics PROTO((void)); 605 626 void setMcalFromTGroups PROTO((void)); 606 627 int setMcalOutput PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr)); 607 void setMgrid PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr)); 608 int setMmos PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr)); 609 int setMgrp PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr)); 628 629 void setMcal PROTO((Catalog *catalog, int Nloop, int Poor, FlatCorrectionTable *flatcorr)); 630 int setMmos PROTO((Catalog *catalog, int Nloop, int Poor, FlatCorrectionTable *flatcorr)); 631 int setMgrp PROTO((Catalog *catalog, int Nloop, int Poor, FlatCorrectionTable *flatcorr)); 632 610 633 int setMrel PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr)); 611 634 void setMrelFinal PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr, int simpleAverage)); 612 635 int setMrelOutput PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr)); 636 613 637 int setMave PROTO((Catalog *catalog, int Ncatalog)); 614 638 void set_ZP PROTO((double ZERO)); … … 627 651 StatType statsMosaicX PROTO((Catalog *catalog)); 628 652 StatType statsMosaicdM PROTO((Catalog *catalog)); 653 StatType statsTGroupM PROTO((Catalog *catalog)); 654 StatType statsTGroupX PROTO((Catalog *catalog)); 655 StatType statsTGroupdM PROTO((Catalog *catalog)); 656 629 657 StatType statsStarN PROTO((Catalog *catalog, int Ncatalog, int Nsec, int seccode, FlatCorrectionTable *flatcorr)); 630 658 StatType statsStarS PROTO((Catalog *catalog, int Ncatalog, int Nsec)); … … 795 823 796 824 int save_images_backup (FITS_DB *db); 825 826 void dump_tgroups (Catalog *catalog, int Npass); 827 void dump_catalog (Catalog *catalog, off_t c, int Npass); 828 829 void SetZeroPointModes (int nloop); -
trunk/Ohana/src/relphot/src/GridOps.c
r41390 r41462 415 415 416 416 // skip mosaics marked as BAD 417 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );417 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 418 418 if (isnan(Mgrp)) { 419 419 Ngrp ++; … … 575 575 continue; 576 576 } 577 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );577 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 578 578 if (isnan(Mgrp)) { 579 579 Ngrp ++; … … 661 661 Mmos = getMmos (m, c); 662 662 if (isnan(Mmos)) continue; 663 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );663 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 664 664 if (isnan(Mgrp)) continue; 665 665 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); -
trunk/Ohana/src/relphot/src/ImageOps.c
r41453 r41462 581 581 582 582 /* determine Mcal values for all images */ 583 void setMcal (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {583 void setMcal (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) { 584 584 585 585 off_t i, j, m, c, n; 586 586 int mark, bad, Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys; 587 587 588 // FREEZE_IMAGES only applies to mosaic data (eg, gpc1)588 if (IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_NONE) return; 589 589 590 590 fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE); … … 609 609 FitDataSetAlloc (&brightStars, Nmax, 0, 0); 610 610 611 // until the analysis has converged a bit, do not use the IRLS analysis 612 if (Nloop < 3) { 613 brightStars.MaxIterations = 0; 614 kronStars.MaxIterations = 0; 615 psfStars.MaxIterations = 0; 616 } 617 618 611 619 Nfew = Nbad = Nmos = Ngrp = Ngrid = Nrel = Nsys = 0; 612 620 … … 627 635 } 628 636 629 // only freeze the gpc1 chips 630 // XXX : when do we FREEZE_IMAGES in a mix of GPC1, GPC2, etc? 631 // if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue; 632 if (FREEZE_IMAGES) continue; 637 // if requested, freeze mosaic chips: 638 if (FREEZE_IMAGES && isMosaicChip (image[i].photcode)) continue; 633 639 if (image[i].photcode == 0) continue; // skip the PHU images 640 641 int badNight = (image[i].flags & ID_IMAGE_NIGHT_POOR); 642 int badMosaic = (image[i].flags & ID_IMAGE_MOSAIC_POOR); 643 644 // in BAD_NIGHT mode, we fit ONLY images in bad nights 645 if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT)) { 646 if (!badNight) continue; 647 } 648 649 // in BAD_NIGHT_BAD_MOSAIC mode, we fit ONLY bad mosaics in bad nights 650 if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC)) { 651 if (!badNight) continue; 652 if (!badMosaic) continue; 653 } 654 655 // in BAD_MOSAIC mode, we fit bad mosaics ignoring night state 656 if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_MOSAIC)) { 657 if (badMosaic) continue; 658 } 634 659 635 660 // UBERCAL image: if this is an ubercal image, set minUbercalDist to 0: … … 665 690 continue; 666 691 } 667 float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );692 float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); // ignore error for now? 668 693 if (isnan(Mgrp)) { 669 694 Ngrp ++; … … 1027 1052 Mmos = getMmos (m, c); 1028 1053 if (isnan(Mmos)) continue; 1029 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );1054 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1030 1055 if (isnan(Mgrp)) continue; 1031 1056 Mgrid = getMgrid (m, c); -
trunk/Ohana/src/relphot/src/MosaicOps.c
r41454 r41462 10 10 // relationships between the mosaics and their associated images 11 11 static off_t *MosaicN_Image; // number of images associated with the given mosaic 12 static off_t **MosaicToImage; // list of images aassociated with the given mosaic12 static off_t **MosaicToImage; // list of images associated with the given mosaic 13 13 14 14 // mosaic index for given image : ImageToMosaic[ImageIndex] = MosaicIndex (ImageIndex : 0 < Nimage) … … 219 219 mosaic[i].photcode = 0; 220 220 mosaic[i].skipCal = FALSE; 221 mosaic[i].inTGroup = FALSE; // not (yet?) assigned to a TGroup 221 222 222 223 memset (&mosaic[i].coords, 0, sizeof(Coords)); … … 301 302 mosaic[j].dMcal = 0.0; 302 303 mosaic[j].McalChiSq = 0.0; 304 305 mosaic[j].nFitPhotom = 0; 306 mosaic[j].nValPhotom = 0; 303 307 304 308 mosaic[j].dMsys = subset[i].flags; … … 750 754 } 751 755 756 void markBadMosaic (int myMosaic) { 757 758 off_t Nimage; 759 Image *image; 760 761 // this mosaic has been identified as poor. 762 mosaic[myMosaic].flags |= ID_IMAGE_PHOTOM_POOR; 763 mosaic[myMosaic].McalPSF = 0.0; 764 mosaic[myMosaic].McalAPER = 0.0; 765 766 image = getimages (&Nimage, NULL); 767 768 // all images should be marked as coming from a bad mosaic 769 // these will be fitted independently 770 for (off_t i = 0; i < MosaicN_Image[myMosaic]; i++) { 771 off_t im = MosaicToImage[myMosaic][i]; 772 image[im].flags |= ID_IMAGE_MOSAIC_POOR; 773 } 774 } 775 776 void markGoodMosaic (int myMosaic) { 777 778 off_t Nimage; 779 Image *image; 780 781 // this mosaic has been identified as good. 782 mosaic[myMosaic].flags &= ~ID_IMAGE_PHOTOM_POOR; 783 784 image = getimages (&Nimage, NULL); 785 786 // all images should be marked as NOT coming from a bad mosaic 787 for (off_t i = 0; i < MosaicN_Image[myMosaic]; i++) { 788 off_t im = MosaicToImage[myMosaic][i]; 789 image[im].flags &= ~ID_IMAGE_MOSAIC_POOR; 790 } 791 } 792 752 793 void initMosaicBins (Catalog *catalog, int Ncatalog, int doMosaicList) { 753 794 … … 923 964 int Nsys; 924 965 int Nskip; 966 int Nloop; 925 967 off_t Nmax; 926 968 int PoorImages; … … 943 985 int setMmos_mosaic (Mosaic *mosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info, FlatCorrectionTable *flatcorr); 944 986 void *setMmos_worker (void *data); 945 int setMmos_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr);946 947 void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists, int PoorImages ) {987 int setMmos_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr); 988 989 void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists, int PoorImages, int Nloop) { 948 990 info->Nfew = 0; 949 991 info->Nbad = 0; … … 955 997 956 998 info->Nmax = Nmax; 999 info->Nloop = Nloop; 957 1000 info->PoorImages = PoorImages; 958 1001 … … 962 1005 FitDataSetAlloc (&info->kronStars, Nmax, 0, 0); 963 1006 FitDataSetAlloc (&info->brightStars, Nmax, 0, 0); 1007 1008 // until the analysis has converged a bit, do not use the IRLS analysis 1009 if (Nloop < 3) { 1010 info->brightStars.MaxIterations = 0; 1011 info->kronStars.MaxIterations = 0; 1012 info->psfStars.MaxIterations = 0; 1013 } 964 1014 } 965 1015 } … … 1003 1053 } 1004 1054 1005 int setMmos (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {1055 int setMmos (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) { 1006 1056 1007 1057 off_t i, N, Nmax; 1008 1058 Image *image; 1009 1059 1010 if (!MOSAIC_ZEROPT) return (FALSE); 1011 if (FREEZE_MOSAICS) return (FALSE); 1060 if (!MOSAIC_ZEROPT) return FALSE; 1061 if (FREEZE_MOSAICS) return FALSE; 1062 1063 if (MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_NONE) return FALSE; 1012 1064 1013 1065 // plots cannot be done in a threaded context (the plot commands collide) 1014 1066 // so do not run setMmos in threaded mode if PLOTSTUFF is set 1015 1067 if (NTHREADS && !PLOTSTUFF) { 1016 int status = setMmos_threaded (catalog, PoorImages, flatcorr);1068 int status = setMmos_threaded (catalog, Nloop, PoorImages, flatcorr); 1017 1069 return status; 1018 1070 } … … 1034 1086 1035 1087 SetMmosInfo info; 1036 SetMmosInfoInit (&info, Nmax, TRUE, PoorImages );1088 SetMmosInfoInit (&info, Nmax, TRUE, PoorImages, Nloop); 1037 1089 1038 1090 // int savePlotDelay = PLOTDELAY; … … 1078 1130 assert (Nmos >= 0); 1079 1131 assert (Nmos < Nmosaic); 1132 1133 int badNight = (myMosaic[0].flags & ID_IMAGE_NIGHT_POOR); 1134 int badMosaic = (myMosaic[0].flags & ID_IMAGE_MOSAIC_POOR); 1135 1136 // if we are fitting TGroup zero points, when we identify the bad TGroups, we proceed 1137 // to fit the mosaics which are from the bad TGroups 1138 1139 // if we are fitting Mosaic zero points, when we identify the bad nights, we proceed 1140 // to fit the images which are from the bad Mosaics 1141 1142 // in BAD_NIGHT mode, we fit ONLY mosaics in bad nights 1143 if (MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT) { 1144 if (!badNight) return TRUE; 1145 } 1146 1147 // in BAD_NIGHT_GOOD_MOSAIC mode, we fit ONLY good mosaics in bad nights 1148 if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC)) { 1149 if (!badNight) return TRUE; 1150 if (badMosaic) return TRUE; 1151 } 1152 1153 // in GOOD_MOSAIC mode, we fit good mosaics ignoring night state 1154 if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_GOOD_MOSAIC)) { 1155 if (badMosaic) return TRUE; 1156 } 1080 1157 1081 1158 // Image *imageReal = getimages (&NimageReal, NULL); returned pointer is not used … … 1140 1217 if (fout) { 1141 1218 float Mcal = getMcal (m, c, MAG_CLASS_PSF); 1142 // float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );1219 // float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1143 1220 float Mgrid = getMgrid (m, c); 1144 1221 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); … … 1164 1241 continue; 1165 1242 } 1166 float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );1243 float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1167 1244 if (isnan(Mgrp)) { 1168 1245 info->Ngrp++; … … 1257 1334 myMosaic[0].McalChiSq = psfStars->chisq; 1258 1335 myMosaic[0].nFitPhotom = psfStars->Nmeas; 1336 myMosaic[0].nValPhotom = N; 1259 1337 1260 1338 // fit1d_irls (kronStars, N); // does it make sense to calculate a zero point based kron mags? … … 1296 1374 } 1297 1375 1298 int setMmos_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {1376 int setMmos_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) { 1299 1377 1300 1378 int i; … … 1317 1395 1318 1396 SetMmosInfo summary; 1319 SetMmosInfoInit (&summary, Nmax, FALSE, PoorImages );1397 SetMmosInfoInit (&summary, Nmax, FALSE, PoorImages, Nloop); 1320 1398 1321 1399 pthread_attr_t attr; … … 1340 1418 threadinfo[i].image = image; 1341 1419 threadinfo[i].flatcorr = flatcorr; 1342 SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages); 1420 1421 // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop, 1422 // PoorImages) used in the threads to allocate the arrays and set the MaxIterations 1423 SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages, Nloop); 1343 1424 pthread_create (&threads[i], NULL, setMmos_worker, &threadinfo[i]); 1344 1425 } … … 1398 1479 1399 1480 SetMmosInfo results; 1400 SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages ); // allocate list, dlist arrays here1481 SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages, threadinfo->info.Nloop); 1401 1482 1402 1483 while (1) { … … 1709 1790 Mcal = getMcal (m, c, MAG_CLASS_PSF); 1710 1791 if (isnan(Mcal)) continue; 1711 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass );1792 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1712 1793 if (isnan(Mgrp)) continue; 1713 1794 Mgrid = getMgrid (m, c); … … 1767 1848 void clean_mosaics () { 1768 1849 1769 off_t i, N, mark, N mark, Nscatter, Noffset;1850 off_t i, N, mark, Ntotal, Nmark, Nscatter, Noffset, Nrejects, Nchisq; 1770 1851 double *mlist, *slist, *dlist; 1771 1852 double MaxOffset, MedOffset, MaxScatter; … … 1800 1881 fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset); 1801 1882 1802 Nmark = Nscatter = Noffset = 0; 1883 // XXX this needs to be configurable 1884 float MaxChiSq = 10.0; 1885 1886 Ntotal = Nmark = Nscatter = Noffset = Nrejects = Nchisq = 0; 1803 1887 for (i = 0; i < Nmosaic; i++) { 1804 1888 // if we are keeping ubercal sacrosanct, then we should not be allowed to break them... 1805 1889 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; 1806 1890 1807 if (mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP)) continue; 1891 Ntotal ++; 1892 1893 if (mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW)) { 1894 continue; 1895 } 1808 1896 if (mosaic[i].skipCal) continue; 1809 1897 … … 1817 1905 Noffset ++; 1818 1906 } 1907 if (mosaic[i].nFitPhotom < 0.7*mosaic[i].nValPhotom) { 1908 mark = TRUE; 1909 Nrejects ++; 1910 } 1911 if (mosaic[i].McalChiSq > MaxChiSq) { 1912 mark = TRUE; 1913 Nchisq ++; 1914 } 1819 1915 if (mark) { 1820 1916 Nmark ++; 1821 m osaic[i].flags |= ID_IMAGE_PHOTOM_POOR;1917 markBadMosaic(i); // mark the images associated with a bad night 1822 1918 } else { 1823 m osaic[i].flags &= ~ID_IMAGE_PHOTOM_POOR;1824 } 1825 } 1826 1827 fprintf (stderr, OFF_T_FMT" mosaics marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n", Nmark, Nscatter, Noffset);1919 markGoodMosaic(i); // mark the images associated with a good night 1920 } 1921 } 1922 1923 fprintf (stderr, OFF_T_FMT" of "OFF_T_FMT" mosaics marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n", Nmark, Ntotal, Nscatter, Noffset); 1828 1924 1829 1925 free (mlist); -
trunk/Ohana/src/relphot/src/StarOps.c
r41453 r41462 493 493 float Mmos = getMmos (m, i); 494 494 if (isnan(Mmos)) continue; 495 float Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass );495 float Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL); 496 496 if (isnan(Mgrp)) continue; 497 497 float Mgrid = getMgrid (m, i); … … 733 733 Mmos = getMmos (m, i); 734 734 if (isnan(Mmos)) { Nmos ++; continue; } 735 Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass );735 Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL); 736 736 if (isnan(Mgrp)) { Ngrp ++; continue; } 737 737 Mgrid = getMgrid (m, i); … … 1082 1082 } 1083 1083 1084 void dump_catalog (Catalog *catalog, off_t c, int Npass) { 1085 1086 int Nsecfilt = GetPhotcodeNsecfilt (); 1087 1088 FILE *fout = NULL; 1089 char filename[64]; 1090 snprintf (filename, 64, "tcat.%02d.dat", Npass); 1091 fout = fopen (filename, "w"); 1092 1093 for (off_t n = 0; n < catalog[c].Naverage; n++) { 1094 1095 off_t m = catalog[c].averageT[n].measureOffset; 1096 for (off_t k = 0; k < catalog[c].averageT[n].Nmeasure; k++, m++) { 1097 1098 float Mcal = getMcal (m, c, MAG_CLASS_PSF); // image zero point 1099 float Mmos = getMmos (m, c); // mosaic zero point 1100 float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1101 1102 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude 1103 // float Mgrid = getMgrid (m, c); // camera offset (deprecated?) 1104 // float Mflat = getMflat (m, c, flatcorr, catalog); // flat-field correction 1105 1106 off_t n = catalog[c].measureT[m].averef; 1107 1108 // nominal magnitude for this measurement (instrumental + Ko(airmass - 1) + Co 1109 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 1110 1111 // for historical reasons, Mflat is defined with the wrong sign 1112 float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrp; 1113 1114 fprintf (fout, "%f %f : %f %f : %f %f %f : %f %f\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mmos, Mgrp, catalog[c].measureT[m].airmass, delta); 1115 } 1116 } 1117 fclose (fout); 1118 } -
trunk/Ohana/src/relphot/src/TGroupOps.c
r41454 r41462 1 1 # include "relphot.h" 2 3 void assignMosaicsToTGroups (void); 2 4 3 5 // tgroupTimes carries the times of the tgroups (initially, just the photometric nights) … … 78 80 tgroup[j].dMsys = 0.0; 79 81 tgroup[j].McalChiSq = 0.0; // NAN or 0.0? 82 83 tgroup[j].stdev = NAN; 84 tgroup[j].nFitPhotom = 0; 85 tgroup[j].nValPhotom = 0; 86 80 87 tgroup[j].flags = ID_IMAGE_PHOTOM_UBERCAL; // we start by treating the suspected photometric nights as photometric 81 88 tgroup[j].photcode = photcodes[j][0].code; … … 85 92 ALLOCATE (tgroup[j].image, off_t, tgroup[j].NIMAGE); 86 93 tgroup[j].image[0] = -1; 94 95 tgroup[j].NMOSAIC = 100; 96 tgroup[j].Nmosaic = 0; 97 ALLOCATE (tgroup[j].mosaic, Mosaic *, tgroup[j].NMOSAIC); 87 98 88 99 tgroup[j].Nmeasure = 0; … … 129 140 tgroup[j].dMsys = 0.0; 130 141 tgroup[j].McalChiSq = 0.0; // NAN or 0.0? 142 143 tgroup[j].stdev = NAN; 144 tgroup[j].nFitPhotom = 0; 145 tgroup[j].nValPhotom = 0; 146 131 147 tgroup[j].flags = 0; // tgroups NOT in the original file are not suspected as photometric 132 148 tgroup[j].photcode = photcodes[j][0].code; 149 133 150 tgroup[j].NIMAGE = 1000; 134 151 tgroup[j].Nimage = 0; // the new TGroup is not suspected to be photometric 135 152 ALLOCATE (tgroup[j].image, off_t, tgroup[j].NIMAGE); 136 153 tgroup[j].image[0] = -1; 154 155 tgroup[j].NMOSAIC = 100; 156 tgroup[j].Nmosaic = 0; 157 ALLOCATE (tgroup[j].mosaic, Mosaic *, tgroup[j].NMOSAIC); 158 137 159 tgroup[j].Nmeasure = 0; 138 160 tgroup[j].NMEASURE = 1000; … … 199 221 } 200 222 223 // assign the mosaics to each tgroup -- we do this by image 224 assignMosaicsToTGroups (); 225 201 226 initTGroupsMcal (); 202 227 … … 215 240 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 216 241 free (tgroup[j].image); 242 free (tgroup[j].mosaic); 217 243 free (tgroup[j].measure); 218 244 free (tgroup[j].catalog); … … 249 275 tgroup[j].dMsys = 0.0; 250 276 tgroup[j].McalChiSq = 0.0;// NAN or 0.0? 277 278 tgroup[j].stdev = NAN; 279 tgroup[j].nFitPhotom = 0; 280 tgroup[j].nValPhotom = 0; 251 281 252 282 if (tgroup[j].Nimage == 0) continue; // no images, ignore the tgroup … … 278 308 } 279 309 310 void assignMosaicsToTGroups (void) { 311 312 if (!TGROUP_ZEROPT) return; 313 314 // init the tgroup array values 315 for (int i = 0; i < NtgroupTimes; i++) { 316 TGroup *tgroup = tgroupTimes[i][0].byCode; 317 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 318 319 if (tgroup[j].Nimage == 0) continue; // no images, ignore the tgroup 320 321 // find the mosaics by image (if MOSAIC_ZEROPT is active) 322 for (int im = 0; MOSAIC_ZEROPT && (im < tgroup[j].Nimage); im++) { 323 int imageIdx = tgroup[j].image[im]; 324 Mosaic *mosaic = getMosaicForImage (imageIdx); 325 326 if (mosaic->inTGroup) continue; 327 328 // mosaic to tgroup and extend as needed 329 tgroup[j].mosaic[tgroup[j].Nmosaic] = mosaic; 330 mosaic->inTGroup = TRUE; 331 332 // advance array and extend if needed 333 tgroup[j].Nmosaic ++; 334 if (tgroup[j].Nmosaic >= tgroup[j].NMOSAIC) { 335 tgroup[j].NMOSAIC += 100; 336 REALLOCATE (tgroup[j].mosaic, Mosaic *, tgroup[j].NMOSAIC); 337 } 338 } 339 } 340 } 341 return; 342 } 343 280 344 TGroup *getTGroupForImage (off_t im) { 281 345 … … 345 409 346 410 fprintf (stderr, "*** return Mcal from tgroup.Mcal to image.Mcal ***\n"); 411 412 // NOTE: nights which are poor should have had Mcal set to 0, making this a NOP for those nights 347 413 348 414 // copy the tgroup results to the images. set the tgroup Mcal to 0.0 since we have moved its … … 360 426 image[im].dMagSys = tgroup[i].dMsys; 361 427 image[im].nFitPhotom = tgroup[i].nFitPhotom; 428 image[im].flags |= (tgroup[i].flags & ID_IMAGE_NIGHT_POOR); // XXX copy this down? 429 image[im].flags |= (tgroup[i].flags & ID_IMAGE_MOSAIC_POOR); // XXX copy this down? 362 430 image[im].flags |= (tgroup[i].flags & ID_IMAGE_PHOTOM_FEW); 363 431 image[im].flags |= (tgroup[i].flags & ID_IMAGE_PHOTOM_POOR); … … 371 439 } 372 440 } 441 } 442 443 void markBadTGroup (TGroup *tgroup) { 444 445 off_t Nimage; 446 Image *image; 447 448 // this tgroup has been identified as poor. 449 tgroup->flags |= ID_IMAGE_NIGHT_POOR; 450 451 // all associated mosaics should be marked as coming from a bad night 452 // these will be fitted independently 453 for (off_t j = 0; j < tgroup->Nmosaic; j++) { 454 tgroup->mosaic[j]->flags |= ID_IMAGE_NIGHT_POOR; 455 } 456 457 // all associated images should be marked as coming from a bad night 458 // these will be fitted independently 459 image = getimages (&Nimage, NULL); 460 for (off_t j = 0; j < tgroup->Nimage; j++) { 461 off_t im = tgroup->image[j]; 462 image[im].flags |= ID_IMAGE_NIGHT_POOR; 463 } 464 465 tgroup->McalPSF = 0.0; 466 tgroup->McalAPER = 0.0; 467 tgroup->dKlam = 0.0; 468 } 469 470 void markGoodTGroup (TGroup *tgroup) { 471 472 off_t Nimage; 473 Image *image; 474 475 // this tgroup has been identified as good. 476 tgroup->flags &= ~ID_IMAGE_NIGHT_POOR; 477 478 // all associated mosaics should be marked as NOT coming from a bad night 479 for (off_t j = 0; j < tgroup->Nmosaic; j++) { 480 tgroup->mosaic[j]->flags &= ~ID_IMAGE_NIGHT_POOR; 481 } 482 483 // all associated images should be marked as NOT coming from a bad night 484 image = getimages (&Nimage, NULL); 485 for (off_t j = 0; j < tgroup->Nimage; j++) { 486 off_t im = tgroup->image[j]; 487 image[im].flags &= ~ID_IMAGE_NIGHT_POOR; 488 } 373 489 } 374 490 … … 488 604 } 489 605 490 float getMgrp (off_t meas, int cat, float airmass) { 491 492 float value; 493 494 if (!TGROUP_ZEROPT) return (0); 606 // XXX return the error as well as the value 607 float getMgrp (off_t meas, int cat, float airmass, float *dZpt) { 608 609 if (dZpt) { *dZpt = 0; } 610 611 if (!TGROUP_ZEROPT) return 0.0; 495 612 496 613 // unassigned measurements belong to simple chips 497 614 TGroup *myGroup = MeasureToTGroup[cat][meas]; 498 if (!myGroup) return (0.0);499 500 // if (myGroup->flags & IMAGE_BAD) return (NAN);501 value = myGroup->McalPSF + myGroup->dKlam*(airmass - 1.0);502 return (value);615 if (!myGroup) return 0.0; 616 617 float value = myGroup->McalPSF + myGroup->dKlam*(airmass - 1.0); 618 if (dZpt) { *dZpt = myGroup->dMcal; } 619 return value; 503 620 } 504 621 … … 525 642 int Nsys; 526 643 int Nskip; 644 int Nloop; 527 645 off_t Nmax; 528 646 int PoorImages; … … 545 663 int setMgrp_tgroup (TGroup *tgroup, off_t Nmos, Image *image, Catalog *catalog, SetMgrpInfo *info, FlatCorrectionTable *flatcorr); 546 664 void *setMgrp_worker (void *data); 547 int setMgrp_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr);548 549 void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists, int PoorImages ) {665 int setMgrp_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr); 666 667 void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists, int PoorImages, int Nloop) { 550 668 info->Nfew = 0; 551 669 info->Nbad = 0; … … 558 676 559 677 info->Nmax = Nmax; 678 info->Nloop = Nloop; 560 679 info->PoorImages = PoorImages; 561 680 … … 567 686 FitDataSetAlloc (&info->brightStars, Nmax, fitOrder, 0); 568 687 688 // until the analysis has converged a bit, do not use the IRLS analysis 689 if (Nloop < 100) { 690 info->brightStars.MaxIterations = 0; 691 info->kronStars.MaxIterations = 0; 692 info->psfStars.MaxIterations = 0; 693 } 569 694 if (1) { 570 695 FitDataSetAddPriors (&info->psfStars); … … 614 739 } 615 740 616 int setMgrp (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {741 int setMgrp (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) { 617 742 618 743 off_t N; … … 620 745 621 746 if (!TGROUP_ZEROPT) return (FALSE); 747 if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_NONE) return (FALSE); 622 748 623 749 // plots cannot be done in a threaded context (the plot commands collide) 624 750 // so do not run setMgrp in threaded mode if PLOTSTUFF is set 625 751 if (NTHREADS && !PLOTSTUFF) { 626 int status = setMgrp_threaded (catalog, PoorImages, flatcorr);752 int status = setMgrp_threaded (catalog, Nloop, PoorImages, flatcorr); 627 753 return status; 628 754 } 629 755 630 756 image = getimages (&N, NULL); 631 632 if (PoorImages) {633 // XXX use bad stars and measurements for PoorImages? or not?634 // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;635 IMAGE_BAD = 0;636 }637 757 638 758 off_t Nmax = 0; … … 645 765 646 766 SetMgrpInfo info; 647 SetMgrpInfoInit (&info, Nmax, TRUE, PoorImages); 648 649 // int savePlotDelay = PLOTDELAY; 650 // if (PLOTSTUFF) PLOTDELAY = 0.0; 767 SetMgrpInfoInit (&info, Nmax, TRUE, PoorImages, Nloop); 651 768 652 769 for (off_t i = 0; i < NtgroupTimes; i++) { … … 654 771 for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) { 655 772 setMgrp_tgroup (&tgroup[j], i, image, catalog, &info, flatcorr); 656 fprintf (stderr, "TGROUP time %.0f photcode %d Mcal: %f, dK: %f, dMcal: %f, limiting negative clouds to %f\n", ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode, tgroup[j].McalPSF, tgroup[j].dKlam, tgroup[j].dMcal, CLOUD_TOLERANCE);773 fprintf (stderr, "TGROUP time %.0f photcode %d Mcal: %f, dK: %f, dMcal: %f, sigma: %f, chisq: %f, %d of %d, limiting negative clouds to %f\n", ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode, tgroup[j].McalPSF, tgroup[j].dKlam, tgroup[j].dMcal, tgroup[j].stdev, tgroup[j].McalChiSq, tgroup[j].nFitPhotom, tgroup[j].nValPhotom, CLOUD_TOLERANCE); 657 774 } 658 775 } … … 668 785 fprintf (stderr, "%d tgroups marked having too few measurements (Nbad: %d, Ncal: %d, Ngrid: %d, Nrel: %d, Nsys: %d)\n", info.Nfew, info.Nbad, info.Ncal, info.Ngrid, info.Nrel, info.Nsys); 669 786 670 if (PoorImages) {671 IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;672 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;673 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;674 }675 787 return (TRUE); 676 788 } … … 684 796 off_t j, NimageReal; 685 797 686 /* on PoorImages run, skip good images */ 687 if (info->PoorImages) { 688 int bad = myTGroup->flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP); 689 if (!bad) return TRUE; 690 } 798 // At some point, we identify good and bad tgroups. We mark bad tgroups and do not fit 799 // a zero point for them. Instead we will fit those exposures or images separately 800 if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_GOOD_NIGHT) { 801 int bad = myTGroup->flags & ID_IMAGE_NIGHT_POOR; 802 if (bad) return TRUE; 803 } 691 804 692 805 FitDataSet *psfStars = &info->psfStars; … … 704 817 int testImage = FALSE; 705 818 TGTimes *tgroup = (TGTimes *) myTGroup->parent; 706 testImage |= (abs(tgroup->start - 1245283200) < 10); 819 // testImage |= (abs(tgroup->start - 1245283200) < 10); 820 // testImage = TRUE; 707 821 708 822 FILE *fout = NULL; … … 825 939 826 940 /* too few good measurements or too many bad measurements (skip in PoorImages run) */ 827 if (!info->PoorImages) { 828 int mark = (N < NIGHT_TOOFEW) || (N < NIGHT_GOOD_FRACTION*myTGroup->Nmeasure); 829 if (mark) { 830 if (VERBOSE2) { 831 TGTimes *mygroup = (TGTimes *) myTGroup->parent; 832 fprintf (stderr, "marked tgroup %f,%d, (%d < %d) || (%d < %f*"OFF_T_FMT")\n", ohana_sec_to_mjd(mygroup->start), myTGroup->photcode, N, NIGHT_TOOFEW, N, NIGHT_GOOD_FRACTION, myTGroup->Nmeasure); 833 } 834 myTGroup->flags |= ID_IMAGE_PHOTOM_FEW; 835 info->Nfew ++; 836 if (testImage) { 837 fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) NIGHT_TOOFEW, (int) (NIGHT_GOOD_FRACTION*myTGroup->Nmeasure)); 838 } 839 } else { 840 myTGroup->flags &= ~ID_IMAGE_PHOTOM_FEW; 841 } 941 int mark = (N < NIGHT_TOOFEW) || (N < NIGHT_GOOD_FRACTION*myTGroup->Nmeasure); 942 if (mark) { 943 if (VERBOSE2) { 944 TGTimes *mygroup = (TGTimes *) myTGroup->parent; 945 fprintf (stderr, "marked tgroup %f,%d, (%d < %d) || (%d < %f*"OFF_T_FMT")\n", ohana_sec_to_mjd(mygroup->start), myTGroup->photcode, N, NIGHT_TOOFEW, N, NIGHT_GOOD_FRACTION, myTGroup->Nmeasure); 946 } 947 myTGroup->flags |= ID_IMAGE_PHOTOM_FEW; 948 info->Nfew ++; 949 if (testImage) { 950 fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) NIGHT_TOOFEW, (int) (NIGHT_GOOD_FRACTION*myTGroup->Nmeasure)); 951 } 952 } else { 953 myTGroup->flags &= ~ID_IMAGE_PHOTOM_FEW; 842 954 } 843 955 … … 852 964 myTGroup->McalPSF = psfStars->bSaveArray[0][0]; 853 965 myTGroup->dMcal = psfStars->bSigma[0]; 966 myTGroup->stdev = psfStars->sigma; 854 967 myTGroup->McalChiSq = psfStars->chisq; 855 968 myTGroup->nFitPhotom = psfStars->Nmeas; 969 myTGroup->nValPhotom = N; 856 970 myTGroup->dKlam = psfStars->bSaveArray[1][0]; 857 971 … … 864 978 fprintf (stderr, "test night %.0f aper: %f %f %d ... ", ohana_sec_to_mjd(parent->start), myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom); 865 979 } 980 981 // fprintf (stderr, "Mgrp: %6.3f +/- %6.3f %5d of %5d | %.2f %.0f\n", myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom, myTGroup->nValPhotom, myTGroup->McalChiSq, ohana_sec_to_mjd(tgroup->start)); 866 982 867 983 if (PLOTSTUFF) { … … 885 1001 } 886 1002 887 // FitDataSetFree (&brightStars);888 // FitDataSetFree (&kronStars);889 // FitDataSetFree (&psfStars);890 891 1003 return TRUE; 892 1004 } 893 1005 894 int setMgrp_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {1006 int setMgrp_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) { 895 1007 896 1008 int i; … … 901 1013 fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE); 902 1014 903 if (PoorImages) {904 // XXX use bad stars and measurements for PoorImages? or not?905 // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;906 IMAGE_BAD = 0;907 }908 909 1015 off_t Nmax = 0; 910 1016 for (off_t i = 0; i < NtgroupTimes; i++) { … … 916 1022 917 1023 SetMgrpInfo summary; 918 SetMgrpInfoInit (&summary, Nmax, FALSE, PoorImages );1024 SetMgrpInfoInit (&summary, Nmax, FALSE, PoorImages, Nloop); 919 1025 920 1026 pthread_attr_t attr; … … 939 1045 threadinfo[i].image = image; 940 1046 threadinfo[i].flatcorr = flatcorr; 941 SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages); 1047 1048 // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop, 1049 // PoorImages) used in the threads to allocate the arrays and set the MaxIterations 1050 SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages, Nloop); 942 1051 pthread_create (&threads[i], NULL, setMgrp_worker, &threadinfo[i]); 943 1052 } … … 986 1095 npass_output ++; 987 1096 988 if (PoorImages) {989 IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;990 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;991 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;992 }993 1097 return TRUE; 994 1098 } … … 999 1103 1000 1104 SetMgrpInfo results; 1001 SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages ); // allocate list, dlist arrays here1105 SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages, threadinfo->info.Nloop); // allocate list, dlist arrays here 1002 1106 1003 1107 while (1) { … … 1024 1128 } 1025 1129 1026 # if (0) 1130 // XXX should I split these stats out by photcode? 1131 // XXX double check the IMAGE_BAD filter: 1027 1132 StatType statsTGroupM (Catalog *catalog) { 1028 1133 OHANA_UNUSED_PARAM(catalog); 1029 1134 1030 off_t i;1031 int n;1032 1135 double *list, *dlist; 1033 1136 StatType stats; … … 1037 1140 1038 1141 // XXX do this by time & photcode? 1039 ALLOCATE (list, double, Ntgroup); 1040 ALLOCATE (dlist, double, Ntgroup); 1041 1042 n = 0; 1142 ALLOCATE (list, double, NtgroupTimes*Nphotcodes); 1143 ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes); 1144 1145 // is ID_IMAGE_PHOTOM_POOR used for tgroups? 1146 int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR; 1147 1148 int n = 0; 1043 1149 for (int i = 0; i < NtgroupTimes; i++) { 1044 1150 TGroup *tgroup = tgroupTimes[i][0].byCode; 1045 1151 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1046 if (tgroup[j].flags & IMAGE_BAD) continue;1152 if (tgroup[j].flags & NIGHT_BAD) continue; 1047 1153 list[n] = tgroup[j].McalPSF; 1048 1154 dlist[n] = 1; … … 1062 1168 OHANA_UNUSED_PARAM(catalog); 1063 1169 1064 off_t i, n;1065 1170 double *list, *dlist; 1066 1171 StatType stats; … … 1069 1174 if (!TGROUP_ZEROPT) return (stats); 1070 1175 1071 ALLOCATE (list, double, Ntgroup); 1072 ALLOCATE (dlist, double, Ntgroup); 1073 1074 n = 0; 1075 for (i = 0; i < Ntgroup; i++) { 1076 if (tgroup[i].flags & IMAGE_BAD) continue; 1077 list[n] = tgroup[i].dMcal; 1078 dlist[n] = 1; 1079 n++; 1176 ALLOCATE (list, double, NtgroupTimes*Nphotcodes); 1177 ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes); 1178 1179 int n = 0; 1180 for (int i = 0; i < NtgroupTimes; i++) { 1181 TGroup *tgroup = tgroupTimes[i][0].byCode; 1182 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1183 if (tgroup[j].flags & IMAGE_BAD) continue; 1184 list[n] = tgroup[j].dMcal; 1185 dlist[n] = 1; 1186 n++; 1187 } 1080 1188 } 1081 1189 … … 1088 1196 } 1089 1197 1090 StatType statsTGroup N (Catalog *catalog, FlatCorrectionTable *flatcorr) {1091 1092 off_t i, j, m, c, n, N; 1198 StatType statsTGroupX (Catalog *catalog) { 1199 OHANA_UNUSED_PARAM(catalog); 1200 1093 1201 double *list, *dlist; 1094 float Mcal, Mgrid, Mrel, Mmos;1095 1202 StatType stats; 1096 1203 … … 1098 1205 if (!TGROUP_ZEROPT) return (stats); 1099 1206 1100 ALLOCATE (list, double, Ntgroup); 1101 ALLOCATE (dlist, double, Ntgroup); 1102 1103 n = 0; 1104 for (i = 0; i < Ntgroup; i++) { 1105 if (tgroup[i].flags & IMAGE_BAD) continue; 1106 1107 N = 0; 1108 for (j = 0; j < tgroup[i].Nmeasure; j++) { 1109 1110 m = tgroup[i].measure[j]; 1111 c = tgroup[i].catalog[j]; 1112 1113 Mcal = getMcal (m, c, MAG_CLASS_PSF); 1114 if (isnan(Mcal)) continue; 1115 Mmos = getMmos (m, c); 1116 if (isnan(Mmos)) continue; 1117 Mgrid = getMgrid (m, c); 1118 if (isnan(Mgrid)) continue; 1119 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 1120 if (isnan(Mrel)) continue; 1121 N++; 1122 } 1123 list[n] = N; 1124 dlist[n] = 1; 1125 n++; 1126 } 1127 // fprintf (stderr, "Ntgroup: "OFF_T_FMT", n: "OFF_T_FMT"\n", Ntgroup, n); 1207 ALLOCATE (list, double, NtgroupTimes*Nphotcodes); 1208 ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes); 1209 1210 int n = 0; 1211 for (int i = 0; i < NtgroupTimes; i++) { 1212 TGroup *tgroup = tgroupTimes[i][0].byCode; 1213 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1214 if (tgroup[j].flags & IMAGE_BAD) continue; 1215 list[n] = tgroup[j].McalChiSq; 1216 dlist[n] = 1; 1217 n++; 1218 } 1219 } 1128 1220 1129 1221 liststats_setmode (&stats, "MEAN"); … … 1135 1227 } 1136 1228 1137 StatType statsTGroupX (Catalog *catalog) {1138 OHANA_UNUSED_PARAM(catalog);1139 1140 off_t i, n;1141 double *list, *dlist;1142 StatType stats;1143 1144 bzero (&stats, sizeof (StatType));1145 if (!TGROUP_ZEROPT) return (stats);1146 1147 ALLOCATE (list, double, Ntgroup);1148 ALLOCATE (dlist, double, Ntgroup);1149 1150 n = 0;1151 for (i = 0; i < Ntgroup; i++) {1152 if (tgroup[i].flags & IMAGE_BAD) continue;1153 if (KEEP_UBERCAL && (tgroup[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;1154 1155 list[n] = tgroup[i].McalChiSq;1156 dlist[n] = 1;1157 n++;1158 }1159 1160 liststats_setmode (&stats, "MEAN");1161 1162 liststats (list, dlist, NULL, n, &stats);1163 free (list);1164 free (dlist);1165 return (stats);1166 }1167 # endif1168 1169 1229 /* mark tgroup if: abs(Mcal - <Mcal>) too large, dMcal too large */ 1170 1230 void clean_tgroups () { 1171 1231 1172 off_t i, N, mark, Nmark, Nscatter, Noffset;1232 off_t mark, Ntotal, Nmark, Nscatter, Noffset, Nrejects, Nchisq; 1173 1233 double *mlist, *slist, *dlist; 1174 1234 double MaxOffset, MedOffset, MaxScatter; … … 1182 1242 ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes); 1183 1243 1184 for (i = N = 0; i < NtgroupTimes; i++) { 1244 int N = 0; 1245 for (int i = 0; i < NtgroupTimes; i++) { 1185 1246 TGroup *tgroup = tgroupTimes[i][0].byCode; 1186 1247 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { … … 1197 1258 1198 1259 liststats (mlist, dlist, NULL, N, &stats); 1199 MaxOffset = MAX (NIGHT_OFFSET, 2*stats.sigma);1260 MaxOffset = MAX (NIGHT_OFFSET, 3*stats.sigma); 1200 1261 MedOffset = stats.median; 1201 1262 1202 1263 liststats (slist, dlist, NULL, N, &stats); 1203 1264 MaxScatter = MAX (NIGHT_SCATTER, 2*stats.median); 1204 fprintf (stderr, " Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset);1265 fprintf (stderr, "TGROUPS: median Mrel: %f, median dMrel: %f, Max Offset: %f, Max Scatter: %f\n", MedOffset, stats.median, MaxOffset, MaxScatter); 1205 1266 1206 Nmark = Nscatter = Noffset = 0; 1207 for (i = 0; i < NtgroupTimes; i++) { 1267 // XXX this needs to be configurable 1268 float MaxChiSq = 10.0; 1269 1270 Ntotal = Nmark = Nscatter = Noffset = Nrejects = Nchisq = 0; 1271 for (int i = 0; i < NtgroupTimes; i++) { 1208 1272 TGroup *tgroup = tgroupTimes[i][0].byCode; 1209 1273 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1210 // if we are keeping ubercal sacrosanct, then we should not be allowed to break them...1211 if (KEEP_UBERCAL && (tgroup[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;1212 1274 1213 if (tgroup[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP)) continue; 1275 Ntotal ++; 1276 1277 // ignore the nights with too few measurements 1278 // XXX what to do with nights with too few measurements? 1279 // XXX probably free the images to be fitted 1280 if (tgroup[j].flags & ID_IMAGE_PHOTOM_FEW) { 1281 markBadTGroup(&tgroup[j]); // mark the image associated with a bad night 1282 continue; 1283 } 1214 1284 1215 1285 mark = FALSE; 1216 if (tgroup[ i].dMcal > MaxScatter) {1286 if (tgroup[j].dMcal > MaxScatter) { 1217 1287 mark = TRUE; 1218 1288 Nscatter ++; 1219 1289 } 1220 if (fabs(tgroup[ i].McalPSF - MedOffset) > MaxOffset) {1290 if (fabs(tgroup[j].McalPSF - MedOffset) > MaxOffset) { 1221 1291 mark = TRUE; 1222 1292 Noffset ++; 1223 1293 } 1294 if (tgroup[j].nFitPhotom < 0.7*tgroup[j].nValPhotom) { 1295 mark = TRUE; 1296 Nrejects ++; 1297 } 1298 if (tgroup[j].McalChiSq > MaxChiSq) { 1299 mark = TRUE; 1300 Nchisq ++; 1301 } 1224 1302 if (mark) { 1225 1303 Nmark ++; 1226 tgroup[i].flags |= ID_IMAGE_PHOTOM_POOR;1304 markBadTGroup(&tgroup[j]); // mark the tgroup & associated images & mosaics with a bad night 1227 1305 } else { 1228 tgroup[i].flags &= ~ID_IMAGE_PHOTOM_POOR;1306 markGoodTGroup(&tgroup[j]); // mark the tgroup & associated images & mosaics with a good night 1229 1307 } 1230 // XXX : unset the ubercal flag if we mark the night as bad? 1231 } 1232 } 1233 1234 fprintf (stderr, OFF_T_FMT" tgroups marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n", Nmark, Nscatter, Noffset); 1308 } 1309 } 1310 1311 fprintf (stderr, OFF_T_FMT" of "OFF_T_FMT" tgroups marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset, "OFF_T_FMT" rejects, "OFF_T_FMT" chisq)\n", Nmark, Ntotal, Nscatter, Noffset, Nrejects, Nchisq); 1235 1312 1236 1313 free (mlist); … … 1347 1424 } 1348 1425 1426 void dump_tgroups (Catalog *catalog, int Npass) { 1427 1428 int Nsecfilt = GetPhotcodeNsecfilt (); 1429 1430 int Ngrp = 0; 1431 for (off_t i = 0; i < NtgroupTimes; i++) { 1432 1433 TGroup *tgroup = tgroupTimes[i][0].byCode; 1434 for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) { 1435 1436 FILE *fout = NULL; 1437 char filename[64]; 1438 snprintf (filename, 64, "tgrp.%05d.%02d.dat", Ngrp, Npass); 1439 fout = fopen (filename, "w"); 1440 Ngrp ++; 1441 1442 TGroup *myTGroup = &tgroup[j]; 1443 1444 for (int k = 0; k < myTGroup->Nmeasure; k++) { 1445 1446 off_t m = myTGroup->measure[k]; 1447 off_t c = myTGroup->catalog[k]; 1448 1449 float Mcal = getMcal (m, c, MAG_CLASS_PSF); // image zero point 1450 float Mmos = getMmos (m, c); // mosaic zero point 1451 float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1452 1453 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude 1454 // float Mgrid = getMgrid (m, c); // camera offset (deprecated?) 1455 // float Mflat = getMflat (m, c, flatcorr, catalog); // flat-field correction 1456 1457 off_t n = catalog[c].measureT[m].averef; 1458 1459 // nominal magnitude for this measurement (instrumental + Ko(airmass - 1) + Co 1460 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 1461 1462 // for historical reasons, Mflat is defined with the wrong sign 1463 float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrp; 1464 1465 fprintf (fout, "%f %f : %f %f : %f %f %f : %f %f\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mmos, Mgrp, catalog[c].measureT[m].airmass, delta); 1466 } 1467 fclose (fout); 1468 } 1469 } 1470 } -
trunk/Ohana/src/relphot/src/args.c
r41453 r41462 303 303 } 304 304 305 // global restriction on fitting image zero points for mosaic cameras 306 FREEZE_IMAGES = FALSE; 307 if ((N = get_argument (argc, argv, "-imfreeze"))) { 308 remove_argument (N, &argc, argv); 309 FREEZE_IMAGES = TRUE; 310 } 311 // global restriction on fitting mosaic zero points 312 FREEZE_MOSAICS = FALSE; 313 if ((N = get_argument (argc, argv, "-mosfreeze"))) { 314 remove_argument (N, &argc, argv); 315 FREEZE_MOSAICS = TRUE; 316 } 317 CALIBRATE_STACKS_AND_WARPS = FALSE; 318 if ((N = get_argument (argc, argv, "-only-stacks-and-warps"))) { 319 remove_argument (N, &argc, argv); 320 CALIBRATE_STACKS_AND_WARPS = TRUE; 321 } 322 USE_MCAL_PSF_FOR_STACK_APER = FALSE; 323 if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) { 324 remove_argument (N, &argc, argv); 325 USE_MCAL_PSF_FOR_STACK_APER = TRUE; 326 } 327 328 329 // default behavior is to fit all chips independently 330 TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE; 331 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE; 332 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_ALL; 333 305 334 /* XXX this argument used to do two things: specify the camera name and tell the analysis to 306 335 calculate a common zero point for a single mosaic. I've moved the MOSAICNAME concept into the … … 315 344 exit (2); 316 345 } 317 } 318 319 FREEZE_IMAGES = FALSE; 320 if ((N = get_argument (argc, argv, "-imfreeze"))) { 321 remove_argument (N, &argc, argv); 322 FREEZE_IMAGES = TRUE; 323 } 324 FREEZE_MOSAICS = FALSE; 325 if ((N = get_argument (argc, argv, "-mosfreeze"))) { 326 remove_argument (N, &argc, argv); 327 FREEZE_MOSAICS = TRUE; 328 } 329 CALIBRATE_STACKS_AND_WARPS = FALSE; 330 if ((N = get_argument (argc, argv, "-only-stacks-and-warps"))) { 331 remove_argument (N, &argc, argv); 332 CALIBRATE_STACKS_AND_WARPS = TRUE; 333 } 334 USE_MCAL_PSF_FOR_STACK_APER = FALSE; 335 if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) { 336 remove_argument (N, &argc, argv); 337 USE_MCAL_PSF_FOR_STACK_APER = TRUE; 346 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_NONE; 347 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_ALL; 338 348 } 339 349 … … 341 351 TGROUP_ZEROPT = FALSE; 342 352 char *TGROUP_FILENAME = NULL; 343 if ((N = get_argument (argc, argv, "-tgroup")) ) {353 if ((N = get_argument (argc, argv, "-tgroup")) || (N = get_argument (argc, argv, "-tgroups"))) { 344 354 TGROUP_ZEROPT = TRUE; 345 355 remove_argument (N, &argc, argv); 346 356 TGROUP_FILENAME = strcreate(argv[N]); 347 357 remove_argument (N, &argc, argv); 348 FREEZE_IMAGES = TRUE; 349 } 350 if ((N = get_argument (argc, argv, "-tgroups"))) { 351 if (TGROUP_ZEROPT) { 352 fprintf (stderr, "use only one of -tgroups and -tgroup (same meaning)\n"); 353 exit (2); 354 } 355 TGROUP_ZEROPT = TRUE; 356 remove_argument (N, &argc, argv); 357 TGROUP_FILENAME = strcreate(argv[N]); 358 remove_argument (N, &argc, argv); 359 FREEZE_IMAGES = TRUE; 358 // if we fit for TGROUPS, start with the images and mosaics frozen 359 TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_ALL; 360 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_NONE; 361 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE; 362 } 363 if ((N = get_argument (argc, argv, "-tgroup")) || (N = get_argument (argc, argv, "-tgroups"))) { 364 fprintf (stderr, "use only one of -tgroups and -tgroup (same meaning)\n"); 365 exit (2); 360 366 } 361 367 TGROUP_FIT_AIRMASS = FALSE; -
trunk/Ohana/src/relphot/src/extra.c
r41428 r41462 130 130 } 131 131 132 double weight_cauchy (double x) { 133 double r = x / 2.385; 134 return (1.0 / (1.0 + SQ(r))); 135 } 136 137 double VectorFractionInterpolate (double *values, float fraction, int Npts) { 138 139 float F = fraction * Npts; 140 int N = fraction * Npts; 141 142 if (N < 0 ) return NAN; 143 if (N >= Npts - 2) return NAN; 144 145 // interpolate between N,N+1 146 147 double S = (F - N) * (values[N+1] - values[N]) + values[N]; 148 return S; 149 } -
trunk/Ohana/src/relphot/src/fit1d_irls.c
r41453 r41462 2 2 3 3 // These should probably be tunable: 4 # define MAX_ITERATIONS 105 4 # define FIT_TOLERANCE 1e-4 6 5 # define FLT_TOLERANCE 1e-6 … … 35 34 36 35 int converged = FALSE; 37 for (int iterations = 0; !converged && (iterations < MAX_ITERATIONS); iterations++) {36 for (int iterations = 0; !converged && (iterations < dataset->MaxIterations); iterations++) { 38 37 39 38 for (int i = 0; i < Npoints; i++) { … … 293 292 dataset->mterm = 2*order + 1; 294 293 dataset->Nbootstrap = Nbootstrap; 294 dataset->MaxIterations = 10; 295 295 296 296 // arrays for actual data values -
trunk/Ohana/src/relphot/src/global_stats.c
r39357 r41462 3 3 void global_stats (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr, int nloop) { 4 4 5 StatType stN, stX, stS, imN, imX, imM, imD, msM, msX, msN, msD ;5 StatType stN, stX, stS, imN, imX, imM, imD, msM, msX, msN, msD, tgM, tgX, tgD; 6 6 7 7 liststats_init (&stN); 8 8 liststats_init (&stX); 9 9 liststats_init (&stS); 10 10 11 liststats_init (&imN); 11 12 liststats_init (&imX); 12 13 liststats_init (&imM); 13 14 liststats_init (&imD); 15 14 16 liststats_init (&msN); 15 17 liststats_init (&msX); … … 17 19 liststats_init (&msD); 18 20 19 // INITTIME; 21 liststats_init (&tgX); 22 liststats_init (&tgM); 23 liststats_init (&tgD); 20 24 21 25 fprintf (stderr, "\n"); … … 29 33 int seccode = photcodes[Ns][0].code; 30 34 31 // MARKTIME("start star stats: %f sec\n", dtime);32 35 stN = statsStarN (catalog, Ncatalog, Nsec, seccode, flatcorr); 33 // MARKTIME("done star N: %f sec\n", dtime);34 36 stX = statsStarX (catalog, Ncatalog, Nsec); 35 // MARKTIME("done star X: %f sec\n", dtime);36 37 stS = statsStarS (catalog, Ncatalog, Nsec); 37 // MARKTIME("done star S: %f sec\n", dtime);38 38 39 39 fprintf (stderr, " --- stats for %s ---\n", photcodes[Ns][0].name); … … 53 53 msX = statsMosaicX (catalog); 54 54 55 tgM = statsMosaicM (catalog); 56 tgD = statsMosaicdM (catalog); 57 tgX = statsMosaicX (catalog); 58 55 59 fprintf (stderr, "meas / image: %7.0f %7.0f %7.0f %7.0f %7.0f %6d\n", imN.median, imN.mean, imN.sigma, imN.min, imN.max, imN.Nmeas); 56 60 fprintf (stderr, "Mcal image: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", imM.median, imM.mean, imM.sigma, imM.min, imM.max, imM.Nmeas); … … 62 66 fprintf (stderr, "dMcal mosaic: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", msD.median, msD.mean, msD.sigma, msD.min, msD.max, msD.Nmeas); 63 67 fprintf (stderr, "chisq mosaic: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", msX.median, msX.mean, msX.sigma, msX.min, msX.max, msX.Nmeas); 68 69 fprintf (stderr, "Mcal tgroup: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", tgM.median, tgM.mean, tgM.sigma, tgM.min, tgM.max, tgM.Nmeas); 70 fprintf (stderr, "dMcal tgroup: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", tgD.median, tgD.mean, tgD.sigma, tgD.min, tgD.max, tgD.Nmeas); 71 fprintf (stderr, "chisq tgroup: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", tgX.median, tgX.mean, tgX.sigma, tgX.min, tgX.max, tgX.Nmeas); 64 72 } 65 73 -
trunk/Ohana/src/relphot/src/liststats.c
r41453 r41462 417 417 } 418 418 419 double weight_cauchy (double x) {420 double r = x / 2.385;421 return (1.0 / (1.0 + SQ(r)));422 }423 424 double VectorFractionInterpolate (double *values, float fraction, int Npts) {425 426 float F = fraction * Npts;427 int N = fraction * Npts;428 429 if (N < 0 ) return NAN;430 if (N >= Npts - 2) return NAN;431 432 // interpolate between N,N+1433 434 double S = (F - N) * (values[N+1] - values[N]) + values[N];435 return S;436 }437 438 419 // we could define the weight to be the only scale factor: 439 420 // \mu = \sum (value_i * weight_i) / \sum (weight_i) -
trunk/Ohana/src/relphot/src/relphot_images.c
r41390 r41462 116 116 /* determine fit values */ 117 117 for (i = 0; i < NLOOP; i++) { 118 if (PLOTSTUFF) { 119 plot_scatter (catalog, Ncatalog, flatcorr); 120 } 121 if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog); 122 // checkImages("start loop"); 118 dump_tgroups (catalog, i); 119 dump_catalog (catalog, 0, i); // for a test, just dump a specific catalog 123 120 124 121 setMrel (catalog, Ncatalog, flatcorr); // threaded 125 if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog); 126 // checkImages("set Mrel"); 127 128 if (PLOTSTUFF) { 129 plot_scatter (catalog, Ncatalog, flatcorr); 130 } 131 setMcal (catalog, FALSE, flatcorr); 132 // checkImages("set Mcal"); 133 if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog); 134 135 setMmos (catalog, FALSE, flatcorr); 136 setMgrp (catalog, FALSE, flatcorr); 122 dump_tgroups (catalog, i + 20); 123 dump_catalog (catalog, 0, i + 20); // for a test, just dump a specific catalog 124 125 setMcal (catalog, i, FALSE, flatcorr); 126 setMmos (catalog, i, FALSE, flatcorr); 127 setMgrp (catalog, i, FALSE, flatcorr); 128 dump_tgroups (catalog, i + 40); 129 dump_catalog (catalog, 0, i + 40); // for a test, just dump a specific catalog 137 130 138 131 setMgrid (catalog, flatcorr); … … 147 140 plot_chisq (catalog, Ncatalog); 148 141 } 149 // if (i < NLOOP - 1) rationalize_mosaics (catalog, Ncatalog);150 // if (i % 6 == 1) rationalize_images ();151 152 // NOTE : in the past, I was not iterating enough before cleaning. make sure we do153 // at least 8 loops first -- that should get the systematic errors down to the ~1%154 // level, even in cases where we have an even split between photometric data and155 // data with 1 mag of extinction.156 157 if ((i > 8) && (i % 8 == 2)) clean_measures (catalog, Ncatalog, FALSE, flatcorr);158 if ((i > 8) && (i % 8 == 3)) clean_stars (catalog, Ncatalog);159 if ((i > 8) && (i % 8 == 5)) clean_mosaics ();160 if ((i > 8) && (i % 8 == 5)) clean_tgroups ();161 if ((i > 8) && (i % 8 == 5)) clean_images ();162 142 163 143 global_stats (catalog, Ncatalog, flatcorr, i); 144 145 SetZeroPointModes (i); 164 146 MARKTIME("-- finished loop %d: %f sec\n", i, dtime); 147 fprintf (stderr, "----- continue loop %d -----\n", i); 165 148 } 166 149 … … 178 161 /* set Mcal & Mmos for bad images */ 179 162 int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS; 180 setMcal (catalog, onlyPoorImages, flatcorr); 181 setMmos (catalog, onlyPoorImages, flatcorr); 182 setMgrp (catalog, onlyPoorImages, flatcorr); 163 onlyPoorImages = FALSE; // XXX deactivate for now 164 setMcal (catalog, 999, onlyPoorImages, flatcorr); // max loop since this is a final pass 165 setMmos (catalog, 999, onlyPoorImages, flatcorr); // max loop since this is a final pass 166 setMgrp (catalog, 999, onlyPoorImages, flatcorr); // max loop since this is a final pass 183 167 MARKTIME("-- finalize Mcal values: %f sec\n", dtime); 184 168 -
trunk/Ohana/src/relphot/src/relphot_parallel_images.c
r41390 r41462 114 114 115 115 // set the image (Mcal) and mosaic (Mmos) zero point offsets given the mean mags and measurements 116 setMcal (catalog, FALSE, flatcorr);117 setMmos (catalog, FALSE, flatcorr);116 setMcal (catalog, i, FALSE, flatcorr); 117 setMmos (catalog, i, FALSE, flatcorr); 118 118 // setMgrp (catalog, FALSE, flatcorr); XXX think this through: this may not make sense for tgroups 119 119 MARKTIME("-- set Mrel, Mcal, Mmos, Mgrid : %f sec\n", dtime); … … 151 151 /* set Mcal & Mmos for bad images (for stack_and_warps, force images to be measured) */ 152 152 int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS; 153 setMcal (catalog, onlyPoorImages, flatcorr);154 setMmos (catalog, onlyPoorImages, flatcorr);153 setMcal (catalog, 999, onlyPoorImages, flatcorr); 154 setMmos (catalog, 999, onlyPoorImages, flatcorr); 155 155 // setMgrp (catalog, onlyPoorImages, flatcorr); XXX see above 156 156 MARKTIME("-- finalize Mcal values: %f sec\n", dtime); -
trunk/Ohana/src/relphot/src/setMrelCatalog.c
r41453 r41462 9 9 # endif 10 10 11 int magStatsByRanking (StatDataSet *dataset, StatType *stats); 11 12 int magStatsByRankingClipped (StatDataSet *dataset, StatType *stats); 12 13 int magStatsByRankingIRLS (StatDataSet *dataset, StatType *stats); … … 17 18 int liststats_irls (StatDataSet *dataset, int Npoints, StatType *stats); 18 19 19 # define MAG_STATS_BY_RANKING magStatsByRankingIRLS 20 // # define MAG_STATS_BY_RANKING magStatsByRankingIRLS 21 # define MAG_STATS_BY_RANKING magStatsByRanking 20 22 21 23 # define UBERCAL_WEIGHT 100.0 … … 56 58 } 57 59 60 FILE *TESTFILE = NULL; 61 58 62 int setMrel_catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) { 59 63 … … 67 71 SetMrelInfoReset (results); // reset the counters 68 72 73 TESTFILE = fopen ("mytest.dat", "w"); 74 69 75 for (j = 0; j < catalog[Nc].Naverage; j++) { 70 76 … … 83 89 } 84 90 } 91 92 fclose (TESTFILE); 85 93 return (TRUE); 86 94 } … … 222 230 // ** Choose the calibration (depends on the mode : do I have an image reference or not?) 223 231 float Mcal = 0.0, Mmos = 0.0, Mgrid = 0.0, Mflat = 0.0, Mgrp = 0.0; 232 float dMgrp = 0.0; 224 233 off_t meas = measureOffset + k; 225 234 if (getImageEntry (meas, cat) < 0) { … … 235 244 Mmos = getMmos (meas, cat); 236 245 if (isnan(Mmos)) SKIP_THIS_MEAS(Nmos); 237 Mgrp = getMgrp (meas, cat, measureT[k].airmass );246 Mgrp = getMgrp (meas, cat, measureT[k].airmass, &dMgrp); 238 247 if (isnan(Mgrp)) SKIP_THIS_MEAS(Ngrp); 239 248 Mgrid = getMgrid (meas, cat); … … 251 260 int useUbercalWeight = isUbercal || (refPhotcode && (code->code == refPhotcode->code)); 252 261 262 // combine the various errors in quadrature here: 263 float dMsys = hypot (code->photomErrSys, dMgrp); 264 253 265 float Map = NAN; 254 266 float dMap = NAN; … … 258 270 // NOTE: for PV3, apFluxErr is broken (see pmSourcePhotometry.c:245). we are going to 259 271 // use PSF flux error instead here: 260 // dMap = MAX (hypot(measure[k].dMap, code->photomErrSys), MIN_ERROR);261 dMap = MAX (hypot(measure[k].dM, code->photomErrSys), MIN_ERROR);272 // dMap = MAX (hypot(measure[k].dMap, dMsys), MIN_ERROR); 273 dMap = MAX (hypot(measure[k].dM, dMsys), MIN_ERROR); 262 274 263 275 if (CHECK_VALID_MAG(Map, dMap)) { … … 277 289 float dMkron; 278 290 if (isSetMrelFinal) { 279 dMkron = MAX (hypot(measure[k].dMkron, code->photomErrSys), MIN_ERROR);291 dMkron = MAX (hypot(measure[k].dMkron, dMsys), MIN_ERROR); 280 292 } else { 281 dMkron = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);293 dMkron = MAX (hypot(measureT[k].dM, dMsys), MIN_ERROR); 282 294 } 283 295 if (CHECK_VALID_MAG(Mkron, dMkron)) { … … 293 305 294 306 float Mpsf = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF); 295 float dMpsf = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);307 float dMpsf = MAX (hypot(measureT[k].dM, dMsys), MIN_ERROR); 296 308 if (CHECK_VALID_MAG(Mpsf, dMpsf)) { 297 309 int Npsf = results->psfData[Nsec].Nlist; … … 401 413 secfilt[Nsec].dMpsfChp = psfstats->error; 402 414 secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN; 415 fprintf (TESTFILE, "%d %d : %d : %f %f : %f\n", cat, (int) ave, NrankingPSF, psfstats->mean, psfstats->median, psfstats->mean - psfstats->median); 403 416 } 404 417 -
trunk/Ohana/src/relphot/src/test_fitirls.c
r41453 r41462 5 5 int main (int argc, char **argv) { 6 6 7 int Ntests = 100; 8 int Npoints = 100; 9 int Noutliers = 10; 10 int Nbootstrap = 100; 7 int Ntests = 100; 8 int Npoints = 100; 9 int Noutliers = 10; 10 int Nbootstrap = 100; 11 int Niterations = 10; 11 12 12 13 int N; … … 29 30 remove_argument (N, &argc, argv); 30 31 Nbootstrap = atoi (argv[N]); 32 remove_argument (N, &argc, argv); 33 } 34 if ((N = get_argument (argc, argv, "-Niterations"))) { 35 remove_argument (N, &argc, argv); 36 Niterations = atoi (argv[N]); 31 37 remove_argument (N, &argc, argv); 32 38 } … … 88 94 FitDataSet dataset; 89 95 FitDataSetAlloc (&dataset, Npoints + Noutliers, FitSlope, Nbootstrap); 96 dataset.MaxIterations = Niterations; 90 97 91 98 if (isfinite(ValuePrior) || isfinite(SlopePrior)) { -
trunk/Ohana/src/relphot/test/relphot.tgroups.dvo
r41453 r41462 451 451 set stars_dmag = 0.02 + 0.1 * rnd(tmp) 452 452 end 453 454 macro plot.test.files 455 if ($0 != 2) 456 echo "USAGE: plot.test.files (N)" 457 break 458 end 459 460 clear -s 461 resize 2000 1200 462 463 section a0 0.00 0.50 0.25 0.50 464 section a1 0.25 0.50 0.25 0.50 465 section a2 0.50 0.50 0.25 0.50 466 section a3 0.75 0.50 0.25 0.50 467 468 section a4 0.00 0.00 0.25 0.50 469 section a5 0.25 0.00 0.25 0.50 470 section a6 0.50 0.00 0.25 0.50 471 section a7 0.75 0.00 0.25 0.50 472 473 label -fn helvetica 12 474 $BSTYLE = -tickpad 0.2 +xpad 0.2 +ypad 0.2 -ypad 5 475 476 for i 0 8 477 sprintf name tgrp.%05d.%02d.dat $i $1 478 data $name 479 exec ls -l --full-time $name 480 read Msys 4 Mrel 5 Mcal 7 Mmos 8 Mgrp 9 airmass 11 dMag 12 481 482 section a$i 483 lim Msys dMag; box $BSTYLE; plot Msys dMag -pt cir -op 0.2 -c blue 484 end 485 end
Note:
See TracChangeset
for help on using the changeset viewer.
