- Timestamp:
- Apr 27, 2021, 8:39:17 AM (5 years ago)
- Location:
- trunk/Ohana/src/relphot
- Files:
-
- 2 added
- 9 edited
-
Makefile (modified) (2 diffs)
-
include/relphot.h (modified) (3 diffs)
-
src/ImageOps.c (modified) (11 diffs)
-
src/MagResidSave.c (added)
-
src/MosaicOps.c (modified) (26 diffs)
-
src/StarOps.c (modified) (1 diff)
-
src/TGroupOps.c (modified) (31 diffs)
-
src/relphot_images.c (modified) (6 diffs)
-
src/relphot_parallel_images.c (modified) (2 diffs)
-
src/relphot_parallel_regions.c (modified) (2 diffs)
-
src/save_images.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/relphot/Makefile
r41462 r41556 54 54 $(SRC)/load_catalogs.$(ARCH).o \ 55 55 $(SRC)/load_images.$(ARCH).o \ 56 $(SRC)/save_images.$(ARCH).o \ 57 $(SRC)/MagResidSave.$(ARCH).o \ 56 58 $(SRC)/synthetic_mags.$(ARCH).o \ 57 59 $(SRC)/plot_scatter.$(ARCH).o \ … … 117 119 $(SRC)/select_images.$(ARCH).o \ 118 120 $(SRC)/load_images.$(ARCH).o \ 121 $(SRC)/save_images.$(ARCH).o \ 122 $(SRC)/MagResidSave.$(ARCH).o \ 119 123 $(SRC)/load_catalogs.$(ARCH).o \ 120 124 $(SRC)/reload_catalogs.$(ARCH).o \ -
trunk/Ohana/src/relphot/include/relphot.h
r41555 r41556 643 643 int setMcalOutput PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr)); 644 644 645 void setMcal PROTO((Catalog *catalog, int Poor,FlatCorrectionTable *flatcorr));646 int setMmos PROTO((Catalog *catalog, int Poor,FlatCorrectionTable *flatcorr));647 int setMgrp PROTO((Catalog *catalog, int Poor,FlatCorrectionTable *flatcorr));645 void setMcal PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr)); 646 int setMmos PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr)); 647 int setMgrp PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr)); 648 648 649 649 int setMrel PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr)); … … 841 841 void RepairWarpMeasuresCloseLogfile (); 842 842 843 int save_images_backup (FITS_DB *db);844 845 843 void dump_tgroups (Catalog *catalog, int Npass); 846 844 void dump_catalog (Catalog *catalog, off_t c, int Npass); … … 853 851 int UseStandardOLS (ZptFitModeType mode); 854 852 int GetActivePhotcodeIndex (int photcode); 853 854 int save_images_backup (FITS_DB *db); 855 int save_images_updates (FITS_DB *db); 856 857 int MagResidSave(char *filename, Catalog *catalog); -
trunk/Ohana/src/relphot/src/ImageOps.c
r41555 r41556 75 75 Image *getimage (off_t N) { 76 76 return (&image[N]); 77 } 78 79 off_t *get_N_onImage() { 80 return N_onImage; 81 } 82 83 IDX_T **get_ImageToCatalog() { 84 return ImageToCatalog; 85 } 86 87 IDX_T **get_ImageToMeasure() { 88 return ImageToMeasure; 77 89 } 78 90 … … 570 582 571 583 /* determine Mcal values for all images */ 572 void setMcal (Catalog *catalog, int PoorImages,FlatCorrectionTable *flatcorr) {584 void setMcal (Catalog *catalog, FlatCorrectionTable *flatcorr) { 573 585 574 586 off_t i, j, m, c, n; 575 int mark, bad,Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys;587 int mark, Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys; 576 588 577 589 if (IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_NONE) return; … … 580 592 581 593 int Nsecfilt = GetPhotcodeNsecfilt (); 582 583 if (PoorImages) {584 // XXX use bad stars and measurements for PoorImages? or not?585 // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;586 IMAGE_BAD = 0;587 }588 594 589 595 off_t Nmax = 0; … … 618 624 } 619 625 620 /* on PoorImages run, skip good images */621 if (PoorImages) {622 bad = image[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP);623 if (!bad) continue;624 }625 626 626 if (image[i].photcode == 0) continue; // skip the PHU images 627 627 … … 629 629 int badMosaic = (image[i].flags & ID_IMAGE_MOSAIC_POOR); 630 630 int isMosaic = isMosaicChip(image[i].photcode); 631 int useMcal = TRUE; 631 632 632 633 // unset at start by default (set if actually used below) … … 638 639 // in BAD_NIGHT mode, we fit ONLY images in bad nights 639 640 if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT)) { 640 if (!badNight) continue;641 if (!badNight) useMcal = FALSE; // do not fit images from good nights 641 642 } 642 643 643 644 // in BAD_NIGHT_BAD_MOSAIC mode, we fit ONLY bad mosaics in bad nights 644 645 if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC)) { 645 if (!badNight) continue;646 if (!badMosaic && isMosaic) continue; // skip good mosaics (but not good images)646 if (!badNight) useMcal = FALSE; // do not fit images from good nights 647 if (!badMosaic && isMosaic) useMcal = FALSE; // skip good mosaics (but not good images) 647 648 } 648 649 649 650 // in BAD_MOSAIC mode, we fit bad mosaics ignoring night state 650 651 if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_MOSAIC)) { 651 if (!badMosaic && isMosaic) continue; // skip good mosaics (but not bad images)652 if (!badMosaic && isMosaic) useMcal = FALSE; // skip good mosaics (but not bad images) 652 653 } 653 654 … … 759 760 760 761 /* too few good measurements or too many bad measurements */ 761 mark = FALSE;762 if ( !PoorImages) {763 mark = (Nref < IMAGE_TOOFEW) || (Nref < IMAGE_GOOD_FRACTION*N_onImage[i]);764 i f (mark) {765 image[i].flags |= ID_IMAGE_PHOTOM_FEW;766 Nfew ++;767 } else {768 image[i].flags &= ~ID_IMAGE_PHOTOM_FEW; 769 }770 } 762 mark = (Nref < IMAGE_TOOFEW) || (Nref < IMAGE_GOOD_FRACTION*N_onImage[i]); 763 if (mark) { 764 image[i].flags |= ID_IMAGE_PHOTOM_FEW; 765 image[i].dMcal = NAN; 766 image[i].McalChiSq = NAN; 767 image[i].nFitPhotom = 0; 768 Nfew ++; 769 } else { 770 image[i].flags &= ~ID_IMAGE_PHOTOM_FEW; 771 } 771 772 if (mark) continue; 772 773 774 // use liststats to find the 20-pct, median, 80-pct points 775 StatType stats; 776 liststats_setmode (&stats, "MEDIAN"); 777 liststats (psfStars.alldata->yVector, NULL, NULL, Nref, &stats); 778 double altSigma = (stats.Upper80 - stats.Lower20) / 1.6; // 20% to 80% encompasses 60% of the values, corresponds to the range (-0.85 sigma : +0.85 sigma) 779 780 // soften the individual errors with 10% of the scatter above 781 for (j = 0; j < Nref; j++) { 782 double newSigma = hypot(psfStars.alldata->dyVector[j], 0.1*altSigma); 783 psfStars.alldata->dyVector[j] = newSigma; 784 } 785 773 786 // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not) 787 // XXX: apply airmass from above and fit only zp? 788 789 // XXX soften the stats? 790 774 791 fit1d_irls (&psfStars, Nref); 775 image[i].McalPSF = psfStars.bSaveArray[0][0]; 792 fit1d_irls (&kronStars, Nkron); 793 fit1d_irls (&brightStars, Nbright); 794 795 // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not) 796 if (useMcal) { 797 image[i].McalPSF = psfStars.bSaveArray[0][0]; 798 image[i].McalAPER = kronStars.bSaveArray[0][0]; 799 image[i].flags |= ID_IMAGE_IMAGE_PHOTCAL; // set this flag (unset by default) 800 } else { 801 image[i].McalPSF = 0.0; 802 image[i].McalAPER = 0.0; 803 } 804 805 // record statistics on the fit regardless if it is used or not 776 806 image[i].dMcal = psfStars.bSigma[0]; 777 807 image[i].nFitPhotom = psfStars.Nmeas; … … 779 809 Ncalibrated ++; 780 810 781 // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not) 782 // XXX: apply airmass from above and fit only zp? 783 // XXX EAM : temporarily use this to track calibration quality 784 if (0) { 785 fit1d_irls (&kronStars, Nkron); 786 image[i].McalAPER = kronStars.bSaveArray[0][0]; 787 } 811 // bright end scatter 812 image[i].dMagSys = brightStars.sigma; 788 813 789 814 if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) { … … 796 821 } 797 822 798 // bright end scatter799 fit1d_irls (&brightStars, Nbright);800 image[i].dMagSys = brightStars.sigma;801 802 if (image[i].McalPSF < -CLOUD_TOLERANCE) {803 image[i].McalPSF = 0.0;804 }805 806 image[i].flags |= ID_IMAGE_IMAGE_PHOTCAL; // set this flag807 808 823 // minUbercalDist calculated here is the min value for any star owned by this image 809 824 // since this particular image is tied to that star, bump its distance by 1 … … 813 828 fprintf (stderr, "%d images calibrated\n", Ncalibrated); 814 829 fprintf (stderr, "%d images marked having too few measurements (Nbad: %d, Nmos: %d, Ngrid: %d, Nrel: %d, Nsys: %d)\n", Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys); 815 816 if (PoorImages) {817 IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;818 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;819 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;820 }821 830 822 831 FitDataSetFree (&brightStars); … … 1291 1300 image = NULL; 1292 1301 } 1293 1294 void checkImages (char *name) {1295 1296 off_t i;1297 fprintf (stderr, "--- %s ---\n", name);1298 1299 OhanaMemblock *ref = (OhanaMemblock *) image - 1;1300 fprintf (stderr, "file: %s\n", ref->file);1301 1302 fprintf (stderr, "0x%08llx \n", (unsigned long long) image);1303 1304 for (i = 0; i < Nimage; i++) {1305 fprintf (stderr, "%s : 0x%08x : %6.3f %6.3f\n", image[i].name, image[i].flags, image[i].McalPSF, image[i].McalAPER);1306 }1307 } -
trunk/Ohana/src/relphot/src/MosaicOps.c
r41555 r41556 1 1 # include "relphot.h" 2 2 off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start); 3 int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog, FlatCorrectionTable *flatcorr); 3 4 4 5 // see discussion in ImagesOps.c re: IDX_T … … 983 984 int Nskip; 984 985 off_t Nmax; 985 int PoorImages;986 986 FitDataSet psfStars; 987 987 FitDataSet kronStars; … … 1002 1002 int setMmos_mosaic (Mosaic *mosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info, FlatCorrectionTable *flatcorr); 1003 1003 void *setMmos_worker (void *data); 1004 int setMmos_threaded (Catalog *catalog, int PoorImages,FlatCorrectionTable *flatcorr);1005 1006 void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists , int PoorImages) {1004 int setMmos_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr); 1005 1006 void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists) { 1007 1007 info->Nfew = 0; 1008 1008 info->Nbad = 0; … … 1014 1014 1015 1015 info->Nmax = Nmax; 1016 info->PoorImages = PoorImages;1017 1016 1018 1017 if (allocLists) { … … 1069 1068 } 1070 1069 1071 int setMmos (Catalog *catalog, int PoorImages,FlatCorrectionTable *flatcorr) {1070 int setMmos (Catalog *catalog, FlatCorrectionTable *flatcorr) { 1072 1071 1073 1072 off_t i, N, Nmax; … … 1082 1081 // so do not run setMmos in threaded mode if PLOTSTUFF is set 1083 1082 if (NTHREADS && !PLOTSTUFF) { 1084 int status = setMmos_threaded (catalog, PoorImages,flatcorr);1083 int status = setMmos_threaded (catalog, flatcorr); 1085 1084 return status; 1086 1085 } … … 1089 1088 1090 1089 fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE); 1091 1092 if (PoorImages) {1093 // XXX use bad stars and measurements for PoorImages? or not?1094 // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;1095 IMAGE_BAD = 0;1096 }1097 1090 1098 1091 Nmax = 0; … … 1102 1095 1103 1096 SetMmosInfo info; 1104 SetMmosInfoInit (&info, Nmax, TRUE , PoorImages);1097 SetMmosInfoInit (&info, Nmax, TRUE); 1105 1098 1106 1099 // int savePlotDelay = PLOTDELAY; … … 1121 1114 fprintf (stderr, "%d mosaics 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); 1122 1115 1123 if (PoorImages) {1124 IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;1125 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;1126 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;1127 }1128 1116 return (TRUE); 1129 1117 } … … 1134 1122 off_t j, NimageReal; 1135 1123 1136 /* on PoorImages run, skip good images */1137 if (info->PoorImages) {1138 int bad = myMosaic[0].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP);1139 if (!bad) return TRUE;1140 }1141 1142 1124 FitDataSet *psfStars = &info->psfStars; 1143 1125 FitDataSet *kronStars = &info->kronStars; … … 1147 1129 assert (Nmos < Nmosaic); 1148 1130 1131 int Nsecfilt = GetPhotcodeNsecfilt (); 1132 1133 int minUbercalDist = 1000; 1134 1135 // unset this flag at start (set below if zeropoint is calculated) 1136 myMosaic->flags &= ~ID_IMAGE_MOSAIC_PHOTCAL; // unset this flag 1137 1138 // calculate the statistics for both good and bad exposures, but only set Mmos if the rules allow 1139 // we only skip the statistics for nights with too few measurements or exposures 1140 1141 // if we are fitting TGroup zero points, when we identify the bad TGroups, we proceed 1142 // to fit the mosaics which are from the bad TGroups 1143 1144 // if we are fitting Mosaic zero points, when we identify the bad nights, we proceed 1145 // to fit the images which are from the bad Mosaics 1146 1149 1147 int badNight = (myMosaic[0].flags & ID_IMAGE_NIGHT_POOR); 1150 1148 int badMosaic = (myMosaic[0].flags & ID_IMAGE_MOSAIC_POOR); 1151 1152 myMosaic->flags &= ~ID_IMAGE_MOSAIC_PHOTCAL; // unset this flag 1153 1154 // if we are fitting TGroup zero points, when we identify the bad TGroups, we proceed 1155 // to fit the mosaics which are from the bad TGroups 1156 1157 // if we are fitting Mosaic zero points, when we identify the bad nights, we proceed 1158 // to fit the images which are from the bad Mosaics 1159 1160 // in BAD_NIGHT mode, we fit ONLY mosaics in bad nights 1149 int useMmos = TRUE; 1150 1151 // in BAD_NIGHT mode, we fit ONLY mosaics in bad nights (do not fit mosaics from good nights) 1161 1152 if (MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT) { 1162 if (!badNight) return TRUE;1153 if (!badNight) useMmos = FALSE; 1163 1154 } 1164 1155 1165 1156 // in BAD_NIGHT_GOOD_MOSAIC mode, we fit ONLY good mosaics in bad nights 1166 1157 if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC)) { 1167 if (!badNight) return TRUE;1168 if (badMosaic) return TRUE;1158 if (!badNight) useMmos = FALSE; // do not fit good nights 1159 if (badMosaic) useMmos = FALSE; // do not fit bad mosaics 1169 1160 } 1170 1161 1171 1162 // in GOOD_MOSAIC mode, we fit good mosaics ignoring night state 1172 1163 if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_GOOD_MOSAIC)) { 1173 if (badMosaic) return TRUE;1164 if (badMosaic) useMmos = FALSE; // do not fit bad mosaics 1174 1165 } 1175 1166 … … 1189 1180 // fprintf (stderr, "%d %d %d\n", (int) i, (int) im, image[im].ubercalDist); 1190 1181 } 1182 // XXX if KEEP_UBERCAL, calculate stats but do not change Mmos 1191 1183 if (KEEP_UBERCAL) return TRUE; 1192 1184 } 1193 1194 int Nsecfilt = GetPhotcodeNsecfilt ();1195 1196 int minUbercalDist = 1000;1197 1185 1198 1186 // do not modify the calibration for mosaics with partial images loaded (skipCal TRUE) … … 1204 1192 int testImage = FALSE; 1205 1193 // testImage |= (abs(myMosaic[0].start - 1324104046) < 10); 1206 // testImage |= (abs(myMosaic[0].start - 1324103823) < 10);1207 // testImage |= (abs(myMosaic[0].start - 1323003245) < 10);1208 // testImage |= (abs(myMosaic[0].start - 1323003069) < 10);1209 // testImage |= (abs(myMosaic[0].start - 1323003125) < 10);1210 // testImage |= (abs(myMosaic[0].start - 1323003300) < 10);1211 // testImage |= (abs(myMosaic[0].start - 1323003365) < 10);1212 // testImage |= (abs(myMosaic[0].start - 1323003191) < 10);1213 // testImage |= (abs(myMosaic[0].start - 1323003014) < 10);1214 // testImage |= (abs(myMosaic[0].start - 1323003484) < 10);1215 // testImage |= (abs(myMosaic[0].start - 1323003419) < 10);1216 // testImage |= (abs(myMosaic[0].start - 1323002949) < 10);1217 1194 1218 1195 FILE *fout = NULL; … … 1221 1198 snprintf (filename, 64, "test.%05d.%02d.dat", (int) Nmos, npass_output); 1222 1199 fout = fopen (filename, "w"); 1200 save_test_mosaic_measures (fout, Nmos, catalog, flatcorr); 1201 fclose (fout); 1223 1202 } 1224 1203 … … 1232 1211 off_t c = MosaicToCatalog[Nmos][j]; 1233 1212 1234 // NOTE : we are only using Mcal == McalPSF in this function; we set McalAPER to McalPSF1235 if (fout) {1236 float Mcal = getMcal (m, c, MAG_CLASS_PSF);1237 // float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL);1238 float Mgrid = getMgrid (m, c);1239 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);1240 float Mflat = getMflat (m, c, flatcorr, catalog);1241 1242 off_t n = catalog[c].measureT[m].averef;1243 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);1244 1245 float delta = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;1246 1247 int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);1248 1249 fprintf (fout, "%f %f : %f %f %f %f %f : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mgrid, Mflat, delta, isBad);1250 }1251 1252 1213 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 1253 1214 info->Nbad ++; … … 1329 1290 /* N_onMosaic[Nmos] is all measurements, N is good measurements */ 1330 1291 1331 if (fout) { fclose (fout); } 1332 1333 /* too few good measurements or too many bad measurements (skip in PoorImages run) */ 1334 if (!info->PoorImages) { 1335 int mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*N_onMosaic[Nmos]); 1336 if (mark) { 1337 if (VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), (%d < %d) || (%d < %f*"OFF_T_FMT")\n", image[MosaicToImage[Nmos][0]].name, Nmos, N, IMAGE_TOOFEW, N, IMAGE_GOOD_FRACTION, N_onMosaic[Nmos]); } 1338 myMosaic[0].flags |= ID_IMAGE_PHOTOM_FEW; 1339 info->Nfew ++; 1340 if (testImage) { 1341 fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) IMAGE_TOOFEW, (int) (IMAGE_GOOD_FRACTION*N_onMosaic[Nmos])); 1342 } 1343 return TRUE; // skip mosaics with too few good measurements 1344 } else { 1345 myMosaic[0].flags &= ~ID_IMAGE_PHOTOM_FEW; 1346 } 1292 /* skip mosaics with too few good measurements or too many bad measurements */ 1293 int mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*N_onMosaic[Nmos]); 1294 if (mark) { 1295 myMosaic->flags |= ID_IMAGE_PHOTOM_FEW; 1296 myMosaic->McalPSF = 0.0; 1297 myMosaic->McalAPER = 0.0; 1298 myMosaic->dMcal = NAN; 1299 myMosaic->stdev = NAN; 1300 myMosaic->dMmin = NAN; 1301 myMosaic->dMmax = NAN; 1302 myMosaic->McalChiSq = NAN; 1303 myMosaic->nFitPhotom = 0; 1304 myMosaic->nValPhotom = N; 1305 info->Nfew ++; 1306 if (testImage) { 1307 fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) IMAGE_TOOFEW, (int) (IMAGE_GOOD_FRACTION*N_onMosaic[Nmos])); 1308 } 1309 return TRUE; // skip mosaics with too few good measurements 1310 } else { 1311 myMosaic[0].flags &= ~ID_IMAGE_PHOTOM_FEW; 1312 } 1313 1314 StatType stats; 1315 liststats_setmode (&stats, "MEDIAN"); 1316 liststats (psfStars->alldata->yVector, NULL, NULL, N, &stats); 1317 double altSigma = (stats.Upper80 - stats.Lower20) / 1.6; // 20% to 80% encompasses 60% of the values, corresponds to the range (-0.85 sigma : +0.85 sigma) 1318 1319 // soften the individual errors with 10% of the scatter above 1320 for (j = 0; j < N; j++) { 1321 double newSigma = hypot(psfStars->alldata->dyVector[j], 0.1*altSigma); 1322 psfStars->alldata->dyVector[j] = newSigma; 1347 1323 } 1348 1324 1349 1325 fit1d_irls (psfStars, N); 1350 1326 fit1d_irls (brightStars, Nbright); 1327 fit1d_irls (kronStars, N); 1328 1329 if (useMmos) { 1330 myMosaic->McalPSF = psfStars->bSaveArray[0][0]; 1331 myMosaic->McalAPER = kronStars->bSaveArray[0][0]; 1332 myMosaic->flags |= ID_IMAGE_MOSAIC_PHOTCAL; // set this flag 1333 } else { 1334 myMosaic->McalPSF = 0.0; 1335 myMosaic->McalAPER = 0.0; 1336 } 1351 1337 1352 1338 // for now, I have no reason to measure these separately for camera-level images 1353 myMosaic[0].McalPSF = psfStars->bSaveArray[0][0]; 1354 myMosaic[0].dMcal = psfStars->bSigma[0]; 1355 myMosaic[0].stdev = psfStars->sigma; 1356 myMosaic[0].McalChiSq = psfStars->chisq; 1357 myMosaic[0].nFitPhotom = psfStars->Nmeas; 1358 myMosaic[0].nValPhotom = N; 1359 1360 fit1d_irls (kronStars, N); 1361 myMosaic->McalAPER = kronStars->bSaveArray[0][0]; 1339 myMosaic->dMcal = psfStars->bSigma[0]; 1340 myMosaic->stdev = psfStars->sigma; 1341 myMosaic->McalChiSq = psfStars->chisq; 1342 myMosaic->nFitPhotom = psfStars->Nmeas; 1343 myMosaic->nValPhotom = N; 1344 1345 // bright end scatter 1346 myMosaic->dMsys = brightStars->sigma; // stdev of bright star mags 1362 1347 1363 1348 if (testImage) { 1364 1349 fprintf (stderr, "test image %d (%d) %f %f %d ... ", (int) Nmos, myMosaic->start, myMosaic->McalPSF, myMosaic->dMcal, myMosaic->nFitPhotom); 1350 fprintf (stderr, "%f %f : %f\n", myMosaic[0].McalPSF, myMosaic[0].dMsys, myMosaic[0].McalChiSq); 1365 1351 } 1366 1352 … … 1368 1354 fprintf (stderr, "Mmos: %6.3f +/- %6.3f %5d %5d | %s\n", myMosaic->McalPSF, myMosaic->dMcal, myMosaic->nFitPhotom, N, image[MosaicToImage[Nmos][0]].name); 1369 1355 plot_setMcal (psfStars->alldata->yVector, N); 1370 }1371 1372 // bright end scatter1373 fit1d_irls (brightStars, Nbright);1374 myMosaic->dMsys = brightStars->sigma; // stdev of bright star mags1375 1376 if (myMosaic[0].McalPSF < -CLOUD_TOLERANCE) {1377 myMosaic[0].McalPSF = 0.0;1378 }1379 1380 myMosaic->flags |= ID_IMAGE_MOSAIC_PHOTCAL; // set this flag1381 1382 if (testImage) {1383 fprintf (stderr, "%f %f : %f\n", myMosaic[0].McalPSF, myMosaic[0].dMsys, myMosaic[0].McalChiSq);1384 1356 } 1385 1357 … … 1400 1372 } 1401 1373 1402 int setMmos_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) { 1374 int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog, FlatCorrectionTable *flatcorr) { 1375 1376 int Nsecfilt = GetPhotcodeNsecfilt (); 1377 1378 for (int j = 0; j < N_onMosaic[Nmos]; j++) { 1379 1380 off_t m = MosaicToMeasure[Nmos][j]; 1381 off_t c = MosaicToCatalog[Nmos][j]; 1382 1383 // NOTE : we are only using Mcal == McalPSF in this function; we set McalAPER to McalPSF 1384 float Mcal = getMcal (m, c, MAG_CLASS_PSF); 1385 // float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1386 float Mgrid = getMgrid (m, c); 1387 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 1388 float Mflat = getMflat (m, c, flatcorr, catalog); 1389 1390 off_t n = catalog[c].measureT[m].averef; 1391 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 1392 1393 float delta = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat; 1394 1395 int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD); 1396 1397 fprintf (fout, "%f %f : %f %f %f %f %f : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mgrid, Mflat, delta, isBad); 1398 } 1399 return TRUE; 1400 } 1401 1402 int setMmos_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr) { 1403 1403 1404 1404 int i; … … 1408 1408 1409 1409 fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE); 1410 1411 if (PoorImages) {1412 // XXX use bad stars and measurements for PoorImages? or not?1413 // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;1414 IMAGE_BAD = 0;1415 }1416 1410 1417 1411 off_t Nmax = 0; … … 1421 1415 1422 1416 SetMmosInfo summary; 1423 SetMmosInfoInit (&summary, Nmax, FALSE , PoorImages);1417 SetMmosInfoInit (&summary, Nmax, FALSE); 1424 1418 1425 1419 pthread_attr_t attr; … … 1445 1439 threadinfo[i].flatcorr = flatcorr; 1446 1440 1447 // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop ,1448 // PoorImages) used inthe threads to allocate the arrays and set the MaxIterations1449 SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE , PoorImages);1441 // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop) used in 1442 // the threads to allocate the arrays and set the MaxIterations 1443 SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE); 1450 1444 pthread_create (&threads[i], NULL, setMmos_worker, &threadinfo[i]); 1451 1445 } … … 1492 1486 npass_output ++; 1493 1487 1494 if (PoorImages) {1495 IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;1496 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;1497 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;1498 }1499 1488 return TRUE; 1500 1489 } … … 1505 1494 1506 1495 SetMmosInfo results; 1507 SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE , threadinfo->info.PoorImages);1496 SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE); 1508 1497 1509 1498 while (1) { … … 1892 1881 int N = 0; 1893 1882 for (int i = 0; i < Nmosaic; i++) { 1894 // if (mosaic[i].flags & IMAGE_BAD) continue;1895 1883 if (!(mosaic[i].flags & ID_IMAGE_MOSAIC_PHOTCAL)) continue; 1896 1884 if (mosaic[i].skipCal) continue; … … 1906 1894 float MaxChiSq = stats.Upper90; 1907 1895 1908 // old version based on Mcal value1909 // MaxOffset = MAX (IMAGE_OFFSET, 2*stats.sigma);1910 /// MedOffset = stats.median;1911 1912 1896 liststats (slist, NULL, NULL, N, &stats); 1913 1897 float MaxScatter = stats.Upper90; 1914 // old: MaxScatter = MAX (IMAGE_SCATTER, 2*stats.median);1915 1898 1916 1899 fprintf (stderr, "MOSAIC: Max ChiSq: %f, Max Scatter: %f\n", MaxChiSq, MaxScatter); … … 1927 1910 int mark = FALSE; 1928 1911 1929 if (mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW)) {1912 if (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW) { 1930 1913 mark = TRUE; 1931 1914 Nfew ++; -
trunk/Ohana/src/relphot/src/StarOps.c
r41473 r41556 662 662 663 663 // this function only operations on the PSF magnitudes 664 665 // XXX EAM clean_measures is no longer used -- we rely on IRLS to down-weight outliers 664 666 665 667 # define NSIGMA_CLIP 3.0 -
trunk/Ohana/src/relphot/src/TGroupOps.c
r41555 r41556 194 194 for (off_t i = 0; i < Nsubset; i++) { 195 195 ImageToTGroup[i] = NULL; 196 197 // ignore non-GPC1 images198 // if (!isGPC1chip(subset[i].photcode)) {199 // Nsimple ++;200 // continue;201 // }202 196 203 197 // ignore mosaic images (photcode == 0) … … 459 453 // this tgroup has been identified as poor. 460 454 tgroup->flags |= ID_IMAGE_NIGHT_POOR; 455 tgroup->McalPSF = 0.0; 456 tgroup->McalAPER = 0.0; 457 tgroup->dKlam = 0.0; 461 458 462 459 // all associated mosaics should be marked as coming from a bad night … … 473 470 image[im].flags |= ID_IMAGE_NIGHT_POOR; 474 471 } 475 476 tgroup->McalPSF = 0.0;477 tgroup->McalAPER = 0.0;478 tgroup->dKlam = 0.0;479 472 } 480 473 … … 552 545 fprintf (stderr, "Matched %d detections to tgroups\n", Nmatch); 553 546 554 // XXX print results for testing555 for (int i = 0; FALSE && (i < NtgroupTimes); i++) {556 TGroup *tgroup = tgroupTimes[i][0].byCode;557 for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {558 if (0) fprintf (stderr, " TGROUP time %.0f photcode %d, Nmeasure: %d, Nimage: %d\n", ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode, (int) tgroup[j].Nmeasure, (int) tgroup[j].Nimage);559 }560 }561 547 return (TRUE); 562 548 } … … 574 560 575 561 TGroup *myGroup = ImageToTGroup[idx]; 576 TGTimes *parent = (TGTimes *) myGroup->parent; 577 if (!myGroup) { 578 // Image *image = getimage(idx); 579 // fprintf (stderr, "unmatched image %s\n", image[0].name); 580 // skip measurements from simple chips (not matched to a tgroup by definition) 581 return; 582 } 583 584 // test to check we got the right match: 585 { 586 Image *image = getimage(idx); 587 // XXX we are now matching with just tzero. be careful for cameras with drift 588 // unsigned int imageStart = image[0].tzero - MAX(0.01*image[0].trate*image[0].NY, 1); 589 unsigned int imageStart = image[0].tzero; 590 // XXX to do this check I need a pointer to the group master 591 if ((imageStart < parent->start) || (imageStart > parent->stop)) { 592 fprintf (stderr, "error in image to tgroup match\n"); 593 abort(); 594 } 595 } 562 if (!myGroup) return; 596 563 597 564 // this measurement is on one of my tgroups, mark it as mine. … … 611 578 } 612 579 613 // XXX return the error as well as the value580 // dZpt (if supplied) returns the error on Mgrp 614 581 float getMgrp (off_t meas, int cat, float airmass, float *dZpt) { 615 582 … … 638 605 } 639 606 640 // XXX remove the lists and replace with StatDataSet structs?641 // XXX move the StatDataSetAlloc up?642 607 typedef struct { 643 608 int Nfew; … … 650 615 int Nskip; 651 616 off_t Nmax; 652 int PoorImages;653 617 FitDataSet psfStars; 654 618 FitDataSet kronStars; … … 669 633 int setMgrp_tgroup (TGroup *tgroup, off_t Nmos, Image *image, Catalog *catalog, SetMgrpInfo *info, FlatCorrectionTable *flatcorr); 670 634 void *setMgrp_worker (void *data); 671 int setMgrp_threaded (Catalog *catalog, int PoorImages,FlatCorrectionTable *flatcorr);672 673 void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists , int PoorImages) {635 int setMgrp_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr); 636 637 void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists) { 674 638 info->Nfew = 0; 675 639 info->Nbad = 0; … … 682 646 683 647 info->Nmax = Nmax; 684 info->PoorImages = PoorImages;685 648 686 649 if (allocLists) { … … 744 707 } 745 708 746 int setMgrp (Catalog *catalog, int PoorImages,FlatCorrectionTable *flatcorr) {709 int setMgrp (Catalog *catalog, FlatCorrectionTable *flatcorr) { 747 710 748 711 off_t N; … … 755 718 // so do not run setMgrp in threaded mode if PLOTSTUFF is set 756 719 if (NTHREADS && !PLOTSTUFF) { 757 int status = setMgrp_threaded (catalog, PoorImages,flatcorr);720 int status = setMgrp_threaded (catalog, flatcorr); 758 721 return status; 759 722 } … … 770 733 771 734 SetMgrpInfo info; 772 SetMgrpInfoInit (&info, Nmax, TRUE , PoorImages);735 SetMgrpInfoInit (&info, Nmax, TRUE); 773 736 774 737 for (off_t i = 0; i < NtgroupTimes; i++) { … … 776 739 for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) { 777 740 setMgrp_tgroup (&tgroup[j], i, image, catalog, &info, flatcorr); 778 // 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); 741 // 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", 742 // 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); 779 743 } 780 744 } … … 799 763 int setMgrp_tgroup (TGroup *myTGroup, off_t Ngrp, Image *image, Catalog *catalog, SetMgrpInfo *info, FlatCorrectionTable *flatcorr) { 800 764 801 off_t j, NimageReal; 802 803 // At some point, we identify good and bad tgroups. We mark bad tgroups and do not fit 804 // a zero point for them. Instead we will fit those exposures or images separately 805 if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_GOOD_NIGHT) { 806 int bad = myTGroup->flags & ID_IMAGE_NIGHT_POOR; 807 if (bad) return TRUE; 808 } 765 off_t j; 766 767 // calculate the statistics for both good and bad nights, but only set Mcal for the good nights 768 // we only skip the statistics for nights with too few measurements or exposures 809 769 810 770 FitDataSet *psfStars = &info->psfStars; … … 815 775 assert (Ngrp < NtgroupTimes); 816 776 817 // Image *imageReal = getimages (&NimageReal, NULL); returned pointer is not used818 getimages (&NimageReal, NULL);819 820 777 int Nsecfilt = GetPhotcodeNsecfilt (); 821 778 822 int testImage = FALSE;823 779 TGTimes *tgroup = (TGTimes *) myTGroup->parent; 824 780 double mjdStart = ohana_sec_to_mjd (tgroup->start); … … 827 783 myTGroup->flags &= ~ID_IMAGE_TGROUP_PHOTCAL; 828 784 829 // testImage = TRUE; 830 testImage |= (abs(mjdStart - 57353) < 0.1); 831 testImage |= (abs(mjdStart - 57952) < 0.1); 832 testImage |= (abs(mjdStart - 55843) < 0.1); 833 testImage |= (abs(mjdStart - 56586) < 0.1); 834 testImage |= (abs(mjdStart - 57323) < 0.1); 835 //testImage |= (abs(mjdStart - 57971) < 0.1); 836 //testImage |= (abs(mjdStart - 57974) < 0.1); 837 //testImage |= (abs(mjdStart - 57978) < 0.1); 838 //testImage |= (abs(mjdStart - 57981) < 0.1); 785 // in clean_tgroups (run on each iteration), we identify good and bad tgroups. We mark 786 // bad tgroups and do not save a zero point for them. Instead we will fit those 787 // exposures or images separately 788 int useMgrp = TRUE; 789 if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_GOOD_NIGHT) { 790 if (myTGroup->flags & ID_IMAGE_NIGHT_POOR) useMgrp = FALSE; 791 } 792 793 // for testing, supply the MJD of a night or nights here to dump the full list of measurements 794 int testImage = FALSE; 795 // testImage |= (abs(mjdStart - 57353) < 0.1); 839 796 840 797 FILE *fout = NULL; … … 905 862 float MsysKron = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_KRON); 906 863 907 // XXX byCode :here we are only checking for equiv photcodes (not active photcodes)864 // here we are only checking for equiv photcodes (not active photcodes) 908 865 PhotCode *code = GetPhotcodebyCode (catalog[c].measureT[m].photcode); 909 866 if (!code) goto skip; … … 942 899 } 943 900 944 /* too few good measurements or too many bad measurements (skip in PoorImages run)*/901 /* skip nights with too few good measurements or too many bad measurements */ 945 902 int mark = (N < NIGHT_TOOFEW) || (N < NIGHT_GOOD_FRACTION*myTGroup->Nmeasure); 946 903 if (mark) { 947 if (TRUE) {948 TGTimes *mygroup = (TGTimes *) myTGroup->parent;949 if (0) { // XXX EAM950 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);951 }952 }953 904 myTGroup->flags |= ID_IMAGE_PHOTOM_FEW; 905 myTGroup->McalPSF = 0.0; 906 myTGroup->McalAPER = 0.0; 907 myTGroup->dMcal = NAN; 908 myTGroup->stdev = NAN; 909 myTGroup->dMmin = NAN; 910 myTGroup->dMmax = NAN; 911 myTGroup->McalChiSq = NAN; 912 myTGroup->nFitPhotom = 0; 954 913 myTGroup->nValPhotom = N; 914 myTGroup->dKlam = (TGROUP_FIT_AIRMASS) ? psfStars->bSaveArray[1][0] : 0; 955 915 info->Nfew ++; 956 916 if (testImage) { … … 986 946 987 947 fit1d_irls (psfStars, N); 988 989 // if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mgrp: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N); 990 991 // for now, I have no reason to measure these separately for camera-level images 992 myTGroup->McalPSF = psfStars->bSaveArray[0][0]; 948 fit1d_irls (kronStars, N); 949 fit1d_irls (brightStars, Nbright); 950 951 if (useMgrp) { 952 myTGroup->McalPSF = psfStars->bSaveArray[0][0]; 953 myTGroup->McalAPER = kronStars->bSaveArray[0][0]; // XXX this does not make sense: I need to apply the airmass slope calculated above first 954 myTGroup->flags |= ID_IMAGE_TGROUP_PHOTCAL; // set this flag (unset by default) 955 } else { 956 myTGroup->McalPSF = 0.0; 957 myTGroup->McalAPER = 0.0; 958 } 959 960 // record statistics on the fit regardless if it is used or not 993 961 myTGroup->dMcal = psfStars->bSigma[0]; 994 962 myTGroup->stdev = psfStars->sigma; … … 1000 968 myTGroup->dKlam = (TGROUP_FIT_AIRMASS) ? psfStars->bSaveArray[1][0] : 0; 1001 969 1002 // XXX this does not make sense: I need to apply the airmass slope calculated above first 1003 fit1d_irls (kronStars, N); 1004 myTGroup->McalAPER = kronStars->bSaveArray[0][0]; 970 // bright end scatter (systematic error) 971 myTGroup->dMsys = brightStars->sigma; 1005 972 1006 973 if (testImage) { 1007 974 TGTimes *parent = (TGTimes *) myTGroup->parent; 1008 975 fprintf (stderr, "test night %.0f aper: %f %f %d ... ", ohana_sec_to_mjd(parent->start), myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom); 976 fprintf (stderr, "%f %f : %f\n", myTGroup->McalPSF, myTGroup->dMsys, myTGroup->McalChiSq); 1009 977 } 1010 978 if (PLOTSTUFF) { 1011 979 fprintf (stderr, "Mgrp: %6.3f +/- %6.3f %5d of %5d | %.0f\n", myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom, N, ohana_sec_to_mjd(tgroup->start)); 1012 980 plot_setMcal (psfStars->alldata->yVector, N); 1013 }1014 1015 // bright end scatter1016 // XXX this does not make sense: I need to apply the airmass slope calculated above first1017 // redo this by calculating the corrected bright stars mags1018 fit1d_irls (brightStars, Nbright);1019 myTGroup->dMsys = brightStars->sigma;1020 1021 // keep this??1022 if (myTGroup->McalPSF < -CLOUD_TOLERANCE) {1023 myTGroup->McalPSF = 0.0;1024 }1025 1026 myTGroup->flags |= ID_IMAGE_TGROUP_PHOTCAL; // set this flag1027 1028 if (testImage) {1029 fprintf (stderr, "%f %f : %f\n", myTGroup->McalPSF, myTGroup->dMsys, myTGroup->McalChiSq);1030 981 } 1031 982 … … 1070 1021 } 1071 1022 1072 int setMgrp_threaded (Catalog *catalog, int PoorImages,FlatCorrectionTable *flatcorr) {1023 int setMgrp_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr) { 1073 1024 1074 1025 int i; … … 1077 1028 Image *image = getimages (&N, NULL); 1078 1029 1079 fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);1080 1081 1030 off_t Nmax = 0; 1082 1031 for (off_t i = 0; i < NtgroupTimes; i++) { … … 1088 1037 1089 1038 SetMgrpInfo summary; 1090 SetMgrpInfoInit (&summary, Nmax, FALSE , PoorImages);1039 SetMgrpInfoInit (&summary, Nmax, FALSE); 1091 1040 1092 1041 pthread_attr_t attr; … … 1112 1061 threadinfo[i].flatcorr = flatcorr; 1113 1062 1114 // we do NOT allocate the arrays here, we only supply basic info (Nmax,1115 // PoorImages) used in the threadsto allocate the arrays and set the MaxIterations1116 SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE , PoorImages);1063 // we do NOT allocate the arrays here, we only supply basic info used in the threads 1064 // to allocate the arrays and set the MaxIterations 1065 SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE); 1117 1066 pthread_create (&threads[i], NULL, setMgrp_worker, &threadinfo[i]); 1118 1067 } … … 1169 1118 1170 1119 SetMgrpInfo results; 1171 SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE , threadinfo->info.PoorImages); // allocate list, dlist arrays here1120 SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE); // allocate list, dlist arrays here 1172 1121 1173 1122 while (1) { … … 1194 1143 } 1195 1144 1196 // XXX should I split these stats out by photcode?1197 // XXX double check the IMAGE_BAD filter:1198 1145 StatType statsTGroupM (Catalog *catalog) { 1199 1146 OHANA_UNUSED_PARAM(catalog); … … 1209 1156 ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes); 1210 1157 1211 // is ID_IMAGE_PHOTOM_POOR used for tgroups? 1212 int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR; 1158 int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW; 1213 1159 1214 1160 int n = 0; … … 1316 1262 ALLOCATE (slist, double, NtgroupTimes*Nphotcodes); 1317 1263 1264 // measure the good/bad statistics using nights which are actually calibrated 1265 // but they will be applied to all nights below (allowing bad nights to become good) 1318 1266 int N = 0; 1319 1267 for (int i = 0; i < NtgroupTimes; i++) { 1320 1268 TGroup *tgroup = tgroupTimes[i][0].byCode; 1321 1269 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1322 if ( tgroup[j].flags & IMAGE_BAD) continue;1270 if (!(tgroup[j].flags & ID_IMAGE_TGROUP_PHOTCAL)) continue; 1323 1271 mlist[N] = tgroup[j].McalChiSq; 1324 1272 slist[N] = tgroup[j].stdev; // stdev of all measurements 1325 // slist[N] = tgroup[j].dMsys; // stdev of bright measurements1326 1273 N++; 1327 1274 } … … 1491 1438 } 1492 1439 1440 // temporary test output 1493 1441 void dump_tgroups (Catalog *catalog, int Npass) { 1494 1442 … … 1606 1554 fclose (fout); 1607 1555 } 1556 1557 /* 1558 for testing, put lines like these in relphot_images.c within the iteration loop 1559 dump_tgroups (catalog, i + 40); 1560 dump_catalog (catalog, 0, i + 40); // for a test, just dump a specific catalog 1561 dump_tgroup_imstats (i + 40); 1562 */ -
trunk/Ohana/src/relphot/src/relphot_images.c
r41555 r41556 41 41 load_images (&db, skylist, &UserPatch, FALSE, USE_ALL_IMAGES); 42 42 MARKTIME("-- load images: %f sec\n", dtime); 43 44 // checkImages("load images");45 43 46 44 /* unlock, if we can (else, unlocked below) */ … … 63 61 /* add in a loop over the catalogs calling dvo_catalog_chipcoords */ 64 62 65 // checkImages("load catalog");66 67 63 /* match measurements with images, mosaics */ 68 64 initImageBins (catalog, Ncatalog, TRUE); … … 87 83 88 84 setExclusions (catalog, Ncatalog, TRUE); 89 // checkImages("set Exclu");90 85 91 86 global_stats (catalog, Ncatalog, flatcorr, 0); … … 118 113 SetZptIteration (i); 119 114 120 dump_tgroups (catalog, i);121 dump_catalog (catalog, 0, i); // for a test, just dump a specific catalog122 dump_tgroup_imstats (i);123 124 115 setMrel (catalog, Ncatalog, flatcorr); // threaded 125 setMcalTest (catalog, flatcorr); 126 127 dump_tgroups (catalog, i + 20); 128 dump_catalog (catalog, 0, i + 20); // for a test, just dump a specific catalog 129 dump_tgroup_imstats (i + 20); 130 131 setMcal (catalog, FALSE, flatcorr); 132 setMmos (catalog, FALSE, flatcorr); 133 setMgrp (catalog, FALSE, flatcorr); 134 dump_tgroups (catalog, i + 40); 135 dump_catalog (catalog, 0, i + 40); // for a test, just dump a specific catalog 136 dump_tgroup_imstats (i + 40); 116 117 setMcal (catalog, flatcorr); 118 setMmos (catalog, flatcorr); 119 setMgrp (catalog, flatcorr); 137 120 138 121 setMgrid (catalog, flatcorr); … … 166 149 if (USE_GRID) dump_grid (); 167 150 168 /* set Mcal & Mmos for bad images */169 int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS;170 onlyPoorImages = FALSE; // XXX deactivate for now171 setMcal (catalog, onlyPoorImages, flatcorr); // max loop since this is a final pass172 setMmos (catalog, onlyPoorImages, flatcorr); // max loop since this is a final pass173 setMgrp (catalog, onlyPoorImages, flatcorr); // max loop since this is a final pass174 151 MARKTIME("-- finalize Mcal values: %f sec\n", dtime); 175 152 … … 177 154 setMcalFromTGroups (); // copy per-tgroup calibrations to the images 178 155 179 if (SAVE_IMAGE_UPDATES) { 180 181 FITS_DB dbX; 182 off_t *LineNumber; 183 Image *image, *subset; 184 off_t Nimage, Nsubset, i, Nx; 185 char filename[1024]; 186 187 gfits_db_init (&dbX); 188 dbX.lockstate = LCK_XCLD; 189 dbX.timeout = 60.0; 190 dbX.mode = db.mode; 191 dbX.format = db.format; 192 193 snprintf (filename, 1024, "%s.bck", ImageCat); 194 if (!gfits_db_lock (&dbX, filename)) { 195 fprintf (stderr, "can't lock backup image image catalog\n"); 196 return (FALSE); 197 } 198 199 // apply the changes from the image subset to the full table: 200 201 // convert database table to internal structure (binary to Image) 202 // 'image' points to the same memory as db->ftable->buffer 203 image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder); 204 if (!image) { 205 fprintf (stderr, "ERROR: failed to read images\n"); 206 exit (2); 207 } 208 gfits_scan (db.ftable.header, "NAXIS1", OFF_T_FMT, 1, &Nx); 209 210 subset = getimages (&Nsubset, &LineNumber); 211 for (i = 0; i < Nsubset; i++) { 212 if (LineNumber[i] == -1) continue; 213 memcpy (&image[LineNumber[i]], &subset[i], Nx); 214 } 215 216 // copy Images.dat data (all or only the subset / vtable elements?) I think I need to dump 217 // the entire Image table, but with the updates in place I think this says: re-work the 218 // ftable/vtable usage in this program to be more sensible... 219 gfits_copy_header (&db.header, &dbX.header); 220 gfits_copy_matrix (&db.matrix, &dbX.matrix); 221 gfits_copy_header (&db.theader, &dbX.theader); 222 gfits_copy_ftable (&db.ftable, &dbX.ftable); 223 224 dbX.ftable.header = &dbX.theader; 225 dbX.virtual = FALSE; 226 227 // save Images.dat using the copied structure 228 if (UPDATE_CATFORMAT) { 229 // ensure the db format is updated 230 dbX.format = dvo_catalog_catformat (UPDATE_CATFORMAT); 231 gfits_modify (&dbX.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT); 232 233 char photcodeFile[1024]; 234 sprintf (photcodeFile, "%s/Photcodes.dat", CATDIR); 235 SavePhotcodesFITS (photcodeFile); 236 } 237 dvo_image_save (&dbX, VERBOSE); 238 dvo_image_unlock (&dbX); 239 gfits_db_free (&dbX); 240 MARKTIME("-- save Image.dat.bck: %f sec\n", dtime); 241 } 156 // calculate and save per-chip residuals here: 157 MagResidSave ("mag.resid.fits", catalog); 158 159 save_images_updates (&db); 242 160 243 161 /* at this point, we have correct cal coeffs in the image/mosaic structures */ -
trunk/Ohana/src/relphot/src/relphot_parallel_images.c
r41473 r41556 112 112 113 113 // set the image (Mcal) and mosaic (Mmos) zero point offsets given the mean mags and measurements 114 setMcal (catalog, FALSE,flatcorr);115 setMmos (catalog, FALSE,flatcorr);114 setMcal (catalog, flatcorr); 115 setMmos (catalog, flatcorr); 116 116 // setMgrp (catalog, FALSE, flatcorr); XXX think this through: this may not make sense for tgroups 117 117 MARKTIME("-- set Mrel, Mcal, Mmos, Mgrid : %f sec\n", dtime); … … 144 144 client_logger_message ("all hosts are done the loops\n"); 145 145 146 /* set Mcal & Mmos for bad images (for stack_and_warps, force images to be measured) */147 int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS;148 setMcal (catalog, onlyPoorImages, flatcorr);149 setMmos (catalog, onlyPoorImages, flatcorr);150 // setMgrp (catalog, onlyPoorImages, flatcorr); XXX see above151 146 MARKTIME("-- finalize Mcal values: %f sec\n", dtime); 152 147 -
trunk/Ohana/src/relphot/src/relphot_parallel_regions.c
r40291 r41556 1 1 # include "relphot.h" 2 int save_images_backup (FITS_DB *db);3 2 4 3 int relphot_parallel_regions (SkyTable *sky) { … … 101 100 return TRUE; 102 101 } 103 104 int save_images_backup (FITS_DB *db) {105 106 FITS_DB dbX;107 char filename[1024];108 109 INITTIME;110 111 gfits_db_init (&dbX);112 dbX.lockstate = LCK_XCLD;113 dbX.timeout = 60.0;114 dbX.mode = db->mode;115 dbX.format = db->format;116 117 snprintf (filename, 1024, "%s.bck", ImageCat);118 if (!gfits_db_lock (&dbX, filename)) {119 fprintf (stderr, "can't lock backup image image catalog\n");120 return (FALSE);121 }122 123 // copy Images.dat data (all or only the subset / vtable elements?) I think I need to dump124 // the entire Image table, but with the updates in place I think this says: re-work the125 // ftable/vtable usage in this program to be more sensible...126 gfits_copy_header (&db->header, &dbX.header);127 gfits_copy_matrix (&db->matrix, &dbX.matrix);128 gfits_copy_header (&db->theader, &dbX.theader);129 gfits_copy_ftable (&db->ftable, &dbX.ftable);130 131 dbX.ftable.header = &dbX.theader;132 133 dvo_image_save (&dbX, VERBOSE);134 dvo_image_unlock (&dbX);135 MARKTIME("-- save Image.dat.bck: %f sec\n", dtime);136 137 gfits_db_free (&dbX);138 return TRUE;139 }
Note:
See TracChangeset
for help on using the changeset viewer.
