Changeset 41647
- Timestamp:
- Jun 7, 2021, 4:14:19 PM (5 years ago)
- Location:
- trunk/Ohana/src/relphot
- Files:
-
- 3 deleted
- 34 edited
- 5 copied
-
. (modified) (1 prop)
-
Makefile (modified) (4 diffs)
-
include/relphot.h (modified) (28 diffs)
-
src/BrightCatalog.c (modified) (4 diffs)
-
src/ConfigInit.c (modified) (3 diffs)
-
src/GridIO.c (copied) (copied from branches/eam_branches/relphot.20210521/src/GridIO.c )
-
src/GridOps.c (modified) (1 diff)
-
src/ImageOps.c (modified) (22 diffs)
-
src/MagResidSave.c (modified) (5 diffs)
-
src/MosaicOps.c (modified) (36 diffs)
-
src/RepairWarpMeasures.c (deleted)
-
src/ResetOps.c (copied) (copied from branches/eam_branches/relphot.20210521/src/ResetOps.c )
-
src/Shutdown.c (modified) (1 diff)
-
src/StackImageMaps.c (deleted)
-
src/StarOps.c (modified) (19 diffs)
-
src/TGroupOps.c (modified) (27 diffs)
-
src/WarpImageMaps.c (deleted)
-
src/ZeroPointModes.c (modified) (6 diffs)
-
src/args.c (modified) (10 diffs)
-
src/assign_images.c (modified) (2 diffs)
-
src/bcatalog.c (modified) (4 diffs)
-
src/extra.c (modified) (3 diffs)
-
src/global_stats.c (modified) (4 diffs)
-
src/initialize.c (modified) (2 diffs)
-
src/launch_region_hosts.c (modified) (1 diff)
-
src/load_catalogs.c (modified) (1 diff)
-
src/load_images.c (modified) (2 diffs)
-
src/plot_scatter.c (modified) (2 diffs)
-
src/reload_catalogs.c (modified) (6 diffs)
-
src/relphot.c (modified) (4 diffs)
-
src/relphot_client.c (modified) (4 diffs)
-
src/relphot_images.c (modified) (12 diffs)
-
src/relphot_objects.c (modified) (2 diffs)
-
src/relphot_parallel_images.c (modified) (8 diffs)
-
src/relphot_parallel_regions.c (modified) (2 diffs)
-
src/select_images.c (modified) (1 diff)
-
src/setMrelCatalog.c (modified) (16 diffs)
-
src/setMrelFinal.c (modified) (6 diffs)
-
test (modified) (1 prop)
-
test/relphot.grid.dvo (copied) (copied from branches/eam_branches/relphot.20210521/test/relphot.grid.dvo )
-
test/relphot.samples.cmd (copied) (copied from branches/eam_branches/relphot.20210521/test/relphot.samples.cmd )
-
test/sample.gdb (copied) (copied from branches/eam_branches/relphot.20210521/test/sample.gdb )
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/relphot
- Property svn:mergeinfo changed
/branches/eam_branches/relphot.20210521 (added) merged: 41602-41608,41610-41612,41615,41620,41623-41627,41631-41632,41637,41644-41646
- Property svn:mergeinfo changed
-
trunk/Ohana/src/relphot/Makefile
r41556 r41647 30 30 $(SRC)/ConfigInit.$(ARCH).o \ 31 31 $(SRC)/GridOps.$(ARCH).o \ 32 $(SRC)/GridIO.$(ARCH).o \ 33 $(SRC)/ResetOps.$(ARCH).o \ 32 34 $(SRC)/ImageOps.$(ARCH).o \ 33 35 $(SRC)/ImageSubset.$(ARCH).o \ … … 39 41 $(SRC)/Shutdown.$(ARCH).o \ 40 42 $(SRC)/StarOps.$(ARCH).o \ 41 $(SRC)/WarpImageMaps.$(ARCH).o \42 $(SRC)/StackImageMaps.$(ARCH).o \43 $(SRC)/RepairWarpMeasures.$(ARCH).o \44 $(SRC)/myIndex.$(ARCH).o \45 43 $(SRC)/psps_ids.$(ARCH).o \ 46 44 $(SRC)/args.$(ARCH).o \ … … 93 91 $(SRC)/ConfigInit.$(ARCH).o \ 94 92 $(SRC)/GridOps.$(ARCH).o \ 93 $(SRC)/GridIO.$(ARCH).o \ 94 $(SRC)/ResetOps.$(ARCH).o \ 95 95 $(SRC)/ImageOps.$(ARCH).o \ 96 96 $(SRC)/ImageSubset.$(ARCH).o \ … … 102 102 $(SRC)/Shutdown.$(ARCH).o \ 103 103 $(SRC)/StarOps.$(ARCH).o \ 104 $(SRC)/WarpImageMaps.$(ARCH).o \105 $(SRC)/StackImageMaps.$(ARCH).o \106 $(SRC)/RepairWarpMeasures.$(ARCH).o \107 $(SRC)/myIndex.$(ARCH).o \108 104 $(SRC)/psps_ids.$(ARCH).o \ 109 105 $(SRC)/bcatalog.$(ARCH).o \ -
trunk/Ohana/src/relphot/include/relphot.h
r41557 r41647 5 5 # include <pthread.h> 6 6 7 /* # define GRID_V1 */8 # define GRID_V29 # define NO_IMAGE -10010 11 7 # define ID_SECF_STACK_PRIMARY 0x00004000 12 8 13 9 # define NBOOTSTRAP 100 10 11 // MEAS_BAD is used in ImageOps.c, MosaicOps.c, TGroupOps.c to skip specific measurements. 12 // ID_MEAS_AREA is raised for measurements outside the user-specified region of the chips 13 // ID_MEAS_NOCAL is raised for measurements outside the valid time range or for inactive photcodes 14 // Note: these bits are only raised on the temporary MeasureTiny elements and are not saved 15 // to the database files. 16 # define MEAS_BAD (ID_MEAS_AREA | ID_MEAS_NOCAL) 14 17 15 18 # ifndef MAX_INT … … 53 56 54 57 typedef enum { 55 MODE_NONE = 0,56 MODE_LOAD = 1,57 MODE_UPDATE = 2,58 MODE_NONE = 0, 59 MODE_LOAD = 1, 60 MODE_UPDATE = 2, 58 61 MODE_UPDATE_OBJECTS = 3, 59 MODE_SYNTH_PHOT = 4,62 MODE_SYNTH_PHOT = 4, 60 63 } ModeType; 61 64 … … 70 73 PS1_w = 6, 71 74 } PS1filters; 75 76 typedef enum { 77 GRID_MEAN = 0, 78 GRID_STDEV = 1, 79 GRID_NPTS = 2, 80 } GridOutputMode; 72 81 73 82 typedef struct { … … 99 108 char skipCal; // if TRUE, this mosaic is incomplete and should not be calibrated 100 109 char inTGroup; 101 Coords coords; 110 Coords coords; // this is only used to set the mosaic center for assign_images used by region hosts 102 111 } Mosaic; 103 112 … … 140 149 int nCode; 141 150 } TGTimes; 151 152 typedef struct { 153 unsigned short photcode; 154 float **Mgrid; // grid of average corrections 155 float **dMgrid; // grid of stdev of corrections 156 int **nMgrid; // grid of number of stars for corrections 157 int Nx; // bin = int(Xchip * (Nx / NxChip)) 158 int Ny; // bin = int(Ychip * (Ny / NyChip)) 159 float dX; // bin = int(Xchip * dX), dX = Nx / NxChip 160 float dY; // bin = int(Ychip * dY), dY = Ny / NyChip 161 // NxChip, NyChip = 4900,4900 for now 162 } GridCorrectionType; 142 163 143 164 typedef enum { … … 366 387 int SKY_DEPTH; /** XXX EAM : depth of catalog tables, fix usage */ 367 388 char *SYNTH_ZERO_POINTS; 389 char *GRID_MEANFILE; 368 390 369 391 // globals for parallel region operations … … 389 411 double IMAGE_OFFSET; 390 412 double NIGHT_SCATTER; 391 double NIGHT_OFFSET; 413 double NIGHT_CHISQ; 414 double MOSAIC_SCATTER; 415 double MOSAIC_CHISQ; 392 416 double STAR_SCATTER; 393 417 double STAR_CHISQ; … … 413 437 int MOSAIC_ZEROPT; 414 438 int TGROUP_ZEROPT; 439 int GRID_ZEROPT; 440 441 int GRID_BIN_HSC; 442 int GRID_BIN_CFH; 443 int GRID_BIN_GPC1; 444 int GRID_BIN_GPC2; 415 445 416 446 int FREEZE_IMAGES; … … 424 454 int MANUAL_ITERATION; 425 455 int NLOOP; 426 int NGRID;427 456 int RESET; 428 457 int RESET_ZEROPTS; 458 int RESET_FLATCORR; 429 459 int REPAIR_WARPS; 430 460 int PRESERVE_PS1; 461 int REQUIRE_PSFFIT; 431 462 int UPDATE; 432 463 int SAVE_IMAGE_UPDATES; … … 436 467 char MOSAICNAME[256]; 437 468 char STATMODE[32]; 438 int STAR_BAD;439 int MEAS_BAD;440 469 int STAR_TOOFEW; 441 470 int GRID_TOOFEW; 442 471 int IMAGE_TOOFEW; 443 472 double IMAGE_GOOD_FRACTION; 444 int IMAGE_BAD;445 473 int CALIBRATE_STACKS_AND_WARPS; 446 int USE_GRID; 474 447 475 int KEEP_UBERCAL; 448 476 char *OUTROOT; … … 457 485 char *PhotcodeList; 458 486 459 int RELPHOT_GRID_X;460 int RELPHOT_GRID_Y;461 int RELPHOT_GRID_BINNING;462 463 487 int *photseclist; 464 488 int Nphotcodes; … … 490 514 char *UserCatalog; 491 515 516 enum {GRID_ZPT_MODE_NONE, GRID_ZPT_MODE_ALL, }; 517 int GRID_ZPT_MODE; 518 492 519 enum {TGROUP_ZPT_MODE_NONE, TGROUP_ZPT_MODE_GOOD_NIGHT, TGROUP_ZPT_MODE_ALL, }; 493 520 int TGROUP_ZPT_MODE; … … 504 531 505 532 RelphotStages STAGES; 506 507 # ifdef GRID_V1508 int setGridMeasure (off_t meas, int cat, double X, double Y);509 # endif510 511 # ifdef GRID_V2512 int setGridMeasure (off_t meas, int cat, double X, double Y, int ccdnum);513 # endif514 533 515 534 /*** relphot prototypes ***/ … … 523 542 int bcatalog PROTO((Catalog *subcatalog, Catalog *catalog, int Ncat)); 524 543 void clean_images PROTO((void)); 525 void clean_measures PROTO((Catalog *catalog, int Ncatalog, int final , FlatCorrectionTable *flatcorr));544 void clean_measures PROTO((Catalog *catalog, int Ncatalog, int final)); 526 545 void clean_mosaics PROTO((void)); 527 546 void clean_tgroups PROTO((void)); … … 549 568 int SetSignals (void); 550 569 551 void freeGridBins PROTO(( int Ncatalog));570 void freeGridBins PROTO((void)); 552 571 void freeImageBins PROTO((int Ncatalog, int doImageList)); 553 572 void freeMosaicBins PROTO((int Ncatalog, int doMosaicList)); … … 560 579 561 580 float getMcal PROTO((off_t meas, int cat, dvoMagClassType class)); 562 float getMflat PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog)); 563 float getMgrid PROTO((off_t meas, int cat)); 581 float getMflat PROTO((off_t meas, int cat, Catalog *catalog)); 582 float getMgridTiny PROTO((MeasureTiny *measure)); 583 float getMgrid PROTO((Measure *measure)); 564 584 float getMmos PROTO((off_t meas, int cat)); 565 585 float getMgrp PROTO((off_t meas, int cat, float airmass, float *dZpt)); … … 570 590 Image *getimages PROTO((off_t *N, off_t **LineNumber)); 571 591 ImageSubset *getimages_subset PROTO((off_t *N)); 572 void global_stats PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr, int nloop)); 573 void initGrid PROTO((int dX, int dY)); 574 void initGridBins PROTO((Catalog *catalog, int Ncatalog)); 592 void global_stats PROTO((Catalog *catalog, int Ncatalog, int nloop)); 593 void initGrid PROTO((void)); 594 void setMflatFromGrid PROTO((Catalog *catalog)); 595 void initGridBins PROTO((void)); 596 GridCorrectionType *getGridCorrByCode PROTO((int code)); 597 GridCorrectionType *getGridCorrNext PROTO((int *Nlast)); 598 int GridCorrectionSave PROTO((void)); 599 int GridCorrectionSaveFile PROTO((char *filename, GridOutputMode mode)); 600 void GridCorrectionLoad PROTO((char *filename)); 575 601 void initImageBins PROTO((Catalog *catalog, int Ncatalog, int doImageList)); 576 602 void initImagesSubset PROTO((ImageSubset *input, off_t *line_number, off_t N)); 577 603 void initImages PROTO((Image *input, off_t *LineNumber, off_t N)); 578 604 void initMosaicBins PROTO((Catalog *catalog, int Ncatalog, int doMosaicList)); 579 void initMosaic GridPROTO((Image *image, off_t Nimage));605 void initMosaicMcal PROTO((Image *image, off_t Nimage)); 580 606 void initMosaics PROTO((Image *subset, off_t Nsubset, Image *image, char *inSubset, off_t Nimage)); 581 607 void initTGroups PROTO((Image *subset, off_t Nsubset)); … … 621 647 void plot_chisq PROTO((Catalog *catalog, int Ncatalog)); 622 648 void plot_defaults PROTO((Graphdata *graphdata)); 623 void plot_grid PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));624 649 void plot_images PROTO((void)); 625 650 void plot_list PROTO((Graphdata *graphdata, double *xlist, double *ylist, int N, char *label, char *format, ...) OHANA_FORMAT(printf, 6, 7) ); 626 651 void plot_mosaic_fields PROTO((Catalog *catalog)); 627 652 void plot_mosaics PROTO((void)); 628 void plot_scatter PROTO((Catalog *catalog, int Ncatalog , FlatCorrectionTable *flatcorr));653 void plot_scatter PROTO((Catalog *catalog, int Ncatalog)); 629 654 void plot_star_coords PROTO((Catalog *catalog, int Ncatalog)); 630 655 void plot_stars PROTO((Catalog *catalog, int Ncatalog)); … … 635 660 int open_graph PROTO((int N)); 636 661 637 void reload_catalogs PROTO((SkyList *skylist, FlatCorrectionTable *flatcorr,int hostID, char *hostpath));662 void reload_catalogs PROTO((SkyList *skylist, int hostID, char *hostpath)); 638 663 int reload_catalogs_parallel PROTO((SkyList *sky)); 639 664 int reload_images PROTO((FITS_DB *db)); 640 665 int setExclusions PROTO((Catalog *catalog, int Ncatalog, int verbose)); 641 void setMgrid PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr)); 666 void setMgrid PROTO((Catalog *catalog, int Ncatalog)); 667 void resetMgrid PROTO((void)); 668 642 669 void setMcalFromMosaics PROTO((void)); 643 670 void setMcalFromTGroups PROTO((void)); 644 int setMcalOutput PROTO((Catalog *catalog, int Ncatalog , FlatCorrectionTable *flatcorr));645 646 void setMcal PROTO((Catalog *catalog , FlatCorrectionTable *flatcorr));647 int setMmos PROTO((Catalog *catalog , FlatCorrectionTable *flatcorr));648 int setMgrp PROTO((Catalog *catalog , FlatCorrectionTable *flatcorr));649 650 int setMrel PROTO((Catalog *catalog, int Ncatalog , FlatCorrectionTable *flatcorr));651 void setMrelFinal PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr,int simpleAverage));652 int setMrelOutput PROTO((Catalog *catalog, int Ncatalog , FlatCorrectionTable *flatcorr));653 654 void setMcalTest PROTO((Catalog *catalog , FlatCorrectionTable *flatcorr));671 int setMcalOutput PROTO((Catalog *catalog, int Ncatalog)); 672 673 void setMcal PROTO((Catalog *catalog)); 674 int setMmos PROTO((Catalog *catalog)); 675 int setMgrp PROTO((Catalog *catalog)); 676 677 int setMrel PROTO((Catalog *catalog, int Ncatalog)); 678 void setMrelFinal PROTO((Catalog *catalog, int simpleAverage)); 679 int setMrelOutput PROTO((Catalog *catalog, int Ncatalog)); 680 681 void setMcalTest PROTO((Catalog *catalog)); 655 682 656 683 int setMave PROTO((Catalog *catalog, int Ncatalog)); 657 684 void set_ZP PROTO((double ZERO)); 658 685 int setrefcode PROTO((Image *image, off_t Nimage)); 659 void skip_measurements PROTO((Catalog *catalog, int pass , FlatCorrectionTable *flatcorr));686 void skip_measurements PROTO((Catalog *catalog, int pass)); 660 687 void sortA PROTO((double *X, int N)); 661 688 void sortB PROTO((double *X, double *Y, int N)); … … 663 690 void sortD PROTO((double *X, double *Y, double *Z, int N)); 664 691 StatType statsImageM PROTO((Catalog *catalog)); 665 StatType statsImageN PROTO((Catalog *catalog , FlatCorrectionTable *flatcorr));692 StatType statsImageN PROTO((Catalog *catalog)); 666 693 StatType statsImageX PROTO((Catalog *catalog)); 667 694 StatType statsImagedM PROTO((Catalog *catalog)); 668 695 StatType statsMosaicM PROTO((Catalog *catalog)); 669 StatType statsMosaicN PROTO((Catalog *catalog , FlatCorrectionTable *flatcorr));696 StatType statsMosaicN PROTO((Catalog *catalog)); 670 697 StatType statsMosaicX PROTO((Catalog *catalog)); 671 698 StatType statsMosaicdM PROTO((Catalog *catalog)); … … 674 701 StatType statsTGroupdM PROTO((Catalog *catalog)); 675 702 676 StatType statsStarN PROTO((Catalog *catalog, int Ncatalog, int Nsec, int seccode , FlatCorrectionTable *flatcorr));703 StatType statsStarN PROTO((Catalog *catalog, int Ncatalog, int Nsec, int seccode)); 677 704 StatType statsStarS PROTO((Catalog *catalog, int Ncatalog, int Nsec)); 678 705 StatType statsStarX PROTO((Catalog *catalog, int Ncatalog, int Nsec)); … … 720 747 721 748 int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure); 722 int setMrel_catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt); 723 int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results); 724 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr); 725 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results); 749 750 // in setMrelCatalog.c: 751 int setMrelCatalog (Catalog *catalog, int Nc, int isSetMrelFinal, SetMrelInfo *results, int Nsecfilt); 752 int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, SetMrelInfo *results); 753 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt); 754 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, SetMrelInfo *results); 726 755 727 756 int setGlobalObjStats (Average *average, Measure *measure); … … 735 764 StatDataSet *StatDataSetAlloc (int Nsecfilt, int Nmax); 736 765 737 int init_synthetic_mags ( );766 int init_synthetic_mags (void); 738 767 int add_synthetic_mags (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, off_t *Nmeasure, off_t *Nm); 739 768 … … 796 825 797 826 int SynthZeroPointsLoad (char *filename); 798 SynthZeroPoints *SynthZeroPointsGet ( );827 SynthZeroPoints *SynthZeroPointsGet (void); 799 828 800 829 int relphot_synthphot (SkyList *sky, int hostID, char *hostpath); … … 815 844 816 845 void put_astrom_table (AstromOffsetTable *myTable); 817 void free_astrom_table (); 818 819 int RepairWarpMeasures (Catalog *catalog); 820 821 int FindWarpGroups (void); 822 int GetWarpSeq (Image *image, int obstime, unsigned short photcode, double Rave, double Dave, float X, float Y); 823 void FreeWarpGroups (void); 824 825 myIndexType *myIndexInit (); 826 int myIndexFree (myIndexType *myIndex); 827 int myIndexUpdateLimits (myIndexType *myIndex, int value); 828 int myIndexSetRange (myIndexType *myIndex); 829 int myIndexSetEntry (myIndexType *myIndex, int value, int entry); 830 int myIndexGetEntry (myIndexType *myIndex, int value); 846 void free_astrom_table (void); 831 847 832 848 uint64_t CreatePSPSObjectID(double ra, double dec); … … 834 850 uint64_t CreatePSPSDetectionID(double tobs, int ccdid, int detID); 835 851 836 int MakeStackIndex (void);837 void FreeStackGroups (void);838 int GetStackSeq (Image *image, double Rstk, double Dstk, unsigned short photcode, float X, float Y);839 852 void sort_by_ra (double *R, double *D, int *I, int *S, int N); 840 841 void RepairWarpMeasuresOpenLogfile ();842 void RepairWarpMeasuresCloseLogfile ();843 853 844 854 void dump_tgroups (Catalog *catalog, int Npass); … … 849 859 int GetZptIteration (void); 850 860 851 void SetZeroPointModes ( void);861 void SetZeroPointModes (Catalog *catalog, int Ncatalog); 852 862 int UseStandardOLS (ZptFitModeType mode); 853 863 int GetActivePhotcodeIndex (int photcode); … … 857 867 858 868 int MagResidSave(char *filename, Catalog *catalog); 869 870 void ResetAverageAndMeasure (Catalog *catalog); 871 void ResetAverageObjects (Catalog *catalog); 872 void ResetImages (Image *subset, off_t Nsubset); 873 void ResetMeasureZeroPoints (MeasureTiny *measure, off_t Nmeasure, off_t Ncat); 874 void ResetAverageActivePhotcodes (SecFilt *secfilt); 875 876 -
trunk/Ohana/src/relphot/src/BrightCatalog.c
r40291 r41647 12 12 myAssert (!strcmp(type, #TYPE), "wrong column type"); 13 13 14 // XXX double check the header extname values for each table15 // XXX make sure we free things as we can16 // XXX make sure we close files as we can17 // XXX handle free and close on error return as well18 14 BrightCatalog *BrightCatalogLoad(char *filename) { 19 15 … … 622 618 int BrightCatalogSplitFree (CatalogSplitter *catalogs) { 623 619 624 // XXX don't free the catalogs : 625 // for (i = 0; i < NCATALOG; i++) { 626 // free (catalogs->catalog[i].averageT); 627 // free (catalogs->catalog[i].measureT); 628 // free (catalogs->catalog[i].secfilt); 629 // } 630 // free (catalogs->catalog); 631 620 // don't free the catalogs : free elsewhere 632 621 free (catalogs->catIDs); 633 622 free (catalogs->NAVERAGE); … … 652 641 catIDmax = MAX(catIDmax, bcatalog->average[i].catID); 653 642 } 654 // XXX validate the measure ID range here655 643 656 644 int maxIDold = catalogs->maxID; … … 746 734 747 735 // assign the measures to the corresponding catalog 748 // XXX what about averef and related links? Do I need them?749 736 for (i = 0; i < bcatalog->Nmeasure; i++) { 750 737 int ID = bcatalog->measure[i].catID; -
trunk/Ohana/src/relphot/src/ConfigInit.c
r41453 r41647 26 26 GetConfig (config, "SIGMA_LIM", "%lf", 0, &SIGMA_LIM); 27 27 28 DefConfig ("STAR_SCATTER", "%lf", 0.1, STAR_SCATTER); 29 DefConfig ("STAR_CHISQ", "%lf", 10.0, STAR_CHISQ); 28 30 29 GetConfig (config, "STAR_SCATTER", "%lf", 0, &STAR_SCATTER); 31 DefConfig ("NIGHT_SCATTER", "%lf", 0.1, NIGHT_SCATTER); 32 DefConfig ("NIGHT_CHISQ", "%lf", 10.0, NIGHT_CHISQ); 33 34 DefConfig ("MOSAIC_SCATTER", "%lf", 0.1, MOSAIC_SCATTER); 35 DefConfig ("MOSAIC_CHISQ", "%lf", 10.0, MOSAIC_CHISQ); 30 36 31 37 GetConfig (config, "IMAGE_SCATTER", "%lf", 0, &IMAGE_SCATTER); 32 38 GetConfig (config, "IMAGE_OFFSET", "%lf", 0, &IMAGE_OFFSET); 33 39 34 GetConfig (config, "STAR_CHISQ", "%lf", 0, &STAR_CHISQ);35 40 GetConfig (config, "GRID_TOOFEW", "%d", 0, &GRID_TOOFEW); 36 41 GetConfig (config, "STAR_TOOFEW", "%d", 0, &STAR_TOOFEW); … … 54 59 55 60 DefConfig ("RELPHOT_IMFIT_SYS_SIGMA_LIM", "%lf", 0.01, IMFIT_SYS_SIGMA_LIM); 56 DefConfig ("NIGHT_SCATTER", "%lf", 0.05, NIGHT_SCATTER);57 DefConfig ("NIGHT_OFFSET", "%lf", 0.50, NIGHT_OFFSET);58 61 DefConfig ("SKY_DEPTH", "%d", 2, SKY_DEPTH); 59 62 … … 63 66 64 67 GetConfig (config, "ZERO_PT", "%lf", 0, &ZERO_POINT); 65 66 GetConfig (config, "RELPHOT_GRID_X", "%d", 0, &RELPHOT_GRID_X);67 GetConfig (config, "RELPHOT_GRID_Y", "%d", 0, &RELPHOT_GRID_Y);68 GetConfig (config, "RELPHOT_GRID_BINNING", "%d", 0, &RELPHOT_GRID_BINNING);69 68 GetConfig (config, "CAMERA_CONFIG", "%s", 0, CameraConfig); 70 69 GetConfig (config, "MOSAICNAME", "%s", 0, MOSAICNAME); -
trunk/Ohana/src/relphot/src/GridOps.c
r41462 r41647 1 1 # include "relphot.h" 2 2 3 enum { 4 GRID_FITTED, 5 GRID_FROZEN, 6 GRID_REFERENCE, 7 }; 8 9 static int Ngrid; // number of grid elements (gridX * gridY) 10 static float *gridM; // magnitude offset for this grid cell 11 static float *gridS; // stdev of the magnitude offset for this grid cell 12 static int *gridN; // number of stars used to measure the magnitude offset for this grid cell 13 static int *gridV; // data mode for this cell: fitted, frozen, reference 14 static int gridX; // number of grid elements in X direction 15 static int gridY; // number of grid elements in Y direction 16 17 static int **bin; // link from catalog, measure to grid element 18 static int **Xmeas; // grid x-coordinate for a measurement 19 static int **Ymeas; // grid y-coordinate for a measurement 20 21 static int **clist; // link from measurement on a cell to catalog containing measurement 22 static off_t **mlist; // link from measurement on a cell to measurement in a catalog 23 static off_t *Nlist; // number of measurements for each grid cell 24 static off_t *NLIST; // allocated number of measurements for each grid cell 25 26 static struct { 27 int Nchip; 28 int Mx, My; /* mosaic size in chips */ 29 int Nx, Ny; /* chip size in pixels */ 30 int *Fx, *Fy; /* chip flip */ 31 int *Ox, *Oy; /* chip offset */ 32 int *valid; 33 char **ccdname; 34 } camera; 35 36 static int *ccdnum; 37 static char *config; 38 39 void initGrid (int dX, int dY) { 40 OHANA_UNUSED_PARAM(dX); 41 OHANA_UNUSED_PARAM(dY); 42 43 int i, N, ccdnum_max, refX, refY, refBin; 44 char *p, field[64], line[256]; 45 int *Fx, *Fy; /* chip flip */ 46 int *Ox, *Oy; /* chip offset */ 47 char **ccdname; 48 49 /* load camera config file */ 50 config = LoadConfigFile (CameraConfig); 51 if (config == (char *) NULL) { 52 fprintf (stderr, "ERROR: can't find camera config file %s\n", CameraConfig); 53 exit (1); 54 } 55 56 /* load basic mosaic parameters */ 57 ScanConfig (config, "NCCD", "%d", 1, &camera.Nchip); 58 ScanConfig (config, "MOSAIC_X", "%d", 1, &camera.Mx); 59 ScanConfig (config, "MOSAIC_Y", "%d", 1, &camera.My); 60 ScanConfig (config, "NAXIS1", "%d", 1, &camera.Nx); 61 ScanConfig (config, "NAXIS2", "%d", 1, &camera.Ny); 62 63 ScanConfig (config, "REFCELL.X", "%d", 1, &refX); 64 ScanConfig (config, "REFCELL.Y", "%d", 1, &refY); 65 66 // temporary storage 67 ALLOCATE (Fx, int, camera.Nchip); 68 ALLOCATE (Fy, int, camera.Nchip); 69 ALLOCATE (Ox, int, camera.Nchip); 70 ALLOCATE (Oy, int, camera.Nchip); 71 ALLOCATE (ccdname, char *, camera.Nchip); 72 ALLOCATE (ccdnum, int, camera.Nchip); 73 74 /* load per-chip parameters */ 75 for (i = 0; i < camera.Nchip; i++) { 76 ALLOCATE (ccdname[i], char, 256); 77 sprintf (field, "CCD.%d", i); 78 ScanConfig (config, field, "%s", 1, line); 79 // XXX get error status! 80 81 sscanf (line, "%s %d %d %d %d", ccdname[i], &Ox[i], &Oy[i], &Fx[i], &Fy[i]); 3 /* 4 We define a 'grid correction', essentially the flat-field correction, as a correction per 5 photcode subdivided into an NxN array. The dimensions of the chips corresponding to a 6 photcode will need to be added to the photcode table. This means a schema update, 7 which I detest. For now (2021.05.16), I will hard-wire the GPC1 / GPC2 chip size and 8 worry about HSC & Megacam in the future. 9 10 We have a collection of photcodes, with photcodeID limited by design to 64k (unsigned short). 11 12 Thus we can generate an array of pointers to the grid correction structures and access them 13 by photcode. 14 15 16 */ 17 18 static GridCorrectionType **GridCorr = NULL; 19 static int NGridCorr = 0; 20 21 # if (0) 22 /* PS1 / PS2 values */ 23 # define NX_CHIP 4900 24 # define NY_CHIP 4900 25 # define NX_BIN 16 26 # define NY_BIN 16 27 # endif 28 29 /* test values */ 30 # define NX_CHIP_DEFAULT 1000 31 # define NY_CHIP_DEFAULT 1000 32 # define NX_BIN_DEFAULT 2 33 # define NY_BIN_DEFAULT 2 34 35 void initGridBins (void) { 36 37 // allocate the full possible range of GridCorrectionType pointers, Nphotcode 38 // loop over all images to find actual existing photcodes 39 // generate initial grid values for each existing photcode 40 41 if (!GRID_ZEROPT) return; // skip if we are ignoring the grid correction 42 43 if (GridCorr) return; 44 45 PhotCodeData *photcodes = GetPhotcodeTable(); 46 if (!photcodes) return; 47 48 // we have photcodes->Ncodes actually loaded. loop over them and allocate 49 // array only as large as the max photcodes->code[i].code 50 51 int maxCode = 0; 52 for (int i = 0; i < photcodes->Ncode; i++) { 53 maxCode = MAX(maxCode, photcodes->code[i].code); 54 myAssert (maxCode < 0x10000, "oops"); 55 } 56 57 NGridCorr = maxCode + 1; 58 ALLOCATE (GridCorr, GridCorrectionType *, NGridCorr); 59 for (int i = 0; i < NGridCorr; i++) { 60 GridCorr[i] = NULL; 61 } 62 63 fprintf (stderr, "Generating grid corrections for %d photcodes\n", NGridCorr); 64 return; 65 } 66 67 void freeGridBins() { 68 69 if (!GridCorr) return; 70 71 for (int code = 0; code < NGridCorr; code++) { 72 if (!GridCorr[code]) continue; 73 74 for (int ix = 0; ix < GridCorr[code]->Nx; ix++) { 75 FREE (GridCorr[code]-> Mgrid[ix]); 76 if (GridCorr[code]->dMgrid) FREE (GridCorr[code]->dMgrid[ix]); 77 if (GridCorr[code]->nMgrid) FREE (GridCorr[code]->nMgrid[ix]); 78 } 79 80 FREE (GridCorr[code]-> Mgrid); 81 FREE (GridCorr[code]->dMgrid); 82 FREE (GridCorr[code]->nMgrid); 83 84 FREE(GridCorr[code]); 85 } 86 87 FREE (GridCorr); 88 GridCorr = NULL; 89 90 return; 91 } 92 93 GridCorrectionType *getGridCorrNext (int *Nlast) { 94 95 if (GridCorr == NULL) return NULL; 96 97 if (*Nlast >= NGridCorr) return NULL; 98 99 if (*Nlast < 0) *Nlast = -1; 100 101 GridCorrectionType *result = NULL; 102 for (int i = *Nlast + 1; i < NGridCorr; i++) { 103 if (GridCorr[i] == NULL) continue; 104 result = GridCorr[i]; 105 *Nlast = i; 106 break; 107 } 108 return result; 109 } 110 111 GridCorrectionType *getGridCorrByCode (int code) { 112 113 if (GridCorr == NULL) return NULL; 114 115 if (code >= NGridCorr) return NULL; 116 if (code < 0) return NULL; 117 118 ALLOCATE(GridCorr[code], GridCorrectionType, 1) 119 GridCorrectionType *result = GridCorr[code]; 120 return result; 121 } 122 123 /* for GPC1, we have 60 chips, 5 filters, 16x16 grid cells = 2MB of memory for this stuff 124 if we go to 64x64 grid cells (~75 pixels), then it is still only 29MB */ 125 void initGrid (void) { 126 127 if (!GRID_ZEROPT) return; 128 129 off_t Nimages = 0; 130 Image *images = getimages (&Nimages, NULL); 131 132 int NGridReal = 0; 133 134 for (int i = 0; i < Nimages; i++) { 135 int code = images[i].photcode; 136 myAssert (code >= 0, "oops"); 137 myAssert (code < NGridCorr, "oops"); 82 138 83 p = ccdname[i]; 84 while (!isdigit(*p) && *p) p++; 85 if (*p == 0) continue; 86 ccdnum[i] = atoi (p); 87 } 88 89 /* we now have the parameters loaded into a minimal length list; reshuffle to the a list of length 0 - MAX(ccdnum) */ 90 ccdnum_max = 0; 91 for (i = 0; i < camera.Nchip; i++) { 92 ccdnum_max = MAX(ccdnum_max, ccdnum[i]); 93 } 94 ccdnum_max ++; 95 96 if (ccdnum_max < camera.Nchip) { 97 fprintf (stderr, "problem with camera config: duplicate ccd IDs\n"); 98 exit (1); 99 } 100 101 if (ccdnum_max > 0x1000) { 102 fprintf (stderr, "problem with camera config: absurd max ccd ID number %d\n", ccdnum_max); 103 exit (1); 104 } 105 106 ALLOCATE (camera.Fx, int, ccdnum_max); 107 ALLOCATE (camera.Fy, int, ccdnum_max); 108 ALLOCATE (camera.Ox, int, ccdnum_max); 109 ALLOCATE (camera.Oy, int, ccdnum_max); 110 ALLOCATE (camera.valid, int, ccdnum_max); 111 ALLOCATE (camera.ccdname, char *, ccdnum_max); 112 113 for (i = 0; i < ccdnum_max; i++) { 114 camera.valid[i] = FALSE; 115 } 116 117 for (i = 0; i < camera.Nchip; i++) { 118 N = ccdnum[i]; 119 camera.Fx[N] = Fx[i]; 120 camera.Fy[N] = Fy[i]; 121 camera.Ox[N] = Ox[i]; 122 camera.Oy[N] = Oy[i]; 123 camera.ccdname[N] = ccdname[i]; 124 camera.valid[N] = TRUE; 125 } 126 127 /* define mosaic 2d correction grid: 128 * GRID_X is the number of grid pixels per chip in the X direction */ 129 gridX = RELPHOT_GRID_X * camera.Mx; 130 gridY = RELPHOT_GRID_Y * camera.My; 131 Ngrid = gridX * gridY; 132 133 ALLOCATE (gridM, float, Ngrid); 134 ALLOCATE (gridS, float, Ngrid); 135 ALLOCATE (gridN, int, Ngrid); 136 ALLOCATE (gridV, int, Ngrid); 137 138 // the grid bins may have one of three possible states: fitted, frozen, reference 139 // set the initial values to indicate that the bins are frozen 140 for (i = 0; i < Ngrid; i++) { 141 gridM[i] = 0.0; 142 gridS[i] = 0.0; 143 gridN[i] = 0; 144 gridV[i] = GRID_FROZEN; 145 } 146 147 // refBin is the index of the grid cell which is kept at 0.0 (all others are relative to this) 148 refBin = refX + refY*gridX; 149 gridV[refBin] = GRID_REFERENCE; 150 } 151 152 void initGridBins (Catalog *catalog, int Ncatalog) { 153 154 int i, j; 155 156 if (!USE_GRID) return; 157 158 /* define cat,meas -> grid pointers */ 159 ALLOCATE (bin, int *, Ncatalog); 160 ALLOCATE (Xmeas, int *, Ncatalog); 161 ALLOCATE (Ymeas, int *, Ncatalog); 162 for (i = 0; i < Ncatalog; i++) { 163 ALLOCATE (bin[i], int, MAX (catalog[i].Nmeasure, 1)); 164 ALLOCATE (Xmeas[i], int, MAX (catalog[i].Nmeasure, 1)); 165 ALLOCATE (Ymeas[i], int, MAX (catalog[i].Nmeasure, 1)); 166 for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1; 167 } 168 169 /* define grid -> cat,meas pointers */ 170 ALLOCATE (Nlist, off_t, Ngrid); 171 ALLOCATE (NLIST, off_t, Ngrid); 172 ALLOCATE (clist, int *, Ngrid); 173 ALLOCATE (mlist, off_t *, Ngrid); 174 175 for (i = 0; i < Ngrid; i++) { 176 Nlist[i] = 0; 177 NLIST[i] = 100; 178 ALLOCATE (clist[i], int, NLIST[i]); 179 ALLOCATE (mlist[i], off_t, NLIST[i]); 180 } 181 } 182 183 void freeGridBins (int Ncatalog) { 184 185 int i; 186 187 if (!USE_GRID) return; 188 189 /* define cat,meas -> grid pointers */ 190 for (i = 0; i < Ncatalog; i++) { 191 free (bin[i]); 192 free (Xmeas[i]); 193 free (Ymeas[i]); 194 } 195 free (bin); 196 free (Xmeas); 197 free (Ymeas); 198 199 /* define grid -> cat,meas pointers */ 200 for (i = 0; i < Ngrid; i++) { 201 free (clist[i]); 202 free (mlist[i]); 203 } 204 free (Nlist); 205 free (NLIST); 206 free (clist); 207 free (mlist); 208 } 209 210 int setGridMeasure (off_t meas, int cat, double X, double Y, int ccdnum) { 211 212 int ix, iy, Cx, Cy, i; 213 double x, y; 214 215 /* X, Y are chip coords on chip ccdnum */ 216 217 /* normalize X & Y */ 218 x = X; 219 if (camera.Fx[ccdnum]) x = camera.Nx - X; 220 y = Y; 221 if (camera.Fy[ccdnum]) y = camera.Ny - Y; 222 223 /* grid coords on the chip */ 224 Cx = MIN (MAX ((x / camera.Nx) * RELPHOT_GRID_X, 0), RELPHOT_GRID_X - 1); 225 Cy = MIN (MAX ((y / camera.Ny) * RELPHOT_GRID_Y, 0), RELPHOT_GRID_Y - 1); 226 227 /* coordinates in the grid */ 228 ix = Cx + camera.Ox[ccdnum]*RELPHOT_GRID_X; 229 iy = Cy + camera.Oy[ccdnum]*RELPHOT_GRID_Y; 230 231 i = ix + iy*gridX; 232 233 bin[cat][meas] = i; 234 Xmeas[cat][meas] = x + camera.Ox[ccdnum]*camera.Nx; 235 Ymeas[cat][meas] = y + camera.Oy[ccdnum]*camera.Ny; 236 clist[i][Nlist[i]] = cat; 237 mlist[i][Nlist[i]] = meas; 238 239 // for the moment, add up the total grid count 240 gridN[i]++; 241 242 Nlist[i] ++; 243 if (Nlist[i] == NLIST[i]) { 244 NLIST[i] += 100; 245 REALLOCATE (clist[i], int, NLIST[i]); 246 REALLOCATE (mlist[i], off_t, NLIST[i]); 247 } 248 return (TRUE); 249 250 fprintf (stderr, "error: star out of grid\n"); 251 exit (1); 252 } 253 254 int showGridCount() { 255 256 int ix, iy, i; 257 258 for (iy = 0; iy < gridY; iy++) { 259 for (ix = 0; ix < gridX; ix++) { 260 i = ix + iy*gridX; 261 fprintf (stderr, "%3d ", gridN[i]); 262 } 263 fprintf (stderr, "\n"); 139 // valid photcodes values (code) are in range 1 <= code < 0x10000 140 // photcode == 0 are e.g., PHU (mosaic) images, and should be ignored here 141 if (!code) continue; 142 143 int NX_CHIP = NX_CHIP_DEFAULT; 144 int NY_CHIP = NY_CHIP_DEFAULT; 145 int NX_BIN = NX_BIN_DEFAULT; 146 int NY_BIN = NY_BIN_DEFAULT; 147 if (isGPC1chip(code)) { NX_CHIP = 4900; NY_CHIP = 4900; NX_BIN = NY_BIN = GRID_BIN_GPC1; } 148 if (isGPC2chip(code)) { NX_CHIP = 4900; NY_CHIP = 4900; NX_BIN = NY_BIN = GRID_BIN_GPC2; } 149 if (isHSCchip(code)) { NX_CHIP = 2100; NY_CHIP = 4200; NX_BIN = NY_BIN = GRID_BIN_HSC; } 150 if (isCFHchip(code)) { NX_CHIP = 2100; NY_CHIP = 4200; NX_BIN = NY_BIN = GRID_BIN_CFH; } 151 152 if (GridCorr[code]) continue; // already created this one 153 154 NGridReal ++; 155 156 ALLOCATE(GridCorr[code], GridCorrectionType, 1); 157 GridCorr[code]->photcode = code; 158 GridCorr[code]->Nx = NX_BIN; 159 GridCorr[code]->Ny = NY_BIN; 160 GridCorr[code]->dX = NX_BIN / (float) NX_CHIP; 161 GridCorr[code]->dY = NY_BIN / (float) NY_CHIP; 162 163 // we are normally accessing this array randomly, so there is no advantage to 164 // doing Mgrid[y][x] vs Mgrid[x][y] 165 ALLOCATE (GridCorr[code]-> Mgrid, float *, NX_BIN); 166 ALLOCATE (GridCorr[code]->dMgrid, float *, NX_BIN); 167 ALLOCATE (GridCorr[code]->nMgrid, int *, NX_BIN); 168 for (int ix = 0; ix < NX_BIN; ix++) { 169 ALLOCATE (GridCorr[code]-> Mgrid[ix], float, NY_BIN); 170 ALLOCATE (GridCorr[code]->dMgrid[ix], float, NY_BIN); 171 ALLOCATE (GridCorr[code]->nMgrid[ix], int, NY_BIN); 172 } 173 } 174 resetMgrid(); // start with values of 0 175 fprintf (stderr, "Init grid corrections for %d photcodes\n", NGridReal); 176 } 177 178 // reset the values in the arrays to 0 179 void resetMgrid () { 180 181 if (!GRID_ZEROPT) return; 182 if (!GridCorr) return; 183 184 for (int code = 0; code < NGridCorr; code++) { 185 if (!GridCorr[code]) continue; 186 187 for (int ix = 0; ix < GridCorr[code]->Nx; ix++) { 188 for (int iy = 0; iy < GridCorr[code]->Ny; iy++) { 189 GridCorr[code]-> Mgrid[ix][iy] = 0.0; 190 GridCorr[code]->dMgrid[ix][iy] = 0.0; 191 GridCorr[code]->nMgrid[ix][iy] = 0; 192 } 193 } 194 } 195 } 196 197 void setMgrid (Catalog *catalog, int Ncatalog) { 198 199 // check if we are actually doing this step 200 if (!GRID_ZEROPT) return; 201 if (GRID_ZPT_MODE == GRID_ZPT_MODE_NONE) return; 202 203 resetMgrid(); // start with values of 0 204 205 // loop over all measurements, accumulate Sum (in Mgrid), Sum2 (in dMgrid), and Npts 206 207 int Nsecfilt = GetPhotcodeNsecfilt (); 208 209 for (int nc = 0; nc < Ncatalog; nc++) { 210 for (int na = 0; na < catalog[nc].Naverage; na++) { 211 212 int nm = catalog[nc].averageT[na].measureOffset; 213 for (int k = 0; k < catalog[nc].averageT[na].Nmeasure; k++, nm++) { 214 215 // skip measurements marked by AREA or TIME 216 if (catalog[nc].measureT[nm].dbFlags & MEAS_BAD) continue; 217 218 float Mcal = getMcal (nm, nc, MAG_CLASS_PSF); 219 if (isnan(Mcal)) continue; 220 221 float Mgrp = getMgrp (nm, nc, catalog[nc].measureT[nm].airmass, NULL); 222 if (isnan(Mgrp)) continue; 223 224 float Mmos = getMmos (nm, nc); 225 if (isnan(Mmos)) continue; 226 227 float Mflat = getMflat (nm, nc, catalog); 228 if (isnan(Mflat)) continue; 229 230 // Mrel* is the average magnitude for this star. For PS1 stacks, we have too much 231 // PSF variability. We need to calibrate the PSF magnitudes separately from the 232 // Aperture-like magnitues. (We have an option to use the kron magnitudes or the 233 // other apertures here). I basically need to do this analysis separately for each 234 // magnitude type 235 236 float MrelPSF = getMrel (catalog, nm, nc, MAG_CLASS_PSF, MAG_SRC_CHP); 237 if (isnan(MrelPSF)) continue; 238 239 float MsysPSF = PhotSysTiny (&catalog[nc].measureT[nm], &catalog[nc].averageT[na], &catalog[nc].secfilt[na*Nsecfilt], MAG_CLASS_PSF); 240 if (isnan(MsysPSF)) continue; 241 242 float Moff = Mcal + Mgrp + Mmos + Mflat; 243 244 // Msys = Mrel + Moff + Mgrid 245 // thus Mgrid = Msys - Mrel - Moff 246 247 int code = catalog[nc].measureT[nm].photcode; 248 if (code <= 0) continue; 249 if (code >= NGridCorr) continue; // does not match one of our image, skip 250 251 GridCorrectionType *grid = GridCorr[code]; 252 if (!grid) continue; // does not match one of our images, skip 253 254 // edge effects could cause some positions to be slightly out of range 255 // probably should trap extreme outliers 256 int ix = MIN(MAX(0, (int)(catalog[nc].measureT[nm].Xccd * grid->dX)), grid->Nx - 1); 257 int iy = MIN(MAX(0, (int)(catalog[nc].measureT[nm].Yccd * grid->dY)), grid->Ny - 1); 258 259 float dM = MsysPSF - MrelPSF - Moff; 260 261 // XXX by the time we get here, we should have already mostly fixed up the zero 262 // points. reject measurements which are way off 263 if (fabs(dM) > 0.5) continue; 264 265 grid-> Mgrid[ix][iy] += dM; 266 grid->dMgrid[ix][iy] += dM*dM; 267 grid->nMgrid[ix][iy] ++; 268 } 264 269 } 265 return (TRUE); 266 } 267 268 float getMgrid (off_t meas, int cat) { 269 270 int i; 271 float value; 272 273 if (!USE_GRID) return (0); 274 i = bin[cat][meas]; 275 if (i == -1) return (NAN); 276 277 // during the grid annealing process, we skip over grid cells until they have enough 278 // valid stars to be fitted 279 if (gridV[i] == GRID_FROZEN) { 280 return (NAN); 281 } 282 283 value = gridM[i]; 284 return (value); 285 } 286 287 /* direct (non-iterative) solution for Mgrid values for all grid bins */ 288 void setMgridDirect (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr) { 289 290 int **gotstar, **gridmeas; 291 int i, j, k, Ngood, Nbad, Nmos, Ncal, Nrel, Nsys, Ngrp; 292 double **A, **B, *Mjx, *Wjx; 293 float Msys, Mcal, Mmos, Mgrp, Merr, Wsys; 294 double Mj, Wj; 295 296 if (!USE_GRID) return; 297 298 ALLOCATE (A, double *, Ngrid); 299 ALLOCATE (B, double *, Ngrid); 300 for (i = 0; i < Ngrid; i++) { 301 ALLOCATE (A[i], double, Ngrid); 302 ALLOCATE (B[i], double, 1); 303 memset (A[i], 0, Ngrid*sizeof(double)); 304 memset (B[i], 0, sizeof(double)); 305 } 306 307 Ngood = Nbad = Ncal = Nmos = Nrel = Nsys = Ngrp = 0; 308 309 ALLOCATE (gotstar, int *, Ncatalog); 310 for (i = 0; i < Ncatalog; i++) { 311 ALLOCATE (gotstar[i], int, catalog[i].Naverage); 312 } 313 314 // set up gridmeas table : grid index for each measurement 315 ALLOCATE (gridmeas, int *, Ncatalog); 316 for (i = 0; i < Ncatalog; i++) { 317 ALLOCATE (gridmeas[i], int, catalog[i].Nmeasure); 318 for (j = 0; j < catalog[i].Nmeasure; j++) { 319 gridmeas[i][j] = -1; 320 } 321 } 322 for (i = 0; i < Ngrid; i++) { 323 for (j = 0; j < Nlist[i]; j++) { 324 int m, c; 325 m = mlist[i][j]; 326 c = clist[i][j]; 327 gridmeas[c][m] = i; 328 } 329 } 330 331 // as we loop over the grid cells, we need to accumulate the values of Wjx for each star 332 ALLOCATE (Wjx, double, Ngrid); 333 ALLOCATE (Mjx, double, Ngrid); 334 335 // accumulate the elements of the matrix equation. We have an equation of the form: Ax = B 336 // where x is the vector of grid cell values G_x (x = 0 - Ngrid), A is an Ngrid x Ngrid matrix, 337 // and B is an Ngrid vector. For a cell A(x,y), we need the following elements from each 338 // star which touches grid cell (x): 339 // 340 // Mj : sum over all measurements of Msys / dMsys^2 341 // Wj : sum over all measurements of 1.0 / dMsys^2 342 // Mjx : sum over all measurements which touch cell (x) of Msys / dMsys^2 343 // Wjx : sum over all measurements which touch cell (x) of 1.0 / dMsys^2 344 345 // Mjx and Wjx can be calculated by summing over all measurements which touch the cell 346 // Mj requires looping over stars which touch (x) 347 348 // this is tricky because we need to know both the measurements which touch a cell 349 // and the stars for which any measurement touches a cell. we need to accumulate 350 // sums for each star which touches as cell on both bases. 351 352 int Nsecfilt = GetPhotcodeNsecfilt (); 353 int thisCode = photcodes[0][0].code; 354 int Nsec = GetPhotcodeNsec(thisCode); 355 356 for (i = 0; i < Ngrid; i++) { 357 358 for (j = 0; j < Ncatalog; j++) { 359 memset (gotstar[j], 0, catalog[j].Naverage*sizeof(int)); 360 } 361 362 // we are looping over the stars, but doing so by looping over the set of measurements: 363 // every star which touches this grid cell has a measurement in Nlist[i] 364 for (j = 0; j < Nlist[i]; j++) { 365 366 int mx, c, n, m0, Npts; 367 368 mx = mlist[i][j]; 369 c = clist[i][j]; 370 n = catalog[c].measureT[mx].averef; 371 372 // if we have already visited this star, skip the stuff below 373 if (gotstar[c][n]) continue; 374 gotstar[c][n] = TRUE; 375 376 // skip stars marked as BAD 377 if (catalog[c].secfilt[n*Nsecfilt+Nsec].flags & STAR_BAD) { 378 Nrel ++; 379 continue; 380 } 381 382 m0 = catalog[c].average[n].measureOffset; 383 384 // we accumuate an entry for each cell 385 memset (Wjx, 0, Ngrid*sizeof(double)); 386 memset (Mjx, 0, Ngrid*sizeof(double)); 387 Npts = Mj = Wj = 0.0; 388 389 // if we have not yet visited this star, accumulate the Mj, Wj entries 390 for (k = 0; k < catalog[c].average[n].Nmeasure; k++) { 391 392 int m, Ng; 393 394 m = m0 + k; 395 396 // skip measurements marked as BAD 397 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 398 Nbad ++; 270 } 271 272 // now calculate Mgrid, dMgrid, nMgrid from Sum, Sum, Npt 273 for (int code = 0; code < NGridCorr; code++) { 274 if (!GridCorr[code]) continue; 275 276 for (int ix = 0; ix < GridCorr[code]->Nx; ix++) { 277 for (int iy = 0; iy < GridCorr[code]->Ny; iy++) { 278 279 // cells without sufficient coverage stay at 0.0 280 if (GridCorr[code]->nMgrid[ix][iy] < 5) { 281 GridCorr[code]-> Mgrid[ix][iy] = 0.0; 282 GridCorr[code]->dMgrid[ix][iy] = 0.0; 399 283 continue; 400 284 } 401 285 402 // skip images marked as BAD 403 Mcal = getMcal (m, c, MAG_CLASS_PSF); 404 if (isnan(Mcal)) { 405 Ncal ++; 406 continue; 407 } 408 409 // skip mosaics marked as BAD 410 Mmos = getMmos (m, c); 411 if (isnan(Mmos)) { 412 Nmos ++; 413 continue; 414 } 415 416 // skip mosaics marked as BAD 417 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 418 if (isnan(Mgrp)) { 419 Ngrp ++; 420 continue; 421 } 422 423 // select the color- and airmass-corrected observed magnitude for this star 424 // XXX need to be able to turn off the color-correction until initial average mags are found 425 Msys = PhotCatTiny (&catalog[c].measureT[m], MAG_CLASS_PSF); 426 if (isnan(Msys)) { 427 Nsys++; 428 continue; 429 } 430 431 // mag-error for this measurement 432 Merr = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 433 434 // disable Wsys for now 435 Wsys = TRUE ? 1.0 : 1.0 / SQ(Merr); 436 437 Ng = gridmeas[c][m]; 438 if (Ng == -1) continue; // skip measurements which do not touch any cell 439 440 Mj += Msys * Wsys; // we are only including measurements touching this cell 441 Wj += Wsys; // we are only including measurements touching this cell 442 Npts ++; 443 Ngood ++; 444 445 Mjx[Ng] += Msys * Wsys; // we are only including measurements touching cell (x) 446 Wjx[Ng] += Wsys; // we are only including measurements touching cell (x) 447 } 448 449 // some stars will not have any valid measurements, skip these 450 if (Npts == 0) continue; 451 452 B[i][0] += Mj*Wjx[i]/Wj - Mjx[i]; 453 A[i][i] -= Wjx[i]; 454 for (k = 0; k < Ngrid; k++) { 455 A[i][k] += Wjx[i]*Wjx[k]/Wj; 456 // fprintf (stderr, "%3.0f ", Wjx[k]); 286 float Mgrid = GridCorr[code]-> Mgrid[ix][iy] / GridCorr[code]->nMgrid[ix][iy]; // average Mgrid 287 float Mgrid2 = GridCorr[code]-> dMgrid[ix][iy] / GridCorr[code]->nMgrid[ix][iy]; // average Mgrid^2 288 289 float r = GridCorr[code]->nMgrid[ix][iy] / (float) (GridCorr[code]->nMgrid[ix][iy] - 1.0); // pop -> sample stdev 290 291 GridCorr[code]-> Mgrid[ix][iy] = Mgrid; 292 GridCorr[code]->dMgrid[ix][iy] = sqrt(r*(Mgrid2 - Mgrid*Mgrid)); // sample stdev 293 // fprintf (stderr, "grid code %d, %d x %d : %f +/- %f : %d\n", code, ix, iy, GridCorr[code]-> Mgrid[ix][iy], GridCorr[code]->dMgrid[ix][iy], GridCorr[code]->nMgrid[ix][iy]); 457 294 } 458 295 } 459 296 } 460 461 if (1) { 462 463 FILE *f; 464 Header theader; 465 Matrix matrix; 466 467 /* we are writing to this file */ 468 f = fopen ("matrix.fits", "w"); 469 if (f == (FILE *) NULL) { 470 fprintf (stderr, "cannot open matrix.fits for output\n"); 471 return; 472 } 473 474 /* save grid mag values */ 475 gfits_init_header (&theader); 476 theader.Naxes = 2; 477 theader.Naxis[0] = Ngrid; 478 theader.Naxis[1] = Ngrid; 479 theader.bitpix = -32; 480 gfits_create_Theader (&theader, "IMAGE"); 481 gfits_modify (&theader, "EXTNAME", "%s", 1, "MATRIX"); 482 gfits_create_matrix (&theader, &matrix); 483 for (i = 0; i < Ngrid; i++) { 484 for (j = 0; j < Ngrid; j++) { 485 gfits_set_matrix_value (&matrix, i, j, (double) A[i][j]); 486 } 487 } 488 gfits_fwrite_header (f, &theader); 489 gfits_fwrite_matrix (f, &matrix); 490 gfits_free_matrix (&matrix); 491 492 gfits_modify (&theader, "EXTNAME", "%s", 1, "TRPOSE"); 493 gfits_create_matrix (&theader, &matrix); 494 for (i = 0; i < Ngrid; i++) { 495 for (j = 0; j < Ngrid; j++) { 496 gfits_set_matrix_value (&matrix, i, j, (double) A[j][i]); 497 } 498 } 499 gfits_fwrite_header (f, &theader); 500 gfits_fwrite_matrix (f, &matrix); 501 gfits_free_matrix (&matrix); 502 fclose (f); 503 } 504 505 dgaussjordan (A, B, Ngrid, 1); 506 507 fprintf (stderr, "grid cells fitted (Ngood: %d, Nbad: %d, Nmos: %d, Ncal: %d, Nrel: %d, Nsys: %d)\n", Ngood, Nbad, Nmos, Ncal, Nrel, Nsys); 508 509 for (i = 0; i < Ngrid; i++) { 510 gridM[i] = B[i][0]; 511 gridS[i] = sqrt(A[i][i]); 512 gridN[i] = Ngood; 513 } 514 515 free (Wjx); 516 free (Mjx); 517 518 for (i = 0; i < Ngrid; i++) { 519 free (A[i]); 520 } 521 free (A); 522 free (B); 523 524 for (i = 0; i < Ncatalog; i++) { 525 free (gotstar[i]); 526 free (gridmeas[i]); 527 } 528 free (gotstar); 529 free (gridmeas); 530 } 531 532 /* determine Mgrid values for all grid bins */ 533 void setMgrid (Catalog *catalog, FlatCorrectionTable *flatcorr) { 534 535 int i, j, m, c, n, N, Nmax, Nbad, Nmos, Ngrp, Ncal, Nrel, Nsys, Nfit; 536 double *list, *dlist; 537 float Msys, Mrel, Mcal, Mmos, Mgrp; 538 539 StatType stats; 540 liststats_setmode (&stats, "INNER_WTMEAN"); 297 return; 298 } 299 300 float getMgrid (Measure *measure) { 301 302 if (!GRID_ZEROPT) return 0.0; 303 if (GRID_ZPT_MODE == GRID_ZPT_MODE_NONE) return 0.0; 304 305 int code = measure->photcode; 306 if (code <= 0) return 0.0; 307 if (code >= NGridCorr) return 0.0; // does not match one of our image, skip 308 309 GridCorrectionType *grid = GridCorr[code]; 310 if (!grid) return 0.0; // does not match one of our images, skip 541 311 542 if (!USE_GRID) return; 543 544 int Nsecfilt = GetPhotcodeNsecfilt (); 545 546 Nmax = Nlist[0]; 547 for (i = 0; i < Ngrid; i++) { 548 Nmax = MAX (Nmax, Nlist[i]); 549 } 550 ALLOCATE (list, double, Nmax); 551 ALLOCATE (dlist, double, Nmax); 552 553 Nbad = Ncal = Nmos = Ngrp = Nrel = Nsys = Nfit = 0; 554 555 for (i = 0; i < Ngrid; i++) { 556 557 N = 0; 558 for (j = 0; j < Nlist[i]; j++) { 559 560 m = mlist[i][j]; 561 c = clist[i][j]; 562 563 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 564 Nbad ++; 565 continue; 566 } 567 Mcal = getMcal (m, c, MAG_CLASS_PSF); 568 if (isnan(Mcal)) { 569 Ncal ++; 570 continue; 571 } 572 Mmos = getMmos (m, c); 573 if (isnan(Mmos)) { 574 Nmos ++; 575 continue; 576 } 577 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 578 if (isnan(Mgrp)) { 579 Ngrp ++; 580 continue; 581 } 582 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 583 if (isnan(Mrel)) { 584 Nrel ++; 585 continue; 586 } 587 588 n = catalog[c].measureT[m].averef; 589 Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 590 if (isnan(Msys)) { 591 Nsys++; 592 continue; 593 } 594 list[N] = Msys - Mrel - Mcal - Mmos - Mgrp; 595 dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR); 596 N++; 597 } 598 599 // the reference Cell is forced to have a value of 0.0, and is never changed to GRID_FITTED 600 if (gridV[i] == GRID_REFERENCE) { 601 gridM[i] = 0.0; 602 gridS[i] = 0.0; 603 gridN[i] = N; 604 continue; 605 } 606 607 // until we have enough valid measurements on this grid cell, skip it 608 if (N < GRID_TOOFEW) { 609 gridV[i] = GRID_FROZEN; 610 continue; 611 } 612 613 liststats (list, dlist, NULL, N, &stats); 614 gridM[i] = stats.mean; 615 gridS[i] = stats.sigma; 616 gridN[i] = N; 617 gridV[i] = GRID_FITTED; 618 Nfit++; 619 } 620 621 fprintf (stderr, "%d of %d grid cells fitted (+ reference cell) (Nbad: %d, Nmos: %d, Ncal: %d, Nrel: %d, Nsys: %d)\n", Nfit, Ngrid, Nbad, Nmos, Ncal, Nrel, Nsys); 622 623 free (list); 624 free (dlist); 625 } 626 627 void plot_grid (Catalog *catalog, FlatCorrectionTable *flatcorr) { 628 629 int i, j, m, c, n, N, Narea; 630 float Msys, Mrel, Mcal, Mmos, Mgrp; 631 double *xlist, *Mlist, *dlist, *ylist; 632 Graphdata graphdata; 633 634 if (!USE_GRID) return; 635 636 int Nsecfilt = GetPhotcodeNsecfilt (); 637 638 N = 0; 639 for (i = 0; i < Ngrid; i++) 640 N += Nlist[i]; 641 642 ALLOCATE (xlist, double, N); 643 ALLOCATE (ylist, double, N); 644 ALLOCATE (Mlist, double, N); 645 ALLOCATE (dlist, double, N); 646 647 Narea = 0; 648 N = 0; 649 for (i = 0; i < Ngrid; i++) { 650 for (j = 0; j < Nlist[i]; j++) { 651 652 m = mlist[i][j]; 653 c = clist[i][j]; 654 655 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) { 656 Narea ++; 657 continue; 658 } 659 Mcal = getMcal (m, c, MAG_CLASS_PSF); 660 if (isnan(Mcal)) continue; 661 Mmos = getMmos (m, c); 662 if (isnan(Mmos)) continue; 663 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 664 if (isnan(Mgrp)) continue; 665 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 666 if (isnan(Mrel)) continue; 667 668 n = catalog[c].measureT[m].averef; 669 Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 670 671 xlist[N] = Xmeas[c][m]; 672 ylist[N] = Ymeas[c][m]; 673 Mlist[N] = Msys - Mrel - Mcal - Mmos - Mgrp; 674 dlist[N] = Msys - Mrel - Mcal - Mmos - Mgrp - gridM[i]; 675 N++; 676 } 677 } 678 679 fprintf (stderr, "skipped %d meas for area\n", Narea); 680 681 plot_defaults (&graphdata); 682 graphdata.ymin = PlotdMmin; 683 graphdata.ymax = PlotdMmax; 684 plot_list (&graphdata, xlist, Mlist, N, "X vs dM raw", "%s.XdM.png", OUTROOT); 685 plot_list (&graphdata, xlist, dlist, N, "X vs dM corrected", "%s.XdMf.png", OUTROOT); 686 plot_list (&graphdata, ylist, dlist, N, "Y vs dM corrected", "%s.YdMf.png", OUTROOT); 687 688 plot_defaults (&graphdata); 689 plot_list (&graphdata, xlist, ylist, N, "X vs Y", "%s.XY.png", OUTROOT); 690 691 free (ylist); 692 free (xlist); 693 free (Mlist); 694 free (dlist); 695 696 } 697 698 void dump_grid () { 699 700 off_t i, Nimage; 701 int j, Nbytes, Nformat; 702 FILE *f; 703 Header header, theader; 704 Matrix matrix; 705 Mosaic *refmosaic; 706 char *filename; 707 char formatline[32], key[32], value[64]; 708 709 Nbytes = strlen (OUTROOT) + 6; 710 ALLOCATE (filename, char, Nbytes); 711 snprintf (filename, Nbytes, "%s.fits", OUTROOT); 712 713 /* select reference mosaic image */ 714 // off_t *imlist = SelectRefMosaic (&refmosaic, &Nimage); return value ignored 715 SelectRefMosaic (&refmosaic, &Nimage); 716 717 /* we are writing to this file */ 718 f = fopen (filename, "w"); 719 if (f == (FILE *) NULL) { 720 fprintf (stderr, "cannot open %s for output\n", filename); 721 free (filename); 722 return; 723 } 724 725 /* create empty phu */ 726 gfits_init_header (&header); 727 header.extend = TRUE; 728 gfits_create_header (&header); 729 gfits_create_matrix (&header, &matrix); 730 gfits_modify (&header, "NEXTEND", OFF_T_FMT, 1, Nimage + 3); 731 gfits_modify (&header, "FILTER", "%s", 1, photcodes[0][0].name); // XXXX note that this expects a single photcode, enforced in initialize.d 732 gfits_modify_alt (&header, "COMMENT", "%S", 1, "Mosaic Photometry Grid Analysis"); 733 734 // we need to add lines to the PHU to identify the camera and format; these are used by the ipp config system 735 // Note that config must have been loaded (and not freed) above. 736 ScanConfig (config, "NFORMAT", "%d", 1, &Nformat); 737 for (i = 1; i <= Nformat; i++) { 738 ScanConfig (config, "FORMAT", "%s", i, formatline); 739 sscanf (formatline, "%s %s", key, value); 740 gfits_modify (&header, key, "%s", 1, value); 741 } 742 743 gfits_fwrite_header (f, &header); 744 gfits_fwrite_matrix (f, &matrix); 745 gfits_free_matrix (&matrix); 746 747 /* save grid mag values */ 748 gfits_init_header (&theader); 749 theader.Naxes = 2; 750 theader.Naxis[0] = gridX; 751 theader.Naxis[1] = gridY; 752 theader.bitpix = -32; 753 gfits_create_Theader (&theader, "IMAGE"); 754 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 755 gfits_modify (&theader, "EXTNAME", "%s", 1, "MAG_OFFSET"); 756 gfits_create_matrix (&theader, &matrix); 757 for (i = 0; i < gridX; i++) { 758 for (j = 0; j < gridY; j++) { 759 gfits_set_matrix_value (&matrix, i, j, (double) gridM[i + j*gridX]); 760 } 761 } 762 write_coords (&theader, &refmosaic[0].coords); 763 gfits_fwrite_header (f, &theader); 764 gfits_fwrite_matrix (f, &matrix); 765 gfits_free_matrix (&matrix); 766 767 /* save grid Nmeas values */ 768 gfits_modify (&theader, "EXTNAME", "%s", 1, "NMEAS"); 769 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 770 gfits_create_matrix (&theader, &matrix); 771 for (i = 0; i < gridX; i++) { 772 for (j = 0; j < gridY; j++) { 773 gfits_set_matrix_value (&matrix, i, j, (double) gridN[i + j*gridX]); 774 } 775 } 776 write_coords (&theader, &refmosaic[0].coords); 777 gfits_fwrite_header (f, &theader); 778 gfits_fwrite_matrix (f, &matrix); 779 gfits_free_matrix (&matrix); 780 781 /* save grid sigma values */ 782 gfits_modify (&theader, "EXTNAME", "%s", 1, "SIGMA"); 783 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 784 gfits_create_matrix (&theader, &matrix); 785 for (i = 0; i < gridX; i++) { 786 for (j = 0; j < gridY; j++) { 787 gfits_set_matrix_value (&matrix, i, j, (double) gridS[i + j*gridX]); 788 } 789 } 790 write_coords (&theader, &refmosaic[0].coords); 791 gfits_fwrite_header (f, &theader); 792 gfits_fwrite_matrix (f, &matrix); 793 gfits_free_matrix (&matrix); 794 795 /* calculate value for each CCD pixel, write out CCD images */ 796 /* grid pixels are tied to detector pixels, but are flipped to match focal plane */ 797 for (i = 0; i < camera.Nchip; i++) { 798 int N, ix, iy, x, y, X, Y, bin; 799 800 N = ccdnum[i]; 801 802 gfits_modify (&theader, "EXTNAME", "%s", 1, camera.ccdname[N]); 803 gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name); 804 gfits_modify (&theader, "NX", "%d", 1, camera.Nx); 805 gfits_modify (&theader, "NY", "%d", 1, camera.Ny); 806 807 theader.Naxis[0] = RELPHOT_GRID_X; 808 theader.Naxis[1] = RELPHOT_GRID_Y; 809 gfits_modify (&theader, "NAXIS1", "%d", 1, RELPHOT_GRID_X); 810 gfits_modify (&theader, "NAXIS2", "%d", 1, RELPHOT_GRID_Y); 811 gfits_create_matrix (&theader, &matrix); 812 813 for (Y = 0; Y < RELPHOT_GRID_Y; Y++) { 814 for (X = 0; X < RELPHOT_GRID_X; X++) { 815 816 /* normalize X & Y */ 817 x = X; 818 if (camera.Fx[N]) x = RELPHOT_GRID_X - X - 1; 819 y = Y; 820 if (camera.Fy[N]) y = RELPHOT_GRID_Y - Y - 1; 821 822 /* coordinates in the grid */ 823 ix = x + camera.Ox[N]*RELPHOT_GRID_X; 824 iy = y + camera.Oy[N]*RELPHOT_GRID_Y; 825 826 bin = ix + iy*gridX; 827 gfits_set_matrix_value (&matrix, X, Y, (double) gridM[bin]); 828 } 829 } 830 gfits_fwrite_header (f, &theader); 831 gfits_fwrite_matrix (f, &matrix); 832 gfits_free_matrix (&matrix); 833 } 834 835 free (filename); 836 } 837 838 void InterpolateGrid (float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords) { 839 840 int i, j; 841 double x, y, r, d, X, Y, dx, dy; 842 double V00, V01, V10, V11; 843 double wV00, wV01, wV10, wV11; 844 double dV00, dV01, dV10, dV11; 845 double v1, v2, value; 846 int ix, iy, N; 847 848 for (i = 0; i < Nx; i++) { 849 for (j = 0; j < Ny; j++) { 850 x = i * RELPHOT_GRID_BINNING / 2; 851 y = j * RELPHOT_GRID_BINNING / 2; 852 XY_to_RD (&r, &d, x, y, ccd); 853 RD_to_XY (&X, &Y, r, d, gcoords); 854 855 X = X / RELPHOT_GRID_BINNING; 856 Y = Y / RELPHOT_GRID_BINNING; 857 858 ix = (int) X; 859 dx = X - ix; 860 iy = (int) Y; 861 dy = Y - iy; 862 863 if (ix < 0) continue; 864 if (iy < 0) continue; 865 if (ix >= gridX) continue; 866 if (iy >= gridY) continue; 867 868 N = ix + iy*gridX; 869 V00 = gridM[N]; 870 V10 = gridM[N + 1]; 871 V01 = gridM[N + gridX]; 872 V11 = gridM[N + gridX + 1]; 873 874 dV00 = gridS[N]; 875 dV10 = gridS[N + 1]; 876 dV01 = gridS[N + gridX]; 877 dV11 = gridS[N + gridX + 1]; 878 879 wV00 = (dV00 == 0) ? 0.0 : 1 / SQ(dV00); 880 wV01 = (dV01 == 0) ? 0.0 : 1 / SQ(dV01); 881 wV10 = (dV10 == 0) ? 0.0 : 1 / SQ(dV10); 882 wV11 = (dV11 == 0) ? 0.0 : 1 / SQ(dV11); 883 884 v1 = wV00*V00*(1 + dx*dy - dx - dy) + 885 wV10*V10*(dx - dx*dy) + 886 wV01*V01*(dy - dx*dy) + 887 wV11*V11*(dx*dy); 888 889 v2 = wV00*(1 + dx*dy - dx - dy) + 890 wV10*(dx - dx*dy) + 891 wV01*(dy - dx*dy) + 892 wV11*(dx*dy); 893 894 value = v1 / v2; 895 buffer[j*Nx + i] = value; 896 } 897 } 898 } 312 // edge effects could cause some positions to be slightly out of range 313 // probably should trap extreme outliers 314 int ix = MIN(MAX(0, (int)(measure->Xccd * grid->dX)), grid->Nx - 1); 315 int iy = MIN(MAX(0, (int)(measure->Yccd * grid->dY)), grid->Ny - 1); 316 317 float Mgrid = grid-> Mgrid[ix][iy]; 318 return Mgrid; 319 } 320 321 float getMgridTiny (MeasureTiny *measure) { 322 323 if (!GRID_ZEROPT) return 0.0; 324 if (GRID_ZPT_MODE == GRID_ZPT_MODE_NONE) return 0.0; 325 326 int code = measure->photcode; 327 if (code <= 0) return 0.0; 328 if (code >= NGridCorr) return 0.0; // does not match one of our image, skip 329 330 GridCorrectionType *grid = GridCorr[code]; 331 if (!grid) return 0.0; // does not match one of our images, skip 332 333 // edge effects could cause some positions to be slightly out of range 334 // probably should trap extreme outliers 335 int ix = MIN(MAX(0, (int)(measure->Xccd * grid->dX)), grid->Nx - 1); 336 int iy = MIN(MAX(0, (int)(measure->Yccd * grid->dY)), grid->Ny - 1); 337 338 float Mgrid = grid-> Mgrid[ix][iy]; 339 return Mgrid; 340 } 341 342 // for historical reasons, Mflat and Mgrid have opposite signs 343 void setMflatFromGrid (Catalog *catalog) { 344 if (!GRID_ZEROPT) return; 345 for (off_t j = 0; j < catalog->Nmeasure; j++) { 346 float Mgrid = getMgrid (&catalog->measure[j]); 347 catalog->measure[j].Mflat += Mgrid; 348 } 349 } 350 -
trunk/Ohana/src/relphot/src/ImageOps.c
r41557 r41647 319 319 } 320 320 321 int findCCD (off_t idx, off_t meas, int cat, MeasureTiny *measure) {322 323 int ccdnum;324 double X, Y;325 char *pname, *filter, *p, base[256];326 327 /* identify the ccd on the basis of the photcode name */328 pname = GetPhotcodeNamebyCode (image[idx].photcode);329 330 // skip measurements which do not match one of the requested photcodes (331 // (do we not already exclude in bcatalog -- maybe needed for reload_objects?332 int Ns = GetActivePhotcodeIndex (measure[0].photcode);333 if (Ns < 0) return FALSE;334 335 filter = photcodes[Ns][0].name;336 sprintf (base, "%s.%s.", MOSAICNAME, filter);337 if (strncmp (pname, base, strlen (base))) return (FALSE);338 p = pname + strlen(base);339 340 /* p is pointing at the DETECTOR ID part of the photcode: CAMERA.FILTER.DETECTOR341 for now, we will let this be of the form SSSSnn where SSS is an arbitrary string342 and nn is an integer -> ccdnum */343 344 /// XXX we have an inconsistency here wrt dvo.layout and dvo.photcode345 346 while (!isdigit(*p) && *p) p++;347 if (*p == 0) return (FALSE);348 ccdnum = atoi (p);349 350 /* ccdnum is an integer, but not necessarily a sequence number. when the camera layout is351 constructed, there will be null values for undefined ccdnums */352 353 // old code to add this measurement to the grid cell for this chip354 // ave = measureT[0].averef;355 // ra = catalog[cat].averageT[ave].R - measureT[0].dR / 3600.0;356 // dec = catalog[cat].averageT[ave].D - measureT[0].dD / 3600.0;357 // RD_to_XY (&X, &Y, ra, dec, &image[i].coords);358 359 // XXX we can now use these values (but need to be careful about old formats)360 X = measure[0].Xccd;361 Y = measure[0].Yccd;362 setGridMeasure (meas, cat, X, Y, ccdnum);363 364 return (TRUE);365 }366 367 321 void matchImage (Catalog *catalog, off_t meas, int cat, int doImageList) { 368 322 369 323 off_t idx, ID; 370 int status;371 324 MeasureTiny *measure; 372 325 … … 381 334 catalog[cat].measureT[meas].myDet = TRUE; 382 335 383 if (USE_GRID) {384 status = findCCD (idx, meas, cat, measure);385 if (!status) {386 if (VERBOSE2) fprintf (stderr, "failed to determine CCD for "OFF_T_FMT", %d\n", meas, cat);387 return;388 }389 }390 391 336 // index for (catalog, measure) -> image 392 337 MeasureToImage[cat][meas] = idx; … … 440 385 if (i == -1) return NAN; 441 386 442 if (image[i].flags & IMAGE_BAD) return NAN; 387 // allow context dependence?: in relphot_images, we want to exclude detections from poor images 388 // but in the final pass, we want to allow even bad detections 389 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) return NAN; 443 390 444 391 switch (class) { … … 464 411 if (i == -1) return (1000); 465 412 466 if (image[i].flags & IMAGE_BAD) return (1000);467 413 distance = image[i].ubercalDist; // was dummy3 in structure 468 414 return (distance); … … 552 498 } 553 499 554 float getMflat (off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog) {555 OHANA_UNUSED_PARAM(flatcorr);556 557 off_t i = MeasureToImage[cat][meas];558 if (i == -1) return (NAN);559 560 float offset = catalog[cat].measureT[meas].Mflat;561 if (!isfinite(offset)) {562 offset = 0.0;563 }564 565 // to do this, I need to pass in the catalog and flatcorr pointers566 // int flat_id = image[i].photom_map_id;567 // if (flat_id) {568 // offset = FlatCorrectionOffset (flatcorr, flat_id, catalog[cat].measureT[meas].Xccd, catalog[cat].measureT[meas].Yccd);569 // }570 571 return (offset);572 }573 574 500 Coords *getCoords (off_t meas, int cat) { 575 501 … … 582 508 583 509 /* determine Mcal values for all images */ 584 void setMcal (Catalog *catalog , FlatCorrectionTable *flatcorr) {510 void setMcal (Catalog *catalog) { 585 511 586 512 off_t i, j, m, c, n; … … 690 616 continue; 691 617 } 692 float Mgrid = getMgrid (m, c);618 float Mgrid = getMgridTiny (&catalog[c].measureT[m]); 693 619 if (isnan(Mgrid)) { 694 620 Ngrid++; … … 711 637 // apply that offset as well here for this image (in other words, each detection is 712 638 // being compared to the model, excluding the zero point, Mcal. The model includes 713 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat) 714 715 float Mflat = getMflat (m, c, flatcorr, catalog); 639 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal + Mflat) 640 // this was inconsistent w.r.t. PhotRel pre-r41606 641 642 float Mflat = getMflat (m, c, catalog); 716 643 717 644 n = catalog[c].measureT[m].averef; … … 722 649 } 723 650 724 float Moff = Mmos + Mgrp + Mgrid -Mflat;651 float Moff = Mmos + Mgrp + Mgrid + Mflat; 725 652 726 653 PhotCode *code = GetPhotcodebyCode (catalog[c].measureT[m].photcode); … … 763 690 if (mark) { 764 691 image[i].flags |= ID_IMAGE_PHOTOM_FEW; 692 image[i].McalPSF = 0.0; 693 image[i].McalAPER = 0.0; 694 image[i].McalChiSq = NAN; 765 695 image[i].dMcal = NAN; 766 image[i]. McalChiSq= NAN;696 image[i].dMagSys = NAN; 767 697 image[i].nFitPhotom = 0; 768 698 Nfew ++; … … 835 765 836 766 /* determine McalTEST values for all images -- this is not used to set measure.Mcal, but only to test */ 837 void setMcalTest (Catalog *catalog , FlatCorrectionTable *flatcorr) {767 void setMcalTest (Catalog *catalog) { 838 768 839 769 off_t i, j, m, c, n; … … 889 819 continue; 890 820 } 891 float Mgrid = getMgrid (m, c);821 float Mgrid = getMgridTiny (&catalog[c].measureT[m]); 892 822 if (isnan(Mgrid)) { 893 823 Ngrid++; … … 905 835 // apply that offset as well here for this image (in other words, each detection is 906 836 // being compared to the model, excluding the zero point, Mcal. The model includes 907 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal -Mflat)908 909 float Mflat = getMflat (m, c, flatcorr,catalog);837 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal + Mflat) 838 839 float Mflat = getMflat (m, c, catalog); 910 840 911 841 // get the PSF magnitude for thie measurement, with airmass slope applied … … 917 847 } 918 848 919 float Moff = Mmos + Mgrp + Mgrid -Mflat;849 float Moff = Mmos + Mgrp + Mgrid + Mflat; 920 850 921 851 psfStars.alldata-> yVector[Nref] = MsysPSF - MrelPSF - Moff; … … 968 898 // measure stats for Mcal and dMcal 969 899 for (i = N = 0; i < Nimage; i++) { 970 if (image[i].flags & IMAGE_BAD) continue;900 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 971 901 972 902 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 996 926 997 927 mark = FALSE; 998 image[i].flags &= ~ID_IMAGE_PHOTOM_POOR; 999 mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].McalPSF - MedOffset) > MaxOffset); 928 929 if (image[i].flags & ID_IMAGE_PHOTOM_FEW) { 930 mark = TRUE; 931 } 932 if (image[i].dMcal > MaxScatter) { 933 mark = TRUE; 934 } 935 if (fabs(image[i].McalPSF - MedOffset) > MaxOffset) { 936 mark = TRUE; 937 } 938 1000 939 if (mark) { 1001 940 Nmark ++; … … 1146 1085 } 1147 1086 1148 StatType statsImageN (Catalog *catalog , FlatCorrectionTable *flatcorr) {1087 StatType statsImageN (Catalog *catalog) { 1149 1088 1150 1089 off_t i, j, m, c, n, N; … … 1163 1102 n = 0; 1164 1103 for (i = 0; i < Nimage; i++) { 1165 if (image[i].flags & IMAGE_BAD)continue;1104 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1166 1105 1167 1106 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 1179 1118 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1180 1119 if (isnan(Mgrp)) continue; 1181 Mgrid = getMgrid (m, c);1120 Mgrid = getMgridTiny (&catalog[c].measureT[m]); 1182 1121 if (isnan(Mgrid)) continue; 1183 1122 N++; … … 1212 1151 for (i = 0; i < Nimage; i++) { 1213 1152 1214 if (image[i].flags & IMAGE_BAD)continue;1153 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1215 1154 1216 1155 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 1245 1184 for (i = 0; i < Nimage; i++) { 1246 1185 1247 if (image[i].flags & IMAGE_BAD)continue;1186 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1248 1187 1249 1188 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; … … 1278 1217 for (i = 0; i < Nimage; i++) { 1279 1218 1280 if (image[i].flags & IMAGE_BAD)continue;1219 if (image[i].flags & (ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1281 1220 1282 1221 if (FREEZE_IMAGES && isMosaicChip(image[i].photcode)) continue; -
trunk/Ohana/src/relphot/src/MagResidSave.c
r41561 r41647 192 192 CHECK_STATUS (!status, "ERROR: problem closing meanmags file %s\n", filename); 193 193 194 FitDataSetFree (&psfStars); 195 194 196 return TRUE; 195 197 } … … 213 215 off_t c = ImageToCatalog[j]; 214 216 215 // XXX drop this?216 217 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) continue; 217 218 … … 225 226 if (isnan(Mgrp)) continue; 226 227 227 float Mgrid = getMgrid (m, c);228 float Mgrid = getMgridTiny (&catalog[c].measureT[m]); 228 229 if (isnan(Mgrid)) continue; 229 230 … … 231 232 // apply that offset as well here for this image (in other words, each detection is 232 233 // being compared to the model, excluding the zero point, Mcal. The model includes 233 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal -Mflat)234 235 // float Mflat = getMflat (m, c, flatcorr, catalog);234 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal + Mflat) 235 236 float Mflat = getMflat (m, c, catalog); 236 237 237 238 // MrelPSF is the average magnitude for this star. … … 246 247 if (isnan(MsysPSF)) continue; 247 248 248 // XXX skip Mflat for now 249 // float Moff = Mcal + Mmos + Mgrp + Mgrid - Mflat; 250 251 float Moff = Mcal + Mmos + Mgrp + Mgrid; 249 float Moff = Mcal + Mmos + Mgrp + Mgrid + Mflat; 252 250 253 251 // Mrel is the true average apparent magnitude of this star -
trunk/Ohana/src/relphot/src/MosaicOps.c
r41559 r41647 1 1 # include "relphot.h" 2 2 off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start); 3 int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog , FlatCorrectionTable *flatcorr);3 int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog); 4 4 5 5 // see discussion in ImagesOps.c re: IDX_T … … 50 50 # undef COMPARE 51 51 52 }53 54 /* find mosaic frames (unique time periods & photcode name matches mosaic) */55 void initMosaics_old (Image *image, off_t Nimage) {56 57 off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;58 unsigned int start, stop;59 char *pname;60 61 if (!MOSAIC_ZEROPT) return;62 63 Nmosaic = 0;64 NMOSAIC = 10;65 ALLOCATE (mosaic, Mosaic, NMOSAIC);66 67 ALLOCATE (MosaicToImage, off_t *, NMOSAIC);68 ALLOCATE (MosaicN_Image, off_t, NMOSAIC);69 ALLOCATE (MosaicN_IMAGE, off_t, NMOSAIC);70 71 ALLOCATE (ImageToMosaic, off_t, Nimage); // mosaic to which image belongs72 73 /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no74 * entry in the image table that represents this mosaic. Instead, it is an75 * internal construct that defines a group of related images76 */77 78 /* generate list of unique mosaics */79 for (i = 0; i < Nimage; i++) {80 ImageToMosaic[i] = -1;81 82 /* select valid mosaic images by photcode */83 pname = GetPhotcodeNamebyCode (image[i].photcode);84 status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));85 if (status) continue;86 87 /* set image time range */88 start = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1);89 stop = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);90 91 /* find existing mosaic with this time range */92 found = FALSE;93 for (j = 0; !found && (j < Nmosaic); j++) {94 if (stop < mosaic[j].start) continue;95 if (start > mosaic[j].stop) continue;96 found = TRUE;97 98 // add reference from image to mosaic99 ImageToMosaic[i] = j;100 101 /* add image to mosaic image list */102 MosaicToImage[j][MosaicN_Image[j]] = i;103 MosaicN_Image[j] ++;104 if (MosaicN_Image[j] == MosaicN_IMAGE[j]) {105 MosaicN_IMAGE[j] += 10;106 REALLOCATE (MosaicToImage[j], off_t, MosaicN_IMAGE[j]);107 }108 109 }110 if (found) continue;111 112 /* a new mosaic, define ranges -- preserve the original values incase this image is not used */113 mosaic[Nmosaic].start = start;114 mosaic[Nmosaic].stop = stop;115 mosaic[Nmosaic].McalPSF = 0.0; // note : at the end, mosaic.Mcal is added back to the input images116 mosaic[Nmosaic].McalAPER = 0.0; // note : mosaic stores only offsets relative to the original image values117 mosaic[Nmosaic].dMcal = 0.0; // note : at the end, mosaic.Mcal is added back to the input images118 mosaic[Nmosaic].dMsys = 0.0;119 mosaic[Nmosaic].McalChiSq = 0.0;// NAN or 0.0?120 mosaic[Nmosaic].flags = image[i].flags;121 mosaic[Nmosaic].secz = image[i].secz;122 mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);123 124 // XXX do we need to do something about flag consistency across a mosaic?125 126 /* add image to mosaic image list */127 MosaicN_IMAGE[Nmosaic] = 10;128 MosaicN_Image[Nmosaic] = 1;129 ALLOCATE (MosaicToImage[Nmosaic], off_t, MosaicN_IMAGE[Nmosaic]);130 MosaicToImage[Nmosaic][0] = i;131 132 // add reference from image to mosaic133 ImageToMosaic[i] = Nmosaic;134 135 Nmosaic ++;136 if (Nmosaic == NMOSAIC) {137 NMOSAIC += 10;138 REALLOCATE (mosaic, Mosaic, NMOSAIC);139 REALLOCATE (MosaicToImage, off_t *, NMOSAIC);140 REALLOCATE (MosaicN_Image, off_t, NMOSAIC);141 REALLOCATE (MosaicN_IMAGE, off_t, NMOSAIC);142 }143 }144 145 // free this or not?146 free (MosaicN_IMAGE);147 148 initMosaicGrid (image, Nimage);149 150 fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nimage, (int) Nmosaic);151 return;152 52 } 153 53 … … 318 218 free (startTimesMosaic); 319 219 320 initMosaic Grid(subset, Nsubset);220 initMosaicMcal (subset, Nsubset); 321 221 322 222 fprintf (stderr, "matched %d images to %d mosaics, %d simple chips not matched to mosaics\n", (int) (Nsubset - Nsimple), (int) Nmosaic, (int) Nsimple); … … 460 360 461 361 if (mergeMcal) { 462 initMosaic Grid(image, Nimage);362 initMosaicMcal (image, Nimage); 463 363 } 464 364 … … 511 411 } 512 412 413 // this function sets mosaic->coords to the median of the individual chips. This 414 // coordinate frame is used by the parallel region analysis to assign exposures (mosaics) 415 // to specific machines by a single center (rather than individual chips) 513 416 void setMosaicCenters (Image *image, off_t Nimage) { 514 417 OHANA_UNUSED_PARAM(Nimage); … … 599 502 mosaic[i].coords.cdelt1 = 1.0 / 3600.0; 600 503 mosaic[i].coords.cdelt2 = 1.0 / 3600.0; 601 602 mosaic[i].McalPSF = 0.0;603 mosaic[i].McalAPER = 0.0;604 mosaic[i].dMcal = 0.0;605 mosaic[i].dMsys = 0.0;606 mosaic[i].McalChiSq = 0.0;607 504 } 608 505 return; 609 506 } 610 507 611 void initMosaic Grid(Image *image, off_t Nimage) {508 void initMosaicMcal (Image *image, off_t Nimage) { 612 509 OHANA_UNUSED_PARAM(Nimage); 613 510 614 /* find max dR, dD range for all mosaics */615 /* define mosaic.coords to cover dR, dD */616 /* send results to initGridBins */617 618 off_t i, j, m, NX, NY;619 int dXmax, dYmax;620 double dS, dX, dY;621 double R, D, Rmin, Rmax, Dmin, Dmax;622 511 double McalPSF, McalAPER, dMcal, McalChiSq; 623 512 624 513 fprintf (stderr, "*** moving Mcal from image.Mcal to mosaic.Mcal ***\n"); 625 514 626 dXmax = dYmax = 0.0; 627 for (i = 0; i < Nmosaic; i++) { 628 Dmin = Rmin = 360.0; 629 Dmax = Rmax = -360.0; 630 dS = 0.0; 515 for (off_t i = 0; i < Nmosaic; i++) { 631 516 McalPSF = McalAPER = dMcal = McalChiSq = 0; 632 for (j = 0; j < MosaicN_Image[i]; j++) { 633 m = MosaicToImage[i][j]; 634 NX = image[m].NX; 635 NY = image[m].NY; 636 dS += hypot (image[m].coords.cdelt1*image[m].coords.pc1_1, image[m].coords.cdelt1*image[m].coords.pc2_1); 637 638 OhanaProjection proj = GetProjection (image[m].coords.ctype); 639 if ((proj == PROJ_WRP) && !image[m].coords.mosaic) { 640 XY_to_LM (&R, &D, 0.0, 0.0, &image[m].coords); 641 } else { 642 XY_to_RD (&R, &D, 0.0, 0.0, &image[m].coords); 643 } 644 Rmin = MIN (Rmin, R); 645 Rmax = MAX (Rmax, R); 646 Dmin = MIN (Dmin, D); 647 Dmax = MAX (Dmax, D); 648 649 if ((proj == PROJ_WRP) && !image[m].coords.mosaic) { 650 XY_to_LM (&R, &D, (double) NX, 0.0, &image[m].coords); 651 } else { 652 XY_to_RD (&R, &D, (double) NX, 0.0, &image[m].coords); 653 } 654 Rmin = MIN (Rmin, R); 655 Rmax = MAX (Rmax, R); 656 Dmin = MIN (Dmin, D); 657 Dmax = MAX (Dmax, D); 658 659 if ((proj == PROJ_WRP) && !image[m].coords.mosaic) { 660 XY_to_LM (&R, &D, (double) NX, (double) NY, &image[m].coords); 661 } else { 662 XY_to_RD (&R, &D, (double) NX, (double) NY, &image[m].coords); 663 } 664 Rmin = MIN (Rmin, R); 665 Rmax = MAX (Rmax, R); 666 Dmin = MIN (Dmin, D); 667 Dmax = MAX (Dmax, D); 668 669 if ((proj == PROJ_WRP) && !image[m].coords.mosaic) { 670 XY_to_LM (&R, &D, 0.0, (double) NY, &image[m].coords); 671 } else { 672 XY_to_RD (&R, &D, 0.0, (double) NY, &image[m].coords); 673 } 674 Rmin = MIN (Rmin, R); 675 Rmax = MAX (Rmax, R); 676 Dmin = MIN (Dmin, D); 677 Dmax = MAX (Dmax, D); 678 679 // XXX : this probably does not handle mosaics at RA = 0,360 well 680 681 /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */ 682 683 // XXX: how does this work with UBERCAL? We want to keep the Mcal values supplied by ubercal, but 684 // solve for a single offset for each exposure (Mosaic.Mcal). 685 // we also want to keep the flat-field terms for each exposure (regardless of ubercal or not) 686 // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value 517 for (off_t j = 0; j < MosaicN_Image[i]; j++) { 518 off_t m = MosaicToImage[i][j]; 687 519 688 520 if (!isfinite(image[m].McalPSF)) { 689 image[m].McalPSF = 0.0;690 image[m].McalAPER = 0.0;691 image[m].dMcal = 0.0;521 image[m].McalPSF = 0.0; 522 image[m].McalAPER = 0.0; 523 image[m].dMcal = 0.0; 692 524 image[m].McalChiSq = 0.0; 693 525 fprintf (stderr, "warning: resetting NAN value for Mcal %s\n", image[m].name); … … 703 535 image[m].dMcal = NAN; 704 536 image[m].McalChiSq = NAN; 705 706 } 707 dS /= MosaicN_Image[i]; 708 709 InitCoords (&mosaic[i].coords, "DEC--TAN"); 710 mosaic[i].coords.crval1 = Rmin; 711 mosaic[i].coords.crval2 = Dmin; 712 mosaic[i].coords.cdelt1 = dS; 713 mosaic[i].coords.cdelt2 = dS; 714 715 RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords); 537 } 716 538 717 539 mosaic[i].McalPSF = McalPSF / MosaicN_Image[i]; … … 720 542 mosaic[i].McalChiSq = McalChiSq / MosaicN_Image[i]; 721 543 } 722 if (!USE_GRID) return;723 724 dXmax = MAX (dXmax, dX);725 dYmax = MAX (dYmax, dY);726 initGrid (dXmax, dYmax);727 544 return; 728 545 } … … 963 780 if (i == -1) return (0.0); 964 781 965 if (mosaic[i].flags & IMAGE_BAD) return (NAN); 782 // if the mosaic cannot be calibrated (too few measurements, skip it) 783 // XXX: if the mosaic is bad (few) but the chips are OK, I can used them. 784 // XXX: if (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW) return (NAN); 966 785 value = mosaic[i].McalPSF; 967 786 return (value); … … 1001 820 Catalog *catalog; 1002 821 Image *image; 1003 FlatCorrectionTable *flatcorr;1004 822 SetMmosInfo info; 1005 823 } ThreadInfo; 1006 824 1007 int setMmos_mosaic (Mosaic *mosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info , FlatCorrectionTable *flatcorr);825 int setMmos_mosaic (Mosaic *mosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info); 1008 826 void *setMmos_worker (void *data); 1009 int setMmos_threaded (Catalog *catalog , FlatCorrectionTable *flatcorr);827 int setMmos_threaded (Catalog *catalog); 1010 828 1011 829 void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists) { … … 1073 891 } 1074 892 1075 int setMmos (Catalog *catalog , FlatCorrectionTable *flatcorr) {893 int setMmos (Catalog *catalog) { 1076 894 1077 895 off_t i, N, Nmax; … … 1086 904 // so do not run setMmos in threaded mode if PLOTSTUFF is set 1087 905 if (NTHREADS && !PLOTSTUFF) { 1088 int status = setMmos_threaded (catalog , flatcorr);906 int status = setMmos_threaded (catalog); 1089 907 return status; 1090 908 } … … 1106 924 1107 925 for (i = 0; i < Nmosaic; i++) { 1108 setMmos_mosaic (&mosaic[i], i, image, catalog, &info , flatcorr);926 setMmos_mosaic (&mosaic[i], i, image, catalog, &info); 1109 927 } 1110 928 SetMmosInfoFree (&info); … … 1123 941 1124 942 // 'mosaic' is a pointer to the current mosaic of interest (Nmos) 1125 int setMmos_mosaic (Mosaic *myMosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info , FlatCorrectionTable *flatcorr) {943 int setMmos_mosaic (Mosaic *myMosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info) { 1126 944 1127 945 off_t j, NimageReal; … … 1204 1022 snprintf (filename, 64, "test.%05d.%02d.dat", (int) Nmos, npass_output); 1205 1023 fout = fopen (filename, "w"); 1206 save_test_mosaic_measures (fout, Nmos, catalog , flatcorr);1024 save_test_mosaic_measures (fout, Nmos, catalog); 1207 1025 fclose (fout); 1208 1026 } … … 1231 1049 continue; 1232 1050 } 1233 float Mgrid = getMgrid (m, c);1051 float Mgrid = getMgridTiny (&catalog[c].measureT[m]); 1234 1052 if (isnan(Mgrid)) { 1235 1053 info->Ngrid ++; … … 1253 1071 // apply that offset as well here for this image (in other words, each detection is 1254 1072 // being compared to the model, excluding the zero point, Mcal. The model includes 1255 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat) 1256 1257 float Mflat = getMflat (m, c, flatcorr, catalog); 1073 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal + Mflat). 1074 // this was inconsistent pre r41606 1075 1076 float Mflat = getMflat (m, c, catalog); 1258 1077 1259 1078 off_t n = catalog[c].measureT[m].averef; … … 1278 1097 assert (Nbright >= 0); 1279 1098 1280 float Moff = Mcal + Mgrp + Mgrid -Mflat;1099 float Moff = Mcal + Mgrp + Mgrid + Mflat; 1281 1100 1282 1101 psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Moff; … … 1370 1189 } 1371 1190 1372 int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog , FlatCorrectionTable *flatcorr) {1191 int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog) { 1373 1192 1374 1193 int Nsecfilt = GetPhotcodeNsecfilt (); … … 1382 1201 float Mcal = getMcal (m, c, MAG_CLASS_PSF); 1383 1202 // float Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1384 float Mgrid = getMgrid (m, c);1203 float Mgrid = getMgridTiny (&catalog[c].measureT[m]); 1385 1204 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); 1386 float Mflat = getMflat (m, c, flatcorr,catalog);1205 float Mflat = getMflat (m, c, catalog); 1387 1206 1388 1207 off_t n = catalog[c].measureT[m].averef; 1389 1208 float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF); 1390 1209 1391 float delta = MsysPSF - MrelPSF - Mcal - Mgrid +Mflat;1210 float delta = MsysPSF - MrelPSF - Mcal - Mgrid - Mflat; 1392 1211 1393 1212 int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD); … … 1398 1217 } 1399 1218 1400 int setMmos_threaded (Catalog *catalog , FlatCorrectionTable *flatcorr) {1219 int setMmos_threaded (Catalog *catalog) { 1401 1220 1402 1221 int i; … … 1435 1254 threadinfo[i].catalog = catalog; 1436 1255 threadinfo[i].image = image; 1437 threadinfo[i].flatcorr = flatcorr;1438 1256 1439 1257 // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop) used in … … 1481 1299 summary.Nskip); 1482 1300 free (threadinfo); 1301 // XXX SetMmosInfoFree (&summary); 1483 1302 1484 1303 npass_output ++; … … 1503 1322 1504 1323 Catalog *catalog = threadinfo->catalog; 1505 FlatCorrectionTable *flatcorr = threadinfo->flatcorr;1506 1324 Image *image = threadinfo->image; 1507 1325 1508 setMmos_mosaic (&mosaic[i], i, image, catalog, &results , flatcorr);1326 setMmos_mosaic (&mosaic[i], i, image, catalog, &results); 1509 1327 SetMmosInfoAccum (&threadinfo->info, &results); 1510 1328 } … … 1512 1330 SetMmosInfoFree (&results); 1513 1331 return NULL; 1514 }1515 1516 // When we rationalize the images/mosaics, we are driving the negative cloud images back1517 // to 0.0. At the same time, we make a guess to the effective impact on all other images,1518 // driven by the coupling of common stars.1519 // XXX this function is no longer used because we force significantly negative clouds to 0.01520 int rationalize_mosaics (Catalog *catalog, int Ncatalog) {1521 1522 double *imageOffset, **starOffset;1523 int **starNcount, *seclist;1524 int **Slist, *NSlist, *NSLIST;1525 int i, j, k, m, nMos, Ns, found;1526 1527 off_t Nimage;1528 Image *image;1529 1530 // set a test value for now1531 float CLOUD_TOLERANCE = 0.025;1532 1533 if (!MOSAIC_ZEROPT) return (FALSE);1534 if (FREEZE_MOSAICS) return (FALSE);1535 1536 image = getimages (&Nimage, NULL);1537 1538 ALLOCATE (imageOffset, double, Nmosaic);1539 ALLOCATE ( Slist, int *, Nmosaic); // array of calibrated star indexes on this mosaic1540 ALLOCATE (NSlist, int, Nmosaic); // number of stars on mosaic1541 ALLOCATE (NSLIST, int, Nmosaic); // number of Slist entries allocated1542 memset (Slist, 0, Nmosaic*sizeof(int *));1543 1544 // find the images / mosaics with negative clouds and save their offset1545 for (i = 0; i < Nmosaic; i++) {1546 1547 NSlist[i] = 0;1548 NSLIST[i] = 100;1549 ALLOCATE (Slist[i], int, NSLIST[i]);1550 1551 imageOffset[i] = 0.0;1552 1553 if (VERBOSE2 && (fabs(mosaic[i].McalPSF) < CLOUD_TOLERANCE)) {1554 fprintf (stderr, "cloud-free: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);1555 }1556 if (VERBOSE2 && (mosaic[i].McalPSF < -CLOUD_TOLERANCE)) {1557 imageOffset[i] = -mosaic[i].McalPSF;1558 // NOTE the negative sign: down below, we are going to add in the negative of McalPSF1559 // to this image, and the propagated mean values for other images1560 fprintf (stderr, "anti-clouds: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);1561 }1562 if (VERBOSE2 && (mosaic[i].McalPSF > CLOUD_TOLERANCE)) {1563 fprintf (stderr, "cloudy : %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);1564 }1565 }1566 1567 int Nsecfilt = GetPhotcodeNsecfilt ();1568 ALLOCATE (seclist, int, Nphotcodes);1569 for (Ns = 0; Ns < Nphotcodes; Ns ++) {1570 int thisCode = photcodes[Ns][0].code;1571 seclist[Ns] = GetPhotcodeNsec(thisCode);1572 }1573 1574 // allocate an array for star offsets1575 int Nstars = 0;1576 int NSTARS = 1000;1577 ALLOCATE (starOffset, double *, NSTARS);1578 ALLOCATE (starNcount, int *, NSTARS);1579 memset (starOffset, 0, NSTARS*sizeof(double *));1580 memset (starNcount, 0, NSTARS*sizeof(int *));1581 1582 // find the mean offset for each star1583 for (i = 0; i < Ncatalog; i++) {1584 for (j = 0; j < catalog[i].Naverage; j++) {1585 ALLOCATE (starOffset[Nstars], double, Nphotcodes);1586 ALLOCATE (starNcount[Nstars], int, Nphotcodes);1587 memset (starOffset[Nstars], 0, Nphotcodes*sizeof(double));1588 memset (starNcount[Nstars], 0, Nphotcodes*sizeof(int));1589 1590 m = catalog[i].averageT[j].measureOffset;1591 1592 // determine the mosaic for each measurement1593 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {1594 1595 // skip unused measurements1596 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;1597 1598 // skip unused measurements1599 1600 // XXX replace with:1601 // Ns = GetActivePhotcodeIndex (photcode);1602 // if (Ns < 0) continue;1603 1604 int Nsec;1605 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);1606 found = FALSE;1607 for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) {1608 if (ecode == photcodes[Ns][0].code) {1609 found = TRUE;1610 break;1611 }1612 }1613 if (!found) continue;1614 Nsec = seclist[Ns];1615 1616 // bad stars for this secfilt1617 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;1618 1619 // skip REF measurements (not tied to an image)1620 if (getImageEntry (m, i) < 0) continue;1621 1622 // find the source of this measurement (skip unassigned measurements)1623 nMos = MeasureToMosaic[i][m];1624 if (nMos == -1) continue;1625 1626 // XXX how can this not be true?1627 if (mosaic[nMos].photcode != ecode) {1628 fprintf (stderr, "*");1629 }1630 1631 assert (Ns >= 0);1632 assert (Ns < Nphotcodes);1633 1634 // accumulate the offsets from the negative cloud images (others have 0.0 value)1635 starOffset[Nstars][Ns] += imageOffset[nMos];1636 starNcount[Nstars][Ns] ++;1637 1638 // record the mosaic->star reference1639 Slist[nMos][NSlist[nMos]] = Nstars;1640 NSlist[nMos] ++;1641 if (NSlist[nMos] == NSLIST[nMos]) {1642 NSLIST[nMos] += 100;1643 REALLOCATE (Slist[nMos], int, NSLIST[nMos]);1644 }1645 }1646 Nstars ++;1647 if (Nstars == NSTARS) {1648 NSTARS += 1000;1649 REALLOCATE (starOffset, double *, NSTARS);1650 REALLOCATE (starNcount, int *, NSTARS);1651 memset (&starOffset[NSTARS-1000], 0, 1000*sizeof(double *));1652 memset (&starNcount[NSTARS-1000], 0, 1000*sizeof(int *));1653 }1654 }1655 }1656 1657 // find the mean offset of the images without negative clouds1658 for (i = 0; i < Nmosaic; i++) {1659 1660 found = FALSE;1661 for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) {1662 if (mosaic[i].photcode == photcodes[Ns][0].code) {1663 found = TRUE;1664 break;1665 }1666 }1667 if (!found) {1668 fprintf (stderr, "invalid photcode for mosaic?\n");1669 abort();1670 }1671 1672 // a negative cloud image (cloud: McalPSF > 0; anti-clouds: McalPSF < 0; imageOffset = -McalPSF)1673 if (imageOffset[i] > 0.0) continue;1674 1675 // we need to actually have cross-references to count1676 if (NSlist[i] < 2) continue;1677 1678 float dM = 0.0;1679 for (j = 0; j < NSlist[i]; j++) {1680 k = Slist[i][j];1681 if (starNcount[k][Ns] > 1) {1682 dM += (starOffset[k][Ns] / starNcount[k][Ns]);1683 }1684 }1685 imageOffset[i] = dM / NSlist[i];1686 // fprintf (stderr, "adjust image: %s : (%f %d) : %f\n", image[MosaicToImage[i][0]].name, dM, NSlist[i], imageOffset[i]);1687 }1688 1689 // for (i = 0; i < Nmosaic; i++) {1690 // fprintf (stderr, "correction: %s : %f\n", image[MosaicToImage[i][0]].name, imageOffset[i]);1691 // }1692 1693 // apply all offset values to the mosaics1694 // find the images / mosaics with negative clouds and save their offset1695 for (i = 0; i < Nmosaic; i++) {1696 mosaic[i].McalPSF += imageOffset[i];1697 }1698 1699 for (i = 0; i < Nstars; i++) {1700 free (starOffset[i]);1701 free (starNcount[i]);1702 }1703 free (starOffset);1704 free (starNcount);1705 1706 free (seclist);1707 free (NSlist);1708 free (NSLIST);1709 for (i = 0; i < Nmosaic; i++){1710 free (Slist[i]);1711 }1712 free (Slist);1713 free (imageOffset);1714 return (TRUE);1715 1332 } 1716 1333 … … 1731 1348 n = 0; 1732 1349 for (i = 0; i < Nmosaic; i++) { 1733 if (mosaic[i].flags & IMAGE_BAD) continue;1350 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1734 1351 if (mosaic[i].skipCal) continue; 1735 1352 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1764 1381 n = 0; 1765 1382 for (i = 0; i < Nmosaic; i++) { 1766 if (mosaic[i].flags & IMAGE_BAD) continue;1383 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1767 1384 if (mosaic[i].skipCal) continue; 1768 1385 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1781 1398 } 1782 1399 1783 StatType statsMosaicN (Catalog *catalog , FlatCorrectionTable *flatcorr) {1400 StatType statsMosaicN (Catalog *catalog) { 1784 1401 1785 1402 off_t i, j, m, c, n, N; … … 1797 1414 n = 0; 1798 1415 for (i = 0; i < Nmosaic; i++) { 1799 if (mosaic[i].flags & IMAGE_BAD) continue;1416 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1800 1417 if (mosaic[i].skipCal) continue; 1801 1418 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1811 1428 Mgrp = getMgrp (m, c, catalog[c].measureT[m].airmass, NULL); 1812 1429 if (isnan(Mgrp)) continue; 1813 Mgrid = getMgrid (m, c);1430 Mgrid = getMgridTiny (&catalog[c].measureT[m]); 1814 1431 if (isnan(Mgrid)) continue; 1815 1432 Mrel = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); … … 1847 1464 n = 0; 1848 1465 for (i = 0; i < Nmosaic; i++) { 1849 if (mosaic[i].flags & IMAGE_BAD) continue;1466 if (mosaic[i].flags & (ID_IMAGE_MOSAIC_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1850 1467 if (mosaic[i].skipCal) continue; 1851 1468 if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue; … … 1866 1483 /* mark mosaic if: abs(Mcal - <Mcal>) too large, dMcal too large */ 1867 1484 1868 static float MinMaxChiSq = NAN; 1869 static float MinMaxScatter = NAN; 1485 static float MinChiSqLim = NAN; 1486 static float MaxChiSqLim = NAN; 1487 static float MinScatterLim = NAN; 1488 static float MaxScatterLim = NAN; 1870 1489 1871 1490 void clean_mosaics () { … … 1877 1496 1878 1497 if (VERBOSE) fprintf (stderr, "marking poor mosaics\n"); 1498 1499 if (isnan (MaxChiSqLim)) MaxChiSqLim = MOSAIC_CHISQ; 1500 if (isnan (MaxScatterLim)) MaxScatterLim = MOSAIC_SCATTER; 1879 1501 1880 1502 ALLOCATE (mlist, double, Nmosaic); … … 1899 1521 liststats (mlist, NULL, NULL, N, &stats); 1900 1522 float ChiSqUpper90 = stats.Upper90; 1901 if (isnan (Min MaxChiSq)) MinMaxChiSq = 2.0*stats.median;1902 float MaxChiSq = MAX (MinMaxChiSq, ChiSqUpper90);1523 if (isnan (MinChiSqLim)) MinChiSqLim = 2.0*stats.median; // chi-square cut cannot fall below this value (even if this is > MaxChiSqLim) 1524 float ChiSqLimit = MAX(MinChiSqLim, MIN(MaxChiSqLim, ChiSqUpper90)); // chi-square cut should be between MinChiSqLim and MaxChiSqLim 1903 1525 1904 1526 liststats (slist, NULL, NULL, N, &stats); 1905 1527 float ScatterUpper90 = stats.Upper90; 1906 if (isnan (Min MaxScatter)) MinMaxScatter = 2.0*stats.median;1907 float MaxScatter = MAX (MinMaxScatter, ScatterUpper90);1908 1909 fprintf (stderr, "MOSAIC: Max ChiSq: %f, Max Scatter: %f | ChiSquare Upper 90: %f, Scatter Upper 90: %f\n", MaxChiSq, MaxScatter, ChiSqUpper90, ScatterUpper90);1528 if (isnan (MinScatterLim)) MinScatterLim = 2.0*stats.median; // scatter cut cannto fall below this value (even if this is > MaxScatterLim) 1529 float ScatterLimit = MAX(MinScatterLim, MIN(MaxScatterLim, ScatterUpper90)); 1530 1531 fprintf (stderr, "MOSAIC: ChiSqLimit: %f, ScatterLimit: %f | ChiSquare Upper 90: %f, Scatter Upper 90: %f\n", ChiSqLimit, ScatterLimit, ChiSqUpper90, ScatterUpper90); 1910 1532 1911 1533 int Ntotal = 0, Npoor = 0, Nmark = 0, Nscatter = 0, Nfew = 0, Nchisq = 0; … … 1930 1552 Nfew ++; 1931 1553 } 1932 if (mosaic[i].stdev > MaxScatter) {1554 if (mosaic[i].stdev > ScatterLimit) { 1933 1555 mark = TRUE; 1934 1556 Nscatter ++; 1935 1557 } 1936 if (mosaic[i].McalChiSq > MaxChiSq) {1558 if (mosaic[i].McalChiSq > ChiSqLimit) { 1937 1559 mark = TRUE; 1938 1560 Nchisq ++; … … 1979 1601 c = MosaicToCatalog[i][j]; 1980 1602 1981 if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;1603 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) continue; 1982 1604 1983 1605 // ave = catalog[c].measureT[m].averef; -
trunk/Ohana/src/relphot/src/Shutdown.c
r38986 r41647 10 10 int Shutdown (char *format, ...) { 11 11 va_list argp; 12 char *formatplus;12 char formatplus[1024]; 13 13 14 ALLOCATE (formatplus, char, strlen(format));15 strcpy (formatplus, format);16 s trcat (formatplus, "\n");14 // we cannot allocate this with the ohana allocation tools 15 // because it could deadlock 16 snprintf (formatplus, 1024, "%s\n", format); 17 17 18 18 va_start (argp, format); 19 19 vfprintf (stderr, formatplus, argp); 20 free (formatplus);21 20 va_end (argp); 22 21 -
trunk/Ohana/src/relphot/src/StarOps.c
r41556 r41647 1 1 # include "relphot.h" 2 3 # define STAR_BAD (ID_SECF_STAR_FEW | ID_SECF_STAR_POOR) 2 4 3 5 enum {THREAD_RUN, THREAD_DONE}; … … 8 10 Catalog *catalog; 9 11 int Ncatalog; 10 FlatCorrectionTable *flatcorr;11 12 SetMrelInfo summary; 12 13 } ThreadInfo; … … 14 15 // ** internal functions: 15 16 void *setMrel_worker (void *data); 16 int setMrel_threaded (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr); 17 int setMrel_catalog (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt); 17 int setMrel_threaded (Catalog *catalog, int Ncatalog); 18 18 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure); 19 19 … … 292 292 293 293 // setMrel and setMrelOutput are extremely similar, but have slightly different implications: 294 // * setMrel uses the internal Tiny structures only 295 // * setMrelOutput skips stars for which there are too few good measurements 296 // * setMrelOutput is meant to be called repeatedly, relaxing the criteria for 'good' on each pass 294 // * both call setMrelCatalog, but setMrel set isSetMrelFinal to FALSE 295 // * setMrel only uses the internal Tiny structures 296 // * setMrel skips stars for which there are too few good measurements 297 // -> (setMrelOutput assigns an average mag for all objects, even those with only 1 measurement) 298 // * setMrelOutput sets psfQF, psfQFperf, extNsigma, rank info, etc 299 // * setMrelOutput sets average Map 297 300 // * setMrelOutput updates 2MASS average flags 298 301 // * setMrelOutput updates average EXT flags (PS1 and 2MASS) 299 300 int setMrel (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr) { 302 // * setMrelOutput sets average stack & warp photometry (if requested), setMrel always skips those 303 // * setMrelOutput is NOT threaded it reads/writes catalogs one at a time 304 305 int setMrel (Catalog *catalog, int Ncatalog) { 301 306 302 307 int i; 303 308 304 309 if (NTHREADS) { 305 int status = setMrel_threaded (catalog, Ncatalog , flatcorr);310 int status = setMrel_threaded (catalog, Ncatalog); 306 311 return status; 307 312 } … … 314 319 315 320 for (i = 0; i < Ncatalog; i++) { 316 setMrel _catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);321 setMrelCatalog (catalog, i, FALSE, &results, Nsecfilt); 317 322 SetMrelInfoAccum (&summary, &results); 318 323 } … … 325 330 } 326 331 327 // setMrelOutput is NOT threaded because we read/write catalogs one at a time (for now) 328 int setMrelOutput (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr) { 332 int setMrelOutput (Catalog *catalog, int Ncatalog) { 329 333 330 334 int i; … … 337 341 338 342 for (i = 0; i < Ncatalog; i++) { 339 setMrel _catalog_alt (catalog, i, TRUE, flatcorr, &results, Nsecfilt);343 setMrelCatalog (catalog, i, TRUE, &results, Nsecfilt); 340 344 SetMrelInfoAccum (&summary, &results); 341 345 } … … 347 351 } 348 352 349 int setMrel_threaded (Catalog *catalog, int Ncatalog , FlatCorrectionTable *flatcorr) {353 int setMrel_threaded (Catalog *catalog, int Ncatalog) { 350 354 351 355 int i; … … 374 378 threadinfo[i].catalog = catalog; 375 379 threadinfo[i].Ncatalog = Ncatalog; 376 threadinfo[i].flatcorr = flatcorr;377 380 SetMrelInfoInit (&threadinfo[i].summary, FALSE); 378 381 pthread_create (&threads[i], NULL, setMrel_worker, &threadinfo[i]); … … 435 438 436 439 Catalog *catalog = threadinfo->catalog; 437 FlatCorrectionTable *flatcorr = threadinfo->flatcorr; 438 439 setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt); 440 441 setMrelCatalog (catalog, i, FALSE, &results, Nsecfilt); 440 442 SetMrelInfoAccum (&threadinfo->summary, &results); 441 443 } … … 444 446 return NULL; 445 447 } 446 447 # define SKIP_THIS_MEAS(REASON) { \448 catalog[Nc].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM; \449 if (catalog[Nc].measure) { \450 catalog[Nc].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM; \451 } \452 results->REASON ++; \453 continue; }454 455 448 456 449 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure) { … … 473 466 } 474 467 475 /* set measure.Mcal for all measures except ID_MEAS_NOCAL and ID_IMAGE_PHOTOM_NOCAL*/476 int setMcalOutput (Catalog *catalog, int Ncatalog , FlatCorrectionTable *flatcorr) {468 /* set measure.Mcal for all measures except ID_MEAS_NOCAL */ 469 int setMcalOutput (Catalog *catalog, int Ncatalog) { 477 470 478 471 int i; 479 472 off_t j, k, m; 480 473 481 MEAS_BAD = ID_MEAS_NOCAL;482 IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;483 484 474 for (i = 0; i < Ncatalog; i++) { 485 475 for (j = 0; j < catalog[i].Naverage; j++) { … … 487 477 m = catalog[i].averageT[j].measureOffset; 488 478 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 489 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;479 if (catalog[i].measureT[m].dbFlags & ID_MEAS_NOCAL) continue; 490 480 float McalPSF = getMcal (m, i, MAG_CLASS_PSF); 491 481 float McalAPER = getMcal (m, i, MAG_CLASS_APER); 492 482 if (isnan(McalPSF)) continue; 493 float Mmos = getMmos (m, i); 494 if (isnan(Mmos)) continue; 495 float Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL); 496 if (isnan(Mgrp)) continue; 497 float Mgrid = getMgrid (m, i); 498 if (isnan(Mgrid)) continue; 483 484 // Mmos, Mgrp have already been transfered to Mcal and should be zero here 485 // float Mmos = getMmos (m, i); 486 // if (isnan(Mmos)) continue; 487 // float Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL); 488 // if (isnan(Mgrp)) continue; 489 490 // Mgrid is applied to Mflat and should be ignored here 491 // float Mgrid = getMgridTiny (&catalog[i].measureT[m]); 492 // if (isnan(Mgrid)) continue; 499 493 500 494 // Note that this operation is setting measure->McalAPER to image->McalAPER only … … 509 503 510 504 // set the output calibration 511 // float Moff = Mmos + Mgrp + Mgrid; 512 float Moff = Mmos + Mgrid; // Mgrp has already been applied to the image.Mcal 513 catalog[i].measure[m].McalPSF = McalPSF + Moff; 514 catalog[i].measure[m].McalAPER = useStackAper ? McalAPER + Moff : McalPSF + Moff; 505 catalog[i].measure[m].McalPSF = McalPSF; 506 catalog[i].measure[m].McalAPER = useStackAper ? McalAPER : McalPSF; 515 507 516 508 if (catalog[i].measureT[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { … … 584 576 } 585 577 578 static float MinChiSqLim = NAN; 579 static float MaxChiSqLim = NAN; 580 static float MinScatterLim = NAN; 581 static float MaxScatterLim = NAN; 582 586 583 void clean_stars (Catalog *catalog, int Ncatalog) { 587 584 588 int i, j, Ndel, Nave, Ntot, mark, Ns, Nscat, Nchi, Nnan; 589 float dM; 590 double MaxScatter, MaxChisq; 591 double *xlist, *slist, *dlist; 585 int Ndel, Nave, Ntot, Nscat, Nchi, Nnan; 586 double *xlist, *slist; 587 588 if (isnan (MaxChiSqLim)) MaxChiSqLim = STAR_CHISQ; 589 if (isnan (MaxScatterLim)) MaxScatterLim = STAR_SCATTER; 592 590 593 591 StatType stats; … … 597 595 598 596 /* find Mchisq median -> ChiSq lim must be > median */ 599 for (i = Ntot = 0; i < Ncatalog; i++) {597 for (int i = Ntot = 0; i < Ncatalog; i++) { 600 598 Ntot += catalog[i].Naverage; 601 599 } 602 600 ALLOCATE (xlist, double, Ntot); 603 601 ALLOCATE (slist, double, Ntot); 604 ALLOCATE (dlist, double, Ntot);605 602 606 603 int Nsecfilt = GetPhotcodeNsecfilt (); 607 604 608 605 // eliminate bad stars using the stats for a single secfilt at a time 609 for ( Ns = 0; Ns < Nphotcodes; Ns ++) {606 for (int Ns = 0; Ns < Nphotcodes; Ns ++) { 610 607 611 608 int thisCode = photcodes[Ns][0].code; 612 609 int Nsec = GetPhotcodeNsec(thisCode); 613 610 614 for (i = Ntot = 0; i < Ncatalog; i++) {615 for ( j = 0; j < catalog[i].Naverage; j++) {616 if ( catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;611 for (int i = Ntot = 0; i < Ncatalog; i++) { 612 for (int j = 0; j < catalog[i].Naverage; j++) { 613 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 617 614 float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq; 618 615 if (isnan(Mchisq)) continue; 619 616 xlist[Ntot] = Mchisq; 620 617 slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp; 621 dlist[Ntot] = 1;622 618 Ntot ++; 623 619 } 624 620 } 625 626 liststats (xlist, dlist, NULL, Ntot, &stats); 627 MaxChisq = MAX (STAR_CHISQ, 2*stats.median); 628 629 liststats (slist, dlist, NULL, Ntot, &stats); 630 MaxScatter = MAX (STAR_SCATTER, 2*stats.median); 631 fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq); 621 622 liststats (xlist, NULL, NULL, Ntot, &stats); 623 float ChiSqUpper90 = stats.Upper90; 624 if (isnan (MinChiSqLim)) MinChiSqLim = 2.0*stats.median; // chi-square cut cannot fall below this value (even if this is > MaxChiSqLim) 625 float ChiSqLimit = MAX(MinChiSqLim, MIN(MaxChiSqLim, ChiSqUpper90)); // chi-square cut should be between MinChiSqLim and MaxChiSqLim 626 627 liststats (slist, NULL, NULL, Ntot, &stats); 628 float ScatterUpper90 = stats.Upper90; 629 if (isnan (MinScatterLim)) MinScatterLim = 2.0*stats.median; // scatter cut cannto fall below this value (even if this is > MaxScatterLim) 630 float ScatterLimit = MAX(MinScatterLim, MIN(MaxScatterLim, ScatterUpper90)); 631 632 fprintf (stderr, "STARS: ChiSqLimit: %f, ScatterLimit: %f | ChiSquare Upper 90: %f, Scatter Upper 90: %f\n", ChiSqLimit, ScatterLimit, ChiSqUpper90, ScatterUpper90); 632 633 633 634 Ndel = Nave = Nscat = Nnan = Nchi = 0; 634 for (i = 0; i < Ncatalog; i++) {635 for ( j = 0; j < catalog[i].Naverage; j++) {636 dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp;635 for (int i = 0; i < Ncatalog; i++) { 636 for (int j = 0; j < catalog[i].Naverage; j++) { 637 float dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp; 637 638 float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq; 638 mark = (dM > MaxScatter) || (isnan(Mchisq)) || (Mchisq > MaxChisq);639 int mark = (dM > ScatterLimit) || (isnan(Mchisq)) || (Mchisq > ChiSqLimit); 639 640 if (mark) { 640 catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_ OBJ_POOR;641 catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_SECF_STAR_POOR; 641 642 Ndel ++; 642 if (dM > MaxScatter) { Nscat ++; }643 if (isnan(Mchisq)) { Nnan ++; }644 if (Mchisq > MaxChisq) { Nchi ++; }643 if (dM > ScatterLimit) { Nscat ++; } 644 if (isnan(Mchisq)) { Nnan ++; } 645 if (Mchisq > ChiSqLimit) { Nchi ++; } 645 646 } else { 646 catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_ OBJ_POOR;647 catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_SECF_STAR_POOR; 647 648 } 648 649 Nave ++; 649 650 } 650 651 } 651 fprintf (stderr, "%d stars marked variable (%d scat, %d nan, %d chi), %d total\n", Ndel, Nscat, Nnan, Nchi, Nave);652 fprintf (stderr, "%d of %d stars marked variable (%d scat, %d nan, %d chi)\n", Ndel, Nave, Nscat, Nnan, Nchi); 652 653 } 653 654 free (xlist); 654 655 free (slist); 655 free (dlist); 656 } 657 658 // clean_measures examines the stats for a single star. It measures the INNER 50% mean 659 // and sigma, it then re-measures the mean and sigma using all stars with NSIGMA_CLIP (3) 660 // sigma of the INNER 50% mean. it then flags any measurements which are more than 661 // NSIGMA_REJECT (5) sigma of the mean 662 663 // this function only operations on the PSF magnitudes 664 665 // XXX EAM clean_measures is no longer used -- we rely on IRLS to down-weight outliers 666 667 # define NSIGMA_CLIP 3.0 668 # define NSIGMA_REJECT 5.0 669 void clean_measures (Catalog *catalog, int Ncatalog, int final, FlatCorrectionTable *flatcorr) { 670 671 off_t j, k, m, Nmax, Ndel, Nave; 672 int i, N, image_bad, TOOFEW; 673 off_t *ilist; 674 double *tlist, *list, *dlist; 675 float Msys, Mcal, Mmos, Mgrp, Mgrid; 676 int Ncal, Nmos, Ngrp, Ngrid, Nfew; 677 678 int Nsecfilt = GetPhotcodeNsecfilt (); 679 680 if (VERBOSE) fprintf (stderr, "marking poor measures\n"); 681 /* Nmeasure is now different, need to reallocate */ 682 Nmax = 0; 683 for (i = 0; i < Ncatalog; i++) { 684 for (j = 0; j < catalog[i].Naverage; j++) { 685 Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure); 686 } 687 } 688 ALLOCATE (list, double, MAX (1, Nmax)); 689 ALLOCATE (dlist, double, MAX (1, Nmax)); 690 ALLOCATE (ilist, off_t, Nmax); 691 ALLOCATE (tlist, double, Nmax); 692 693 /* it makes no sense to mark 3-sigma outliers with <5 measurements */ 694 TOOFEW = MAX (5, STAR_TOOFEW); 695 696 // stats structures for inner and full stats 697 StatType instats, stats; 698 liststats_setmode (&instats, "INNER_MEAN"); 699 liststats_setmode (&stats, "MEAN"); 700 701 Ndel = Nave = 0; 702 Ncal = Nmos = Ngrp = Ngrid = Nfew = 0; 703 for (i = 0; i < Ncatalog; i++) { 704 for (j = 0; j < catalog[i].Naverage; j++) { 705 706 int Ns; 707 for (Ns = 0; Ns < Nphotcodes; Ns++) { 708 709 int thisCode = photcodes[Ns][0].code; 710 int Nsec = GetPhotcodeNsec(thisCode); 711 712 /* on final processing, skip stars already measured */ 713 if (final && catalog[i].found_t[Nsecfilt*j + Nsec]) continue; 714 715 /* skip bad stars to prevent them from becoming good (on inner sample) */ 716 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 717 718 /* accumulate list of valid measurements */ 719 m = catalog[i].averageT[j].measureOffset; 720 N = 0; 721 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 722 // skip measurements that do not match the current photcode 723 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 724 if (ecode != thisCode) { continue; } 725 726 // SKIP gpc1 stack data 727 if (isGPC1stack(catalog[i].measureT[m].photcode)) continue; 728 729 // SKIP gpc1 forced-warp data 730 if (isGPC1warp(catalog[i].measureT[m].photcode)) continue; 731 732 // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers 733 Mcal = getMcal (m, i, MAG_CLASS_PSF); 734 if (isnan(Mcal)) { Ncal ++; continue; } 735 Mmos = getMmos (m, i); 736 if (isnan(Mmos)) { Nmos ++; continue; } 737 Mgrp = getMgrp (m, i, catalog[i].measureT[m].airmass, NULL); 738 if (isnan(Mgrp)) { Ngrp ++; continue; } 739 Mgrid = getMgrid (m, i); 740 if (isnan(Mgrid)) { Ngrid ++; continue; } 741 742 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF); 743 list[N] = Msys - Mcal - Mmos - Mgrp - Mgrid; 744 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR); 745 N++; 746 } 747 if (N <= TOOFEW) { 748 Nfew ++; 749 continue; 750 } 751 752 /* 3-sigma clip based on stats of inner 50% */ 753 754 // calculated mean of inner 50% 755 liststats (list, dlist, NULL, N, &instats); 756 instats.sigma = MAX (MIN_ERROR, instats.sigma); /* if measurements agree too well, sigma -> 0.0 */ 757 758 // ignore entries > 3sigma from inner mean 759 for (k = m = 0; k < N; k++) { 760 if (fabs (list[k] - instats.median) < NSIGMA_CLIP*instats.sigma) { 761 list[m] = list[k]; 762 m++; 763 } 764 } 765 // recalculate the mean & sigma of the accepted measurements 766 liststats (list, dlist, NULL, m, &stats); 767 stats.sigma = MAX (MIN_ERROR, stats.sigma); 768 769 /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */ 770 image_bad = IMAGE_BAD; 771 IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL; 772 m = catalog[i].averageT[j].measureOffset; 773 N = 0; 774 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 775 // skip measurements that do not match the current photcode 776 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 777 if (ecode != thisCode) { continue; } 778 779 // SKIP gpc1 stack data 780 if (isGPC1stack(catalog[i].measureT[m].photcode)) continue; 781 782 // SKIP gpc1 forced-warp data 783 if (isGPC1warp(catalog[i].measureT[m].photcode)) continue; 784 785 // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers 786 Mcal = getMcal (m, i, MAG_CLASS_PSF); 787 if (isnan(Mcal)) continue; 788 Mmos = getMmos (m, i); 789 if (isnan(Mmos)) continue; 790 Mgrid = getMgrid (m, i); 791 if (isnan(Mgrid)) continue; 792 793 Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF); 794 list[N] = Msys - Mcal - Mmos - Mgrid; 795 dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR); 796 ilist[N] = m; 797 N++; 798 Nave ++; 799 } 800 if (N < TOOFEW) continue; 801 802 /* mark bad measures (> 5 sigma deviant) */ 803 for (k = 0; k < N; k++) { 804 // treat the scatter of the star as a systematic term. this is a bit of an 805 // over-estimage (a perfect Gauss distribution with perfect errors would have 806 // mySigma = sqrt(2) too large) 807 float mySigma = hypot (stats.sigma, dlist[k]); 808 if (fabs (list[k] - stats.median) > NSIGMA_REJECT*mySigma) { 809 catalog[i].measureT[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM; 810 if (final) { 811 // for the final pass, we have a duplicate set of values in measure and measureT 812 catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM; 813 } 814 Ndel ++; 815 } else { 816 catalog[i].measureT[ilist[k]].dbFlags &= ~ID_MEAS_POOR_PHOTOM; 817 if (final) { 818 // for the final pass, we have a duplicate set of values in measure and measureT 819 catalog[i].measure[ilist[k]].dbFlags &= ~ID_MEAS_POOR_PHOTOM; 820 } 821 } 822 } 823 IMAGE_BAD = image_bad; 824 } 825 } 826 } 827 if (VERBOSE) fprintf (stderr, OFF_T_FMT" measures marked poor, "OFF_T_FMT" total\n", Ndel, Nave); 828 829 free (list); 830 free (dlist); 831 free (ilist); 832 free (tlist); 833 } 834 835 StatType statsStarN (Catalog *catalog, int Ncatalog, int Nsec, int seccode, FlatCorrectionTable *flatcorr) { 656 } 657 658 StatType statsStarN (Catalog *catalog, int Ncatalog, int Nsec, int seccode) { 836 659 837 660 off_t j, k, m, Ntot; … … 869 692 Mmos = getMmos (m, i); 870 693 if (isnan(Mmos)) { continue; } 871 Mgrid = getMgrid (m, i);694 Mgrid = getMgridTiny (&catalog[i].measureT[m]); 872 695 if (isnan(Mgrid)) { continue;} 873 696 N++; … … 1105 928 1106 929 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude 1107 // float Mgrid = getMgrid (m, c); // camera offset (deprecated?)1108 // float Mflat = getMflat (m, c, flatcorr,catalog); // flat-field correction930 // float Mgrid = getMgridTiny (&catalog[c].measureT[m]); // camera offset (deprecated?) 931 // float Mflat = getMflat (m, c, catalog); // flat-field correction 1109 932 1110 933 off_t n = catalog[c].measureT[m].averef; … … 1121 944 fclose (fout); 1122 945 } 946 947 // maybe make this a macro 948 float getMflat (off_t meas, int cat, Catalog *catalog) { 949 float offset = catalog[cat].measureT[meas].Mflat; 950 if (!isfinite(offset)) { 951 offset = 0.0; 952 } 953 return (offset); 954 } -
trunk/Ohana/src/relphot/src/TGroupOps.c
r41562 r41647 2 2 3 3 void assignMosaicsToTGroups (void); 4 int save_test_night_measures (FILE *fout, TGroup *myTGroup, Catalog *catalog , FlatCorrectionTable *flatcorr);4 int save_test_night_measures (FILE *fout, TGroup *myTGroup, Catalog *catalog); 5 5 6 6 // tgroupTimes carries the times of the tgroups (initially, just the photometric nights) … … 647 647 Catalog *catalog; 648 648 Image *image; 649 FlatCorrectionTable *flatcorr;650 649 SetMgrpInfo info; 651 650 } ThreadInfo; 652 651 653 int setMgrp_tgroup (TGroup *tgroup, off_t Nmos, Image *image, Catalog *catalog, SetMgrpInfo *info , FlatCorrectionTable *flatcorr);652 int setMgrp_tgroup (TGroup *tgroup, off_t Nmos, Image *image, Catalog *catalog, SetMgrpInfo *info); 654 653 void *setMgrp_worker (void *data); 655 int setMgrp_threaded (Catalog *catalog , FlatCorrectionTable *flatcorr);654 int setMgrp_threaded (Catalog *catalog); 656 655 657 656 void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists) { … … 727 726 } 728 727 729 int setMgrp (Catalog *catalog , FlatCorrectionTable *flatcorr) {728 int setMgrp (Catalog *catalog) { 730 729 731 730 off_t N; … … 738 737 // so do not run setMgrp in threaded mode if PLOTSTUFF is set 739 738 if (NTHREADS && !PLOTSTUFF) { 740 int status = setMgrp_threaded (catalog , flatcorr);739 int status = setMgrp_threaded (catalog); 741 740 return status; 742 741 } … … 758 757 TGroup *tgroup = tgroupTimes[i][0].byCode; 759 758 for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) { 760 setMgrp_tgroup (&tgroup[j], i, image, catalog, &info , flatcorr);759 setMgrp_tgroup (&tgroup[j], i, image, catalog, &info); 761 760 // fprintf (stderr, "TGROUP time %.0f photcode %d Mcal: %f, dK: %f, dMcal: %f, sigma: %f, chisq: %f, %d of %d, limiting negative clouds to %f\n", 762 761 // ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode, tgroup[j].McalPSF, tgroup[j].dKlam, tgroup[j].dMcal, tgroup[j].stdev, tgroup[j].McalChiSq, tgroup[j].nFitPhotom, tgroup[j].nValPhotom, CLOUD_TOLERANCE); … … 781 780 782 781 // 'tgroup' is a pointer to the current tgroup of interest (entry Ngrp) 783 int setMgrp_tgroup (TGroup *myTGroup, off_t Ngrp, Image *image, Catalog *catalog, SetMgrpInfo *info , FlatCorrectionTable *flatcorr) {782 int setMgrp_tgroup (TGroup *myTGroup, off_t Ngrp, Image *image, Catalog *catalog, SetMgrpInfo *info) { 784 783 785 784 off_t j; … … 826 825 fout = fopen (filename, "w"); 827 826 fprintf (fout, "# tgroup %s (%.0f)\n", ohana_sec_to_date(tgroup->start), mjdStart); 828 save_test_night_measures (fout, myTGroup, catalog , flatcorr);827 save_test_night_measures (fout, myTGroup, catalog); 829 828 fclose (fout); 830 829 } … … 853 852 continue; 854 853 } 855 float Mgrid = getMgrid (m, c);854 float Mgrid = getMgridTiny (&catalog[c].measureT[m]); 856 855 if (isnan(Mgrid)) { 857 856 info->Ngrid ++; … … 875 874 // apply that offset as well here for this image (in other words, each detection is 876 875 // being compared to the model, excluding the zero point, Mcal. The model includes 877 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat) 878 879 float Mflat = getMflat (m, c, flatcorr, catalog); 876 // the flat-correction. NOTE the sign of Mflat (Image.Mcal = Measure.Mcal + Mflat) 877 // this was inconsistent with PhotRel pre-r41606 878 879 float Mflat = getMflat (m, c, catalog); 880 880 881 881 off_t n = catalog[c].measureT[m].averef; … … 900 900 assert (Nbright >= 0); 901 901 902 float Moff = Mcal + Mmos + Mgrid -Mflat;902 float Moff = Mcal + Mmos + Mgrid + Mflat; 903 903 904 904 psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Moff; … … 1000 1000 } 1001 1001 1002 int save_test_night_measures (FILE *fout, TGroup *myTGroup, Catalog *catalog , FlatCorrectionTable *flatcorr) {1002 int save_test_night_measures (FILE *fout, TGroup *myTGroup, Catalog *catalog) { 1003 1003 1004 1004 int Nsecfilt = GetPhotcodeNsecfilt (); … … 1013 1013 float Mmos = getMmos (m, c); // mosaic zero point 1014 1014 1015 float Mgrid = getMgrid (m, c); // camera offset (deprecated?)1015 float Mgrid = getMgridTiny (&catalog[c].measureT[m]); // camera offset (deprecated?) 1016 1016 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude 1017 float Mflat = getMflat (m, c, flatcorr,catalog); // flat-field correction1017 float Mflat = getMflat (m, c, catalog); // flat-field correction 1018 1018 1019 1019 off_t n = catalog[c].measureT[m].averef; … … 1023 1023 1024 1024 // for historical reasons, Mflat is defined with the wrong sign 1025 float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrid +Mflat - myTGroup->McalPSF;1025 float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrid - Mflat - myTGroup->McalPSF; 1026 1026 1027 1027 int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD); … … 1037 1037 } 1038 1038 1039 int setMgrp_threaded (Catalog *catalog , FlatCorrectionTable *flatcorr) {1039 int setMgrp_threaded (Catalog *catalog) { 1040 1040 1041 1041 int i; … … 1075 1075 threadinfo[i].catalog = catalog; 1076 1076 threadinfo[i].image = image; 1077 threadinfo[i].flatcorr = flatcorr;1078 1077 1079 1078 // we do NOT allocate the arrays here, we only supply basic info used in the threads … … 1124 1123 free (threadinfo); 1125 1124 1125 // XXX not allocated SetMgrpInfoFree (&summary); 1126 1126 1127 npass_output ++; 1127 1128 … … 1145 1146 1146 1147 Catalog *catalog = threadinfo->catalog; 1147 FlatCorrectionTable *flatcorr = threadinfo->flatcorr;1148 1148 Image *image = threadinfo->image; 1149 1149 1150 1150 TGroup *tgroup = tgroupTimes[i][0].byCode; 1151 1151 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1152 setMgrp_tgroup (&tgroup[j], i, image, catalog, &results , flatcorr);1152 setMgrp_tgroup (&tgroup[j], i, image, catalog, &results); 1153 1153 SetMgrpInfoAccum (&threadinfo->info, &results); 1154 1154 } … … 1172 1172 ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes); 1173 1173 1174 int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW;1175 1176 1174 int n = 0; 1177 1175 for (int i = 0; i < NtgroupTimes; i++) { 1178 1176 TGroup *tgroup = tgroupTimes[i][0].byCode; 1179 1177 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1180 if (tgroup[j].flags & NIGHT_BAD) continue;1178 if (tgroup[j].flags & (ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1181 1179 list[n] = tgroup[j].McalPSF; 1182 1180 dlist[n] = 1; … … 1209 1207 TGroup *tgroup = tgroupTimes[i][0].byCode; 1210 1208 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1211 if (tgroup[j].flags & IMAGE_BAD) continue;1209 if (tgroup[j].flags & (ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1212 1210 list[n] = tgroup[j].dMcal; 1213 1211 dlist[n] = 1; … … 1240 1238 TGroup *tgroup = tgroupTimes[i][0].byCode; 1241 1239 for (int j = 0; j < tgroupTimes[i][0].nCode; j++) { 1242 if (tgroup[j].flags & IMAGE_BAD) continue;1240 if (tgroup[j].flags & (ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW)) continue; 1243 1241 list[n] = tgroup[j].McalChiSq; 1244 1242 dlist[n] = 1; … … 1267 1265 */ 1268 1266 1269 static float MinMaxChiSq = NAN; 1270 static float MinMaxScatter = NAN; 1267 static float MinChiSqLim = NAN; 1268 static float MaxChiSqLim = NAN; 1269 static float MinScatterLim = NAN; 1270 static float MaxScatterLim = NAN; 1271 1271 1272 1272 void clean_tgroups () { … … 1277 1277 1278 1278 if (VERBOSE) fprintf (stderr, "marking poor tgroups\n"); 1279 1280 if (isnan (MaxChiSqLim)) MaxChiSqLim = NIGHT_CHISQ; 1281 if (isnan (MaxScatterLim)) MaxScatterLim = NIGHT_SCATTER; 1279 1282 1280 1283 ALLOCATE (mlist, double, NtgroupTimes*Nphotcodes); … … 1300 1303 liststats (mlist, NULL, NULL, N, &stats); 1301 1304 float ChiSqUpper90 = stats.Upper90; 1302 if (isnan (Min MaxChiSq)) MinMaxChiSq = 2.0*stats.median;1303 float MaxChiSq = MAX (MinMaxChiSq, ChiSqUpper90);1305 if (isnan (MinChiSqLim)) MinChiSqLim = 2.0*stats.median; // chi-square cut cannot fall below this value (even if this is > MaxChiSqLim) 1306 float ChiSqLimit = MAX(MinChiSqLim, MIN(MaxChiSqLim, ChiSqUpper90)); // chi-square cut should be between MinChiSqLim and MaxChiSqLim 1304 1307 1305 1308 liststats (slist, NULL, NULL, N, &stats); 1306 1309 float ScatterUpper90 = stats.Upper90; 1307 if (isnan (Min MaxScatter)) MinMaxScatter = 2.0*stats.median;1308 float MaxScatter = MAX (MinMaxScatter, ScatterUpper90);1309 1310 fprintf (stderr, "TGROUPS: Max ChiSq: %f, Max Scatter: %f | ChiSquare Upper 90: %f, Scatter Upper 90: %f\n", MaxChiSq, MaxScatter, ChiSqUpper90, ScatterUpper90);1310 if (isnan (MinScatterLim)) MinScatterLim = 2.0*stats.median; // scatter cut cannto fall below this value (even if this is > MaxScatterLim) 1311 float ScatterLimit = MAX(MinScatterLim, MIN(MaxScatterLim, ScatterUpper90)); 1312 1313 fprintf (stderr, "TGROUPS: ChiSqLimit: %f, ScatterLimit: %f | ChiSquare Upper 90: %f, Scatter Upper 90: %f\n", ChiSqLimit, ScatterLimit, ChiSqUpper90, ScatterUpper90); 1311 1314 1312 1315 int Ntotal = 0, Npoor = 0, Nmark = 0, Nscatter = 0, Nchisq = 0, NfewNights = 0, NfewExp = 0; … … 1337 1340 } 1338 1341 // scatter too large 1339 if (tgroup[j].stdev > MaxScatter) {1342 if (tgroup[j].stdev > ScatterLimit) { 1340 1343 mark = TRUE; 1341 1344 Nscatter ++; 1342 1345 } 1343 1346 // chisq too large 1344 if (tgroup[j].McalChiSq > MaxChiSq) {1347 if (tgroup[j].McalChiSq > ChiSqLimit) { 1345 1348 mark = TRUE; 1346 1349 Nchisq ++; … … 1394 1397 c = tgroup[i].catalog[j]; 1395 1398 1396 if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;1399 if (catalog[c].measureT[m].dbFlags & MEAS_BAD) continue; 1397 1400 1398 1401 // ave = catalog[c].measureT[m].averef; … … 1501 1504 1502 1505 float MrelPSF = getMrel (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude 1503 // float Mgrid = getMgrid (m, c);// camera offset (deprecated?)1504 // float Mflat = getMflat (m, c, flatcorr, catalog); // flat-field correction1506 // float Mgrid = getMgridTiny (&catalog[c].measureT[m]); // camera offset (deprecated?) 1507 float Mflat = getMflat (m, c, catalog); // flat-field correction 1505 1508 1506 1509 off_t n = catalog[c].measureT[m].averef; … … 1510 1513 1511 1514 // for historical reasons, Mflat is defined with the wrong sign 1512 float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrp ;1515 float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrp - Mflat; 1513 1516 1514 1517 fprintf (fout, "%f %f : %f %f : %f %f %f : %f %f\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mmos, Mgrp, catalog[c].measureT[m].airmass, delta); -
trunk/Ohana/src/relphot/src/ZeroPointModes.c
r41598 r41647 22 22 } 23 23 24 void SetZeroPointModes ( void) {24 void SetZeroPointModes (Catalog *catalog, int Ncatalog) { 25 25 26 26 if (TGROUP_ZEROPT && MOSAIC_ZEROPT) { … … 49 49 clean_mosaics(); // do this on every pass 50 50 } 51 if ((CurrentLoop >= 18) && (CurrentLoop < = 999)) {51 if ((CurrentLoop >= 18) && (CurrentLoop < 21)) { 52 52 // after iterating a few times on the TGroup & Mosaic zero points: 53 53 // * identify the good / bad Mosaics … … 59 59 clean_mosaics(); // do this on every pass 60 60 clean_images(); // do this on every pass 61 clean_stars(catalog, Ncatalog); // do this on every pass 62 } 63 if ((CurrentLoop >= 21) && (CurrentLoop <= 999)) { 64 // after iterating a few times on the TGroup & Mosaic zero points: 65 // * identify the good / bad Mosaics 66 // * fit the chips from the bad Mosaics 67 TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_GOOD_NIGHT; // stop fitting the bad nights 68 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC; // only fit good mosaics on bad nights 69 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC; // only fit bad mosaics on bad nights 70 GRID_ZPT_MODE = GRID_ZPT_MODE_ALL; // only fit bad mosaics on bad nights 71 clean_tgroups(); // do this on every pass 72 clean_mosaics(); // do this on every pass 73 clean_images(); // do this on every pass 74 clean_stars(catalog, Ncatalog); // do this on every pass 61 75 } 62 76 } … … 68 82 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE; 69 83 } 70 if ((CurrentLoop > 4) && (CurrentLoop <= 999)) {84 if ((CurrentLoop > 4) && (CurrentLoop <= 8)) { 71 85 // after iterating a few times on the TGroup zero points: 72 86 // * identify the photometric nights … … 77 91 clean_tgroups(); // do this on every pass or just sometimes? 78 92 } 93 if ((CurrentLoop > 8) && (CurrentLoop <= 999)) { 94 // after iterating a few times on the TGroup zero points: 95 // * identify the photometric nights 96 // * fit the images from the non-photometric nights 97 TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_GOOD_NIGHT; // stop fitting the bad nights 98 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE; 99 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_BAD_NIGHT; 100 GRID_ZPT_MODE = GRID_ZPT_MODE_ALL; // only fit bad mosaics on bad nights 101 clean_tgroups(); // do this on every pass or just sometimes? 102 } 79 103 } 80 104 81 105 if (!TGROUP_ZEROPT && MOSAIC_ZEROPT) { 82 if (CurrentLoop < = 4) {106 if (CurrentLoop < 6) { 83 107 TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE; 84 108 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_ALL; 85 109 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_NONE; 86 110 } 87 if ((CurrentLoop > 4) && (CurrentLoop <= 999)) {111 if ((CurrentLoop >= 6) && (CurrentLoop < 12)) { 88 112 // after iterating a few times on the Mosaic zero points: 89 113 // * identify the good / bad mosaics … … 94 118 clean_mosaics(); // do this on every pass or just sometimes? 95 119 } 120 if ((CurrentLoop >= 12) && (CurrentLoop < 18)) { 121 // after iterating a few times on the Mosaic zero points: 122 // * identify the good / bad mosaics 123 // * fit the images from the bad mosaics 124 TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE; // stop fitting the bad nights 125 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_GOOD_MOSAIC; 126 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_BAD_MOSAIC; 127 clean_mosaics(); // do this on every pass or just sometimes? 128 clean_images(); // do this on every pass 129 clean_stars(catalog, Ncatalog); // do this on every pass 130 } 131 if ((CurrentLoop >= 18) && (CurrentLoop < 999)) { 132 // after iterating a few times on the Mosaic zero points: 133 // * identify the good / bad mosaics 134 // * fit the images from the bad mosaics 135 TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE; // stop fitting the bad nights 136 MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_GOOD_MOSAIC; 137 IMAGE_ZPT_MODE = IMAGE_ZPT_MODE_BAD_MOSAIC; 138 GRID_ZPT_MODE = GRID_ZPT_MODE_ALL; // only fit bad mosaics on bad nights 139 clean_mosaics(); // do this on every pass or just sometimes? 140 clean_images(); // do this on every pass 141 clean_stars(catalog, Ncatalog); // do this on every pass 142 } 96 143 } 97 144 -
trunk/Ohana/src/relphot/src/args.c
r41562 r41647 198 198 } 199 199 200 NGRID = 8;201 if ((N = get_argument (argc, argv, "-ngrid"))) {202 remove_argument (N, &argc, argv);203 NGRID = atof (argv[N]);204 remove_argument (N, &argc, argv);205 }206 207 200 TEST_IMAGE1 = -1; 208 201 if ((N = get_argument (argc, argv, "-test-image1"))) { … … 227 220 RESET = TRUE; 228 221 } 229 230 222 RESET_ZEROPTS = FALSE; 231 223 if ((N = get_argument (argc, argv, "-reset-zpts"))) { … … 233 225 RESET_ZEROPTS = TRUE; 234 226 } 227 RESET_FLATCORR = FALSE; 228 if ((N = get_argument (argc, argv, "-reset-flat"))) { 229 remove_argument (N, &argc, argv); 230 RESET_FLATCORR = TRUE; 231 } 235 232 236 233 REPAIR_WARPS = FALSE; … … 244 241 remove_argument (N, &argc, argv); 245 242 PRESERVE_PS1 = TRUE; 243 } 244 REQUIRE_PSFFIT = FALSE; 245 if ((N = get_argument (argc, argv, "-require-psffit"))) { 246 remove_argument (N, &argc, argv); 247 REQUIRE_PSFFIT = TRUE; 246 248 } 247 249 … … 387 389 } 388 390 389 // USE_GRID is not valid for all cases, probably should be its own mode... 390 USE_GRID = FALSE; 391 // GRID_ZEROPT is not valid for all cases, probably should be its own mode... 392 GRID_ZEROPT = FALSE; 393 GRID_MEANFILE = NULL; // this is set by GridCorrectionSave() 394 GRID_ZPT_MODE = GRID_ZPT_MODE_NONE; // start with grid off 391 395 if ((N = get_argument (argc, argv, "-grid"))) { 392 396 remove_argument (N, &argc, argv); 393 USE_GRID = TRUE; 397 GRID_ZEROPT = TRUE; 398 } 399 if ((N = get_argument (argc, argv, "-grid-meanfile"))) { 400 GRID_ZEROPT = TRUE; 401 remove_argument (N, &argc, argv); 402 GRID_MEANFILE = strcreate (argv[N]); // used by relphot -averages and relphot -apply-offsets 403 remove_argument (N, &argc, argv); 404 } 405 406 GRID_BIN_GPC1 = 16; 407 if ((N = get_argument (argc, argv, "-grid-bin-gpc1"))) { 408 remove_argument (N, &argc, argv); 409 GRID_BIN_GPC1 = atof (argv[N]); 410 remove_argument (N, &argc, argv); 411 } 412 GRID_BIN_GPC2 = 16; 413 if ((N = get_argument (argc, argv, "-grid-bin-gpc2"))) { 414 remove_argument (N, &argc, argv); 415 GRID_BIN_GPC2 = atof (argv[N]); 416 remove_argument (N, &argc, argv); 417 } 418 GRID_BIN_HSC = 8; 419 if ((N = get_argument (argc, argv, "-grid-bin-hsc"))) { 420 remove_argument (N, &argc, argv); 421 GRID_BIN_HSC = atof (argv[N]); 422 remove_argument (N, &argc, argv); 423 } 424 GRID_BIN_CFH = 8; 425 if ((N = get_argument (argc, argv, "-grid-bin-cfh"))) { 426 remove_argument (N, &argc, argv); 427 GRID_BIN_CFH = atof (argv[N]); 428 remove_argument (N, &argc, argv); 394 429 } 395 430 … … 555 590 case SYNTH_PHOT: 556 591 case UPDATE_AVERAGES: 592 // note: initialize sets PhotcodeList to the full set of average photcodes 593 // if the mode is UPDATE_AVERAGES 557 594 if (argc != 1) relphot_usage(); 558 595 break; … … 608 645 FREE (REGION_FILE); 609 646 FREE (SYNTH_ZERO_POINTS); 647 FREE (GRID_MEANFILE); 610 648 FREE (IMAGE_TABLE); 611 649 FREE (CATDIR); … … 763 801 RESET = TRUE; 764 802 } 765 766 803 RESET_ZEROPTS = FALSE; 767 804 if ((N = get_argument (argc, argv, "-reset-zpts"))) { 768 805 remove_argument (N, &argc, argv); 769 806 RESET_ZEROPTS = TRUE; 807 } 808 RESET_FLATCORR = FALSE; 809 if ((N = get_argument (argc, argv, "-reset-flat"))) { 810 remove_argument (N, &argc, argv); 811 RESET_FLATCORR = TRUE; 770 812 } 771 813 … … 864 906 } 865 907 908 // load the GridCorrection file 909 GRID_ZEROPT = FALSE; 910 GRID_MEANFILE = NULL; 911 if ((N = get_argument (argc, argv, "-grid"))) { 912 GRID_ZEROPT = TRUE; 913 remove_argument (N, &argc, argv); 914 GRID_MEANFILE = strcreate (argv[N]); 915 remove_argument (N, &argc, argv); 916 GRID_ZPT_MODE = GRID_ZPT_MODE_ALL; // since we are applying the grid, need to active this 917 } 918 866 919 ImagSelect = FALSE; 867 920 if ((N = get_argument (argc, argv, "-instmag"))) { … … 922 975 923 976 FREE (SYNTH_ZERO_POINTS); 977 FREE (GRID_MEANFILE); 924 978 FREE (BOUNDARY_TREE); 925 979 FREE (UPDATE_CATFORMAT); -
trunk/Ohana/src/relphot/src/assign_images.c
r41485 r41647 36 36 if (MOSAIC_ZEROPT) { 37 37 makeMosaics (image, Nimage, FALSE); 38 39 // center coords and Mcal, dMcal, Mchisq for the mosaics 38 MARKTIME("set mosaic coordinates and Mcal values: %f sec\n", dtime); 39 40 // center coords and zero Mcal, dMcal, Mchisq for the mosaics 40 41 setMosaicCenters (image, Nimage); 41 42 MARKTIME("set mosaic coordinates and Mcal values: %f sec\n", dtime); … … 124 125 Mosaic *mosaic = getMosaicForImage (j); 125 126 if (mosaic) { 126 Rc = mosaic->coords.crval1;127 Dc = mosaic->coords.crval2;128 // NOTE : have defined mosaic Rc,Dc to choose the side of 0,360 on which most of the129 // chips are located. but, for host assignment, we rationalize to 0.0 - 360.0130 Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);127 Rc = mosaic->coords.crval1; 128 Dc = mosaic->coords.crval2; 129 // NOTE : have defined mosaic Rc,Dc to choose the side of 0,360 on which most of the 130 // chips are located. but, for host assignment, we rationalize to 0.0 - 360.0 131 Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0); 131 132 } 132 133 } -
trunk/Ohana/src/relphot/src/bcatalog.c
r41561 r41647 35 35 ALLOCATE (Nvalid, int, Nsecfilt); 36 36 37 // flags used by the photometry analysis (excluding UBERCAL)38 unsigned int PHOTOM_FLAGS =39 ID_MEAS_NOCAL | // detection ignored for this analysis (photcode, time range)40 ID_MEAS_POOR_PHOTOM | // detection is photometry outlier41 ID_MEAS_SKIP_PHOTOM | // detection was ignored for photometry measurement42 ID_MEAS_AREA | // detetion was outside acceptable area of device43 ID_MEAS_SYNTH_MAG | // magnitude is synthetic44 ID_MEAS_STACK_PRIMARY | // this stack measurement is in the primary skycell45 ID_MEAS_STACK_PHOT_SRC | // this measurement supplied the stack photometry46 ID_MEAS_PHOTOM_PSF | // this measurement is used for the mean psf mag47 ID_MEAS_PHOTOM_APER | // this measurement is used for the mean ap mag48 ID_MEAS_PHOTOM_KRON ; // this measurement is used for the mean kron mag49 50 37 /* exclude stars not in range or with too few measurements */ 51 38 for (i = 0; i < catalog[0].Naverage; i++) { … … 61 48 } 62 49 63 // reset the calculated average magnitudes (does not affect ubercal-tied measurements or images) 64 if (RESET) { 65 int Ns; 66 67 for (Ns = 0; Ns < Nphotcodes; Ns++) { 68 69 int thisCode = photcodes[Ns][0].code; 70 int Nsec = GetPhotcodeNsec(thisCode); 71 72 dvo_secfilt_init (&subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec], SECFILT_RESET_ALL); 73 } 74 } 50 // reset the calculated average magnitudes for active photcode only 51 ResetAverageActivePhotcodes (&subcatalog[0].secfilt[Nsecfilt*Naverage]); 75 52 76 53 Nm = 0; … … 111 88 if (isnan(catalog[0].measure[offset].Mkron)) { Nnan ++; continue; } 112 89 113 // require 0x01 in photFlags (fitted with a PSF) 114 if ( (catalog[0].measure[offset].photFlags & 0x01) == 0) { Nbad ++; continue; }90 // require 0x01 in photFlags (fitted with a PSF) -- add to the test data 91 if (REQUIRE_PSFFIT && (catalog[0].measure[offset].photFlags & 0x01) == 0) { Nbad ++; continue; } 115 92 116 93 // very loose cut on PSF - Kron … … 156 133 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 157 134 subcatalog[0].measureT[Nmeasure].averef = Naverage; 158 if (RESET) { 159 // only reset Mcal for measures with a matching image 160 // do not reset Mcal for ubercal images unless explicitly requested 161 if (subcatalog[0].measureT[Nmeasure].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { 162 if (!KEEP_UBERCAL) { 163 subcatalog[0].measureT[Nmeasure].McalPSF = 0.0; 164 subcatalog[0].measureT[Nmeasure].McalAPER = 0.0; 165 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL; 166 } 167 } else { 168 if (getImageEntry (Nmeasure, Ncat) >= 0) { 169 subcatalog[0].measureT[Nmeasure].McalPSF = 0.0; 170 subcatalog[0].measureT[Nmeasure].McalAPER = 0.0; 171 } 172 } 173 subcatalog[0].measureT[Nmeasure].dbFlags &= ~PHOTOM_FLAGS; 174 } 135 ResetMeasureZeroPoints (&subcatalog[0].measureT[Nmeasure], Nmeasure, Ncat); 136 175 137 Nmeasure ++; 176 138 Nm ++; -
trunk/Ohana/src/relphot/src/extra.c
r41467 r41647 1 1 # include "relphot.h" 2 # define DISABLE_CORNER_GPC1 0 2 3 3 4 int isMosaicChip (int photcode) { … … 14 15 int whichGPC1filter (int photcode) { 15 16 16 # if ( 1)17 # if (DISABLE_CORNER_GPC1) 17 18 // disable the corner chips: 18 19 if (((photcode > 10000) && (photcode < 10077)) || (photcode == 4100)) return PS1_g; // g-band … … 37 38 int isGPC1chip (int photcode) { 38 39 39 # if ( 1)40 # if (DISABLE_CORNER_GPC1) 40 41 if (((photcode > 10000) && (photcode < 10077)) || (photcode == 4100)) return TRUE; // g-band 41 42 if (((photcode > 10100) && (photcode < 10177)) || (photcode == 4200)) return TRUE; // r-band -
trunk/Ohana/src/relphot/src/global_stats.c
r41462 r41647 1 1 # include "relphot.h" 2 2 3 void global_stats (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr,int nloop) {3 void global_stats (Catalog *catalog, int Ncatalog, int nloop) { 4 4 5 5 StatType stN, stX, stS, imN, imX, imM, imD, msM, msX, msN, msD, tgM, tgX, tgD; … … 33 33 int seccode = photcodes[Ns][0].code; 34 34 35 stN = statsStarN (catalog, Ncatalog, Nsec, seccode , flatcorr);35 stN = statsStarN (catalog, Ncatalog, Nsec, seccode); 36 36 stX = statsStarX (catalog, Ncatalog, Nsec); 37 37 stS = statsStarS (catalog, Ncatalog, Nsec); … … 43 43 } 44 44 45 imN = statsImageN (catalog , flatcorr);45 imN = statsImageN (catalog); 46 46 imX = statsImageX (catalog); 47 47 imM = statsImageM (catalog); 48 48 imD = statsImagedM (catalog); 49 49 50 msN = statsMosaicN (catalog , flatcorr);50 msN = statsMosaicN (catalog); 51 51 msM = statsMosaicM (catalog); 52 52 msD = statsMosaicdM (catalog); … … 58 58 59 59 fprintf (stderr, "meas / image: %7.0f %7.0f %7.0f %7.0f %7.0f %6d\n", imN.median, imN.mean, imN.sigma, imN.min, imN.max, imN.Nmeas); 60 fprintf (stderr, "Mcal image:%7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", imM.median, imM.mean, imM.sigma, imM.min, imM.max, imM.Nmeas);60 fprintf (stderr, "Mcal image: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", imM.median, imM.mean, imM.sigma, imM.min, imM.max, imM.Nmeas); 61 61 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); 62 62 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); 63 63 64 64 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); 65 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);65 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); 66 66 fprintf (stderr, "dMcal mosaic: %7.4f %7.4f %7.4f %7.4f %7.4f %6d\n", msD.median, msD.mean, msD.sigma, msD.min, msD.max, msD.Nmeas); 67 67 fprintf (stderr, "chisq mosaic: %7.1f %7.1f %7.1f %7.1f %7.1f %6d\n", msX.median, msX.mean, msX.sigma, msX.min, msX.max, msX.Nmeas); -
trunk/Ohana/src/relphot/src/initialize.c
r41453 r41647 27 27 } 28 28 29 if (USE_GRID && (Nphotcodes > 1)) {30 fprintf (stderr, "grid correction analysis currently can only operate on a single photcode\n");31 exit (1);32 }33 34 IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;35 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;36 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;37 38 29 if (SHOW_PARAMS) { 39 30 int Ns; … … 67 58 68 59 fprintf (stderr, "VERBOSE: %d, PLOTSTUFF: %d\n", VERBOSE, PLOTSTUFF); 69 fprintf (stderr, "GRID_X: %d, GRID_Y: %d, BINNING: %d == Nmx: %d, Nmy: %d\n",70 RELPHOT_GRID_X,71 RELPHOT_GRID_Y,72 RELPHOT_GRID_BINNING,73 (int)(RELPHOT_GRID_X/RELPHOT_GRID_BINNING), (int)(RELPHOT_GRID_Y/RELPHOT_GRID_BINNING));74 60 75 61 fprintf (stderr, "STAR_SCATTER %lf\n", STAR_SCATTER); 62 fprintf (stderr, "STAR_CHISQ %lf\n", STAR_CHISQ); 63 64 fprintf (stderr, "MOSAIC_SCATTER %lf\n", MOSAIC_SCATTER); 65 fprintf (stderr, "MOSAIC_CHISQ %lf\n", MOSAIC_CHISQ); 66 67 fprintf (stderr, "NIGHT_SCATTER %lf\n", NIGHT_SCATTER); 68 fprintf (stderr, "NIGHT_CHISQ %lf\n", NIGHT_CHISQ); 69 76 70 fprintf (stderr, "IMAGE_SCATTER %lf\n", IMAGE_SCATTER); 77 71 fprintf (stderr, "IMAGE_OFFSET %lf\n", IMAGE_OFFSET); -
trunk/Ohana/src/relphot/src/launch_region_hosts.c
r40291 r41647 62 62 if (RESET) strextend (&command, "-reset"); 63 63 if (RESET_ZEROPTS) strextend (&command, "-reset-zpts"); 64 if (RESET_FLATCORR) strextend (&command, "-reset-flat"); 64 65 if (!KEEP_UBERCAL) strextend (&command, "-reset-ubercal"); 65 66 if (DophotSelect) strextend (&command, "-dophot %d", DophotValue); -
trunk/Ohana/src/relphot/src/load_catalogs.c
r40549 r41647 165 165 if (RESET) { strextend (&command, "-reset"); } 166 166 if (RESET_ZEROPTS) { strextend (&command, "-reset-zpts"); } 167 if (RESET_FLATCORR) { strextend (&command, "-reset-flat"); } 167 168 if (!KEEP_UBERCAL) { strextend (&command, "-reset-ubercal"); } 168 169 if (DophotSelect) { strextend (&command, "-dophot %d", DophotValue); } -
trunk/Ohana/src/relphot/src/load_images.c
r41555 r41647 57 57 // reset image values as needed. always allow 'few' images to succeed, if possible (new 58 58 // images / detections may have been added 59 for (off_t i = 0; i < Nsubset; i++) { 60 // reset these two regardless (we will re-determine) 61 subset[i].flags &= ~(ID_IMAGE_PHOTOM_NOCAL | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP | ID_IMAGE_PHOTOM_FEW); 62 if (RESET) { 63 if (RESET_ZEROPTS) { 64 if (!KEEP_UBERCAL || !(subset[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) { 65 subset[i].McalPSF = 0.0; 66 subset[i].McalAPER = 0.0; 67 subset[i].dMcal = NAN; 68 subset[i].flags &= ~ID_IMAGE_PHOTOM_UBERCAL; 69 } 70 } 71 subset[i].flags &= ~(ID_IMAGE_MOSAIC_POOR | ID_IMAGE_NIGHT_POOR); 72 subset[i].flags &= ~(ID_IMAGE_IMAGE_PHOTCAL | ID_IMAGE_MOSAIC_PHOTCAL | ID_IMAGE_TGROUP_PHOTCAL); 73 subset[i].ubercalDist = 1000; 74 } 75 } 59 ResetImages (subset, Nsubset); 76 60 77 61 // XXX consider allowing relphot to skip the AstroMap load (do we need precise astrometry here?) … … 115 99 return TRUE; 116 100 } 101 102 // This function re-creates the image subset array using the array of LineNumbers saved 103 // initially by load_images. This function is only called by relphot_images.c after the 104 // loops have been completed (if any). I am not certain this function is doing anything 105 // at all : the values in the image subset are copied back to the master table in 106 // save_images_updates() so the values copied from the master to the subset should already 107 // be there. 117 108 118 109 int reload_images (FITS_DB *db) { -
trunk/Ohana/src/relphot/src/plot_scatter.c
r40291 r41647 1 1 # include "relphot.h" 2 2 3 void plot_scatter (Catalog *catalog, int Ncatalog , FlatCorrectionTable *flatcorr) {3 void plot_scatter (Catalog *catalog, int Ncatalog) { 4 4 5 5 off_t i, j, k, m, N, Ntot; … … 28 28 N = 0; 29 29 for (i = 0; i < Ncatalog; i++) { 30 for (j = 0; j < catalog[i].Naverage; j++) {30 for (j = 0; j < catalog[i].Naverage; j++) { 31 31 32 /* calculate the average value for a single star */33 if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;34 m = catalog[i].averageT[j].measureOffset;32 /* calculate the average value for a single star */ 33 // if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 34 m = catalog[i].averageT[j].measureOffset; 35 35 36 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {37 // skip measurements that do not match the current photcode38 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);39 if (ecode != thisCode) { continue; }36 for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) { 37 // skip measurements that do not match the current photcode 38 int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode); 39 if (ecode != thisCode) { continue; } 40 40 41 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;42 Mcal = getMcal (m, i, MAG_CLASS_PSF);43 if (isnan(Mcal)) continue;44 Mmos = getMmos (m, i);45 if (isnan(Mmos)) continue;46 Mgrid = getMgrid (m, i);47 if (isnan(Mgrid)) continue;41 if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; 42 Mcal = getMcal (m, i, MAG_CLASS_PSF); 43 if (isnan(Mcal)) continue; 44 Mmos = getMmos (m, i); 45 if (isnan(Mmos)) continue; 46 Mgrid = getMgridTiny (&catalog[i].measureT[m]); 47 if (isnan(Mgrid)) continue; 48 48 49 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp;50 if (isnan(Mrel)) continue;49 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp; 50 if (isnan(Mrel)) continue; 51 51 52 xlist[N] = Mrel; 53 ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF) - Mcal - Mmos - Mgrid - Mrel; 54 ilist[N] = PhotInstTiny (&catalog[i].measureT[m], MAG_CLASS_PSF); 55 N++; 56 } 52 xlist[N] = Mrel; 53 ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF) - Mcal - Mmos - Mgrid - Mrel; 54 ilist[N] = PhotInstTiny (&catalog[i].measureT[m], MAG_CLASS_PSF); 55 N++; 57 56 } 57 } 58 58 } 59 59 -
trunk/Ohana/src/relphot/src/reload_catalogs.c
r41390 r41647 9 9 gettimeofday (&start, (void *) NULL); 10 10 11 void reload_catalogs (SkyList *skylist, FlatCorrectionTable *flatcorr,int hostID, char *hostpath) {11 void reload_catalogs (SkyList *skylist, int hostID, char *hostpath) { 12 12 13 13 int i; … … 17 17 18 18 struct timeval start, stop; 19 double dtime = 0.0; 20 double time1 = 0.0; 21 double time2 = 0.0; 22 double time3a = 0.0; 23 double time3b = 0.0; 24 double time4 = 0.0; 25 double time5 = 0.0; 26 double time6 = 0.0; 27 double time7 = 0.0; 19 double dtime = 0.0, time1 = 0.0, time2 = 0.0, time3 = 0.0; 20 double time4 = 0.0, time5 = 0.0, time6 = 0.0, time7 = 0.0, time8 = 0.0; 28 21 29 22 // XXX need to decide how to determine PARALLEL mode... … … 81 74 82 75 populate_tiny_values(&catalog, DVO_TV_MEASURE | DVO_TV_AVERAGE); 83 TIMESTAMP(time3 a);76 TIMESTAMP(time3); 84 77 85 78 // XXX need to worry about the image subset data 86 79 initImageBins (&catalog, 1, FALSE); 87 initMosaicBins (&catalog, 1, FALSE); 88 initTGroupBins (&catalog, 1); 89 90 initGridBins (&catalog, 1); 91 TIMESTAMP(time3b); 80 TIMESTAMP(time4); 92 81 93 82 findImages (&catalog, 1, FALSE); 94 findMosaics (&catalog, 1, FALSE); 95 findTGroups (&catalog, 1); 96 97 TIMESTAMP(time4); 83 TIMESTAMP(time5); 98 84 99 85 initMrel (&catalog, 1); 100 setMrelFinal (&catalog, flatcorr, FALSE); 101 TIMESTAMP(time5); 86 87 setMrelFinal (&catalog, FALSE); 88 TIMESTAMP(time6); 102 89 103 90 // modify the output format as desired (ignore current format on disk) … … 119 106 free_tiny_values(&catalog); 120 107 dvo_catalog_free (&catalog); 121 TIMESTAMP(time6); 122 123 // XXX freeTgroupBins here: 108 TIMESTAMP(time7); 124 109 125 110 freeImageBins (1, FALSE); 126 freeMosaicBins (1, FALSE); 127 freeTGroupBins (1); 128 freeGridBins (1); 129 TIMESTAMP(time7); 111 TIMESTAMP(time8); 130 112 131 113 if (hostID) { … … 134 116 } 135 117 136 fprintf (stderr, "time step 1 %10.3f sec : find catalog\n", time1);137 fprintf (stderr, "time step 2 %10.3f sec : load catalog\n", time2);138 fprintf (stderr, "time step 3 %10.3f sec : make tiny values\n", time3 a);139 fprintf (stderr, "time step 4 %10.3f sec : init imbins\n", time3b);140 fprintf (stderr, "time step 5 %10.3f sec : find images\n", time4);141 fprintf (stderr, "time step 6 %10.3f sec : set Mrel\n", time5);142 fprintf (stderr, "time step 7 %10.3f sec : save catalog\n", time6);143 fprintf (stderr, "time step 8 %10.3f sec : free catalog\n", time7);118 fprintf (stderr, "time step 1 %10.3f sec : find catalog\n", time1); 119 fprintf (stderr, "time step 2 %10.3f sec : load catalog\n", time2); 120 fprintf (stderr, "time step 3 %10.3f sec : make tiny values\n", time3); 121 fprintf (stderr, "time step 4 %10.3f sec : init imbins\n", time4); 122 fprintf (stderr, "time step 5 %10.3f sec : find images\n", time5); 123 fprintf (stderr, "time step 6 %10.3f sec : set Mrel\n", time6); 124 fprintf (stderr, "time step 7 %10.3f sec : save catalog\n", time7); 125 fprintf (stderr, "time step 8 %10.3f sec : free catalog\n", time8); 144 126 } 145 127 … … 231 213 char *command = NULL; 232 214 strextend (&command, "relphot_client %s -update-catalogs %s", PhotcodeList, imageFile); 233 strextend (&command, "-hostID %d -D CATDIR %s -hostdir %s", group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname); 215 strextend (&command, "-hostID %d", group->hosts[i][0].hostID); 216 strextend (&command, "-D CATDIR %s", CATDIR); 217 strextend (&command, "-hostdir %s", group->hosts[i][0].pathname); 234 218 strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax); 235 219 strextend (&command, "-statmode %s", STATMODE); 236 220 strextend (&command, "-D CAMERA %s", CAMERA); 237 strextend (&command, "-D STAR_TOOFEW %d -minerror %f", STAR_TOOFEW, MIN_ERROR); 238 239 // options & configs which affect relphot_client -update-catalogs 240 // VERBOSE, VERBOSE2 241 // RESET 242 // RESET_ZEROPTS 243 // TimeSelect 244 // AreaSelect 245 // STATMODE 246 // STAR_TOOFEW 247 // MIN_ERROR 248 221 strextend (&command, "-D STAR_TOOFEW %d", STAR_TOOFEW); 222 strextend (&command, "-minerror %f", MIN_ERROR); 223 249 224 if (VERBOSE) { strextend (&command, "-v"); } 250 225 if (VERBOSE2) { strextend (&command, "-vv"); } 251 226 if (RESET) { strextend (&command, "-reset"); } 252 227 if (RESET_ZEROPTS) { strextend (&command, "-reset-zpts"); } 228 if (RESET_FLATCORR) { strextend (&command, "-reset-flat"); } 229 if (!KEEP_UBERCAL) { strextend (&command, "-reset-ubercal"); } 253 230 if (PRESERVE_PS1) { strextend (&command, "-preserve-ps1"); } 231 if (IS_DIFF_DB) { strextend (&command, "-is-diff-db"); } 254 232 if (UPDATE) { strextend (&command, "-update"); } 255 if (IS_DIFF_DB) { strextend (&command, "-is-diff-db"); }256 if (!KEEP_UBERCAL) { strextend (&command, "-reset-ubercal"); }257 233 if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); } 258 234 if (BOUNDARY_TREE) { strextend (&command, "-boundary-tree %s", BOUNDARY_TREE); } 259 235 if (SYNTH_ZERO_POINTS) { strextend (&command, "-synthphot-zpts %s", SYNTH_ZERO_POINTS); } 236 if (GRID_ZEROPT) { strextend (&command, "-grid %s", GRID_MEANFILE); } 260 237 if (USE_BASIC_CHECK) { strextend (&command, "-basic-image-search"); } 238 // if (USE_ALL_IMAGES) { strextend (&command, "-use-all-images"); } 261 239 if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); } 262 240 -
trunk/Ohana/src/relphot/src/relphot.c
r39481 r41647 34 34 switch (mode) { 35 35 case UPDATE_IMAGES: 36 // calculate zero points for images (may group by exposure [mosaic], night [tgroups]; may measure flat-correction) 36 37 // IF CALLED WITH NLOOP == 0, DOES NOT LOAD bcatalog, just loads image table and generates ImageSubset.dat 38 // If called with -update, calls reload_catalogs() just like apply_offsets 37 39 relphot_images (skylist); 38 40 relphot_free (sky, skylist); … … 52 54 53 55 case PARALLEL_REGIONS: 54 // run image updates in parallel across multiple remote machines 56 // calculate zero points for images (may group my exposure [mosaic], night [tgroups]; may measure flat-correction) 57 // equivalent to relphot_images, but run in parallel across multiple remote machines 55 58 relphot_parallel_regions (sky); 56 59 relphot_free (sky, skylist); … … 69 72 exit (2); 70 73 } 71 reload_catalogs (skylist, NULL, 0, NULL); 74 // we do not need to load grid corrections here. the value of 75 // GRID_MEANFILE, if specified, is passed to the clients 76 reload_catalogs (skylist, 0, NULL); 72 77 relphot_free (sky, skylist); 73 78 exit (0); … … 84 89 85 90 I would like to merge the functionality of relphot_images (Nloop == 0), relphot_objects, and apply_offsets 91 92 relphot_objects vs reload_objects (apply offsets): 93 94 relphot_objects 95 86 96 87 97 ***/ -
trunk/Ohana/src/relphot/src/relphot_client.c
r39643 r41647 80 80 initImagesSubset (image, NULL, Nimage); 81 81 82 // load the flat-field correction table from CATDIR 83 FlatCorrectionTable *flatcorr = NULL; 84 reload_catalogs (skylist, flatcorr, HOST_ID, HOSTDIR); 82 // load grid corrections here 83 GridCorrectionLoad (GRID_MEANFILE); 84 85 reload_catalogs (skylist, HOST_ID, HOSTDIR); 85 86 freeImages ((char *)image); 86 87 free (image); 88 freeGridBins (); 87 89 client_logger_message ("updated catalogs\n"); 88 90 relphot_client_free (sky, skylist); … … 90 92 } 91 93 94 /* deprecated (absorbed into MODE_UPDATE) 92 95 case MODE_UPDATE_OBJECTS: { 93 96 // take the current set of detections and set the mean magnitudes … … 97 100 break; 98 101 } 102 */ 99 103 100 104 case MODE_SYNTH_PHOT: … … 104 108 break; 105 109 110 case MODE_UPDATE_OBJECTS: 106 111 default: 107 112 fprintf (stderr, "impossible!"); -
trunk/Ohana/src/relphot/src/relphot_images.c
r41556 r41647 38 38 MARKTIME("-- load image data: %f sec\n", dtime); 39 39 40 /* load regions and images based on specified sky patch and/or catalog */ 40 // load regions and images based on specified sky patch and/or catalog 41 // NOTE: load_images transfers zero points from images to mosaics (initMosaicMcal) 42 // and to tgroups (initTGroupMcal), resetting the image zero points to 0.0. 43 44 // (if both tgroups and mosaics are used, the mosaics will hold the value and tgroups 45 // will get values of 0.0. This is not clearly the right way to go, but may not matter 46 // if we reset everything). 47 41 48 load_images (&db, skylist, &UserPatch, FALSE, USE_ALL_IMAGES); 42 49 MARKTIME("-- load images: %f sec\n", dtime); … … 45 52 if (!UPDATE) dvo_image_unlock (&db); 46 53 47 // load the flat correction table (if defined) 48 // we no longer need to do this: the flatcorrection is now saved in measure.Mflat 49 # if (0) 50 char flatcorrfile[256]; 51 sprintf (flatcorrfile, "%s/flatcorr.fits", CATDIR); 52 FlatCorrectionTable *flatcorr = FlatCorrectionLoad (flatcorrfile, VERBOSE); 53 # endif 54 FlatCorrectionTable *flatcorr = NULL; 54 initGridBins (); // allocates the empty array of corrections (elements are built below) 55 55 56 56 if (CALIBRATE_STACKS_AND_WARPS || (NLOOP > 0)) { 57 initGrid (); // allocate grid correction entries for existing photcodes 58 57 59 /* load catalog data from region files (hostID is 0 since we are not a client */ 58 60 catalog = load_catalogs (skylist, &Ncatalog, 0, NULL, NULL); … … 68 70 initTGroupBins (catalog, Ncatalog); 69 71 70 initGridBins (catalog, Ncatalog);71 72 initMrel (catalog, Ncatalog); 72 73 … … 74 75 MARKTIME("-- set up image indexes: %f sec\n", dtime); 75 76 76 findMosaics (catalog, Ncatalog, TRUE); /* also sets Grid values */77 findMosaics (catalog, Ncatalog, TRUE); 77 78 MARKTIME("-- set up mosaic indexes: %f sec\n", dtime); 78 79 … … 82 83 SAVEPLOT = FALSE; 83 84 85 // mark ID_MEAS_AREA (user-selected chip region) and ID_MEAS_NOCAL (time range & active photcode) 84 86 setExclusions (catalog, Ncatalog, TRUE); 85 87 86 global_stats (catalog, Ncatalog, flatcorr,0);88 global_stats (catalog, Ncatalog, 0); 87 89 88 90 if (PLOTSTUFF) { … … 91 93 } 92 94 93 // if we are measuring the flat-field correction grid, we need to perform a number of iterations first:94 if (USE_GRID) {95 int star_toofew;96 97 // until we finish the grid analysis, do not reject stars out-of-hand based on ID_OBJ_FEW98 // XXX this is kind of poor: need to have a better distinctions about STAR_BAD in setMrel vs getMrel99 star_toofew = STAR_TOOFEW;100 STAR_TOOFEW = 0;101 for (i = 0; i < NGRID; i++) {102 STAR_BAD = ID_OBJ_POOR;103 setMrel (catalog, Ncatalog, flatcorr);104 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;105 setMgrid (catalog, flatcorr);106 }107 STAR_BAD = ID_OBJ_POOR | ID_OBJ_FEW;108 STAR_TOOFEW = star_toofew;109 }110 111 95 /* determine fit values */ 112 96 for (i = 0; i < NLOOP; i++) { 113 97 SetZptIteration (i); 114 98 115 setMrel (catalog, Ncatalog , flatcorr); // threaded116 117 setMcal (catalog , flatcorr);118 setMmos (catalog , flatcorr);119 setMgrp (catalog , flatcorr);120 121 setMgrid (catalog, flatcorr);99 setMrel (catalog, Ncatalog); // threaded (calls setMrelCatalog) 100 101 setMcal (catalog); 102 setMmos (catalog); 103 setMgrp (catalog); 104 105 setMgrid (catalog, Ncatalog); 122 106 MARKTIME("-- set Mrel, Mcal, Mmos, Mgrid : %f sec\n", dtime); 123 107 124 108 if (PLOTSTUFF) { 125 plot_scatter (catalog, Ncatalog, flatcorr); 126 plot_grid (catalog, flatcorr); 109 plot_scatter (catalog, Ncatalog); 127 110 plot_mosaics (); 128 111 plot_images (); … … 131 114 } 132 115 133 global_stats (catalog, Ncatalog, flatcorr,i);134 SetZeroPointModes ( );116 global_stats (catalog, Ncatalog, i); 117 SetZeroPointModes (catalog, Ncatalog); 135 118 136 119 MARKTIME("-- finished loop %d: %f sec\n", i, dtime); … … 139 122 140 123 if (PLOTSTUFF) { 141 plot_scatter (catalog, Ncatalog, flatcorr); 142 plot_grid (catalog, flatcorr); 124 plot_scatter (catalog, Ncatalog); 143 125 plot_mosaics (); 144 126 plot_images (); … … 147 129 } 148 130 149 if (USE_GRID) dump_grid ();131 // if (GRID_ZEROPT) dump_grid (); 150 132 151 133 MARKTIME("-- finalize Mcal values: %f sec\n", dtime); … … 169 151 freeMosaicBins (Ncatalog, TRUE); 170 152 freeTGroupBins (Ncatalog); 171 freeGridBins (Ncatalog); 153 154 GridCorrectionSave (); 172 155 173 156 // end of if (NLOOP > 0) block : this loop determines the offsets per chip … … 179 162 } 180 163 164 // once the zero points have been calculated, they are reassigned to the 165 // individual images. At this point, the mosaic and tgroup values should not 166 // be used. 167 freeMosaics (); 168 freeTGroups (); 169 MOSAIC_ZEROPT = FALSE; 170 TGROUP_ZEROPT = FALSE; 171 172 // only change the real database files if -update is requested 173 if (!UPDATE) { 174 dvo_image_unlock (&db); 175 freeImages (db.ftable.buffer); 176 gfits_db_free (&db); 177 freeGridBins (); 178 return TRUE; 179 } 180 181 181 reload_images (&db); 182 182 183 // only change the real database files if -update is requested184 if (!UPDATE) exit (0);185 186 183 /* Load catalog data from region files, update Mrel include all data. In a parallel 187 184 context, this function writes the image parameters as a subset table for the remote 188 185 clients */ 189 186 if (!CALIBRATE_STACKS_AND_WARPS) { 190 reload_catalogs (skylist, flatcorr, 0, NULL);187 reload_catalogs (skylist, 0, NULL); // calls setMrelFinal which setMrelOutput which calls setMrelCatalog 191 188 MARKTIME("-- updated all catalogs: %f sec\n", dtime); 192 189 } 193 190 194 191 if (UPDATE_CATFORMAT) { 195 // ensure the db format is updated192 // ensure the Image db format is updated 196 193 db.format = dvo_catalog_catformat (UPDATE_CATFORMAT); 197 194 gfits_modify (&db.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT); … … 204 201 205 202 freeImages (db.ftable.buffer); 206 freeMosaics (); 203 freeGridBins (); 204 207 205 gfits_db_free (&db); 208 206 -
trunk/Ohana/src/relphot/src/relphot_objects.c
r41507 r41647 6 6 // has been correctly propagated to the measurement, the average will respect that value. 7 7 8 int relphot_objects_parallel (SkyList *sky);9 10 8 int relphot_objects (SkyList *skylist, int hostID, char *hostpath) { 11 9 12 off_t i, j, k; 13 int Nsecfilt; 14 struct stat filestat; 15 16 Catalog catalog; 10 FITS_DB db; 17 11 18 12 INITTIME; 19 13 20 // XXX need to decide how to determine PARALLEL mode...21 if (PARALLEL && !hostID) {22 relphot_objects_parallel (skylist);23 return TRUE;24 }25 26 FITS_DB db;27 28 14 set_db (&db); 29 15 gfits_db_init (&db); … … 41 27 MARKTIME("loaded images: %f sec\n", dtime); 42 28 43 // load the ZP corrections here44 if (SYNTH_ZERO_POINTS) SynthZeroPointsLoad (SYNTH_ZERO_POINTS);29 // load grid corrections here (specified by -grid-meanfile) 30 GridCorrectionLoad (GRID_MEANFILE); 45 31 46 if (REPAIR_WARPS) { 47 FindWarpGroups (); 48 MARKTIME("setup warp groups: %f sec\n", dtime); 49 MakeStackIndex (); 50 MARKTIME("setup stack index: %f sec\n", dtime); 51 RepairWarpMeasuresOpenLogfile (); 52 } 53 54 // load data from each region file, only use bright stars 55 for (i = 0; i < skylist[0].Nregions; i++) { 56 57 // does this host ID match the desired location for the table? 58 if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue; 59 60 // set up the basic catalog info 61 char hostfile[1024]; 62 snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name); 63 64 dvo_catalog_init (&catalog, TRUE); 65 catalog.filename = hostID ? hostfile : skylist[0].filename[i]; 66 67 // only update existing db tables 68 int status = stat (catalog.filename, &filestat); 69 if ((status == -1) && (errno == ENOENT)) { 70 if (VERBOSE) fprintf (stderr, "no file %s, skipping\n", catalog.filename); 71 continue; 72 } 73 74 catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT; 75 // if we are going to update the format, we should update all tables 76 if (UPDATE_CATFORMAT) { 77 catalog.catflags |= DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT; 78 } 79 catalog.Nsecfilt = GetPhotcodeNsecfilt (); 80 81 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) { 82 fprintf (stderr, "ERROR: failure reading catalog %s, skipping\n", catalog.filename); 83 continue; 84 } 85 if (!catalog.Naverage_disk) { 86 if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename); 87 dvo_catalog_unlock (&catalog); 88 dvo_catalog_free (&catalog); 89 continue; 90 } 91 92 // reset the calculated average magnitudes (does not affect ubercal-tied measurements or images) 93 if (RESET) { 94 Nsecfilt = catalog.Nsecfilt; 95 96 DVOAverageFlags photomBits = 97 ID_OBJ_EXT | // extended in our data (eg, PS) 98 ID_OBJ_EXT_ALT | // extended in external data (eg, 2MASS) 99 ID_OBJ_GOOD | // good-quality measurement in our data (eg,PS) 100 ID_OBJ_GOOD_ALT | // good-quality measurement in external data (eg, 2MASS) 101 ID_OBJ_GOOD_STACK | // good-quality object in the stack (> 1 good stack) 102 ID_OBJ_BEST_STACK | // the primary stack measurement are the best measurements 103 ID_OBJ_SUSPECT_STACK | // suspect object in the stack (> 1 good or suspect stack, < 2 good) 104 ID_OBJ_BAD_STACK; // good-quality object in the stack (> 1 good stack) 105 106 for (j = 0; j < catalog.Naverage; j++) { 107 catalog.average[j].flags &= ~photomBits; // reset all except astrometry bits 108 catalog.average[j].psfQF = NAN; // reset (will be re-calculated here) 109 catalog.average[j].psfQFperf = NAN; // reset (will be re-calculated here) 110 catalog.average[j].stargal = NAN; // reset (will be re-calculated here) 111 catalog.average[j].photFlagsUpper = 0; // reset (will be re-calculated here) 112 catalog.average[j].photFlagsLower = 0; // reset (will be re-calculated here) 113 catalog.average[j].NwarpOK = 0; // reset (will be re-calculated here) 114 for (k = 0; k < Nsecfilt; k++) { 115 dvo_secfilt_init (&catalog.secfilt[j*Nsecfilt + k], SECFILT_RESET_ALL); 116 } 117 } 118 } 119 120 populate_tiny_values(&catalog, DVO_TV_MEASURE | DVO_TV_AVERAGE); 121 122 // XXX need to worry about the image subset data 123 initImageBins (&catalog, 1, FALSE); 124 initMosaicBins (&catalog, 1, FALSE); 125 initGridBins (&catalog, 1); 126 127 findImages (&catalog, 1, FALSE); 128 findMosaics (&catalog, 1, FALSE); 129 130 // update the detection coordinates using the new image parameters 131 if (REPAIR_WARPS) RepairWarpMeasures (&catalog); 132 133 initMrel (&catalog, 1); 134 setMrelFinal (&catalog, NULL, TRUE); 135 136 // uncomment for extra verbosity 137 // MARKTIME("setMrelFinal for "OFF_T_FMT" average "OFF_T_FMT" measure : %f sec\n", catalog.Naverage, catalog.Nmeasure, dtime); 138 // gettimeofday (&startTimer, NULL); // reset timer 139 140 // XXX if we want to have options for setting warp, chip, stack independently, we need to init only the desired ones 141 // NOTE flatcorr == NULL, but it should have been applied already by setphot 142 143 if (!UPDATE) { 144 dvo_catalog_unlock (&catalog); 145 free_tiny_values(&catalog); 146 dvo_catalog_free (&catalog); 147 freeImageBins (1, FALSE); 148 freeMosaicBins (1, FALSE); 149 freeGridBins (1); 150 continue; 151 } 152 153 if (VERBOSE) fprintf (stderr, "saving catalog %s\n", catalog.filename); 154 155 char history[128]; 156 struct timeval now; 157 gettimeofday (&now, (void *) NULL); 158 char *moddate = ohana_sec_to_date (now.tv_sec); 159 gfits_modify (&catalog.header, "RELPHOT", "%s", 1, moddate); 160 if (REPAIR_WARPS) { 161 snprintf (history, 128, "repair warp measure.imageID: %s", moddate); 162 gfits_modify_alt (&catalog.header, "HISTORY", "%S", 0, history); // adds a new entry 163 } 164 free (moddate); 165 166 // we can optionally convert output format here 167 // but it would be better to define a dvo crawler program to do this 168 // catalog.catformat = DVO_FORMAT_PS1_V1; 169 170 // modify the output format as desired (ignore current format on disk) 171 if (UPDATE_CATFORMAT) { 172 catalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT); 173 } 174 175 SetProtect (TRUE); 176 if (!dvo_catalog_save (&catalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", catalog.filename); exit (1); } 177 if (!dvo_catalog_unlock (&catalog)) { fprintf (stderr, "ERROR: failed to unlock %s\n", catalog.filename); exit (1); } 178 SetProtect (FALSE); 179 180 free_tiny_values(&catalog); 181 dvo_catalog_free (&catalog); 182 183 freeImageBins (1, FALSE); 184 freeMosaicBins (1, FALSE); 185 freeGridBins (1); 186 } 187 188 if (REPAIR_WARPS) { 189 FreeWarpGroups (); 190 FreeStackGroups (); 191 RepairWarpMeasuresCloseLogfile (); 192 } 32 reload_catalogs (skylist, hostID, hostpath); 193 33 194 34 freeImages(db.ftable.buffer); 35 freeGridBins (); 36 195 37 gfits_db_free (&db); 196 38 197 39 return (TRUE); 198 40 } 199 200 // CATDIR is supplied globally201 # define DEBUG 1202 int relphot_objects_parallel (SkyList *sky) {203 204 // launch the setphot_client jobs to the parallel hosts205 206 // load the list of hosts207 HostTable *table = HostTableLoad (CATDIR, sky->hosts);208 if (!table) {209 fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);210 exit (1);211 }212 213 if (BOUNDARY_TREE) {214 char *tmppath = abspath(BOUNDARY_TREE, DVO_MAX_PATH);215 free (BOUNDARY_TREE);216 BOUNDARY_TREE = tmppath;217 }218 219 int i;220 for (i = 0; i < table->Nhosts; i++) {221 222 // ensure that the paths are absolute path names223 char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);224 free (table->hosts[i].pathname);225 table->hosts[i].pathname = tmppath;226 227 // options / arguments that can affect relphot_client -update-objects:228 // VERBOSE, VERBOSE2229 // KEEP_UBERCAL230 // RESET (-reset)231 // TimeSelect -time232 // DophotSelect233 // (note that psfQF is applied rigidly at 0.85, as is the galaxy test)234 // MAG_LIM235 // SIGMA_LIM236 // ImagSelect, ImagMin, ImagMax237 // MaxDensityUse, MaxDensityValue238 239 char *command = NULL;240 strextend (&command, "relphot_client -update-objects");241 strextend (&command, "-hostID %d", table->hosts[i].hostID);242 strextend (&command, "-D CATDIR %s", CATDIR);243 strextend (&command, "-hostdir %s", table->hosts[i].pathname);244 strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);245 strextend (&command, "-statmode %s", STATMODE);246 strextend (&command, "-D CAMERA %s", CAMERA);247 strextend (&command, "-D STAR_TOOFEW %d", STAR_TOOFEW);248 strextend (&command, "-minerror %f", MIN_ERROR);249 250 if (VERBOSE) { strextend (&command, "-v"); }251 if (VERBOSE2) { strextend (&command, "-vv"); }252 if (RESET) { strextend (&command, "-reset"); }253 if (RESET_ZEROPTS) { strextend (&command, "-reset-zpts"); }254 if (REPAIR_WARPS) { strextend (&command, "-repair-warps"); }255 if (PRESERVE_PS1) { strextend (&command, "-preserve-ps1"); }256 if (IS_DIFF_DB) { strextend (&command, "-is-diff-db"); }257 if (UPDATE) { strextend (&command, "-update"); }258 if (!KEEP_UBERCAL) { strextend (&command, "-reset-ubercal"); }259 if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }260 if (BOUNDARY_TREE) { strextend (&command, "-boundary-tree %s", BOUNDARY_TREE); }261 if (SYNTH_ZERO_POINTS) { strextend (&command, "-synthphot-zpts %s", SYNTH_ZERO_POINTS); }262 if (USE_BASIC_CHECK) { strextend (&command, "-basic-image-search"); }263 if (USE_ALL_IMAGES) { strextend (&command, "-use-all-images"); }264 if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); }265 266 if (!(STAGES & STAGE_CHIP)) { strextend (&command, "-skip-chip"); }267 if (!(STAGES & STAGE_WARP)) { strextend (&command, "-skip-warp"); }268 if (!(STAGES & STAGE_STACK)) { strextend (&command, "-skip-stack"); }269 270 // if (SET_MREL_VERSION != 1) { strextend (&command, "-set-mrel-version %d", SET_MREL_VERSION); }271 272 fprintf (stderr, "command: %s\n", command);273 274 if (PARALLEL_MANUAL) {275 free (command);276 continue;277 }278 279 if (PARALLEL_SERIAL) {280 int status = system (command);281 if (status) {282 fprintf (stderr, "ERROR running relphot_client\n");283 exit (2);284 }285 } else {286 // launch the job on the remote machine (no handshake)287 int errorInfo = 0;288 int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);289 if (!pid) {290 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);291 exit (1);292 }293 table->hosts[i].pid = pid; // save for future reference294 }295 free (command);296 }297 298 if (PARALLEL_MANUAL) {299 fprintf (stderr, "run the relphot_client commands above. when these are done, hit return\n");300 getchar();301 }302 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {303 HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);304 }305 306 FreeHostTable (table);307 return TRUE;308 } -
trunk/Ohana/src/relphot/src/relphot_parallel_images.c
r41556 r41647 8 8 * update the unowned detections for owned objects from neighbor regions 9 9 * update the unowned objects for owned detections 10 11 * TGROUP and GRID corrections are not calculated. 10 12 */ 11 13 … … 39 41 40 42 initImages (image, NULL, Nimage); 41 42 // load the flat correction table (if defined)43 // we no longer need to do this: the flatcorrection is now saved in measure.Mflat44 # if (0)45 char flatcorrfile[256];46 sprintf (flatcorrfile, "%s/flatcorr.fits", CATDIR);47 FlatCorrectionTable *flatcorr = FlatCorrectionLoad (flatcorrfile, VERBOSE);48 # endif49 FlatCorrectionTable *flatcorr = NULL;50 43 51 44 // UserPatch.Rmin,Rmax may have range from a few degrees < 0.0 to few degrees > 360.0. … … 88 81 setExclusions (catalog, Ncatalog, TRUE); 89 82 90 global_stats (catalog, Ncatalog, flatcorr,0);83 global_stats (catalog, Ncatalog, 0); 91 84 92 85 if (PLOTSTUFF) { … … 101 94 102 95 // set the mean stellar mags given the measurements and the image calibrations 103 setMrel (catalog, Ncatalog , flatcorr);96 setMrel (catalog, Ncatalog); 104 97 105 98 // share mean mags for objects at the boundary (number of unowned meas > 0) … … 112 105 113 106 // set the image (Mcal) and mosaic (Mmos) zero point offsets given the mean mags and measurements 114 setMcal (catalog, flatcorr); 115 setMmos (catalog, flatcorr); 116 // setMgrp (catalog, FALSE, flatcorr); XXX think this through: this may not make sense for tgroups 107 setMcal (catalog); 108 setMmos (catalog); 117 109 MARKTIME("-- set Mrel, Mcal, Mmos, Mgrid : %f sec\n", dtime); 118 110 … … 124 116 client_logger_message ("slurped image data : loop %d \n", i); 125 117 126 global_stats (catalog, Ncatalog, flatcorr,i);118 global_stats (catalog, Ncatalog, i); 127 119 128 SetZeroPointModes ( );120 SetZeroPointModes (catalog, Ncatalog); 129 121 MARKTIME("-- finished loop %d: %f sec\n", i, dtime); 130 122 } … … 147 139 148 140 setMcalFromMosaics (); // copy per-mosaic calibrations to the images 149 // XXX keep? setMcalFromTGroups (); // copy per-tgroup calibrations to the images150 141 151 142 share_image_mags (regionHosts, -1); … … 161 152 freeImageBins(Ncatalog, TRUE); 162 153 freeMosaicBins (Ncatalog, TRUE); 163 freeGridBins (Ncatalog);164 154 freeImages((char *)image); 165 155 free (image); -
trunk/Ohana/src/relphot/src/relphot_parallel_regions.c
r41556 r41647 14 14 exit (2); 15 15 } 16 17 // load the flat correction table (if defined)18 # if (0)19 char flatcorrfile[256];20 sprintf (flatcorrfile, "%s/flatcorr.fits", CATDIR);21 FlatCorrectionTable *flatcorr = FlatCorrectionLoad (flatcorrfile, VERBOSE);22 # endif23 FlatCorrectionTable *flatcorr = NULL;24 16 25 17 // register database handle with shutdown procedure … … 81 73 82 74 /* update catalogs (in parallel) */ 83 reload_catalogs (skylist, flatcorr,0, NULL);75 reload_catalogs (skylist, 0, NULL); 84 76 85 77 // save the changes to the image parameters -
trunk/Ohana/src/relphot/src/select_images.c
r41601 r41647 103 103 if (!(i % 300000)) fprintf (stderr, "."); 104 104 105 // XXX I am just going for force this for the moment: 106 // goto found_it; 107 108 /* exclude images by photcode (we are not doing this, but I'm not sure why) */ 105 // only include active photcodes in the analysis 109 106 if (timage[i].photcode) { 110 107 int Ns = GetActivePhotcodeIndex (timage[i].photcode); -
trunk/Ohana/src/relphot/src/setMrelCatalog.c
r41561 r41647 60 60 int useOLS = TRUE; // chosen based on iteration below 61 61 62 int setMrel _catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {62 int setMrelCatalog (Catalog *catalog, int Nc, int isSetMrelFinal, SetMrelInfo *results, int Nsecfilt) { 63 63 64 64 off_t j; … … 75 75 76 76 if (STAGES & STAGE_CHIP) { 77 setMrelAverageExposure (&catalog[Nc], Nc, j, Nsecfilt, isSetMrelFinal, flatcorr,results);77 setMrelAverageExposure (&catalog[Nc], Nc, j, Nsecfilt, isSetMrelFinal, results); 78 78 } 79 79 80 80 // only apply Stack operation on setMrelFinal in first pass 81 81 if (isSetMrelFinal && (STAGES & STAGE_STACK) && !IS_DIFF_DB) { 82 setMrelAverageStack (&catalog[Nc], Nc, j, Nsecfilt , flatcorr);82 setMrelAverageStack (&catalog[Nc], Nc, j, Nsecfilt); 83 83 } 84 84 85 85 // only measure force-warp mean values if issetMrelFinal (make it optional?) 86 86 if (isSetMrelFinal && (STAGES & STAGE_WARP)) { 87 setMrelAverageForcedWarp (&catalog[Nc], Nc, j, Nsecfilt, flatcorr,results);87 setMrelAverageForcedWarp (&catalog[Nc], Nc, j, Nsecfilt, results); 88 88 } 89 89 } … … 113 113 114 114 // set mean of chip measurements (selected by photcode range for now): 115 int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, FlatCorrectionTable *flatcorr,SetMrelInfo *results) {115 int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, SetMrelInfo *results) { 116 116 117 117 int Nsec; … … 225 225 } 226 226 227 /* some things to note here: 228 229 Mcal, Mmos, Mgrid are only relevant (non-zero) during the relphot_images and 230 relphot_parallel_images analysis steps. For the final output steps (setMrelFinal), 231 these are turned off 232 233 During the image analysis, Mflat is the prior stored value while Mgrid is the new 234 measurement. In the final output step, Mgrid is transferred to Mflat and zero 235 236 On the final calculation of Mrel, the value of Mgrid has been applied to Mflat, but 237 it has not been removed from the GridOps.c structures. In order to avoid 238 double-counting, we need to skip Mgrid on the final calculation. 239 */ 240 227 241 // ** Choose the calibration (depends on the mode : do I have an image reference or not?) 228 242 float Mcal = 0.0, Mmos = 0.0, Mgrid = 0.0, Mflat = 0.0, Mgrp = 0.0; … … 233 247 // data for which the associated image has not been loaded (probably because of 234 248 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 235 Mmos = Mgrid = 0;236 249 Mcal = measureT[k].McalPSF; // check that this is zero for loaded REF value 237 250 } else { 238 // getMcal returns image[].Mcal ; note the flat-field correction is stored in measure.Mflat251 // getMcal returns image[].Mcal 239 252 Mcal = getMcal (meas, cat, MAG_CLASS_PSF); 240 253 if (isnan(Mcal)) SKIP_THIS_MEAS(Ncal); 241 Mmos = getMmos (meas, cat); 242 if (isnan(Mmos)) SKIP_THIS_MEAS(Nmos); 243 Mgrp = getMgrp (meas, cat, measureT[k].airmass, &dMgrp); 244 if (isnan(Mgrp)) SKIP_THIS_MEAS(Ngrp); 245 Mgrid = getMgrid (meas, cat); 246 if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid); 254 255 // the flat-field correction is stored in measure.Mflat 247 256 Mflat = isnan (measureT[k].Mflat) ? 0.0 : measureT[k].Mflat; 257 258 // see note above re: final output vs image analysis 259 if (!isSetMrelFinal) { 260 Mmos = getMmos (meas, cat); 261 if (isnan(Mmos)) SKIP_THIS_MEAS(Nmos); 262 Mgrp = getMgrp (meas, cat, measureT[k].airmass, &dMgrp); 263 if (isnan(Mgrp)) SKIP_THIS_MEAS(Ngrp); 264 Mgrid = getMgridTiny (&measureT[k]); 265 if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid); 266 } 248 267 } 249 268 … … 269 288 float dMap = NAN; 270 289 271 // XXX I am not convinced the sign on Mflat here is correct272 float Moff = M flat + Mcal + Mmos + Mgrp + Mgrid;290 // This definition is consistent with PhotRel: Mrel = Msys - Mcal - Mflat 291 float Moff = Mcal + Mmos + Mgrp + Mgrid + Mflat; 273 292 274 293 if (isSetMrelFinal) { … … 349 368 for (Nsec = 0; Nsec < Nsecfilt; Nsec++) { 350 369 351 // if we detected this object in PS1, or do not request -preserve-ps1, keep the mean photometry values 370 // -preserve-ps1 means keep an existing average PS1 value 371 // if we did not detect this object in PS1, or do not request -preserve-ps1, keep the mean photometry values 352 372 if (!PRESERVE_PS1 || !(secfilt[Nsec].flags & ID_SECF_HAS_PS1)) { 353 373 dvo_secfilt_init (&secfilt[Nsec], SECFILT_RESET_CHIP); // this does not reset astrometry or STACK bits … … 364 384 } 365 385 386 // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps: 387 // NOTE: This test only applies if this bit was set by an earlier analysis 366 388 if (PRESERVE_PS1 && (secfilt[Nsec].flags & ID_SECF_HAS_PS1)) continue; 367 // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps:368 389 369 390 // XXX hardwired grizy = (01234) JHK = (567) w = (8) … … 416 437 int NrankingPSF = useOLS ? magStatsByRanking (&results->psfData[Nsec], psfstats) : magStatsByRankingIRLS (&results->psfData[Nsec], psfstats); 417 438 if (NrankingPSF < Nminmeas) { 418 secfilt[Nsec].flags |= ID_ OBJ_FEW;439 secfilt[Nsec].flags |= ID_SECF_STAR_FEW; 419 440 } else { 420 441 secfilt[Nsec].MpsfChp = psfstats->mean; 421 442 secfilt[Nsec].dMpsfChp = psfstats->error; 422 443 secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN; 444 secfilt[Nsec].flags &= ~ID_SECF_STAR_FEW; 423 445 } 424 446 … … 552 574 // measure->McalAPER to image->McalPSF for chips and warps, but not stacks 553 575 554 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt , FlatCorrectionTable *flatcorr) {576 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt) { 555 577 556 578 // we are guaranteed to have average, measure, secfilt … … 562 584 SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt]; 563 585 564 float McalPSF = 0, McalAPER = 0 , Mmos = 0, Mgrid = 0;586 float McalPSF = 0, McalAPER = 0; 565 587 566 588 // set the primary projection cell and skycell for this coordinate … … 604 626 605 627 // reset all stack-related values for this secfilt: 606 secfilt[Nsec].stackBestOff = -1; 607 secfilt[Nsec].stackPrmryOff = -1; 608 secfilt[Nsec].FpsfStk = NAN; 609 secfilt[Nsec].dFpsfStk = NAN; 610 secfilt[Nsec].FkronStk = NAN; 611 secfilt[Nsec].dFkronStk = NAN; 612 secfilt[Nsec].FapStk = NAN; 613 secfilt[Nsec].dFapStk = NAN; 614 secfilt[Nsec].MpsfStk = NAN; 615 secfilt[Nsec].MkronStk = NAN; 616 secfilt[Nsec].MapStk = NAN; 617 secfilt[Nsec].Nstack = 0; 618 secfilt[Nsec].NstackDet = 0; 619 secfilt[Nsec].flags &= ~ID_SECF_STACK_FLAGS; // reset the stack flags 628 dvo_secfilt_init (&secfilt[Nsec], SECFILT_RESET_STACK); 620 629 621 630 for (off_t k = 0; k < Nmeasure; k++) { … … 638 647 haveStack = TRUE; 639 648 haveStackObject = TRUE; 640 641 // if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);642 649 643 650 int isPrimary = FALSE; … … 726 733 McalPSF = measure[meas].McalPSF; // check that this is zero for loaded REF value 727 734 McalAPER = McalPSF; // check that this is zero for loaded REF value 728 Mmos = 0.0;729 Mgrid = 0.0;730 735 } else { 731 736 McalPSF = getMcal (measSeq, cat, MAG_CLASS_PSF); 732 737 McalAPER = USE_MCAL_PSF_FOR_STACK_APER ? getMcal (measSeq, cat, MAG_CLASS_PSF) : getMcal (measSeq, cat, MAG_CLASS_KRON); 733 Mmos = getMmos (measSeq, cat);734 Mgrid = getMgrid (measSeq, cat);735 // XXX can Mmos and Mgrid exist for stacks?736 738 } 737 739 … … 769 771 // get the zero point for the selected image 770 772 // Use a different zero point for the PSF-like and APERTURE-like magnitudes 771 float zpPSF = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalPSF + Mmos + Mgrid);772 float zpAPER = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalAPER + Mmos + Mgrid);773 float zpPSF = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - McalPSF; 774 float zpAPER = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - McalAPER; 773 775 774 776 // zpFactor to go from instrumental flux to Janskies … … 884 886 // chips and warps, but not stacks 885 887 886 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) { 887 OHANA_UNUSED_PARAM(flatcorr); 888 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, SetMrelInfo *results) { 888 889 889 890 // we are guaranteed to have average, measure, secfilt -
trunk/Ohana/src/relphot/src/setMrelFinal.c
r40291 r41647 5 5 // output dbFlags values 6 6 7 void setMrelFinal (Catalog *catalog, FlatCorrectionTable *flatcorr,int simpleAverage) {7 void setMrelFinal (Catalog *catalog, int simpleAverage) { 8 8 9 9 off_t i; … … 11 11 int Nsecfilt = GetPhotcodeNsecfilt (); 12 12 13 /*** RESET photometry flags and Mcal values ***/ 14 if (RESET) { 15 // flags used by the photometry analysis (excluding UBERCAL) 16 unsigned int PHOTOM_FLAGS = 17 ID_MEAS_NOCAL | // detection ignored for this analysis (photcode, time range) 18 ID_MEAS_POOR_PHOTOM | // detection is photometry outlier 19 ID_MEAS_SKIP_PHOTOM | // detection was ignored for photometry measurement 20 ID_MEAS_AREA | // detetion was outside acceptable area of device 21 ID_MEAS_SYNTH_MAG | // magnitude is synthetic 22 ID_MEAS_STACK_PRIMARY | // this stack measurement is in the primary skycell 23 ID_MEAS_STACK_PHOT_SRC; // this measurement supplied the stack photometry 24 25 // ID_MEAS_PHOTOM_UBERCAL -- externally-supplied zero point from ubercal analysis 26 // this is set by 'setphot', do not reset here 27 28 // flags used by the photometry analysis (excluding UBERCAL) 29 // unsigned int secfiltFlags = 30 // ID_PHOTOM_PASS_0 | // average measured at pass 0 31 // ID_PHOTOM_PASS_1 | // average measured at pass 1 32 // ID_PHOTOM_PASS_2 | // average measured at pass 2 33 // ID_PHOTOM_PASS_3 | // average measured at pass 3 34 // ID_PHOTOM_PASS_4 | // average measured at pass 3 35 // ID_SECF_USE_SYNTH | // average measured at pass 3 36 // ID_SECF_USE_UBERCAL | // average measured at pass 3 37 // ID_SECF_OBJ_EXT; // average measured at pass 3 38 39 // XXX I should really deprecate the concept of applying the average 40 // calculation to a limited set of photcodes. 41 // for now, just do all photcodes here ( 42 // as it stands, only stacks are limited by photcode; mean exp and forced warp 43 // are applied to all Nsecfilt 44 45 for (i = 0; i < catalog[0].Naverage; i++) { 46 int Ns; 47 for (Ns = 0; Ns < Nsecfilt; Ns++) { 48 49 off_t N = Nsecfilt*i+Ns; 50 dvo_secfilt_init (&catalog[0].secfilt[N], SECFILT_RESET_ALL); 51 52 off_t m = catalog[0].average[i].measureOffset; 53 off_t j; 54 for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) { 55 56 /* select measurements by time */ 57 if (TimeSelect) { 58 if (catalog[0].measure[m].t < TSTART) continue; 59 if (catalog[0].measure[m].t > TSTOP) continue; 60 } 61 62 // only reset Mcal for measures with a matching image 63 // do not reset Mcal for ubercal images unless explicitly requested 64 65 if (catalog[0].measure[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) { 66 if (!KEEP_UBERCAL) { 67 catalog[0].measure[m].McalPSF = 0.0; 68 catalog[0].measure[m].McalAPER = 0.0; 69 catalog[0].measure[m].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL; 70 } 71 } else { 72 if (RESET_ZEROPTS && (getImageEntry (m, 0) >= 0)) { 73 catalog[0].measure[m].McalPSF = 0.0; 74 catalog[0].measure[m].McalAPER = 0.0; 75 } 76 } 77 catalog[0].measure[m].dbFlags &= ~PHOTOM_FLAGS; 78 } 79 } 80 } 81 } 82 83 // this sets flags in the measureT element, not the measure element 13 ResetAverageAndMeasure (catalog); 14 15 // This sets ID_MEAS flags in the measureT element, not the measure element 16 // These bits are thus ephemeral and not saved. 84 17 setExclusions (catalog, 1, VERBOSE); /* mark by area */ 85 18 … … 92 25 } 93 26 94 for (i = 0; i < catalog[0].Naverage; i++) {95 catalog[0].average[i].psfQF = NAN; // force recalculation below96 catalog[0].average[i].psfQFperf = NAN; // force recalculation below97 catalog[0].average[i].stargal = NAN; // force recalculation below98 catalog[0].average[i].photFlagsUpper = 0; // reset (will be re-calculated here)99 catalog[0].average[i].photFlagsLower = 0; // reset (will be re-calculated here)100 catalog[0].average[i].NwarpOK = 0; // reset (will be re-calculated here)101 }102 103 // XXX make this optional? (do not clean for -averages?)104 // XXX : for the moment, disable clean_measures105 if (!simpleAverage && FALSE) clean_measures (catalog, 1, TRUE, flatcorr); /* mark outliers ID_MEAS_POOR_PHOTOM */106 107 27 ALLOCATE (catalog[0].measureRank, char, catalog[0].Nmeasure); 108 28 setMeasureRank (catalog); 109 setMrelOutput (catalog, 1, flatcorr); // sets the values secfilt.MpsfChp = <measure.M + measure.Mflat - image.Mcal>110 setMcalOutput (catalog, 1, flatcorr); // sets measure.Mcal = image.Mcal111 29 112 /* clear ID_OBJ_POOR, ID_OBJ_FEW values before writing ??? */ 113 /* ID_MEAS_NOCAL is an internal bit, so it should be cleared */ 114 // XXX eventually: move these internal flags to an internal-only catalog->FOO element (like found) 115 for (i = 0; i < catalog[0].Naverage; i++) { 116 catalog[0].average[i].flags &= ~ID_OBJ_FEW; 117 catalog[0].average[i].flags &= ~ID_OBJ_POOR; 118 off_t j; 119 for (j = 0; j < Nsecfilt; j++) { 120 catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_OBJ_FEW; 121 catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_OBJ_POOR; 122 } 123 off_t m = catalog[0].average[i].measureOffset; 124 for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) { 125 catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL; 126 } 127 } 30 setMflatFromGrid (catalog); // Mgrid is used to set Mflat; Mgrid is the ignored in setMrelOutput / setMrelCatalog 31 setMrelOutput (catalog, 1); // sets the values secfilt.MpsfChp = <measure.M - image.Mcal - measure.Mflat> 32 setMcalOutput (catalog, 1); // sets measure.Mcal = image.Mcal 128 33 } 129 130 /* ID_MEAS_SKIP marks measurements which were not used to calculate Mrel */131 // For each star & photcode, we are selecting the measurements to use in the average132 // photometry value. This function is called several times, lowering the bar to133 // acceptance on each pass. The rejections at the different passes are:134 135 // 0 : only use measurements thought to be GOOD (photflags not POOR or BAD)136 // 1 : accept measurements thought to be POOR based on photflags137 // 2 : accept the measurements marked as outliers; accept images marked as outliers138 // 3 : accept measurements thought to be BAD based on photflags139 // 4 : accept the measurements outside of the instrumental magnitude limits (eg, SAT)140 141 // XXX if I'm reading this correctly, passes 0, 1, 2 are identical & accept all142 // non-outliers with Imag range143 34 144 35 // int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure) { … … 161 52 // } 162 53 163 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure); 164 165 void skip_measurements (Catalog *catalog, int pass, FlatCorrectionTable *flatcorr) { 166 167 off_t i, k, m; 168 off_t Ntot, Ntry, Nkeep, Nskip; 169 float mag; 170 171 int Nsecfilt = GetPhotcodeNsecfilt (); 172 173 Ntot = Ntry = Nskip = Nkeep = 0; 174 175 /* allow measures from images marked POOR and FEW */ 176 if (pass >= 3) IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL; 177 178 /* allow measures marked as outliers (POOR) and off image region (AREA) */ 179 if (pass >= 3) { 180 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_SKIP_PHOTOM; 181 } else { 182 MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA; 183 } 184 185 /* mark measures which should be ignored on this pass */ 186 for (i = 0; i < catalog[0].Naverage; i++) { 187 Ntot += catalog[0].average[i].Nmeasure; 188 189 if (FALSE && (catalog[0].average[i].objID == 0x46a4) && (catalog[0].average[i].catID == 0xf40e)) { 190 fprintf (stderr, "test obj\n"); 191 print_measure_set (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], catalog[0].measure); 192 } 193 194 // mark measurements for each secfilt separately 195 int Ns; 196 for (Ns = 0; Ns < Nphotcodes; Ns++) { 197 198 int thisCode = photcodes[Ns][0].code; 199 int Nsec = GetPhotcodeNsec(thisCode); 200 201 /* star/photcodes already calibrated */ 202 if (catalog[0].found_t[Nsecfilt*i+Nsec]) continue; 203 204 m = catalog[0].average[i].measureOffset; 205 for (k = 0; k < catalog[0].average[i].Nmeasure; k++, m++) { 206 Ntry++; 207 208 // skip measurements not related to this photcode 209 PhotCode *code = GetPhotcodebyCode (catalog[0].measure[m].photcode); 210 if (!code) continue; 211 if (code->equiv != thisCode) continue; 212 213 // skip measurements by time range (mark as skipped for this secfilt) 214 // XXX note that this is a bit dangerous : some objects may never get calibrated 215 if (TimeSelect) { 216 if (catalog[0].measure[m].t < TSTART) goto skip; 217 if (catalog[0].measure[m].t > TSTOP) goto skip; 218 } 219 220 // we now have a measurement relavant to this photcode (and time range) 221 222 // clear SKIP for all measures at first 223 catalog[0].measureT[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 224 catalog[0].measure [m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 225 226 // skip measurements from BAD images and mosaics (not REF mags) 227 // do NOT skip measurements without a matching image (REF mags) 228 off_t Nim = getImageEntry (m, 0); 229 if (Nim > -1) { 230 if (isnan(getMcal (m, 0, MAG_CLASS_PSF))) goto skip; 231 if (isnan(getMmos (m, 0))) goto skip; 232 } 233 234 // PASS 4 : skip measurements by inst mag limit (not REF mags) 235 if ((pass < 4) && ImagSelect) { 236 if (Nim > -1) { 237 mag = PhotInst (&catalog[0].measure[m], MAG_CLASS_PSF); 238 if (mag < ImagMin) goto skip; 239 if (mag > ImagMax) goto skip; 240 } 241 } 242 243 // PASS 3 : accept bad measurements (eg, SAT, CR), internal outliers 244 if (pass < 3) { 245 if (catalog[0].measure[m].photFlags & code->photomBadMask) goto skip; 246 if ((catalog[0].measure[m].photcode > 10000) && (catalog[0].measure[m].photcode < 10500)) { 247 if (catalog[0].measure[m].psfQF < 0.85) goto skip; 248 } 249 } 250 251 // PASS 2 : (no additional cut) 252 253 // PASS 1 : accept poor measurements as well (eg, POOR FIT, etc) 254 if ((pass < 1) && (catalog[0].measure[m].photFlags & code->photomPoorMask)) goto skip; 255 256 // PASS 0 : skip poor, outlier, bad measurements as well (eg, POOR FIT, etc) 257 258 Nkeep ++; 259 260 continue; 261 262 skip: 263 catalog[0].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM; 264 catalog[0].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM; 265 Nskip ++; 266 } 267 } 268 } 269 if (VERBOSE) fprintf (stderr, "pass %d, Ntot: "OFF_T_FMT", Ntry: "OFF_T_FMT", Nskip: "OFF_T_FMT", Nkeep: "OFF_T_FMT"\n", 270 pass, Ntot, Ntry, Nskip, Nkeep); 271 } 272 54 // This function is only called for the final output step. By this point, we have 55 // propagated the mosaic and tgroup flags to each image. 273 56 void setMeasureRank (Catalog *catalog) { 274 57 275 58 int i; 276 59 277 // make these global278 int IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;279 int IMAGE_POOR = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;280 int MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_SKIP_PHOTOM;281 int MEAS_POOR = ID_MEAS_POOR_PHOTOM | ID_MEAS_AREA;282 283 60 Measure *measure = catalog[0].measure; 284 MeasureTiny *measureT = catalog[0].measureT;285 61 char *measureRank = catalog[0].measureRank; 286 62 … … 289 65 measureRank[i] = 11; // start at a low rank 290 66 291 // clear SKIP for all measures at first 292 measureT[i].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 293 measure [i].dbFlags &= ~ID_MEAS_SKIP_PHOTOM; 294 295 // skip measurements without a valid photcode 67 // measurements without a valid photcode have lowest rank (should not be used anyway) 296 68 PhotCode *code = GetPhotcodebyCode (measure[i].photcode); 297 69 if (!code) continue; … … 299 71 // measurements outside time range have poor rank 300 72 if (TimeSelect) { 301 if (measure[i].t < TSTART) { measureRank[i] = 10; continue; }302 if (measure[i].t > TSTOP) { measureRank[i] = 10; continue; }73 if (measure[i].t < TSTART) { measureRank[i] = 10; continue; } 74 if (measure[i].t > TSTOP) { measureRank[i] = 10; continue; } 303 75 } 304 76 305 // measurements from BAD images and mosaics (not REF mags)306 off_t Nim = getImageEntry (i, 0);77 // Nim < 0 for REF mags, imageFlags have bits for IMAGE, MOSAIC, NIGHT 78 off_t Nim = getImageEntry (i, 0); 307 79 int imageFlags = getImageFlags (i, 0); 308 int mosaicFlags = getMosaicFlags (i, 0);309 80 310 81 if (Nim > -1) { 311 if (imageFlags & IMAGE_BAD) { measureRank[i] = 9; continue; }312 313 if (mosaicFlags & IMAGE_BAD) { measureRank[i] = 9; continue; }314 315 82 // measurements ranked by inst mag limit (not REF mags) 316 83 if (ImagSelect) { 317 84 float mag = PhotInst (&measure[i], MAG_CLASS_PSF); 318 if (mag < ImagMin) { measureRank[i] = 8; continue; }319 if (mag > ImagMax) { measureRank[i] = 8; continue; }85 if (mag < ImagMin) { measureRank[i] = 9; continue; } 86 if (mag > ImagMax) { measureRank[i] = 9; continue; } 320 87 } 321 88 } 322 89 323 // RANK 1 : BAD photFlags 324 if (measure[i].dbFlags & MEAS_BAD) { measureRank[i] = 7; continue; } 325 326 // RANK 3 : BAD photFlags (eg, SAT, CR), internal outliers 327 if (measure[i].photFlags & code->photomBadMask) { measureRank[i] = 6; continue; } 328 90 // RANK 8 : Poor image 329 91 if (Nim > -1) { 330 if (imageFlags & IMAGE_POOR) { measureRank[i] = 5; continue; } 331 if (mosaicFlags & IMAGE_POOR) { measureRank[i] = 5; continue; } 92 if (imageFlags & ID_IMAGE_PHOTOM_POOR) { measureRank[i] = 8; continue; } 332 93 } 333 94 334 // RANK 2 : psfQF value 335 if (!isfinite(measure[i].psfQF) || measure[i].psfQF < 0.85) { measureRank[i] = 4; continue; } 95 // RANK 7 : BAD photFlags (eg, SAT, CR), internal outliers 96 if (measure[i].photFlags & code->photomBadMask) { measureRank[i] = 7; continue; } 97 98 // RANK 6 : bad psfQF value 99 if (!isfinite(measure[i].psfQF) || measure[i].psfQF < 0.85) { measureRank[i] = 6; continue; } 336 100 337 // RANK 1 : POOR photFlags338 if (measure[i].dbFlags & MEAS_POOR) { measureRank[i] = 3; continue; }101 // RANK 5 : not in valid chip region 102 if (measure[i].dbFlags & ID_MEAS_AREA) { measureRank[i] = 5; continue; } 339 103 340 // RANK 1: POOR photFlags341 if (measure[i].photFlags & code->photomPoorMask) { measureRank[i] = 2; continue; }104 // RANK 4 : POOR photFlags 105 if (measure[i].photFlags & code->photomPoorMask) { measureRank[i] = 4; continue; } 342 106 343 // RANK 1 :psfQFperfect value344 if (!isfinite(measure[i].psfQFperf) || measure[i].psfQFperf < 0.85) { measureRank[i] = 1; continue; }107 // RANK 3 : bad psfQFperfect value 108 if (!isfinite(measure[i].psfQFperf) || measure[i].psfQFperf < 0.85) { measureRank[i] = 3; continue; } 345 109 110 // RANK 2 : Poor mosaic 111 if (Nim > -1) { 112 if (imageFlags & ID_IMAGE_MOSAIC_POOR) { measureRank[i] = 2; continue; } 113 } 114 115 // RANK 1 : Poor night 116 if (Nim > -1) { 117 if (imageFlags & ID_IMAGE_NIGHT_POOR) { measureRank[i] = 1; continue; } 118 } 346 119 // RANK 0 : perfect measurement: 347 120 measureRank[i] = 0; -
trunk/Ohana/src/relphot/test
-
Property svn:ignore
set to
GSCregions.tbl
dvo.photcodes
ptolemy.rc
tap.log
tgroups.dat
.dvo
.mana
-
Property svn:ignore
set to
Note:
See TracChangeset
for help on using the changeset viewer.
