IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates to get tgroups working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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?
Note: See TracChangeset for help on using the changeset viewer.