IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41454 for trunk


Ignore:
Timestamp:
Dec 7, 2020, 5:45:21 PM (6 years ago)
Author:
eugene
Message:

pre-allocate psf,kron,brightStar arrays; use FitStatData for MosaicOps.c

Location:
trunk/Ohana/src/relphot/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r41453 r41454  
    925925  off_t Nmax;
    926926  int PoorImages;
    927   double *psfMagList;
    928   double *psfErrList;
    929   double *brightMagList;
    930   double *brightErrList;
    931   double *kronMagList;
    932   double *kronErrList;
     927  FitDataSet psfStars;
     928  FitDataSet kronStars;
     929  FitDataSet brightStars;
    933930} SetMmosInfo;
    934931
     
    961958
    962959  if (allocLists) {
    963     ALLOCATE (info->psfMagList, double, Nmax);
    964     ALLOCATE (info->psfErrList, double, Nmax);
    965     ALLOCATE (info->kronMagList, double, Nmax);
    966     ALLOCATE (info->kronErrList, double, Nmax);
    967     ALLOCATE (info->brightMagList, double, Nmax);
    968     ALLOCATE (info->brightErrList, double, Nmax);
     960    // we can only fit the zero point for individual exposures, not the airmass
     961    FitDataSetAlloc (&info->psfStars,    Nmax, 0, 0);
     962    FitDataSetAlloc (&info->kronStars,   Nmax, 0, 0);
     963    FitDataSetAlloc (&info->brightStars, Nmax, 0, 0);
    969964  }
    970965}
    971966
    972967void SetMmosInfoFree (SetMmosInfo *info) {
    973   free (info->psfMagList   );
    974   free (info->psfErrList   );
    975   free (info->kronMagList  );
    976   free (info->kronErrList  );
    977   free (info->brightMagList);
    978   free (info->brightErrList);
     968  FitDataSetFree (&info->brightStars);
     969  FitDataSetFree (&info->kronStars);
     970  FitDataSetFree (&info->psfStars);
    979971}
    980972
     
    10741066  off_t j, NimageReal;
    10751067
    1076   StatType stats;
    1077   liststats_setmode (&stats, "INNER_WTMEAN");
    1078 
    1079   double *psfMagList    = info->psfMagList;
    1080   double *psfErrList    = info->psfErrList;
    1081   double *kronMagList   = info->kronMagList;
    1082   double *kronErrList   = info->kronErrList;
    1083   double *brightMagList = info->brightMagList;
    1084   double *brightErrList = info->brightErrList;
    1085 
    1086   assert (Nmos >= 0);
    1087   assert (Nmos < Nmosaic);
    1088 
    1089   // Image *imageReal = getimages (&NimageReal, NULL); returned pointer is not used
    1090   getimages (&NimageReal, NULL);
    1091 
    10921068  /* on PoorImages run, skip good images */
    10931069  if (info->PoorImages) {
     
    10951071    if (!bad) return TRUE;
    10961072  }     
     1073
     1074  FitDataSet *psfStars = &info->psfStars;
     1075  FitDataSet *kronStars = &info->kronStars;
     1076  FitDataSet *brightStars = &info->brightStars;
     1077
     1078  assert (Nmos >= 0);
     1079  assert (Nmos < Nmosaic);
     1080
     1081  // Image *imageReal = getimages (&NimageReal, NULL); returned pointer is not used
     1082  getimages (&NimageReal, NULL);
    10971083
    10981084  // UBERCAL image: if this is an ubercal image, set minUbercalDist to 0:
     
    12301216    assert (Nbright >= 0);
    12311217
    1232     psfMagList[N]  = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
    1233     psfErrList[N]  = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    1234     kronMagList[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
    1235     kronErrList[N] = psfErrList[N];
     1218    psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
     1219    psfStars->alldata->dyVector[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     1220
     1221    kronStars->alldata-> yVector[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
     1222    kronStars->alldata->dyVector[N] = psfStars->alldata->dyVector[N];
     1223
    12361224    if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
    1237       brightMagList[Nbright] = psfMagList[N];
    1238       brightErrList[Nbright] = psfErrList[N];
     1225      brightStars->alldata-> yVector[Nbright] = psfStars->alldata-> yVector[N];
     1226      brightStars->alldata->dyVector[Nbright] = psfStars->alldata->dyVector[N];
    12391227      Nbright ++;
    12401228    }
    12411229    N++;
     1230
    12421231  }
    12431232  /* N_onMosaic[Nmos] is all measurements, N is good measurements */
    12441233
    1245   if (fout) {
    1246     fclose (fout);
    1247   }
     1234  if (fout) { fclose (fout); }
    12481235
    12491236  /* too few good measurements or too many bad measurements (skip in PoorImages run) */
     
    12621249  }
    12631250
    1264   liststats (psfMagList, psfErrList, NULL, N, &stats);
    1265   if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mmos: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
     1251  fit1d_irls (psfStars, N);
     1252  // if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mmos: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
    12661253
    12671254  // for now, I have no reason to measure these separately for camera-level images
    1268   myMosaic[0].McalPSF    = stats.mean;
    1269   myMosaic[0].dMcal      = stats.error;
    1270   myMosaic[0].McalChiSq  = stats.chisq;
    1271   myMosaic[0].nFitPhotom = N;
    1272 
    1273   liststats (kronMagList, kronErrList, NULL, N, &stats);
    1274   myMosaic[0].McalAPER   = stats.mean;
     1255  myMosaic[0].McalPSF    = psfStars->bSaveArray[0][0];
     1256  myMosaic[0].dMcal      = psfStars->bSigma[0];     
     1257  myMosaic[0].McalChiSq  = psfStars->chisq;         
     1258  myMosaic[0].nFitPhotom = psfStars->Nmeas;         
     1259
     1260  // fit1d_irls (kronStars, N);    // does it make sense to calculate a zero point based kron mags?
     1261  // myMosaic->McalAPER   = ???
    12751262
    12761263  if (testImage) {
    1277     fprintf (stderr, "test image %d (%d) %f %f %d ... ", (int) Nmos, myMosaic[0].start, stats.mean, stats.error, myMosaic[0].nFitPhotom);
     1264    fprintf (stderr, "test image %d (%d) %f %f %d ... ", (int) Nmos, myMosaic->start, myMosaic->McalPSF, myMosaic->dMcal, myMosaic->nFitPhotom);
    12781265  }
    12791266
    12801267  if (PLOTSTUFF) {
    1281     fprintf (stderr, "Mmos: %6.3f %6.3f +/- %6.3f %5d %5d | %s\n", stats.mean, stats.median, stats.sigma, stats.Nmeas, N, image[MosaicToImage[Nmos][0]].name);
    1282     plot_setMcal (psfMagList, N);
     1268    fprintf (stderr, "Mmos: %6.3f +/- %6.3f %5d %5d | %s\n", myMosaic->McalPSF, myMosaic->dMcal, myMosaic->nFitPhotom, N, image[MosaicToImage[Nmos][0]].name);
     1269    plot_setMcal (psfStars->alldata->yVector, N);
    12831270  }
    12841271
    12851272  // bright end scatter
    1286   liststats (brightMagList, brightErrList, NULL, Nbright, &stats);
    1287   myMosaic[0].dMsys = stats.sigma;
     1273  // fit1d_irls (brightStars, N);  // does it make sense to calculate a separate bright star zero point?
     1274  // myMosaic->dMsys = ???
    12881275
    12891276  if (myMosaic[0].McalPSF < -CLOUD_TOLERANCE) {
  • trunk/Ohana/src/relphot/src/TGroupOps.c

    r41453 r41454  
    527527  off_t Nmax;
    528528  int PoorImages;
    529   double *psfMagList;
    530   double *psfAirList;
    531   double *psfErrList;
    532   double *brightMagList;
    533   double *brightErrList;
    534   double *kronMagList;
    535   double *kronErrList;
     529  FitDataSet psfStars;
     530  FitDataSet kronStars;
     531  FitDataSet brightStars;
    536532} SetMgrpInfo;
    537533
     
    565561
    566562  if (allocLists) {
    567     ALLOCATE (info->psfMagList, double, Nmax);
    568     ALLOCATE (info->psfAirList, double, Nmax);
    569     ALLOCATE (info->psfErrList, double, Nmax);
    570     ALLOCATE (info->kronMagList, double, Nmax);
    571     ALLOCATE (info->kronErrList, double, Nmax);
    572     ALLOCATE (info->brightMagList, double, Nmax);
    573     ALLOCATE (info->brightErrList, double, Nmax);
     563    int fitOrder = TGROUP_FIT_AIRMASS ? 1 : 0;
     564   
     565    FitDataSetAlloc (&info->psfStars,    Nmax, fitOrder, 0);
     566    FitDataSetAlloc (&info->kronStars,   Nmax, fitOrder, 0);
     567    FitDataSetAlloc (&info->brightStars, Nmax, fitOrder, 0);
     568
     569    if (1) {
     570      FitDataSetAddPriors (&info->psfStars);
     571      info->psfStars.bPriorValue[1] = 0.0;  // note that we are fitting relative to the nominal slope
     572      info->psfStars.bPriorSigma[1] = 0.04; // XXX this prior sigma needs to be user-configured
     573    }
    574574  }
    575575}
    576576
    577577void SetMgrpInfoFree (SetMgrpInfo *info) {
    578   free (info->psfMagList   );
    579   free (info->psfAirList   );
    580   free (info->psfErrList   );
    581   free (info->kronMagList  );
    582   free (info->kronErrList  );
    583   free (info->brightMagList);
    584   free (info->brightErrList);
     578  FitDataSetFree (&info->brightStars);
     579  FitDataSetFree (&info->kronStars);
     580  FitDataSetFree (&info->psfStars);
    585581}
    586582
     
    694690  }     
    695691
    696   int fitOrder = TGROUP_FIT_AIRMASS ? 1 : 0;
    697 
    698   // allocate the arrays used by the fit1d_irls analysis below.
    699   // the last 0 means we are NOT using bootstrap analysis here
    700 
    701   FitDataSet psfStars, kronStars, brightStars;
    702   FitDataSetAlloc (&psfStars,    myTGroup->Nmeasure, fitOrder, 0);
    703   FitDataSetAlloc (&kronStars,   myTGroup->Nmeasure, fitOrder, 0);
    704   FitDataSetAlloc (&brightStars, myTGroup->Nmeasure, fitOrder, 0);
    705 
    706   // add prior constraint on airmass:
    707   if (1) {
    708     FitDataSetAddPriors (&psfStars);
    709     psfStars.bPriorValue[1] = 0.0;  // note that we are fitting relative to the nominal slope
    710     psfStars.bPriorSigma[1] = 0.04; // XXX this prior sigma needs to be user-configured
    711   }
     692  FitDataSet *psfStars = &info->psfStars;
     693  FitDataSet *kronStars = &info->kronStars;
     694  FitDataSet *brightStars = &info->brightStars;
     695
     696  assert (Ngrp >= 0);
     697  assert (Ngrp < NtgroupTimes);
    712698
    713699  // Image *imageReal = getimages (&NimageReal, NULL); returned pointer is not used
     
    820806    assert (Nbright >= 0);
    821807
    822     psfStars.alldata-> yVector[N] = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
    823     psfStars.alldata-> xVector[N] = (catalog[c].measureT[m].airmass - 1.0);
    824     psfStars.alldata->dyVector[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    825 
    826     kronStars.alldata-> yVector[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
    827     kronStars.alldata-> xVector[N] = psfStars.alldata-> xVector[N];
    828     kronStars.alldata->dyVector[N] = psfStars.alldata->dyVector[N];
     808    psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
     809    psfStars->alldata-> xVector[N] = (catalog[c].measureT[m].airmass - 1.0);
     810    psfStars->alldata->dyVector[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     811
     812    kronStars->alldata-> yVector[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
     813    kronStars->alldata-> xVector[N] = psfStars->alldata-> xVector[N];
     814    kronStars->alldata->dyVector[N] = psfStars->alldata->dyVector[N];
    829815
    830816    if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
    831       brightStars.alldata-> yVector[Nbright] = psfStars.alldata-> yVector[N];
    832       brightStars.alldata-> xVector[Nbright] = psfStars.alldata-> xVector[N];
    833       brightStars.alldata->dyVector[Nbright] = psfStars.alldata->dyVector[N];
     817      brightStars->alldata-> yVector[Nbright] = psfStars->alldata-> yVector[N];
     818      brightStars->alldata-> xVector[Nbright] = psfStars->alldata-> xVector[N];
     819      brightStars->alldata->dyVector[Nbright] = psfStars->alldata->dyVector[N];
    834820      Nbright ++;
    835821    }
     
    859845  // (myTGroup->flags & ID_IMAGE_PHOTOM_UBERCAL)
    860846
    861   fit1d_irls (&psfStars, N);
     847  fit1d_irls (psfStars, N);
    862848
    863849  // if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mgrp: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
    864850
    865851  // for now, I have no reason to measure these separately for camera-level images
    866   myTGroup->McalPSF    = psfStars.bSaveArray[0][0];
    867   myTGroup->dMcal      = psfStars.bSigma[0];
    868   myTGroup->McalChiSq  = psfStars.chisq;
    869   myTGroup->nFitPhotom = psfStars.Nmeas;
    870   myTGroup->dKlam      = psfStars.bSaveArray[1][0];
     852  myTGroup->McalPSF    = psfStars->bSaveArray[0][0];
     853  myTGroup->dMcal      = psfStars->bSigma[0];
     854  myTGroup->McalChiSq  = psfStars->chisq;
     855  myTGroup->nFitPhotom = psfStars->Nmeas;
     856  myTGroup->dKlam      = psfStars->bSaveArray[1][0];
    871857
    872858  // XXX drop this for tgroups?
    873   // fit1d_irls (&kronStars, N);    // does it make sense to calculate a zero point based kron mags?
     859  // fit1d_irls (kronStars, N);    // does it make sense to calculate a zero point based kron mags?
    874860  // myTGroup->McalAPER   = stats.mean;
    875861
     
    881867  if (PLOTSTUFF) {
    882868    fprintf (stderr, "Mgrp: %6.3f +/- %6.3f %5d of %5d | %.0f\n", myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom, N, ohana_sec_to_mjd(tgroup->start));
    883     plot_setMcal (psfStars.alldata->yVector, N);
     869    plot_setMcal (psfStars->alldata->yVector, N);
    884870  }
    885871
     
    887873  // XXX this does not make sense: I need to apply the airmass slope calculated above first
    888874  // redo this by calculating the corrected bright stars mags
    889   // fit1d_irls (&brightStars, N);  // does it make sense to calculate a separate bright star zero point?
     875  // fit1d_irls (brightStars, N);  // does it make sense to calculate a separate bright star zero point?
    890876  // myTGroup->dMsys = stats.sigma;
    891877
     
    899885  }
    900886
    901   FitDataSetFree (&brightStars);
    902   FitDataSetFree (&kronStars);
    903   FitDataSetFree (&psfStars);
     887  // FitDataSetFree (&brightStars);
     888  // FitDataSetFree (&kronStars);
     889  // FitDataSetFree (&psfStars);
    904890
    905891  return TRUE;
Note: See TracChangeset for help on using the changeset viewer.