IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41387


Ignore:
Timestamp:
Jul 7, 2020, 9:30:05 AM (6 years ago)
Author:
eugene
Message:

updates to get tgroups working

Location:
branches/eam_branches/relphot.20200519
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/relphot.20200519/include/relphot.h

    r41362 r41387  
    9696  float McalPSF;
    9797  float McalAPER;
     98  float dKlam;
    9899  float dMcal;
    99100  float dMsys;
     
    110111  off_t *measure;
    111112
    112   off_t Ncatalog;
    113   off_t NCATALOG;
     113  off_t Ncatalog; // XX not needed
     114  off_t NCATALOG; // XX not needed
    114115  off_t *catalog;
    115116} TGroup;
     
    332333int    MOSAIC_ZEROPT;
    333334int    TGROUP_ZEROPT;
     335int    TGROUP_FIT_AIRMASS;
    334336
    335337int    TEST_IMAGE1;
     
    457459void          freeImageBins       PROTO((int Ncatalog, int doImageList));
    458460void          freeMosaicBins      PROTO((int Ncatalog, int doMosaicList));
    459 void          freeTGroupBins      PROTO((int Ncatalog, int doTGroupList));
     461void          freeTGroupBins      PROTO((int Ncatalog));
    460462
    461463void          free_catalogs       PROTO((Catalog *catalog, int Ncatalog));
     
    468470float         getMgrid            PROTO((off_t meas, int cat));
    469471float         getMmos             PROTO((off_t meas, int cat));
    470 float         getMgrp             PROTO((off_t meas, int cat));
     472float         getMgrp             PROTO((off_t meas, int cat, float airmass));
    471473float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source));
    472474short         getUbercalDist      PROTO((off_t meas, int cat));
     
    485487void          initMosaics         PROTO((Image *subset, off_t Nsubset, Image *image, char *inSubset, off_t Nimage));
    486488void          initTGroups         PROTO((Image *subset, off_t *LineNumber, off_t Nsubset));
     489void          freeTGroups         PROTO((void));
    487490void          initTGroupBins      PROTO((Catalog *catalog, int Ncatalog));
    488491void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
     
    493496int           liststats_init      PROTO((StatType *stats));
    494497int           liststats_irls      PROTO((StatDataSet *dataset, int Npoints, StatType *stats));
     498int           liststats_fit1d     PROTO((double *value, double *err, double *x, int Npts, StatType *stats, double *dk));
    495499
    496500unsigned int *ReadTGroupFile      PROTO((FILE *f, int *nelem));
     
    721725void RepairWarpMeasuresOpenLogfile ();
    722726void RepairWarpMeasuresCloseLogfile ();
     727
     728int save_images_backup (FITS_DB *db);
  • branches/eam_branches/relphot.20200519/src/GridOps.c

    r40291 r41387  
    289289
    290290  int **gotstar, **gridmeas;
    291   int i, j, k, Ngood, Nbad, Nmos, Ncal, Nrel, Nsys;
     291  int i, j, k, Ngood, Nbad, Nmos, Ncal, Nrel, Nsys, Ngrp;
    292292  double **A, **B, *Mjx, *Wjx;
    293   float Msys, Mcal, Mmos, Merr, Wsys;
     293  float Msys, Mcal, Mmos, Mgrp, Merr, Wsys;
    294294  double Mj, Wj;
    295295 
     
    305305  }
    306306
    307   Ngood = Nbad = Ncal = Nmos = Nrel = Nsys = 0;
     307  Ngood = Nbad = Ncal = Nmos = Nrel = Nsys = Ngrp = 0;
    308308
    309309  ALLOCATE (gotstar, int *, Ncatalog);
     
    411411        if (isnan(Mmos)) {
    412412          Nmos ++;
     413          continue;
     414        }
     415
     416        // skip mosaics marked as BAD
     417        Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     418        if (isnan(Mgrp)) {
     419          Ngrp ++;
    413420          continue;
    414421        }
     
    526533void setMgrid (Catalog *catalog, FlatCorrectionTable *flatcorr) {
    527534
    528   int i, j, m, c, n, N, Nmax, Nbad, Nmos, Ncal, Nrel, Nsys, Nfit;
     535  int i, j, m, c, n, N, Nmax, Nbad, Nmos, Ngrp, Ncal, Nrel, Nsys, Nfit;
    529536  double *list, *dlist;
    530   float Msys, Mrel, Mcal, Mmos;
     537  float Msys, Mrel, Mcal, Mmos, Mgrp;
    531538
    532539  StatType stats;
     
    544551  ALLOCATE (dlist, double, Nmax);
    545552
    546   Nbad = Ncal = Nmos = Nrel = Nsys = Nfit = 0;
     553  Nbad = Ncal = Nmos = Ngrp = Nrel = Nsys = Nfit = 0;
    547554
    548555  for (i = 0; i < Ngrid; i++) {
     
    568575        continue;
    569576      }
     577      Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     578      if (isnan(Mgrp)) {
     579        Ngrp ++;
     580        continue;
     581      }
    570582      Mrel  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
    571583      if (isnan(Mrel)) {
     
    580592        continue;
    581593      }
    582       list[N] = Msys - Mrel - Mcal - Mmos;
     594      list[N] = Msys - Mrel - Mcal - Mmos - Mgrp;
    583595      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    584596      N++;
     
    616628
    617629  int i, j, m, c, n, N, Narea;
    618   float Msys, Mrel, Mcal, Mmos;
     630  float Msys, Mrel, Mcal, Mmos, Mgrp;
    619631  double *xlist, *Mlist, *dlist, *ylist;
    620632  Graphdata graphdata;
     
    649661      Mmos  = getMmos  (m, c);
    650662      if (isnan(Mmos)) continue;
     663      Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     664      if (isnan(Mgrp)) continue;
    651665      Mrel  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
    652666      if (isnan(Mrel)) continue;
     
    657671      xlist[N] = Xmeas[c][m];
    658672      ylist[N] = Ymeas[c][m];
    659       Mlist[N] = Msys - Mrel - Mcal - Mmos;
    660       dlist[N] = Msys - Mrel - Mcal - Mmos - gridM[i];
     673      Mlist[N] = Msys - Mrel - Mcal - Mmos - Mgrp;
     674      dlist[N] = Msys - Mrel - Mcal - Mmos - Mgrp - gridM[i];
    661675      N++;
    662676    }
  • branches/eam_branches/relphot.20200519/src/ImageOps.c

    r40291 r41387  
    586586
    587587  off_t i, j, m, c, n;
    588   int mark, bad, Nfew, Nbad, Nmos, Nrel, Ngrid, Nsys;
     588  int mark, bad, Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys;
    589589
    590590  StatType stats;
     
    612612  StatDataSet *brightStars = StatDataSetAlloc (1, Nmax);
    613613
    614   Nfew = Nbad = Nmos = Ngrid = Nrel = Nsys = 0;
     614  Nfew = Nbad = Nmos = Ngrp = Ngrid = Nrel = Nsys = 0;
    615615
    616616  int Ncalibrated = 0;
     
    631631
    632632    // only freeze the gpc1 chips
    633     if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     633    // XXX : when do we FREEZE_IMAGES in a mix of GPC1, GPC2, etc?
     634    // if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     635    if (FREEZE_IMAGES) continue;
    634636    if (image[i].photcode == 0) continue; // skip the PHU images
    635637
     
    666668          continue;
    667669      }
     670      float Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     671      if (isnan(Mgrp)) {
     672          Ngrp ++;
     673          continue;
     674      }
    668675      float Mgrid = getMgrid (m, c);
    669676      if (isnan(Mgrid)) {
     
    706713
    707714    skip:
    708       psfStars->flxlist[Nref] = MsysPSF - MrelPSF - Mmos - Mgrid + Mflat;
     715      psfStars->flxlist[Nref] = MsysPSF - MrelPSF - Mmos - Mgrp - Mgrid + Mflat;
    709716      psfStars->errlist[Nref] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    710717      psfStars->wgtlist[Nref] = 1;
     
    718725
    719726      if (isfinite(MrelKron) && isfinite(MsysKron)) {
    720         kronStars->flxlist[Nkron] = MsysKron - MrelKron - Mmos - Mgrid + Mflat;
     727        kronStars->flxlist[Nkron] = MsysKron - MrelKron - Mmos - Mgrp - Mgrid + Mflat;
    721728        kronStars->errlist[Nkron] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    722729        kronStars->wgtlist[Nkron] = 1;
     
    10231030  off_t i, j, m, c, n, N;
    10241031  double *list, *dlist;
    1025   float Mcal, Mmos, Mgrid;
     1032  float Mcal, Mmos, Mgrp, Mgrid;
    10261033
    10271034  StatType stats;
     
    10501057      Mmos  = getMmos  (m, c);
    10511058      if (isnan(Mmos)) continue;
     1059      Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     1060      if (isnan(Mgrp)) continue;
    10521061      Mgrid = getMgrid (m, c);
    10531062      if (isnan(Mgrid)) continue;
  • branches/eam_branches/relphot.20200519/src/MosaicOps.c

    r41362 r41387  
    919919  int Nbad;
    920920  int Ncal;
     921  int Ngrp;
    921922  int Ngrid;
    922923  int Nrel;
     
    11541155    if (fout) {
    11551156      float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);
     1157      // float Mgrp     = getMgrp  (m, c, catalog[c].measureT[m].airmass);
    11561158      float Mgrid    = getMgrid (m, c);
    11571159      float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
     
    11751177    if (isnan(Mcal)) {
    11761178      info->Ncal++;
     1179      continue;
     1180    }
     1181    float Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     1182    if (isnan(Mgrp)) {
     1183      info->Ngrp++;
    11771184      continue;
    11781185    }
     
    16921699  off_t i, j, m, c, n, N;
    16931700  double *list, *dlist;
    1694   float Mcal, Mgrid, Mrel;
     1701  float Mcal, Mgrp, Mgrid, Mrel;
    16951702  StatType stats;
    16961703
     
    17161723      Mcal = getMcal  (m, c, MAG_CLASS_PSF);
    17171724      if (isnan(Mcal)) continue;
     1725      Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     1726      if (isnan(Mgrp)) continue;
    17181727      Mgrid = getMgrid (m, c);
    17191728      if (isnan(Mgrid)) continue;
  • branches/eam_branches/relphot.20200519/src/StarOps.c

    r41362 r41387  
    491491        float Mmos  = getMmos  (m, i);
    492492        if (isnan(Mmos)) continue;
    493         float Mgrp  = getMgrp  (m, i);
     493        float Mgrp  = getMgrp  (m, i, catalog[i].measureT[m].airmass);
    494494        if (isnan(Mgrp)) continue;
    495495        float Mgrid = getMgrid (m, i);
     
    507507
    508508        // set the output calibration
    509         float Moff = Mmos + Mgrp + Mgrid;
     509        // float Moff = Mmos + Mgrp + Mgrid;
     510        float Moff = Mmos + Mgrid; // Mgrp has already been applied to the image.Mcal
    510511        catalog[i].measure[m].McalPSF  = McalPSF + Moff;
    511512        catalog[i].measure[m].McalAPER = useStackAper ? McalAPER + Moff : McalPSF + Moff;
     
    730731          Mmos  = getMmos  (m, i);
    731732          if (isnan(Mmos)) { Nmos ++; continue; }
    732           Mgrp  = getMgrp  (m, i);
     733          Mgrp  = getMgrp  (m, i, catalog[i].measureT[m].airmass);
    733734          if (isnan(Mgrp)) { Ngrp ++; continue; }
    734735          Mgrid = getMgrid (m, i);
     
    736737
    737738          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF);
    738           list[N] = Msys - Mcal - Mmos - Mgrid;
     739          list[N] = Msys - Mcal - Mmos - Mgrp - Mgrid;
    739740          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
    740741          N++;
  • branches/eam_branches/relphot.20200519/src/TGroupOps.c

    r41362 r41387  
    3636// load the photometric nights from a file : these will be used to define the tgroups
    3737// XXX call this in args.c where TGROUP_ZEROPT is set
     38// XXX cannot call this in args.c : the Nphotcodes have not yet been loaded.
    3839void loadTGroups (char *filename) {
    3940
     
    7374      tgroup[Nt].McalPSF   = 0.0; // note : at the end, tgroup.Mcal is added back to the input images
    7475      tgroup[Nt].McalAPER  = 0.0; // note : tgroup stores only offsets relative to the original image values
     76      tgroup[Nt].dKlam     = 0.0;
    7577      tgroup[Nt].dMcal     = 0.0; // note : at the end, tgroup.Mcal is added back to the input images
    7678      tgroup[Nt].dMsys     = 0.0;
     
    111113
    112114    // ignore non-GPC1 images
    113     if (!isGPC1chip(subset[i].photcode)) {
    114       Nsimple ++;
     115    // if (!isGPC1chip(subset[i].photcode)) {
     116    //   Nsimple ++;
     117    //   continue;
     118    // }
     119
     120    // ignore mosaic images (photcode == 0)
     121    if (!subset[i].photcode) {
    115122      continue;
    116123    }
     
    138145
    139146  fprintf (stderr, "matched %d images to %d tgroups, %d simple chips not matched to tgroups\n", (int) (Nsubset - Nsimple), (int) Ntgroup, (int) Nsimple);
     147  return;
     148}
     149
     150void freeTGroups (void) {
     151
     152  if (!TGROUP_ZEROPT) return;
     153
     154  free (ImageToTGroup);
     155  free (tgroupTimes);
     156
     157  for (int i = 0; i < Ntgroup; i++) {
     158    free (tgroup[i].image);
     159    free (tgroup[i].measure);
     160    free (tgroup[i].catalog);
     161  }
     162  free (tgroup);
    140163  return;
    141164}
     
    221244  // if start is not in this range, return -1
    222245  if (start < tgroupTimes[Nlo]) return (-1);
    223   if (start > tgroupTimes[Nhi]) return (-1);
     246  if (start > tgroupTimes[Nhi] + 86399) return (-1); // 1-day range for tgroup for now
    224247
    225248  while (Nhi - Nlo > 4) {
     
    259282    for (j = 0; j < tgroup[i].Nimage; j++) {
    260283      im = tgroup[i].image[j];
    261       image[im].McalPSF    += tgroup[i].McalPSF;
    262       image[im].McalAPER   += tgroup[i].McalAPER;
     284      double Mgrp = (TGROUP_FIT_AIRMASS) ? tgroup[i].McalPSF + tgroup[i].dKlam*(image[im].secz - 1.0) : tgroup[i].McalPSF;
     285      image[im].McalPSF    += Mgrp;
     286      image[im].McalAPER   += Mgrp;
    263287      image[im].dMcal       = tgroup[i].dMcal;
    264288      image[im].McalChiSq   = tgroup[i].McalChiSq;
     
    267291      image[im].flags      |= (tgroup[i].flags & ID_IMAGE_PHOTOM_FEW);
    268292      image[im].flags      |= (tgroup[i].flags & ID_IMAGE_PHOTOM_POOR);
     293
     294      fprintf (stderr, "TG to IMAGE: %f -> %f (%d)\n", tgroup[i].McalPSF, image[im].McalPSF, tgroup[i].nFitPhotom);
    269295    }
    270296    tgroup[i].McalPSF  = 0.0;
    271297    tgroup[i].McalAPER = 0.0;
     298    tgroup[i].dKlam    = 0.0;
    272299  }     
    273300}
     
    287314}
    288315
    289 void freeTGroupBins (int Ncatalog, int doTGroupList) {
     316void freeTGroupBins (int Ncatalog) {
    290317
    291318  off_t i;
     
    329356    }
    330357  }
    331   // fprintf (stderr, "matched %d detections to tgroups\n", Nmatch);
     358  fprintf (stderr, "Matched %d detections to tgroups\n", Nmatch);
     359  for (i = 0; i < Ntgroup; i++) {
     360    fprintf (stderr, "  TGROUP time %d, Nmeasure: %d, Nimage: %d\n", tgroup[i].start, (int) tgroup[i].Nmeasure, (int) tgroup[i].Nimage);
     361  }
    332362  return (TRUE);
    333363}
     
    380410}
    381411
    382 float getMgrp (off_t meas, int cat) {
     412float getMgrp (off_t meas, int cat, float airmass) {
    383413
    384414  off_t i;
     
    392422
    393423  // if (tgroup[i].flags & IMAGE_BAD) return (NAN); 
    394   value = tgroup[i].McalPSF;
     424  value = tgroup[i].McalPSF + tgroup[i].dKlam*(airmass - 1.0);
    395425  return (value);
    396426}
     
    419449  int PoorImages;
    420450  double *psfMagList;
     451  double *psfAirList;
    421452  double *psfErrList;
    422453  double *brightMagList;
     
    456487  if (allocLists) {
    457488    ALLOCATE (info->psfMagList, double, Nmax);
     489    ALLOCATE (info->psfAirList, double, Nmax);
    458490    ALLOCATE (info->psfErrList, double, Nmax);
    459491    ALLOCATE (info->kronMagList, double, Nmax);
     
    466498void SetMgrpInfoFree (SetMgrpInfo *info) {
    467499  free (info->psfMagList   );
     500  free (info->psfAirList   );
    468501  free (info->psfErrList   );
    469502  free (info->kronMagList  );
     
    522555  image = getimages (&N, NULL);
    523556
    524   fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
    525 
    526557  if (PoorImages) {
    527558    // XXX use bad stars and measurements for PoorImages? or not?
     
    543574  for (i = 0; i < Ntgroup; i++) {
    544575    setMgrp_tgroup (&tgroup[i], i, image, catalog, &info, flatcorr);
     576    fprintf (stderr, "TGROUP Mcal: %f, dK: %f, limiting negative clouds to %f\n", tgroup[i].McalPSF, tgroup[i].dKlam, CLOUD_TOLERANCE);
    545577  }
    546578  SetMgrpInfoFree (&info);
     
    575607
    576608  double *psfMagList    = info->psfMagList;
     609  double *psfAirList    = info->psfAirList;
    577610  double *psfErrList    = info->psfErrList;
    578611  double *kronMagList   = info->kronMagList;
     
    593626
    594627  int testImage = FALSE;
    595   // testImage |= (abs(myTGroup[0].start - 1324104046) < 10);
     628  testImage |= (abs(myTGroup[0].start - 1245283200) < 10);
    596629  // testImage |= (abs(myTGroup[0].start - 1324103823) < 10);
    597630
     
    633666      int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);
    634667
    635       fprintf (fout, "%f %f : %f %f %f %f %f  : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mgrid, Mflat, delta, isBad);
     668      fprintf (fout, "%f %f : %f %f %f %f %f  : %f %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mgrid, Mflat, catalog[c].measureT[m].airmass, delta, isBad);
    636669    }
    637670
     
    697730
    698731    psfMagList[N]  = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
     732    psfAirList[N]  = (catalog[c].measureT[m].airmass - 1.0);
    699733    psfErrList[N]  = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    700734    kronMagList[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
     
    725759  }
    726760
    727   liststats (psfMagList, psfErrList, NULL, N, &stats);
     761  double dk = 0.0;
     762  if (TGROUP_FIT_AIRMASS) {
     763    liststats_fit1d (psfMagList, psfErrList, psfAirList, N, &stats, &dk);
     764  } else {
     765    liststats (psfMagList, psfErrList, NULL, N, &stats);
     766  }
    728767  if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mgrp: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
    729768
     
    733772  myTGroup[0].McalChiSq  = stats.chisq;
    734773  myTGroup[0].nFitPhotom = N;
     774  myTGroup[0].dKlam      = dk;
    735775
    736776  // drop this for tgroups?
  • branches/eam_branches/relphot.20200519/src/args.c

    r41362 r41387  
    317317  }
    318318
     319  FREEZE_IMAGES = FALSE;
     320  if ((N = get_argument (argc, argv, "-imfreeze"))) {
     321    remove_argument (N, &argc, argv);
     322    FREEZE_IMAGES = TRUE;
     323  }
     324  FREEZE_MOSAICS = FALSE;
     325  if ((N = get_argument (argc, argv, "-mosfreeze"))) {
     326    remove_argument (N, &argc, argv);
     327    FREEZE_MOSAICS = TRUE;
     328  }
     329  CALIBRATE_STACKS_AND_WARPS = FALSE;
     330  if ((N = get_argument (argc, argv, "-only-stacks-and-warps"))) {
     331    remove_argument (N, &argc, argv);
     332    CALIBRATE_STACKS_AND_WARPS = TRUE;
     333  }
     334  USE_MCAL_PSF_FOR_STACK_APER = FALSE;
     335  if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
     336    remove_argument (N, &argc, argv);
     337    USE_MCAL_PSF_FOR_STACK_APER = TRUE;
     338  }
     339
    319340  // calibrate the photometry by night / time period
    320341  TGROUP_ZEROPT = FALSE;
     342  char *TGROUP_FILENAME = NULL;
    321343  if ((N = get_argument (argc, argv, "-tgroup"))) {
    322344    TGROUP_ZEROPT = TRUE;
    323345    remove_argument (N, &argc, argv);
    324     loadTGroups (argv[N]);
    325     remove_argument (N, &argc, argv);
    326   }
    327 
    328   FREEZE_IMAGES = FALSE;
    329   if ((N = get_argument (argc, argv, "-imfreeze"))) {
     346    TGROUP_FILENAME = strcreate(argv[N]);
    330347    remove_argument (N, &argc, argv);
    331348    FREEZE_IMAGES = TRUE;
    332349  }
    333   FREEZE_MOSAICS = FALSE;
    334   if ((N = get_argument (argc, argv, "-mosfreeze"))) {
    335     remove_argument (N, &argc, argv);
    336     FREEZE_MOSAICS = TRUE;
    337   }
    338   CALIBRATE_STACKS_AND_WARPS = FALSE;
    339   if ((N = get_argument (argc, argv, "-only-stacks-and-warps"))) {
    340     remove_argument (N, &argc, argv);
    341     CALIBRATE_STACKS_AND_WARPS = TRUE;
    342   }
    343   USE_MCAL_PSF_FOR_STACK_APER = FALSE;
    344   if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
    345     remove_argument (N, &argc, argv);
    346     USE_MCAL_PSF_FOR_STACK_APER = TRUE;
     350  if ((N = get_argument (argc, argv, "-tgroups"))) {
     351    if (TGROUP_ZEROPT) {
     352      fprintf (stderr, "use only one of -tgroups and -tgroup (same meaning)\n");
     353      exit (2);
     354    }
     355    TGROUP_ZEROPT = TRUE;
     356    remove_argument (N, &argc, argv);
     357    TGROUP_FILENAME = strcreate(argv[N]);
     358    remove_argument (N, &argc, argv);
     359    FREEZE_IMAGES = TRUE;
     360  }
     361  TGROUP_FIT_AIRMASS = FALSE;
     362  if ((N = get_argument (argc, argv, "-tgroup-fit-airmass"))) {
     363    if (!TGROUP_ZEROPT) {
     364      fprintf (stderr, "-tgroup-fit-airmass requires -tgroup (filename) option\n");
     365      exit (2);
     366    }
     367    TGROUP_FIT_AIRMASS = TRUE;
     368    remove_argument (N, &argc, argv);
    347369  }
    348370
     
    528550  if (argc != 1) relphot_usage ();
    529551
     552  if (TGROUP_ZEROPT) {
     553    loadTGroups (TGROUP_FILENAME);
     554    free (TGROUP_FILENAME);
     555  }
     556
    530557  return mode;
    531558}
     
    551578  FreePhotcodeTable();
    552579 
     580  freeTGroups();
     581
    553582  ohana_memcheck (VERBOSE);
    554583  ohana_memdump (VERBOSE);
  • branches/eam_branches/relphot.20200519/src/liststats.c

    r40291 r41387  
    172172  for (i = ks; i < ke; i++) {
    173173    M  = SQ (value[i] - Mo);
    174     dM = SQ (dvalue[i]);
    175     X2 += M / dM;
     174    if (dvalue) {
     175      dM = SQ (dvalue[i]);
     176      X2 += M / dM;
     177    }
    176178    dS += M;
    177179  }
    178   X2 = X2 / (Nm - 1);
     180  X2 = dvalue ? X2 / (Nm - 1) : NAN;
    179181  dS = sqrt (dS / (Nm - 1));
    180182
     
    187189  return (TRUE);
    188190}
     191
     192int liststats_fit1d (double *value, double *err, double *x, int Npts, StatType *stats, double *dk) {
     193
     194  double M = 0.0, MZ = 0.0, Z1 = 0.0, Z2 = 0.0, R = 0.0;
     195
     196  for (int i = 0; i < Npts; i++) {
     197    double wt = 1.0 / (err[i]*err[i]);
     198    double V = value[i];
     199    double Z = x[i];
     200    M  += V   * wt;
     201    MZ += V*Z * wt;
     202    Z1 += Z   * wt;
     203    Z2 += Z*Z * wt;
     204    R  += 1.0 * wt;
     205  }
     206
     207  double DetInv = (R*Z2 - Z1*Z1);
     208  double Det = (fabs(DetInv) < -1e6) ? 0.0 : 1.0 / DetInv; // do not allow unstable solutions
     209
     210  double zp = (M*Z2 - Z1*MZ)*Det;
     211  *dk = (MZ*R - M*Z1)*Det;
     212
     213  stats->mean = zp;
     214  stats->chisq = NAN;
     215  return TRUE;
     216}
     217
    189218
    190219// These should probably be tunable:
  • branches/eam_branches/relphot.20200519/src/reload_catalogs.c

    r41341 r41387  
    8686    initImageBins  (&catalog, 1, FALSE);
    8787    initMosaicBins (&catalog, 1, FALSE);
     88    initTGroupBins (&catalog, 1);
     89
    8890    initGridBins   (&catalog, 1);
    8991    TIMESTAMP(time3b);
     
    9193    findImages (&catalog, 1, FALSE);
    9294    findMosaics (&catalog, 1, FALSE);
     95    findTGroups (&catalog, 1);
     96
    9397    TIMESTAMP(time4);
    9498
     
    117121    TIMESTAMP(time6);
    118122
     123    // XXX freeTgroupBins here:
     124
    119125    freeImageBins (1, FALSE);
    120126    freeMosaicBins (1, FALSE);
     127    freeTGroupBins (1);
    121128    freeGridBins (1);
    122129    TIMESTAMP(time7);
  • branches/eam_branches/relphot.20200519/src/relphot_images.c

    r41362 r41387  
    8181    MARKTIME("-- set up mosaic indexes: %f sec\n", dtime);
    8282
    83     findTGroups (catalog, Ncatalog);  /* also sets Grid values */
     83    findTGroups (catalog, Ncatalog);
    8484    MARKTIME("-- set up mosaic indexes: %f sec\n", dtime);
    8585
     
    158158      if ((i > 8) && (i % 8 == 3)) clean_stars (catalog, Ncatalog);
    159159      if ((i > 8) && (i % 8 == 5)) clean_mosaics ();
     160      if ((i > 8) && (i % 8 == 5)) clean_tgroups ();
    160161      if ((i > 8) && (i % 8 == 5)) clean_images ();
    161162
     
    258259    freeImageBins (Ncatalog, TRUE);
    259260    freeMosaicBins (Ncatalog, TRUE);
     261    freeTGroupBins (Ncatalog);
    260262    freeGridBins (Ncatalog);
    261263
  • branches/eam_branches/relphot.20200519/src/setMrelCatalog.c

    r40373 r41387  
    221221
    222222    // ** Choose the calibration (depends on the mode : do I have an image reference or not?)
    223     float Mcal = 0.0, Mmos = 0.0, Mgrid = 0.0, Mflat = 0.0;
     223    float Mcal = 0.0, Mmos = 0.0, Mgrid = 0.0, Mflat = 0.0, Mgrp = 0.0;
    224224    off_t meas = measureOffset + k;
    225225    if (getImageEntry (meas, cat) < 0) {
     
    235235      Mmos  = getMmos  (meas, cat);
    236236      if (isnan(Mmos))  SKIP_THIS_MEAS(Nmos);
     237      Mgrp  = getMgrp  (meas, cat, measureT[k].airmass);
     238      if (isnan(Mgrp))  SKIP_THIS_MEAS(Ngrp);
    237239      Mgrid = getMgrid (meas, cat);
    238240      if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid);
     
    261263      if (CHECK_VALID_MAG(Map, dMap)) {
    262264        int Nap = results->aperData[Nsec].Nlist;
    263         results->aperData[Nsec].flxlist[Nap] = Map - Mflat - Mcal - Mmos - Mgrid; // this is consistent with PhotRel
     265        results->aperData[Nsec].flxlist[Nap] = Map - Mflat - Mcal - Mmos - Mgrp - Mgrid; // this is consistent with PhotRel
    264266        results->aperData[Nsec].errlist[Nap] = dMap;
    265267        results->aperData[Nsec].wgtlist[Nap] = useUbercalWeight ? UBERCAL_WEIGHT : 1.0;
     
    281283    if (CHECK_VALID_MAG(Mkron, dMkron)) {
    282284      int Nkron = results->kronData[Nsec].Nlist;
    283       results->kronData[Nsec].flxlist[Nkron] = Mkron - Mflat - Mcal - Mmos - Mgrid; // this is consistent with PhotRel
     285      results->kronData[Nsec].flxlist[Nkron] = Mkron - Mflat - Mcal - Mmos - Mgrp - Mgrid; // this is consistent with PhotRel
    284286      results->kronData[Nsec].errlist[Nkron] = dMkron;
    285287      results->kronData[Nsec].wgtlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0;
     
    294296    if (CHECK_VALID_MAG(Mpsf, dMpsf)) {
    295297      int Npsf = results->psfData[Nsec].Nlist;
    296       results->psfData[Nsec].flxlist[Npsf] = Mpsf - Mflat - Mcal - Mmos - Mgrid; // this is consistent with PhotRel
     298      results->psfData[Nsec].flxlist[Npsf] = Mpsf - Mflat - Mcal - Mmos - Mgrp - Mgrid; // this is consistent with PhotRel
    297299      results->psfData[Nsec].errlist[Npsf] = dMpsf;
    298300      results->psfData[Nsec].wgtlist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0;
     
    711713      Mmos      = getMmos  (measSeq, cat);
    712714      Mgrid     = getMgrid (measSeq, cat);
     715      // XXX can Mmos and Mgrid exist for stacks?
    713716    }
    714717   
Note: See TracChangeset for help on using the changeset viewer.