IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42818


Ignore:
Timestamp:
May 8, 2025, 4:07:43 PM (15 months ago)
Author:
eugene
Message:

merge from trunk: relphot grid improvements

Location:
branches/eam_branches/ipp-20230313/Ohana
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/Ohana

  • branches/eam_branches/ipp-20230313/Ohana/src/addstar/src/grefstars.c

    r41801 r42818  
    4141    catalog->average[N].R = ohana_normalize_angle (catalog->average[N].R);
    4242
     43    catalog->measure[N].McalPSF  = 0.0;
     44    catalog->measure[N].McalAPER = 0.0;
     45    catalog->measure[N].dMcal    = 0.0;
     46       
    4347    catalog->measure[N].R = catalog->average[N].R;
    4448    catalog->measure[N].D = catalog->average[N].D;
  • branches/eam_branches/ipp-20230313/Ohana/src/relphot

  • branches/eam_branches/ipp-20230313/Ohana/src/relphot/Makefile

    r42112 r42818  
    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
  • branches/eam_branches/ipp-20230313/Ohana/src/relphot/include/relphot.h

    r42740 r42818  
    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
     
    615618void          initGridBins        PROTO((void));
    616619GridCorrectionType *getGridCorrByCode PROTO((int code));
     620GridCorrectionType *newGridCorrByCode PROTO((int code));
    617621GridCorrectionType *getGridCorrNext   PROTO((int *Nlast));
    618622int           GridCorrectionSave  PROTO((void));
     
    902906double get_median_zpt_tgroups (short photcode);
    903907void   set_median_zpt_tgroups (short photcode, double zpt);
     908
     909int DumpAllMags(char *filename, Catalog *catalog, int Ncatalog);
  • branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/GridIO.c

    r41647 r42818  
    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
  • branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/GridOps.c

    r41664 r42818  
    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) {
  • branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/MagResidSave.c

    r41647 r42818  
    5454  gfits_create_table_header (&theader, "BINTABLE", "MAG_PSF_RESID");
    5555
    56   gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degree", 1.0, 0.0);
    57   gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degree", 1.0, 0.0);
    58   gfits_define_bintable_column (&theader, "E", "MAG_RESID", "magnitude residual", "magnitudes", 1.0, 0.0);
    59   gfits_define_bintable_column (&theader, "E", "MAG_ERROR", "magnitude error", "magnitudes", 1.0, 0.0);
    60   gfits_define_bintable_column (&theader, "E", "MAG_CHISQ", "magnitude resid chisq", "unitless", 1.0, 0.0);
    61   gfits_define_bintable_column (&theader, "E", "MAG_MEDIAN", "median magnitude residual", "magnitudes", 1.0, 0.0);
     56  gfits_define_bintable_column (&theader, "D", "RA",         "ra",                           "degree",    1.0, 0.0);
     57  gfits_define_bintable_column (&theader, "D", "DEC",        "dec",                          "degree",    1.0, 0.0);
     58  gfits_define_bintable_column (&theader, "E", "MAG_RESID",  "magnitude residual",          "magnitudes", 1.0, 0.0);
     59  gfits_define_bintable_column (&theader, "E", "MAG_ERROR",  "magnitude error",              "magnitudes", 1.0, 0.0);
     60  gfits_define_bintable_column (&theader, "E", "MAG_CHISQ",  "magnitude resid chisq",        "unitless",  1.0, 0.0);
     61  gfits_define_bintable_column (&theader, "E", "MAG_MEDIAN", "median magnitude residual",    "magnitudes", 1.0, 0.0);
    6262  gfits_define_bintable_column (&theader, "E", "MAG_ALTSIG", "68 percentile range as sigma", "magnitudes", 1.0, 0.0);
    63   gfits_define_bintable_column (&theader, "E", "AIRMASS",   "", "unitless", 1.0, 0.0);
    64   gfits_define_bintable_column (&theader, "D", "MJD",       "", "unitless", 1.0, 0.0);
    65   gfits_define_bintable_column (&theader, "E", "EXPTIME",   "", "unitless", 1.0, 0.0);
    66   gfits_define_bintable_column (&theader, "J", "PHOTCODE",  "", "unitless", 1.0, 0.0);
    67   gfits_define_bintable_column (&theader, "J", "FLAGS",     "image flags", "unitless",   1.0, 0.0);
    68   gfits_define_bintable_column (&theader, "J", "NFIT",      "number of stars fitted", NULL, 1.0, FT_BZERO_INT32);
    69   gfits_define_bintable_column (&theader, "J", "NMEAS",     "number of stars on image", NULL, 1.0, FT_BZERO_INT32);
     63  gfits_define_bintable_column (&theader, "E", "AIRMASS",    "",                             "unitless",  1.0, 0.0);
     64  gfits_define_bintable_column (&theader, "D", "MJD",        "",                             "unitless",  1.0, 0.0);
     65  gfits_define_bintable_column (&theader, "E", "EXPTIME",    "",                             "unitless",  1.0, 0.0);
     66  gfits_define_bintable_column (&theader, "J", "PHOTCODE",   "",                             "unitless",  1.0, 0.0);
     67  gfits_define_bintable_column (&theader, "J", "FLAGS",      "image flags",                  "unitless",   1.0, 0.0);
     68  gfits_define_bintable_column (&theader, "J", "NFIT",       "number of stars fitted",       NULL,         1.0, 0.0);
     69  gfits_define_bintable_column (&theader, "J", "NMEAS",      "number of stars on image",     NULL,         1.0, 0.0);
    7070
    7171  // generate the output array that carries the data
  • branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/relphot_images.c

    r42132 r42818  
    147147    MagResidSave ("mag.resid.fits", catalog);
    148148
     149    // DumpAllMags ("all.mags.fits", catalog, Ncatalog);
     150
    149151    save_images_updates (&db);
    150152
  • branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/setMrelCatalog.c

    r42537 r42818  
    412412      secfilt[Nsec].flags |= ID_SECF_HAS_CFH;
    413413    }
     414//  secfilt[Nsec].flags |= ID_SECF_AST_GAIA ; // for building reference catalog only, STAR_FEW need to comment out
     415//  secfilt[Nsec].flags |= ID_SECF_PHO_SYNTH; // for building reference catalog only, STAR_FEW need to comment out
     416//  secfilt[Nsec].flags |= ID_SECF_PHO_ATLAS; // for building reference catalog only, STAR_FEW need to comment out
     417//  secfilt[Nsec].flags |= ID_SECF_PHO_PV3  ; // for building reference catalog only, STAR_FEW need to comment out
     418//  secfilt[Nsec].flags |= ID_SECF_PHO_SOUTH; // for building reference catalog only, STAR_FEW need to comment out
    414419
    415420    // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps:
Note: See TracChangeset for help on using the changeset viewer.