Changeset 31450
- Timestamp:
- May 5, 2011, 10:43:45 AM (15 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 30 edited
- 3 copied
-
dvomerge/src/dvo_image_merge_dbs.c (modified) (1 diff)
-
dvomerge/src/dvoverify.c (modified) (4 diffs)
-
libdvo/include/dvo.h (modified) (4 diffs)
-
libdvo/src/dvo_catalog_split.c (modified) (1 diff)
-
libdvo/src/dvo_photcode_ops.c (modified) (1 diff)
-
opihi/cmd.data/Makefile (modified) (1 diff)
-
opihi/cmd.data/gridify.c (modified) (3 diffs)
-
opihi/cmd.data/init.c (modified) (2 diffs)
-
opihi/cmd.data/vshift.c (copied) (copied from branches/eam_branches/ipp-20110404/Ohana/src/opihi/cmd.data/vshift.c )
-
opihi/dvo/Makefile (modified) (1 diff)
-
opihi/dvo/avextract.c (modified) (3 diffs)
-
opihi/dvo/init.c (modified) (2 diffs)
-
opihi/dvo/objectcoverage.c (copied) (copied from branches/eam_branches/ipp-20110404/Ohana/src/opihi/dvo/objectcoverage.c )
-
photdbc/src/make_subcatalog.c (modified) (2 diffs)
-
relastro/src/UpdateObjects.c (modified) (1 diff)
-
relphot/doc/allsky.txt (copied) (copied from branches/eam_branches/ipp-20110404/Ohana/src/relphot/doc/allsky.txt )
-
relphot/include/relphot.h (modified) (4 diffs)
-
relphot/src/GridOps.c (modified) (18 diffs)
-
relphot/src/ImageOps.c (modified) (16 diffs)
-
relphot/src/MosaicOps.c (modified) (19 diffs)
-
relphot/src/StarOps.c (modified) (31 diffs)
-
relphot/src/args.c (modified) (1 diff)
-
relphot/src/bcatalog.c (modified) (10 diffs)
-
relphot/src/global_stats.c (modified) (1 diff)
-
relphot/src/initialize.c (modified) (3 diffs)
-
relphot/src/load_images.c (modified) (1 diff)
-
relphot/src/plot_scatter.c (modified) (1 diff)
-
relphot/src/reload_catalogs.c (modified) (4 diffs)
-
relphot/src/relphot.c (modified) (10 diffs)
-
relphot/src/relphot_objects.c (modified) (3 diffs)
-
relphot/src/select_images.c (modified) (7 diffs)
-
relphot/src/setExclusions.c (modified) (3 diffs)
-
relphot/src/setMrelFinal.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c
r29938 r31450 202 202 if (newID == 0) { 203 203 fprintf (stderr, "cannot find image ID "OFF_T_FMT"\n", oldID); 204 exit (2);204 // exit (2); 205 205 } 206 206 catalog[0].measure[i].imageID = newID; -
trunk/Ohana/src/dvomerge/src/dvoverify.c
r31160 r31450 148 148 int VerifyTableFile (char *filename) { 149 149 150 int status ;150 int status, Next; 151 151 off_t Nbytes; 152 152 Header header; … … 205 205 // scan all extentions 206 206 Nbytes = 0; 207 Next = -1; 207 208 if (DEBUG) fprintf (stderr, "sizes: ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nbytes, fileStats.st_size); 208 209 while (Nbytes < fileStats.st_size) { … … 210 211 // Check on the PHU 211 212 if (!gfits_fread_header (file, &header)) { 212 fprintf (stderr, "unable to read PHU header for %s\n", filename); 213 if (Next == -1) { 214 fprintf (stderr, "unable to read PHU header for %s\n", filename); 215 } else { 216 fprintf (stderr, "unable to read header for %s, extension %d (or file has excess bytes)\n", filename, Next); 217 } 213 218 fclose(file); 214 219 return (FALSE); … … 243 248 } 244 249 } 250 Next ++; 245 251 } 246 252 if (DEBUG) fprintf (stderr, "file is good: %s\n", filename); -
trunk/Ohana/src/libdvo/include/dvo.h
r31160 r31450 20 20 DVO_FORMAT_PS1_DEV_2, 21 21 DVO_FORMAT_PS1_DEV_3, 22 DVO_FORMAT_PS1_REF, 22 23 DVO_FORMAT_PS1_V1, 23 24 DVO_FORMAT_PS1_V2, 24 DVO_FORMAT_PS1_REF25 25 } DVOTableFormat; 26 26 … … 210 210 } PhotCodeData; 211 211 212 // a reduced-subset structure for relphot 213 typedef struct { 214 double R; 215 double D; 216 unsigned short Nmeasure; 217 int measureOffset; 218 uint32_t flags; 219 } AverageTiny; 220 221 // a reduced-subset structure for relphot 222 typedef struct { 223 float dR; 224 float dD; 225 float M; 226 float Mcal; 227 float dM; 228 float airmass; 229 float Xccd; 230 float Yccd; 231 float dt; 232 int t; 233 unsigned int averef; 234 unsigned int imageID; 235 unsigned int dbFlags; 236 unsigned short photcode; 237 } MeasureTiny; 238 212 239 /* a catalog contains this data */ 213 240 typedef struct Catalog { … … 226 253 off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */ 227 254 off_t Naves_off, Nmeas_off, Nmiss_off, Nsecf_off; /* index of first loaded data value */ 255 256 // note that we use these for the full-sky relphot analysis 257 AverageTiny *averageT; 258 MeasureTiny *measureT; 228 259 229 260 /* the Nsecf_* values above are number of table rows (eg, Naverage*Nsecfilt) */ … … 330 361 int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color); 331 362 363 float PhotInstTiny (MeasureTiny *measure); 364 float PhotCatTiny (MeasureTiny *measure); 365 float PhotAperTiny (MeasureTiny *measure); 366 float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt); 367 float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt); 368 float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code); 369 float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt); 370 float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure); 371 float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt); 372 float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt); 373 374 float PhotColorForCodeTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code); 375 int PhotColorTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, int c1, int c2, double *color); 376 377 332 378 PhotCodeData *GetPhotcodeTable (void); 333 379 void SetPhotcodeTable (PhotCodeData *); -
trunk/Ohana/src/libdvo/src/dvo_catalog_split.c
r29938 r31450 448 448 catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat); 449 449 if (Nmeasure != Nrows) { 450 fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nmeasure, Nrows); 450 // XXX this condition denotes the eof has been reached; not an error or a warning 451 // fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nmeasure, Nrows); 451 452 } 452 453 gfits_free_header (&header); -
trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c
r29938 r31450 536 536 return (TRUE); 537 537 } 538 539 /******** alternate photometry conversion functions using MeasureTiny and AverageTiny *********/ 540 float PhotInstTiny (MeasureTiny *measure) { 541 542 int Np; 543 float M; 544 545 Np = photcodes[0].hashcode[measure[0].photcode]; 546 if (Np == -1) return (NAN); 547 548 if (photcodes[0].code[Np].type == PHOT_REF) { 549 M = measure[0].M; 550 return (M); 551 } 552 553 M = measure[0].M - measure[0].dt - ZERO_POINT; 554 555 return (M); 556 557 } 558 559 float PhotCatTiny (MeasureTiny *measure) { 560 561 int Np; 562 float Mcat; 563 PhotCode *code; 564 565 Np = photcodes[0].hashcode[measure[0].photcode]; 566 if (Np == -1) return (NAN); 567 568 if (photcodes[0].code[Np].type == PHOT_REF) { 569 Mcat = measure[0].M; 570 return (Mcat); 571 } 572 code = &photcodes[0].code[Np]; 573 Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C; 574 575 return (Mcat); 576 } 577 578 # if (0) 579 float PhotAperTiny (MeasureTiny *measure) { 580 581 int Np; 582 float Mcat; 583 PhotCode *code; 584 585 Np = photcodes[0].hashcode[measure[0].photcode]; 586 if (Np == -1) return (NAN); 587 588 if (photcodes[0].code[Np].type == PHOT_REF) { 589 Mcat = measure[0].Map; 590 return (Mcat); 591 } 592 code = &photcodes[0].code[Np]; 593 Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C; 594 595 return (Mcat); 596 } 597 # endif 598 599 float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) { 600 601 int i, Np; 602 float Mcat, Mcol, Msys, mc, Mc; 603 PhotCode *code; 604 605 Np = photcodes[0].hashcode[measure[0].photcode]; 606 if (Np == -1) return (NAN); 607 608 if (photcodes[0].code[Np].type == PHOT_REF) { 609 Msys = measure[0].M; 610 return (Msys); 611 } 612 code = &photcodes[0].code[Np]; 613 Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C; 614 615 /* for DEP, color must be made of PRI/SEC */ 616 mc = PhotColorForCodeTiny (average, secfilt, NULL, code); 617 if (isnan(mc)) return (Mcat); 618 mc = mc - SCALE*code[0].dX; 619 620 Mc = mc; 621 Mcol = 0; 622 for (i = 0; i < code[0].Nc; i++) { 623 Mcol += code[0].X[i]*Mc; 624 Mc *= mc; 625 } 626 Msys = Mcat + Mcol; 627 return (Msys); 628 } 629 630 float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) { 631 632 int i, Np; 633 float Mcat, Mcol, Mrel, mc, Mc; 634 PhotCode *code; 635 636 Np = photcodes[0].hashcode[measure[0].photcode]; 637 if (Np == -1) return (NAN); 638 639 if (photcodes[0].code[Np].type == PHOT_REF) { 640 Mcat = measure[0].M; 641 return (Mcat); 642 } 643 code = &photcodes[0].code[Np]; 644 Mrel = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal; 645 646 /* for DEP, color must be made of PRI/SEC */ 647 mc = PhotColorForCodeTiny (average, secfilt, NULL, code); 648 if (isnan(mc)) return (Mrel); 649 mc = mc - SCALE*code[0].dX; 650 651 Mc = mc; 652 Mcol = 0; 653 for (i = 0; i < code[0].Nc; i++) { 654 Mcol += code[0].X[i]*Mc; 655 Mc *= mc; /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */ 656 } 657 Mrel += Mcol; 658 return (Mrel); 659 } 660 661 /* return calibrated magnitude from measure for given photcode */ 662 float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code) { 663 664 int i, Np; 665 float Mcal, Mrel, Mcol, mc, Mc; 666 667 if (code == NULL) return NAN; 668 669 /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */ 670 Np = photcodes[0].hashcode[thisone[0].photcode]; 671 if (Np == -1) return (NAN); 672 673 if (photcodes[0].code[Np].type == PHOT_REF) { 674 Mrel = thisone[0].M; 675 return (Mrel); 676 } 677 if (code[0].code != photcodes[0].code[Np].equiv) return (NAN); 678 679 Mcal = PhotRelTiny (thisone, average, secfilt) + SCALE*code[0].C; 680 681 mc = PhotColorForCodeTiny (average, secfilt, measure, code); 682 if (isnan(mc)) return (Mcal); 683 mc = mc - SCALE*code[0].dX; 684 685 Mc = mc; 686 Mcol = 0; 687 for (i = 0; i < code[0].Nc; i++) { 688 Mcol += code[0].X[i]*Mc; 689 Mc *= mc; 690 } 691 Mcal += Mcol; 692 return (Mcal); 693 } 694 695 /* color term may not use DEP magnitude */ 696 float PhotColorForCodeTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code) { 697 698 int i, Ns1, Ns2, Ns; 699 float m1, m2, mc; 700 PhotCode *color; 701 702 m1 = m2 = NAN; 703 704 if (measure == NULL) { 705 Ns1 = photcodes[0].hashNsec[code[0].c1]; 706 Ns2 = photcodes[0].hashNsec[code[0].c2]; 707 708 m1 = (Ns1 == -1) ? NAN : secfilt[Ns1].M; 709 m2 = (Ns2 == -1) ? NAN : secfilt[Ns2].M; 710 mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2); 711 return (mc); 712 } 713 714 /* find magnitude matching first color term */ 715 color = GetPhotcodebyCode (code[0].c1); 716 if (color == NULL) return (NAN); 717 if (color[0].type == PHOT_REF) { 718 for (i = 0; (i < average[0].Nmeasure) && (isnan(m1)); i++) { 719 if (measure[i].photcode == color[0].code) { 720 m1 = measure[i].M; 721 } 722 } 723 } else { 724 Ns = photcodes[0].hashNsec[color[0].code]; 725 m1 = (Ns == -1) ? NAN : secfilt[Ns].M; 726 } 727 728 /* find magnitude matching second color term */ 729 color = GetPhotcodebyCode (code[0].c2); 730 if (color == NULL) return (NAN); 731 if (color[0].type == PHOT_REF) { 732 for (i = 0; (i < average[0].Nmeasure) && (isnan(m2)); i++) { 733 if (measure[i].photcode == color[0].code) { 734 m2 = measure[i].M; 735 } 736 } 737 } else { 738 Ns = photcodes[0].hashNsec[color[0].code]; 739 m2 = (Ns == -1) ? NAN : secfilt[Ns].M; 740 } 741 mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2); 742 return (mc); 743 } 744 745 /* return calibrated magnitude from average/secfilt for given photcode */ 746 float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure) { 747 748 int i, Ns; 749 float Mave, Mref, Mcol, mc; 750 double Mc; 751 752 if (code == NULL) return NAN; 753 754 Ns = photcodes[0].hashNsec[code[0].code]; 755 Mave = (Ns == -1) ? NAN : secfilt[Ns].M; 756 Mref = Mave + SCALE*code[0].C; 757 758 mc = PhotColorForCodeTiny (average, secfilt, measure, code); 759 if (isnan(mc)) return (Mref); 760 mc = mc - SCALE*code[0].dX; 761 762 Mc = mc; 763 Mcol = 0; 764 for (i = 0; i < code[0].Nc; i++) { 765 Mcol += code[0].X[i]*Mc; 766 Mc *= mc; /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */ 767 } 768 Mref += Mcol; 769 return (Mref); 770 } 771 772 /***/ 773 float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) { 774 775 int Ns; 776 float Mave; 777 778 if (code == NULL) return NAN; 779 780 Ns = photcodes[0].hashNsec[code[0].code]; 781 Mave = (Ns == -1) ? NAN : secfilt[Ns].M; 782 return (Mave); 783 } 784 785 float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) { 786 787 int Ns; 788 float dM; 789 790 if (code == NULL) return NAN; 791 792 Ns = photcodes[0].hashNsec[code[0].code]; 793 dM = (Ns == -1) ? NAN : secfilt[Ns].dM; 794 return (dM); 795 } 796 797 // XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short) 798 float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) { 799 800 int Ns; 801 short Mi; 802 float Xm; 803 804 if (code == NULL) return NAN; 805 806 Ns = photcodes[0].hashNsec[code[0].code]; 807 Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm; 808 Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi); 809 return (Xm); 810 } 811 812 /* given a photcode pair c1 & c2, return the color of this star (NaN if not found) */ 813 int PhotColorTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, int c1, int c2, double *color) { 814 815 int i, Ns; 816 double M1, M2, dM; 817 PhotCode *code; 818 819 code = GetPhotcodebyCode (c1); 820 if (code == NULL) return (FALSE); 821 if (code[0].type == PHOT_REF) { 822 for (i = 0; i < average[0].Nmeasure; i++) { 823 if (measure[i].photcode == c1) { 824 M1 = measure[i].M; 825 goto filter1; 826 } 827 } 828 return (FALSE); 829 } else { 830 Ns = photcodes[0].hashNsec[code[0].code]; 831 M1 = (Ns == -1) ? NAN : secfilt[Ns].M; 832 } 833 834 filter1: 835 code = GetPhotcodebyCode (c2); 836 if (code == NULL) return (FALSE); 837 if (code[0].type == PHOT_REF) { 838 for (i = 0; i < average[0].Nmeasure; i++) { 839 if (measure[i].photcode == c2) { 840 M2 = measure[i].M; 841 goto filter2; 842 } 843 } 844 return (FALSE); 845 } else { 846 Ns = photcodes[0].hashNsec[code[0].code]; 847 M2 = (Ns == -1) ? NAN : secfilt[Ns].M; 848 } 849 850 filter2: 851 852 dM = M1 - M2; 853 *color = dM; 854 855 return (TRUE); 856 } 857 /***********************************************/ 538 858 539 859 // Create a map between the secfilt values from one photcode table to another -
trunk/Ohana/src/opihi/cmd.data/Makefile
r29938 r31450 141 141 $(SRC)/vpop.$(ARCH).o \ 142 142 $(SRC)/vroll.$(ARCH).o \ 143 $(SRC)/vshift.$(ARCH).o \ 143 144 $(SRC)/vsmooth.$(ARCH).o \ 144 145 $(SRC)/vstats.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/gridify.c
r20936 r31450 4 4 5 5 int i, Nx, Ny, Xb, Yb, Normalize, N; 6 float Xmin, Xmax, dX, Ymin, Ymax, dY ;6 float Xmin, Xmax, dX, Ymin, Ymax, dY, initValue; 7 7 float *buf, *val; 8 8 int *Nval; … … 15 15 remove_argument (N, &argc, argv); 16 16 Normalize = FALSE; 17 } 18 19 initValue = 0.0; 20 if ((N = get_argument (argc, argv, "-init-value"))) { 21 remove_argument (N, &argc, argv); 22 initValue = atof(argv[N]); 23 remove_argument (N, &argc, argv); 17 24 } 18 25 … … 69 76 buf = (float *) bf[0].matrix.buffer; 70 77 for (i = 0; i < Nx*Ny; i++) { 78 buf[i] = initValue; 71 79 if (Normalize) { 72 80 if (Nval[i] == 0) { 73 buf[i] = 0;74 81 continue; 75 82 } -
trunk/Ohana/src/opihi/cmd.data/init.c
r29938 r31450 130 130 int vstats PROTO((int, char **)); 131 131 int vroll PROTO((int, char **)); 132 int vshift PROTO((int, char **)); 132 133 int vpop PROTO((int, char **)); 133 134 int vsmooth PROTO((int, char **)); … … 274 275 {1, "vmaxwell", vmaxwell, "fit a Maxwellian to a vector"}, 275 276 {1, "vpop", vpop, "remove first element of a vector"}, 276 {1, "vroll", vroll, "roll vector elements"}, 277 {1, "vroll", vroll, "roll vector elements by 1 entry"}, 278 {1, "vshift", vshift, "shift vector elements by arbitrary amount"}, 277 279 {1, "vsmooth", vsmooth, "Gaussian smooth of a vector"}, 278 280 {1, "vstats", vstats, "statistics on a vector"}, -
trunk/Ohana/src/opihi/dvo/Makefile
r27594 r31450 80 80 $(SRC)/mextract.$(ARCH).o \ 81 81 $(SRC)/mmextract.$(ARCH).o \ 82 $(SRC)/objectcoverage.$(ARCH).o \ 82 83 $(SRC)/photcodes.$(ARCH).o \ 83 84 $(SRC)/pmeasure.$(ARCH).o \ -
trunk/Ohana/src/opihi/dvo/avextract.c
r30612 r31450 5 5 off_t i, j, n, m; 6 6 int N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack; 7 int Nsecfilt, mode, VERBOSE ;7 int Nsecfilt, mode, VERBOSE, needMeasures; 8 8 char **cstack, name[1024]; 9 9 void *Signal; … … 101 101 } 102 102 103 // check the requested fields : are all average/secfilt entries, or do we need measures? 104 needMeasures = FALSE; 105 for (i = 0; !needMeasures && (i < Nfields); i++) { 106 if (fields[i].magMode == MAG_NONE) continue; 107 if (fields[i].photcode == NULL) continue; // assert this? 108 if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE; 109 if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE; 110 } 111 103 112 // grab data from all selected sky regions 104 113 Signal = signal (SIGINT, handle_interrupt); … … 107 116 /* lock, load, unlock catalog */ 108 117 catalog.filename = skylist[0].filename[i]; 109 catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF; 118 catalog.catflags = LOAD_AVES | LOAD_SECF; 119 if (needMeasures) { 120 catalog.catflags |= LOAD_MEAS; 121 } 110 122 catalog.Nsecfilt = 0; 111 123 -
trunk/Ohana/src/opihi/dvo/init.c
r27594 r31450 40 40 int lightcurve PROTO((int, char **)); 41 41 int mextract PROTO((int, char **)); 42 int mmextract PROTO((int, char **)); 42 int mmextract PROTO((int, char **)); 43 int objectcoverage PROTO((int, char **)); 43 44 int pcat PROTO((int, char **)); 44 45 int photcodes PROTO((int, char **)); … … 92 93 {1, "mextract", mextract, "extract measure data values"}, 93 94 {1, "mmextract", mmextract, "extract joined measurements"}, 95 {1, "objectcoverage", objectcoverage, "plot catalog boundaries"}, 94 96 {1, "pcat", skycat, "plot catalog boundaries"}, 95 97 {1, "photcodes", photcodes, "list photometry codes"}, -
trunk/Ohana/src/photdbc/src/make_subcatalog.c
r30616 r31450 71 71 } 72 72 73 // if the input catalog is an old type, generate the catID entries: 74 if (catalog[0].catformat < DVO_FORMAT_PS1_V1) { 75 subcatalog[0].average[Naverage].catID = catalog[0].catID; 76 } 77 73 78 minMag = 32; 74 79 minSigma = 32; … … 127 132 subcatalog[0].measure[Nmeasure] = catalog[0].measure[offset]; 128 133 subcatalog[0].measure[Nmeasure].averef = Naverage; 134 135 // if the input catalog is an old type, generate the catID entries: 136 if (catalog[0].catformat < DVO_FORMAT_PS1_V1) { 137 subcatalog[0].measure[Nmeasure].catID = catalog[0].catID; 138 } 139 129 140 Nmeasure ++; 130 141 Nm ++; -
trunk/Ohana/src/relastro/src/UpdateObjects.c
r31160 r31450 189 189 coords.crval1 = R[0]; 190 190 coords.crval2 = D[0]; 191 Tmean /= (float) N; 191 192 if (FIT_TARGET == TARGET_HIGH_SPEED) { 193 Tmean = 0.5*(Tmax - Tmin); 194 } else { 195 Tmean /= (float) N; 196 } 192 197 193 198 XVERB = FALSE && (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY); -
trunk/Ohana/src/relphot/include/relphot.h
r30616 r31450 11 11 unsigned int start; 12 12 unsigned int stop; 13 short photcode; 13 14 float Mcal; 14 15 float dMcal; … … 85 86 int RELPHOT_GRID_BINNING; 86 87 87 PhotCode *photcode; 88 int PhotNsec; 89 int PhotSec; 88 int *photseclist; 89 int Nphotcodes; 90 PhotCode **photcodes; 91 // int PhotSec; 92 // int PhotNsec; 90 93 91 94 PhotCode *refPhotcode; 95 96 int MaxDensityUse; 97 double MaxDensityValue; 92 98 93 99 int AreaSelect; … … 213 219 StatType statsMosaicX PROTO((Catalog *catalog)); 214 220 StatType statsMosaicdM PROTO((Catalog *catalog)); 215 StatType statsStarN PROTO((Catalog *catalog, int Ncatalog ));216 StatType statsStarS PROTO((Catalog *catalog, int Ncatalog ));217 StatType statsStarX PROTO((Catalog *catalog, int Ncatalog ));221 StatType statsStarN PROTO((Catalog *catalog, int Ncatalog, int Nsec, int seccode)); 222 StatType statsStarS PROTO((Catalog *catalog, int Ncatalog, int Nsec)); 223 StatType statsStarX PROTO((Catalog *catalog, int Ncatalog, int Nsec)); 218 224 void wcatalog PROTO((Catalog *catalog)); 219 225 void wimages PROTO((void)); … … 223 229 void relphot_usage (void); 224 230 void relphot_help (int argc, char **argv); 231 232 off_t getImageByID (off_t ID); 233 234 int rationalize_mosaics (); 235 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog); 236 237 int populate_tiny_values (Catalog *catalog); 238 int free_tiny_values (Catalog *catalog); -
trunk/Ohana/src/relphot/src/GridOps.c
r28241 r31450 348 348 // sums for each star which touches as cell on both bases. 349 349 350 int Nsecfilt = GetPhotcodeNsecfilt (); 351 int thisCode = photcodes[0][0].code; 352 int Nsec = GetPhotcodeNsec(thisCode); 353 350 354 for (i = 0; i < Ngrid; i++) { 351 355 … … 362 366 mx = mlist[i][j]; 363 367 c = clist[i][j]; 364 n = catalog[c].measure [mx].averef;368 n = catalog[c].measureT[mx].averef; 365 369 366 370 // if we have already visited this star, skip the stuff below … … 369 373 370 374 // skip stars marked as BAD 371 if (catalog[c]. average[n].flags & STAR_BAD) {375 if (catalog[c].secfilt[n*Nsecfilt+Nsec].flags & STAR_BAD) { 372 376 Nrel ++; 373 377 continue; … … 389 393 390 394 // skip measurements marked as BAD 391 if (catalog[c].measure [m].dbFlags & MEAS_BAD) {395 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 392 396 Nbad ++; 393 397 continue; … … 410 414 // select the color- and airmass-corrected observed magnitude for this star 411 415 // XXX need to be able to turn off the color-correction until initial average mags are found 412 // Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]); 413 Msys = PhotCat (&catalog[c].measure[m]); 416 Msys = PhotCatTiny (&catalog[c].measureT[m]); 414 417 if (isnan(Msys)) { 415 418 Nsys++; … … 418 421 419 422 // mag-error for this measurement 420 Merr = MAX (catalog[c].measure [m].dM, MIN_ERROR);423 Merr = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 421 424 422 425 // Wsys = 1.0 / SQ(Merr); … … 528 531 if (!USE_GRID) return; 529 532 533 int Nsecfilt = GetPhotcodeNsecfilt (); 534 530 535 Nmax = Nlist[0]; 531 536 for (i = 0; i < Ngrid; i++) { … … 545 550 c = clist[i][j]; 546 551 547 if (catalog[c].measure [m].dbFlags & MEAS_BAD) {552 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 548 553 Nbad ++; 549 554 continue; … … 565 570 } 566 571 567 n = catalog[c].measure [m].averef;568 Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);572 n = catalog[c].measureT[m].averef; 573 Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]); 569 574 if (isnan(Msys)) { 570 575 Nsys++; … … 572 577 } 573 578 list[N] = Msys - Mrel - Mcal - Mmos; 574 dlist[N] = MAX (catalog[c].measure [m].dM, MIN_ERROR);579 dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 575 580 N++; 576 581 } … … 613 618 if (!USE_GRID) return; 614 619 620 int Nsecfilt = GetPhotcodeNsecfilt (); 621 615 622 N = 0; 616 623 for (i = 0; i < Ngrid; i++) … … 630 637 c = clist[i][j]; 631 638 632 if (catalog[c].measure [m].dbFlags & MEAS_BAD) {639 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 633 640 Narea ++; 634 641 continue; … … 641 648 if (isnan(Mrel)) continue; 642 649 643 n = catalog[c].measure [m].averef;644 Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);650 n = catalog[c].measureT[m].averef; 651 Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]); 645 652 646 653 xlist[N] = Xmeas[c][m]; … … 704 711 gfits_create_matrix (&header, &matrix); 705 712 gfits_modify (&header, "NEXTEND", OFF_T_FMT, 1, Nimage + 3); 706 gfits_modify (&header, "FILTER", "%s", 1, photcode [0].name);713 gfits_modify (&header, "FILTER", "%s", 1, photcodes[0][0].name); // XXXX note that this expects a single photcode, enforced in initialize.d 707 714 gfits_modify_alt (&header, "COMMENT", "%S", 1, "Mosaic Photometry Grid Analysis"); 708 715 … … 727 734 theader.bitpix = -32; 728 735 gfits_create_Theader (&theader, "IMAGE"); 729 gfits_modify (&theader, "FILTER", "%s", 1, photcode [0].name);736 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 730 737 gfits_modify (&theader, "EXTNAME", "%s", 1, "MAG_OFFSET"); 731 738 gfits_create_matrix (&theader, &matrix); … … 742 749 /* save grid Nmeas values */ 743 750 gfits_modify (&theader, "EXTNAME", "%s", 1, "NMEAS"); 744 gfits_modify (&theader, "FILTER", "%s", 1, photcode [0].name);751 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 745 752 gfits_create_matrix (&theader, &matrix); 746 753 for (i = 0; i < gridX; i++) { … … 756 763 /* save grid sigma values */ 757 764 gfits_modify (&theader, "EXTNAME", "%s", 1, "SIGMA"); 758 gfits_modify (&theader, "FILTER", "%s", 1, photcode [0].name);765 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 759 766 gfits_create_matrix (&theader, &matrix); 760 767 for (i = 0; i < gridX; i++) { … … 776 783 777 784 gfits_modify (&theader, "EXTNAME", "%s", 1, camera.ccdname[N]); 778 gfits_modify (&theader, "FILTER", "%s", 1, photcode [0].name);785 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 779 786 gfits_modify (&theader, "NX", "%d", 1, camera.Nx); 780 787 gfits_modify (&theader, "NY", "%d", 1, camera.Ny); -
trunk/Ohana/src/relphot/src/ImageOps.c
r30616 r31450 1 1 # include "relphot.h" 2 3 # define USE_IMAGE_ID 14 2 5 3 static off_t **bin; // link from catalog,measure to image … … 12 10 static off_t Nimage; // number of available images 13 11 14 // if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted 15 // index 16 17 # if USE_IMAGE_ID 12 // to search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted index 18 13 static off_t *imageIDs; // list of all image IDs 19 14 static off_t *imageIdx; // list of index for image IDs 20 # else21 static unsigned int *start;22 static unsigned int *stop;23 # endif24 15 25 16 Image *getimages (off_t *N) { … … 40 31 Nimage = N; 41 32 42 # if USE_IMAGE_ID43 33 ALLOCATE (imageIDs, off_t, Nimage); 44 34 ALLOCATE (imageIdx, off_t, Nimage); … … 49 39 } 50 40 llsortpair (imageIDs, imageIdx, Nimage); 51 # else52 ALLOCATE (start, unsigned, Nimage);53 ALLOCATE (stop, unsigned, Nimage);54 55 for (i = 0; i < Nimage; i++) {56 start[i] = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1);57 stop[i] = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);58 }59 # endif60 41 } 61 42 … … 65 46 // use bisection to find the specified image ID 66 47 67 # if USE_IMAGE_ID68 48 off_t Nlo, Nhi, N; 69 49 … … 82 62 return (imageIdx[N]); 83 63 } 84 # endif85 64 86 65 return (-1); … … 128 107 } 129 108 130 /* select all image equivalent to the current photcode*/109 /* select all image equivalent to the active photcode set */ 131 110 void findImages (Catalog *catalog, int Ncatalog) { 132 111 133 112 off_t j; 134 int i, ecode; 135 136 for (i = 0; i < Ncatalog; i++) { 113 int i, ecode, Ns, found; 114 115 int Nmatch = 0; 116 for (i = 0; i < Ncatalog; i++) { 137 117 for (j = 0; j < catalog[i].Nmeasure; j++) { 138 ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode); 139 if (photcode[0].code != ecode) continue; 118 ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode); 119 found = FALSE; 120 for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 121 if (ecode == photcodes[Ns][0].code) found = TRUE; 122 } 123 if (!found) continue; 140 124 matchImage (catalog, j, i); 141 } 142 } 143 } 144 145 int findCCD (off_t idx, off_t meas, int cat, Measure *measure) { 146 147 int ccdnum; 125 Nmatch ++; 126 } 127 } 128 // fprintf (stderr, "matched %d detections to images\n", Nmatch); 129 } 130 131 int findCCD (off_t idx, off_t meas, int cat, MeasureTiny *measure) { 132 133 int ccdnum, found, Ns, ecode; 148 134 double X, Y; 149 135 char *pname, *filter, *p, base[256]; … … 151 137 /* identify the ccd on the basis of the photcode name */ 152 138 pname = GetPhotcodeNamebyCode (image[idx].photcode); 153 filter = photcode[0].name; 139 140 // XXX this seems quite terrible... 141 ecode = GetPhotcodeEquivCodebyCode (measure[0].photcode); 142 found = FALSE; 143 for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 144 if (ecode == photcodes[Ns][0].code) found = TRUE; 145 } 146 if (!found) return (FALSE); 147 148 filter = photcodes[Ns][0].name; 154 149 sprintf (base, "%s.%s.", MOSAICNAME, filter); 155 150 if (strncmp (pname, base, strlen (base))) return (FALSE); … … 170 165 171 166 // old code to add this measurement to the grid cell for this chip 172 // ave = measure [0].averef;173 // ra = catalog[cat].average [ave].R - measure[0].dR / 3600.0;174 // dec = catalog[cat].average [ave].D - measure[0].dD / 3600.0;167 // ave = measureT[0].averef; 168 // ra = catalog[cat].averageT[ave].R - measureT[0].dR / 3600.0; 169 // dec = catalog[cat].averageT[ave].D - measureT[0].dD / 3600.0; 175 170 // RD_to_XY (&X, &Y, ra, dec, &image[i].coords); 176 171 … … 183 178 } 184 179 185 # if USE_IMAGE_ID186 180 void matchImage (Catalog *catalog, off_t meas, int cat) { 187 181 188 182 off_t idx, ID; 189 183 int status; 190 Measure *measure;184 MeasureTiny *measure; 191 185 192 measure = &catalog[cat].measure [meas];186 measure = &catalog[cat].measureT[meas]; 193 187 194 188 ID = measure[0].imageID; … … 226 220 } 227 221 228 # else229 // this is the time-based match230 void matchImage (Catalog *catalog, off_t meas, int cat) {231 232 off_t i;233 int status;234 Measure *measure;235 236 measure = &catalog[cat].measure[meas];237 for (i = 0; i < Nimage; i++) {238 if (image[0].photcode == -1) continue;239 if (measure[0].photcode != image[i].photcode) continue;240 if (measure[0].t < start[i]) continue;241 if (measure[0].t > stop[i]) continue;242 243 if (USE_GRID) {244 status = findCCD(i, meas, cat);245 if (!status) continue;246 }247 248 // index for (catalog, measure) -> image249 bin[cat][meas] = i;250 251 // index for image, Nentry -> catalog252 clist[i][Nlist[i]] = cat;253 254 // index for image, Nentry -> measure255 mlist[i][Nlist[i]] = meas;256 Nlist[i] ++;257 258 if (Nlist[i] == NLIST[i]) {259 NLIST[i] += 100;260 REALLOCATE (clist[i], off_t, NLIST[i]);261 REALLOCATE (mlist[i], off_t, NLIST[i]);262 }263 return;264 }265 /* fprintf (stderr, "can't find source image for this measurement: %d (%d)\n", measure[0].t, measure[0].photcode); */266 }267 # endif268 269 222 off_t getImageEntry (off_t meas, int cat) { 270 223 … … 307 260 308 261 if (FREEZE_IMAGES) return; 262 263 int Nsecfilt = GetPhotcodeNsecfilt (); 309 264 310 265 if (PoorImages) { … … 339 294 c = clist[i][j]; 340 295 341 if (catalog[c].measure [m].dbFlags & MEAS_BAD) {296 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 342 297 Nbad++; 343 298 continue; … … 359 314 } 360 315 361 n = catalog[c].measure [m].averef;362 Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);316 n = catalog[c].measureT[m].averef; 317 Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]); 363 318 if (isnan(Msys)) { 364 319 Nsys++; … … 366 321 } 367 322 list[N] = Msys - Mrel - Mmos - Mgrid; 368 dlist[N] = MAX (catalog[c].measure [m].dM, MIN_ERROR);369 if (catalog[c].measure [m].dM < IMFIT_SYS_SIGMA_LIM) {323 dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 324 if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) { 370 325 McalBright += list[N]; 371 326 McalBright2 += SQ(list[N]); … … 632 587 return (stats); 633 588 } 634 -
trunk/Ohana/src/relphot/src/MosaicOps.c
r30616 r31450 9 9 static off_t **imlist; /* mosaic -> image[] */ 10 10 static off_t **bin; /* catalog, measure -> mosaic */ 11 12 // list of mosaics associated with an image 13 static off_t *mosimage; 11 14 12 15 // list of mosaic associated with each image … … 33 36 ALLOCATE (NIMLIST, off_t, NMOSAIC); 34 37 38 ALLOCATE (mosimage, off_t, Nimage); // mosaic to which image belongs 39 35 40 /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no 36 41 * entry in the image table that represents this mosaic. Instead, it is an … … 40 45 /* generate list of unique mosaics */ 41 46 for (i = 0; i < Nimage; i++) { 47 mosimage[i] = -1; 42 48 43 49 /* select valid mosaic images by photcode */ … … 56 62 if (start > mosaic[j].stop) continue; 57 63 found = TRUE; 64 65 // add reference from image to mosaic 66 mosimage[i] = j; 58 67 59 68 /* add image to mosaic image list */ … … 77 86 mosaic[Nmosaic].flags = image[i].flags; 78 87 mosaic[Nmosaic].secz = image[i].secz; 88 mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode); 79 89 80 90 /* add image to mosaic image list */ … … 84 94 imlist[Nmosaic][0] = i; 85 95 96 // add reference from image to mosaic 97 mosimage[i] = Nmosaic; 98 86 99 Nmosaic ++; 87 100 if (Nmosaic == NMOSAIC) { … … 250 263 int findMosaics (Catalog *catalog, int Ncatalog) { 251 264 252 int i, ecode ;265 int i, ecode, found, Ns; 253 266 off_t j; 254 267 255 268 if (!MOSAIC_ZEROPT) return (FALSE); 256 269 270 int Nmatch = 0; 257 271 for (i = 0; i < Ncatalog; i++) { 258 272 for (j = 0; j < catalog[i].Nmeasure; j++) { 259 273 if (TimeSelect) { 260 if (catalog[i].measure[j].t < TSTART) continue; 261 if (catalog[i].measure[j].t > TSTOP) continue; 262 } 263 ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode); 264 if (photcode[0].code != ecode) continue; 274 if (catalog[i].measureT[j].t < TSTART) continue; 275 if (catalog[i].measureT[j].t > TSTOP) continue; 276 } 277 ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode); 278 found = FALSE; 279 for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 280 if (ecode == photcodes[Ns][0].code) found = TRUE; 281 } 282 if (!found) continue; 265 283 matchMosaics (catalog, j, i); 266 } 267 } 284 Nmatch ++; 285 } 286 } 287 // fprintf (stderr, "matched %d detections to mosaics\n", Nmatch); 268 288 return (TRUE); 269 289 } … … 271 291 void matchMosaics (Catalog *catalog, off_t meas, int cat) { 272 292 273 int i; 274 275 for (i = 0; i < Nmosaic; i++) { 276 if (catalog[cat].measure[meas].t < mosaic[i].start) continue; 277 if (catalog[cat].measure[meas].t > mosaic[i].stop) continue; 293 off_t idx, ID, mosID; 294 MeasureTiny *measure; 295 296 measure = &catalog[cat].measureT[meas]; 297 298 ID = measure[0].imageID; 299 idx = getImageByID (ID); 300 if (idx == -1) { 301 if (VERBOSE2) fprintf (stderr, "missed measurement "OFF_T_FMT", %d\n", meas, cat); 302 return; 303 } 304 305 mosID = mosimage[idx]; 306 if (mosID < 0) { 307 Image *image = getimage(idx); 308 fprintf (stderr, "unmatched image %s\n", image[0].name); 309 return; 310 } 311 312 // test to check we got the right match: 313 { 314 Image *image = getimage(idx); 315 unsigned int imageStart = image[0].tzero - MAX(0.01*image[0].trate*image[0].NY, 1); 316 if (imageStart != mosaic[mosID].start) { 317 fprintf (stderr, "error in image to mosaic match\n"); 318 abort(); 319 } 320 } 321 322 bin[cat][meas] = mosID; 323 324 clist[mosID][Nlist[mosID]] = cat; 325 mlist[mosID][Nlist[mosID]] = meas; 326 Nlist[mosID] ++; 278 327 279 # ifdef GRID_V1 280 if (USE_GRID) { 281 ave = catalog[cat].measure[meas].averef; 282 ra = catalog[cat].average[ave].R - catalog[cat].measure[meas].dR / 3600.0; 283 dec = catalog[cat].average[ave].D - catalog[cat].measure[meas].dD / 3600.0; 284 285 /* X,Y always positive-definite in range 0,0 - dX, dY */ 286 RD_to_XY (&X, &Y, ra, dec, &mosaic[i].coords); 287 setGridMeasure (meas, cat, X, Y); 288 } 289 # endif 290 291 bin[cat][meas] = i; 292 293 clist[i][Nlist[i]] = cat; 294 mlist[i][Nlist[i]] = meas; 295 Nlist[i] ++; 296 297 if (Nlist[i] == NLIST[i]) { 298 NLIST[i] += 100; 299 REALLOCATE (clist[i], int, NLIST[i]); 300 REALLOCATE (mlist[i], off_t, NLIST[i]); 301 } 302 return; 303 } 304 fprintf (stderr, "missed measurement\n"); 328 if (Nlist[mosID] == NLIST[mosID]) { 329 NLIST[mosID] += 100; 330 REALLOCATE (clist[mosID], int, NLIST[mosID]); 331 REALLOCATE (mlist[mosID], off_t, NLIST[mosID]); 332 } 305 333 return; 306 334 } … … 324 352 325 353 off_t i, j, m, c, N, Nmax; 326 int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys ;354 int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys, Nsecfilt; 327 355 float Msys, Mrel, Mcal, Mgrid; 328 356 double *list, *dlist, *Mlist, *dMlist; … … 334 362 335 363 image = getimages (&N); 364 365 Nsecfilt = GetPhotcodeNsecfilt (); 336 366 337 367 if (PoorImages) { … … 364 394 c = clist[i][j]; 365 395 366 if (catalog[c].measure [m].dbFlags & MEAS_BAD) {396 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 367 397 Nbad ++; 368 398 continue; … … 384 414 } 385 415 386 n = catalog[c].measure [m].averef;387 Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);416 n = catalog[c].measureT[m].averef; 417 Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]); 388 418 if (isnan(Msys)) { 389 419 Nsys++; … … 391 421 } 392 422 list[N] = Msys - Mrel - Mcal - Mgrid; 393 dlist[N] = MAX (catalog[c].measure [m].dM, MIN_ERROR);423 dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 394 424 Mlist[N] = Msys; 395 425 dMlist[N] = list[N]; … … 433 463 } 434 464 465 // When we rationalize the images/mosaics, we are driving the negative cloud images back 466 // to 0.0. At the same time, we make a guess to the effective impact on all other images, 467 // driven by the coupling of common stars. 468 int rationalize_mosaics (Catalog *catalog, int Ncatalog) { 469 470 double *imageOffset, **starOffset; 471 int **starNcount, *seclist; 472 int **Slist, *NSlist, *NSLIST; 473 int i, j, k, m, nMos, Ns, found; 474 475 off_t Nimage; 476 Image *image; 477 478 // set a test value for now 479 float CLOUD_TOLERANCE = 0.025; 480 481 if (!MOSAIC_ZEROPT) return (FALSE); 482 if (FREEZE_MOSAICS) return (FALSE); 483 484 image = getimages (&Nimage); 485 486 ALLOCATE (imageOffset, double, Nmosaic); 487 488 ALLOCATE ( Slist, int *, Nmosaic); // array of calibrated star indexes on this mosaic 489 ALLOCATE (NSlist, int, Nmosaic); // number of stars on mosaic 490 ALLOCATE (NSLIST, int, Nmosaic); // number of Slist entries allocated 491 memset (Slist, 0, Nmosaic*sizeof(int *)); 492 493 // find the images / mosaics with negative clouds and save their offset 494 for (i = 0; i < Nmosaic; i++) { 495 496 NSlist[i] = 0; 497 NSLIST[i] = 100; 498 ALLOCATE (Slist[i], int, NSLIST[i]); 499 500 imageOffset[i] = 0.0; 501 502 if (VERBOSE2 && (fabs(mosaic[i].Mcal) < CLOUD_TOLERANCE)) { 503 fprintf (stderr, "cloud-free: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal); 504 } 505 if (VERBOSE2 && (mosaic[i].Mcal < -CLOUD_TOLERANCE)) { 506 imageOffset[i] = -mosaic[i].Mcal; 507 // NOTE the negative sign: down below, we are going to add in the negative of Mcal 508 // to this image, and the propagated mean values for other images 509 fprintf (stderr, "anti-clouds: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal); 510 } 511 if (VERBOSE2 && (mosaic[i].Mcal > CLOUD_TOLERANCE)) { 512 fprintf (stderr, "cloudy : %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal); 513 } 514 } 515 516 int Nsecfilt = GetPhotcodeNsecfilt (); 517 ALLOCATE (seclist, int, Nphotcodes); 518 for (Ns = 0; Ns < Nphotcodes; Ns ++) { 519 int thisCode = photcodes[Ns][0].code; 520 seclist[Ns] = GetPhotcodeNsec(thisCode); 521 } 522 523 // allocate an array for star offsets 524 int Nstars = 0; 525 int NSTARS = 1000; 526 ALLOCATE (starOffset, double *, NSTARS); 527 ALLOCATE (starNcount, int *, NSTARS); 528 memset (starOffset, 0, NSTARS*sizeof(double *)); 529 memset (starNcount, 0, NSTARS*sizeof(int *)); 530 531 // find the mean offset for each star 532 for (i = 0; i < Ncatalog; i++) { 533 for (j = 0; j < catalog[i].Naverage; j++) { 534 ALLOCATE (starOffset[Nstars], double, Nphotcodes); 535 ALLOCATE (starNcount[Nstars], int, Nphotcodes); 536 memset (starOffset[Nstars], 0, Nphotcodes*sizeof(double)); 537 memset (starNcount[Nstars], 0, Nphotcodes*sizeof(int)); 538 539 m = catalog[i].averageT[j].measureOffset; 540 541 // determine the mosaic for each measurement 542 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 543 544 // skip unused measurements 545 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 546 547 // skip unused measurements 548 int Nsec; 549 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 550 found = FALSE; 551 for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) { 552 if (ecode == photcodes[Ns][0].code) { 553 found = TRUE; 554 break; 555 } 556 } 557 if (!found) continue; 558 Nsec = seclist[Ns]; 559 560 // bad stars for this secfilt 561 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 562 563 // skip REF measurements (not tied to an image) 564 if (getImageEntry (m, i) < 0) continue; 565 566 // find the source of this measurement (skip unassigned measurements) 567 nMos = bin[i][m]; 568 if (nMos == -1) continue; 569 570 if (mosaic[nMos].photcode != ecode) { 571 fprintf (stderr, "*"); 572 } 573 574 assert (Ns >= 0); 575 assert (Ns < Nphotcodes); 576 577 // accumulate the offsets from the negative cloud images (others have 0.0 value) 578 starOffset[Nstars][Ns] += imageOffset[nMos]; 579 starNcount[Nstars][Ns] ++; 580 581 // record the mosaic->star reference 582 Slist[nMos][NSlist[nMos]] = Nstars; 583 NSlist[nMos] ++; 584 if (NSlist[nMos] == NSLIST[nMos]) { 585 NSLIST[nMos] += 100; 586 REALLOCATE (Slist[nMos], int, NSLIST[nMos]); 587 } 588 } 589 Nstars ++; 590 if (Nstars == NSTARS) { 591 NSTARS += 1000; 592 REALLOCATE (starOffset, double *, NSTARS); 593 REALLOCATE (starNcount, int *, NSTARS); 594 memset (&starOffset[NSTARS-1000], 0, 1000*sizeof(double *)); 595 memset (&starNcount[NSTARS-1000], 0, 1000*sizeof(int *)); 596 } 597 } 598 } 599 600 // find the mean offset of the images without negative clouds 601 for (i = 0; i < Nmosaic; i++) { 602 603 found = FALSE; 604 for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) { 605 if (mosaic[i].photcode == photcodes[Ns][0].code) { 606 found = TRUE; 607 break; 608 } 609 } 610 if (!found) { 611 fprintf (stderr, "invalid photcode for mosaic?\n"); 612 abort(); 613 } 614 615 // a negative cloud image (cloud: Mcal > 0; anti-clouds: Mcal < 0; imageOffset = -Mcal) 616 if (imageOffset[i] > 0.0) continue; 617 618 // we need to actually have cross-references to count 619 if (NSlist[i] < 2) continue; 620 621 float dM = 0.0; 622 for (j = 0; j < NSlist[i]; j++) { 623 Nstars = Slist[i][j]; 624 if (starNcount[Nstars][Ns] > 1) { 625 dM += (starOffset[Nstars][Ns] / starNcount[Nstars][Ns]); 626 } 627 } 628 imageOffset[i] = dM / NSlist[i]; 629 // fprintf (stderr, "adjust image: %s : (%f %d) : %f\n", image[imlist[i][0]].name, dM, NSlist[i], imageOffset[i]); 630 } 631 632 // for (i = 0; i < Nmosaic; i++) { 633 // fprintf (stderr, "correction: %s : %f\n", image[imlist[i][0]].name, imageOffset[i]); 634 // } 635 636 // apply all offset values to the mosaics 637 // find the images / mosaics with negative clouds and save their offset 638 for (i = 0; i < Nmosaic; i++) { 639 mosaic[i].Mcal += imageOffset[i]; 640 } 641 642 for (i = 0; i < Nstars; i++) { 643 free (starOffset[i]); 644 free (starNcount[i]); 645 } 646 free (starOffset); 647 free (starNcount); 648 649 for (i = 0; i < Nmosaic; i++){ 650 free (Slist[i]); 651 } 652 free (NSlist); 653 free (NSLIST); 654 free (imageOffset); 655 free (seclist); 656 return (TRUE); 657 } 658 435 659 StatType statsMosaicM (Catalog *catalog) { 436 660 … … 524 748 n++; 525 749 } 526 fprintf (stderr, "Nmosaic: "OFF_T_FMT", n: "OFF_T_FMT"\n", Nmosaic, n);750 // fprintf (stderr, "Nmosaic: "OFF_T_FMT", n: "OFF_T_FMT"\n", Nmosaic, n); 527 751 528 752 liststats (list, dlist, n, &stats); … … 563 787 void clean_mosaics () { 564 788 565 off_t i, N, mark, Nmark ;789 off_t i, N, mark, Nmark, Nscatter, Noffset; 566 790 double *mlist, *slist, *dlist; 567 791 double MaxOffset, MedOffset, MaxScatter; … … 592 816 fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset); 593 817 594 Nmark = 0;818 Nmark = Nscatter = Noffset = 0; 595 819 for (i = 0; i < Nmosaic; i++) { 596 820 mark = FALSE; 597 mark = (mosaic[i].dMcal > MaxScatter) || (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset); 821 if (mosaic[i].dMcal > MaxScatter) { 822 mark = TRUE; 823 Nscatter ++; 824 } 825 if (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset) { 826 mark = TRUE; 827 Noffset ++; 828 } 598 829 if (mark) { 599 830 Nmark ++; … … 604 835 } 605 836 606 fprintf (stderr, OFF_T_FMT" mosaics marked poor \n", Nmark);837 fprintf (stderr, OFF_T_FMT" mosaics marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n", Nmark, Nscatter, Noffset); 607 838 initstats (STATMODE); 608 839 free (mlist); … … 640 871 c = clist[i][j]; 641 872 642 if (catalog[c].measure [m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;643 644 ave = catalog[c].measure [m].averef;645 xlist[N] = catalog[c].average [ave].R - catalog[c].measure[m].dR / 3600.0;646 ylist[N] = catalog[c].average [ave].D - catalog[c].measure[m].dD / 3600.0;873 if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue; 874 875 ave = catalog[c].measureT[m].averef; 876 xlist[N] = catalog[c].averageT[ave].R - catalog[c].measureT[m].dR / 3600.0; 877 ylist[N] = catalog[c].averageT[ave].D - catalog[c].measureT[m].dD / 3600.0; 647 878 N++; 648 879 } -
trunk/Ohana/src/relphot/src/StarOps.c
r29001 r31450 5 5 static double *dlist; 6 6 7 // When we rationalize the images/mosaics, we are driving the negative cloud images back 8 // to 0.0. At the same time, we make a guess to the effective impact on all other images, 9 // driven by the coupling of common stars. This array carries the impact of those offsets 10 // on each star 11 static double *Moffset; 12 7 13 void initMrel (Catalog *catalog, int Ncatalog) { 8 14 … … 12 18 for (i = 0; i < Ncatalog; i++) { 13 19 for (j = 0; j < catalog[i].Naverage; j++) { 14 Nmax = MAX (Nmax, catalog[i].average[j].Nmeasure); 15 } 16 } 17 18 ALLOCATE (list, double, MAX (1, Nmax)); 19 ALLOCATE (dlist, double, MAX (1, Nmax)); 20 Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure); 21 } 22 } 23 24 ALLOCATE (list, double, MAX (1, Nmax)); 25 ALLOCATE (dlist, double, MAX (1, Nmax)); 26 ALLOCATE (Moffset, double, MAX (1, Nmax)); 20 27 } 21 28 22 29 float getMrel (Catalog *catalog, off_t meas, int cat) { 23 30 31 int Nsec, Nsecfilt, photcode; 24 32 int ave; 25 33 float value; 26 34 27 ave = catalog[cat].measure[meas].averef; 28 if (catalog[cat].average[ave].flags & STAR_BAD) return (NAN); 35 ave = catalog[cat].measureT[meas].averef; 36 photcode = catalog[cat].measureT[meas].photcode; 37 38 int ecode = GetPhotcodeEquivCodebyCode (photcode); 39 Nsec = GetPhotcodeNsec(ecode); 40 Nsecfilt = GetPhotcodeNsecfilt (); 41 42 // is this star OK? 43 if (catalog[cat].secfilt[Nsecfilt*ave+Nsec].flags & STAR_BAD) return (NAN); 29 44 30 value = catalog[cat].secfilt[ PhotNsec*ave+PhotSec].M;45 value = catalog[cat].secfilt[Nsecfilt*ave+Nsec].M; 31 46 return (value); 32 47 } … … 39 54 StatType stats; 40 55 56 int Nsecfilt = GetPhotcodeNsecfilt (); 41 57 Nfew = Nsys = Nbad = Ncal = Nmos = Ngrid = 0; 42 58 … … 44 60 for (j = 0; j < catalog[i].Naverage; j++) { 45 61 46 /* calculate the average value for a single star */ 47 if (catalog[i].average[j].flags & STAR_BAD) continue; 48 m = catalog[i].average[j].measureOffset; 49 50 N = 0; 51 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 52 if (catalog[i].measure[m].dbFlags & MEAS_BAD) { 53 Nbad ++; 54 continue; 55 } 56 // XXX allow REF stars (no Image Entry) to be included in the calculation this 57 // should be optionally set, and should allow for REF stars to be downweighted by 58 // more than their reported errors. how such info is carried is unclear... 59 if (getImageEntry (m, i) < 0) { 60 Mcal = Mmos = Mgrid = 0; 61 } else { 62 Mcal = getMcal (m, i); 63 if (isnan(Mcal)) { 64 Ncal ++; 62 int Ns; 63 for (Ns = 0; Ns < Nphotcodes; Ns++) { 64 65 int thisCode = photcodes[Ns][0].code; 66 int Nsec = GetPhotcodeNsec(thisCode); 67 68 /* calculate the average value for a single star */ 69 70 // skip bad stars 71 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 72 m = catalog[i].averageT[j].measureOffset; 73 74 N = 0; 75 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 76 // skip measurements that do not match the current photcode 77 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 78 if (ecode != thisCode) { continue; } 79 80 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) { 81 Nbad ++; 65 82 continue; 66 83 } 67 Mmos = getMmos (m, i); 68 if (isnan(Mmos)) { 69 Nmos ++; 84 // XXX allow REF stars (no Image Entry) to be included in the calculation this 85 // should be optionally set, and should allow for REF stars to be downweighted by 86 // more than their reported errors. how such info is carried is unclear... 87 if (getImageEntry (m, i) < 0) { 88 Mcal = Mmos = Mgrid = 0; 89 } else { 90 Mcal = getMcal (m, i); 91 if (isnan(Mcal)) { 92 Ncal ++; 93 continue; 94 } 95 Mmos = getMmos (m, i); 96 if (isnan(Mmos)) { 97 Nmos ++; 98 continue; 99 } 100 Mgrid = getMgrid (m, i); 101 if (isnan(Mgrid)) { 102 Ngrid++; 103 continue; 104 } 105 } 106 107 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]); 108 if (isnan(Msys)) { 109 Nsys++; 70 110 continue; 71 111 } 72 Mgrid = getMgrid (m, i); 73 if (isnan(Mgrid)) { 74 Ngrid++; 75 continue; 112 list[N] = Msys - Mcal - Mmos - Mgrid; 113 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR); 114 115 // tie down reference photometry if the -refcode (code) option is selected 116 if (refPhotcode) { 117 if (GetPhotcodeEquivCodebyCode(catalog[i].measureT[m].photcode) == refPhotcode[0].equiv) { 118 // increase the weight by a factor of 100: 119 dlist[N] = 0.01*catalog[i].measureT[m].dM; 120 } 76 121 } 77 } 78 79 Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]); 80 if (isnan(Msys)) { 81 Nsys++; 82 continue; 83 } 84 list[N] = Msys - Mcal - Mmos - Mgrid; 85 dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR); 86 87 if (refPhotcode) { 88 if (GetPhotcodeEquivCodebyCode(catalog[i].measure[m].photcode) == refPhotcode[0].equiv) { 89 // increase the weight by a factor of 100: 90 dlist[N] = 0.01*catalog[i].measure[m].dM; 91 } 92 } 93 N++; 94 } 95 96 // when performing the grid analysis, STAR_TOOFEW will be set to 1; 97 98 if (N <= STAR_TOOFEW) { /* too few measurements */ 99 catalog[i].average[j].flags |= ID_STAR_FEW; 100 Nfew ++; 101 } else { 102 catalog[i].average[j].flags &= ~ID_STAR_FEW; 103 } 104 105 liststats (list, dlist, N, &stats); 106 107 catalog[i].secfilt[PhotNsec*j+PhotSec].M = stats.mean; 108 catalog[i].secfilt[PhotNsec*j+PhotSec].dM = stats.sigma; 109 catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT; 122 N++; 123 } 124 125 // when performing the grid analysis, STAR_TOOFEW will be set to 1; 126 if (N <= STAR_TOOFEW) { /* too few measurements */ 127 catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_STAR_FEW; 128 Nfew ++; 129 } else { 130 catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_STAR_FEW; 131 } 132 133 liststats (list, dlist, N, &stats); 134 135 catalog[i].secfilt[Nsecfilt*j+Nsec].M = stats.mean; 136 catalog[i].secfilt[Nsecfilt*j+Nsec].dM = stats.sigma; 137 catalog[i].secfilt[Nsecfilt*j+Nsec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT; 138 } 110 139 } 111 140 } … … 122 151 double *list, *dlist; 123 152 StatType stats; 153 int Nsec, Nsecfilt, ecode; 154 155 Nsecfilt = GetPhotcodeNsecfilt (); 124 156 125 157 /* Nmeasure is now different, need to reallocate */ … … 127 159 for (i = 0; i < Ncatalog; i++) { 128 160 for (j = 0; j < catalog[i].Naverage; j++) { 129 Nmax = MAX (Nmax, catalog[i].average [j].Nmeasure);161 Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure); 130 162 } 131 163 } … … 135 167 for (i = 0; i < Ncatalog; i++) { 136 168 for (j = 0; j < catalog[i].Naverage; j++) { 137 138 169 /* skip stars already calibrated */ 139 170 if (catalog[i].found[j]) continue; 140 171 141 N = 0; 142 m = catalog[i].average[j].measureOffset; 143 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 144 if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; 145 // XXX allow REF stars (no Image Entry) to be included in the calculation this 146 // should be optionally set, and should allow for REF stars to be downweighted by 147 // more than their reported errors. how such info is carried is unclear... 148 if (getImageEntry (m, i) < 0) { 149 Mcal = Mmos = Mgrid = 0; 150 } else { 151 Mcal = getMcal (m, i); 152 if (isnan(Mcal)) continue; 153 Mmos = getMmos (m, i); 154 if (isnan(Mmos)) continue; 155 Mgrid = getMgrid (m, i); 156 if (isnan(Mgrid)) continue; 157 } 158 159 Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]); 160 list[N] = Msys - Mcal - Mmos - Mgrid; 161 dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR); 162 N++; 163 } 164 if (N < 1) continue; 165 166 liststats (list, dlist, N, &stats); 167 if (mark) catalog[i].found[j] = TRUE; 168 169 /* use sigma or error in dM for output? */ 170 catalog[i].secfilt[PhotNsec*j+PhotSec].M = stats.mean; 171 catalog[i].secfilt[PhotNsec*j+PhotSec].dM = MAX (stats.error, stats.sigma); 172 catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT; 172 int Ns; 173 for (Ns = 0; Ns < Nphotcodes; Ns++) { 174 int thisCode = photcodes[Ns][0].code; 175 Nsec = GetPhotcodeNsec(thisCode); 176 177 N = 0; 178 m = catalog[i].averageT[j].measureOffset; 179 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 180 // skip measurements that do not match the current photcode 181 ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 182 if (ecode != thisCode) { continue; } 183 184 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 185 186 // XXX allow REF stars (no Image Entry) to be included in the calculation this 187 // should be optionally set, and should allow for REF stars to be downweighted by 188 // more than their reported errors. how such info is carried is unclear... 189 if (getImageEntry (m, i) < 0) { 190 Mcal = Mmos = Mgrid = 0; 191 } else { 192 Mcal = getMcal (m, i); 193 if (isnan(Mcal)) continue; 194 Mmos = getMmos (m, i); 195 if (isnan(Mmos)) continue; 196 Mgrid = getMgrid (m, i); 197 if (isnan(Mgrid)) continue; 198 } 199 200 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]); 201 list[N] = Msys - Mcal - Mmos - Mgrid; 202 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR); 203 N++; 204 } 205 if (N < 1) continue; 206 207 liststats (list, dlist, N, &stats); 208 if (mark) catalog[i].found[j] = TRUE; 209 210 /* use sigma or error in dM for output? */ 211 catalog[i].secfilt[Nsecfilt*j+Nsec].M = stats.mean; 212 catalog[i].secfilt[Nsecfilt*j+Nsec].dM = MAX (stats.error, stats.sigma); 213 catalog[i].secfilt[Nsecfilt*j+Nsec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT; 214 } 173 215 } 174 216 } … … 179 221 } 180 222 181 // for each average object, set the average mags based on existing equiv photometry 223 // For each average object, set the average mags based on existing equiv photometry. 224 // NOTE: this function operates on the real Measure & Average structures, not the 225 // MeasureTiny & AverageTiny structures 182 226 int setMave (Catalog *catalog, int Ncatalog) { 183 227 … … 202 246 ALLOCATE (dlist, double, MAX (1, Nmax)); 203 247 204 Nsecfilt = catalog[0].Nsecfilt;248 Nsecfilt = GetPhotcodeNsecfilt (); 205 249 206 250 # define PSFQUALSTATS 1 … … 220 264 if (GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode) != Nc) continue; 221 265 222 Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j* PhotNsec]);266 Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 223 267 if (isnan(Msys)) continue; 224 268 … … 321 365 for (j = 0; j < catalog[i].Naverage; j++) { 322 366 323 m = catalog[i].average [j].measureOffset;324 for (k = 0; k < catalog[i].average [j].Nmeasure; k++, m++) {325 if (catalog[i].measure [m].dbFlags & MEAS_BAD) continue;367 m = catalog[i].averageT[j].measureOffset; 368 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 369 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 326 370 Mcal = getMcal (m, i); 327 371 if (isnan(Mcal)) continue; … … 330 374 Mgrid = getMgrid (m, i); 331 375 if (isnan(Mgrid)) continue; 376 377 // set the output calibration 332 378 catalog[i].measure[m].Mcal = Mcal + Mmos + Mgrid; 333 379 } … … 339 385 void clean_stars (Catalog *catalog, int Ncatalog) { 340 386 341 int i, j, Ndel, Nave, Ntot, mark ;387 int i, j, Ndel, Nave, Ntot, mark, Ns; 342 388 float dM, Xm; 343 389 double Chisq, MaxScatter, MaxChisq; … … 354 400 ALLOCATE (slist, double, Ntot); 355 401 ALLOCATE (dlist, double, Ntot); 356 for (i = Ntot = 0; i < Ncatalog; i++) { 357 for (j = 0; j < catalog[i].Naverage; j++) { 358 if (catalog[i].average[j].flags & STAR_BAD) continue; 359 Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm; 360 if (Xm == -1) continue; 361 Chisq = pow (10.0, 0.01*Xm); 362 xlist[Ntot] = Chisq; 363 slist[Ntot] = catalog[i].secfilt[PhotNsec*j+PhotSec].dM; 364 dlist[Ntot] = 1; 365 Ntot ++; 366 } 367 } 402 403 int Nsecfilt = GetPhotcodeNsecfilt (); 404 405 // eliminate bad stars using the stats for a single secfilt at a time 406 // XXX DEP replace average.flags with secfilt flags 407 for (Ns = 0; Ns < Nphotcodes; Ns ++) { 408 409 int thisCode = photcodes[Ns][0].code; 410 int Nsec = GetPhotcodeNsec(thisCode); 411 412 for (i = Ntot = 0; i < Ncatalog; i++) { 413 for (j = 0; j < catalog[i].Naverage; j++) { 414 if ( catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD ) continue; 415 Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm; 416 if (Xm == -1) continue; 417 Chisq = pow (10.0, 0.01*Xm); 418 xlist[Ntot] = Chisq; 419 slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dM; 420 dlist[Ntot] = 1; 421 Ntot ++; 422 } 423 } 368 424 369 initstats ("MEAN"); 370 liststats (xlist, dlist, Ntot, &stats); 371 MaxChisq = MAX (STAR_CHISQ, 2*stats.median); 372 liststats (slist, dlist, Ntot, &stats); 373 MaxScatter = MAX (STAR_SCATTER, 2*stats.median); 374 fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq); 375 376 Ndel = Nave = 0; 377 for (i = 0; i < Ncatalog; i++) { 378 for (j = 0; j < catalog[i].Naverage; j++) { 379 dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM; 380 Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm; 381 Chisq = pow (10.0, 0.01*Xm); 382 mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq); 383 if (mark) { 384 catalog[i].average[j].flags |= ID_STAR_POOR; 385 Ndel ++; 386 } else { 387 catalog[i].average[j].flags &= ~ID_STAR_POOR; 388 } 389 Nave ++; 390 } 391 } 392 fprintf (stderr, "%d stars marked variable, %d total\n", Ndel, Nave); 393 initstats (STATMODE); 425 initstats ("MEAN"); 426 liststats (xlist, dlist, Ntot, &stats); 427 MaxChisq = MAX (STAR_CHISQ, 2*stats.median); 428 liststats (slist, dlist, Ntot, &stats); 429 MaxScatter = MAX (STAR_SCATTER, 2*stats.median); 430 fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq); 431 432 Ndel = Nave = 0; 433 for (i = 0; i < Ncatalog; i++) { 434 for (j = 0; j < catalog[i].Naverage; j++) { 435 dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM; 436 Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm; 437 Chisq = pow (10.0, 0.01*Xm); 438 mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq); 439 if (mark) { 440 catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_STAR_POOR; 441 Ndel ++; 442 } else { 443 catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_STAR_POOR; 444 } 445 Nave ++; 446 } 447 } 448 fprintf (stderr, "%d stars marked variable, %d total\n", Ndel, Nave); 449 initstats (STATMODE); 450 } 394 451 free (xlist); 395 452 free (slist); … … 409 466 int Ncal, Nmos, Ngrid, Nfew; 410 467 468 int Nsecfilt = GetPhotcodeNsecfilt (); 469 411 470 if (VERBOSE) fprintf (stderr, "marking poor measures\n"); 412 471 /* Nmeasure is now different, need to reallocate */ … … 414 473 for (i = 0; i < Ncatalog; i++) { 415 474 for (j = 0; j < catalog[i].Naverage; j++) { 416 Nmax = MAX (Nmax, catalog[i].average [j].Nmeasure);475 Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure); 417 476 } 418 477 } … … 430 489 for (j = 0; j < catalog[i].Naverage; j++) { 431 490 432 /* skip bad stars to prevent them from becoming good (on inner sample) */ 433 if (catalog[i].average[j].flags & STAR_BAD) continue; 434 435 /* on final processing, skip stars already measured */ 436 if (final && catalog[i].found[j]) continue; 437 438 /* accumulate list of valid measurements */ 439 m = catalog[i].average[j].measureOffset; 440 N = 0; 441 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 442 /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */ 443 Mcal = getMcal (m, i); 444 if (isnan(Mcal)) { Ncal ++; continue; } 445 Mmos = getMmos (m, i); 446 if (isnan(Mmos)) { Nmos ++; continue; } 447 Mgrid = getMgrid (m, i); 448 if (isnan(Mgrid)) { Ngrid ++; continue; } 449 450 Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]); 451 list[N] = Msys - Mcal - Mmos - Mgrid; 452 dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR); 453 N++; 454 } 455 if (N <= TOOFEW) { Nfew ++; continue; } 456 457 /* 3-sigma clip based on stats of inner 50% */ 458 459 // calculated mean of inner 50% 460 initstats ("INNER_MEAN"); 461 liststats (list, dlist, N, &stats); 462 stats.sigma = MAX (MIN_ERROR, stats.sigma); /* if measurements agree too well, sigma -> 0.0 */ 463 464 // ignore entries > 3sigma from inner mean 465 for (k = m = 0; k < N; k++) { 466 if (fabs (list[k] - stats.median) < NSIGMA_CLIP*stats.sigma) { 467 list[m] = list[k]; 468 m++; 469 } 470 } 471 // recalculate the mean & sigma of the accepted measurements 472 initstats ("MEAN"); 473 liststats (list, dlist, m, &stats); 474 stats.sigma = MAX (MIN_ERROR, stats.sigma); 475 476 /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */ 477 image_bad = IMAGE_BAD; 478 IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL; 479 m = catalog[i].average[j].measureOffset; 480 N = 0; 481 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 482 /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */ 483 Mcal = getMcal (m, i); 484 if (isnan(Mcal)) continue; 485 Mmos = getMmos (m, i); 486 if (isnan(Mmos)) continue; 487 Mgrid = getMgrid (m, i); 488 if (isnan(Mgrid)) continue; 489 490 Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]); 491 list[N] = Msys - Mcal - Mmos - Mgrid; 492 dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR); 493 ilist[N] = m; 494 N++; 495 Nave ++; 496 } 497 if (N < TOOFEW) continue; 498 499 /* mark bad measures (> 3 sigma deviant) */ 500 for (k = 0; k < N; k++) { 501 if (fabs (list[k] - stats.median) > NSIGMA_REJECT*stats.sigma) { 502 catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM; 503 Ndel ++; 504 } 505 } 506 IMAGE_BAD = image_bad; 491 int Ns; 492 for (Ns = 0; Ns < Nphotcodes; Ns++) { 493 494 /* on final processing, skip stars already measured */ 495 if (final && catalog[i].found[j]) continue; 496 497 int thisCode = photcodes[Ns][0].code; 498 int Nsec = GetPhotcodeNsec(thisCode); 499 500 /* skip bad stars to prevent them from becoming good (on inner sample) */ 501 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 502 503 /* accumulate list of valid measurements */ 504 m = catalog[i].averageT[j].measureOffset; 505 N = 0; 506 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 507 // skip measurements that do not match the current photcode 508 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 509 if (ecode != thisCode) { continue; } 510 511 /* if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; */ 512 Mcal = getMcal (m, i); 513 if (isnan(Mcal)) { Ncal ++; continue; } 514 Mmos = getMmos (m, i); 515 if (isnan(Mmos)) { Nmos ++; continue; } 516 Mgrid = getMgrid (m, i); 517 if (isnan(Mgrid)) { Ngrid ++; continue; } 518 519 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]); 520 list[N] = Msys - Mcal - Mmos - Mgrid; 521 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR); 522 N++; 523 } 524 if (N <= TOOFEW) { Nfew ++; continue; } 525 526 /* 3-sigma clip based on stats of inner 50% */ 527 528 // calculated mean of inner 50% 529 initstats ("INNER_MEAN"); 530 liststats (list, dlist, N, &stats); 531 stats.sigma = MAX (MIN_ERROR, stats.sigma); /* if measurements agree too well, sigma -> 0.0 */ 532 533 // ignore entries > 3sigma from inner mean 534 for (k = m = 0; k < N; k++) { 535 if (fabs (list[k] - stats.median) < NSIGMA_CLIP*stats.sigma) { 536 list[m] = list[k]; 537 m++; 538 } 539 } 540 // recalculate the mean & sigma of the accepted measurements 541 initstats ("MEAN"); 542 liststats (list, dlist, m, &stats); 543 stats.sigma = MAX (MIN_ERROR, stats.sigma); 544 545 /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */ 546 image_bad = IMAGE_BAD; 547 IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL; 548 m = catalog[i].averageT[j].measureOffset; 549 N = 0; 550 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 551 // skip measurements that do not match the current photcode 552 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 553 if (ecode != thisCode) { continue; } 554 555 /* if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; */ 556 Mcal = getMcal (m, i); 557 if (isnan(Mcal)) continue; 558 Mmos = getMmos (m, i); 559 if (isnan(Mmos)) continue; 560 Mgrid = getMgrid (m, i); 561 if (isnan(Mgrid)) continue; 562 563 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]); 564 list[N] = Msys - Mcal - Mmos - Mgrid; 565 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR); 566 ilist[N] = m; 567 N++; 568 Nave ++; 569 } 570 if (N < TOOFEW) continue; 571 572 /* mark bad measures (> 3 sigma deviant) */ 573 for (k = 0; k < N; k++) { 574 if (fabs (list[k] - stats.median) > NSIGMA_REJECT*stats.sigma) { 575 catalog[i].measureT[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM; 576 if (final) { 577 // for the final pass, we have a duplicate set of values in measure and measureT 578 catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM; 579 } 580 Ndel ++; 581 } 582 } 583 IMAGE_BAD = image_bad; 584 } 507 585 } 508 586 } … … 513 591 } 514 592 515 StatType statsStarN (Catalog *catalog, int Ncatalog ) {593 StatType statsStarN (Catalog *catalog, int Ncatalog, int Nsec, int seccode) { 516 594 517 595 off_t j, k, m, Ntot; … … 520 598 float Mcal, Mmos, Mgrid; 521 599 StatType stats; 600 // int N1, N2, N3, N4, N0; 601 // N1 = N2 = N3 = N4 = N0 = 0; 602 603 int Nsecfilt = GetPhotcodeNsecfilt (); 522 604 523 605 Ntot = 0; … … 534 616 535 617 /* calculate the average value for a single star */ 536 if (catalog[i]. average[j].flags & STAR_BAD) continue;537 m = catalog[i].average [j].measureOffset;618 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) { continue; } 619 m = catalog[i].averageT[j].measureOffset; 538 620 539 621 N = 0; 540 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 622 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 623 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 624 if (ecode != seccode) { continue;} 541 625 Mcal = getMcal (m, i); 542 if (isnan(Mcal)) continue;626 if (isnan(Mcal)) { continue;} 543 627 Mmos = getMmos (m, i); 544 if (isnan(Mmos)) continue;628 if (isnan(Mmos)) { continue; } 545 629 Mgrid = getMgrid (m, i); 546 if (isnan(Mgrid)) continue;630 if (isnan(Mgrid)) { continue;} 547 631 N++; 548 632 } … … 554 638 } 555 639 640 // fprintf (stderr, "N1: %d, N2: %d, N3: %d, N4: %d, N0: %d\n", N1, N2, N3, N4, N0); 556 641 liststats (list, dlist, n, &stats); 557 642 free (list); … … 560 645 } 561 646 562 StatType statsStarX (Catalog *catalog, int Ncatalog) { 647 // stats for a single secfilt at a time 648 StatType statsStarX (Catalog *catalog, int Ncatalog, int Nsec) { 563 649 564 650 off_t j, Ntot; … … 567 653 StatType stats; 568 654 655 int Nsecfilt = GetPhotcodeNsecfilt (); 656 569 657 Ntot = 0; 570 658 for (i = 0; i < Ncatalog; i++) { … … 580 668 581 669 /* calculate the average value for a single star */ 582 if (catalog[i]. average[j].flags & STAR_BAD) continue;583 584 Xm = catalog[i].secfilt[ PhotNsec*j+PhotSec].Xm;670 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 671 672 Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm; 585 673 if (Xm == NAN_S_SHORT) continue; 586 674 list[n] = pow (10.0, 0.01*Xm); … … 596 684 } 597 685 598 StatType statsStarS (Catalog *catalog, int Ncatalog ) {686 StatType statsStarS (Catalog *catalog, int Ncatalog, int Nsec) { 599 687 600 688 int i, n; … … 604 692 StatType stats; 605 693 694 int Nsecfilt = GetPhotcodeNsecfilt (); 695 606 696 Ntot = 0; 607 697 for (i = 0; i < Ncatalog; i++) { … … 617 707 618 708 /* calculate the average value for a single star */ 619 if (catalog[i]. average[j].flags & STAR_BAD) continue;620 621 dM = catalog[i].secfilt[ PhotNsec*j+PhotSec].dM;709 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 710 711 dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM; 622 712 list[n] = dM; 623 713 dlist[n] = 1; … … 644 734 ALLOCATE (Mlist, double, NBIN); 645 735 646 for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i; 647 bzero (Mlist, NBIN*sizeof(double)); 648 for (i = 0; i < Ncatalog; i++) { 649 for (j = 0; j < catalog[i].Naverage; j++) { 650 if (catalog[i].average[j].flags & STAR_BAD) continue; 651 dMrel = catalog[i].secfilt[PhotNsec*j+PhotSec].dM; 652 bin = dMrel / 0.00025; 653 bin = MAX (0, MIN (NBIN-1, bin)); 654 Mlist[bin] += 1.0; 655 } 656 } 657 658 plot_defaults (&graphdata); 659 graphdata.style = 1; 660 plot_list (&graphdata, xlist, Mlist, NBIN, "dMrel hist", "%s.dMhist.png", OUTROOT); 661 736 int Nsecfilt = GetPhotcodeNsecfilt (); 737 738 int Ns; 739 for (Ns = 0; Ns < Nphotcodes; Ns++) { 740 741 int thisCode = photcodes[Ns][0].code; 742 int Nsec = GetPhotcodeNsec(thisCode); 743 744 for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i; 745 bzero (Mlist, NBIN*sizeof(double)); 746 for (i = 0; i < Ncatalog; i++) { 747 for (j = 0; j < catalog[i].Naverage; j++) { 748 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 749 dMrel = catalog[i].secfilt[Nsecfilt*j+Nsec].dM; 750 bin = dMrel / 0.00025; 751 bin = MAX (0, MIN (NBIN-1, bin)); 752 Mlist[bin] += 1.0; 753 } 754 } 755 756 plot_defaults (&graphdata); 757 graphdata.style = 1; 758 plot_list (&graphdata, xlist, Mlist, NBIN, "dMrel hist", "%s.dMhist.png", OUTROOT); 759 } 662 760 free (xlist); 663 761 free (Mlist); … … 671 769 Graphdata graphdata; 672 770 771 int Nsecfilt = GetPhotcodeNsecfilt (); 772 673 773 Ntotal = 0; 674 774 for (i = 0; i < Ncatalog; i++) Ntotal += catalog[i].Naverage; … … 677 777 ALLOCATE (ylist, double, Ntotal); 678 778 679 N = 0; 680 for (i = 0; i < Ncatalog; i++) { 681 for (j = 0; j < catalog[i].Naverage; j++) { 682 if (catalog[i].average[j].flags & STAR_BAD) continue; 683 xlist[N] = catalog[i].secfilt[PhotNsec*j+PhotSec].M; 684 value = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm; 685 if (value == NAN_S_SHORT) continue; 686 ylist[N] = 0.01*value; 687 N++; 688 } 689 } 690 691 plot_defaults (&graphdata); 692 graphdata.ymin = -3.0; 693 plot_list (&graphdata, xlist, ylist, N, "chisq", "%s.chisq.png", OUTROOT); 779 int Ns; 780 for (Ns = 0; Ns < Nphotcodes; Ns++) { 781 782 int thisCode = photcodes[Ns][0].code; 783 int Nsec = GetPhotcodeNsec(thisCode); 784 785 N = 0; 786 for (i = 0; i < Ncatalog; i++) { 787 for (j = 0; j < catalog[i].Naverage; j++) { 788 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 789 xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].M; 790 value = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm; 791 if (value == NAN_S_SHORT) continue; 792 ylist[N] = 0.01*value; 793 N++; 794 } 795 } 796 797 plot_defaults (&graphdata); 798 graphdata.ymin = -3.0; 799 plot_list (&graphdata, xlist, ylist, N, "chisq", "%s.chisq.png", OUTROOT); 800 } 801 694 802 free (xlist); 695 803 free (ylist); … … 716 824 for (i = 0; i < Ncatalog; i++) { 717 825 for (j = 0; j < catalog[i].Naverage; j++) { 718 xlist[N] = catalog[i].average [j].R;719 ylist[N] = catalog[i].average [j].D;826 xlist[N] = catalog[i].averageT[j].R; 827 ylist[N] = catalog[i].averageT[j].D; 720 828 N++; 721 829 } -
trunk/Ohana/src/relphot/src/args.c
r31160 r31450 128 128 } 129 129 130 MaxDensityUse = FALSE; 131 if ((N = get_argument (argc, argv, "-max-density"))) { 132 remove_argument (N, &argc, argv); 133 MaxDensityValue = atof(argv[N]); 134 remove_argument (N, &argc, argv); 135 MaxDensityUse = TRUE; 136 } 137 130 138 SHOW_PARAMS = FALSE; 131 139 if ((N = get_argument (argc, argv, "-params"))) { -
trunk/Ohana/src/relphot/src/bcatalog.c
r31160 r31450 1 1 # include "relphot.h" 2 3 extern double drand48(); 4 5 int CopyAverageTiny (AverageTiny *averageT, Average *average) { 6 7 averageT[0].R = average[0].R; 8 averageT[0].D = average[0].D; 9 averageT[0].flags = average[0].flags; 10 averageT[0].Nmeasure = average[0].Nmeasure; 11 averageT[0].measureOffset = average[0].measureOffset; 12 13 // make Nmeasure & measureOffset optional? 14 15 return (TRUE); 16 } 17 18 int CopyMeasureTiny (MeasureTiny *measureT, Measure *measure) { 19 20 measureT[0].dR = measure[0].dR; 21 measureT[0].dD = measure[0].dD; 22 measureT[0].M = measure[0].M; 23 measureT[0].Mcal = measure[0].Mcal; 24 measureT[0].dM = measure[0].dM; 25 measureT[0].airmass = measure[0].airmass; 26 measureT[0].Xccd = measure[0].Xccd; 27 measureT[0].Yccd = measure[0].Yccd; 28 measureT[0].t = measure[0].t; 29 measureT[0].dt = measure[0].dt; 30 measureT[0].averef = measure[0].averef; 31 measureT[0].imageID = measure[0].imageID; 32 measureT[0].dbFlags = measure[0].dbFlags; 33 measureT[0].photcode = measure[0].photcode; 34 35 return (TRUE); 36 } 2 37 3 38 int bcatalog (Catalog *subcatalog, Catalog *catalog) { 4 39 5 40 off_t i, j, offset; 6 int ecode ;41 int ecode, found, Ns; 7 42 off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm; 8 43 float mag; 9 44 int Ncode, Ntime, Ndophot, Nmag, Nsigma, Nimag, Nfew, Ngalaxy, Npsfqf; 10 45 11 // XXX PhotNsec as a global is a bad idea; either get it from catalog 12 // or get it from: 13 // Nsecfilt = GetPhotcodeNsecfilt (); 14 // assert (catalog[0].Nsecfilt == Nsecfilt); 46 int Nsecfilt = GetPhotcodeNsecfilt (); 47 assert (Nsecfilt == catalog[0].Nsecfilt); 15 48 16 49 /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */ … … 18 51 NAVERAGE = 50; 19 52 NMEASURE = 1000; 20 ALLOCATE (subcatalog[0]. average, Average, NAVERAGE);21 ALLOCATE (subcatalog[0]. secfilt, SecFilt, NAVERAGE*PhotNsec);22 ALLOCATE (subcatalog[0]. measure, Measure, NMEASURE);53 ALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE); 54 ALLOCATE (subcatalog[0].averageT, AverageTiny, NAVERAGE); 55 ALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt); 23 56 Nmeasure = Naverage = 0; 24 57 … … 30 63 31 64 /* start with all stars good */ 32 subcatalog[0].average[Naverage] = catalog[0].average[i]; 33 subcatalog[0].average[Naverage].measureOffset = Nmeasure; 34 for (j = 0; j < PhotNsec; j++) { 35 subcatalog[0].secfilt[PhotNsec*Naverage+j] = catalog[0].secfilt[PhotNsec*i+j]; 65 CopyAverageTiny (&subcatalog[0].averageT[Naverage], &catalog[0].average[i]); 66 subcatalog[0].averageT[Naverage].measureOffset = Nmeasure; 67 68 for (j = 0; j < Nsecfilt; j++) { 69 subcatalog[0].secfilt[Nsecfilt*Naverage+j] = catalog[0].secfilt[Nsecfilt*i+j]; 36 70 } 37 71 38 72 if (RESET) { 39 subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].M = NAN; 40 subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].dM = NAN; 41 subcatalog[0].average[Naverage].flags &= ~ID_STAR_FEW; 42 subcatalog[0].average[Naverage].flags &= ~ID_STAR_POOR; 73 int Ns; 74 for (Ns = 0; Ns < Nphotcodes; Ns++) { 75 76 int thisCode = photcodes[Ns][0].code; 77 int Nsec = GetPhotcodeNsec(thisCode); 78 79 subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M = NAN; 80 subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].dM = NAN; 81 subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].flags &= ~ID_STAR_FEW; 82 subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].flags &= ~ID_STAR_POOR; 83 } 43 84 } 44 85 … … 52 93 /* select measurements by photcode */ 53 94 ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[offset].photcode); 54 if (ecode != photcode[0].code) { Ncode ++; continue; } 95 found = FALSE; 96 for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 97 if (ecode == photcodes[Ns][0].code) found = TRUE; 98 } 99 if (!found) { 100 Ncode ++; 101 continue; 102 } 55 103 56 104 /* select measurements by time */ … … 61 109 62 110 /* select measurements by quality */ 63 // XXX ignore this criterion for REF measurements?64 // XXX chnage this to select by bitflags65 111 if (DophotSelect && ((catalog[0].measure[offset].photFlags >> 16) != DophotValue)) { Ndophot ++; continue; } 66 112 … … 70 116 // check for galaxies 71 117 if (!isnan(catalog[0].measure[offset].Map)) { 72 if (catalog[0].measure[offset].M - catalog[0].measure[offset].Map > 0.15) {73 nEXT ++;74 } else {75 nPSF ++;76 }118 if (catalog[0].measure[offset].M - catalog[0].measure[offset].Map > 0.15) { 119 nEXT ++; 120 } else { 121 nPSF ++; 122 } 77 123 } 78 124 … … 91 137 } 92 138 93 subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;94 subcatalog[0].measure [Nmeasure] = catalog[0].measure[offset];95 subcatalog[0].measure [Nmeasure].averef = Naverage;139 CopyMeasureTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]); 140 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 141 subcatalog[0].measureT[Nmeasure].averef = Naverage; 96 142 if (RESET) { 97 subcatalog[0].measure [Nmeasure].Mcal = 0;98 subcatalog[0].measure [Nmeasure].dbFlags &= 0xff00;99 subcatalog[0].measure [Nmeasure].dbFlags &= ~ID_MEAS_POOR_PHOTOM;100 subcatalog[0].measure [Nmeasure].dbFlags &= ~ID_MEAS_AREA;101 subcatalog[0].measure [Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;143 subcatalog[0].measureT[Nmeasure].Mcal = 0; 144 subcatalog[0].measureT[Nmeasure].dbFlags &= 0xff00; 145 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_PHOTOM; 146 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA; 147 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL; 102 148 } 103 149 Nmeasure ++; … … 105 151 if (Nmeasure == NMEASURE) { 106 152 NMEASURE += 1000; 107 REALLOCATE (subcatalog[0].measure , Measure, NMEASURE);153 REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE); 108 154 } 109 155 } … … 122 168 continue; 123 169 } 124 subcatalog[0].average [Naverage].Nmeasure = Nm;170 subcatalog[0].averageT[Naverage].Nmeasure = Nm; 125 171 Naverage ++; 126 172 if (Naverage == NAVERAGE) { 127 173 NAVERAGE += 50; 128 REALLOCATE (subcatalog[0].average , Average, NAVERAGE);129 REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*PhotNsec);130 } 131 } 132 REALLOCATE (subcatalog[0].average , Average, MAX (Naverage, 1));133 REALLOCATE (subcatalog[0].measure , Measure, MAX (Nmeasure, 1));134 REALLOCATE (subcatalog[0].secfilt, SecFilt, PhotNsec*MAX (Naverage, 1));174 REALLOCATE (subcatalog[0].averageT, AverageTiny, NAVERAGE); 175 REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt); 176 } 177 } 178 REALLOCATE (subcatalog[0].averageT, AverageTiny, MAX (Naverage, 1)); 179 REALLOCATE (subcatalog[0].measureT, MeasureTiny, MAX (Nmeasure, 1)); 180 REALLOCATE (subcatalog[0].secfilt, SecFilt, Nsecfilt*MAX (Naverage, 1)); 135 181 subcatalog[0].Naverage = Naverage; 136 182 subcatalog[0].Nmeasure = Nmeasure; 137 183 subcatalog[0].Nsecfilt = catalog[0].Nsecfilt; 138 184 subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt; 139 assert (PhotNsec == catalog[0].Nsecfilt); 185 186 // limit the total number of stars in the catalog 187 if (MaxDensityUse) { 188 LimitDensityCatalog (subcatalog, catalog); 189 } 140 190 141 191 if (VERBOSE) { … … 147 197 return (TRUE); 148 198 } 199 200 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) { 201 202 Catalog tmpcatalog; 203 204 double Rmin, Rmax, Dmin, Dmax; 205 206 int Nsecfilt = GetPhotcodeNsecfilt (); 207 208 gfits_scan (&catalog[0].header, "RA0", "%lf", 1, &Rmin); 209 gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin); 210 gfits_scan (&catalog[0].header, "RA1", "%lf", 1, &Rmax); 211 gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax); 212 213 if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax); 214 215 float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin)); 216 assert (AREA > 0); 217 218 off_t Nmax = MaxDensityValue * AREA; 219 if (subcatalog[0].Naverage <= Nmax) { 220 if (VERBOSE) { 221 fprintf (stderr, "subcatalog has less than the max density\n"); 222 } 223 return (TRUE); 224 } 225 226 off_t Naverage = subcatalog[0].Naverage; 227 228 // select a random subset of Nmax stars from subcatalog using Fisher-Yates 229 230 // we are going to select Nmax entries by generating a random-sorted index list 231 off_t *index, tmp, i, j, ave; 232 ALLOCATE (index, off_t, Naverage); 233 for (i = 0; i < Naverage; i++) { 234 index[i] = i; 235 } 236 for (i = 0; i < Naverage; i++) { 237 j = (Naverage - i) * drand48() + i; // a number between i and Naverage 238 tmp = index[j]; 239 index[j] = index[i]; 240 index[i] = tmp; 241 } 242 243 // count the number of measurements this selection will yield 244 off_t NMEASURE = 0; 245 for (i = 0; i < Nmax; i++) { 246 ave = index[i]; 247 NMEASURE += subcatalog[0].averageT[ave].Nmeasure; 248 } 249 250 // allocate the output data 251 ALLOCATE (tmpcatalog.averageT, AverageTiny, Nmax); 252 ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE); 253 ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * Nsecfilt); 254 255 off_t Nmeasure = 0; 256 257 // copy the Nmax selected entries from subcatalog to tmpcatalog (adjusting links) 258 for (i = 0; i < Nmax; i++) { 259 ave = index[i]; 260 tmpcatalog.averageT[i] = subcatalog[0].averageT[ave]; 261 tmpcatalog.averageT[i].measureOffset = Nmeasure; 262 for (j = 0; j < tmpcatalog.averageT[i].Nmeasure; j++) { 263 off_t offset = subcatalog[0].averageT[ave].measureOffset + j; 264 tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset]; 265 tmpcatalog.measureT[Nmeasure].averef = i; 266 Nmeasure ++; 267 } 268 } 269 270 if (VERBOSE) { 271 fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n", 272 Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure, catalog[0].filename); 273 } 274 275 free (subcatalog[0].averageT); 276 free (subcatalog[0].measureT); 277 free (subcatalog[0].secfilt); 278 279 subcatalog[0].averageT = tmpcatalog.averageT; 280 subcatalog[0].measureT = tmpcatalog.measureT; 281 subcatalog[0].secfilt = tmpcatalog.secfilt; 282 subcatalog[0].Naverage = Nmax; 283 subcatalog[0].Nmeasure = Nmeasure; 284 subcatalog[0].Nsecfilt = catalog[0].Nsecfilt; 285 subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt; 286 287 return (TRUE); 288 } 289 290 // for the cases where we are not using a subset of the data, we still need to have a copy of these fields 291 int populate_tiny_values (Catalog *catalog) { 292 293 off_t i; 294 295 ALLOCATE (catalog[0].measureT, MeasureTiny, catalog[0].Nmeasure); 296 ALLOCATE (catalog[0].averageT, AverageTiny, catalog[0].Naverage); 297 298 for (i = 0; i < catalog[0].Naverage; i++) { 299 CopyAverageTiny (&catalog[0].averageT[i], &catalog[0].average[i]); 300 } 301 302 for (i = 0; i < catalog[0].Nmeasure; i++) { 303 CopyMeasureTiny (&catalog[0].measureT[i], &catalog[0].measure[i]); 304 } 305 306 return (TRUE); 307 } 308 309 int free_tiny_values (Catalog *catalog) { 310 311 free (catalog[0].averageT); 312 free (catalog[0].measureT); 313 return (TRUE); 314 } 315 -
trunk/Ohana/src/relphot/src/global_stats.c
r5143 r31450 7 7 initstats ("MEAN"); 8 8 9 stN = statsStarN (catalog, Ncatalog); 10 stX = statsStarX (catalog, Ncatalog); 11 stS = statsStarS (catalog, Ncatalog); 9 fprintf (stderr, "\n"); 10 fprintf (stderr, "STATS median mean sigma min max Nmeas\n"); 12 11 12 int Ns; 13 for (Ns = 0; Ns < Nphotcodes; Ns++) { 14 15 int thisCode = photcodes[Ns][0].code; 16 int Nsec = GetPhotcodeNsec(thisCode); 17 int seccode = photcodes[Ns][0].code; 18 19 stN = statsStarN (catalog, Ncatalog, Nsec, seccode); 20 stX = statsStarX (catalog, Ncatalog, Nsec); 21 stS = statsStarS (catalog, Ncatalog, Nsec); 22 23 fprintf (stderr, " --- stats for %s ---\n", photcodes[Ns][0].name); 24 fprintf (stderr, "meas / star: %7.0f %7.1f %7.1f %7.0f %7.0f %6d\n", stN.median, stN.mean, stN.sigma, stN.min, stN.max, stN.Nmeas); 25 fprintf (stderr, "dMrel star: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", stS.median, stS.mean, stS.sigma, stS.min, stS.max, stS.Nmeas); 26 fprintf (stderr, "chisq star: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", stX.median, stX.mean, stX.sigma, stX.min, stX.max, stX.Nmeas); 27 } 28 13 29 imN = statsImageN (catalog); 14 30 imX = statsImageX (catalog); 15 31 imM = statsImageM (catalog); 16 32 imD = statsImagedM (catalog); 17 33 18 34 msN = statsMosaicN (catalog); 19 35 msM = statsMosaicM (catalog); 20 36 msD = statsMosaicdM (catalog); 21 37 msX = statsMosaicX (catalog); 22 23 fprintf (stderr, "STATS median mean sigma min max Nmeas\n"); 38 24 39 fprintf (stderr, "meas / image: %7.0f %7.0f %7.0f %7.0f %7.0f %6d\n", imN.median, imN.mean, imN.sigma, imN.min, imN.max, imN.Nmeas); 25 fprintf (stderr, "meas / mosaic: %7.0f %7.0f %7.0f %7.0f %7.0f %6d\n", msN.median, msN.mean, msN.sigma, msN.min, msN.max, msN.Nmeas);26 fprintf (stderr, "meas / star: %7.0f %7.1f %7.1f %7.0f %7.0f %6d\n", stN.median, stN.mean, stN.sigma, stN.min, stN.max, stN.Nmeas);27 28 fprintf (stderr, "chisq image: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", imX.median, imX.mean, imX.sigma, imX.min, imX.max, imX.Nmeas);29 fprintf (stderr, "chisq mosaic: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", msX.median, msX.mean, msX.sigma, msX.min, msX.max, msX.Nmeas);30 fprintf (stderr, "chisq star: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", stX.median, stX.mean, stX.sigma, stX.min, stX.max, stX.Nmeas);31 32 40 fprintf (stderr, "Mcal image: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", imM.median, imM.mean, imM.sigma, imM.min, imM.max, imM.Nmeas); 33 41 fprintf (stderr, "dMcal image: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", imD.median, imD.mean, imD.sigma, imD.min, imD.max, imD.Nmeas); 42 fprintf (stderr, "chisq image: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", imX.median, imX.mean, imX.sigma, imX.min, imX.max, imX.Nmeas); 34 43 44 fprintf (stderr, "meas / mosaic: %7.0f %7.0f %7.0f %7.0f %7.0f %6d\n", msN.median, msN.mean, msN.sigma, msN.min, msN.max, msN.Nmeas); 35 45 fprintf (stderr, "Mcal mosaic: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", msM.median, msM.mean, msM.sigma, msM.min, msM.max, msM.Nmeas); 36 46 fprintf (stderr, "dMcal mosaic: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", msD.median, msD.mean, msD.sigma, msD.min, msD.max, msD.Nmeas); 37 38 fprintf (stderr, "dMrel star: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n\n", stS.median, stS.mean, stS.sigma, stS.min, stS.max, stS.Nmeas);47 fprintf (stderr, "chisq mosaic: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", msX.median, msX.mean, msX.sigma, msX.min, msX.max, msX.Nmeas); 48 39 49 40 50 initstats (STATMODE); -
trunk/Ohana/src/relphot/src/initialize.c
r30616 r31450 13 13 N = UserPatchSelect ? 1 : 2; 14 14 15 # if (0) 16 // XXX DEP 15 17 if ((photcode = GetPhotcodebyName (argv[N])) == NULL) { 16 18 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]); … … 21 23 exit (1); 22 24 } 25 // PhotSec is used to select the single average photcode being processed 23 26 PhotSec = GetPhotcodeNsec (photcode[0].code); 27 # endif 28 29 Nphotcodes = 0; 30 photcodes = NULL; 31 int NPHOTCODES = 10; 32 ALLOCATE (photcodes, PhotCode *, NPHOTCODES); 33 34 /* parse the comma-separated list of photcodesKeep */ 35 char *myList = strcreate(argv[N]); 36 char *list = myList; 37 char *codename = NULL; 38 char *ptr = NULL; 39 while ((codename = strtok_r (list, ",", &ptr)) != NULL) { 40 list = NULL; // pass NULL on successive strtok_r calls 41 fprintf (stderr, "PHOTCODE LIST: %s\n", myList); 42 fprintf (stderr, "codename: %s\n", codename); 43 if ((photcodes[Nphotcodes] = GetPhotcodebyName (codename)) == NULL) { 44 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename); 45 exit (1); 46 } 47 if (photcodes[Nphotcodes][0].type != PHOT_SEC) { 48 fprintf (stderr, "photcode %s is not an filter type (SEC)\n", codename); 49 exit (1); 50 } 51 Nphotcodes ++; 52 CHECK_REALLOCATE (photcodes, PhotCode *, NPHOTCODES, Nphotcodes, 10); 53 } 24 54 } 25 26 PhotNsec = GetPhotcodeNsecfilt (); 55 // XXX DEP PhotNsec = GetPhotcodeNsecfilt (); 56 if (USE_GRID && (Nphotcodes > 1)) { 57 fprintf (stderr, "grid correction analysis currently can only operate on a single photcode\n"); 58 exit (1); 59 } 27 60 28 61 initstats (STATMODE); … … 55 88 exit (0); 56 89 } 90 91 // init the random seed 92 long A, B; 93 A = time(NULL); 94 for (B = 0; A == time(NULL); B++); 95 srand48(B); 57 96 } 58 -
trunk/Ohana/src/relphot/src/load_images.c
r31160 r31450 44 44 // select the images which overlap the selected sky regions 45 45 subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset); 46 MARKTIME("selected images: %f sec\n", dtime);46 MARKTIME("selected %d overlapping images: %f sec\n", (int) Nsubset, dtime); 47 47 48 48 // generate db->vtable from db->ftable based on the selection -
trunk/Ohana/src/relphot/src/plot_scatter.c
r27435 r31450 18 18 ALLOCATE (ilist, double, Ntot); 19 19 20 N = 0; 21 for (i = 0; i < Ncatalog; i++) { 22 for (j = 0; j < catalog[i].Naverage; j++) { 20 int Nsecfilt = GetPhotcodeNsecfilt (); 23 21 24 /* calculate the average value for a single star */ 25 if (catalog[i].average[j].flags & STAR_BAD) continue; 26 m = catalog[i].average[j].measureOffset; 22 int Ns; 23 for (Ns = 0; Ns < Nphotcodes; Ns++) { 27 24 28 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 29 if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; 30 Mcal = getMcal (m, i); 31 if (isnan(Mcal)) continue; 32 Mmos = getMmos (m, i); 33 if (isnan(Mmos)) continue; 34 Mgrid = getMgrid (m, i); 35 if (isnan(Mgrid)) continue; 25 int thisCode = photcodes[Ns][0].code; 26 int Nsec = GetPhotcodeNsec(thisCode); 36 27 37 Mrel = catalog[i].secfilt[PhotNsec*j+PhotSec].M; 38 xlist[N] = Mrel; 39 ylist[N] = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]) - Mcal - Mmos - Mgrid - Mrel; 40 ilist[N] = PhotInst (&catalog[i].measure[m]); 41 N++; 42 } 28 N = 0; 29 for (i = 0; i < Ncatalog; i++) { 30 for (j = 0; j < catalog[i].Naverage; j++) { 31 32 /* calculate the average value for a single star */ 33 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 34 m = catalog[i].average[j].measureOffset; 35 36 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 37 // skip measurements that do not match the current photcode 38 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 39 if (ecode != thisCode) { continue; } 40 41 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 42 Mcal = getMcal (m, i); 43 if (isnan(Mcal)) continue; 44 Mmos = getMmos (m, i); 45 if (isnan(Mmos)) continue; 46 Mgrid = getMgrid (m, i); 47 if (isnan(Mgrid)) continue; 48 49 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].M; 50 xlist[N] = Mrel; 51 ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]) - Mcal - Mmos - Mgrid - Mrel; 52 ilist[N] = PhotInstTiny (&catalog[i].measureT[m]); 53 N++; 54 } 55 } 43 56 } 57 58 plot_defaults (&graphdata); 59 graphdata.xmin = PlotMmin; 60 graphdata.xmax = PlotMmax; 61 graphdata.ymin = PlotdMmin; 62 graphdata.ymax = PlotdMmax; 63 plot_list (&graphdata, xlist, ylist, N, "mag vs dmag", "%s.Mag.png", OUTROOT); 64 65 plot_defaults (&graphdata); 66 graphdata.ymin = PlotdMmin; 67 graphdata.ymax = PlotdMmax; 68 plot_list (&graphdata, ilist, ylist, N, "imag vs dmag", "%s.iMag.png", OUTROOT); 44 69 } 45 46 plot_defaults (&graphdata);47 graphdata.xmin = PlotMmin;48 graphdata.xmax = PlotMmax;49 graphdata.ymin = PlotdMmin;50 graphdata.ymax = PlotdMmax;51 plot_list (&graphdata, xlist, ylist, N, "mag vs dmag", "%s.Mag.png", OUTROOT);52 53 plot_defaults (&graphdata);54 graphdata.ymin = PlotdMmin;55 graphdata.ymax = PlotdMmax;56 plot_list (&graphdata, ilist, ylist, N, "imag vs dmag", "%s.iMag.png", OUTROOT);57 70 free (xlist); 58 71 free (ylist); -
trunk/Ohana/src/relphot/src/reload_catalogs.c
r15743 r31450 1 1 # include "relphot.h" 2 3 # define TIMESTAMP(TIME) \ 4 gettimeofday (&stop, (void *) NULL); \ 5 dtime = DTIME (stop, start); \ 6 TIME += dtime; \ 7 gettimeofday (&start, (void *) NULL); 2 8 3 9 void reload_catalogs (SkyList *skylist) { … … 8 14 Catalog catalog; 9 15 16 struct timeval start, stop; 17 double dtime = 0.0; 18 double time1 = 0.0; 19 double time2 = 0.0; 20 double time3 = 0.0; 21 double time4 = 0.0; 22 double time5 = 0.0; 23 double time6 = 0.0; 24 double time7 = 0.0; 25 10 26 if (VERBOSE) fprintf (stderr, "re-loading catalog data\n"); 11 27 12 28 /* load data from each region file */ 13 29 for (i = 0; i < skylist[0].Nregions; i++) { 30 gettimeofday (&start, (void *) NULL); 14 31 catalog.filename = skylist[0].filename[i]; 15 32 … … 20 37 continue; 21 38 } 39 TIMESTAMP(time1); 22 40 23 41 catalog.catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data … … 36 54 continue; 37 55 } 56 TIMESTAMP(time2); 57 58 populate_tiny_values(&catalog); 38 59 39 60 initImageBins (&catalog, 1); 40 61 initMosaicBins (&catalog, 1); 41 initGridBins (&catalog, 1); 62 initGridBins (&catalog, 1); 63 TIMESTAMP(time3); 42 64 43 findImages (&catalog, 1); 44 findMosaics (&catalog, 1); 65 findImages (&catalog, 1); // FX 66 findMosaics (&catalog, 1); // 67 TIMESTAMP(time4); 45 68 46 69 setMrelFinal (&catalog); 70 TIMESTAMP(time5); 71 47 72 dvo_catalog_save (&catalog, VERBOSE); 48 73 dvo_catalog_unlock (&catalog); 74 75 free_tiny_values(&catalog); 49 76 dvo_catalog_free (&catalog); 77 TIMESTAMP(time6); 50 78 51 79 freeImageBins (1); 52 80 freeMosaicBins (1); 53 81 freeGridBins (1); 82 TIMESTAMP(time7); 54 83 } 84 85 fprintf (stderr, "time1 %f : find catalog\n", time1); 86 fprintf (stderr, "time2 %f : load catalog\n", time2); 87 fprintf (stderr, "time3 %f : init imbins\n", time3); 88 fprintf (stderr, "time4 %f : find images\n", time4); 89 fprintf (stderr, "time5 %f : set Mrel\n", time5); 90 fprintf (stderr, "time6 %f : save catalog\n", time6); 91 fprintf (stderr, "time7 %f : free catalog\n", time7); 55 92 } -
trunk/Ohana/src/relphot/src/relphot.c
r30616 r31450 47 47 if (!dvo_image_load (&db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db.filename); 48 48 } 49 MARKTIME(" load image data: %f sec\n", dtime);49 MARKTIME("-- load image data: %f sec\n", dtime); 50 50 51 51 /* load regions and images based on specified sky patch */ … … 54 54 // XXX this is fairly lame: argv[1] is photcode if UserPatchSelect is true 55 55 skylist = load_images (&db, argv[1], &UserPatch, UserPatchSelect); 56 MARKTIME(" load images: %f sec\n", dtime);56 MARKTIME("-- load images: %f sec\n", dtime); 57 57 58 58 /* unlock, if we can (else, unlocked below) */ … … 61 61 /* load catalog data from region files */ 62 62 catalog = load_catalogs (skylist, &Ncatalog); 63 MARKTIME(" load catalog data: %f sec\n", dtime);63 MARKTIME("-- load catalog data: %f sec\n", dtime); 64 64 65 65 /* add in a loop over the catalogs calling dvo_catalog_chipcoords */ … … 67 67 /* match measurements with images, mosaics */ 68 68 initImageBins (catalog, Ncatalog); 69 MARKTIME(" make image bins: %f sec\n", dtime);69 MARKTIME("-- make image bins: %f sec\n", dtime); 70 70 71 71 initMosaicBins (catalog, Ncatalog); … … 74 74 75 75 findImages (catalog, Ncatalog); 76 MARKTIME(" set up image indexes: %f sec\n", dtime);76 MARKTIME("-- set up image indexes: %f sec\n", dtime); 77 77 78 78 findMosaics (catalog, Ncatalog); /* also sets Grid values */ 79 MARKTIME(" set up mosaic indexes: %f sec\n", dtime);79 MARKTIME("-- set up mosaic indexes: %f sec\n", dtime); 80 80 81 81 SAVEPLOT = FALSE; 82 82 83 83 setExclusions (catalog, Ncatalog); 84 85 global_stats (catalog, Ncatalog); 84 86 85 87 if (PLOTSTUFF) { … … 91 93 if (USE_GRID) { 92 94 int star_toofew; 93 94 # if (USE_DIRECT)95 // until we finish the grid analysis, do not reject stars out-of-hand based on ID_STAR_FEW96 // XXX this is kind of poor: need to have a better distinctions about STAR_BAD in setMrel vs getMrel97 star_toofew = STAR_TOOFEW;98 STAR_TOOFEW = 0;99 STAR_BAD = ID_STAR_POOR;100 101 showGridCount ();102 setMgridDirect (catalog, Ncatalog);103 104 STAR_BAD = ID_STAR_POOR | ID_STAR_FEW;105 STAR_TOOFEW = star_toofew;106 107 dump_grid ();108 exit (0);109 110 # else111 95 112 96 // until we finish the grid analysis, do not reject stars out-of-hand based on ID_STAR_FEW … … 122 106 STAR_BAD = ID_STAR_POOR | ID_STAR_FEW; 123 107 STAR_TOOFEW = star_toofew; 124 # endif125 108 } 126 109 … … 140 123 plot_chisq (catalog, Ncatalog); 141 124 } 142 if ((i == 1) || (i == 5) || (i == 9) || (i == 13)) clean_measures (catalog, Ncatalog, FALSE); 143 if ((i == 2) || (i == 6) || (i == 10) || (i == 14)) clean_stars (catalog, Ncatalog); 144 if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_mosaics (); 145 if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_images (); 125 if (i % 6 == 1) rationalize_mosaics (catalog, Ncatalog); 126 // if (i % 6 == 1) rationalize_images (); 127 if (i % 6 == 2) clean_measures (catalog, Ncatalog, FALSE); 128 if (i % 6 == 3) clean_stars (catalog, Ncatalog); 129 if (i % 6 == 5) clean_mosaics (); 130 if (i % 6 == 5) clean_images (); 131 132 // if ((i == 1) || (i == 5) || (i == 9) || (i == 13)) clean_measures (catalog, Ncatalog, FALSE); 133 // if ((i == 2) || (i == 6) || (i == 10) || (i == 14)) clean_stars (catalog, Ncatalog); 134 // if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_mosaics (); 135 // if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_images (); 146 136 global_stats (catalog, Ncatalog); 137 MARKTIME("-- finished loop %d: %f sec\n", i, dtime); 147 138 } 148 139 149 SAVEPLOT = TRUE; 150 plot_scatter (catalog, Ncatalog); 151 plot_grid (catalog); 152 plot_mosaics (); 153 plot_images (); 154 plot_stars (catalog, Ncatalog); 155 plot_chisq (catalog, Ncatalog); 156 140 if (PLOTSTUFF) { 141 plot_scatter (catalog, Ncatalog); 142 plot_grid (catalog); 143 plot_mosaics (); 144 plot_images (); 145 plot_stars (catalog, Ncatalog); 146 plot_chisq (catalog, Ncatalog); 147 } 148 157 149 if (USE_GRID) dump_grid (); 158 150 if (!UPDATE) exit (0); … … 161 153 setMcal (catalog, TRUE); 162 154 setMmos (catalog, TRUE); 155 MARKTIME("-- finalize Mcal values: %f sec\n", dtime); 163 156 164 157 /* at this point, we have correct cal coeffs in the image/mosaic structures */ 165 for (i = 0; i < Ncatalog; i++) dvo_catalog_free (&catalog[i]); 158 for (i = 0; i < Ncatalog; i++) { 159 free_tiny_values (&catalog[i]); 160 dvo_catalog_free (&catalog[i]); 161 } 166 162 freeImageBins (Ncatalog); 167 163 freeMosaicBins (Ncatalog); … … 170 166 /* load catalog data from region files, update Mrel include all data */ 171 167 reload_catalogs (skylist); 168 MARKTIME("-- updated all catalogs: %f sec\n", dtime); 169 172 170 setMcalFinal (); 173 174 171 reload_images (&db); 175 172 -
trunk/Ohana/src/relphot/src/relphot_objects.c
r28241 r31450 3 3 int relphot_objects () { 4 4 5 off_t i, j, k , m;5 off_t i, j, k; 6 6 int Nsecfilt; 7 7 … … 38 38 } 39 39 40 // XXX consider what gets reset (only PHOTOM flags)40 // reset 41 41 if (RESET) { 42 42 Nsecfilt = catalog.Nsecfilt; … … 51 51 catalog.secfilt[j*Nsecfilt + k].Ncode = 0; 52 52 catalog.secfilt[j*Nsecfilt + k].Nused = 0; 53 } 54 m = catalog.average[j].measureOffset; 55 for (k = 0; k < catalog.average[j].Nmeasure; k++) { 56 catalog.measure[m+k].dbFlags = 0; 57 catalog.measure[m+k].Mcal = 0; 53 // XXX reset the photometry flags for secfilt entries? 58 54 } 59 55 } -
trunk/Ohana/src/relphot/src/select_images.c
r31160 r31450 64 64 DmaxSkyRegion = -90.0; 65 65 66 // FILE *ftest = fopen ("relphot.dump.dat", "w"); 67 66 68 /* compare with each region file */ 67 69 for (i = 0; i < skylist[0].Nregions; i++) { … … 117 119 /* exclude images by photcode */ 118 120 ecode = GetPhotcodeEquivCodebyCode (timage[i].photcode); 119 if (ecode != photcode[0].code) continue; 121 found = FALSE; 122 int Ns; 123 for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 124 if (ecode == photcodes[Ns][0].code) found = TRUE; 125 } 126 if (!found) continue; 120 127 121 128 /* exclude images by time */ … … 130 137 continue; 131 138 } 139 140 // XXX temporary test : record center coords for each accepted and rejected chip/mosaic 141 // double RAo, DECo; 132 142 133 143 /* define image corners - note the DIS images (mosaic phu) are special */ … … 138 148 Xi[3] = -0.5*timage[i].NX; Yi[3] = +0.5*timage[i].NY; 139 149 Xi[4] = -0.5*timage[i].NX; Yi[4] = -0.5*timage[i].NY; 150 // XY_to_RD(&RAo, &DECo, 0.0, 0.0, &timage[i].coords); 140 151 } else { 141 152 Xi[0] = 0; Yi[0] = 0; … … 144 155 Xi[3] = 0; Yi[3] = timage[i].NY; 145 156 Xi[4] = 0; Yi[4] = 0; 157 // XY_to_RD(&RAo, &DECo, 0.5*timage[i].NX, 0.5*timage[i].NY, &timage[i].coords); 146 158 } 147 159 found = FALSE; 148 160 149 161 /* transform corners to ra,dec -- costs ~3sec for 3M images (pikake) */ 150 double RminImage = 360.0;151 double RmaxImage = 0.0;162 double RminImage = RmidSkyRegion + 180.0; 163 double RmaxImage = RmidSkyRegion - 180.0; 152 164 double DminImage = +90.0; 153 165 double DmaxImage = -90.0; … … 218 230 219 231 found_it: 232 // XXX We claim this is a good image: write to a test file 233 // fprintf (ftest, "%s : %lf %lf : %f %f %d %x\n", timage[i].name, RAo, DECo, timage[i].Mcal, timage[i].dMcal, timage[i].nstar, timage[i].flags); 234 220 235 image[nimage] = timage[i]; 221 236 /* always allow 'few' images to succeed, if possible */ … … 239 254 } 240 255 MARKTIME("finish image selection: %f sec\n", dtime); 256 257 // fclose (ftest); 241 258 242 259 if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n", nimage); -
trunk/Ohana/src/relphot/src/setExclusions.c
r28241 r31450 1 1 # include "relphot.h" 2 3 // this function sets the NOCAL and AREA dbFlags bits for the MeasureTiny elements these 4 // are used elsewhere (StarOps.c, ImageOps.c, MosaicOps.c, GridOps.c, etc) to skip bad 5 // measurements. The only exception is 'setMave' which is called by 'relphot_objects', 6 // and uses the bits read from disk as the test 2 7 3 8 int setExclusions (Catalog *catalog, int Ncatalog) { 4 9 5 10 off_t i, j, k, m, Narea, Nnocal, Ngood; 6 int ecode ;11 int ecode, found, Ns; 7 12 Coords *coords; 8 13 double r, d, x, y; … … 11 16 for (i = 0; i < Ncatalog; i++) { 12 17 for (j = 0; j < catalog[i].Naverage; j++) { 13 m = catalog[i].average [j].measureOffset;14 for (k = 0; k < catalog[i].average [j].Nmeasure; k++, m++) {18 m = catalog[i].averageT[j].measureOffset; 19 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 15 20 16 21 /* select measurements by photcode */ 17 ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode); 18 if (ecode != photcode[0].code) goto mark_nocal; 22 ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 23 found = FALSE; 24 for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 25 if (ecode == photcodes[Ns][0].code) found = TRUE; 26 } 27 if (!found) goto mark_nocal; 19 28 20 29 /* select measurements by time */ 21 30 if (TimeSelect) { 22 if (catalog[i].measure [m].t < TSTART) goto mark_nocal;23 if (catalog[i].measure [m].t > TSTOP) goto mark_nocal;31 if (catalog[i].measureT[m].t < TSTART) goto mark_nocal; 32 if (catalog[i].measureT[m].t > TSTOP) goto mark_nocal; 24 33 } 25 34 26 35 /* select measurements by mag limit */ 27 36 if (AreaSelect) { 28 r = catalog[i].average [j].R + catalog[i].measure[m].dR / 3600.0;29 d = catalog[i].average [j].D + catalog[i].measure[m].dD / 3600.0;37 r = catalog[i].averageT[j].R + catalog[i].measureT[m].dR / 3600.0; 38 d = catalog[i].averageT[j].D + catalog[i].measureT[m].dD / 3600.0; 30 39 if ((coords = getCoords (m, i)) == NULL) goto markbad; 31 40 RD_to_XY (&x, &y, r, d, coords); … … 39 48 40 49 markbad: 41 catalog[i].measure [m].dbFlags |= ID_MEAS_AREA;50 catalog[i].measureT[m].dbFlags |= ID_MEAS_AREA; 42 51 Narea ++; 43 52 continue; 44 53 45 54 mark_nocal: 46 catalog[i].measure [m].dbFlags |= ID_MEAS_NOCAL;55 catalog[i].measureT[m].dbFlags |= ID_MEAS_NOCAL; 47 56 Nnocal ++; 48 57 continue; -
trunk/Ohana/src/relphot/src/setMrelFinal.c
r29001 r31450 1 1 # include "relphot.h" 2 3 // we've just reloaded the data from disk; we now need to apply the Image/Mosaic/Grid 4 // calibrations determined by the rest of the program. We also need to set the final 5 // output dbFlags values 2 6 3 7 void setMrelFinal (Catalog *catalog) { … … 9 13 if (RESET) { 10 14 11 for (i = 0; i < catalog[0].Naverage; i++) { 12 catalog[0].secfilt[PhotNsec*i+PhotSec].M = NAN; 13 catalog[0].secfilt[PhotNsec*i+PhotSec].dM = NAN; 14 catalog[0].secfilt[PhotNsec*i+PhotSec].Xm = NAN_S_SHORT; 15 int Nsecfilt = GetPhotcodeNsecfilt (); 15 16 16 m = catalog[0].average[i].measureOffset;17 for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {17 int Ns; 18 for (Ns = 0; Ns < Nphotcodes; Ns++) { 18 19 19 /* select measurements by photcode */ 20 ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode); 21 if (ecode != photcode[0].code) continue; 20 int thisCode = photcodes[Ns][0].code; 21 int Nsec = GetPhotcodeNsec(thisCode); 22 23 for (i = 0; i < catalog[0].Naverage; i++) { 24 catalog[0].secfilt[Nsecfilt*i+Nsec].M = NAN; 25 catalog[0].secfilt[Nsecfilt*i+Nsec].dM = NAN; 26 catalog[0].secfilt[Nsecfilt*i+Nsec].Xm = NAN_S_SHORT; 27 28 m = catalog[0].average[i].measureOffset; 29 for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) { 22 30 23 /* select measurements by time */ 24 if (TimeSelect) { 25 if (catalog[0].measure[m].t < TSTART) continue; 26 if (catalog[0].measure[m].t > TSTOP) continue; 31 // skip measurements that do not match the current photcode 32 ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode); 33 if (ecode != thisCode) { continue; } 34 35 /* select measurements by time */ 36 if (TimeSelect) { 37 if (catalog[0].measure[m].t < TSTART) continue; 38 if (catalog[0].measure[m].t > TSTOP) continue; 39 } 40 41 catalog[0].measure[m].Mcal = 0; 42 catalog[0].measure[m].dbFlags &= 0xff00; 43 catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_PHOTOM; 44 catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 45 catalog[0].measure[m].dbFlags &= ~ID_MEAS_AREA; 46 catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL; 27 47 } 28 29 catalog[0].measure[m].Mcal = 0;30 catalog[0].measure[m].dbFlags &= 0xff00;31 catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_PHOTOM;32 catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;33 catalog[0].measure[m].dbFlags &= ~ID_MEAS_AREA;34 catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;35 48 } 36 49 } 37 50 } 38 51 52 // this sets flags in the measureT element, not the measure element 39 53 setExclusions (catalog, 1); /* mark by area */ 40 54 … … 53 67 setMcalOutput (catalog, 1); 54 68 55 /* clear ID_STAR_POOR, ID_STAR_FEW, ID_MEAS_NOCAL values before writing ??? */ 69 int Nsecfilt = GetPhotcodeNsecfilt (); 70 71 /* clear ID_STAR_POOR, ID_STAR_FEW values before writing ??? */ 72 /* ID_MEAS_NOCAL is an internal bit, so it should be cleared */ 56 73 for (i = 0; i < catalog[0].Naverage; i++) { 57 74 catalog[0].average[i].flags &= ~ID_STAR_FEW; 58 75 catalog[0].average[i].flags &= ~ID_STAR_POOR; 76 for (j = 0; j < Nsecfilt; j++) { 77 catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_STAR_FEW; 78 catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_STAR_POOR; 79 } 59 80 m = catalog[0].average[i].measureOffset; 60 81 for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) { … … 68 89 69 90 off_t i, k, m; 70 int ecode ;91 int ecode, found, Ns; 71 92 off_t Ntot, Ntry, Nkeep, Nskip; 72 93 float mag; … … 90 111 91 112 /* clear SKIP for all measures at first */ 92 catalog[0].measure [m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;113 catalog[0].measureT[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 93 114 94 115 /** never use these measurements (wrong photcode, bad time range) */ 95 116 /* skipped via NOCAL, don't mark as skipped */ 96 117 ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode); 97 if (ecode != photcode[0].code) continue; 118 found = FALSE; 119 for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) { 120 if (ecode == photcodes[Ns][0].code) found = TRUE; 121 } 122 if (!found) continue; 98 123 99 124 /* skip measurements by time range */ … … 134 159 135 160 skip: 136 catalog[0].measure[m].dbFlags |= ID_MEAS_SKIP_PHOTOM; 161 catalog[0].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM; 162 catalog[0].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM; 137 163 Nskip ++; 138 164 }
Note:
See TracChangeset
for help on using the changeset viewer.
