IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 7, 2025, 3:07:30 PM (17 months ago)
Author:
eugene
Message:

modify grid correction to use median of the data vectors

Location:
trunk/Ohana/src/relphot
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/Makefile

    r42112 r42788  
    8282$(SRC)/setExclusions.$(ARCH).o   \
    8383$(SRC)/setMrelFinal.$(ARCH).o    \
    84 $(SRC)/setMrelCatalog.$(ARCH).o          \
    85 $(SRC)/BoundaryTreeOps.$(ARCH).o         \
     84$(SRC)/setMrelCatalog.$(ARCH).o   \
     85$(SRC)/BoundaryTreeOps.$(ARCH).o  \
     86$(SRC)/DumpAllMags.$(ARCH).o      \
    8687$(SRC)/write_coords.$(ARCH).o
    8788
  • trunk/Ohana/src/relphot/include/relphot.h

    r42389 r42788  
    160160  float dY; // bin = int(Ychip * dY), dY = Ny / NyChip
    161161  // NxChip, NyChip = 4900,4900 for now
     162
     163    int **nAlloc; // allocated vector length
     164  double ***dMval; // values used to calculate corrections
    162165} GridCorrectionType;
    163166
     
    607610void          initGridBins        PROTO((void));
    608611GridCorrectionType *getGridCorrByCode PROTO((int code));
     612GridCorrectionType *newGridCorrByCode PROTO((int code));
    609613GridCorrectionType *getGridCorrNext   PROTO((int *Nlast));
    610614int           GridCorrectionSave  PROTO((void));
     
    894898double get_median_zpt_tgroups (short photcode);
    895899void   set_median_zpt_tgroups (short photcode, double zpt);
     900
     901int DumpAllMags(char *filename, Catalog *catalog, int Ncatalog);
  • trunk/Ohana/src/relphot/src/GridIO.c

    r41647 r42788  
    151151
    152152    if (!gfits_scan (&header, "PHOTCODE", "%d", 1, &photcode))    myAbort ("failed to get PHOTCODE");
    153     GridCorrectionType *GridCorr = getGridCorrByCode (photcode);
     153    GridCorrectionType *GridCorr = newGridCorrByCode (photcode);
    154154    GridCorr->photcode = photcode;
    155155
  • trunk/Ohana/src/relphot/src/GridOps.c

    r41664 r42788  
    3030# define NX_CHIP_DEFAULT 1000
    3131# define NY_CHIP_DEFAULT 1000
    32 # define NX_BIN_DEFAULT 2
    33 # define NY_BIN_DEFAULT 2
     32# define NX_BIN_DEFAULT 4
     33# define NY_BIN_DEFAULT 4
    3434
    3535void initGridBins (void) {
     
    7676      if (GridCorr[code]->dMgrid) FREE (GridCorr[code]->dMgrid[ix]);
    7777      if (GridCorr[code]->nMgrid) FREE (GridCorr[code]->nMgrid[ix]);
     78      if (GridCorr[code]->nAlloc) FREE (GridCorr[code]->nAlloc[ix]);
     79
     80      // dMval is a 2D array of vectors
     81      for (int iy = 0; iy < GridCorr[code]->Ny; iy++) {
     82        FREE (GridCorr[code]->dMval[ix][iy]);
     83      }
     84      FREE (GridCorr[code]->dMval[ix]);
    7885    }     
    7986
     
    8188    FREE (GridCorr[code]->dMgrid);
    8289    FREE (GridCorr[code]->nMgrid);
     90    FREE (GridCorr[code]->nAlloc);
     91    FREE (GridCorr[code]-> dMval);
    8392
    8493    FREE(GridCorr[code]);
     
    109118}
    110119
    111 GridCorrectionType *getGridCorrByCode (int code) {
     120// generate a new GridCorr structure in the array
     121GridCorrectionType *newGridCorrByCode (int code) {
    112122
    113123  if (GridCorr == NULL) return NULL;
     
    116126  if (code <          0) return NULL;
    117127
     128  myAssert (GridCorr[code] == NULL, "oops, should not already be allocated!");
    118129  ALLOCATE(GridCorr[code], GridCorrectionType, 1)
     130  GridCorrectionType *result = GridCorr[code];
     131  return result;
     132}
     133
     134// return the GridCode structure corresponding to 'code'
     135GridCorrectionType *getGridCorrByCode (int code) {
     136
     137  if (GridCorr == NULL) return NULL;
     138
     139  if (code >= NGridCorr) return NULL;
     140  if (code <          0) return NULL;
     141
    119142  GridCorrectionType *result = GridCorr[code];
    120143  return result;
     
    163186    // we are normally accessing this array randomly, so there is no advantage to
    164187    // doing Mgrid[y][x] vs Mgrid[x][y]
     188    ALLOCATE (GridCorr[code]-> dMval, double **, NX_BIN);
    165189    ALLOCATE (GridCorr[code]-> Mgrid, float *, NX_BIN);
    166190    ALLOCATE (GridCorr[code]->dMgrid, float *, NX_BIN);
    167191    ALLOCATE (GridCorr[code]->nMgrid,   int *, NX_BIN);
     192    ALLOCATE (GridCorr[code]->nAlloc,   int *, NX_BIN);
    168193    for (int ix = 0; ix < NX_BIN; ix++) {
    169194      ALLOCATE (GridCorr[code]-> Mgrid[ix], float, NY_BIN);
    170195      ALLOCATE (GridCorr[code]->dMgrid[ix], float, NY_BIN);
    171196      ALLOCATE (GridCorr[code]->nMgrid[ix],   int, NY_BIN);
     197      ALLOCATE (GridCorr[code]->nAlloc[ix],   int, NY_BIN);
     198
     199      // when we first allocate this array, set the elements to 0 (NULL)
     200      // these arrays will be allocated or reallocated in resetMgrid
     201      ALLOCATE_ZERO (GridCorr[code]-> dMval[ix], double *, NX_BIN);
    172202    }     
    173203  }
     
    190220        GridCorr[code]->dMgrid[ix][iy] = 0.0;
    191221        GridCorr[code]->nMgrid[ix][iy] =   0;
     222        GridCorr[code]->nAlloc[ix][iy] = 100;
     223
     224        // allocate or reset vector length to default
     225        if (GridCorr[code]->dMval[ix][iy]) {
     226          REALLOCATE (GridCorr[code]->dMval[ix][iy], double, GridCorr[code]->nAlloc[ix][iy]);
     227        } else {
     228          ALLOCATE (GridCorr[code]->dMval[ix][iy], double, GridCorr[code]->nAlloc[ix][iy]);
     229        }
    192230      }
    193231    }     
     
    263301        if (fabs(dM) > 0.5) continue;
    264302
    265         grid-> Mgrid[ix][iy] += dM;
    266         grid->dMgrid[ix][iy] += dM*dM;
     303        int ival = grid->nMgrid[ix][iy];
     304        grid-> dMval[ix][iy][ival] = dM;
    267305        grid->nMgrid[ix][iy] ++;
     306        CHECK_REALLOCATE (grid-> dMval[ix][iy], double, grid->nAlloc[ix][iy], grid->nMgrid[ix][iy], 100);
     307
     308        /* XXX old code to calculate simple means:
     309           grid-> Mgrid[ix][iy] += dM;
     310           grid->dMgrid[ix][iy] += dM*dM;
     311           grid->nMgrid[ix][iy] ++;
     312        */
    268313      }
    269314    }
    270315  }
     316
     317  StatType stats;
     318  liststats_setmode (&stats, "MEDIAN");
     319
     320  // now calculate Mgrid, dMgrid, nMgrid from Sum, Sum, Npt
     321  for (int code = 0; code < NGridCorr; code++) {
     322    if (!GridCorr[code]) continue;
     323
     324    for (int ix = 0; ix < GridCorr[code]->Nx; ix++) {
     325      for (int iy = 0; iy < GridCorr[code]->Ny; iy++) {
     326
     327        // cells without sufficient coverage stay at 0.0
     328        if (GridCorr[code]->nMgrid[ix][iy] < 5) {
     329          GridCorr[code]-> Mgrid[ix][iy] = 0.0;
     330          GridCorr[code]->dMgrid[ix][iy] = 0.0;
     331          continue;
     332        }
     333
     334        liststats_init (&stats);
     335
     336        liststats (GridCorr[code]->dMval[ix][iy], NULL, NULL, GridCorr[code]->nMgrid[ix][iy], &stats);
     337        double altSigma = (stats.Upper80 - stats.Lower20) / 1.6;  // 20% to 80% encompasses 60% of the values, corresponds to the range (-0.85 sigma : +0.85 sigma)
     338
     339        GridCorr[code]-> Mgrid[ix][iy] = stats.median;
     340        GridCorr[code]->dMgrid[ix][iy] = altSigma; // sample stdev
     341      }
     342    }
     343  }
     344  return;
     345}
     346
     347# if (0)
    271348
    272349  // now calculate Mgrid, dMgrid, nMgrid from Sum, Sum, Npt
     
    300377    // float GridAve = GridSum / GridCnt;
    301378    // fprintf (stderr, "grid average: %f\n", GridAve);
    302   }
    303   return;
    304 }
     379# endif
    305380
    306381float getMgrid (Measure *measure) {
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r42132 r42788  
    147147    MagResidSave ("mag.resid.fits", catalog);
    148148
     149    // DumpAllMags ("all.mags.fits", catalog, Ncatalog);
     150
    149151    save_images_updates (&db);
    150152
Note: See TracChangeset for help on using the changeset viewer.