Changeset 40477 for branches/czw_branch/20170908/Ohana/src/relphot
- Timestamp:
- Jun 27, 2018, 3:20:35 PM (8 years ago)
- Location:
- branches/czw_branch/20170908/Ohana
- Files:
-
- 28 edited
-
. (modified) (1 prop)
-
src/relphot/include/relphot.h (modified) (7 diffs)
-
src/relphot/src/BrightCatalog.c (modified) (14 diffs)
-
src/relphot/src/GridOps.c (modified) (4 diffs)
-
src/relphot/src/ImageMagIO.c (modified) (8 diffs)
-
src/relphot/src/ImageOps.c (modified) (23 diffs)
-
src/relphot/src/ImageSubset.c (modified) (9 diffs)
-
src/relphot/src/MosaicOps.c (modified) (30 diffs)
-
src/relphot/src/StarOps.c (modified) (15 diffs)
-
src/relphot/src/args.c (modified) (4 diffs)
-
src/relphot/src/bcatalog.c (modified) (1 diff)
-
src/relphot/src/launch_region_hosts.c (modified) (1 diff)
-
src/relphot/src/liststats.c (modified) (5 diffs)
-
src/relphot/src/load_images.c (modified) (1 diff)
-
src/relphot/src/plot_scatter.c (modified) (2 diffs)
-
src/relphot/src/plotstuff.c (modified) (1 diff)
-
src/relphot/src/reload_catalogs.c (modified) (2 diffs)
-
src/relphot/src/relphot_images.c (modified) (6 diffs)
-
src/relphot/src/relphot_objects.c (modified) (1 diff)
-
src/relphot/src/relphot_parallel_images.c (modified) (4 diffs)
-
src/relphot/src/relphot_parallel_regions.c (modified) (2 diffs)
-
src/relphot/src/relphot_synthphot_catalog.c (modified) (1 diff)
-
src/relphot/src/select_images.c (modified) (1 diff)
-
src/relphot/src/setMrelCatalog.c (modified) (19 diffs)
-
src/relphot/src/setMrelFinal.c (modified) (3 diffs)
-
src/relphot/src/share_image_mags.c (modified) (2 diffs)
-
src/relphot/src/share_mean_mags.c (modified) (2 diffs)
-
src/relphot/src/synthetic_mags.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20170908/Ohana
- Property svn:mergeinfo changed
-
branches/czw_branch/20170908/Ohana/src/relphot/include/relphot.h
r39926 r40477 77 77 unsigned int stop; 78 78 short photcode; 79 float Mcal; 79 float McalPSF; 80 float McalAPER; 80 81 float dMcal; 81 82 float dMsys; 82 unsigned short nFitPhotom; 83 short Xm; 83 float McalChiSq; 84 84 float secz; 85 85 float ubercalDist; 86 unsigned short nFitPhotom; 86 87 unsigned int flags; 87 88 char skipCal; // if TRUE, this mosaic is incomplete and should not be calibrated … … 201 202 202 203 typedef struct { 203 float Mcal; 204 float McalPSF; 205 float McalAPER; 204 206 float dMcal; 205 207 float dMagSys; 206 short Xm;208 float McalChiSq; 207 209 int nFitPhotom; 208 210 int flags; … … 220 222 221 223 typedef struct { 222 float Mcal; 224 float McalPSF; 225 float McalAPER; 223 226 float dMcal; 224 227 unsigned int imageID; … … 291 294 int PARALLEL_SERIAL; 292 295 char *MANUAL_UNIQUER; 296 297 int SKIP_PARALLEL_GROUPS; 293 298 294 299 int PARALLEL_REGIONS_MANUAL; … … 336 341 int SyntheticPhotometry; 337 342 343 int USE_MCAL_PSF_FOR_STACK_APER; 344 338 345 char *PhotcodeList; 339 346 … … 404 411 int findMosaics PROTO((Catalog *catalog, int Ncatalog, int doMosaicList)); 405 412 413 void clearImages (void); 414 void checkImages (char *name); 415 int dumpMags (FILE *fout, Catalog *catalog, int Ncatalog); 416 406 417 void makeMosaics (Image *image, off_t Nimage, int mergeMcal); 407 418 Mosaic *getMosaicForImage (off_t im); … … 422 433 off_t getImageEntry PROTO((off_t meas, int cat)); 423 434 424 float getMcal_alt PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, float Xccd, float Yccd)); 425 float getMcal PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog)); 435 float getMcal PROTO((off_t meas, int cat, dvoMagClassType class)); 426 436 float getMflat PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog)); 427 437 float getMgrid PROTO((off_t meas, int cat)); 428 438 float getMmos PROTO((off_t meas, int cat)); 429 float getMrel PROTO((Catalog *catalog, off_t meas, int cat ));439 float getMrel PROTO((Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source)); 430 440 short getUbercalDist PROTO((off_t meas, int cat)); 431 441 float getCenterOffset PROTO((off_t meas, int cat, Measure *measure, unsigned int *myID)); -
branches/czw_branch/20170908/Ohana/src/relphot/src/BrightCatalog.c
r39478 r40477 66 66 GET_COLUMN(D, "DEC", double); 67 67 GET_COLUMN(M, "MAG_SYS", float); 68 GET_COLUMN(Mcal, "MAG_CAL", float); 68 GET_COLUMN(Mkron, "MAG_KRON", float); 69 GET_COLUMN(McalPSF, "MCAL_PSF", float); 70 GET_COLUMN(McalAPER, "MCAL_APER", float); 69 71 GET_COLUMN(Mflat, "MAG_FLAT", float); 70 72 GET_COLUMN(dM, "MAG_ERR", float); … … 89 91 measure[i].D = D[i]; 90 92 measure[i].M = M[i]; 91 measure[i].Mcal = Mcal[i]; 93 measure[i].Mkron = Mkron[i]; 94 measure[i].McalPSF = McalPSF[i]; 95 measure[i].McalAPER = McalAPER[i]; 92 96 measure[i].Mflat = Mflat[i]; 93 97 measure[i].dM = dM[i]; … … 110 114 free (D ); 111 115 free (M ); 112 free (Mcal ); 116 free (Mkron ); 117 free (McalPSF ); 118 free (McalAPER); 113 119 free (Mflat ); 114 120 free (dM ); … … 186 192 // need to create and assign to flat-field correction 187 193 GET_COLUMN(M, "MAG", float); 194 GET_COLUMN(Mkron, "MAG_KRON", float); 188 195 GET_COLUMN(dM, "MAG_ERR", float); 189 196 GET_COLUMN(Mchisq, "MAG_CHI", float); … … 199 206 ALLOCATE (secfilt, SecFilt, Nrow); 200 207 for (i = 0; i < Nrow; i++) { 201 secfilt[i].M = M[i]; 202 secfilt[i].dM = dM[i]; 203 secfilt[i].Mchisq = Mchisq[i]; 204 secfilt[i].flags = flags[i]; 205 secfilt[i].Ncode = Ncode[i]; 206 secfilt[i].Nused = Nused[i]; 207 secfilt[i].Mmin = Mmin[i]; 208 secfilt[i].Mmax = Mmax[i]; 208 secfilt[i].MpsfChp = M[i]; 209 secfilt[i].MkronChp = Mkron[i]; 210 secfilt[i].dMpsfChp = dM[i]; 211 secfilt[i].Mchisq = Mchisq[i]; 212 secfilt[i].flags = flags[i]; 213 secfilt[i].Ncode = Ncode[i]; 214 secfilt[i].Nused = Nused[i]; 215 secfilt[i].Mmin = Mmin[i]; 216 secfilt[i].Mmax = Mmax[i]; 209 217 } 210 218 fprintf (stderr, "loaded data for %lld secfilt\n", (long long) Nrow); 211 219 212 220 free (M ); 221 free (Mkron ); 213 222 free (dM ); 214 223 free (Mchisq); … … 271 280 gfits_define_bintable_column (&theader, "D", "DEC", "dec", "degree", 1.0, 0.0); 272 281 gfits_define_bintable_column (&theader, "E", "MAG_SYS", "magnitude (sys)", NULL, 1.0, 0.0); 273 gfits_define_bintable_column (&theader, "E", "MAG_CAL", "magnitude (cal)", NULL, 1.0, 0.0); 282 gfits_define_bintable_column (&theader, "E", "MAG_KRON", "magnitude (sys,kron)", NULL, 1.0, 0.0); 283 gfits_define_bintable_column (&theader, "E", "MCAL_PSF", "magnitude (cal)", NULL, 1.0, 0.0); 284 gfits_define_bintable_column (&theader, "E", "MCAL_APER","magnitude (cal)", NULL, 1.0, 0.0); 274 285 gfits_define_bintable_column (&theader, "E", "MAG_FLAT", "magnitude (flat)", NULL, 1.0, 0.0); 275 286 gfits_define_bintable_column (&theader, "E", "MAG_ERR", "magnitude (err)", NULL, 1.0, 0.0); … … 293 304 double *D ; ALLOCATE (D , double, catalog->Nmeasure); 294 305 float *M ; ALLOCATE (M , float, catalog->Nmeasure); 295 float *Mcal ; ALLOCATE (Mcal , float, catalog->Nmeasure); 306 float *Mkron ; ALLOCATE (Mkron , float, catalog->Nmeasure); 307 float *McalPSF ; ALLOCATE (McalPSF , float, catalog->Nmeasure); 308 float *McalAPER ; ALLOCATE (McalAPER , float, catalog->Nmeasure); 296 309 float *Mflat ; ALLOCATE (Mflat , float, catalog->Nmeasure); 297 310 float *dM ; ALLOCATE (dM , float, catalog->Nmeasure); … … 311 324 MeasureTiny *measure = catalog->measure; 312 325 for (i = 0; i < catalog->Nmeasure; i++) { 313 R[i] = measure[i].R ;314 D[i] = measure[i].D ;326 R[i] = measure[i].R ; 327 D[i] = measure[i].D ; 315 328 M[i] = measure[i].M ; 316 Mcal[i] = measure[i].Mcal ; 329 Mkron[i] = measure[i].Mkron ; 330 McalPSF[i] = measure[i].McalPSF ; 331 McalAPER[i] = measure[i].McalAPER ; 317 332 Mflat[i] = measure[i].Mflat ; 318 333 dM[i] = measure[i].dM ; … … 334 349 gfits_set_bintable_column (&theader, &ftable, "DEC", D, catalog->Nmeasure); 335 350 gfits_set_bintable_column (&theader, &ftable, "MAG_SYS", M, catalog->Nmeasure); 336 gfits_set_bintable_column (&theader, &ftable, "MAG_CAL", Mcal, catalog->Nmeasure); 351 gfits_set_bintable_column (&theader, &ftable, "MAG_KRON", Mkron, catalog->Nmeasure); 352 gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF", McalPSF, catalog->Nmeasure); 353 gfits_set_bintable_column (&theader, &ftable, "MCAL_APER", McalAPER, catalog->Nmeasure); 337 354 gfits_set_bintable_column (&theader, &ftable, "MAG_FLAT", Mflat, catalog->Nmeasure); 338 355 gfits_set_bintable_column (&theader, &ftable, "MAG_ERR", dM, catalog->Nmeasure); … … 352 369 free (D ); 353 370 free (M ); 354 free (Mcal ); 371 free (Mkron ); 372 free (McalPSF ); 373 free (McalAPER); 355 374 free (Mflat ); 356 375 free (dM ); … … 436 455 gfits_create_table_header (&theader, "BINTABLE", "SECFILT"); 437 456 438 gfits_define_bintable_column (&theader, "E", "MAG", "", "arcsec", 1.0, 0.0); 439 gfits_define_bintable_column (&theader, "E", "MAG_ERR", "", "arcsec", 1.0, 0.0); 457 gfits_define_bintable_column (&theader, "E", "MAG", "", "mag", 1.0, 0.0); 458 gfits_define_bintable_column (&theader, "E", "MAG_KRON", "", "mag", 1.0, 0.0); 459 gfits_define_bintable_column (&theader, "E", "MAG_ERR", "", "mag", 1.0, 0.0); 440 460 gfits_define_bintable_column (&theader, "E", "MAG_CHI", "", NULL, 1.0, 0.0); 441 461 gfits_define_bintable_column (&theader, "J", "FLAGS", "", NULL, 1.0, 0.0); … … 454 474 // create intermediate storage arrays 455 475 float *M ; ALLOCATE (M , float, Nsec); 476 float *Mkron ; ALLOCATE (Mkron , float, Nsec); 456 477 float *dM ; ALLOCATE (dM , float, Nsec); 457 478 float *Mchisq ; ALLOCATE (Mchisq , float, Nsec); … … 465 486 SecFilt *secfilt = catalog->secfilt; 466 487 for (i = 0; i < Nsec; i++) { 467 M [i] = secfilt[i].M ; 468 dM [i] = secfilt[i].dM ; 469 Mchisq[i] = secfilt[i].Mchisq ; 470 flags [i] = secfilt[i].flags ; 471 Ncode [i] = secfilt[i].Ncode ; 472 Nused [i] = secfilt[i].Nused ; 473 Mmin [i] = secfilt[i].Mmin ; 474 Mmax [i] = secfilt[i].Mmax ; 488 M [i] = secfilt[i].MpsfChp ; 489 Mkron [i] = secfilt[i].MkronChp; 490 dM [i] = secfilt[i].dMpsfChp; 491 Mchisq[i] = secfilt[i].Mchisq ; 492 flags [i] = secfilt[i].flags ; 493 Ncode [i] = secfilt[i].Ncode ; 494 Nused [i] = secfilt[i].Nused ; 495 Mmin [i] = secfilt[i].Mmin ; 496 Mmax [i] = secfilt[i].Mmax ; 475 497 } 476 498 477 499 // add the columns to the output array 478 500 gfits_set_bintable_column (&theader, &ftable, "MAG", M , Nsec); 501 gfits_set_bintable_column (&theader, &ftable, "MAG_KRON", Mkron , Nsec); 479 502 gfits_set_bintable_column (&theader, &ftable, "MAG_ERR", dM , Nsec); 480 503 gfits_set_bintable_column (&theader, &ftable, "MAG_CHI", Mchisq, Nsec); … … 486 509 487 510 free (M ); 511 free (Mkron ); 488 512 free (dM ); 489 513 free (Mchisq ); -
branches/czw_branch/20170908/Ohana/src/relphot/src/GridOps.c
r39632 r40477 401 401 402 402 // skip images marked as BAD 403 Mcal = getMcal (m, c, flatcorr, catalog);403 Mcal = getMcal (m, c, MAG_CLASS_PSF); 404 404 if (isnan(Mcal)) { 405 405 Ncal ++; … … 558 558 continue; 559 559 } 560 Mcal = getMcal (m, c, flatcorr, catalog);560 Mcal = getMcal (m, c, MAG_CLASS_PSF); 561 561 if (isnan(Mcal)) { 562 562 Ncal ++; … … 568 568 continue; 569 569 } 570 Mrel = getMrel (catalog, m, c );570 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 571 571 if (isnan(Mrel)) { 572 572 Nrel ++; … … 645 645 continue; 646 646 } 647 Mcal = getMcal (m, c, flatcorr, catalog);647 Mcal = getMcal (m, c, MAG_CLASS_PSF); 648 648 if (isnan(Mcal)) continue; 649 649 Mmos = getMmos (m, c); 650 650 if (isnan(Mmos)) continue; 651 Mrel = getMrel (catalog, m, c );651 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 652 652 if (isnan(Mrel)) continue; 653 653 -
branches/czw_branch/20170908/Ohana/src/relphot/src/ImageMagIO.c
r37037 r40477 58 58 char type[16]; 59 59 60 GET_COLUMN (Mcal, "MCAL", float); 60 GET_COLUMN (McalPSF, "MCAL_PSF", float); 61 GET_COLUMN (McalAPER, "MCAL_APER", float); 61 62 GET_COLUMN (dMcal, "MCAL_ERR", float); 62 63 GET_COLUMN (dMagSys, "MCAL_SYSERR", float); 63 GET_COLUMN ( nFitPhotom, "NFIT", int);64 GET_COLUMN ( flags, "FLAGS",int);65 GET_COLUMN ( ubercalDist, "UDIST",int);66 GET_COLUMN ( imageID, "ID",int);67 GET_COLUMN ( Xm, "CHISQ", short);64 GET_COLUMN (McalChiSq, "MCAL_CHISQ", float); 65 GET_COLUMN (nFitPhotom, "NFIT", int); 66 GET_COLUMN (flags, "FLAGS", int); 67 GET_COLUMN (ubercalDist, "UDIST", int); 68 GET_COLUMN (imageID, "ID", int); 68 69 69 70 // free the memory associated with the FITS files … … 75 76 ALLOCATE (image_mags, ImageMag, Nrow); 76 77 for (i = 0; i < Nrow; i++) { 77 image_mags[i].Mcal = Mcal [i]; 78 image_mags[i].McalPSF = McalPSF [i]; 79 image_mags[i].McalAPER = McalAPER [i]; 78 80 image_mags[i].dMcal = dMcal [i]; 79 81 image_mags[i].dMagSys = dMagSys [i]; 80 image_mags[i]. Xm = Xm[i];82 image_mags[i].McalChiSq = McalChiSq [i]; 81 83 image_mags[i].nFitPhotom = nFitPhotom [i]; 82 84 image_mags[i].flags = flags [i]; … … 86 88 fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow); 87 89 88 free (Mcal ); 90 free (McalPSF ); 91 free (McalAPER ); 89 92 free (dMcal ); 90 93 free (dMagSys ); 91 free ( Xm);94 free (McalChiSq ); 92 95 free (nFitPhotom ); 93 96 free (flags ); … … 121 124 gfits_create_table_header (&theader, "BINTABLE", "IMAGE_MAGS"); 122 125 123 gfits_define_bintable_column (&theader, "E", "MCAL", "cal offset", "magnitudes", 1.0, 0.0); 126 gfits_define_bintable_column (&theader, "E", "MCAL_PSF", "PSF cal offset", "magnitudes", 1.0, 0.0); 127 gfits_define_bintable_column (&theader, "E", "MCAL_APER", "APER cal offset", "magnitudes", 1.0, 0.0); 124 128 gfits_define_bintable_column (&theader, "E", "MCAL_ERR", "cal error", "magnitudes", 1.0, 0.0); 125 129 gfits_define_bintable_column (&theader, "E", "MCAL_SYSERR", "systematic error", "magnitudes", 1.0, 0.0); 130 gfits_define_bintable_column (&theader, "E", "MCAL_CHISQ", "cal chisq", "unitless", 1.0, 0.0); 126 131 gfits_define_bintable_column (&theader, "J", "NFIT", "number of fitted stars", "unitless", 1.0, 0.0); 127 132 gfits_define_bintable_column (&theader, "J", "FLAGS", "analysis flags", "unitless", 1.0, 0.0); 128 133 gfits_define_bintable_column (&theader, "J", "UDIST", "distance to ubercal images", "images", 1.0, 0.0); 129 134 gfits_define_bintable_column (&theader, "J", "ID", "image ID", "unitless", 1.0, 0.0); 130 gfits_define_bintable_column (&theader, "I", "CHISQ", "cal chisq", "unitless", 1.0, FT_BZERO_INT16);131 135 132 136 // generate the output array that carries the data 133 137 gfits_create_table (&theader, &ftable); 134 138 135 float *Mcal ; 139 float *McalPSF ; 140 float *McalAPER ; 136 141 float *dMcal ; 137 142 float *dMagSys ; 138 float * Xm;143 float *McalChiSq ; 139 144 int *nFitPhotom ; 140 145 int *flags ; … … 143 148 144 149 // create intermediate storage arrays 145 ALLOCATE (Mcal , float, Nimage_mags); 150 ALLOCATE (McalPSF , float, Nimage_mags); 151 ALLOCATE (McalAPER , float, Nimage_mags); 146 152 ALLOCATE (dMcal , float, Nimage_mags); 147 153 ALLOCATE (dMagSys , float, Nimage_mags); 148 ALLOCATE ( Xm, float, Nimage_mags);154 ALLOCATE (McalChiSq , float, Nimage_mags); 149 155 ALLOCATE (nFitPhotom , int, Nimage_mags); 150 156 ALLOCATE (flags , int, Nimage_mags); … … 154 160 // assign the storage arrays 155 161 for (i = 0; i < Nimage_mags; i++) { 156 Mcal [i] = image_mags[i].Mcal ; 162 McalPSF [i] = image_mags[i].McalPSF ; 163 McalAPER [i] = image_mags[i].McalAPER ; 157 164 dMcal [i] = image_mags[i].dMcal ; 158 165 dMagSys [i] = image_mags[i].dMagSys ; 159 Xm [i] = image_mags[i].Xm;166 McalChiSq [i] = image_mags[i].McalChiSq ; 160 167 nFitPhotom [i] = image_mags[i].nFitPhotom ; 161 168 flags [i] = image_mags[i].flags ; … … 165 172 166 173 // add the columns to the output array 167 gfits_set_bintable_column (&theader, &ftable, "MCAL", Mcal , Nimage_mags); 174 gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF", McalPSF , Nimage_mags); 175 gfits_set_bintable_column (&theader, &ftable, "MCAL_APER", McalAPER , Nimage_mags); 168 176 gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR", dMcal , Nimage_mags); 169 177 gfits_set_bintable_column (&theader, &ftable, "MCAL_SYSERR", dMagSys , Nimage_mags); 170 gfits_set_bintable_column (&theader, &ftable, " CHISQ", Xm, Nimage_mags);178 gfits_set_bintable_column (&theader, &ftable, "MCAL_CHISQ", McalChiSq , Nimage_mags); 171 179 gfits_set_bintable_column (&theader, &ftable, "NFIT", nFitPhotom , Nimage_mags); 172 180 gfits_set_bintable_column (&theader, &ftable, "FLAGS", flags , Nimage_mags); … … 174 182 gfits_set_bintable_column (&theader, &ftable, "ID", imageID , Nimage_mags); 175 183 176 free (Mcal ); 184 free (McalPSF ); 185 free (McalAPER ); 177 186 free (dMcal ); 178 187 free (dMagSys ); 179 free ( Xm);188 free (McalChiSq ); 180 189 free (nFitPhotom ); 181 190 free (flags ); -
branches/czw_branch/20170908/Ohana/src/relphot/src/ImageOps.c
r39643 r40477 143 143 image[i].photom_map_id = input[i].photom_map_id; 144 144 image[i].flags = input[i].flags ; 145 image[i].Mcal = input[i].Mcal ; 145 image[i].McalPSF = input[i].McalPSF ; 146 image[i].McalAPER = input[i].McalAPER ; 146 147 image[i].dMcal = input[i].dMcal ; 147 148 image[i].tzero = input[i].tzero ; … … 179 180 subset[i].photom_map_id = image[i].photom_map_id; 180 181 subset[i].flags = image[i].flags ; 181 subset[i].Mcal = image[i].Mcal ; 182 subset[i].McalPSF = image[i].McalPSF ; 183 subset[i].McalAPER = image[i].McalAPER ; 182 184 subset[i].dMcal = image[i].dMcal ; 183 185 subset[i].tzero = image[i].tzero ; … … 430 432 } 431 433 432 // returns image.Mcal 434 // returns image.McalPSF or image.McalAPER 433 435 // NOTE: static flat-field component is included in measure.Mflat 434 float getMcal (off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog) { 435 OHANA_UNUSED_PARAM(flatcorr); 436 OHANA_UNUSED_PARAM(catalog); 437 438 off_t i; 439 float value; 436 float getMcal (off_t meas, int cat, dvoMagClassType class) { 437 438 off_t i; 440 439 441 440 i = MeasureToImage[cat][meas]; 442 if (i == -1) return (NAN); 443 444 if (image[i].flags & IMAGE_BAD) return (NAN); 445 value = image[i].Mcal; 446 447 // to do this, I need to pass in the catalog and flatcorr pointers 448 // int flat_id = image[i].photom_map_id; 449 // float offset = 0.0; 450 // if (flat_id) { 451 // offset = FlatCorrectionOffset (flatcorr, flat_id, catalog[cat].measureT[meas].Xccd, catalog[cat].measureT[meas].Yccd); 452 // } 453 // value -= offset; 454 455 return (value); 456 } 457 458 // returns image.Mcal - ff(x,y) 459 // NOTE: static flat-field component is included in measure.Mflat 460 float getMcal_alt (off_t meas, int cat, FlatCorrectionTable *flatcorr, float Xccd, float Yccd) { 461 OHANA_UNUSED_PARAM(flatcorr); 462 OHANA_UNUSED_PARAM(Xccd); 463 OHANA_UNUSED_PARAM(Yccd); 464 465 off_t i; 466 float value; 467 468 i = MeasureToImage[cat][meas]; 469 if (i == -1) return (NAN); 470 471 if (image[i].flags & IMAGE_BAD) return (NAN); 472 value = image[i].Mcal; 473 474 // to do this, I need to pass in the catalog and flatcorr pointers 475 // int flat_id = image[i].photom_map_id; 476 // float offset = 0.0; 477 // if (flat_id) { 478 // offset = FlatCorrectionOffset (flatcorr, flat_id, Xccd, Yccd); 479 // } 480 // value -= offset; 481 482 return (value); 483 } 484 485 // returns image.Mcal - ff(x,y) 441 if (i == -1) return NAN; 442 443 if (image[i].flags & IMAGE_BAD) return NAN; 444 445 switch (class) { 446 case MAG_CLASS_PSF: 447 return image[i].McalPSF; 448 case MAG_CLASS_APER: 449 case MAG_CLASS_KRON: 450 return image[i].McalAPER; 451 default: 452 return NAN; 453 } 454 return NAN; // should not be able to reach here 455 } 456 486 457 short getUbercalDist (off_t meas, int cat) { 487 458 … … 499 470 } 500 471 501 // returns image.Mcal - ff(x,y)502 472 float getCenterOffset (off_t meas, int cat, Measure *measure, unsigned int *myID) { 503 473 … … 519 489 } 520 490 521 // returns image.Mcal - ff(x,y)522 491 int MatchImageName (off_t meas, int cat, char *name) { 523 492 … … 542 511 } 543 512 544 // returns image.Mcal - ff(x,y)545 513 int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID) { 546 514 … … 563 531 } 564 532 565 // returns image.Mcal - ff(x,y)566 533 int FindImageSkycellID (off_t meas, int cat, int *myTessID, int *myProjectionID, int *mySkycellID) { 567 534 … … 618 585 void setMcal (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) { 619 586 620 off_t i, j, m, c, n , Nmax;587 off_t i, j, m, c, n; 621 588 int mark, bad, Nfew, Nbad, Nmos, Nrel, Ngrid, Nsys; 622 float Msys, Mrel, Mmos, Mgrid, Mflat;623 // double *list, *dlist, *Mlist, *dMlist;624 589 625 590 StatType stats; … … 638 603 } 639 604 640 Nmax = 0;605 off_t Nmax = 0; 641 606 for (i = 0; i < Nimage; i++) { 642 607 Nmax = MAX (Nmax, N_onImage[i]); 643 608 } 644 StatDataSet *refStars = StatDataSetAlloc (1, Nmax); 609 610 StatDataSet *kronStars = StatDataSetAlloc (1, Nmax); 611 StatDataSet *psfStars = StatDataSetAlloc (1, Nmax); 645 612 StatDataSet *brightStars = StatDataSetAlloc (1, Nmax); 646 613 … … 676 643 int minUbercalDist = 1000; 677 644 678 off_t Nref = 0; // total number of reference stars on the image 679 int Nbright = 0; // number of stars to measure the bright-end scatter 645 off_t Nref = 0; // number of stars used to measure McalPSF 646 int Nkron = 0; // number of stars to measure McalAPER 647 int Nbright = 0; // number of stars to measure the bright-end scatter 680 648 681 649 if (N_onImage[i] == 0) { … … 693 661 continue; 694 662 } 695 Mmos = getMmos (m, c);663 float Mmos = getMmos (m, c); 696 664 if (isnan(Mmos)) { 697 665 Nmos ++; 698 666 continue; 699 667 } 700 Mgrid = getMgrid (m, c);668 float Mgrid = getMgrid (m, c); 701 669 if (isnan(Mgrid)) { 702 670 Ngrid++; 703 671 continue; 704 672 } 705 Mrel = getMrel (catalog, m, c); 706 if (isnan(Mrel)) { 673 674 // Mrel* is the average magnitude for this star. For PS1 stacks, we have too much 675 // PSF variability. We need to calibrate the PSF magnitudes separately from the 676 // Aperture-like magnitues. (We have an option to use the kron magnitudes or the 677 // other apertures here). I basically need to do this analysis separately for each 678 // magnitude type 679 680 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 681 if (isnan(MrelPSF)) { 707 682 Nrel ++; 708 683 continue; … … 714 689 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat) 715 690 716 Mflat = getMflat (m, c, flatcorr, catalog);691 float Mflat = getMflat (m, c, flatcorr, catalog); 717 692 718 693 n = catalog[c].measureT[m].averef; 719 Msys= PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);720 if (isnan(Msys )) {694 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 695 if (isnan(MsysPSF)) { 721 696 Nsys++; 722 697 continue; … … 731 706 732 707 skip: 733 refStars->flxlist[Nref] = Msys - Mrel- Mmos - Mgrid + Mflat;734 refStars->errlist[Nref] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);735 refStars->wgtlist[Nref] = 1;736 refStars->msklist[Nref] = 0;737 if (fabs( refStars->flxlist[Nref]) > 0.03) {708 psfStars->flxlist[Nref] = MsysPSF - MrelPSF - Mmos - Mgrid + Mflat; 709 psfStars->errlist[Nref] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 710 psfStars->wgtlist[Nref] = 1; 711 psfStars->msklist[Nref] = 0; 712 if (fabs(psfStars->flxlist[Nref]) > 0.03) { 738 713 // fprintf (stderr, "deviant\n"); 739 714 } 740 715 716 float MrelKron = getMrel (catalog, m, c, MAG_CLASS_KRON, MAG_SRC_CHP); 717 float MsysKron = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_KRON); 718 719 if (isfinite(MrelKron) && isfinite(MsysKron)) { 720 kronStars->flxlist[Nkron] = MsysKron - MrelKron - Mmos - Mgrid + Mflat; 721 kronStars->errlist[Nkron] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 722 kronStars->wgtlist[Nkron] = 1; 723 kronStars->msklist[Nkron] = 0; 724 Nkron ++; 725 } 726 741 727 if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) { 742 fprintf (stderr, "%1d, %3d : %3d, %3d : %10.6f %10.6f : %6.3f %6.3f %6.3f %6.3f %6.3f : %6.3f\n", (int) i, (int) j, (int) c, (int) m, catalog[c].averageT[n].R, catalog[c].averageT[n].D, Msys , Mrel, Mmos, Mgrid, Mflat, refStars->flxlist[Nref]);728 fprintf (stderr, "%1d, %3d : %3d, %3d : %10.6f %10.6f : %6.3f %6.3f %6.3f %6.3f %6.3f : %6.3f\n", (int) i, (int) j, (int) c, (int) m, catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysKron, MrelKron, Mmos, Mgrid, Mflat, kronStars->flxlist[Nref]); 743 729 } 744 730 745 731 if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) { 746 brightStars->flxlist[Nbright] = refStars->flxlist[Nref];747 brightStars->errlist[Nbright] = refStars->errlist[Nref];732 brightStars->flxlist[Nbright] = psfStars->flxlist[Nref]; 733 brightStars->errlist[Nbright] = psfStars->errlist[Nref]; 748 734 brightStars->wgtlist[Nbright] = 1; 749 735 brightStars->msklist[Nbright] = 0; … … 770 756 // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not) 771 757 # if (BASIC_STATS) 772 liststats ( refStars->flxlist, refStars->errlist, NULL, Nref, &stats);758 liststats (psfStars->flxlist, psfStars->errlist, NULL, Nref, &stats); 773 759 # else 774 liststats_irls ( refStars, Nref, &stats);760 liststats_irls (psfStars, Nref, &stats); 775 761 # endif 776 image[i].Mcal = stats.mean;762 image[i].McalPSF = stats.mean; 777 763 image[i].dMcal = stats.error; 778 764 image[i].nFitPhotom = Nref; 779 image[i]. Xm = 100.0*log10(stats.chisq);765 image[i].McalChiSq = stats.chisq; 780 766 Ncalibrated ++; 767 768 // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not) 769 # if (BASIC_STATS) 770 liststats (kronStars->flxlist, kronStars->errlist, NULL, Nkron, &stats); 771 # else 772 liststats_irls (kronStars, Nref, &stats); 773 # endif 774 image[i].McalAPER = stats.mean; 781 775 782 776 if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) { 783 777 for (j = 0; j < Nref; j++) { 784 fprintf (stderr, "%1d, %8d : %6.3f %6.3f %6.3f %d\n", (int) i, (int) image[i].imageID, refStars->flxlist[j], refStars->errlist[j], refStars->wgtlist[j], refStars->msklist[j]);778 fprintf (stderr, "%1d, %8d : %6.3f %6.3f %6.3f %d\n", (int) i, (int) image[i].imageID, kronStars->flxlist[j], kronStars->errlist[j], kronStars->wgtlist[j], kronStars->msklist[j]); 785 779 } 786 780 } 787 781 788 782 if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) { 789 fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].Mcal , image[i].dMcal);783 fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].McalAPER, image[i].dMcal); 790 784 } 791 785 792 786 if (!mark && VERBOSE_IMAGE) { 793 fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].Mcal , image[i].dMcal);787 fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].McalAPER, image[i].dMcal); 794 788 } 795 789 796 790 if (PLOTSTUFF) { 797 fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].Mcal , image[i].dMcal);798 plot_setMcal ( refStars->flxlist, Nref, &stats, CLOUD_TOLERANCE);791 fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].McalAPER, image[i].dMcal); 792 plot_setMcal (psfStars->flxlist, Nref, &stats, CLOUD_TOLERANCE); 799 793 } 800 794 … … 803 797 image[i].dMagSys = stats.sigma; 804 798 805 if (image[i].Mcal < -CLOUD_TOLERANCE) {806 image[i].Mcal = 0.0;799 if (image[i].McalPSF < -CLOUD_TOLERANCE) { 800 image[i].McalPSF = 0.0; 807 801 } 808 802 … … 813 807 814 808 StatDataSetFree (brightStars, 1); 815 StatDataSetFree (refStars, 1); 809 StatDataSetFree (kronStars, 1); 810 StatDataSetFree (psfStars, 1); 816 811 817 812 fprintf (stderr, "%d images calibrated\n", Ncalibrated); … … 848 843 if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue; 849 844 850 mlist[N] = image[i].Mcal ;845 mlist[N] = image[i].McalPSF; 851 846 slist[N] = image[i].dMcal; 852 847 dlist[N] = 1; … … 873 868 mark = FALSE; 874 869 image[i].flags &= ~ID_IMAGE_PHOTOM_POOR; 875 mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].Mcal - MedOffset) > MaxOffset);870 mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].McalPSF - MedOffset) > MaxOffset); 876 871 if (mark) { 877 872 Nmark ++; … … 961 956 if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue; 962 957 963 Mlist[Nplot] = image[i].Mcal ;958 Mlist[Nplot] = image[i].McalPSF; 964 959 dlist[Nplot] = image[i].dMcal; 965 960 xlist[Nplot] = image[i].secz; 966 961 minAirmass = MIN (image[i].secz, minAirmass); 967 962 maxAirmass = MAX (image[i].secz, maxAirmass); 968 minMcal = MIN (image[i].Mcal , minMcal);969 maxMcal = MAX (image[i].Mcal , maxMcal);963 minMcal = MIN (image[i].McalPSF, minMcal); 964 maxMcal = MAX (image[i].McalPSF, maxMcal); 970 965 mindMcal = MIN (image[i].dMcal, mindMcal); 971 966 maxdMcal = MAX (image[i].dMcal, maxdMcal); … … 1051 1046 c = ImageToCatalog[i][j]; 1052 1047 1053 Mcal = getMcal (m, c, flatcorr, catalog);1048 Mcal = getMcal (m, c, MAG_CLASS_PSF); 1054 1049 if (isnan(Mcal)) continue; 1055 1050 Mmos = getMmos (m, c); … … 1092 1087 if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue; 1093 1088 1094 list[n] = pow (10.0, 0.01*image[i].Xm);1089 list[n] = image[i].McalChiSq; 1095 1090 dlist[n] = 1; 1096 1091 n++; … … 1125 1120 if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue; 1126 1121 1127 list[n] = image[i].Mcal ;1122 list[n] = image[i].McalPSF; 1128 1123 dlist[n] = 1; 1129 1124 n++; … … 1170 1165 return (stats); 1171 1166 } 1167 1168 void clearImages (void) { 1169 image = NULL; 1170 } 1171 1172 void checkImages (char *name) { 1173 1174 off_t i; 1175 fprintf (stderr, "--- %s ---\n", name); 1176 1177 OhanaMemblock *ref = (OhanaMemblock *) image - 1; 1178 fprintf (stderr, "file: %s\n", ref->file); 1179 1180 fprintf (stderr, "0x%08llx \n", (unsigned long long) image); 1181 1182 for (i = 0; i < Nimage; i++) { 1183 fprintf (stderr, "%s : 0x%08x : %6.3f %6.3f\n", image[i].name, image[i].flags, image[i].McalPSF, image[i].McalAPER); 1184 } 1185 } -
branches/czw_branch/20170908/Ohana/src/relphot/src/ImageSubset.c
r39478 r40477 63 63 char type[16]; 64 64 65 GET_COLUMN (Mcal, "MCAL", float); 65 GET_COLUMN (McalPSF, "MCAL_PSF", float); 66 GET_COLUMN (McalAPER, "MCAL_APER", float); 66 67 GET_COLUMN (dMcal, "MCAL_ERR", float); 67 68 GET_COLUMN (imageID, "IMAGE_ID", int); … … 79 80 ALLOCATE (image, ImageSubset, Nrow); 80 81 for (i = 0; i < Nrow; i++) { 81 image[i].Mcal = Mcal[i]; 82 image[i].McalPSF = McalPSF[i]; 83 image[i].McalAPER = McalAPER[i]; 82 84 image[i].dMcal = dMcal[i]; 83 85 image[i].imageID = imageID[i]; … … 93 95 fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow); 94 96 95 free (Mcal); 97 free (McalPSF); 98 free (McalAPER); 96 99 free (dMcal); 97 100 free (imageID); … … 136 139 gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET"); 137 140 138 gfits_define_bintable_column (&theader, "E", "MCAL", "zero point offset", "magnitudes", 1.0, 0.0); 141 gfits_define_bintable_column (&theader, "E", "MCAL_PSF", "zero point offset", "magnitudes", 1.0, 0.0); 142 gfits_define_bintable_column (&theader, "E", "MCAL_APER", "zero point offset", "magnitudes", 1.0, 0.0); 139 143 gfits_define_bintable_column (&theader, "E", "MCAL_ERR", "zero point error", "magnitudes", 1.0, 0.0); 140 144 gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", NULL, 1.0, FT_BZERO_INT32); … … 151 155 gfits_create_table (&theader, &ftable); 152 156 153 float *Mcal , *dMcal;157 float *McalPSF, *McalAPER, *dMcal; 154 158 unsigned int *imageID, *map, *flags, *tzero; 155 159 int *tessID, *projID, *skycellID; … … 158 162 159 163 // create intermediate storage arrays 160 ALLOCATE (Mcal, float, Nimage); 164 ALLOCATE (McalPSF, float, Nimage); 165 ALLOCATE (McalAPER, float, Nimage); 161 166 ALLOCATE (dMcal, float, Nimage); 162 167 ALLOCATE (imageID, unsigned int, Nimage); … … 172 177 // assign the storage arrays 173 178 for (i = 0; i < Nimage; i++) { 174 Mcal[i] = image[i].Mcal; 179 McalPSF[i] = image[i].McalPSF; 180 McalAPER[i] = image[i].McalAPER; 175 181 dMcal[i] = image[i].dMcal; 176 182 imageID[i] = image[i].imageID; … … 186 192 187 193 // add the columns to the output array 188 gfits_set_bintable_column (&theader, &ftable, "MCAL", Mcal, Nimage); 194 gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF", McalPSF, Nimage); 195 gfits_set_bintable_column (&theader, &ftable, "MCAL_APER", McalAPER, Nimage); 189 196 gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR", dMcal, Nimage); 190 197 gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID", imageID, Nimage); … … 198 205 gfits_set_bintable_column (&theader, &ftable, "UBERCAL_DIST", ucdist, Nimage); 199 206 200 free (Mcal); 207 free (McalPSF); 208 free (McalAPER); 201 209 free (dMcal); 202 210 free (imageID); -
branches/czw_branch/20170908/Ohana/src/relphot/src/MosaicOps.c
r39632 r40477 111 111 112 112 /* a new mosaic, define ranges -- preserve the original values incase this image is not used */ 113 mosaic[Nmosaic].start = start; 114 mosaic[Nmosaic].stop = stop; 115 mosaic[Nmosaic].Mcal = 0.0; // note : mosaic stores only offsets relative to the original image values 116 mosaic[Nmosaic].dMcal = 0.0; // note : at the end, mosaic.Mcal is added back to the input images 117 mosaic[Nmosaic].dMsys = 0.0; 118 mosaic[Nmosaic].Xm = 0.0; 119 mosaic[Nmosaic].flags = image[i].flags; 120 mosaic[Nmosaic].secz = image[i].secz; 121 mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode); 113 mosaic[Nmosaic].start = start; 114 mosaic[Nmosaic].stop = stop; 115 mosaic[Nmosaic].McalPSF = 0.0; // note : at the end, mosaic.Mcal is added back to the input images 116 mosaic[Nmosaic].McalAPER = 0.0; // note : mosaic stores only offsets relative to the original image values 117 mosaic[Nmosaic].dMcal = 0.0; // note : at the end, mosaic.Mcal is added back to the input images 118 mosaic[Nmosaic].dMsys = 0.0; 119 mosaic[Nmosaic].McalChiSq = 0.0;// NAN or 0.0? 120 mosaic[Nmosaic].flags = image[i].flags; 121 mosaic[Nmosaic].secz = image[i].secz; 122 mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode); 122 123 123 124 // XXX do we need to do something about flag consistency across a mosaic? … … 208 209 for (i = 0; i < Nmosaic; i++) { 209 210 /* a new mosaic, define ranges */ 210 mosaic[i].start = startTimesMosaic[i]; 211 mosaic[i].stop = 0; 212 mosaic[i].Mcal = 0.0; 213 mosaic[i].dMcal = 0.0; 214 mosaic[i].dMsys = 0.0; 215 mosaic[i].Xm = 0.0; 216 mosaic[i].flags = 0; 217 mosaic[i].secz = NAN; 218 mosaic[i].photcode = 0; 219 mosaic[i].skipCal = FALSE; 211 mosaic[i].start = startTimesMosaic[i]; 212 mosaic[i].stop = 0; 213 mosaic[i].McalPSF = 0.0; // note : at the end, mosaic.Mcal is added back to the input images 214 mosaic[i].McalAPER = 0.0; // note : mosaic stores only offsets relative to the original image values 215 mosaic[i].dMcal = 0.0; // note : at the end, mosaic.Mcal is added back to the input images 216 mosaic[i].dMsys = 0.0; 217 mosaic[i].McalChiSq = 0.0;// NAN or 0.0? 218 mosaic[i].flags = 0; 219 mosaic[i].secz = NAN; 220 mosaic[i].photcode = 0; 221 mosaic[i].skipCal = FALSE; 220 222 221 223 memset (&mosaic[i].coords, 0, sizeof(Coords)); … … 294 296 abort(); 295 297 } 296 mosaic[j].stop = stop; 297 mosaic[j].Mcal = 0.0; 298 mosaic[j].dMcal = 0.0; 299 mosaic[j].Xm = 0.0; 300 mosaic[j].dMsys = subset[i].flags; 301 mosaic[j].flags = subset[i].flags; 302 mosaic[j].secz = subset[i].secz; 303 mosaic[j].photcode = GetPhotcodeEquivCodebyCode (subset[i].photcode); 298 mosaic[j].stop = stop; 299 300 mosaic[j].McalPSF = 0.0; 301 mosaic[j].McalAPER = 0.0; 302 mosaic[j].dMcal = 0.0; 303 mosaic[j].McalChiSq = 0.0; 304 305 mosaic[j].dMsys = subset[i].flags; 306 mosaic[j].flags = subset[i].flags; 307 mosaic[j].secz = subset[i].secz; 308 mosaic[j].photcode = GetPhotcodeEquivCodebyCode (subset[i].photcode); 304 309 } 305 310 … … 377 382 // init the mosaic array values 378 383 for (i = 0; i < Nmosaic; i++) { 379 mosaic[i].start = startTimesMosaic[i]; 380 mosaic[i].stop = 0; 381 mosaic[i].Mcal = 0.0; 382 mosaic[i].dMcal = 0.0; 383 mosaic[i].dMsys = 0.0; 384 mosaic[i].Xm = 0.0; 385 mosaic[i].flags = 0; 386 mosaic[i].secz = NAN; 387 mosaic[i].photcode = 0; 388 mosaic[i].skipCal = FALSE; 384 mosaic[i].start = startTimesMosaic[i]; 385 mosaic[i].stop = 0; 386 mosaic[i].McalPSF = 0.0; // note : at the end, mosaic.Mcal is added back to the input images 387 mosaic[i].McalAPER = 0.0; // note : mosaic stores only offsets relative to the original image values 388 mosaic[i].dMcal = 0.0; // note : at the end, mosaic.Mcal is added back to the input images 389 mosaic[i].dMsys = 0.0; 390 mosaic[i].McalChiSq = 0.0;// NAN or 0.0? 391 mosaic[i].flags = 0; 392 mosaic[i].secz = NAN; 393 mosaic[i].photcode = 0; 394 mosaic[i].skipCal = FALSE; 389 395 390 396 memset (&mosaic[i].coords, 0, sizeof(Coords)); … … 438 444 } 439 445 mosaic[j].stop = stop; 440 mosaic[j].Mcal = 0.0; 441 mosaic[j].dMcal = 0.0; 442 mosaic[j].Xm = 0.0; 443 mosaic[j].dMsys = image[i].flags; 444 mosaic[j].flags = image[i].flags; 445 mosaic[j].secz = image[i].secz; 446 mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode); 446 mosaic[j].McalPSF = 0.0; 447 mosaic[j].McalAPER = 0.0; 448 mosaic[j].dMcal = 0.0; 449 mosaic[j].McalChiSq = 0.0; 450 mosaic[j].dMsys = image[i].flags; 451 mosaic[j].flags = image[i].flags; 452 mosaic[j].secz = image[i].secz; 453 mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode); 447 454 } 448 455 MARKTIME("assign images to mosaic: %f sec\n", dtime); … … 594 601 mosaic[i].coords.cdelt2 = 1.0 / 3600.0; 595 602 596 mosaic[i].Mcal = 0.0; 597 mosaic[i].dMcal = 0.0; 598 mosaic[i].Xm = 0.0; 603 mosaic[i].McalPSF = 0.0; 604 mosaic[i].McalAPER = 0.0; 605 mosaic[i].dMcal = 0.0; 606 mosaic[i].dMsys = 0.0; 607 mosaic[i].McalChiSq = 0.0; 599 608 } 600 609 return; … … 612 621 double dS, dX, dY; 613 622 double R, D, Rmin, Rmax, Dmin, Dmax; 614 double Mcal , dMcal, Xm;623 double McalPSF, McalAPER, dMcal, McalChiSq; 615 624 616 625 fprintf (stderr, "*** moving Mcal from image.Mcal to mosaic.Mcal ***\n"); … … 621 630 Dmax = Rmax = -360.0; 622 631 dS = 0.0; 623 Mcal = dMcal = Xm= 0;632 McalPSF = McalAPER = dMcal = McalChiSq = 0; 624 633 for (j = 0; j < MosaicN_Image[i]; j++) { 625 634 m = MosaicToImage[i][j]; … … 678 687 // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value 679 688 680 Mcal += image[m].Mcal; 681 dMcal += image[m].dMcal; 682 Xm += image[m].Xm; 683 684 image[m].Mcal = 0.0; 685 image[m].dMcal = NAN; 686 image[m].Xm = NAN_S_SHORT; 689 McalPSF += image[m].McalPSF; 690 McalAPER += image[m].McalAPER; 691 dMcal += image[m].dMcal; 692 McalChiSq += image[m].McalChiSq; 693 694 image[m].McalPSF = 0.0; 695 image[m].McalAPER = 0.0; 696 image[m].dMcal = NAN; 697 image[m].McalChiSq = NAN; 687 698 } 688 699 dS /= MosaicN_Image[i]; … … 696 707 RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords); 697 708 698 mosaic[i].Mcal = Mcal / MosaicN_Image[i]; 699 mosaic[i].dMcal = dMcal / MosaicN_Image[i]; 700 mosaic[i].Xm = Xm / MosaicN_Image[i]; 709 mosaic[i].McalPSF = McalPSF / MosaicN_Image[i]; 710 mosaic[i].McalAPER = McalAPER / MosaicN_Image[i]; 711 mosaic[i].dMcal = dMcal / MosaicN_Image[i]; 712 mosaic[i].McalChiSq = McalChiSq / MosaicN_Image[i]; 701 713 } 702 714 if (!USE_GRID) return; … … 724 736 for (j = 0; j < MosaicN_Image[i]; j++) { 725 737 im = MosaicToImage[i][j]; 726 image[im].Mcal += mosaic[i].Mcal; 727 image[im].dMcal = mosaic[i].dMcal; 728 image[im].Xm = mosaic[i].Xm; 738 image[im].McalPSF += mosaic[i].McalPSF; 739 image[im].McalAPER += mosaic[i].McalAPER; 740 image[im].dMcal = mosaic[i].dMcal; 741 image[im].McalChiSq = mosaic[i].McalChiSq; 729 742 image[im].ubercalDist = mosaic[i].ubercalDist; 730 image[im].dMagSys = mosaic[i].dMsys; 731 image[im].nFitPhotom = mosaic[i].nFitPhotom; 732 image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW); 733 image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR); 734 } 735 mosaic[i].Mcal = 0.0; 743 image[im].dMagSys = mosaic[i].dMsys; 744 image[im].nFitPhotom = mosaic[i].nFitPhotom; 745 image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW); 746 image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR); 747 } 748 mosaic[i].McalPSF = 0.0; 749 mosaic[i].McalAPER = 0.0; 736 750 } 737 751 } … … 886 900 887 901 if (mosaic[i].flags & IMAGE_BAD) return (NAN); 888 value = mosaic[i].Mcal ;902 value = mosaic[i].McalPSF; 889 903 return (value); 890 904 } … … 911 925 off_t Nmax; 912 926 int PoorImages; 913 double *list; 914 double *dlist; 915 double *Mlist; 916 double *dMlist; 927 double *psfMagList; 928 double *psfErrList; 929 double *brightMagList; 930 double *brightErrList; 931 double *kronMagList; 932 double *kronErrList; 917 933 } SetMmosInfo; 918 934 … … 945 961 946 962 if (allocLists) { 947 ALLOCATE (info->list, double, Nmax); 948 ALLOCATE (info->dlist, double, Nmax); 949 ALLOCATE (info->Mlist, double, Nmax); 950 ALLOCATE (info->dMlist, double, Nmax); 963 ALLOCATE (info->psfMagList, double, Nmax); 964 ALLOCATE (info->psfErrList, double, Nmax); 965 ALLOCATE (info->kronMagList, double, Nmax); 966 ALLOCATE (info->kronErrList, double, Nmax); 967 ALLOCATE (info->brightMagList, double, Nmax); 968 ALLOCATE (info->brightErrList, double, Nmax); 951 969 } 952 970 } 953 971 954 972 void SetMmosInfoFree (SetMmosInfo *info) { 955 free (info->list); 956 free (info->dlist); 957 free (info->Mlist); 958 free (info->dMlist); 973 free (info->psfMagList ); 974 free (info->psfErrList ); 975 free (info->kronMagList ); 976 free (info->kronErrList ); 977 free (info->brightMagList); 978 free (info->brightErrList); 959 979 } 960 980 … … 1057 1077 liststats_setmode (&stats, "INNER_WTMEAN"); 1058 1078 1059 double *list = info->list; 1060 double *dlist = info->dlist; 1061 double *Mlist = info->Mlist; 1062 double *dMlist = info->dMlist; 1079 double *psfMagList = info->psfMagList; 1080 double *psfErrList = info->psfErrList; 1081 double *kronMagList = info->kronMagList; 1082 double *kronErrList = info->kronErrList; 1083 double *brightMagList = info->brightMagList; 1084 double *brightErrList = info->brightErrList; 1063 1085 1064 1086 assert (Nmos >= 0); … … 1125 1147 int N = 0; 1126 1148 for (j = 0; j < N_onMosaic[Nmos]; j++) { 1127 float Msys, Mrel, Mcal, Mgrid, Mflat;1128 1149 1129 1150 off_t m = MosaicToMeasure[Nmos][j]; 1130 1151 off_t c = MosaicToCatalog[Nmos][j]; 1131 1152 1153 // NOTE : we are only using Mcal == McalPSF in this function; we set McalAPER to McalPSF 1132 1154 if (fout) { 1133 Mcal = getMcal (m, c, flatcorr, catalog);1134 Mgrid= getMgrid (m, c);1135 Mrel = getMrel (catalog, m, c);1136 Mflat= getMflat (m, c, flatcorr, catalog);1155 float Mcal = getMcal (m, c, MAG_CLASS_PSF); 1156 float Mgrid = getMgrid (m, c); 1157 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 1158 float Mflat = getMflat (m, c, flatcorr, catalog); 1137 1159 1138 1160 off_t n = catalog[c].measureT[m].averef; 1139 Msys= PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);1140 1141 float delta = Msys - Mrel- Mcal - Mgrid + Mflat;1161 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 1162 1163 float delta = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat; 1142 1164 1143 1165 int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD); 1144 1166 1145 fprintf (fout, "%f %f : %f %f %f %f %f : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, Msys , Mrel, Mcal, Mgrid, Mflat, delta, isBad);1167 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); 1146 1168 } 1147 1169 … … 1150 1172 continue; 1151 1173 } 1152 Mcal = getMcal (m, c, flatcorr, catalog);1174 float Mcal = getMcal (m, c, MAG_CLASS_PSF); 1153 1175 if (isnan(Mcal)) { 1154 1176 info->Ncal++; 1155 1177 continue; 1156 1178 } 1157 Mgrid = getMgrid (m, c);1179 float Mgrid = getMgrid (m, c); 1158 1180 if (isnan(Mgrid)) { 1159 1181 info->Ngrid ++; 1160 1182 continue; 1161 1183 } 1162 Mrel = getMrel (catalog, m, c); 1163 if (isnan(Mrel)) { 1184 1185 // Mrel* is the average magnitude for this star. For PS1 stacks, we have too much 1186 // PSF variability. We need to calibrate the PSF magnitudes separately from the 1187 // Aperture-like magnitues. (We have an option to use the kron magnitudes or the 1188 // other apertures here). I basically need to do this analysis separately for each 1189 // magnitude type 1190 1191 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 1192 if (isnan(MrelPSF)) { 1164 1193 info->Nrel ++; 1165 1194 continue; 1166 1195 } 1196 float MrelKron = getMrel (catalog, m, c, MAG_CLASS_KRON, MAG_SRC_CHP); 1167 1197 1168 1198 // image.Mcal is not supposed to include the flat-field correction, so we need to … … 1171 1201 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat) 1172 1202 1173 Mflat = getMflat (m, c, flatcorr, catalog);1203 float Mflat = getMflat (m, c, flatcorr, catalog); 1174 1204 1175 1205 off_t n = catalog[c].measureT[m].averef; 1176 Msys= PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);1177 if (isnan(Msys )) {1206 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 1207 if (isnan(MsysPSF)) { 1178 1208 info->Nsys++; 1179 1209 continue; 1180 1210 } 1211 float MsysKron = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_KRON); 1181 1212 1182 1213 PhotCode *code = GetPhotcodebyCode (catalog[c].measureT[m].photcode); … … 1193 1224 assert (Nbright >= 0); 1194 1225 1195 list[N] = Msys - Mrel - Mcal - Mgrid + Mflat; 1196 dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 1226 psfMagList[N] = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat; 1227 psfErrList[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 1228 kronMagList[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat; 1229 kronErrList[N] = psfErrList[N]; 1197 1230 if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) { 1198 Mlist[Nbright] = list[N];1199 dMlist[Nbright] = dlist[N];1231 brightMagList[Nbright] = psfMagList[N]; 1232 brightErrList[Nbright] = psfErrList[N]; 1200 1233 Nbright ++; 1201 1234 } … … 1223 1256 } 1224 1257 1225 liststats ( list, dlist, NULL, N, &stats);1258 liststats (psfMagList, psfErrList, NULL, N, &stats); 1226 1259 if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mmos: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N); 1227 1260 1228 myMosaic[0].Mcal = stats.mean; 1229 myMosaic[0].dMcal = stats.error; 1261 // for now, I have no reason to measure these separately for camera-level images 1262 myMosaic[0].McalPSF = stats.mean; 1263 myMosaic[0].dMcal = stats.error; 1264 myMosaic[0].McalChiSq = stats.chisq; 1230 1265 myMosaic[0].nFitPhotom = N; 1231 myMosaic[0].Xm = 100.0*log10(stats.chisq); 1266 1267 liststats (kronMagList, kronErrList, NULL, N, &stats); 1268 myMosaic[0].McalAPER = stats.mean; 1232 1269 1233 1270 if (testImage) { … … 1237 1274 if (PLOTSTUFF) { 1238 1275 fprintf (stderr, "Mmos: %6.3f %6.3f +/- %6.3f %5d %5d | %s\n", stats.mean, stats.median, stats.sigma, stats.Nmeas, N, image[MosaicToImage[Nmos][0]].name); 1239 plot_setMcal ( list, N, &stats, CLOUD_TOLERANCE);1276 plot_setMcal (psfMagList, N, &stats, CLOUD_TOLERANCE); 1240 1277 } 1241 1278 1242 1279 // bright end scatter 1243 liststats ( Mlist, dMlist, NULL, Nbright, &stats);1280 liststats (brightMagList, brightErrList, NULL, Nbright, &stats); 1244 1281 myMosaic[0].dMsys = stats.sigma; 1245 1282 1246 if (myMosaic[0].Mcal < -CLOUD_TOLERANCE) {1247 myMosaic[0].Mcal = 0.0;1283 if (myMosaic[0].McalPSF < -CLOUD_TOLERANCE) { 1284 myMosaic[0].McalPSF = 0.0; 1248 1285 } 1249 1286 1250 1287 if (testImage) { 1251 fprintf (stderr, "%f %f : %f\n", myMosaic[0].Mcal , myMosaic[0].dMsys, pow (10.0, 0.01*myMosaic[0].Xm));1288 fprintf (stderr, "%f %f : %f\n", myMosaic[0].McalPSF, myMosaic[0].dMsys, myMosaic[0].McalChiSq); 1252 1289 } 1253 1290 … … 1427 1464 imageOffset[i] = 0.0; 1428 1465 1429 if (VERBOSE2 && (fabs(mosaic[i].Mcal ) < CLOUD_TOLERANCE)) {1430 fprintf (stderr, "cloud-free: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal );1466 if (VERBOSE2 && (fabs(mosaic[i].McalPSF) < CLOUD_TOLERANCE)) { 1467 fprintf (stderr, "cloud-free: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF); 1431 1468 } 1432 if (VERBOSE2 && (mosaic[i].Mcal < -CLOUD_TOLERANCE)) {1433 imageOffset[i] = -mosaic[i].Mcal ;1434 // NOTE the negative sign: down below, we are going to add in the negative of Mcal 1469 if (VERBOSE2 && (mosaic[i].McalPSF < -CLOUD_TOLERANCE)) { 1470 imageOffset[i] = -mosaic[i].McalPSF; 1471 // NOTE the negative sign: down below, we are going to add in the negative of McalPSF 1435 1472 // to this image, and the propagated mean values for other images 1436 fprintf (stderr, "anti-clouds: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal );1473 fprintf (stderr, "anti-clouds: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF); 1437 1474 } 1438 if (VERBOSE2 && (mosaic[i].Mcal > CLOUD_TOLERANCE)) {1439 fprintf (stderr, "cloudy : %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal );1475 if (VERBOSE2 && (mosaic[i].McalPSF > CLOUD_TOLERANCE)) { 1476 fprintf (stderr, "cloudy : %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF); 1440 1477 } 1441 1478 } … … 1540 1577 } 1541 1578 1542 // a negative cloud image (cloud: Mcal > 0; anti-clouds: Mcal < 0; imageOffset = -Mcal)1579 // a negative cloud image (cloud: McalPSF > 0; anti-clouds: McalPSF < 0; imageOffset = -McalPSF) 1543 1580 if (imageOffset[i] > 0.0) continue; 1544 1581 … … 1564 1601 // find the images / mosaics with negative clouds and save their offset 1565 1602 for (i = 0; i < Nmosaic; i++) { 1566 mosaic[i].Mcal += imageOffset[i];1603 mosaic[i].McalPSF += imageOffset[i]; 1567 1604 } 1568 1605 … … 1605 1642 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; 1606 1643 1607 list[n] = mosaic[i].Mcal ;1644 list[n] = mosaic[i].McalPSF; 1608 1645 dlist[n] = 1; 1609 1646 n++; … … 1677 1714 c = MosaicToCatalog[i][j]; 1678 1715 1679 Mcal = getMcal (m, c, flatcorr, catalog);1716 Mcal = getMcal (m, c, MAG_CLASS_PSF); 1680 1717 if (isnan(Mcal)) continue; 1681 1718 Mgrid = getMgrid (m, c); 1682 1719 if (isnan(Mgrid)) continue; 1683 Mrel = getMrel (catalog, m, c );1720 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 1684 1721 if (isnan(Mrel)) continue; 1685 1722 N++; … … 1719 1756 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; 1720 1757 1721 list[n] = pow (10.0, 0.01*mosaic[i].Xm);1758 list[n] = mosaic[i].McalChiSq; 1722 1759 dlist[n] = 1; 1723 1760 n++; … … 1751 1788 if (mosaic[i].flags & IMAGE_BAD) continue; 1752 1789 if (mosaic[i].skipCal) continue; 1753 mlist[N] = mosaic[i].Mcal ;1790 mlist[N] = mosaic[i].McalPSF; 1754 1791 slist[N] = mosaic[i].dMcal; 1755 1792 dlist[N] = 1; … … 1781 1818 Nscatter ++; 1782 1819 } 1783 if (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset) {1820 if (fabs(mosaic[i].McalPSF - MedOffset) > MaxOffset) { 1784 1821 mark = TRUE; 1785 1822 Noffset ++; … … 1858 1895 1859 1896 for (i = 0; i < Nmosaic; i++) { 1860 Mlist[i] = mosaic[i].Mcal ;1897 Mlist[i] = mosaic[i].McalPSF; 1861 1898 dlist[i] = mosaic[i].dMcal; 1862 1899 xlist[i] = mosaic[i].secz; -
branches/czw_branch/20170908/Ohana/src/relphot/src/StarOps.c
r40019 r40477 34 34 } 35 35 36 float getMrel (Catalog *catalog, off_t meas, int cat) { 37 38 int Nsec, Nsecfilt, photcode; 39 int ave; 40 float value; 41 42 ave = catalog[cat].measureT[meas].averef; 43 photcode = catalog[cat].measureT[meas].photcode; 36 // 37 float getMrel (Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source) { 38 39 int ave = catalog[cat].measureT[meas].averef; 40 int photcode = catalog[cat].measureT[meas].photcode; 44 41 45 42 int ecode = GetPhotcodeEquivCodebyCode (photcode); 46 Nsec = GetPhotcodeNsec(ecode); 47 Nsecfilt = GetPhotcodeNsecfilt (); 43 int Nsec = GetPhotcodeNsec(ecode); 44 int Nsecfilt = GetPhotcodeNsecfilt (); 45 46 int entry = Nsecfilt*ave+Nsec; 47 48 SecFilt *secfilt = &catalog[cat].secfilt[entry]; 48 49 49 50 // is this star OK? 50 if (catalog[cat].secfilt[Nsecfilt*ave+Nsec].flags & STAR_BAD) return (NAN); 51 52 value = catalog[cat].secfilt[Nsecfilt*ave+Nsec].M; 53 return (value); 51 if (secfilt->flags & STAR_BAD) return (NAN); 52 53 switch (class) { 54 case MAG_CLASS_PSF: 55 switch (source) { 56 case MAG_SRC_CHP: 57 return secfilt->MpsfChp; 58 case MAG_SRC_WRP: 59 return secfilt->MpsfWrp; 60 case MAG_SRC_STK: 61 return secfilt->MpsfStk; 62 default: 63 return NAN; 64 } 65 break; 66 case MAG_CLASS_KRON: 67 switch (source) { 68 case MAG_SRC_CHP: 69 return secfilt->MkronChp; 70 case MAG_SRC_WRP: 71 return secfilt->MkronWrp; 72 case MAG_SRC_STK: 73 return secfilt->MkronStk; 74 default: 75 return NAN; 76 } 77 break; 78 case MAG_CLASS_APER: 79 switch (source) { 80 case MAG_SRC_CHP: 81 return secfilt->MapChp; 82 case MAG_SRC_WRP: 83 return secfilt->MapWrp; 84 case MAG_SRC_STK: 85 return secfilt->MapStk; 86 default: 87 return NAN; 88 } 89 break; 90 case MAG_CLASS_NONE: 91 case MAG_CLASS_DEV: // DeVaucouleur Model (only for galphot) 92 case MAG_CLASS_EXP: // Exponential Model (only for galphot) 93 case MAG_CLASS_SER: // Sersic Model (only for galphot) 94 return NAN; 95 break; 96 } 97 return NAN; // should not be able to reach here 54 98 } 55 99 … … 429 473 int i; 430 474 off_t j, k, m; 431 float Mcal, Mmos, Mgrid;432 475 433 476 MEAS_BAD = ID_MEAS_NOCAL; … … 440 483 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 441 484 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 442 Mcal = getMcal (m, i, flatcorr, catalog); 443 if (isnan(Mcal)) continue; 444 Mmos = getMmos (m, i); 485 float McalPSF = getMcal (m, i, MAG_CLASS_PSF); 486 float McalAPER = getMcal (m, i, MAG_CLASS_APER); 487 if (isnan(McalPSF)) continue; 488 float Mmos = getMmos (m, i); 445 489 if (isnan(Mmos)) continue; 446 Mgrid = getMgrid (m, i);490 float Mgrid = getMgrid (m, i); 447 491 if (isnan(Mgrid)) continue; 492 493 // Note that this operation is setting measure->McalAPER to image->McalAPER only 494 // for the stacks. Elsewhere (setMrelCatalog) we are using image->McalPSF for all 495 // types of measurements EXCEPT stacks. 496 497 // we need to use McalAPER for stacks (and only stacks) 498 int useStackAper = !USE_MCAL_PSF_FOR_STACK_APER && isGPC1stack(catalog[i].measureT[m].photcode); 448 499 449 500 // note that measurements for which the image is not selected will not be modified … … 451 502 452 503 // set the output calibration 453 catalog[i].measure[m].Mcal = Mcal + Mmos + Mgrid; 504 catalog[i].measure[m].McalPSF = McalPSF + Mmos + Mgrid; 505 catalog[i].measure[m].McalAPER = useStackAper ? McalAPER + Mmos + Mgrid : McalPSF + Mmos + Mgrid; 454 506 455 507 if (catalog[i].measureT[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { 456 myAssert (isfinite(catalog[i].measure[m].Mcal ), "oops, broke an ubercal mag");508 myAssert (isfinite(catalog[i].measure[m].McalPSF), "oops, broke an ubercal mag"); 457 509 } 458 510 } … … 501 553 } 502 554 555 int dumpMags (FILE *fout, Catalog *catalog, int Ncatalog) { 556 557 int i, n; 558 off_t j; 559 560 int Nsecfilt = GetPhotcodeNsecfilt (); 561 562 for (i = 0; i < Ncatalog; i++) { 563 for (j = 0; (j < catalog[i].Naverage) && (j < 2); j++) { 564 fprintf (fout, "%08x %08x %10.6f %10.6f : \n", catalog[i].averageT[j].catID, catalog[i].averageT[j].objID, catalog[i].averageT[j].R, catalog[i].averageT[j].D); 565 for (n = 0; n < 5; n++) { 566 fprintf (fout, "secf %5d | %6.3f %6.3f | %6.3f %6.3f | %6.3f %6.3f\n", n, catalog[i].secfilt[j*Nsecfilt + n].MpsfChp, catalog[i].secfilt[j*Nsecfilt + n].MkronChp, catalog[i].secfilt[j*Nsecfilt + n].MpsfStk, catalog[i].secfilt[j*Nsecfilt + n].MkronStk, catalog[i].secfilt[j*Nsecfilt + n].MpsfWrp, catalog[i].secfilt[j*Nsecfilt + n].MkronWrp); 567 } 568 int m = catalog[i].averageT[j].measureOffset; 569 for (n = 0; n < catalog[i].averageT[j].Nmeasure; n++) { 570 fprintf (fout, "meas %5d %5d | %6.3f %6.3f | %6.3f %6.3f\n", m+n, catalog[i].measureT[m+n].photcode, catalog[i].measureT[m+n].M, catalog[i].measureT[m+n].Mkron, catalog[i].measureT[m+n].McalPSF, catalog[i].measureT[m+n].McalAPER); 571 } 572 } 573 } 574 return TRUE; 575 } 576 503 577 void clean_stars (Catalog *catalog, int Ncatalog) { 504 578 … … 513 587 if (VERBOSE) fprintf (stderr, "marking poor stars\n"); 514 588 515 /* find Xmmedian -> ChiSq lim must be > median */589 /* find Mchisq median -> ChiSq lim must be > median */ 516 590 for (i = Ntot = 0; i < Ncatalog; i++) { 517 591 Ntot += catalog[i].Naverage; … … 535 609 if (isnan(Mchisq)) continue; 536 610 xlist[Ntot] = Mchisq; 537 slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dM ;611 slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp; 538 612 dlist[Ntot] = 1; 539 613 Ntot ++; … … 551 625 for (i = 0; i < Ncatalog; i++) { 552 626 for (j = 0; j < catalog[i].Naverage; j++) { 553 dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM ;627 dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp; 554 628 float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq; 555 629 mark = (dM > MaxScatter) || (isnan(Mchisq)) || (Mchisq > MaxChisq); … … 578 652 // NSIGMA_REJECT (5) sigma of the mean 579 653 654 // this function only operations on the PSF magnitudes 655 580 656 # define NSIGMA_CLIP 3.0 581 657 # define NSIGMA_REJECT 5.0 … … 644 720 645 721 // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers 646 Mcal = getMcal (m, i, flatcorr, catalog);722 Mcal = getMcal (m, i, MAG_CLASS_PSF); 647 723 if (isnan(Mcal)) { Ncal ++; continue; } 648 724 Mmos = getMmos (m, i); … … 695 771 696 772 // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers 697 Mcal = getMcal (m, i, flatcorr, catalog);773 Mcal = getMcal (m, i, MAG_CLASS_PSF); 698 774 if (isnan(Mcal)) continue; 699 775 Mmos = getMmos (m, i); … … 776 852 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 777 853 if (ecode != seccode) { continue;} 778 Mcal = getMcal (m, i, flatcorr, catalog);854 Mcal = getMcal (m, i, MAG_CLASS_PSF); 779 855 if (isnan(Mcal)) { continue;} 780 856 Mmos = getMmos (m, i); … … 865 941 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 866 942 867 dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM ;943 dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp; 868 944 if (isnan(dM)) continue; 869 945 list[n] = dM; … … 906 982 for (j = 0; j < catalog[i].Naverage; j++) { 907 983 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 908 dMrel = catalog[i].secfilt[Nsecfilt*j+Nsec].dM ;984 dMrel = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp; 909 985 bin = dMrel / 0.00025; 910 986 bin = MAX (0, MIN (NBIN-1, bin)); … … 946 1022 for (j = 0; j < catalog[i].Naverage; j++) { 947 1023 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 948 xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].M ;1024 xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp; 949 1025 value = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq; 950 1026 if (isnan((double)(value))) continue; -
branches/czw_branch/20170908/Ohana/src/relphot/src/args.c
r39926 r40477 136 136 remove_argument (N, &argc, argv); 137 137 } 138 SKIP_PARALLEL_GROUPS = 0; 139 if ((N = get_argument (argc, argv, "-skip-parallel-groups"))) { 140 remove_argument (N, &argc, argv); 141 SKIP_PARALLEL_GROUPS = atoi(argv[N]); 142 remove_argument (N, &argc, argv); 143 } 138 144 139 145 // elements needed for parallel regions / parallel images … … 325 331 remove_argument (N, &argc, argv); 326 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; 327 338 } 328 339 … … 544 555 PARALLEL_MANUAL = FALSE; 545 556 PARALLEL_SERIAL = FALSE; 557 SKIP_PARALLEL_GROUPS = 0; 546 558 547 559 HOST_ID = 0; … … 694 706 remove_argument (N, &argc, argv); 695 707 KEEP_UBERCAL = FALSE; 708 } 709 710 USE_MCAL_PSF_FOR_STACK_APER = FALSE; 711 if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) { 712 remove_argument (N, &argc, argv); 713 USE_MCAL_PSF_FOR_STACK_APER = TRUE; 696 714 } 697 715 -
branches/czw_branch/20170908/Ohana/src/relphot/src/bcatalog.c
r39641 r40477 153 153 if (subcatalog[0].measureT[Nmeasure].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { 154 154 if (!KEEP_UBERCAL) { 155 subcatalog[0].measureT[Nmeasure].Mcal = 0.0; 155 subcatalog[0].measureT[Nmeasure].McalPSF = 0.0; 156 subcatalog[0].measureT[Nmeasure].McalAPER = 0.0; 156 157 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL; 157 158 } 158 159 } else { 159 160 if (getImageEntry (Nmeasure, Ncat) >= 0) { 160 subcatalog[0].measureT[Nmeasure].Mcal = 0.0; 161 subcatalog[0].measureT[Nmeasure].McalPSF = 0.0; 162 subcatalog[0].measureT[Nmeasure].McalAPER = 0.0; 161 163 } 162 164 } -
branches/czw_branch/20170908/Ohana/src/relphot/src/launch_region_hosts.c
r39511 r40477 58 58 strextend (&command, "-cloud-limit %f", CLOUD_TOLERANCE); 59 59 60 if (VERBOSE) strextend (&command, "-v");61 if (VERBOSE2) strextend (&command, "-vv");62 if (RESET) strextend (&command, "-reset");63 if (RESET_ZEROPTS) strextend (&command, "-reset-zpts");64 if (!KEEP_UBERCAL) strextend (&command, "-reset-ubercal");65 if (DophotSelect) strextend (&command, "-dophot %d", DophotValue);66 if (ImagSelect) strextend (&command, "-instmag %f %f", ImagMin, ImagMax);67 if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue);68 if (SyntheticPhotometry) strextend (&command, "-synthphot");69 if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");60 if (VERBOSE) strextend (&command, "-v"); 61 if (VERBOSE2) strextend (&command, "-vv"); 62 if (RESET) strextend (&command, "-reset"); 63 if (RESET_ZEROPTS) strextend (&command, "-reset-zpts"); 64 if (!KEEP_UBERCAL) strextend (&command, "-reset-ubercal"); 65 if (DophotSelect) strextend (&command, "-dophot %d", DophotValue); 66 if (ImagSelect) strextend (&command, "-instmag %f %f", ImagMin, ImagMax); 67 if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue); 68 if (SyntheticPhotometry) strextend (&command, "-synthphot"); 69 if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search"); 70 70 71 if (UPDATE) strextend (&command, "-update"); 72 if (MOSAIC_ZEROPT) strextend (&command, "-mosaic"); 73 if (FREEZE_IMAGES) strextend (&command, "-imfreeze"); 74 if (FREEZE_MOSAICS) strextend (&command, "-mosfreeze"); 75 if (PARALLEL) strextend (&command, "-parallel"); 76 if (PARALLEL_MANUAL) strextend (&command, "-parallel-manual"); 77 if (PARALLEL_SERIAL) strextend (&command, "-parallel-serial"); 71 if (UPDATE) strextend (&command, "-update"); 72 if (MOSAIC_ZEROPT) strextend (&command, "-mosaic"); 73 if (FREEZE_IMAGES) strextend (&command, "-imfreeze"); 74 if (FREEZE_MOSAICS) strextend (&command, "-mosfreeze"); 75 if (CALIBRATE_STACKS_AND_WARPS) strextend (&command, "-only-stacks-and-warps"); 76 if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); } 77 78 if (PARALLEL) strextend (&command, "-parallel"); 79 if (PARALLEL_MANUAL) strextend (&command, "-parallel-manual"); 80 if (PARALLEL_SERIAL) strextend (&command, "-parallel-serial"); 78 81 79 82 // XXX deprecate this if we are happy with the new version -
branches/czw_branch/20170908/Ohana/src/relphot/src/liststats.c
r39648 r40477 194 194 # define WEIGHT_THRESHOLD 0.3 195 195 196 int fit_least_squares (double *fit, double * y, double *dy, double *wgt, double *wt, int Npts);196 int fit_least_squares (double *fit, double *err, double *y, double *dy, double *wgt, double *wt, int Npts); 197 197 double VectorFractionInterpolate (double *values, float fraction, int Npts); 198 198 double weight_cauchy (double x); … … 253 253 254 254 double oldValue = value; 255 if (!fit_least_squares (&value, dataset->flxlist, dataset->errlist, dataset->wgtlist, dataset->wtvals, Npoints)) {255 if (!fit_least_squares (&value, NULL, dataset->flxlist, dataset->errlist, dataset->wgtlist, dataset->wtvals, Npoints)) { 256 256 value = oldValue; 257 257 break; … … 330 330 } 331 331 332 if (!fit_least_squares (&value, dataset->ysample, dataset->dysample, dataset->wtsample, NULL, Nkeep)) continue;332 if (!fit_least_squares (&value, NULL, dataset->ysample, dataset->dysample, dataset->wtsample, NULL, Nkeep)) continue; 333 333 334 334 dataset->bvalue[Nboot] = value; … … 342 342 stats->error = (Shi - Slo) / 2.0; 343 343 344 // bootstrap can sometimes yield an excessively-optimistic result for the error. Do not let 345 // the reported error be smaller than the formal error 346 double errvalue; 347 if (fit_least_squares (&value, &errvalue, dataset->ykeep, dataset->dykeep, dataset->wtkeep, NULL, Nkeep)) { 348 stats->error = MAX (stats->error, errvalue); 349 } 350 344 351 return TRUE; 345 352 } 346 353 347 354 // wgt is externally-supplied weight, wt is optional 348 int fit_least_squares (double *fit, double * y, double *dy, double *wgt, double *wt, int Npts) {355 int fit_least_squares (double *fit, double *err, double *y, double *dy, double *wgt, double *wt, int Npts) { 349 356 350 357 int i; … … 364 371 } 365 372 if (S0 == 0.0) return FALSE; 366 *fit = S1 / S0; 373 *fit = S1 / S0; 374 if (err) { *err = 1.0 / S0; } 367 375 return TRUE; 368 376 } -
branches/czw_branch/20170908/Ohana/src/relphot/src/load_images.c
r39642 r40477 52 52 free (subset); 53 53 subset = image; 54 } 55 } 56 57 // reset image values as needed. always allow 'few' images to succeed, if possible (new 58 // images / detections may have been added 59 for (off_t i = 0; i < Nsubset; i++) { 60 if (subset[i].flags & ID_IMAGE_PHOTOM_FEW) { 61 subset[i].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR); 62 } 63 if (RESET) { 64 if (RESET_ZEROPTS) { 65 if (!KEEP_UBERCAL || !(subset[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) { 66 subset[i].McalPSF = 0.0; 67 subset[i].McalAPER = 0.0; 68 subset[i].dMcal = NAN; 69 subset[i].flags &= ~ID_IMAGE_PHOTOM_UBERCAL; 70 } 71 } 72 subset[i].flags &= ~ID_IMAGE_PHOTOM_POOR; 73 subset[i].ubercalDist = 1000; 54 74 } 55 75 } -
branches/czw_branch/20170908/Ohana/src/relphot/src/plot_scatter.c
r37037 r40477 40 40 41 41 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 42 Mcal = getMcal (m, i, flatcorr, catalog);42 Mcal = getMcal (m, i, MAG_CLASS_PSF); 43 43 if (isnan(Mcal)) continue; 44 44 Mmos = getMmos (m, i); … … 47 47 if (isnan(Mgrid)) continue; 48 48 49 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].M ;49 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp; 50 50 if (isnan(Mrel)) continue; 51 51 -
branches/czw_branch/20170908/Ohana/src/relphot/src/plotstuff.c
r39457 r40477 179 179 180 180 KapaInitGraph (graphdata); 181 graphdata[0].style = 2;181 graphdata[0].style = KAPA_PLOT_POINTS; /* points */ 182 182 graphdata[0].ptype = 2; 183 183 graphdata[0].ltype = 0; -
branches/czw_branch/20170908/Ohana/src/relphot/src/reload_catalogs.c
r39926 r40477 180 180 for (i = 0; i < Ngroups; i++) { 181 181 // update only a group of unique machines at a time 182 if (i < SKIP_PARALLEL_GROUPS) continue; 182 183 reload_catalog_parallel_group (&groups[i], sky, imageFile); 183 184 } … … 247 248 if (SYNTH_ZERO_POINTS) { strextend (&command, "-synthphot-zpts %s", SYNTH_ZERO_POINTS); } 248 249 if (USE_BASIC_CHECK) { strextend (&command, "-basic-image-search"); } 250 if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); } 249 251 250 252 if (!(STAGES & STAGE_CHIP)) { strextend (&command, "-skip-chip"); } -
branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_images.c
r39643 r40477 42 42 MARKTIME("-- load images: %f sec\n", dtime); 43 43 44 // checkImages("load images"); 45 44 46 /* unlock, if we can (else, unlocked below) */ 45 47 if (!UPDATE) dvo_image_unlock (&db); 46 48 47 49 // load the flat correction table (if defined) 50 // we no longer need to do this: the flatcorrection is now saved in measure.Mflat 48 51 # if (0) 49 52 char flatcorrfile[256]; … … 60 63 /* add in a loop over the catalogs calling dvo_catalog_chipcoords */ 61 64 65 // checkImages("load catalog"); 66 62 67 /* match measurements with images, mosaics */ 63 68 initImageBins (catalog, Ncatalog, TRUE); … … 77 82 78 83 setExclusions (catalog, Ncatalog, TRUE); 84 // checkImages("set Exclu"); 79 85 80 86 global_stats (catalog, Ncatalog, flatcorr, 0); … … 108 114 plot_scatter (catalog, Ncatalog, flatcorr); 109 115 } 116 if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog); 117 // checkImages("start loop"); 118 110 119 setMrel (catalog, Ncatalog, flatcorr); // threaded 120 if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog); 121 // checkImages("set Mrel"); 122 111 123 if (PLOTSTUFF) { 112 124 plot_scatter (catalog, Ncatalog, flatcorr); 113 125 } 114 126 setMcal (catalog, FALSE, flatcorr); 127 // checkImages("set Mcal"); 128 if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog); 129 115 130 setMmos (catalog, FALSE, flatcorr); 116 131 setMgrid (catalog, flatcorr); … … 213 228 // ensure the db format is updated 214 229 dbX.format = dvo_catalog_catformat (UPDATE_CATFORMAT); 230 gfits_modify (&dbX.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT); 231 215 232 char photcodeFile[1024]; 216 233 sprintf (photcodeFile, "%s/Photcodes.dat", CATDIR); … … 257 274 // ensure the db format is updated 258 275 db.format = dvo_catalog_catformat (UPDATE_CATFORMAT); 276 gfits_modify (&db.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT); 259 277 } 260 278 if (CALIBRATE_STACKS_AND_WARPS || (NLOOP > 0)) { -
branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_objects.c
r39926 r40477 251 251 if (USE_BASIC_CHECK) { strextend (&command, "-basic-image-search"); } 252 252 if (USE_ALL_IMAGES) { strextend (&command, "-use-all-images"); } 253 if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); } 253 254 254 255 if (!(STAGES & STAGE_CHIP)) { strextend (&command, "-skip-chip"); } -
branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_parallel_images.c
r39643 r40477 36 36 client_logger_message ("loaded images\n"); 37 37 38 // once we have read this table, we should remove it for repeat runs39 // unlink (IMAGE_TABLE); // XXX a bit risky, add some protection?40 41 38 makeMosaics (image, Nimage, TRUE); 42 39 … … 44 41 45 42 // load the flat correction table (if defined) 43 // we no longer need to do this: the flatcorrection is now saved in measure.Mflat 46 44 # if (0) 47 45 char flatcorrfile[256]; … … 150 148 client_logger_message ("all hosts are done the loops\n"); 151 149 152 /* set Mcal & Mmos for bad images */ 153 setMcal (catalog, TRUE, flatcorr); 154 setMmos (catalog, TRUE, flatcorr); 150 /* set Mcal & Mmos for bad images (for stack_and_warps, force images to be measured) */ 151 int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS; 152 setMcal (catalog, onlyPoorImages, flatcorr); 153 setMmos (catalog, onlyPoorImages, flatcorr); 155 154 MARKTIME("-- finalize Mcal values: %f sec\n", dtime); 156 155 … … 171 170 freeGridBins (Ncatalog); 172 171 freeImages((char *)image); 172 free (image); 173 173 174 174 SkyListFree(skylist); -
branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_parallel_regions.c
r39643 r40477 51 51 // ensure the db format is updated 52 52 db.format = dvo_catalog_catformat (UPDATE_CATFORMAT); 53 gfits_modify (&db.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT); 53 54 } 54 55 … … 84 85 85 86 // save the changes to the image parameters 86 dvo_image_save (&db, VERBOSE); // this function modifies the db.ftable.buffer: do not free stored Image table 87 dvo_image_save (&db, VERBOSE); 88 89 // dvo_image_save frees db.ftable.buffer (== image) and replaces it: do not free stored Image table 90 clearImages (); 91 87 92 dvo_image_unlock (&db); 88 93 MARKTIME ("finished relphot -parallel-regions: %f sec total\n", dtime); -
branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_synthphot_catalog.c
r38062 r40477 92 92 float *value = (float *) zpts->matrix[Nsec].buffer; 93 93 float ZP = !isnan(value[Npix]) ? value[Npix] : 0.0; 94 secfilt[Nsec].M = measure[measSYN[i]].M + ZP;95 secfilt[Nsec].dM = 0.6;96 secfilt[Nsec].Mchisq = NAN;97 secfilt[Nsec].flags |= ID_SECF_USE_SYNTH;94 secfilt[Nsec].MpsfChp = measure[measSYN[i]].M + ZP; 95 secfilt[Nsec].dMpsfChp = 0.6; 96 secfilt[Nsec].Mchisq = NAN; 97 secfilt[Nsec].flags |= ID_SECF_USE_SYNTH; 98 98 } 99 99 } -
branches/czw_branch/20170908/Ohana/src/relphot/src/select_images.c
r39648 r40477 251 251 image[nimage] = timage[i]; 252 252 inSubset[i] = TRUE; 253 /* always allow 'few' images to succeed, if possible (new images / detections may have254 * been added) */255 if (image[nimage].flags & ID_IMAGE_PHOTOM_FEW) {256 image[nimage].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR);257 }258 if (RESET) {259 if (RESET_ZEROPTS) {260 if (!KEEP_UBERCAL || !(image[nimage].flags & ID_IMAGE_PHOTOM_UBERCAL)) {261 image[nimage].Mcal = 0.0;262 image[nimage].dMcal = NAN;263 image[nimage].flags &= ~ID_IMAGE_PHOTOM_UBERCAL;264 }265 }266 image[nimage].flags &= ~ID_IMAGE_PHOTOM_POOR;267 image[nimage].ubercalDist = 1000;268 }269 253 line_number[nimage] = i; 270 254 nimage ++; -
branches/czw_branch/20170908/Ohana/src/relphot/src/setMrelCatalog.c
r39926 r40477 2 2 3 3 # if (0) 4 # define TEST_OBJ_ID 0x000 0000e5 # define TEST_CAT_ID 0x0000 76ee4 # define TEST_OBJ_ID 0x000149b0 5 # define TEST_CAT_ID 0x00000001 6 6 # else 7 7 # define TEST_OBJ_ID 0 … … 102 102 // 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages 103 103 // 4) some reference photcode of some kind can be specified as fixed and have a high weight 104 105 // Although I calculate McalAPER for exposures, I am only using McalPSF for chips. Note 106 // in StarOps.c:setMcalOutput I am setting measure->McalAPER to image->McalPSF for chips 107 // and warps, but not stacks 104 108 105 109 // set mean of chip measurements (selected by photcode range for now): … … 224 228 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 225 229 Mmos = Mgrid = 0; 226 Mcal = measureT[k].Mcal ; // check that this is zero for loaded REF value230 Mcal = measureT[k].McalPSF; // check that this is zero for loaded REF value 227 231 } else { 228 // getMcal_alt returns image[].Mcal modified by flatcorr(image.photom_map_id,x,y) 229 // NOTE: getMcal_alt does not include measure.Mflat 230 Mcal = getMcal_alt (meas, cat, flatcorr, measureT[k].Xccd, measureT[k].Yccd); 232 // getMcal returns image[].Mcal; note the flat-field correction is stored in measure.Mflat 233 Mcal = getMcal (meas, cat, MAG_CLASS_PSF); 231 234 if (isnan(Mcal)) SKIP_THIS_MEAS(Ncal); 232 235 Mmos = getMmos (meas, cat); … … 268 271 } 269 272 270 float Mkron, dMkron; 273 // NOTE: we need to calculate the averge chip Kron on each pass to be able to calibrate the stacks 274 float Mkron = PhotCatTiny (&measureT[k], MAG_CLASS_KRON); 275 float dMkron; 271 276 if (isSetMrelFinal) { 272 Mkron = PhotCat (&measure[k], MAG_CLASS_KRON);273 277 dMkron = MAX (hypot(measure[k].dMkron, code->photomErrSys), MIN_ERROR); 274 if (CHECK_VALID_MAG(Mkron, dMkron)) { 275 int Nkron = results->kronData[Nsec].Nlist; 276 results->kronData[Nsec].flxlist[Nkron] = Mkron - Mflat - Mcal - Mmos - Mgrid; // this is consistent with PhotRel 277 results->kronData[Nsec].errlist[Nkron] = dMkron; 278 results->kronData[Nsec].wgtlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0; 279 results->kronData[Nsec].ranking[Nkron] = measureRank[k]; 280 results->kronData[Nsec].measSeq[Nkron] = k; 281 results->kronData[Nsec].msklist[Nkron] = 0; 282 results->kronData[Nsec].Nlist ++; 283 } 278 } else { 279 dMkron = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR); 280 } 281 if (CHECK_VALID_MAG(Mkron, dMkron)) { 282 int Nkron = results->kronData[Nsec].Nlist; 283 results->kronData[Nsec].flxlist[Nkron] = Mkron - Mflat - Mcal - Mmos - Mgrid; // this is consistent with PhotRel 284 results->kronData[Nsec].errlist[Nkron] = dMkron; 285 results->kronData[Nsec].wgtlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0; 286 results->kronData[Nsec].ranking[Nkron] = measureRank ? measureRank[k] : 0; 287 results->kronData[Nsec].measSeq[Nkron] = k; 288 results->kronData[Nsec].msklist[Nkron] = 0; 289 results->kronData[Nsec].Nlist ++; 284 290 } 285 291 … … 377 383 } 378 384 } 379 secfilt[Nsec].M = Mpsf + ZP;380 secfilt[Nsec].dM = 0.6;381 secfilt[Nsec].Mchisq = 0.0;382 secfilt[Nsec].flags |= ID_SECF_USE_SYNTH;385 secfilt[Nsec].MpsfChp = Mpsf + ZP; 386 secfilt[Nsec].dMpsfChp = 0.6; 387 secfilt[Nsec].Mchisq = 0.0; 388 secfilt[Nsec].flags |= ID_SECF_USE_SYNTH; 383 389 continue; 384 390 } … … 386 392 // if too few valid measurements meet the minimum criteria, go to the next entry 387 393 StatType *psfstats = &results->psfstats; 388 int Nranking = MAG_STATS_BY_RANKING (&results->psfData[Nsec], psfstats);389 if (Nranking < Nminmeas) {394 int NrankingPSF = MAG_STATS_BY_RANKING (&results->psfData[Nsec], psfstats); 395 if (NrankingPSF < Nminmeas) { 390 396 secfilt[Nsec].flags |= ID_OBJ_FEW; 391 397 } else { 392 secfilt[Nsec].M = psfstats->mean; 393 secfilt[Nsec].dM = psfstats->error; 394 secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN; 395 } 396 int minRankPSF = (Nranking > 0) ? results->psfData[Nsec].ranking[0] : 10; 398 secfilt[Nsec].MpsfChp = psfstats->mean; 399 secfilt[Nsec].dMpsfChp = psfstats->error; 400 secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN; 401 } 397 402 398 403 // when running -averages, we have no information about the images, so we cannot set this … … 401 406 } 402 407 408 StatType *kronstats = &results->kronstats; 409 int NrankingKRON = MAG_STATS_BY_RANKING (&results->kronData[Nsec], kronstats); 410 if (NrankingKRON) { 411 secfilt[Nsec].MkronChp = kronstats->mean; 412 secfilt[Nsec].dMkronChp = kronstats->error; 413 secfilt[Nsec].sMkronChp = kronstats->sigma; 414 secfilt[Nsec].NusedKron = NrankingKRON; 415 } 416 403 417 if (isSetMrelFinal) { 404 418 if ((average[0].objID == TEST_OBJ_ID) && (average[0].catID == TEST_CAT_ID)) { … … 406 420 } 407 421 408 // mark the measurements matching this ranking 409 markMeasureByRanking (&results->psfData[Nsec], measure, minRankPSF, ID_MEAS_PHOTOM_PSF, ID_MEAS_MASKED_PSF); 410 411 if (Nranking) { 412 secfilt[Nsec].Mstdev = psfstats->sigma; 413 secfilt[Nsec].Nused = psfstats->Nmeas; 414 secfilt[Nsec].Mmax = psfstats->max; 415 secfilt[Nsec].Mmin = psfstats->min; 422 if (NrankingPSF) { 423 secfilt[Nsec].sMpsfChp = psfstats->sigma; 424 secfilt[Nsec].Nused = psfstats->Nmeas; 425 secfilt[Nsec].Mmax = psfstats->max; 426 secfilt[Nsec].Mmin = psfstats->min; 416 427 } 417 428 secfilt[Nsec].psfQfMax = results->psfQfMax[Nsec]; … … 421 432 MAX_NOT_NAN (psfQfPerfMax, secfilt[Nsec].psfQfPerfMax); 422 433 434 // mark the measurements matching this ranking 435 int minRankPSF = (NrankingPSF > 0) ? results->psfData[Nsec].ranking[0] : 10; 436 markMeasureByRanking (&results->psfData[Nsec], measure, minRankPSF, ID_MEAS_PHOTOM_PSF, ID_MEAS_MASKED_PSF); 437 438 int minRankKron = (NrankingKRON > 0) ? results->kronData[Nsec].ranking[0] : 10; 439 markMeasureByRanking (&results->kronData[Nsec], measure, minRankKron, ID_MEAS_PHOTOM_KRON, ID_MEAS_MASKED_KRON); 440 423 441 StatType *apstats = &results->apstats; 424 Nranking= MAG_STATS_BY_RANKING (&results->aperData[Nsec], apstats);425 if (Nranking ) {426 secfilt[Nsec].Map = apstats->mean;427 secfilt[Nsec].dMap = apstats->error;428 secfilt[Nsec].sMap = apstats->sigma;429 secfilt[Nsec].NusedAp = Nranking ;430 } 431 int minRankAper = (Nranking > 0) ? results->aperData[Nsec].ranking[0] : 10;442 int NrankingAPER = MAG_STATS_BY_RANKING (&results->aperData[Nsec], apstats); 443 if (NrankingAPER) { 444 secfilt[Nsec].MapChp = apstats->mean; 445 secfilt[Nsec].dMapChp = apstats->error; 446 secfilt[Nsec].sMapChp = apstats->sigma; 447 secfilt[Nsec].NusedAp = NrankingAPER; 448 } 449 int minRankAper = (NrankingAPER > 0) ? results->aperData[Nsec].ranking[0] : 10; 432 450 markMeasureByRanking (&results->aperData[Nsec], measure, minRankAper, ID_MEAS_PHOTOM_APER, ID_MEAS_MASKED_APER); 433 434 StatType *kronstats = &results->kronstats;435 Nranking = MAG_STATS_BY_RANKING (&results->kronData[Nsec], kronstats);436 if (Nranking) {437 secfilt[Nsec].Mkron = kronstats->mean;438 secfilt[Nsec].dMkron = kronstats->error;439 secfilt[Nsec].sMkron = kronstats->sigma;440 secfilt[Nsec].NusedKron = Nranking;441 }442 int minRankKron = (Nranking > 0) ? results->kronData[Nsec].ranking[0] : 10;443 markMeasureByRanking (&results->kronData[Nsec], measure, minRankKron, ID_MEAS_PHOTOM_KRON, ID_MEAS_MASKED_KRON);444 451 445 452 // does this object appear extended in > 50% of measurements? … … 518 525 // 2) select the BEST detections per filter (regardless of PRIMARY) 519 526 // 3) apply the zero point and AB->Jy transformations 527 528 // I calculate McalAPER and McalPSF independently for stacks. I use McalAPER for Mkron 529 // and Map, and McalPSF for Mpsf. Note in StarOps.c:setMcalOutput I am setting 530 // measure->McalAPER to image->McalPSF for chips and warps, but not stacks 531 520 532 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr) { 521 533 … … 528 540 SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt]; 529 541 530 off_t k; 531 532 float Mcal = 0, Mmos = 0, Mgrid = 0, Finst = 0; 542 float McalPSF = 0, McalAPER = 0, Mmos = 0, Mgrid = 0; 533 543 534 544 // set the primary projection cell and skycell for this coordinate … … 546 556 int haveStackObject = FALSE; 547 557 548 int Ns; 549 for (Ns = 0; Ns < Nphotcodes; Ns++) { 558 for (int Ns = 0; Ns < Nphotcodes; Ns++) { 550 559 551 560 int thisCode = photcodes[Ns][0].code; … … 556 565 int haveStack = FALSE; 557 566 558 float psfQFbest = 0.0;559 560 off_t stackBestMeasure = -1;561 off_t stackPrimaryMeasure = -1;562 563 567 int isBad = FALSE; 564 568 int isSuspect = FALSE; 565 569 566 int Nstack = 0; // number for this photcode 567 int NstackDet = 0; // number for this photcode 568 570 int NstackMeas = 0; // number of stack measurements for this photcode 571 int NstackDet = 0; // number of stack detections for this photcode (not forced) 572 573 int primaryLevelMax = 0; 574 off_t primaryEntryMax = -1; 575 float primaryValueMax = 0.0; 576 577 int bestLevelMax = 0; 578 off_t bestEntryMax = -1; 579 float bestValueMax = 0.0; 580 581 int Nprimary = 0; 582 583 // reset all stack-related values for this secfilt: 569 584 secfilt[Nsec].stackBestOff = -1; 570 585 secfilt[Nsec].stackPrmryOff = -1; 571 572 off_t meas = measureOffset; 573 for (k = 0; k < Nmeasure; k++, meas++) { 586 secfilt[Nsec].FpsfStk = NAN; 587 secfilt[Nsec].dFpsfStk = NAN; 588 secfilt[Nsec].FkronStk = NAN; 589 secfilt[Nsec].dFkronStk = NAN; 590 secfilt[Nsec].FapStk = NAN; 591 secfilt[Nsec].dFapStk = NAN; 592 secfilt[Nsec].MpsfStk = NAN; 593 secfilt[Nsec].MkronStk = NAN; 594 secfilt[Nsec].MapStk = NAN; 595 secfilt[Nsec].Nstack = 0; 596 secfilt[Nsec].NstackDet = 0; 597 secfilt[Nsec].flags &= ~ID_SECF_STACK_FLAGS; // reset the stack flags 598 599 for (off_t k = 0; k < Nmeasure; k++) { 574 600 575 601 // only examine gpc1 stack data … … 581 607 if (code->equiv != thisCode) { continue; } 582 608 583 Nstack ++;584 if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++; 609 NstackMeas ++; 610 if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++; // 0x04 = PM_SOURCE_MODE2_MATCHED 585 611 586 612 // clear this bit for all measurements … … 590 616 haveStack = TRUE; 591 617 haveStackObject = TRUE; 618 619 // if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad); 620 621 int isPrimary = FALSE; 592 622 593 // ** find the PRIMARY measurement594 595 // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement is from the596 // primary skycell for this position597 if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {598 stackPrimaryMeasure = k; 623 // ** is this a PRIMARY measurement? (there may be more than one) 624 625 // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement 626 // is from the primary skycell for this position. (note that MatchImageSkycellID 627 // requires the entry in the full Measure table, not just this object) 628 if (MatchImageSkycellID (measureOffset + k, cat, tessID, projectID, skycellID)) { 599 629 measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY; 600 secfilt[Nsec].stackPrmryOff = meas; 601 myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range"); 602 } 603 604 // ** now choose the BEST measurements (may also be PRIMARY) 605 606 // ensure that we at least have a single best measure 607 if (stackBestMeasure == -1) stackBestMeasure = k; 608 609 // choose the best psfQFperf value for the BEST measurement 610 if (isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > psfQFbest)) { 611 psfQFbest = measure[k].psfQFperf; 612 stackBestMeasure = k; 613 } 614 // ... UNLESS psfQFperf > 0.98 for the primary, in which case just use the primary. 615 if ((measure[k].dbFlags & ID_MEAS_STACK_PRIMARY) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.98)) { 616 psfQFbest = 1000; // force this to be the best entry 617 stackBestMeasure = k; 618 } 619 620 if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad); 621 630 isPrimary = TRUE; 631 Nprimary ++; 632 } 633 634 // soften the error floor (can dM be 0.0?) 635 // XXX EAM : this was int SNvalue -- isfinite(SNvalue) would always be finite 636 float SNvalue = isfinite(measure[k].dM) ? 1.0 / hypot (measure[k].dM, MIN_ERROR) : NAN; 637 int psfQFperfAboveLimit = isfinite(SNvalue) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.95); 638 639 // ** determine the BEST level 640 int bestLevel = 0; 641 if (!isPrimary && !psfQFperfAboveLimit) bestLevel = 1; 642 if ( isPrimary && !psfQFperfAboveLimit) bestLevel = 2; 643 if (!isPrimary && psfQFperfAboveLimit) bestLevel = 3; 644 if ( isPrimary && psfQFperfAboveLimit) bestLevel = 4; 645 646 // here is the rule for choosing the best value: 647 float bestValue = (bestLevel > 2) ? SNvalue : measure[k].psfQFperf; 648 649 // if we have not reached this level before, set the new level 650 if (bestLevelMax < bestLevel) { 651 bestValueMax = bestValue; 652 bestLevelMax = bestLevel; 653 bestEntryMax = k; 654 } 655 // if we have reached this level before, set the new value if we beat the old one 656 if ((bestLevelMax == bestLevel) && (bestValueMax < bestValue)) { 657 bestValueMax = bestValue; 658 bestEntryMax = k; 659 } 660 myAssert (bestEntryMax > -1, "this should not happen"); 661 662 // ** determine the PRIMARY level 663 int primaryLevel = 0; 664 if ( isPrimary && !psfQFperfAboveLimit) primaryLevel = 1; 665 if ( isPrimary && psfQFperfAboveLimit) primaryLevel = 2; 666 667 // here is the rule for choosing the PRIMARY value: 668 float primaryValue = 0.0; 669 if (primaryLevel == 1) { primaryValue = measure[k].psfQFperf; } 670 if (primaryLevel == 2) { primaryValue = SNvalue; } 671 672 // if we have not reached this level before, set the new level 673 if (isPrimary && (primaryLevelMax < primaryLevel)) { 674 primaryValueMax = primaryValue; 675 primaryLevelMax = primaryLevel; 676 primaryEntryMax = k; 677 } 678 // if we have reached this level before, set the new value if we beat the old one 679 if (isPrimary && (primaryLevelMax == primaryLevel) && (primaryValueMax < primaryValue)) { 680 primaryValueMax = primaryValue; 681 primaryEntryMax = k; 682 } 683 } 684 685 // if we do not have a stack measurement for this photcode, skip everything below 686 if (!haveStack) continue; 687 688 // now we have a BEST and a PRIMARY entry (may be the same entry) 689 690 off_t meas = bestEntryMax; 691 off_t measSeq = meas + measureOffset; 692 693 myAssert (meas >= 0, "this should not happen"); 694 695 // measurements without an image are either external reference photometry or 696 // data for which the associated image has not been loaded (probably because of 697 // overlaps). we only want measurements associated with stack images in this loop 698 699 // match measurement to its image (this is just a check, right?) 700 if (getImageEntry (measSeq, cat) < 0) { 622 701 // measurements without an image are either external reference photometry or 623 702 // data for which the associated image has not been loaded (probably because of 624 // overlaps). we only want measurements associated with stack images in this loop 625 626 // match measurement to its image (this is just a check, right?) 627 if (getImageEntry (meas, cat) < 0) { 628 // measurements without an image are either external reference photometry or 629 // data for which the associated image has not been loaded (probably because of 630 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 631 Mmos = Mgrid = 0; 632 Mcal = measure[k].Mcal; // check that this is zero for loaded REF value 633 } else { 634 Mcal = getMcal_alt (meas, cat, flatcorr, measure[k].Xccd, measure[k].Yccd); 635 if (isnan(Mcal)) SKIP_THIS_MEAS_STACK(Ncal); 636 Mmos = getMmos (meas, cat); 637 if (isnan(Mmos)) SKIP_THIS_MEAS_STACK(Nmos); 638 Mgrid = getMgrid (meas, cat); 639 if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid); 640 } 641 642 // NOTE: negative and insignificant flux values are allowed, but not NAN flux values 643 Finst = PhotFluxInst (&measure[k], MAG_CLASS_PSF); 644 if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst); 645 646 // data quality assessment 647 isBad |= (measure[k].photFlags & code->photomBadMask); 648 isBad |= (measure[k].psfQF < 0.85); 649 isBad |= isnan(measure[k].psfQF); 650 isBad |= measure[k].dM > 0.2; // S/N < 5.0 651 652 isSuspect |= (measure[k].photFlags & code->photomPoorMask); 653 isSuspect |= (measure[k].psfQFperf < 0.85); 654 } 655 656 if (!haveStack) continue; 657 658 if (!isSuspect && !isBad) { 659 NstackGood ++; 660 } 661 if (isSuspect && !isBad) { 662 NstackSuspect ++; 663 } 664 665 // measurements which are bad will not have a valid stack entry and are skipped 666 k = (stackBestMeasure >= 0) ? stackBestMeasure : stackPrimaryMeasure; 667 if (k < 0) continue; 668 669 // we are now populating stackDetectID not stack Image ID in secfilt 670 // ID = (stackPrimaryMeasureMin >= 0) ? stackPrimaryIDmin : stackCenterIDmin; 671 // ID = measure[k].extID; // for the stack, this is the stackDetectID 672 673 // get the zero point for the selected image 674 float zp = PhotZeroPoint (&measure[k], &average[0], &secfilt[0]) - (Mcal + Mmos + Mgrid); 703 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 704 McalPSF = measure[meas].McalPSF; // check that this is zero for loaded REF value 705 McalAPER = McalPSF; // check that this is zero for loaded REF value 706 Mmos = 0.0; 707 Mgrid = 0.0; 708 } else { 709 McalPSF = getMcal (measSeq, cat, MAG_CLASS_PSF); 710 McalAPER = USE_MCAL_PSF_FOR_STACK_APER ? getMcal (measSeq, cat, MAG_CLASS_PSF) : getMcal (measSeq, cat, MAG_CLASS_KRON); 711 Mmos = getMmos (measSeq, cat); 712 Mgrid = getMgrid (measSeq, cat); 713 } 714 715 // ** Here is the math to relate mag,zp to flux 675 716 676 717 // flux_cgs : erg sec^1 cm^-2 Hz^-1 … … 703 744 // flux_Jy = flux_inst * ten(-0.4*ZP + 3.56) 704 745 746 // get the zero point for the selected image 747 // Use a different zero point for the PSF-like and APERTURE-like magnitudes 748 float zpPSF = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalPSF + Mmos + Mgrid); 749 float zpAPER = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalAPER + Mmos + Mgrid); 750 705 751 // zpFactor to go from instrumental flux to Janskies 706 float zpFactor = pow(10.0, -0.4*zp + 3.56); 752 float zpFactorPSF = pow(10.0, -0.4*zpPSF + 3.56); 753 float zpFactorAPER = pow(10.0, -0.4*zpAPER + 3.56); 707 754 708 755 // need to put in AB mag factor to get to Janskies (or uJy?) 709 secfilt[Nsec].FpsfStk = zpFactor * measure[k].FluxPSF;710 secfilt[Nsec].dFpsfStk = zpFactor * measure[k].dFluxPSF;711 secfilt[Nsec].FkronStk = zpFactor * measure[k].FluxKron;712 secfilt[Nsec].dFkronStk = zpFactor * measure[k].dFluxKron;713 secfilt[Nsec].FapStk = zpFactor * measure[k].FluxAp;756 secfilt[Nsec].FpsfStk = zpFactorPSF * measure[meas].FluxPSF; 757 secfilt[Nsec].dFpsfStk = zpFactorPSF * measure[meas].dFluxPSF; 758 secfilt[Nsec].FkronStk = zpFactorAPER * measure[meas].FluxKron; 759 secfilt[Nsec].dFkronStk = zpFactorAPER * measure[meas].dFluxKron; 760 secfilt[Nsec].FapStk = zpFactorAPER * measure[meas].FluxAp; 714 761 715 762 // NOTE: for PV3, apFluxErr is broken (see pmSourcePhotometry.c:245). we are going to 716 763 // use PSF flux error instead here: 717 // secfilt[Nsec].dFapStk = zpFactor * measure[k].dFluxAp;718 secfilt[Nsec].dFapStk = zpFactor * measure[k].dFluxPSF;764 // secfilt[Nsec].dFapStk = zpFactorAPER * measure[meas].dFluxAp; 765 secfilt[Nsec].dFapStk = zpFactorAPER * measure[meas].dFluxPSF; 719 766 720 767 // Jy to AB mags 721 secfilt[Nsec].MpsfStk = (measure[k].FluxPSF > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN; 722 secfilt[Nsec].MkronStk = (measure[k].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN; 723 secfilt[Nsec].MapStk = (measure[k].FluxAp > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN; 724 725 secfilt[Nsec].stackBestOff = k + measureOffset; 768 secfilt[Nsec].MpsfStk = (measure[meas].FluxPSF > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN; 769 secfilt[Nsec].MkronStk = (measure[meas].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN; 770 secfilt[Nsec].MapStk = (measure[meas].FluxAp > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN; 771 772 // record the measurement which gave the best value 773 secfilt[Nsec].stackBestOff = (bestEntryMax == -1) ? -1 : bestEntryMax + measureOffset; 726 774 myAssert (secfilt[Nsec].stackBestOff <= catalog[0].Nmeasure, "stackBestOff out of range"); 727 775 728 secfilt[Nsec].Nstack = Nstack; 776 // record the selected primary measurement 777 secfilt[Nsec].stackPrmryOff = (primaryEntryMax == -1) ? -1 : primaryEntryMax + measureOffset; 778 myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range"); 779 780 // this is the selected measurement used by secfilt[] 781 measure[meas].dbFlags |= ID_MEAS_STACK_PHOT_SRC; 782 if (Nprimary) { 783 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY; 784 if (Nprimary > 1) { 785 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY_MULTIPLE; 786 } 787 } 788 789 // stack measurement used for 'best' was a detection (not forced from the other bands) 790 if ((measure[bestEntryMax].photFlags2 & 0x00000004) == 0) { 791 secfilt[Nsec].flags |= ID_SECF_STACK_BESTDET; 792 } 793 794 // stack measurement used for 'primary' was a detection (not forced from the other bands) 795 if ((primaryEntryMax >= 0) && ((measure[primaryEntryMax].photFlags2 & 0x00000004) == 0)) { 796 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMDET; 797 } 798 799 secfilt[Nsec].flags |= ID_SECF_HAS_PS1_STACK; 800 801 // NOTE: negative and insignificant flux values are allowed, but not NAN flux values 802 // float Finst = PhotFluxInst (&measure[meas], MAG_CLASS_PSF); 803 804 // data quality assessment 805 isBad |= (measure[meas].photFlags & photcodes[Ns][0].photomBadMask); 806 isBad |= (measure[meas].psfQF < 0.85); 807 isBad |= isnan(measure[meas].psfQF); 808 isBad |= measure[meas].dM > 0.2; // S/N < 5.0 809 810 isSuspect |= (measure[meas].photFlags & photcodes[Ns][0].photomPoorMask); 811 isSuspect |= (measure[meas].psfQFperf < 0.85); 812 813 if (!isSuspect && !isBad) { 814 NstackGood ++; 815 } 816 if (isSuspect && !isBad) { 817 NstackSuspect ++; 818 } 819 820 secfilt[Nsec].Nstack = NstackMeas; 729 821 secfilt[Nsec].NstackDet = NstackDet; 730 822 731 // this is the measurement used by secfilt[]732 measure[k].dbFlags |= ID_MEAS_STACK_PHOT_SRC;733 if (k == stackPrimaryMeasure) {734 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY;735 }736 737 // stack measurement used for 'best' was a detection (not forced from the other bands)738 if ((measure[k].photFlags2 & 0x00000004) == 0) {739 secfilt[Nsec].flags |= ID_SECF_STACK_BESTDET;740 }741 // stack measurement used for 'primary' was a detection (not forced from the other bands)742 if ((stackPrimaryMeasure >= 0) && ((measure[stackPrimaryMeasure].photFlags2 & 0x00000004) == 0)) {743 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMDET;744 }745 746 secfilt[Nsec].flags |= ID_SECF_HAS_PS1_STACK;747 823 } // Nsecfilt loop 748 824 … … 755 831 756 832 int PrimaryIsBest = TRUE; 757 for ( Ns = 0; Ns < Nphotcodes; Ns++) {833 for (int Ns = 0; Ns < Nphotcodes; Ns++) { 758 834 if (!(secfilt[Ns].flags & ID_SECF_HAS_PS1_STACK)) continue; // no stack detection in PS1, nothing is best 759 835 if (secfilt[Ns].flags & ID_SECF_STACK_PRIMARY) continue; // primary stack detection is best … … 780 856 // * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr 781 857 // analysis is done on flux, not mags (as the faintest objects will be nearly insignificant) 858 859 // Although I calculate McalAPER for exposures, I am only using McalPSF for warps.. 860 // Note in StarOps.c:setMcalOutput I am setting measure->McalAPER to image->McalPSF for 861 // chips and warps, but not stacks 862 782 863 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) { 783 864 OHANA_UNUSED_PARAM(flatcorr); … … 857 938 // data for which the associated image has not been loaded (probably because of 858 939 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 859 Mcal = measure[k].Mcal ; // check that this is zero for loaded REF value940 Mcal = measure[k].McalPSF; // check that this is zero for loaded REF value 860 941 } else { 861 // use getMcal not getMcal_alt? 862 Mcal = getMcal_alt (meas, cat, NULL, measure[k].Xccd, measure[k].Yccd); 863 // Mcal = getMcal (meas, cat); 942 Mcal = getMcal (meas, cat, MAG_CLASS_PSF); 864 943 if (isnan(Mcal)) SKIP_THIS_MEAS(Ncal); 865 944 } -
branches/czw_branch/20170908/Ohana/src/relphot/src/setMrelFinal.c
r39632 r40477 65 65 if (catalog[0].measure[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { 66 66 if (!KEEP_UBERCAL) { 67 catalog[0].measure[m].Mcal = 0.0; 67 catalog[0].measure[m].McalPSF = 0.0; 68 catalog[0].measure[m].McalAPER = 0.0; 68 69 catalog[0].measure[m].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL; 69 70 } 70 71 } else { 71 72 if (RESET_ZEROPTS && (getImageEntry (m, 0) >= 0)) { 72 catalog[0].measure[m].Mcal = 0.0; 73 catalog[0].measure[m].McalPSF = 0.0; 74 catalog[0].measure[m].McalAPER = 0.0; 73 75 } 74 76 } … … 105 107 ALLOCATE (catalog[0].measureRank, char, catalog[0].Nmeasure); 106 108 setMeasureRank (catalog); 107 setMrelOutput (catalog, 1, flatcorr); // sets the values secfilt.M = <measure.M + measure.Mflat - image.Mcal>109 setMrelOutput (catalog, 1, flatcorr); // sets the values secfilt.MpsfChp = <measure.M + measure.Mflat - image.Mcal> 108 110 setMcalOutput (catalog, 1, flatcorr); // sets measure.Mcal = image.Mcal 109 111 … … 226 228 off_t Nim = getImageEntry (m, 0); 227 229 if (Nim > -1) { 228 if (isnan(getMcal (m, 0, flatcorr, catalog))) goto skip;230 if (isnan(getMcal (m, 0, MAG_CLASS_PSF))) goto skip; 229 231 if (isnan(getMmos (m, 0))) goto skip; 230 232 } -
branches/czw_branch/20170908/Ohana/src/relphot/src/share_image_mags.c
r36630 r40477 74 74 continue; 75 75 } 76 images[seq].Mcal = image_mags[i].Mcal; 76 images[seq].McalPSF = image_mags[i].McalPSF; 77 images[seq].McalAPER = image_mags[i].McalAPER; 77 78 images[seq].dMcal = image_mags[i].dMcal; 78 79 images[seq].dMagSys = image_mags[i].dMagSys; 79 images[seq]. Xm = image_mags[i].Xm;80 images[seq].McalChiSq = image_mags[i].McalChiSq; 80 81 images[seq].nFitPhotom = image_mags[i].nFitPhotom; 81 82 images[seq].flags = image_mags[i].flags; … … 91 92 int set_image_mags (ImageMag *image_mags, Image *image) { 92 93 93 image_mags->Mcal = image->Mcal; 94 image_mags->McalPSF = image->McalPSF; 95 image_mags->McalAPER = image->McalAPER; 94 96 image_mags->dMcal = image->dMcal; 95 97 image_mags->dMagSys = image->dMagSys; 96 image_mags-> Xm = image->Xm;98 image_mags->McalChiSq = image->McalChiSq; 97 99 image_mags->nFitPhotom = image->nFitPhotom; 98 100 image_mags->flags = image->flags; -
branches/czw_branch/20170908/Ohana/src/relphot/src/share_mean_mags.c
r39457 r40477 111 111 if (Nsec < 0) continue; 112 112 113 catalog[catSeq].secfilt[objSeq*Nsecfilt + Nsec].M = meanmags[i].M;113 catalog[catSeq].secfilt[objSeq*Nsecfilt + Nsec].MpsfChp = meanmags[i].M; 114 114 } 115 115 free (meanmags); … … 122 122 int set_mean_mags (MeanMag *meanmags, AverageTiny *average, SecFilt *secfilt, int Nsec) { 123 123 124 meanmags->M = secfilt->M ;125 meanmags->dM = secfilt->dM ;124 meanmags->M = secfilt->MpsfChp; 125 meanmags->dM = secfilt->dMpsfChp; 126 126 meanmags->Mchisq = secfilt->Mchisq; 127 127 meanmags->Nsec = Nsec; // key to secfilt entry -
branches/czw_branch/20170908/Ohana/src/relphot/src/synthetic_mags.c
r39457 r40477 37 37 // (r - i > 0.5) : w = r + 0.268 - 0.435 (r-i) - 0.078(r-i)^2 38 38 39 float Mr = secfilt[NSr].M ;40 float Mi = secfilt[NSi].M ;39 float Mr = secfilt[NSr].MpsfChp; 40 float Mi = secfilt[NSi].MpsfChp; 41 41 42 42 if (!isfinite(Mr)) return FALSE;
Note:
See TracChangeset
for help on using the changeset viewer.
